raimund@603: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@603: * Software engineering by Intevation GmbH raimund@603: * raimund@603: * This file is Free Software under the GNU GPL (v>=3) raimund@603: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@603: * the documentation coming with IMIS-Labordaten-Application for details. raimund@603: */ raimund@603: dustin@742: /* dustin@1013: * This is a controller for an Ortszuordnung Form dustin@742: */ dustin@1013: Ext.define('Lada.controller.form.Ortszuordnung', { raimund@603: extend: 'Ext.app.Controller', raimund@603: dustin@742: /** dustin@742: * Initialize the Controller with 4 listeners dustin@742: */ raimund@603: init: function() { raimund@603: this.control({ dustin@1013: 'ortszuordnungform button[action=save]': { raimund@603: click: this.save raimund@603: }, dustin@1013: 'ortszuordnungform button[action=discard]': { raimund@603: click: this.discard raimund@603: }, dustin@1013: 'ortszuordnungform': { raimund@603: dirtychange: this.dirtyForm raimund@603: }, dustin@1013: 'ortszuordnungform combobox[name=ort]': { raimund@603: select: this.updateDetails raimund@603: } raimund@603: }); raimund@603: }, raimund@603: dustin@742: /** dustin@972: * The save function saves the content of the Ort form. dustin@742: * On success it will reload the Store, dustin@742: * on failure, it will display an Errormessage dustin@742: */ dustin@742: save: function(button) { dustin@1013: var formPanel = button.up('ortszuordnungform'); raimund@603: var data = formPanel.getForm().getFieldValues(true); dustin@1013: var i18n = Lada.getApplication().bundle; raimund@603: for (var key in data) { raimund@603: formPanel.getForm().getRecord().set(key, data[key]); raimund@603: } dustin@972: if (!formPanel.getForm().getRecord().get('letzteAenderung')) { dustin@972: formPanel.getForm().getRecord().data.letzteAenderung = new Date(); dustin@972: } raimund@603: formPanel.getForm().getRecord().save({ raimund@603: success: function(record, response) { raimund@603: var json = Ext.decode(response.response.responseText); raimund@641: if (json) { raimund@603: button.setDisabled(true); raimund@603: button.up('toolbar').down('button[action=discard]') raimund@603: .setDisabled(true); raimund@603: formPanel.clearMessages(); raimund@603: formPanel.setRecord(record); raimund@603: formPanel.setMessages(json.errors, json.warnings); raimund@644: formPanel.up('window').grid.store.reload(); dustin@1013: debugger; raimund@603: } raimund@603: }, raimund@603: failure: function(record, response) { raimund@603: button.setDisabled(true); raimund@603: button.up('toolbar').down('button[action=discard]') raimund@603: .setDisabled(true); raimund@603: formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); raimund@603: var json = response.request.scope.reader.jsonData; raimund@603: if (json) { dustin@695: if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ dustin@695: formPanel.setMessages(json.errors, json.warnings); dustin@695: } dustin@695: dustin@695: if(json.message){ dustin@1013: Ext.Msg.alert(i18n.getMsg('err.msg.save.title') dustin@701: +' #'+json.message, dustin@1013: i18n.getMsg(json.message)); dustin@701: } else { dustin@1013: Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), dustin@1013: i18n.getMsg('err.msg.generic.body')); dustin@695: } dustin@701: } else { dustin@1013: Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), dustin@1013: i18n.getMsg('err.msg.response.body')); raimund@603: } raimund@603: } raimund@603: }); raimund@603: }, raimund@603: dustin@1013: /** dustin@1013: * The discard function resets the Location form dustin@1013: * to its original state. dustin@1013: */ dustin@1013: discard: function(button) { raimund@603: var formPanel = button.up('form'); raimund@603: formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); raimund@603: }, raimund@603: dustin@1013: /** dustin@1013: * The dirtyForm function enables or disables the save and discard dustin@1013: * button which are present in the toolbar of the form. dustin@1013: * The Buttons are only active if the content of the form was altered dustin@1013: * (the form is dirty). dustin@1013: */ raimund@603: dirtyForm: function(form, dirty) { raimund@603: if (dirty) { raimund@603: form.owner.down('button[action=save]').setDisabled(false); raimund@603: form.owner.down('button[action=discard]').setDisabled(false); raimund@603: } raimund@603: else { raimund@603: form.owner.down('button[action=save]').setDisabled(true); raimund@603: form.owner.down('button[action=discard]').setDisabled(true); raimund@603: } raimund@603: } raimund@603: });