From: <ga...@us...> - 2009-05-30 22:02:13
|
Revision: 3886 http://jaffa.svn.sourceforge.net/jaffa/?rev=3886&view=rev Author: gautamj Date: 2009-05-30 22:02:00 +0000 (Sat, 30 May 2009) Log Message: ----------- Refactored Jaffa.maintenance.FormPanel to utilize the all new PanelLoadSave plugin Modified Paths: -------------- trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/Maintenance.js trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js Modified: trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/Maintenance.js =================================================================== --- trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/Maintenance.js 2009-05-30 21:06:42 UTC (rev 3885) +++ trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/Maintenance.js 2009-05-30 22:02:00 UTC (rev 3886) @@ -251,137 +251,9 @@ * By default this panel will get a "save" option in the toolbar, which will be tied to * the controllers "save" process. */ -Jaffa.maintenance.FormPanel = Ext.extend(Jaffa.maintenance.Panel, { - /** - * @cfg {boolean} isNew - * This indicates if the Panel is being used to create a record. - */ - isNew: false - - ,readOnly: false - ,autoScroll: true - ,defaultType: 'textfield' - ,layout: 'formdescription' - - - ,constructor: function (config) { - Jaffa.maintenance.FormPanel.superclass.constructor.call(this, config); - } - - /** - * A general load method that is automatically wired in to the controller's - * onload event as part of the panels registration. This method generally will - * use the panel's {@link #findDataSource} method to figure out what data to - * load into the panel. For this to work the "mapping" properties on the widgets - * in the panel should be based on the object returned as the data source. - * <p> - * By default this method will make "textOnly" any field on this panel that is specified - * as a "key" field in its class metadata definition. - */ - ,load: function(){ - this.controller.clearPanelFields(this); - - if (this.isDirty) - this.onSaveSuccess(); - - var ds = this.findDataSource(); - if (ds) - this.controller.setPanelFields(this, ds); - - // Disable primary key fields for existing records - if (ClassMetaData[this.metaClass] && ClassMetaData[this.metaClass].key && typeof ClassMetaData[this.metaClass].key === 'string') { - //var keyField = this.findByMapping(ClassMetaData[this.metaClass].key); - var keyField = this.find("mapping", ClassMetaData[this.metaClass].key); - if (keyField && keyField.length == 1) - keyField[0].setTextOnly(true); - } - - // reset the isNew flag to support subsequent saves after a creation of a new record - this.isNew = false; - } - - /** - * 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 {Object} Returns first entry in array of objects in the associated controller's model - */ - ,findDataSource: function () { - var output = this.controller.isLoaded && this.controller.model ? this.controller.model.itemAt(0) : null; - if (!output) { - output = new Ext.util.MixedCollection(); - this.controller.model = output; - this.isNew = true; - } - return output; - } - - /** - * A general validation method that is invoked to see if this panel's - * data can be saved without errors. This is invoked because (a) a save - * has been invoked on the controller related to this panel, and (b) because - * this panel when created registered its self with the controller - * - * @return {String} Returns a null string if all vaildation pass, or - * a HTML string containing the errors to be displayed * - * @DEPRECATES tabValidate - */ - ,validateData: function() { - return this.controller.validatePanelFields(this); - } - - /** - * This packages up the data to saved from this panel, the original data object is provided - * so a delta between it and the panel's values so only changed values need to be saved. - * - * If the 'isDelete' flag is set to true on the panel, the object will be marked for deletion - * - * - * @param {Object} origData This is the original graph data object this panel is changing - * @param {Object} saveData This object should be modifed by this function to contain a copy of - * the origData including all the changes made to the panel. - * It is recommended that you only include the fields that have changed, - * assuming your back end service can support this. - * @return {boolean} Return true if there is a change in the data, ie something needs - * to be saved - * - * @DEPRECATES tabSave - */ - ,saveData: function(origData, saveData) { - // Propagate the isDelete flag so the source object will be deleted - if (this.isDelete) { - saveData.deleteObject = true; - this.isDelete = false; - return true; - } - return this.controller.getModifiedPanelFields(this, saveData, origData); - } - - /** - * (Optional) Implement if data added to this panel should be saved. - * - * This packages up the data to saved from this panel, the original data object is provided - * so a delta between it and the panel's values so only changed values need to be saved. - * - * If this Panel contains new data, the Panel is registered with a Collection, as opposed - * to the instance being modified. Therefore the difference between the data passed here, compared - * to the saveData() method, is that the origData is the array of these kinds of records, and - * saveData is also the array of records to save. - * - * @param {Object} origData This is the original array of graph data objects. - * @param {Object} saveData This array should have the new object appended to it. - */ - ,createData: function (origData, saveData) { - var child, exists = false; - // @TODO: Lookup existing object in saveData. Reuse, if present - if (!exists) - child = {}; - var updated = this.saveData(null, child); - if (updated && !exists) - saveData[saveData.length] = child; - return updated; - } +Jaffa.maintenance.FormPanel = Ext.extend(Ext.Panel, { + defaultType: 'textfield', + plugins: [new Jaffa.maintenance.plugins.PanelLoadSave()] }); Modified: trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js =================================================================== --- trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js 2009-05-30 21:06:42 UTC (rev 3885) +++ trunk/JaffaRIA/source/html/js/extjs/jaffa/maintenance/plugins/PanelLoadSave.js 2009-05-30 22:02:00 UTC (rev 3886) @@ -37,14 +37,16 @@ //determine metaClass if (!c.metaClass) c.metaClass = this.metaClass - if (!c.metaClass) - c.metaClass = Jaffa.component.Controller.lookupMetaClass(c); //lookup the metaClass from the component or its parent + //@FIXME: Uncomment the following after the lookupMetaClass() function has been implemented + //if (!c.metaClass) + // c.metaClass = Jaffa.component.Controller.lookupMetaClass(c); //lookup the metaClass from the component or its parent //determine controller if (!c.controller && this.controller) c.controller = typeof this.controller == "string" ? Jaffa.component.Controller.getController(this.controller) : this.controller; - if (!c.controller) - c.controller = Jaffa.component.Controller.lookupController(c); //lookup the controller from the component or its parent + //@FIXME: Uncomment the following after the lookupController() function has been implemented + //if (!c.controller) + // c.controller = Jaffa.component.Controller.lookupController(c); //lookup the controller from the component or its parent if (c.controller) c.controller.registerPanel(c, c.findDataSource()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |