comparison app/view/window/DeleteProbe.js @ 856:e44070aa45d2

Implemented a 'Delete Button' in the ResultGrid. Proben can be deleted when they are not ReadOnly and the Users is the Owner of the Probe
author Dustin Demuth <dustin@intevation.de>
date Fri, 10 Jul 2015 17:14:19 +0200
parents
children 2c686025934a
comparison
equal deleted inserted replaced
855:dff2798390f8 856:e44070aa45d2
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 * Window to show a confirmation dialog to delete a Probe
11 */
12 Ext.define('Lada.view.window.DeleteProbe', {
13 extend: 'Ext.window.Window',
14 alias: 'widget.deleteProbe',
15
16 collapsible: true,
17 maximizable: true,
18 autoShow: true,
19 autoScroll: true,
20 layout: 'fit',
21 constrain: true,
22
23 record: null,
24 parentWindow: null,
25
26 initComponent: function() {
27 var i18n = Lada.getApplication().bundle;
28
29 // add listeners to change the window appearence when it becomes inactive
30 this.on({
31 activate: function(){
32 this.getEl().removeCls('window-inactive');
33 },
34 deactivate: function(){
35 this.getEl().addCls('window-inactive');
36 }
37 });
38
39 this.title = i18n.getMsg('delete.probe.window.title');
40 var me = this;
41 this.buttons = [{
42 text: i18n.getMsg('cancel'),
43 scope: this,
44 handler: this.close
45 }, {
46 text: i18n.getMsg('delete'),
47 handler: function() {
48
49 Ext.Ajax.request({
50 //TODO Use correct URLs
51 url: 'lada-server/probe/'+me.record.get('id'),
52 method: 'DELETE',
53 headers: {
54 'X-OPENID-PARAMS': Lada.openIDParams
55 },
56 success: function(response) {
57 var json = Ext.JSON.decode(response.responseText);
58 Ext.Msg.show({
59 title: i18n.getMsg('success'),
60 autoScroll: true,
61 msg: me.evalResponse(json),
62 buttons: Ext.Msg.OK,
63 });
64 },
65 failure: function(response) {
66 var json = null;
67 try {
68 json = Ext.JSON.decode(response.responseText);
69 }
70 catch(err){
71 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
72 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
73 }
74 if (json) {
75 if(json.errors.totalCount > 0 || json.warnings.totalCount > 0){
76 formPanel.setMessages(json.errors, json.warnings);
77 }
78 // TODO Move this handling of 699 and 698 to a more central place!
79 // TODO i18n
80 if (json.message === "699" || json.message === "698") {
81 /* This is the unauthorized message with the authentication
82 * redirect in the data */
83
84 /* We decided to handle this with a redirect to the identity
85 * provider. In which case we have no other option then to
86 * handle it here with relaunch. */
87 Ext.MessageBox.confirm('Erneutes Login erforderlich',
88 'Der Server konnte die Anfrage nicht authentifizieren.<br/>'+
89 'Für ein erneutes Login muss die Anwendung neu geladen werden.<br/>' +
90 'Alle ungesicherten Daten gehen dabei verloren.<br/>' +
91 'Soll die Anwendung jetzt neu geladen werden?', me.reload);
92 }
93 else if(json.message){
94 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title')
95 +' #'+json.message,
96 Lada.getApplication().bundle.getMsg(json.message));
97 } else {
98 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
99 Lada.getApplication().bundle.getMsg('err.msg.generic.body'));
100 }
101 } else {
102 Ext.Msg.alert(Lada.getApplication().bundle.getMsg('err.msg.generic.title'),
103 Lada.getApplication().bundle.getMsg('err.msg.response.body'));
104 }
105 }
106 });
107 }
108 }];
109 this.width = 350;
110 this.height = 250;
111
112 // add listeners to change the window appearence when it becomes inactive
113 this.on({
114 activate: function(){
115 this.getEl().removeCls('window-inactive');
116 },
117 deactivate: function(){
118 this.getEl().addCls('window-inactive');
119 },
120 close: function () {
121 this.parentWindow.probenWindow = null;
122 }
123 });
124
125 // InitialConfig is the config object passed to the constructor on
126 // creation of this window. We need to pass it throuh to the form as
127 // we need the "Id" param to load the correct item.
128 this.items = [{
129 border: 0,
130 autoScroll: true,
131 items: [{
132 xtype: 'panel',
133 border: 0,
134 margin: 5,
135 layout: 'fit',
136 html: '<p>'
137 + i18n.getMsg('delete.probe')
138 + '<br/>'
139 + '<br/>'
140 + this.record.get('probeId')
141 + '<br/>'
142 + '<br/>'
143 + i18n.getMsg('delete.probe.warning')
144 + '</p>'
145 }]
146 }];
147 this.callParent(arguments);
148 },
149
150 /**
151 * Init
152 */
153 initData: function() {
154 var i18n = Lada.getApplication().bundle;
155 me = this;
156 },
157
158 /**
159 * Parse ServerResponse when Proben have been generated
160 */
161 evalResponse: function(response) {
162 var i18n = Lada.getApplication().bundle;
163 var r = '';
164 r += response.data.length;
165 r += ' ' + i18n.getMsg('probedeleted');
166 return r;
167 },
168
169 reload: function(btn) {
170 if (btn === 'yes') {
171 location.reload();
172 }
173 }
174 });
175

http://lada.wald.intevation.org