oils_persist support for textbox values
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 6 Nov 2009 20:32:42 +0000 (20:32 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 6 Nov 2009 20:32:42 +0000 (20:32 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@14813 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js

index 4872a2f..dfdeaef 100644 (file)
                     var key = base_key + attribute_list[j];
                     var value = prefs.prefHasUserValue(key) ? prefs.getCharPref(key) : null;
                     dump('persist_helper: retrieving key = ' + key + ' value = ' + value + ' for ' + nodes[i].nodeName + '\n');
-                    if (value) nodes[i].setAttribute( attribute_list[j], value );
+                    if (value) {
+                        nodes[i].setAttribute( attribute_list[j], value );
+                        if (attribute_list[j]=='value') { nodes[i].value = value; }
+                    }
                 }
                 if ( (nodes[i].nodeName == 'checkbox' || nodes[i].nodeName == 'menuitem') && attribute_list.indexOf('checked') > -1) {
                     var cmd = nodes[i].getAttribute('command');
                             false
                         );
                     }
+                } else if ( (nodes[i].nodeName == 'textbox') && attribute_list.indexOf('value') > -1) {
+                    if (nodes[i].disabled == false && nodes[i].hidden == false) {
+                        var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
+                        if (no_poke && no_poke == 'true') {
+                            dump('\tpersist_helper: not poking element with key = ' + key + '\n');
+                        } else {
+                            dump('\tpersist_helper: poking element with key = ' + key + '\n');
+                            var evt = document.createEvent("Events");
+                            evt.initEvent( 'change', true, true );
+                            nodes[i].dispatchEvent(evt);
+                        }
+                    }
+                    nodes[i].addEventListener(
+                        'change',
+                        function(bk) {
+                            return function(ev) {
+                                try {
+                                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+                                    var key = bk + 'value';
+                                    var value = ev.target.value;
+                                    ev.target.setAttribute( 'value', value );
+                                    prefs.setCharPref( key, value );
+                                    dump('persist_helper: setting key = ' +  key + ' value = ' + value + ' for value\n');
+                                } catch(E) {
+                                    alert('Error in persist_helper(), textbox change event listener: ' + E);
+                                }
+                            };
+                        }(base_key), 
+                        false
+                    );
                 }
                 // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc.
             }