Mercurial > lada > lada-client
changeset 984:b21421ba6917 stammdatengrids
added buttons for datensatzerzeuger, pobenehmer, added controllers
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Thu, 10 Dec 2015 08:30:14 +0100 |
parents | 0a5fe163f1c8 |
children | f73ca04d73a7 |
files | app.js app/controller/grid/Datensatzerzeuger.js app/controller/grid/MessprogrammKategorie.js app/controller/grid/Probenehmer.js app/model/DatensatzErzeuger.js app/store/DatensatzErzeuger.js app/view/grid/DatensatzErzeuger.js app/view/grid/Probenehmer.js resources/i18n/Lada_de-DE.properties |
diffstat | 9 files changed, 560 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/app.js Tue Dec 08 15:59:00 2015 +0100 +++ b/app.js Thu Dec 10 08:30:14 2015 +0100 @@ -204,6 +204,8 @@ 'Lada.controller.ModeSwitcher', 'Lada.controller.grid.ProbeList', 'Lada.controller.grid.MessprogrammeList', + 'Lada.controller.grid.Datensatzerzeuger', + 'Lada.controller.grid.Probenehmer', 'Lada.controller.form.Probe', 'Lada.controller.form.Messung', 'Lada.controller.form.Ort',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controller/grid/Datensatzerzeuger.js Thu Dec 10 08:30:14 2015 +0100 @@ -0,0 +1,160 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * This is a controller for a grid of Datensatzerzeuger Stammdaten + */ +Ext.define('Lada.controller.grid.Datensatzerzeuger', { + extend: 'Ext.app.Controller', + + /** + * Inhitialize the controller + * It has 3 listeners + */ + init: function() { + this.control({ + 'datensatzerzeugergrid': { + edit: this.gridSave, + canceledit: this.cancelEdit, + select: this.activateButtons, + deselect: this.deactivateButtons + }, + 'datensatzerzeugergrid button[action=add]': { + click: this.add + }, + 'datensatzerzeugergrid button[action=delete]': { + click: this.remove + } + }); + }, + + /** + * This function is called when the grids roweditor saves + * the record. + * On success it refreshes the windows which contains the grid + * On failure it displays a message + */ + gridSave: function(editor, context) { + context.record.set('datum', new Date()); + context.record.save({ + success: function(record, response) { + //Do Nothing + }, + failure: function(record, response) { + var json = response.request.scope.reader.jsonData; + if (json) { + if (json.message){ + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') + +' #'+json.message, + Lada.getApplication().bundle.getMsg(json.message)); + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), + Lada.getApplication().bundle.getMsg('err.msg.generic.body')); + } + } + } + }); + }, + + /** + * When the edit was canceled, + * the empty row might have been created by the roweditor is removed + */ + cancelEdit: function(editor, context) { + if (!context.record.get('id') || + context.record.get('id') === '') { + editor.getCmp().store.remove(context.record); + } + context.grid.getSelectionModel().deselect(context.record); + }, + + /** + * This function adds a new row to add a Datensatzerzeuger + */ + add: function(button) { + var record = Ext.create('Lada.model.DatensatzErzeuger'); + button.up('datensatzerzeugergrid').store.insert(0, record); + button.up('datensatzerzeugergrid').rowEditing.startEdit(0, 1); + }, + + /** + * A record can be removed from the grid with the remove + * function. It asks the user for confirmation + * If the removal was confirmed, it reloads the parent window on success, + * on failure, an error message is shown. + */ + remove: function(button) { + var grid = button.up('grid'); + var selection = grid.getView().getSelectionModel().getSelection()[0]; + //TODO: i18n + Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { + if (btn === 'yes') { + selection.destroy({ + success: function() { + //DO NOTHING + }, + failure: function(request, response) { + var json = response.request.scope.reader.jsonData; + if (json) { + if (json.message){ + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') + +' #'+json.message, + Lada.getApplication().bundle.getMsg(json.message)); + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), + Lada.getApplication().bundle.getMsg('err.msg.generic.body')); + } + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), + Lada.getApplication().bundle.getMsg('err.msg.response.body')); + } + } + }); + } + }); + grid.down('button[action=delete]').disable(); + }, + /** + * Toggles the buttons in the toolbar + **/ + activateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + this.buttonToggle(true, grid); + }, + + /** + * Toggles the buttons in the toolbar + **/ + deactivateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + // Only disable buttons when nothing is selected + if (rowModel.selected.items == 0) { + this.buttonToggle(false, grid); + } + }, + + /** + * Enables/Disables a set of buttons + **/ + buttonToggle: function(enabled, grid) { + if (!enabled) { + grid.down('button[action=delete]').disable(); + } + else { + if (!grid.getPlugin('rowedit').editing) { + //only enable buttons, when grid is not beeing edited + grid.down('button[action=delete]').enable(); + } + //else turn them off again! + else { + this.buttonToggle(false, grid); + } + } + } +}); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controller/grid/MessprogrammKategorie.js Thu Dec 10 08:30:14 2015 +0100 @@ -0,0 +1,160 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * This is a controller for a grid of MessprogrammKategorie Stammdaten + */ +Ext.define('Lada.controller.grid.MessprogrammKategorie', { + extend: 'Ext.app.Controller', + + /** + * Inhitialize the controller + * It has 3 listeners + */ + init: function() { + this.control({ + 'messprogrammkategoriegrid': { + edit: this.gridSave, + canceledit: this.cancelEdit, + select: this.activateButtons, + deselect: this.deactivateButtons + }, + 'messprogrammkategoriegrid button[action=add]': { + click: this.add + }, + 'messprogrammkategoriegrid button[action=delete]': { + click: this.remove + } + }); + }, + + /** + * This function is called when the grids roweditor saves + * the record. + * On success it refreshes the windows which contains the grid + * On failure it displays a message + */ + gridSave: function(editor, context) { + context.record.save({ + success: function(record, response) { + //Do Nothing + }, + failure: function(record, response) { + var json = response.request.scope.reader.jsonData; + if (json) { + if (json.message){ + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') + +' #'+json.message, + Lada.getApplication().bundle.getMsg(json.message)); + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), + Lada.getApplication().bundle.getMsg('err.msg.generic.body')); + } + } + } + }); + }, + + /** + * When the edit was canceled, + * the empty row might have been created by the roweditor is removed + */ + cancelEdit: function(editor, context) { + if (!context.record.get('id') || + context.record.get('id') === '') { + editor.getCmp().store.remove(context.record); + } + context.grid.getSelectionModel().deselect(context.record); + }, + + /** + * This function adds a new row to add a probenehmer + */ + add: function(button) { + var record = Ext.create('Lada.model.MessprogrammKategorie'); + button.up('messprogrammkategoriegrid').store.insert(0, record); + button.up('probenehmergrid').rowEditing.startEdit(0, 1); + }, + + /** + * A record can be removed from the grid with the remove + * function. It asks the user for confirmation + * If the removal was confirmed, it reloads the parent window on success, + * on failure, an error message is shown. + */ + remove: function(button) { + var grid = button.up('grid'); + var selection = grid.getView().getSelectionModel().getSelection()[0]; + //TODO: i18n + Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { + if (btn === 'yes') { + selection.destroy({ + success: function() { + //DO NOTHING + }, + failure: function(request, response) { + var json = response.request.scope.reader.jsonData; + if (json) { + if (json.message){ + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') + +' #'+json.message, + Lada.getApplication().bundle.getMsg(json.message)); + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), + Lada.getApplication().bundle.getMsg('err.msg.generic.body')); + } + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), + Lada.getApplication().bundle.getMsg('err.msg.response.body')); + } + } + }); + } + }); + grid.down('button[action=delete]').disable(); + }, + /** + * Toggles the buttons in the toolbar + **/ + activateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + this.buttonToggle(true, grid); + }, + + /** + * Toggles the buttons in the toolbar + **/ + deactivateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + // Only disable buttons when nothing is selected + if (rowModel.selected.items == 0) { + this.buttonToggle(false, grid); + } + }, + + /** + * Enables/Disables a set of buttons + **/ + buttonToggle: function(enabled, grid) { + if (!enabled) { + grid.down('button[action=delete]').disable(); + } + else { + if (!grid.getPlugin('rowedit').editing) { + //only enable buttons, when grid is not beeing edited + grid.down('button[action=delete]').enable(); + } + //else turn them off again! + else { + this.buttonToggle(false, grid); + } + } + }, +}); + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/controller/grid/Probenehmer.js Thu Dec 10 08:30:14 2015 +0100 @@ -0,0 +1,159 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ + +/** + * This is a controller for a grid of Probenehmer Stammdaten + */ +Ext.define('Lada.controller.grid.Probenehmer', { + extend: 'Ext.app.Controller', + + /** + * Inhitialize the controller + * It has 3 listeners + */ + init: function() { + this.control({ + 'probenehmergrid': { + edit: this.gridSave, + canceledit: this.cancelEdit, + select: this.activateButtons, + deselect: this.deactivateButtons + }, + 'probenehmergrid button[action=add]': { + click: this.add + }, + 'probenehmergrid button[action=delete]': { + click: this.remove + } + }); + }, + + /** + * This function is called when the grids roweditor saves + * the record. + * On success it refreshes the windows which contains the grid + * On failure it displays a message + */ + gridSave: function(editor, context) { + context.record.save({ + success: function(record, response) { + //Do Nothing + }, + failure: function(record, response) { + var json = response.request.scope.reader.jsonData; + if (json) { + if (json.message){ + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title') + +' #'+json.message, + Lada.getApplication().bundle.getMsg(json.message)); + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), + Lada.getApplication().bundle.getMsg('err.msg.generic.body')); + } + } + } + }); + }, + + /** + * When the edit was canceled, + * the empty row might have been created by the roweditor is removed + */ + cancelEdit: function(editor, context) { + if (!context.record.get('id') || + context.record.get('id') === '') { + editor.getCmp().store.remove(context.record); + } + context.grid.getSelectionModel().deselect(context.record); + }, + + /** + * This function adds a new row to add a probenehmer + */ + add: function(button) { + var record = Ext.create('Lada.model.Probenehmer'); + button.up('probenehmergrid').store.insert(0, record); + button.up('probenehmergrid').rowEditing.startEdit(0, 1); + }, + + /** + * A record can be removed from the grid with the remove + * function. It asks the user for confirmation + * If the removal was confirmed, it reloads the parent window on success, + * on failure, an error message is shown. + */ + remove: function(button) { + var grid = button.up('grid'); + var selection = grid.getView().getSelectionModel().getSelection()[0]; + //TODO: i18n + Ext.MessageBox.confirm('Löschen', 'Sind Sie sicher?', function(btn) { + if (btn === 'yes') { + selection.destroy({ + success: function() { + //DO NOTHING + }, + failure: function(request, response) { + var json = response.request.scope.reader.jsonData; + if (json) { + if (json.message){ + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title') + +' #'+json.message, + Lada.getApplication().bundle.getMsg(json.message)); + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), + Lada.getApplication().bundle.getMsg('err.msg.generic.body')); + } + } else { + Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.delete.title'), + Lada.getApplication().bundle.getMsg('err.msg.response.body')); + } + } + }); + } + }); + grid.down('button[action=delete]').disable(); + }, + /** + * Toggles the buttons in the toolbar + **/ + activateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + this.buttonToggle(true, grid); + }, + + /** + * Toggles the buttons in the toolbar + **/ + deactivateButtons: function(rowModel, record) { + var grid = rowModel.view.up('grid'); + // Only disable buttons when nothing is selected + if (rowModel.selected.items == 0) { + this.buttonToggle(false, grid); + } + }, + + /** + * Enables/Disables a set of buttons + **/ + buttonToggle: function(enabled, grid) { + if (!enabled) { + grid.down('button[action=delete]').disable(); + } + else { + if (!grid.getPlugin('rowedit').editing) { + //only enable buttons, when grid is not beeing edited + grid.down('button[action=delete]').enable(); + } + //else turn them off again! + else { + this.buttonToggle(false, grid); + } + } + }, +}); +
--- a/app/model/DatensatzErzeuger.js Tue Dec 08 15:59:00 2015 +0100 +++ b/app/model/DatensatzErzeuger.js Thu Dec 10 08:30:14 2015 +0100 @@ -52,8 +52,8 @@ idProperty: 'id', proxy: { - type: 'rest', - url: 'lada-server/datensatzerzeuger', + type: 'memory', + //url: 'lada-server/datensatzerzeuger', reader: { type: 'json', root: 'data'
--- a/app/store/DatensatzErzeuger.js Tue Dec 08 15:59:00 2015 +0100 +++ b/app/store/DatensatzErzeuger.js Thu Dec 10 08:30:14 2015 +0100 @@ -11,5 +11,15 @@ */ Ext.define('Lada.store.DatensatzErzeuger', { extend: 'Ext.data.Store', - model: 'Lada.model.DatensatzErzeuger' + model: 'Lada.model.DatensatzErzeuger', + data: { + data: { + id: 1, + netzbetreiberId: 'F', + daErzeugerId: 5, + mstId: '12020', + bezeichnung: 'ABCDÄ', + letzteAenderung: new Date() + } + } });
--- a/app/view/grid/DatensatzErzeuger.js Tue Dec 08 15:59:00 2015 +0100 +++ b/app/view/grid/DatensatzErzeuger.js Thu Dec 10 08:30:14 2015 +0100 @@ -46,6 +46,18 @@ xtype: 'tbtext', id: 'tbtitle', text: i18n.getMsg('de.gridTitle') + }, + '->', + { + text: i18n.getMsg('de.button.add'), + icon: 'resources/img/list-add.png', + action: 'add', + disabled: true // disabled on startup, will be enabled by setStore + }, { + text: i18n.getMsg('de.button.delete'), + icon: 'resources/img/list-remove.png', + action: 'delete', + disabled: true // disabled on startup, will be enabled by controller if necessary }] }]; @@ -81,6 +93,7 @@ header: i18n.getMsg('bezeichnung'), dataIndex: 'bezeichnung', editor: { + allowBlank: false, xtype: 'textfield' } }, { @@ -100,7 +113,7 @@ }, editor: { xtype: 'combobox', - store: Ext.data.StoreManager.get('messstellenFiltered'), + store: Ext.data.StoreManager.get('messstellen'), displayField: 'messStelle', valueField: 'id', allowBlank: false @@ -128,14 +141,17 @@ setStore: function(store){ var i18n = Lada.getApplication().bundle; - this.removeDocked(Ext.getCmp('ptbar'), true); - this.reconfigure(store); - this.addDocked([{ - xtype: 'pagingtoolbar', - id: 'ptbar', - dock: 'bottom', - store: store, - displayInfo: true - }]); + if (store) { + this.removeDocked(Ext.getCmp('ptbar'), true); + this.reconfigure(store); + this.down('button[action=add]').enable(); + this.addDocked([{ + xtype: 'pagingtoolbar', + id: 'ptbar', + dock: 'bottom', + store: store, + displayInfo: true + }]); + } } });
--- a/app/view/grid/Probenehmer.js Tue Dec 08 15:59:00 2015 +0100 +++ b/app/view/grid/Probenehmer.js Thu Dec 10 08:30:14 2015 +0100 @@ -46,6 +46,18 @@ xtype: 'tbtext', id: 'tbtitle', text: i18n.getMsg('pn.gridTitle') + }, + '->', + { + text: i18n.getMsg('pn.button.add'), + icon: 'resources/img/list-add.png', + action: 'add', + disabled: true // disabled on startup, will be enabled by setStore + }, { + text: i18n.getMsg('pn.button.delete'), + icon: 'resources/img/list-remove.png', + action: 'delete', + disabled: true // disabled on startup, will be enabled by controller if necessary }] }]; this.columns = [{ @@ -86,31 +98,36 @@ header: i18n.getMsg('bemerkung'), dataIndex: 'bemerkung', editor: { - allowBlank: false + allowBlank: false, + xtype: 'textfield' } }, { header: i18n.getMsg('kurzBezeichnung'), dataIndex: 'kurzBezeichnung', editor: { - allowBlank: false + allowBlank: false, + xtype: 'textfield' } }, { header: i18n.getMsg('ort'), dataIndex: 'ort', editor: { - allowBlank: false + allowBlank: false, + xtype: 'textfield' } }, { header: i18n.getMsg('plz'), dataIndex: 'plz', editor: { - allowBlank: false + allowBlank: false, + xtype: 'numberfield' } }, { header: i18n.getMsg('strasse'), dataIndex: 'strasse', editor: { - allowBlank: false + allowBlank: false, + xtype: 'textfield' } }, { header: i18n.getMsg('telefon'), @@ -153,15 +170,18 @@ setStore: function(store){ var i18n = Lada.getApplication().bundle; - this.removeDocked(Ext.getCmp('ptbar'), true); - this.reconfigure(store); - this.addDocked([{ - xtype: 'pagingtoolbar', - id: 'ptbar', - dock: 'bottom', - store: store, - displayInfo: true - }]); + if (store) { + this.removeDocked(Ext.getCmp('ptbar'), true); + this.reconfigure(store); + this.down('button[action=add]').enable(); + this.addDocked([{ + xtype: 'pagingtoolbar', + id: 'ptbar', + dock: 'bottom', + store: store, + displayInfo: true + }]); + } } });
--- a/resources/i18n/Lada_de-DE.properties Tue Dec 08 15:59:00 2015 +0100 +++ b/resources/i18n/Lada_de-DE.properties Thu Dec 10 08:30:14 2015 +0100 @@ -202,15 +202,21 @@ ## de.emptyGrid:Keine DatensatzErzeuger gefunden. de.gridTitle:Datensatzerzeuger +de.button.add:Datensatzerzeuger hinzufügen +de.button.delete:Datensatzerzeuger löschen ## # MessprogrammKategorie Grid: ## mk.emptyGrid:Keine Messprogrammkategorie gefunden. mk.gridTitle:Messprogramm Kategorien +mk.button.add:Kategorie hinzufügen +mk.button.delete:Kategorie löschen ## # Probenehmer Grid: ## pn.emptyGrid:Keine Probenehmer gefunden. pn.gridTitle:Probenehmer +pn.button.add:Probenehmer hinzufügen +pn.button.delete:Probenehmer löschen