Status: | Needs review |
---|---|
Proposed branch: | lp:~sis-ma/dhis2/SISMA-33 |
Merge into: | lp:dhis2 |
Diff against target: |
358 lines (+231/-106) 1 file modified
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js (+231/-106) |
To merge this branch: | bzr merge lp:~sis-ma/dhis2/SISMA-33 |
Related bugs: | |
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
DHIS 2 core developers | Pending | ||
Review via email: mp+186322@code.launchpad.net |
Commit message
Description of the change
Read data inserted during temporarily offline mode.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js' |
2 | --- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-09-27 12:55:38 +0000 |
3 | +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-09-30 13:44:21 +0000 |
4 | @@ -1037,6 +1037,79 @@ |
5 | displayEntryFormCompleted(); |
6 | } |
7 | |
8 | +function insertOfflineDataValues(dataSetId, periodId, dataValueMap){ |
9 | + var formType = dataSets[dataSetId].type; |
10 | + |
11 | + $( '[name="entryfield"]' ).each( function( i ) |
12 | + { |
13 | + var id = $( this ).attr( 'id' ); |
14 | + |
15 | + var split = splitFieldId( id ); |
16 | + var dataElementId = split.dataElementId; |
17 | + var optionComboId = split.optionComboId; |
18 | + currentOrganisationUnitId = split.organisationUnitId; |
19 | + |
20 | + var elem = storageManager.getDataValue( dataElementId, optionComboId, periodId, currentOrganisationUnitId ); |
21 | + if (elem != null) |
22 | + { |
23 | + var fieldId = '#' + elem.dataElementId + '-' + elem.optionComboId + '-val'; |
24 | + |
25 | + if ( $( fieldId ).length > 0 ) // Insert for fixed input fields |
26 | + { |
27 | + if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' ) { |
28 | + $( fieldId ).attr('checked', true); |
29 | + } else { |
30 | + $( fieldId ).val( elem.value ); |
31 | + } |
32 | + } |
33 | + else // Insert for potential dynamic input fields |
34 | + { |
35 | + var dataElementId = elem.dataElementId; |
36 | + var optionComboId = elem.optionComboId; |
37 | + |
38 | + var selectElementId = '#' + getDynamicSelectElementId( dataElementId ); |
39 | + |
40 | + if ( $( selectElementId ).length == 0 ) |
41 | + { |
42 | + log( 'Could not find dynamic select element for data element: ' + dataElementId ); |
43 | + return true; |
44 | + } |
45 | + |
46 | + var code = $( selectElementId ).attr( 'id' ).split( '-' )[0]; |
47 | + |
48 | + if ( !isDefined( code ) ) |
49 | + { |
50 | + log( 'Could not find code on select element: ' + selectElementId ); |
51 | + return true; |
52 | + } |
53 | + |
54 | + var dynamicInputId = '#' + code + '-' + optionComboId + '-dyninput'; |
55 | + |
56 | + if ( $( dynamicInputId ).length == 0 ) |
57 | + { |
58 | + log( 'Could not find find dynamic input element for option combo: ' + optionComboId ); |
59 | + return true; |
60 | + } |
61 | + |
62 | + // Set data element in select list |
63 | + |
64 | + $( selectElementId ).val( dataElementId ); |
65 | + |
66 | + // Enable input fields and set value |
67 | + |
68 | + $( 'input[code="' + code + '"]' ).prop( 'disabled', false ); |
69 | + $( 'input[code="' + code + '"]' ).css( 'background-color', COLOR_WHITE ); |
70 | + |
71 | + $( dynamicInputId ).val( elem.val ); |
72 | + } |
73 | + |
74 | + dataValueMap[elem.dataElementId+'-'+elem.optionComboId] = elem.val |
75 | + } |
76 | + } |
77 | + ); |
78 | +} |
79 | + |
80 | + |
81 | function insertDataValues() |
82 | { |
83 | var dataValueMap = []; |
84 | @@ -1063,116 +1136,168 @@ |
85 | |
86 | $( '.entryfield' ).filter( ':disabled' ).css( 'background-color', COLOR_GREY ); |
87 | |
88 | - $.ajax( { |
89 | - url: 'getDataValues.action', |
90 | - data: |
91 | - { |
92 | - periodId : periodId, |
93 | - dataSetId : dataSetId, |
94 | - organisationUnitId : getCurrentOrganisationUnit(), |
95 | - multiOrganisationUnit: multiOrganisationUnit |
96 | - }, |
97 | - dataType: 'json', |
98 | - error: function() // offline |
99 | - { |
100 | - $( '#contentDiv' ).show(); |
101 | - $( '#completenessDiv' ).show(); |
102 | - $( '#infoDiv' ).hide(); |
103 | - }, |
104 | - success: function( json ) // online |
105 | - { |
106 | - if ( json.locked ) |
107 | - { |
108 | - $( '#contentDiv input').attr( 'readonly', 'readonly' ); |
109 | - $( '.entryoptionset').autocomplete( 'disable' ); |
110 | - $( '.sectionFilter').removeAttr( 'disabled' ); |
111 | - $( '#completenessDiv' ).hide(); |
112 | - setHeaderDelayMessage( i18n_dataset_is_locked ); |
113 | - } |
114 | - else |
115 | - { |
116 | - $( '.entryoptionset' ).autocomplete( 'enable' ); |
117 | - $( '#contentDiv input' ).removeAttr( 'readonly' ); |
118 | - $( '#completenessDiv' ).show(); |
119 | - } |
120 | - |
121 | - // Set data values, works for selects too as data value=select value |
122 | - |
123 | - $.safeEach( json.dataValues, function( i, value ) |
124 | - { |
125 | - var fieldId = '#' + value.id + '-val'; |
126 | - var commentId = '#' + value.id + '-comment'; |
127 | - |
128 | - if ( $( fieldId ).length > 0 ) // Set values |
129 | - { |
130 | - if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' && 'true' == value.val ) |
131 | - { |
132 | - $( fieldId ).attr( 'checked', true ); |
133 | - } |
134 | - else |
135 | - { |
136 | - $( fieldId ).val( value.val ); |
137 | - } |
138 | - } |
139 | - |
140 | - if ( 'true' == value.com ) // Set active comments |
141 | - { |
142 | - if ( $( commentId ).length > 0 ) |
143 | - { |
144 | - $( commentId ).attr( 'src', '../images/comment_active.png' ); |
145 | + //Validation if user is Online or Offline |
146 | + if(!dhis2.availability._isAvailable){ |
147 | + insertOfflineDataValues(dataSetId, periodId, dataValueMap); |
148 | + } else{ |
149 | + |
150 | + $.ajax( { |
151 | + url: 'getDataValues.action', |
152 | + data: |
153 | + { |
154 | + periodId : periodId, |
155 | + dataSetId : dataSetId, |
156 | + organisationUnitId : getCurrentOrganisationUnit(), |
157 | + multiOrganisationUnit: multiOrganisationUnit |
158 | + }, |
159 | + dataType: 'json', |
160 | + error: function() // offline |
161 | + { |
162 | + $( '#contentDiv' ).show(); |
163 | + $( '#completenessDiv' ).show(); |
164 | + $( '#infoDiv' ).hide(); |
165 | + }, |
166 | + success: function( json ) // online |
167 | + { |
168 | + if ( json.locked ) |
169 | + { |
170 | + $( '#contentDiv input').attr( 'readonly', 'readonly' ); |
171 | + $( '.entryoptionset').autocomplete( 'disable' ); |
172 | + $( '.sectionFilter').removeAttr( 'disabled' ); |
173 | + $( '#completenessDiv' ).hide(); |
174 | + setHeaderDelayMessage( i18n_dataset_is_locked ); |
175 | + } |
176 | + else |
177 | + { |
178 | + $( '.entryoptionset' ).autocomplete( 'enable' ); |
179 | + $( '#contentDiv input' ).removeAttr( 'readonly' ); |
180 | + $( '#completenessDiv' ).show(); |
181 | + } |
182 | + |
183 | + // Set data values, works for selects too as data value=select value |
184 | + |
185 | + $.safeEach( json.dataValues, function( i, value ) |
186 | + { |
187 | + var fieldId = '#' + value.id + '-val'; |
188 | + var commentId = '#' + value.id + '-comment'; |
189 | + |
190 | + if ( $( fieldId ).length > 0 ) // Set values |
191 | + { |
192 | + if ( $( fieldId ).attr( 'name' ) == 'entrytrueonly' && 'true' == value.val ) |
193 | + { |
194 | + $( fieldId ).attr( 'checked', true ); |
195 | + } |
196 | + else |
197 | + { |
198 | + $( fieldId ).val( value.val ); |
199 | + } |
200 | } |
201 | - else if ( $( fieldId ).length > 0 ) |
202 | + |
203 | + if ( 'true' == value.com ) // Set active comments |
204 | + { |
205 | + if ( $( commentId ).length > 0 ) |
206 | + { |
207 | + $( commentId ).attr( 'src', '../images/comment_active.png' ); |
208 | + |
209 | + |
210 | + |
211 | + |
212 | + |
213 | + |
214 | + |
215 | + |
216 | + |
217 | + |
218 | + |
219 | + |
220 | + |
221 | + |
222 | + |
223 | + |
224 | + |
225 | + |
226 | + |
227 | + |
228 | + |
229 | + |
230 | + |
231 | + |
232 | + |
233 | + |
234 | + |
235 | + |
236 | + |
237 | + |
238 | + |
239 | + |
240 | + |
241 | + |
242 | + } |
243 | + else if ( $( fieldId ).length > 0 ) |
244 | + { |
245 | + $( fieldId ).css( 'border-color', COLOR_BORDER_ACTIVE ) |
246 | + } |
247 | + } |
248 | + |
249 | + dataValueMap[value.id] = value.val; |
250 | + } ); |
251 | + |
252 | + // Set min-max values and colorize violation fields |
253 | + |
254 | + if( !json.locked ) |
255 | + { |
256 | + $.safeEach( json.minMaxDataElements, function( i, value ) |
257 | { |
258 | - $( fieldId ).css( 'border-color', COLOR_BORDER_ACTIVE ) |
259 | - } |
260 | + var minId = value.id + '-min'; |
261 | + var maxId = value.id + '-max'; |
262 | + |
263 | + var valFieldId = '#' + value.id + '-val'; |
264 | + |
265 | + var dataValue = dataValueMap[value.id]; |
266 | + |
267 | + if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number( |
268 | + value.min ) ) || ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) ) |
269 | + { |
270 | + $( valFieldId ).css( 'background-color', COLOR_ORANGE ); |
271 | + } |
272 | + |
273 | + currentMinMaxValueMap[minId] = value.min; |
274 | + currentMinMaxValueMap[maxId] = value.max; |
275 | + } ); |
276 | } |
277 | - |
278 | - dataValueMap[value.id] = value.val; |
279 | - } ); |
280 | - |
281 | - // Set min-max values and colorize violation fields |
282 | - |
283 | - if( !json.locked ) |
284 | - { |
285 | - $.safeEach( json.minMaxDataElements, function( i, value ) |
286 | - { |
287 | - var minId = value.id + '-min'; |
288 | - var maxId = value.id + '-max'; |
289 | - |
290 | - var valFieldId = '#' + value.id + '-val'; |
291 | - |
292 | - var dataValue = dataValueMap[value.id]; |
293 | - |
294 | - if ( dataValue && ( ( value.min && new Number( dataValue ) < new Number( |
295 | - value.min ) ) || ( value.max && new Number( dataValue ) > new Number( value.max ) ) ) ) |
296 | - { |
297 | - $( valFieldId ).css( 'background-color', COLOR_ORANGE ); |
298 | - } |
299 | - |
300 | - currentMinMaxValueMap[minId] = value.min; |
301 | - currentMinMaxValueMap[maxId] = value.max; |
302 | - } ); |
303 | - } |
304 | - |
305 | - // Update indicator values in form |
306 | - |
307 | - updateIndicators(); |
308 | - updateDataElementTotals(); |
309 | - |
310 | - // Set completeness button |
311 | - |
312 | - if ( json.complete && !json.locked) |
313 | - { |
314 | - $( '#completeButton' ).attr( 'disabled', 'disabled' ); |
315 | - $( '#undoButton' ).removeAttr( 'disabled' ); |
316 | - |
317 | - if ( json.storedBy ) |
318 | + |
319 | + // Update indicator values in form |
320 | + |
321 | + updateIndicators(); |
322 | + updateDataElementTotals(); |
323 | + |
324 | + // Set completeness button |
325 | + |
326 | + if ( json.complete && !json.locked) |
327 | + { |
328 | + $( '#completeButton' ).attr( 'disabled', 'disabled' ); |
329 | + $( '#undoButton' ).removeAttr( 'disabled' ); |
330 | + |
331 | + if ( json.storedBy ) |
332 | + { |
333 | + $( '#infoDiv' ).show(); |
334 | + $( '#completedBy' ).html( json.storedBy ); |
335 | + $( '#completedDate' ).html( json.date ); |
336 | + |
337 | + currentCompletedByUser = json.storedBy; |
338 | + } |
339 | + } |
340 | + else |
341 | + { |
342 | + $( '#completeButton' ).removeAttr( 'disabled' ); |
343 | + $( '#undoButton' ).attr( 'disabled', 'disabled' ); |
344 | + $( '#infoDiv' ).hide(); |
345 | + } |
346 | + |
347 | + if ( json.locked ) |
348 | { |
349 | - $( '#infoDiv' ).show(); |
350 | - $( '#completedBy' ).html( json.storedBy ); |
351 | - $( '#completedDate' ).html( json.date ); |
352 | - |
353 | - currentCompletedByUser = json.storedBy; |
354 | + $( '#contentDiv input' ).css( 'backgroundColor', '#eee' ); |
355 | + $( '.sectionFilter' ).css( 'backgroundColor', '#fff' ); |
356 | } |
357 | } |
358 | else |