From: <Se...@us...> - 2009-09-25 20:29:27
|
Revision: 4114 http://jaffa.svn.sourceforge.net/jaffa/?rev=4114&view=rev Author: SeanZ Date: 2009-09-25 20:29:21 +0000 (Fri, 25 Sep 2009) Log Message: ----------- added StoreLoadSave plugin for non-grid panels that have a store, such as a store backed tree panel. Modified Paths: -------------- trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js Modified: trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js =================================================================== --- trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js 2009-09-25 20:27:33 UTC (rev 4113) +++ trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js 2009-09-25 20:29:21 UTC (rev 4114) @@ -485,7 +485,103 @@ } }); +Jaffa.maintenance.plugins.StoreLoadSave = Ext.extend(Jaffa.maintenance.plugins.PanelLoadSave, { + beforerenderHandler: function (c) { + Jaffa.maintenance.plugins.StoreLoadSave.superclass.beforerenderHandler.apply(this, arguments); + + // NOTE: The following code is similar to the one in Jaffa.maintenance.Viewport.addTabPanel() method + var dataSource = c.findDataSource(); + + // Propagate the metadata class name from the data to the component if available + if (dataSource && !c.metaClass) { + if (Ext.isArray(dataSource)) { + if (dataSource[0]) + c.metaClass = dataSource[0].className; + } else if (dataSource.itemAt && typeof dataSource.itemAt === 'function') { + if (dataSource.itemAt(0)) + c.metaClass = dataSource.itemAt(0).className; + } else { + c.metaClass = dataSource.className; + } + } + + if (c.controller) { + // invoke the load event if the controller already had data, else initialize the fields of the panel + if (c.controller.isLoaded) + c.loadData(); + else + c.controller.setPanelFields(c); + } + + // Disable primary key fields for existing records + if (c.metaClass && ClassMetaData[c.metaClass] && ClassMetaData[c.metaClass].key && typeof ClassMetaData[c.metaClass].key === 'string') { + c.on('beforeedit', function (e) { + if (!e.record.isNew && e.field === ClassMetaData[this.metaClass].key) + return false; + }, c); + } + }, + doLoadData: function() { + if (this.isDirty) + this.onSaveSuccess(); + + this.getStore().removeAll(); + var ds = this.findDataSource(); + if (ds) { + if (Ext.isArray(ds)) { + // handling the circumstance that the array of graphs are not converted to mixed collections + console.debug('Loading store ', ds); + this.getStore().loadData(ds); + console.debug('Store is ', this.getStore()); + } else { + console.debug('Loading store ', ds.getRange()); + this.getStore().loadData(ds.getRange()); + console.debug('Store is ', this.getStore()); + } + } + }, + + saveData: function(origData, saveData) { + var output = this.controller.getModifiedPanelStore(origData, saveData, this.getStore(), this.metaClass); + console.debug("Store.saveData: ", origData, saveData, this.metaClass, output); + return output; + }, + + /** + * This method is used to locate the data source associated to this panel by + * the {@link #load} method. On reload of a previously registered panel this method + * is also used by the controller to register this panel with it's data source. + * + * @return {Ext.util.MixedCollection} Returns first entry in array of objects in the associated controller's model + */ + findDataSource: function(){ + return this.controller.model; + }, + + /** + * A convenience method to add the input record to the grid. + * @param {Jaffa.data.Record} record A record. + */ + addRecord: function (record) { + record.isNew = true; + this.getStore().add(record); + }, + + /** + * A convenience method to remove the input record from the grid. + * If the input record already exists in the model, then that corresponding object will be marked for deletion. + * @param {Jaffa.data.Record} record A record. + */ + removeRecord: function (record) { + if (!record.isNew) { + var keyValue = record.get(ClassMetaData[this.metaClass].key); + this.findDataSource().get(keyValue).deleteObject = true; + } + this.getStore().remove(record); + } +}); + /** * @class Jaffa.maintenance.plugins.GridLoadSave * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |