Mercurial > lada > lada-client
changeset 1130:e4952906634d
Implemented insert, edit and delete for stammdaten.ort.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 25 May 2016 14:04:51 +0200 |
parents | f1d234a7adc7 |
children | 6549abef70e1 |
files | app/controller/Ort.js app/model/Ort.js app/view/grid/Orte.js app/view/panel/Map.js |
diffstat | 4 files changed, 205 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controller/Ort.js Tue May 24 10:41:07 2016 +0200 +++ b/app/controller/Ort.js Wed May 25 14:04:51 2016 +0200 @@ -12,7 +12,7 @@ var me = this; this.control({ 'ortpanel button[action=addMap]': { - click: me.addFeature + click: me.activateDraw }, 'ortpanel button[action=add]': { click: me.addRecord @@ -23,22 +23,87 @@ 'ortpanel ortstammdatengrid': { edit: me.gridSave, canceledit: me.cancelEdit, - select: me.activateButtons, - deselect: me.deactivateButtons + select: me.select + }, + 'ortpanel map': { + featureadded: me.featureadded } }); }, - addFeature: function(button) { - console.log('add feature'); + featureadded: function(record) { + var grid = Ext.ComponentQuery.query('ortpanel ortstammdatengrid')[0]; + if (!record.get('letzteAenderung')) { + record.data.letzteAenderung = new Date(); + } + grid.store.insert(0, record); + grid.rowEditing.startEdit(0, 1); + }, + + activateDraw: function(button) { + var map = button.up('ortpanel').down('map'); + var record = Ext.create('Lada.model.Ort'); + map.activateDraw(record); }, addRecord: function(button) { console.log('add record'); + var record = Ext.create('Lada.model.Ort'); + var grid = button.up('ortpanel').down('ortstammdatengrid'); + if (!record.get('letzteAenderung')) { + record.data.letzteAenderung = new Date(); + } + grid.store.insert(0, record); + grid.rowEditing.startEdit(0, 1); }, deleteItem: function(button) { - console.log('delete item'); + var grid = button.up('ortpanel').down('ortstammdatengrid'); + var selection = grid.getView().getSelectionModel().getSelection()[0]; + var i18n = Lada.getApplication().bundle; + Ext.MessageBox.confirm(i18n.getMsg('delete'), + i18n.getMsg('confirmation.question'), + 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(i18n.getMsg('err.msg.delete.title') + +' #'+json.message, + i18n.getMsg(json.message)); + } else { + Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'), + i18n.getMsg('err.msg.generic.body')); + } + } else { + Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'), + i18n.getMsg('err.msg.response.body')); + } + } + }); + } + }); + grid.up('ortpanel').down('button[action=delete]').disable(); + }, + + select: function(rowModel, record) { + this.checkEdit(rowModel, record); + this.buttonToggle(rowModel, record); + }, + + checkEdit: function(rowModel, record) { + if (!Ext.Array.contains(Lada.netzbetreiber, + record.get('netzbetreiberId')) && + record.get('netzbetreiberId') !== '') { + var grid = Ext.ComponentQuery.query('ortpanel ortstammdatengrid')[0]; + grid.rowEditing.cancelEdit(); + return; + } }, /** @@ -51,7 +116,8 @@ var i18n = Lada.getApplication().bundle; context.record.save({ success: function(record, response) { - //Do Nothing + var grid = Ext.ComponentQuery.query('ortstammdatengrid')[0]; + grid.store.reload(); }, failure: function(record, response) { var json = response.request.scope.reader.jsonData; @@ -80,29 +146,35 @@ } context.grid.getSelectionModel().deselect(context.record); }, - /** - * Toggles the buttons in the toolbar - **/ - activateButtons: function(rowModel, record) { - var panel = rowModel.view.up('ortpanel'); - this.buttonToggle(true, panel); - }, - - /** - * Toggles the buttons in the toolbar - **/ - deactivateButtons: function(rowModel, record) { - var panel = rowModel.view.up('ortpanel'); - // Only disable buttons when nothing is selected - if (rowModel.selected.items == 0) { - this.buttonToggle(false, panel); - } - }, /** * Enables/Disables a set of buttons **/ - buttonToggle: function(enabled, panel) { + buttonToggle: function(rowModel, record) { + if (!Ext.Array.contains(Lada.funktionen, 4)) { + return; + } + var grid = Ext.ComponentQuery.query('ortstammdatengrid')[0]; + if (!record || + !Ext.Array.contains(Lada.netzbetreiber, + record.get('netzbetreiberId'))) { + grid.up('ortpanel').down('button[action=delete]').disable(); + return; + } + if (record.get('readonly') || + rowModel.selected.items.length === 0) { + grid.up('ortpanel').down('button[action=delete]').disable(); + } + else { + if (grid.getPlugin('rowedit').editing) { + //only enable buttons, when grid is not beeing edited + grid.up('ortpanel').down('button[action=delete]').disable(); + } + else { + grid.up('ortpanel').down('button[action=delete]').enable(); + } + } + /* if (!enabled && panel.down('button[action=delete]')) { panel.down('button[action=delete]').disable(); @@ -119,5 +191,6 @@ panel.down('button[action=delete]').disable(); } } + */ } });
--- a/app/model/Ort.js Tue May 24 10:41:07 2016 +0200 +++ b/app/model/Ort.js Wed May 25 14:04:51 2016 +0200 @@ -49,8 +49,6 @@ }, { name: 'langtext' }, { - name: 'beschreibung' - }, { name: 'unscharf' }, { name: 'hoeheLand'
--- a/app/view/grid/Orte.js Tue May 24 10:41:07 2016 +0200 +++ b/app/view/grid/Orte.js Wed May 25 14:04:51 2016 +0200 @@ -56,34 +56,89 @@ return 'noedit'; } }, { + header: i18n.getMsg('netzbetreiber'), + renderer: function(value) { + var r = ''; + if (!value || value === '') { + r = 'Error'; + } + var store = Ext.data.StoreManager.get('netzbetreiber'); + var record = store.getById(value); + if (record) { + r = record.get('netzbetreiber'); + } + return r; + }, + editor: { + xtype: 'combobox', + store: Ext.data.StoreManager.get('netzbetreiberFiltered'), + displayField: 'netzbetreiber', + valueField: 'id', + allowBlank: false + }, + dataIndex: 'netzbetreiberId' + }, { header: i18n.getMsg('orte.ortId'), + editor: { + xtype: 'textfield' + }, dataIndex: 'ortId' }, { header: i18n.getMsg('orte.nutsCode'), + editor: { + xtype: 'textfield' + }, dataIndex: 'nutsCode' }, { header: i18n.getMsg('orte.anlageId'), + editor: { + xtype: 'numberfield' + }, dataIndex: 'anlageId' }, { header: i18n.getMsg('orte.gemId'), dataIndex: 'gemId', width: 120, renderer: function(value) { + if (!value) { + return ''; + } var store = Ext.data.StoreManager.get('verwaltungseinheiten'); var record = store.getById(value); return record.get('bezeichnung'); + }, + editor: { + xtype: 'combobox', + store: Ext.data.StoreManager.get('verwaltungseinheiten'), + displayField: 'bezeichnung', + valueField: 'id', + allowBlank: false } }, { header: i18n.getMsg('orte.staatId'), dataIndex: 'staatId', width: 70, renderer: function(value) { + if (!value) { + return ''; + } var staaten = Ext.data.StoreManager.get('staaten'); var record = staaten.getById(value); return record.get('staatIso'); + }, + editor: { + xtype: 'combobox', + store: Ext.data.StoreManager.get('staaten'), + displayField: 'staatIso', + valueField: 'id', + allowBlank: false } }, { header: i18n.getMsg('orte.kdaId'), + editor: { + xtype: 'numberfield', + allowBlank: false + }, dataIndex: 'kdaId' }, { header: i18n.getMsg('orte.ozId'), @@ -93,45 +148,81 @@ dataIndex: 'ortTyp' }, { header: i18n.getMsg('orte.mpArt'), + editor: { + xtype: 'textfield' + }, dataIndex: 'mpArt' }, { header: i18n.getMsg('orte.zone'), + editor: { + xtype: 'textfield' + }, dataIndex: 'zone' }, { header: i18n.getMsg('orte.sektor'), + editor: { + xtype: 'textfield' + }, dataIndex: 'sektor' }, { header: i18n.getMsg('orte.zustaendigkeit'), + editor: { + xtype: 'textfield' + }, dataIndex: 'zustaendigkeit' }, { header: i18n.getMsg('orte.berichtstext'), + editor: { + xtype: 'textfield' + }, dataIndex: 'berichtstext' }, { header: i18n.getMsg('orte.kurztext'), + editor: { + xtype: 'textfield' + }, dataIndex: 'kurztext' }, { header: i18n.getMsg('orte.langtext'), + editor: { + xtype: 'textfield' + }, dataIndex: 'langtext' }, { - header: i18n.getMsg('orte.beschreibung'), - dataIndex: 'beschreibung' - }, { header: i18n.getMsg('orte.unscharf'), + editor: { + xtype: 'textfield' + }, dataIndex: 'unscharf' }, { header: i18n.getMsg('orte.hoeheLand'), + editor: { + xtype: 'numberfield' + }, dataIndex: 'hoeheLand' }, { header: i18n.getMsg('orte.koordXExtern'), + editor: { + xtype: 'textfield' + }, dataIndex: 'koordXExtern' }, { header: i18n.getMsg('orte.koordYExtern'), + editor: { + xtype: 'textfield' + }, dataIndex: 'koordYExtern' }, { header: i18n.getMsg('orte.longitude'), + editor: { + xtype: 'numberfield' + }, dataIndex: 'longitude' }, { header: i18n.getMsg('orte.latitude'), + editor: { + xtype: 'numberfield' + }, dataIndex: 'latitude' }, { header: i18n.getMsg('orte.letzteAenderung'), @@ -163,6 +254,12 @@ }]); } } + + if (Ext.Array.contains(Lada.funktionen, 4)) { + var panel = this.up('ortpanel'); + panel.down('button[action=add]').enable(); + panel.down('button[action=addMap]').enable(); + } }, selectOrt: function(map, feature) {
--- a/app/view/panel/Map.js Tue May 24 10:41:07 2016 +0200 +++ b/app/view/panel/Map.js Wed May 25 14:04:51 2016 +0200 @@ -86,6 +86,9 @@ }, selectFeature: function(model, record) { + if (!record.get('id') || record.get('id') === '') { + return; + } var feature = this.featureLayer.getFeaturesByAttribute('id', record.get('id')); this.map.setCenter( new OpenLayers.LonLat(feature[0].geometry.x, feature[0].geometry.y)); @@ -109,8 +112,9 @@ this.locationRecord.set('latitude', features.feature.geometry.y); this.locationRecord.set('longitude', features.feature.geometry.x); this.drawPoint.deactivate(); - this.selectControl.unselectAll(); - this.selectControl.select(features.feature); + this.fireEvent('featureadded', this.locationRecord); + // this.selectControl.unselectAll(); + // this.selectControl.select(features.feature); }, addLocations: function(locationStore) {