Remember MARC Template selection
authorThomas Berezansky <tsbere@mvlc.org>
Wed, 14 Sep 2011 17:37:27 +0000 (13:37 -0400)
committerDan Scott <dscott@laurentian.ca>
Mon, 17 Oct 2011 17:32:51 +0000 (13:32 -0400)
Implement both a workstation default and "last used" for the MARC template
selector.

Workstation default is set with a new "Set Workstation Default" button.

"Last used" will override the workstation default, and is updated every
time you load a template. It is forgotten when you close the client.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/web/opac/locale/en-US/lang.dtd
Open-ILS/xul/staff_client/server/cat/marc_new.xul
Open-ILS/xul/staff_client/server/locale/en-US/cat.properties

index 4714957..741b58d 100644 (file)
 <!ENTITY staff.cat.marcedit.source.submit.label "Update source">
 <!ENTITY staff.cat.marc_new.load.label "Load">
 <!ENTITY staff.cat.marc_new.load.accesskey "L">
+<!ENTITY staff.cat.marc_new.set_default.label "Set Workstation Default">
+<!ENTITY staff.cat.marc_new.set_default.accesskey "S">
 <!ENTITY staff.cat.marc_view.title "MARC View">
 <!ENTITY staff.cat.opac.menuitem.opacview.label "OPAC View">
 <!ENTITY staff.cat.opac.menuitem.opacview.accesskey "O">
index 633d047..859f410 100644 (file)
 
                 var templates = g.network.simple_request('MARC_XML_TEMPLATE_LIST',[]);
                 if (typeof templates.ilsevent != 'undefined') throw(templates);
+                var default_template;
+                g.prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
+                var default_template_key = 'oils.marc_new.default_template';
+                if(g.data.last_marc_template) default_template = g.data.last_marc_template;
+                if(!default_template) {
+                    var has_key = g.prefs.prefHasUserValue(default_template_key);
+                    if(has_key) default_template = g.prefs.getCharPref(default_template_key);
+                }
                 var ml = util.widgets.make_menulist(
                     util.functional.map_list(
                         templates.sort(),
                         function(el) {
                             return [ el /* The menu entry label */, el /* The menu entry value */ ];
                         }
-                    )
+                    ), default_template
                 );
                 $('menu_placeholder').appendChild(ml);
 
                                 [ template_name ]
                             );
                             if (typeof marc.ilsevent != 'undefined') throw(marc);
-    
+
+                            g.data.stash_retrieve();
+                            g.data.last_marc_template = template_name;
+                            g.data.stash('last_marc_template');
+
                             var url = urls.XUL_MARC_EDIT;
                             var params = {
                                 'record' : { 'marc' : marc },
                     false
                 );
 
+                $('set_default').addEventListener(
+                    'command',
+                    function(ev) {
+                        var template_name;
+                        try {
+                            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+                            template_name = $('menu_placeholder').firstChild.value;
+                            g.prefs.setCharPref(default_template_key, template_name);
+                            alert(catStrings.getFormattedString('staff.cat.marc_new.set_default.success', [template_name]));
+                        } catch (E) {
+                            g.error.standard_unexpected_error_alert(
+                                catStrings.getFormattedString('staff.cat.marc_new.set_default.error', [template_name]), E
+                            );
+                        }
+                    },
+                    false
+                );
+
             } catch(E) {
                 g.error.standard_unexpected_error_alert('cat/marc_new.xul',E);
             }
         <hbox id="actions">
             <hbox id="menu_placeholder" />
             <button id="load" label="&staff.cat.marc_new.load.label;" accesskey="&staff.cat.marc_new.load.accesskey;"/>
+            <button id="set_default" label="&staff.cat.marc_new.set_default.label;" accesskey="&staff.cat.marc_new.set_default.accesskey;"/>
         </hbox>
     </vbox>
 
index 79807a5..3e8b411 100644 (file)
@@ -274,6 +274,8 @@ staff.cat.marc_new.system_local.label=System Local
 staff.cat.marc_new.retrieving.label=Retrieving title...
 staff.cat.marc_new.creating_record.error=Error creating MARC record.
 staff.cat.marc_new.loading_template.error=Error loading MARC template: %1$s
+staff.cat.marc_new.set_default.error=Error setting default MARC template: %1$s
+staff.cat.marc_new.set_default.success=Default template set to %1$s
 staff.cat.opac.set_marc_edit.alert=Record successfully saved.
 staff.cat.opac.set_marc_edit.std_unexpected_error=Record not likely updated.
 staff.cat.opac.refresh.function_not_implemented.alert=Not yet implemented.  Work around: Choose Duplicate in New Tab option