﻿// ------------ store extensions ------------ //
Ext.ux.StoreEx = Ext.extend(Ext.data.Store, {

    m_initialPageSize: 0, // this is the number of items that were loaded initially (before any deletions)


    // standard constructor
    constructor: function(config) {
        Ext.ux.StoreEx.superclass.constructor.call(this, config);

        // array of deleted records
        // we maintain this separately because overriding 'remove' functionality isn't an option
        // due to the fact that it is called when reordering (by removing & inserting)
        this.m_deleted = [];

        this.on('load', this.onLoad, this);
    },

    // no initializer because it isn't a component

    // fires after a new set of Records has been loaded.
    onLoad: function(store, records, options) {
        this.clearDeletedRecords();

        this.setInitialPageSize(records.length);
    },
    
    // add a deleted record to the 
    addDeletedRecord: function(record) {
        this.m_deleted.push(record);
    },

    // retrieve deleted records
    getDeletedRecords: function() {
        return this.m_deleted;
    },

    // clears the array of deleted records
    clearDeletedRecords: function() {
        this.m_deleted = [];
    },

    // stores the page size
    setInitialPageSize: function(initialPageSize) {
        this.m_initialPageSize = initialPageSize;
    },

    // gets the page size
    getInitialPageSize: function() {
        return this.m_initialPageSize;
    }
});
