comparison app/controller/form/Ortserstellung.js @ 1337:7194964183f4

Ortserstellung controller separated from form
author Maximilian Krambach <mkrambach@intevation.de>
date Fri, 03 Feb 2017 17:44:41 +0100
parents
children 1a2cd9bef6d7
comparison
equal deleted inserted replaced
1336:f879c806f880 1337:7194964183f4
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU GPL (v>=3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
6 * the documentation coming with IMIS-Labordaten-Application for details.
7 */
8
9 /*
10 * This is a controller for an Ortserstellung Form
11 */
12 Ext.define('Lada.controller.form.Ortserstellung', {
13 extend: 'Ext.app.Controller',
14
15 /**
16 * Initialize the Controller
17 */
18 init: function() {
19 this.control({
20 'ortserstellungsform button[action=save]': {
21 click: this.save
22 },
23 'ortserstellungsform button[action=revert]': {
24 click: this.discard
25 },
26 'ortserstellungsform staat' : {
27 change: this.checkCommitEnabled
28 },
29 'ortserstellungsform verwaltungseinheit' : {
30 change: this.checkCommitEnabled
31 },
32 'ortserstellungsform koordinatenart': {
33 change: this.checkCommitEnabled
34 },
35 'ortserstellungsform numfield [name=koordXExtern]': {
36 change: this.checkCommitEnabled
37 },
38 'ortserstellungsform numfield [name=koordYExtern]': {
39 change: this.checkCommitEnabled
40 }
41 });
42 },
43
44 save: function() {
45 var this_panel = this.up('panel');
46 var me = this;
47 var form = this_panel.getForm();
48 var record = form.getRecord();
49 var data = form.getFieldValues(true);
50 for (var key in data) {
51 record.set(key, data[key]);
52 }
53 record.set('id', null);
54 record.set('netzbetreiberId', Lada.netzbetreiber[0]);
55 record.save({
56 success: function(newrecord, response) {
57 form.loadRecord(newrecord);
58 this_panel.down('verwaltungseinheit').store.load(
59 { id:newrecord.get('gemId') });
60 this_panel.down('staat').store.load(
61 { id : newrecord.get('staat') });
62 me.setDisabled(true);
63 me.hide();
64 var ozw = this_panel.up().parentWindow;
65 var json = Ext.decode(response.response.responseText);
66 if (json) {
67 this_panel.clearMessages();
68 this_panel.setMessages(json.errors, json.warnings);
69 }
70 ozw.ortstore.load({
71 callback: function(records, operation, success) {
72 ozw.down('map').addLocations(ozw.ortstore);
73 var osg = ozw.down('ortstammdatengrid');
74 osg.setStore(ozw.ortstore);
75 var id = Ext.decode(response.response.responseText).data.id;
76 var record = osg.store.getById(id);
77 var selmod = osg.getView().getSelectionModel();
78 selmod.select(record);
79 var resulttext;
80 if (json) {
81 if (json.message == '201') {
82 resulttext = 'Dieser Ort existiert bereits!';
83 }
84 if (json.message == '200') {
85 resulttext = 'Ort erfolgreich angelegt!';
86 }
87 }
88 Ext.Msg.show({
89 title: Lada.getApplication().bundle.getMsg('success'),
90 autoScroll: true,
91 msg: resulttext,
92 buttons: Ext.Msg.OK
93 });
94 },
95 scope: this
96 });
97
98 },
99 failure: function(record, response) {
100 var json = Ext.decode(response.response.responseText);
101 if (json) {
102 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
103 formPanel.setMessages(json.errors, json.warnings);
104 }
105 if(json.message){
106 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title')
107 +' #'+json.message,
108 Lada.getApplication().bundle.getMsg(json.message));
109 } else {
110 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
111 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
112 }
113 } else {
114 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
115 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
116 }
117 me.setDisabled(true);
118 }
119 });
120 },
121
122 discard: function(button) {
123 this.up('panel').getForm().reset();
124 this.up('toolbar').down('button [action=save]').setDisabled(true);
125 },
126
127 /**
128 * checks if the Messpunkt can be committed.
129 * Disables the save button if false
130 */
131 checkCommitEnabled: function(field) {
132 var panel;
133 if (field.up('panel')) {
134 panel = field.up('panel').up('panel');
135 } else {
136 panel = field;
137 }
138 var savebutton = panel.down('button[action=save]');
139 var form = panel.getForm();
140 if (form.isDirty()) {
141 panel.down('button[action=revert]').setDisabled(false);
142 } else {
143 panel.down('button[action=revert]').setDisabled(true);
144 }
145 if (form.isValid()) {
146 //one of three conditions must apply, the first one depending
147 // on three fields
148 if (
149 (form.findField('kdaId').getValue()
150 && form.findField('koordYExtern').getValue()
151 && form.findField('koordXExtern').getValue()
152 )
153 || form.findField('gemId').getValue() >= 0
154 || form.findField('staatId').getValue() >= 0
155 ) {
156 savebutton.setDisabled(false);
157 } else {
158 savebutton.setDisabled(true);
159 }
160 } else { //form invalid
161 savebutton.setDisabled(true);
162 }
163 }
164 });

http://lada.wald.intevation.org