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@1130: click: me.activateDraw 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@1329: select: me.selectPanel raimund@1130: }, mkrambach@1315: 'ortszuordnungwindow ortstammdatengrid': { mkrambach@1315: edit: me.gridSave, mkrambach@1315: canceledit: me.cancelEdit, raimund@1329: select: me.selectWindow raimund@1049: } raimund@1049: }); raimund@1049: }, raimund@1049: raimund@1130: activateDraw: function(button) { raimund@1130: var map = button.up('ortpanel').down('map'); raimund@1130: var record = Ext.create('Lada.model.Ort'); raimund@1130: map.activateDraw(record); raimund@1049: }, raimund@1049: raimund@1049: addRecord: function(button) { mkrambach@1361: Ext.create('Lada.view.window.Ortserstellung',{ mkrambach@1361: record: Ext.create('Lada.model.Ort', {ortTyp: 1}), mkrambach@1361: parentWindow: button.up('ortpanel') mkrambach@1361: }).show(); raimund@1130: var grid = button.up('ortpanel').down('ortstammdatengrid'); mkrambach@1361: // if (grid.getCollapsed()) { mkrambach@1361: // grid.expand(); mkrambach@1361: // } raimund@1049: }, raimund@1049: raimund@1049: deleteItem: function(button) { raimund@1130: var grid = button.up('ortpanel').down('ortstammdatengrid'); raimund@1130: var selection = grid.getView().getSelectionModel().getSelection()[0]; raimund@1130: var i18n = Lada.getApplication().bundle; raimund@1130: Ext.MessageBox.confirm(i18n.getMsg('delete'), raimund@1130: i18n.getMsg('confirmation.question'), raimund@1130: function(btn) { raimund@1130: if (btn === 'yes') { raimund@1130: selection.destroy({ raimund@1130: success: function() { raimund@1130: //DO NOTHING raimund@1130: }, raimund@1130: failure: function(request, response) { raimund@1130: var json = response.request.scope.reader.jsonData; raimund@1130: if (json) { raimund@1130: if (json.message){ raimund@1130: Ext.Msg.alert(i18n.getMsg('err.msg.delete.title') raimund@1130: +' #'+json.message, raimund@1130: i18n.getMsg(json.message)); raimund@1130: } else { raimund@1130: Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'), raimund@1130: i18n.getMsg('err.msg.generic.body')); raimund@1130: } raimund@1130: } else { raimund@1130: Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'), raimund@1130: i18n.getMsg('err.msg.response.body')); raimund@1130: } raimund@1130: } raimund@1130: }); raimund@1130: } raimund@1130: }); raimund@1130: grid.up('ortpanel').down('button[action=delete]').disable(); raimund@1130: }, raimund@1130: raimund@1329: selectPanel: function(rowModel, record) { raimund@1329: this.checkEditPanel(rowModel, record); raimund@1130: this.buttonToggle(rowModel, record); raimund@1130: }, raimund@1130: raimund@1329: selectWindow: function(rowModel, record) { raimund@1329: this.checkEditWindow(rowModel, record); raimund@1329: this.buttonToggle(rowModel, record); raimund@1329: }, raimund@1329: raimund@1329: checkEditWindow: function(rowModel, record) { raimund@1329: if (!Ext.Array.contains(Lada.netzbetreiber, raimund@1329: record.get('netzbetreiberId')) && raimund@1329: record.get('netzbetreiberId') !== '') { raimund@1329: var grid = Ext.ComponentQuery.query('ortszuordnungwindow ortstammdatengrid')[0]; raimund@1329: grid.rowEditing.cancelEdit(); raimund@1329: return; raimund@1329: } raimund@1329: }, raimund@1329: raimund@1329: checkEditPanel: function(rowModel, record) { raimund@1130: if (!Ext.Array.contains(Lada.netzbetreiber, raimund@1130: record.get('netzbetreiberId')) && raimund@1130: record.get('netzbetreiberId') !== '') { raimund@1130: var grid = Ext.ComponentQuery.query('ortpanel ortstammdatengrid')[0]; raimund@1130: grid.rowEditing.cancelEdit(); raimund@1130: return; raimund@1130: } 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@1130: var grid = Ext.ComponentQuery.query('ortstammdatengrid')[0]; raimund@1130: grid.store.reload(); raimund@1145: Ext.StoreManager.get('orte').load(); 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: /** raimund@1049: * Enables/Disables a set of buttons raimund@1049: **/ raimund@1130: buttonToggle: function(rowModel, record) { raimund@1130: if (!Ext.Array.contains(Lada.funktionen, 4)) { raimund@1130: return; raimund@1130: } raimund@1130: var grid = Ext.ComponentQuery.query('ortstammdatengrid')[0]; raimund@1366: if (!grid.up('ortpanel')) { raimund@1366: return; raimund@1366: } raimund@1130: if (!record || raimund@1130: !Ext.Array.contains(Lada.netzbetreiber, raimund@1130: record.get('netzbetreiberId'))) { raimund@1130: grid.up('ortpanel').down('button[action=delete]').disable(); raimund@1130: return; raimund@1130: } raimund@1130: if (record.get('readonly') || raimund@1130: rowModel.selected.items.length === 0) { raimund@1130: grid.up('ortpanel').down('button[action=delete]').disable(); raimund@1130: } raimund@1130: else { raimund@1130: if (grid.getPlugin('rowedit').editing) { raimund@1130: //only enable buttons, when grid is not beeing edited raimund@1130: grid.up('ortpanel').down('button[action=delete]').disable(); raimund@1130: } raimund@1130: else { raimund@1130: grid.up('ortpanel').down('button[action=delete]').enable(); raimund@1130: } raimund@1130: } raimund@1130: /* raimund@1050: if (!enabled && raimund@1050: panel.down('button[action=delete]')) { raimund@1049: panel.down('button[action=delete]').disable(); raimund@1049: } raimund@1049: else { raimund@1050: if (panel.down('ortstammdatengrid').getPlugin('rowedit') && raimund@1050: !panel.down('ortstammdatengrid').getPlugin('rowedit').editing && raimund@1050: panel.down('button[action=delete]')) { 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@1051: else if (panel.down('button[action=delete]')) { raimund@1050: panel.down('button[action=delete]').disable(); raimund@1049: } raimund@1049: } raimund@1130: */ raimund@1049: } raimund@1049: });