comparison app/controller/form/Ortserstellung.js @ 1361:5c2d6812d85a

Merge behaviour of Stammdaten panel and ortszuordnungs grid according to the recent changes in Ortszuordnung and Ortserstellung.
author Maximilian Krambach <mkrambach@intevation.de>
date Tue, 07 Feb 2017 19:50:36 +0100
parents d1dce50fa9a6
children b58868c47f02
comparison
equal deleted inserted replaced
1360:d1dce50fa9a6 1361:5c2d6812d85a
44 }, 44 },
45 }); 45 });
46 }, 46 },
47 47
48 save: function(button) { 48 save: function(button) {
49 var me = button.up('panel'); 49 var me = this;
50 var form = me.getForm(); 50 var formpanel = button.up('ortserstellungsform');
51 var form = formpanel.getForm();
51 var record = form.getRecord(); 52 var record = form.getRecord();
52 var data = form.getFieldValues(true); 53 var data = form.getFieldValues(true);
53 for (var key in data) { 54 for (var key in data) {
54 record.set(key, data[key]); 55 record.set(key, data[key]);
55 } 56 }
56 record.set('id', null); 57 record.set('id', null);
57 record.set('netzbetreiberId', Lada.netzbetreiber[0]); 58 record.set('netzbetreiberId', Lada.netzbetreiber[0]);
58 record.save({ 59 record.save({
59 success: function(newrecord, response) { 60 success: function(newrecord, response) {
60 form.loadRecord(newrecord); 61 form.loadRecord(newrecord);
61 me.down('verwaltungseinheit').store.clearFilter(); 62 formpanel.down('verwaltungseinheit').store.clearFilter();
62 me.down('staat').store.clearFilter(); 63 formpanel.down('staat').store.clearFilter();
63 button.setDisabled(true); 64 button.setDisabled(true);
64 me.down('button[action=revert]').setDisabled(true); 65 formpanel.down('button[action=revert]').setDisabled(true);
65 button.hide(); 66 button.hide();
66 var ozw = me.up('window').parentWindow; 67 var ozw = formpanel.up('panel').parentWindow;
67 var json = Ext.decode(response.response.responseText); 68 var json = Ext.decode(response.response.responseText);
68 if (json) { 69 if (json) {
69 me.clearMessages(); 70 formpanel.clearMessages();
70 me.setMessages(json.errors, json.warnings); 71 formpanel.setMessages(json.errors, json.warnings);
71 } 72 }
72 ozw.ortstore.load({ 73 if (ozw.ortstore) {
73 callback: function(records, operation, success) { 74 ozw.ortstore.load({
74 ozw.down('map').addLocations(ozw.ortstore); 75 callback: function(records, operation, success) {
75 var osg = ozw.down('ortstammdatengrid'); 76 me.afterSave(formpanel, ozw.ortstore, json);
76 osg.setStore(ozw.ortstore); 77 },
77 var id = Ext.decode(response.response.responseText).data.id; 78 scope: this
78 var record = osg.store.getById(id); 79 });
79 var selmod = osg.getView().getSelectionModel(); 80 } else {
80 selmod.select(record); 81 ozw.setStore();
81 var resulttext; 82 me.afterSave(formpanel, ozw.getStore(), json);
82 if (json) { 83 }
83 if (json.message == '201') {
84 resulttext = 'Dieser Ort existiert bereits!';
85 }
86 if (json.message == '200') {
87 resulttext = 'Ort erfolgreich angelegt!';
88 }
89 }
90 Ext.Msg.show({
91 title: Lada.getApplication().bundle.getMsg('success'),
92 autoScroll: true,
93 msg: resulttext,
94 buttons: Ext.Msg.OK
95 });
96 },
97 scope: this
98 });
99
100 }, 84 },
101 failure: function(record, response) { 85 failure: function(record, response) {
102 var json = response.request.scope.reader.jsonData; 86 var json = response.request.scope.reader.jsonData;
103 if (json) { 87 if (json) {
104 if(json.message){ 88 if(json.message){
114 } else { 98 } else {
115 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'), 99 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.save.title'),
116 Lada.getApplication().bundle.getMsg('err.msg.response.body')); 100 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
117 } 101 }
118 } 102 }
103 });
104 },
105
106 /**
107 * Callbacks after a Ort has been saved and the store is reloaded
108 */
109 afterSave: function(form, store, json) {
110 var ozw = form.up('panel').parentWindow;
111 ozw.down('map').addLocations(ozw.ortstore);
112 var osg = ozw.down('ortstammdatengrid');
113 osg.setStore(ozw.ortstore);
114 var id = json.data.id;
115 var record = osg.store.getById(id);
116 var selmod = osg.getView().getSelectionModel();
117 selmod.select(record);
118 var resulttext;
119 if (json) {
120 if (json.message == '201') {
121 resulttext = 'Dieser Ort existiert bereits!';
122 }
123 if (json.message == '200') {
124 resulttext = 'Ort erfolgreich angelegt!';
125 }
126 }
127 Ext.Msg.show({
128 title: Lada.getApplication().bundle.getMsg('success'),
129 autoScroll: true,
130 msg: resulttext,
131 buttons: Ext.Msg.OK
119 }); 132 });
120 }, 133 },
121 134
122 discard: function(button) { 135 discard: function(button) {
123 button.up('panel').getForm().reset(); 136 button.up('panel').getForm().reset();

http://lada.wald.intevation.org