raimund@587: /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz raimund@587: * Software engineering by Intevation GmbH raimund@587: * raimund@587: * This file is Free Software under the GNU GPL (v>=3) raimund@587: * and comes with ABSOLUTELY NO WARRANTY! Check out raimund@587: * the documentation coming with IMIS-Labordaten-Application for details. raimund@587: */ raimund@587: dustin@742: /** dustin@742: * This is a controller for a grid of Orte dustin@742: */ dustin@1012: Ext.define('Lada.controller.grid.Ortszuordnung', { raimund@587: extend: 'Ext.app.Controller', raimund@587: raimund@602: requires: [ mkrambach@1279: 'Lada.view.window.Ortszuordnung', mkrambach@1279: 'Lada.view.form.Ortserstellung' raimund@602: ], raimund@602: dustin@742: /** dustin@742: * Inhitialize the controller dustin@742: * It has 3 listeners dustin@742: */ raimund@587: init: function() { raimund@587: this.control({ dustin@1012: 'ortszuordnunggrid': { raimund@602: itemdblclick: this.open raimund@587: }, dustin@1012: 'ortszuordnunggrid button[action=add]': { raimund@587: click: this.add raimund@587: }, dustin@1012: 'ortszuordnunggrid button[action=delete]': { raimund@587: click: this.remove mkrambach@1279: }, mkrambach@1279: 'ortszuordnungwindow toolbar button[action=createort]':{ mkrambach@1279: click: this.createort mkrambach@1279: }, mkrambach@1279: 'ortszuordnungwindow toolbar button[action=frommap]':{ mkrambach@1279: click: this.frommap mkrambach@1279: }, mkrambach@1279: 'ortszuordnungwindow toolbar button[action=clone]':{ mkrambach@1279: click: this.cloneort raimund@587: } raimund@587: }); raimund@587: }, raimund@587: dustin@742: /** dustin@1013: * When open is called, a {@link Lada.view.window.Ortszuordnung} dustin@742: * is created which allows to edit the Orte dustin@742: */ raimund@602: open: function(grid, record) { raimund@690: var probe = grid.up('window').record; dustin@1013: var win = Ext.create('Lada.view.window.Ortszuordnung', { raimund@690: parentWindow: grid.up('window'), mkrambach@1279: probe: probe, dustin@1028: record: record, raimund@644: grid: grid raimund@587: }); raimund@602: win.show(); raimund@602: win.initData(); raimund@587: }, raimund@587: dustin@742: /** dustin@742: * This function adds a new row to add an Ort dustin@742: */ raimund@643: add: function(button) { raimund@643: var probe = button.up('window').record; dustin@1013: var win = Ext.create('Lada.view.window.Ortszuordnung', { dustin@1013: parentWindow: button.up('window'), dustin@1013: probe: probe, dustin@1013: record: null, dustin@1012: grid: button.up('ortszuordnung') raimund@643: }); raimund@643: win.show(); raimund@643: win.initData(); raimund@587: }, raimund@587: dustin@742: /** dustin@742: * A Ort-row can be removed from the grid with the remove dustin@742: * function. It asks the user for confirmation dustin@742: * If the removal was confirmed, it reloads the parent window on success, dustin@742: * on failure, an error message is shown. dustin@742: */ raimund@587: remove: function(button) { raimund@587: var grid = button.up('grid'); raimund@587: var selection = grid.getView().getSelectionModel().getSelection()[0]; dustin@1012: var i18n = Lada.getApplication().bundle; dustin@1012: Ext.MessageBox.confirm(i18n.getMsg('delete'), i18n.getMsg('confirmation.question'), dustin@1012: function(btn) { dustin@1012: if (btn === 'yes') { raimund@587: selection.destroy({ raimund@587: success: function() { raimund@587: button.up('window').initData(); raimund@587: }, dustin@701: failure: function(request, response) { dustin@1012: var i18n = Lada.getApplication().bundle; dustin@701: var json = response.request.scope.reader.jsonData; dustin@701: if (json) { dustin@701: if (json.message){ dustin@1012: Ext.Msg.alert(i18n.getMsg('err.msg.delete.title') dustin@701: +' #'+json.message, dustin@1012: i18n.getMsg(json.message)); dustin@701: } else { dustin@1012: Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'), dustin@1012: i18n.getMsg('err.msg.generic.body')); dustin@701: } dustin@701: } else { dustin@1012: Ext.Msg.alert(i18n.getMsg('err.msg.delete.title'), dustin@1012: i18n.getMsg('err.msg.response.body')); dustin@701: } raimund@587: } raimund@587: }); raimund@587: } raimund@587: }); dustin@826: grid.down('button[action=delete]').disable(); mkrambach@1279: }, mkrambach@1279: mkrambach@1279: /** mkrambach@1279: * Opens the form for a new Messpunkt mkrambach@1279: */ mkrambach@1279: createort: function() { mkrambach@1279: Ext.create('Lada.view.form.Ortserstellung').show(); mkrambach@1279: }, mkrambach@1279: mkrambach@1279: /** mkrambach@1279: * mkrambach@1279: * Opens the form for a new Messpunkt, with prefilled coordinates. mkrambach@1279: * TODO Not functional yet mkrambach@1279: */ mkrambach@1279: frommap: function(button) { mkrambach@1279: var map = button.up('ortszuordnungwindow').down('map'); mkrambach@1279: // map.getClick(); mkrambach@1279: //TODO: wait for click return mkrambach@1279: Ext.create('Lada.view.form.Ortserstellung', { mkrambach@1279: presets: { mkrambach@1279: kda_id: 4, mkrambach@1279: koord_x_extern: 35000000, //TODO dummy values mkrambach@1279: koord_y_extern: 1000000 mkrambach@1279: } mkrambach@1279: }).show(); mkrambach@1279: }, mkrambach@1279: mkrambach@1279: /** mkrambach@1279: * Opens the form for a new Messpunkt, with all values prefilled from the currently mkrambach@1279: * selected item mkrambach@1279: */ mkrambach@1279: cloneort: function(button) { mkrambach@1279: var grid = button.up('ortszuordnungwindow').down('ortstammdatengrid').getView(); mkrambach@1279: var selected = grid.getSelectionModel().getSelection()[0]; mkrambach@1279: Ext.create('Lada.view.form.Ortserstellung', { mkrambach@1279: presets: selected.data mkrambach@1279: }).show(); raimund@587: } raimund@587: });