From: <Se...@us...> - 2009-09-25 20:26:08
|
Revision: 4112 http://jaffa.svn.sourceforge.net/jaffa/?rev=4112&view=rev Author: SeanZ Date: 2009-09-25 20:25:54 +0000 (Fri, 25 Sep 2009) Log Message: ----------- implemented binding mechanisms to allow saving from multiple panels to the same graph objects. 1 - register the new graph object to originalGraphObject.registeredPanels.graphInSaveModel 2 - run a binding at array to match the new and original graph object by key/createKey Modified Paths: -------------- trunk/JaffaRIA/source/html/js/extjs/jaffa/component/Component.js Modified: trunk/JaffaRIA/source/html/js/extjs/jaffa/component/Component.js =================================================================== --- trunk/JaffaRIA/source/html/js/extjs/jaffa/component/Component.js 2009-09-25 18:24:01 UTC (rev 4111) +++ trunk/JaffaRIA/source/html/js/extjs/jaffa/component/Component.js 2009-09-25 20:25:54 UTC (rev 4112) @@ -1467,6 +1467,21 @@ * perform mandatory checks and other meta rules, then build up a * "changes only" version of the Graph model, and use the supplied * proxy to save this back to the web server. + * + * @important saveData(originalSubGraph_Array, newSubGraph_Array) on panels are called to perform the save action. + * When sub graphs to the input graph are created in newSubGraph_Array, it should be registered in the corresponding originalSubGraph_Array. + * + * <pre><code> + * var obj = Ext.ux.clone(originalSubGraph_Array.maintenance[3]); + * if (originalSubGraph_Array.maintenance[3].registeredPanels && + * originalSubGraph_Array.maintenance[3].registeredPanels.graphInSaveModel) { + * obj = originalSubGraph_Array.maintenance[3].registeredPanels.graphInSaveModel; + * } + * // --------- performing updates on obj ----------- + * newSubGraph_Array.maintenance[1] = obj; + * if (originalSubGraph_Array.maintenance[3].registeredPanels) + * originalSubGraph_Array.maintenance[3].registeredPanels.graphInSaveModel = obj; + * </code></pre> * * @param {function} callbackOk Method to invoke if the save was sucessful * @param {function} callbackError Method to invoke if the save failed @@ -1841,7 +1856,7 @@ * This first goes through the registed panels invoking the 'tabSave()' method incase * the panel needs to do some local changes to the model prior to cloning. * - * The tabSave() is called with parameters 'originalObject' and 'newObject', and it is + * The saveData() is called with parameters 'originalObject' and 'newObject', and it is * assumed that the fields modified in the panel and set on the 'newObject'. This is typically * done on a panel using the {#link getModifiedPanelFields(panel, newData, oldData)} * @@ -1849,13 +1864,10 @@ * * @DEPRECATES Jaffa.DWRService.clone */ - ,_extractChangedData: function(myObj, validationFailed){ + ,_extractChangedData: function(myObj){ if (myObj == null) return null; - - var objectClone = new myObj.constructor(); - objectClone.isChanged = false; - + if (myObj.isNew) { if (myObj.registeredPanels && myObj.registeredPanels.getCount() == 0) { // when registeredPanels is on a new graph object, this new graph is created on the orignal graph. @@ -1863,9 +1875,19 @@ // be deleted. return null; } + } + + var objectClone; + if (myObj.registeredPanels && myObj.registeredPanels.graphInSaveModel) { + objectClone = myObj.registeredPanels.graphInSaveModel; + } else if (myObj.isNew){ objectClone = this._extractAllData(myObj); objectClone.isChanged = true; + } else { + objectClone = new myObj.constructor(); + objectClone.isChanged = false; } + if (myObj.registeredPanels) myObj.registeredPanels.graphInSaveModel = objectClone; // Loop through objects registeredPanels and save changed values from the panel if (myObj.registeredPanels && myObj.registeredPanels.getCount() > 0) @@ -1891,6 +1913,7 @@ if (typeof myObj == 'object' && myObj.length && myObj.length > 0) for (var i = 0; i < myObj.length; i++) { // @TODO: Lookup existing object in objectClone, based on key/createKey and pass it, if found + this._bindTargetGraph(myObj[i], objectClone); var oc = this._extractChangedData(myObj[i]); if (oc) { objectClone.push(oc); @@ -1948,8 +1971,42 @@ } /** + * Lookup existing object in the new object array, based on key/createKey and bind it to the + * corresponding original object. + * This becomes neccesary when the application developer forgot to make the binding in saveData() + * on their panel. + * * @private * + * @param {Object} origObj + * @param {Object} newObjArray + */ + ,_bindTargetGraph: function(origObj, newObjArray) { + if (!origObj.registeredPanels ||origObj.registeredPanels.graphInSaveModel) return; + if (!ClassMetaData[origObj.className]) return; + var key = ClassMetaData[origObj.className].key; + if (!key) return; + var altKey = ClassMetaData[origObj.className].createKey; + if (origObj[key]) { + for (var i=0; i<newObjArray.length; i++) { + if (origObj[key] == newObjArray[i][key]) { + origObj.registeredPanels.graphInSaveModel = newObjArray[i]; + break; + } + } + } else if (origObj[altKey]) { + for (var i=0; i<newObjArray.length; i++) { + if (origObj[altKey] == newObjArray[i][altKey]) { + origObj.registeredPanels.graphInSaveModel = newObjArray[i]; + break; + } + } + } + } + + /** + * @private + * * Full clone of a graph object (excluding any 'registeredPanels' property) * This is a deep copy at it will recurse if there are nested objects * @@ -1983,6 +2040,8 @@ } } } + if (myObj.registeredPanels) myObj.registeredPanels.graphInSaveModel = objectClone; + return objectClone; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |