From: <ga...@us...> - 2010-08-23 21:11:04
|
Revision: 4698 http://jaffa.svn.sourceforge.net/jaffa/?rev=4698&view=rev Author: gautamj Date: 2010-08-23 21:10:58 +0000 (Mon, 23 Aug 2010) Log Message: ----------- initial commit Modified Paths: -------------- trunk/JaffaRIA/source/html/js/extjs/jaffa/attachment/Container.js Modified: trunk/JaffaRIA/source/html/js/extjs/jaffa/attachment/Container.js =================================================================== --- trunk/JaffaRIA/source/html/js/extjs/jaffa/attachment/Container.js 2010-08-21 02:10:28 UTC (rev 4697) +++ trunk/JaffaRIA/source/html/js/extjs/jaffa/attachment/Container.js 2010-08-23 21:10:58 UTC (rev 4698) @@ -322,9 +322,10 @@ query: Jaffa_Attachment_AttachmentService.query, update: Jaffa_Attachment_AttachmentService.update }), - reader: new Ext.data.DwrReader({id: 'attachmentId'}, Jaffa.attachment.Record), + reader: new Jaffa.data.DWRQueryResponseReader({id: 'attachmentId'}), listeners: { beforepostdata: function (controller) { + // This listener is called before data is posted. //CREATE mode: Set default data for the non-rendered fields in CREATE mode var graph = controller.saveModel && controller.saveModel.length == 1 ? controller.saveModel[0] : null; if (graph) { @@ -334,13 +335,47 @@ } } }, + save: function (controller, response) { + // In CREATE mode, the response will contain the generated attachmentId. + // Maintain a reference to it, so that it can be reloaded. + if (response && response.length == 1 && response[0].source) + this.attachmentId = response[0].source.attachmentId; + }, beforeload: function (controller) { - // the load is called immediately after a save. - // create a criteria to retrieve the most recently updated Attachment. - // @todo: for better accuracy, use the attachmentId - controller.criteria = {serializedKey: {values: [this.serializedKey]}, resultGraphRules: ['-data', '*'], objectLimit: 1, findTotalRecords: false, orderByFields: [{fieldName: 'lastChangedOn', sortAscending: false}]}; + // This listener is called immediately after a save. Create a criteria to reload the attachment. + controller.criteria = {attachmentId: {values: [this.attachmentId]}, resultGraphRules: ['-data', '*']}; }, - //@todo: create a listener to grab the attachmentId after a CREATE + load: function (controller) { + // This listener is called after an attachment is loaded. + if (controller.model && controller.model.getCount() == 1) { + var graph = controller.model.itemAt(0); + if (graph.attachmentId) { + //UPDATE + this.attachmentId = graph.attachmentId; + this.setTitle('Modify'); + this.datesPanel.show(); + this.clearButton.hide(); + } else { + //CREATE + delete attachmentId; + this.setTitle('Add'); + this.datesPanel.hide(); + this.clearButton.show(); + } + this.originalFileName.label.dom.innerHTML = !graph.attachmentType || graph.attachmentType === 'W' ? 'Web Link' : 'File Name'; + this.setDisabled(false); + if (this.collapsed) + this.expand(); + } else { + //default + delete attachmentId; + this.setTitle(''); + this.datesPanel.hide(); + this.clearButton.show(); + this.originalFileName.label.dom.innerHTML = 'Web Link'; + this.setDisabled(true); + } + }, scope: this } }), @@ -389,12 +424,17 @@ icon: Ext.MessageBox.QUESTION, scope: this, fn: function (btn) { - if (btn == 'yes') - this.grid.getSelectionModel().clearSelections(); + if (btn == 'yes') { + this.unloadData(); + if (this.grid) + this.grid.getSelectionModel().clearSelections(); + } } }); } else - this.grid.getSelectionModel().clearSelections(); + this.unloadData(); + if (this.grid) + this.grid.getSelectionModel().clearSelections(); } }, { disabled: !security.hasAttachmentMaintenance, @@ -414,32 +454,16 @@ /** Loads the input Graph into this Panel. */ loadGraph: function (graph) { - this.clearButton.hide(); - this.originalFileName.label.dom.innerHTML = graph.attachmentType === 'W' ? 'Web Link' : 'File Name'; - this.datesPanel.show(); this.controller._onLoad({records: [graph]}); - this.setTitle('Modify'); - this.setDisabled(false); - if (this.collapsed) - this.expand(); }, /** Unloads data from this Panel. */ unloadData: function () { - this.clearButton.show(); - this.originalFileName.label.dom.innerHTML = 'Web Link'; - this.datesPanel.hide(); this.controller._onLoad(); - this.setTitle(''); - this.setDisabled(true); }, /** Prepares this panel to be in 'add' mode. */ activateAddMode: function () { - this.unloadData(); - this.setTitle('Add'); - this.setDisabled(false); - if (this.collapsed) - this.expand(); + this.controller._onLoad({records: [{className: 'AttachmentGraph'}]}); } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |