PDA

View Full Version : [ExtJS 3 to 4] store.rejectChanges() -> store.reject()



lorezyra
13 Dec 2011, 4:12 PM
I'm migrating my ExtJS 3 app to ExtJS 4 (and refactoring with MVC pattern). This is a "2-page" application that has a login and the main app. I've completed the login "app" and it works great. However, my trouble starts in the implementation of my multi-controller based app. I'm designing this app to use a separate controller per feature (as opposed to one per view).


Previously in ExtJS3, to reject changes made to a store since the last commit/load, you would call upon the store's rejectChanges() method. Looking through the API, it seems this function no longer exists (in Ext.data.Store). Instead, it's now apart of Ext.data.Model as the method reject().


UserViewPanelGrpForgetOnClick: function () {
Ext.StoreMgr.lookup("blogGroup").reject();
},



I modified a record in my store and attempted to revert the changes. However, FireBug spits out the following error (for the above code):

TypeError: Ext.StoreMgr.lookup("blogGroup").reject is not a function

Could anyone suggest the best way to reject changes to a store/grid?

lorezyra
13 Dec 2011, 5:26 PM
Attempts to directly call the function fail without error:

RichieBartlett.model.blogGroup.prototype.reject();

lorezyra
13 Dec 2011, 6:04 PM
Ahhh! Found the problem... Sencha forgot to include this functionality along with commitChanges() and getModifiedRecords()...


Here's the post where I found this bit of info:
http://www.sencha.com/forum/showthread.php?136871

So, until Ext 4.1 is officially released, I have pieced the following override to include the missing functions:


var xVer= new Ext.Version(Ext.getVersion().version);
if (xVer.isLessThan('4.1')) { //only overRide if ExtJs.version < 4.1
if (Ext.isGecko) { console.warn('Patching ExtJS 4.x Ext.data.Store...'); }
Ext.override(Ext.data.Store, {
rejectChanges: function() {
var me = this,
recs = me.getModifiedRecords(),
len = recs.length,
i = 0;

for (; i < len; i++) {
recs[i].reject();
if (recs[i].phantom) {
me.remove(recs[i]);
}
}

recs = me.removed;
len = recs.length;

for (i = 0; i < len; i++) {
me.insert(recs[i].lastIndex || 0, recs[i]);
recs[i].reject();
// lastIndex will get re-added if this rec gets removed again later
delete recs[i].lastIndex;
}

// Since removals are cached in a simple array we can simply reset it here.
// Adds and updates are managed in the data MixedCollection and should already be current.
me.removed.length = 0;
},
getModifiedRecords : function(){
return [].concat(this.getNewRecords(), this.getUpdatedRecords());
},
commitChanges: function() {// this is a depreciated function! use store.sync() instead!
Ext.each(this.getUpdatedRecords(), function(rec) {
rec.commit();
});

Ext.each(this.getNewRecords(), function(rec) {
rec.commit();
rec.phantom = false;
});

this.removed = [];
}
});
}//end if xVer
delete xVer; //don't need this var after processing



Now, I can call the rejectChanges() method of the store...

UserViewPanelUsrRejectOnClick: function () {
Ext.StoreMgr.lookup("blogUser").rejectChanges();
},