Mercurial > lada > lada-client
comparison app/controller/form/Ortszuordnung.js @ 1013:75ce503ab296 stammdatengrids
Added a Ortszuordnungwindow and Form
author | Dustin Demuth <dustin@intevation.de> |
---|---|
date | Tue, 26 Jan 2016 12:29:59 +0100 |
parents | app/controller/form/Ort.js@24b5684d74d7 |
children | 1df6b6210b42 |
comparison
equal
deleted
inserted
replaced
1012:2adc329d90fe | 1013:75ce503ab296 |
---|---|
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 Ortszuordnung Form | |
11 */ | |
12 Ext.define('Lada.controller.form.Ortszuordnung', { | |
13 extend: 'Ext.app.Controller', | |
14 | |
15 /** | |
16 * Initialize the Controller with 4 listeners | |
17 */ | |
18 init: function() { | |
19 this.control({ | |
20 'ortszuordnungform button[action=save]': { | |
21 click: this.save | |
22 }, | |
23 'ortszuordnungform button[action=discard]': { | |
24 click: this.discard | |
25 }, | |
26 'ortszuordnungform': { | |
27 dirtychange: this.dirtyForm | |
28 }, | |
29 'ortszuordnungform combobox[name=ort]': { | |
30 select: this.updateDetails | |
31 } | |
32 }); | |
33 }, | |
34 | |
35 /** | |
36 * The save function saves the content of the Ort form. | |
37 * On success it will reload the Store, | |
38 * on failure, it will display an Errormessage | |
39 */ | |
40 save: function(button) { | |
41 var formPanel = button.up('ortszuordnungform'); | |
42 var data = formPanel.getForm().getFieldValues(true); | |
43 var i18n = Lada.getApplication().bundle; | |
44 for (var key in data) { | |
45 formPanel.getForm().getRecord().set(key, data[key]); | |
46 } | |
47 if (!formPanel.getForm().getRecord().get('letzteAenderung')) { | |
48 formPanel.getForm().getRecord().data.letzteAenderung = new Date(); | |
49 } | |
50 formPanel.getForm().getRecord().save({ | |
51 success: function(record, response) { | |
52 var json = Ext.decode(response.response.responseText); | |
53 if (json) { | |
54 button.setDisabled(true); | |
55 button.up('toolbar').down('button[action=discard]') | |
56 .setDisabled(true); | |
57 formPanel.clearMessages(); | |
58 formPanel.setRecord(record); | |
59 formPanel.setMessages(json.errors, json.warnings); | |
60 formPanel.up('window').grid.store.reload(); | |
61 debugger; | |
62 } | |
63 }, | |
64 failure: function(record, response) { | |
65 button.setDisabled(true); | |
66 button.up('toolbar').down('button[action=discard]') | |
67 .setDisabled(true); | |
68 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
69 var json = response.request.scope.reader.jsonData; | |
70 if (json) { | |
71 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){ | |
72 formPanel.setMessages(json.errors, json.warnings); | |
73 } | |
74 | |
75 if(json.message){ | |
76 Ext.Msg.alert(i18n.getMsg('err.msg.save.title') | |
77 +' #'+json.message, | |
78 i18n.getMsg(json.message)); | |
79 } else { | |
80 Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), | |
81 i18n.getMsg('err.msg.generic.body')); | |
82 } | |
83 } else { | |
84 Ext.Msg.alert(i18n.getMsg('err.msg.save.title'), | |
85 i18n.getMsg('err.msg.response.body')); | |
86 } | |
87 } | |
88 }); | |
89 }, | |
90 | |
91 /** | |
92 * The discard function resets the Location form | |
93 * to its original state. | |
94 */ | |
95 discard: function(button) { | |
96 var formPanel = button.up('form'); | |
97 formPanel.getForm().loadRecord(formPanel.getForm().getRecord()); | |
98 }, | |
99 | |
100 /** | |
101 * The dirtyForm function enables or disables the save and discard | |
102 * button which are present in the toolbar of the form. | |
103 * The Buttons are only active if the content of the form was altered | |
104 * (the form is dirty). | |
105 */ | |
106 dirtyForm: function(form, dirty) { | |
107 if (dirty) { | |
108 form.owner.down('button[action=save]').setDisabled(false); | |
109 form.owner.down('button[action=discard]').setDisabled(false); | |
110 } | |
111 else { | |
112 form.owner.down('button[action=save]').setDisabled(true); | |
113 form.owner.down('button[action=discard]').setDisabled(true); | |
114 } | |
115 } | |
116 }); |