Commit f9ad9ff43e3bd577a1aa49f1bd2e501933d179f0

Authored by Megan Watson
1 parent a56cfc9c

KTC-524

"When Editing Fieldset Rules for Conditional Fieldset, clicking edit field displays incorrect control/dependent group, inconsistent with configured Field Ordering"
Fixed. Removed the stack.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9034 c91229c3-7414-0410-bfa2-8a42b809f60b
resources/js/conditional_simple_edit.js
1 /* Model Functions 1 /* Model Functions
2 * 2 *
3 - * Perform various and sundry operations on the edit-page. 3 + * Perform various and sundry operations on the edit-page.
4 */ 4 */
5 5
6 6
@@ -44,7 +44,7 @@ function setActiveFields(active_fields) { @@ -44,7 +44,7 @@ function setActiveFields(active_fields) {
44 var column = getColumnForField(active_fields[i]); 44 var column = getColumnForField(active_fields[i]);
45 setElementClass(column, 'active'); 45 setElementClass(column, 'active');
46 } 46 }
47 - 47 +
48 } 48 }
49 49
50 // takes a field, and sets all items in active_lookups to be active. other items are deleted. 50 // takes a field, and sets all items in active_lookups to be active. other items are deleted.
@@ -94,17 +94,17 @@ function getActiveLookups() { @@ -94,17 +94,17 @@ function getActiveLookups() {
94 } 94 }
95 } 95 }
96 } 96 }
97 - } 97 + }
98 return active_lookups; 98 return active_lookups;
99 } 99 }
100 100
101 /** Simple edit: AJAX component */ 101 /** Simple edit: AJAX component */
102 // extract the "fixed" field, and identify which fields (if any) are active. 102 // extract the "fixed" field, and identify which fields (if any) are active.
103 function updateActiveFields() { 103 function updateActiveFields() {
104 - 104 +
105 simpleLog('DEBUG','function updateActiveFields called.'); 105 simpleLog('DEBUG','function updateActiveFields called.');
106 var req = getXMLHttpRequest(); 106 var req = getXMLHttpRequest();
107 - 107 +
108 req.open('GET',getTargetUrl()+'?action=updateActiveFields&active_field='+current_fixed, true); 108 req.open('GET',getTargetUrl()+'?action=updateActiveFields&active_field='+current_fixed, true);
109 var deferred = sendXMLHttpRequest(req); 109 var deferred = sendXMLHttpRequest(req);
110 deferred.addCallback(do_updateActiveFields); 110 deferred.addCallback(do_updateActiveFields);
@@ -117,7 +117,7 @@ function do_handleAjaxError(err_source, err) { @@ -117,7 +117,7 @@ function do_handleAjaxError(err_source, err) {
117 117
118 // from a selected_lookup, get the fixed_field and pass through, getting the items that selection currently activates. 118 // from a selected_lookup, get the fixed_field and pass through, getting the items that selection currently activates.
119 function updateActiveLookups(selected_lookup, lookup_label) { 119 function updateActiveLookups(selected_lookup, lookup_label) {
120 - 120 +
121 simpleLog('DEBUG','function updateActiveLookups called.'); 121 simpleLog('DEBUG','function updateActiveLookups called.');
122 var req = getXMLHttpRequest(); 122 var req = getXMLHttpRequest();
123 req.open('GET',getTargetUrl()+'?action=updateActiveLookups&active_field='+current_fixed+'&selected_lookup='+selected_lookup, true); 123 req.open('GET',getTargetUrl()+'?action=updateActiveLookups&active_field='+current_fixed+'&selected_lookup='+selected_lookup, true);
@@ -127,9 +127,9 @@ function updateActiveLookups(selected_lookup, lookup_label) { @@ -127,9 +127,9 @@ function updateActiveLookups(selected_lookup, lookup_label) {
127 } 127 }
128 128
129 // send a "save" request to the backend, asking it to make the child_lookups the only items parented 129 // send a "save" request to the backend, asking it to make the child_lookups the only items parented
130 -// to the selected_lookup (include field_id for selected, and fieldset). 130 +// to the selected_lookup (include field_id for selected, and fieldset).
131 function storeRelationship(selected_lookup, child_lookups) { 131 function storeRelationship(selected_lookup, child_lookups) {
132 - 132 +
133 var formKeys = Array(); 133 var formKeys = Array();
134 var formValues = Array(); 134 var formValues = Array();
135 135
@@ -170,7 +170,7 @@ function storeRelationship(selected_lookup, child_lookups) { @@ -170,7 +170,7 @@ function storeRelationship(selected_lookup, child_lookups) {
170 // inform the user that something has happened. 170 // inform the user that something has happened.
171 // FIXME this isn't i18n friendly. 171 // FIXME this isn't i18n friendly.
172 addInformationNote(_('Dependencies saved. (at ') + new Date() + ')'); 172 addInformationNote(_('Dependencies saved. (at ') + new Date() + ')');
173 - 173 +
174 deferred.addCallback(do_updateActiveLookups); 174 deferred.addCallback(do_updateActiveLookups);
175 deferred.addErrback(partial(do_handleAjaxError, 'storeRelationship')); 175 deferred.addErrback(partial(do_handleAjaxError, 'storeRelationship'));
176 } 176 }
@@ -185,7 +185,7 @@ function addInformationNote(message) { @@ -185,7 +185,7 @@ function addInformationNote(message) {
185 var sH = secondHeaders[0]; 185 var sH = secondHeaders[0];
186 contentBox.insertBefore(dynamicMessage, sH); 186 contentBox.insertBefore(dynamicMessage, sH);
187 } 187 }
188 - 188 +
189 var newStr = createDOM('P',null,message); 189 var newStr = createDOM('P',null,message);
190 replaceChildNodes(dynamicMessage, newStr); 190 replaceChildNodes(dynamicMessage, newStr);
191 } 191 }
@@ -197,20 +197,20 @@ function do_updateActiveFields(req) { @@ -197,20 +197,20 @@ function do_updateActiveFields(req) {
197 var incoming_fields = req.responseXML.getElementsByTagName('active'); 197 var incoming_fields = req.responseXML.getElementsByTagName('active');
198 for (var i=0; i<incoming_fields.length; i++) { 198 for (var i=0; i<incoming_fields.length; i++) {
199 active_fields.push(incoming_fields[i].getAttribute('field_id')); 199 active_fields.push(incoming_fields[i].getAttribute('field_id'));
200 - } 200 + }
201 simpleLog('DEBUG','do_updateActiveFields found active fields: '+repr(active_fields)); 201 simpleLog('DEBUG','do_updateActiveFields found active fields: '+repr(active_fields));
202 setActiveFields(active_fields); 202 setActiveFields(active_fields);
203 } 203 }
204 204
205 -// should receive a simple-enough set of "field" elements,  
206 -// filled with "lookup" items. 205 +// should receive a simple-enough set of "field" elements,
  206 +// filled with "lookup" items.
207 function do_updateActiveLookups(label, req) { 207 function do_updateActiveLookups(label, req) {
208 simpleLog('DEBUG','AJAX function do_updateActiveLookups triggered'); 208 simpleLog('DEBUG','AJAX function do_updateActiveLookups triggered');
209 var active_fields = Array(); 209 var active_fields = Array();
210 var incoming_fields = req.responseXML.getElementsByTagName('field'); 210 var incoming_fields = req.responseXML.getElementsByTagName('field');
211 for (var i=0; i<incoming_fields.length; i++) { 211 for (var i=0; i<incoming_fields.length; i++) {
212 var field = incoming_fields[i]; 212 var field = incoming_fields[i];
213 - 213 +
214 var field_id = field.getAttribute('field_id'); 214 var field_id = field.getAttribute('field_id');
215 simpleLog('DEBUG','found field: '+field_id); 215 simpleLog('DEBUG','found field: '+field_id);
216 var infoset = {'field_id':field_id, 'lookups':new Array()}; 216 var infoset = {'field_id':field_id, 'lookups':new Array()};
@@ -228,7 +228,7 @@ function do_updateActiveLookups(label, req) { @@ -228,7 +228,7 @@ function do_updateActiveLookups(label, req) {
228 setActiveLookupsForField(active_fields[i].field_id, active_fields[i].lookups); 228 setActiveLookupsForField(active_fields[i].field_id, active_fields[i].lookups);
229 } 229 }
230 } 230 }
231 - 231 +
232 addInformationNote(_('Dependencies for value "')+label+('" loaded.(at ') + new Date() + ')'); 232 addInformationNote(_('Dependencies for value "')+label+('" loaded.(at ') + new Date() + ')');
233 } 233 }
234 234
@@ -253,7 +253,7 @@ function setExclusiveEditing(field_id) { @@ -253,7 +253,7 @@ function setExclusiveEditing(field_id) {
253 var column = getColumnForField(field_id); 253 var column = getColumnForField(field_id);
254 simpleLog('DEBUG','setExclusiveEditing found column' + column + ' for id ' + field_id); 254 simpleLog('DEBUG','setExclusiveEditing found column' + column + ' for id ' + field_id);
255 setElementClass(column, 'active editing'); 255 setElementClass(column, 'active editing');
256 - var item_list = getElementsByTagAndClassName('SELECT','item_list',column)[0]; // FIXME catch potential failure here (pathalogical) 256 + var item_list = getElementsByTagAndClassName('SELECT','item_list',column)[0]; // FIXME catch potential failure here (pathalogical)
257 item_list.multiple = false; 257 item_list.multiple = false;
258 updateNodeAttributes(item_list, {'onchange':partial(handleChangedSelection, field_id, item_list)}); 258 updateNodeAttributes(item_list, {'onchange':partial(handleChangedSelection, field_id, item_list)});
259 259
@@ -287,8 +287,8 @@ function saveSimpleField(field_id) { @@ -287,8 +287,8 @@ function saveSimpleField(field_id) {
287 if (item_list_select.length == 0) { 287 if (item_list_select.length == 0) {
288 simpleLog('ERROR','no item_list select found in field '+field_id); 288 simpleLog('ERROR','no item_list select found in field '+field_id);
289 return false; 289 return false;
290 - }  
291 - // else 290 + }
  291 + // else
292 var selected_lookup = item_list_select[0].value; 292 var selected_lookup = item_list_select[0].value;
293 simpleLog('DEBUG','extracted selected lookup of '+selected_lookup); 293 simpleLog('DEBUG','extracted selected lookup of '+selected_lookup);
294 294
@@ -318,8 +318,11 @@ function handleChangedSelection(field_id, select_input) { @@ -318,8 +318,11 @@ function handleChangedSelection(field_id, select_input) {
318 var undoStack = Array(); // stores the field_ids. 318 var undoStack = Array(); // stores the field_ids.
319 var current_fixed = null; // current fixed. saves a bit of time... 319 var current_fixed = null; // current fixed. saves a bit of time...
320 function pushUndoStack(field_id) { 320 function pushUndoStack(field_id) {
321 - simpleLog('DEBUG','untested function pushUndoStack called.');  
322 - if (current_fixed == null) { 321 + current_fixed = field_id;
  322 + return false;
  323 +
  324 + simpleLog('DEBUG','untested function pushUndoStack called.');
  325 + if (current_fixed == null) {
323 current_fixed = field_id; 326 current_fixed = field_id;
324 return false; 327 return false;
325 // pre-initialisation. 328 // pre-initialisation.
@@ -332,23 +335,23 @@ function pushUndoStack(field_id) { @@ -332,23 +335,23 @@ function pushUndoStack(field_id) {
332 } else { 335 } else {
333 return false; // pass 336 return false; // pass
334 } 337 }
335 - simpleLog('DEBUG','undoStack is now: '+repr(undoStack)); 338 + simpleLog('DEBUG','undoStack is now: '+repr(undoStack));
336 current_fixed=field_id; 339 current_fixed=field_id;
337 } 340 }
338 341
339 -function popUndoStack() {  
340 - simpleLog('DEBUG','function popUndoStack called.'); 342 +function popUndoStack() {
  343 + simpleLog('DEBUG','function popUndoStack called.');
341 if (undoStack.length == 0 ) { 344 if (undoStack.length == 0 ) {
342 - simpleLog('ERROR','undo stack popped at 0. This should be impossible'); 345 + simpleLog('ERROR','undo stack popped at 0. This should be impossible');
343 return false; 346 return false;
344 } 347 }
345 var targetFixed = undoStack.pop(); 348 var targetFixed = undoStack.pop();
346 current_fixed = targetFixed; 349 current_fixed = targetFixed;
347 setExclusiveEditing(targetFixed); 350 setExclusiveEditing(targetFixed);
348 - updateActiveFields(); // trigger an update of the backend. 351 + updateActiveFields(); // trigger an update of the backend.
349 if (undoStack.length == 0) { 352 if (undoStack.length == 0) {
350 undoStack.push(targetFixed); 353 undoStack.push(targetFixed);
351 - simpleLog('ERROR','undo stack popped to 0, re-pushing this last item. '); 354 + simpleLog('ERROR','undo stack popped to 0, re-pushing this last item. ');
352 } 355 }
353 - simpleLog('DEBUG','undoStack is now: '+repr(undoStack)); 356 + simpleLog('DEBUG','undoStack is now: '+repr(undoStack));
354 } 357 }
templates/ktcore/metadata/conditional/editsimple.smarty
@@ -20,10 +20,10 @@ td { vertical-align: top; } @@ -20,10 +20,10 @@ td { vertical-align: top; }
20 .buttonset.inactive { background: transparent; } 20 .buttonset.inactive { background: transparent; }
21 21
22 .inactive { background: #ccc; } 22 .inactive { background: #ccc; }
23 -.inactive .fixed_message, 23 +.inactive .fixed_message,
24 .inactive .unassigned_items, 24 .inactive .unassigned_items,
25 .inactive .available_behaviours, 25 .inactive .available_behaviours,
26 -.inactive .behaviour_edit_options 26 +.inactive .behaviour_edit_options
27 { 27 {
28 display: none; 28 display: none;
29 } 29 }
@@ -61,9 +61,9 @@ addLoadEvent(partial(editSimpleField, {$iMasterFieldId})); @@ -61,9 +61,9 @@ addLoadEvent(partial(editSimpleField, {$iMasterFieldId}));
61 61
62 <h2>{i18n}Editing Fieldset Rules (Simple){/i18n}</h2> 62 <h2>{i18n}Editing Fieldset Rules (Simple){/i18n}</h2>
63 63
64 -<p class="descriptiveText">{i18n}To make a value in a <strong>child field</strong> available to the user when another value is  
65 -selected in a <strong>parent field</strong>, first ensure that the parent field is being edited (it will have "save" and "done"  
66 -as the buttons at the bottom of the column) and then select the value for the parent field. Now select the value(s) in 64 +<p class="descriptiveText">{i18n}To make a value in a <strong>child field</strong> available to the user when another value is
  65 +selected in a <strong>parent field</strong>, first ensure that the parent field is being edited (it will have "save" and "done"
  66 +as the buttons at the bottom of the column) and then select the value for the parent field. Now select the value(s) in
67 the child column(s) you wish to be available to the user when the parent field's value is selected, 67 the child column(s) you wish to be available to the user when the parent field's value is selected,
68 and click "save". Note you that you can use Ctrl-&lt;click&gt; to select multiple child values 68 and click "save". Note you that you can use Ctrl-&lt;click&gt; to select multiple child values
69 at the same time.{/i18n}</p> 69 at the same time.{/i18n}</p>
@@ -98,7 +98,7 @@ refresh the page.{/i18n}&lt;/p&gt; @@ -98,7 +98,7 @@ refresh the page.{/i18n}&lt;/p&gt;
98 </div> 98 </div>
99 </td> 99 </td>
100 {/foreach} 100 {/foreach}
101 - 101 +
102 </tr> 102 </tr>
103 </tbody> 103 </tbody>
104 <tfoot> 104 <tfoot>
@@ -108,12 +108,9 @@ refresh the page.{/i18n}&lt;/p&gt; @@ -108,12 +108,9 @@ refresh the page.{/i18n}&lt;/p&gt;
108 <div class="form_actions">{capture assign=fid}{$oField->getId()}{/capture} 108 <div class="form_actions">{capture assign=fid}{$oField->getId()}{/capture}
109 {if (!empty($ordering.$fid))}<input type="button" value="{i18n}edit field{/i18n}" class="edit_button" onclick="editSimpleField({$oField->getId()})" />{/if} 109 {if (!empty($ordering.$fid))}<input type="button" value="{i18n}edit field{/i18n}" class="edit_button" onclick="editSimpleField({$oField->getId()})" />{/if}
110 <input type="button" value="{i18n}save this dependency{/i18n}" class="save_button" onclick="saveSimpleField({$oField->getId()})" /> 110 <input type="button" value="{i18n}save this dependency{/i18n}" class="save_button" onclick="saveSimpleField({$oField->getId()})" />
111 - {if ($iMasterFieldId != $oField->getId())} {* Only for non-initial fields. *}  
112 - <input type="button" value="{i18n}finished with this field{/i18n}" class="done_button" onclick="finishSimpleField({$oField->getId()})" />  
113 - {/if}  
114 </div> 111 </div>
115 </td> 112 </td>
116 -{/foreach} 113 +{/foreach}
117 </tr> 114 </tr>
118 </tfoot> 115 </tfoot>
119 </table> 116 </table>