raimund@1049: /** raimund@1049: * raimund@1049: */ raimund@1049: Ext.define('Lada.controller.Ort', { raimund@1049: extend: 'Ext.app.Controller', raimund@1049: raimund@1049: /** raimund@1049: * @private raimund@1049: * Initialize the controller. raimund@1049: */ raimund@1049: init: function() { raimund@1049: var me = this; raimund@1049: this.control({ raimund@1049: 'ortpanel button[action=addMap]': { raimund@1049: click: me.addFeature raimund@1049: }, raimund@1049: 'ortpanel button[action=add]': { raimund@1049: click: me.addRecord raimund@1049: }, raimund@1049: 'ortpanel button[action=delete]': { raimund@1049: click: me.deleteItem raimund@1049: }, raimund@1049: 'ortpanel ortstammdatengrid': { raimund@1049: edit: me.gridSave, raimund@1049: canceledit: me.cancelEdit, raimund@1049: select: me.activateButtons, raimund@1049: deselect: me.deactivateButtons raimund@1049: } raimund@1049: }); raimund@1049: }, raimund@1049: raimund@1049: addFeature: function(button) { raimund@1049: console.log('add feature'); raimund@1049: }, raimund@1049: raimund@1049: addRecord: function(button) { raimund@1049: console.log('add record'); raimund@1049: }, raimund@1049: raimund@1049: deleteItem: function(button) { raimund@1049: console.log('delete item'); raimund@1049: }, raimund@1049: raimund@1049: /** raimund@1049: * This function is called when the grids roweditor saves raimund@1049: * the record. raimund@1049: * On success it refreshes the windows which contains the grid raimund@1049: * On failure it displays a message raimund@1049: */ raimund@1049: gridSave: function(editor, context) { raimund@1049: var i18n = Lada.getApplication().bundle; raimund@1049: context.record.save({ raimund@1049: success: function(record, response) { raimund@1049: //Do Nothing raimund@1049: }, raimund@1049: failure: function(record, response) { raimund@1049: var json = response.request.scope.reader.jsonData; raimund@1049: if (json) { raimund@1049: if (json.message){ raimund@1049: Ext.Msg.alert(i18n.getMsg('err.msg.save.title') raimund@1049: +' #'+json.message, raimund@1049: i18n.getMsg(json.message)); raimund@1049: } else { raimund@1049: Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), raimund@1049: i18n.getMsg('err.msg.generic.body')); raimund@1049: } raimund@1049: } raimund@1049: } raimund@1049: }); raimund@1049: }, raimund@1049: raimund@1049: /** raimund@1049: * When the edit was canceled, raimund@1049: * the empty row might have been created by the roweditor is removed raimund@1049: */ raimund@1049: cancelEdit: function(editor, context) { raimund@1049: if (!context.record.get('id') || raimund@1049: context.record.get('id') === '') { raimund@1049: editor.getCmp().store.remove(context.record); raimund@1049: } raimund@1049: context.grid.getSelectionModel().deselect(context.record); raimund@1049: }, raimund@1049: /** raimund@1049: * Toggles the buttons in the toolbar raimund@1049: **/ raimund@1049: activateButtons: function(rowModel, record) { raimund@1049: var panel = rowModel.view.up('ortpanel'); raimund@1049: this.buttonToggle(true, panel); raimund@1049: }, raimund@1049: raimund@1049: /** raimund@1049: * Toggles the buttons in the toolbar raimund@1049: **/ raimund@1049: deactivateButtons: function(rowModel, record) { raimund@1049: var panel = rowModel.view.up('ortpanel'); raimund@1049: // Only disable buttons when nothing is selected raimund@1049: if (rowModel.selected.items == 0) { raimund@1049: this.buttonToggle(false, panel); raimund@1049: } raimund@1049: }, raimund@1049: raimund@1049: /** raimund@1049: * Enables/Disables a set of buttons raimund@1049: **/ raimund@1049: buttonToggle: function(enabled, panel) { raimund@1049: if (!enabled) { raimund@1049: panel.down('button[action=delete]').disable(); raimund@1049: } raimund@1049: else { raimund@1049: if (!panel.down('ortstammdatengrid').getPlugin('rowedit').editing) { raimund@1049: //only enable buttons, when grid is not beeing edited raimund@1049: panel.down('button[action=delete]').enable(); raimund@1049: } raimund@1049: //else turn them off again! raimund@1049: else { raimund@1049: this.buttonToggle(false, panel); raimund@1049: } raimund@1049: } raimund@1049: } raimund@1049: });