comparison app/view/window/SetStatus.js @ 1082:dbd435256f77

Open status edit window and send status objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 13 Apr 2016 19:04:15 +0200
parents
children 7a71723fda83
comparison
equal deleted inserted replaced
1081:5e9a674d7bb4 1082:dbd435256f77
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 simple Window to set the Status for multiple Messungen on bulk.
11 */
12 Ext.define('Lada.view.window.SetStatus', {
13 extend: 'Ext.window.Window',
14 alias: 'setstatuswindow',
15
16 requires: [
17 'Lada.view.widget.Status'
18 ],
19
20 grid: null,
21 selection: null,
22
23 modal: true,
24 closable: false,
25 resultMessage: '',
26
27 /**
28 * This function initialises the Window
29 */
30 initComponent: function() {
31 var i18n = Lada.getApplication().bundle;
32 var me = this;
33 this.items = [{
34 xtype: 'panel',
35 name: 'valueselection',
36 border: 0,
37 items: [{
38 xtype: 'fieldset',
39 title: 'Status für ' + this.selection.length + ' Messung(en) setzen',
40 margin: '5, 5, 10, 5',
41 items: [{
42 xtype: 'combobox',
43 store: Ext.data.StoreManager.get('messstellenFiltered'),
44 displayField: 'messStelle',
45 valueField: 'id',
46 allowBlank: false,
47 queryMode: 'local',
48 editable: false,
49 width: 300,
50 labelWidth: 100,
51 emptyText: 'Wählen Sie einen Erzeuger aus.',
52 fieldLabel: i18n.getMsg('statusgrid.header.erzeuger')
53 }, {
54 xtype: 'statuswert',
55 allowBlank: false,
56 width: 300,
57 labelWidth: 100,
58 fieldLabel: i18n.getMsg('statusgrid.header.statusWert')
59 }, {
60 xtype: 'textarea',
61 width: 300,
62 height: 100,
63 labelWidth: 100,
64 fieldLabel: i18n.getMsg('statusgrid.header.text'),
65 emptyText: 'Geben Sie einen Kommentar ein.'
66 }]
67 }]
68 }, {
69 xtype: 'panel',
70 hidden: true,
71 margin: '5, 5, 5, 5',
72 overflow: 'auto',
73 name: 'result'
74 }, {
75 xtype: 'progressbar',
76 margin: '5, 5, 5, 5',
77 hidden: true,
78 text: 'Verarbeite Statusänderungen'
79 }];
80 this.buttons = [{
81 text: i18n.getMsg('statusSetzen'),
82 name: 'start',
83 icon: 'resources/img/emblem-important.png',
84 handler: this.setStatus
85 }, {
86 text: i18n.getMsg('cancel'),
87 name: 'abort',
88 handler: this.closeWindow
89 }, {
90 text: i18n.getMsg('close'),
91 name: 'close',
92 hidden: true,
93 handler: this.closeWindow
94 }];
95
96 this.callParent(arguments);
97 },
98
99 /**
100 * @private
101 * A handler for a Abort-Button
102 */
103 closeWindow: function(button) {
104 var win = button.up('window');
105 win.close();
106 },
107
108 /**
109 * @private
110 * A handler to setStatus on Bulk.
111 */
112 setStatus: function(button) {
113 var win = button.up('window');
114 win.down('panel').disable();
115 win.down('button[name=start]').disable();
116 win.down('button[name=abort]').disable();
117 var progress = win.down('progressbar');
118 progress.show();
119 win.send();
120 },
121
122 send: function() {
123 var i18n = Lada.getApplication().bundle;
124 var me = this;
125 var progress = me.down('progressbar');
126 var progressText = progress.getText();
127 var count = 0;
128 for (var i = 0; i < this.selection.length; i++) {
129 var data = Ext.create('Lada.model.Status', {
130 messungsId: this.selection[i].get('id'),
131 erzeuger: this.down('combobox').getValue(),
132 datum: new Date(),
133 statusWert: this.down('statuswert').getValue(),
134 text: this.down('textarea').getValue()
135 });
136 Ext.Ajax.request({
137 url: 'lada-server/rest/status',
138 method: 'POST',
139 jsonData: data.raw,
140 success: function(response) {
141 var json = Ext.JSON.decode(response.responseText);
142 me.resultMessage += '<strong>' + i18n.getMsg('messung') + ': ';
143 var sel = me.selection[count];
144 me.resultMessage += sel.get('hauptprobenNr') + ' - ' + sel.get('nebenprobenNr') + '</strong><br><dd>';
145 me.resultMessage += i18n.getMsg(json.message) + '</dd><br>';
146 count++;
147 progress.updateProgress(count / me.selection.length, progressText + ' (' + count + ')');
148 if (count === me.selection.length) {
149 var result = me.down('panel[name=result]');
150 var values = me.down('panel[name=valueselection]');
151 me.down('button[name=start]').hide();
152 me.down('button[name=abort]').hide();
153 me.down('button[name=close]').show();
154 result.setSize(values.getWidth(), values.getHeight());
155 result.getEl().setHTML(me.resultMessage);
156 result.show();
157 values.hide();
158 }
159 },
160 failure: function(response) {
161 console.log(response);
162 count++;
163 progress.updateProgress(count / me.selection.length);
164 if (count === me.selection.length) {
165 me.close();
166 }
167 }
168 });
169 }
170 }
171 });
172

http://lada.wald.intevation.org