Make spine label settings configurable as org unit settings
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 26 Aug 2010 00:16:11 +0000 (00:16 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 26 Aug 2010 00:16:11 +0000 (00:16 +0000)
Note that due to the persist attribute on these XUL elements, a user
who has manually changed their spine label settings may not see the
org unit setting defaults for those particular settings if those
org unit settings are created or changed.

Now that the infrastructure is in place, We could make the org unit
settings take precedence over the persisted attributes if we think
that's the right way to go.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@17341 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/0380.data.spine_label.sql [new file with mode: 0644]
Open-ILS/xul/staff_client/server/cat/spine_labels.js
Open-ILS/xul/staff_client/server/cat/spine_labels.xul

index 46cfd93..cf7c4cb 100644 (file)
@@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0379'); -- phasefx
+INSERT INTO config.upgrade_log (version) VALUES ('0380'); -- dbs
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index a11e088..8ee21df 100644 (file)
@@ -6664,3 +6664,56 @@ INSERT INTO config.org_unit_setting_type ( name, label, description, datatype, f
         'ccs'
 );
 
+-- 0380.data.spine_label.sql Add spine label preferences
+INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
+    VALUES
+        ('cat.spine.font.size',
+            oils_i18n_gettext('cat.spine.font.size',
+                'Cataloging: Spine label font size', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.font.size',
+                'Set the default font size for spine labels', 'coust', 'description'),
+            'integer'
+        )
+        ,('cat.spine.font.family',
+            oils_i18n_gettext('cat.spine.font.family',
+                'Cataloging: Spine label font family', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.font.family',
+                'Set the preferred font family for spine labels. You can specify a list of fonts, separated by commas, in order of preference; the system will use the first font it finds with a matching name. For example, "Arial, Helvetica, serif".',
+                'coust', 'description'),
+            'string'
+        )
+        ,('cat.spine.line.width',
+            oils_i18n_gettext('cat.spine.line.width',
+                'Cataloging: Spine label line width', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.line.width',
+                'Set the default line width for spine labels in number of characters. This specifies the boundary at which lines must be wrapped.',
+                'coust', 'description'),
+            'integer'
+        )
+        ,('cat.spine.line.height',
+            oils_i18n_gettext('cat.spine.line.height',
+                'Cataloging: Spine label maximum lines', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.line.height',
+                'Set the default maximum number of lines for spine labels.',
+                'coust', 'description'),
+            'integer'
+        )
+        ,('cat.spine.line.margin',
+            oils_i18n_gettext('cat.spine.line.margin',
+                'Cataloging: Spine label left margin', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.line.margin',
+                'Set the left margin for spine labels in number of characters.',
+                'coust', 'description'),
+            'integer'
+        )
+;
+
+INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES
+    (1, 'cat.spine.line.margin', 0)
+    ,(1, 'cat.spine.line.height', 9)
+    ,(1, 'cat.spine.line.width', 8)
+    ,(1, 'cat.label.font.family', '"monospace"')
+    ,(1, 'cat.label.font.size', 10)
+;
+
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/0380.data.spine_label.sql b/Open-ILS/src/sql/Pg/upgrade/0380.data.spine_label.sql
new file mode 100644 (file)
index 0000000..76ef2d0
--- /dev/null
@@ -0,0 +1,56 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0380'); -- dbs
+
+INSERT INTO config.org_unit_setting_type (name, label, description, datatype)
+    VALUES
+        ('cat.spine.font.size',
+            oils_i18n_gettext('cat.spine.font.size',
+                'Cataloging: Spine label font size', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.font.size',
+                'Set the default font size for spine labels', 'coust', 'description'),
+            'integer'
+        )
+        ,('cat.spine.font.family',
+            oils_i18n_gettext('cat.spine.font.family',
+                'Cataloging: Spine label font family', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.font.family',
+                'Set the preferred font family for spine labels. You can specify a list of fonts, separated by commas, in order of preference; the system will use the first font it finds with a matching name. For example, "Arial, Helvetica, serif".',
+                'coust', 'description'),
+            'string'
+        )
+        ,('cat.spine.line.width',
+            oils_i18n_gettext('cat.spine.line.width',
+                'Cataloging: Spine label line width', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.line.width',
+                'Set the default line width for spine labels in number of characters. This specifies the boundary at which lines must be wrapped.',
+                'coust', 'description'),
+            'integer'
+        )
+        ,('cat.spine.line.height',
+            oils_i18n_gettext('cat.spine.line.height',
+                'Cataloging: Spine label maximum lines', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.line.height',
+                'Set the default maximum number of lines for spine labels.',
+                'coust', 'description'),
+            'integer'
+        )
+        ,('cat.spine.line.margin',
+            oils_i18n_gettext('cat.spine.line.margin',
+                'Cataloging: Spine label left margin', 'coust', 'label'),
+            oils_i18n_gettext('cat.spine.line.margin',
+                'Set the left margin for spine labels in number of characters.',
+                'coust', 'description'),
+            'integer'
+        )
+;
+
+INSERT INTO actor.org_unit_setting (org_unit, name, value) VALUES
+    (1, 'cat.spine.line.margin', 0)
+    ,(1, 'cat.spine.line.height', 9)
+    ,(1, 'cat.spine.line.width', 8)
+    ,(1, 'cat.label.font.family', '"monospace"')
+    ,(1, 'cat.label.font.size', 10)
+;
+
+COMMIT;
index 5094591..1be57e8 100644 (file)
                 JSAN.use('util.widgets');
                 var pn = $('panel');
                 $('preview').disabled = false;
-                var lw = Number($('lw').value) || 8; /* spine label width */
-                var ll = Number($('ll').value) || 9; /* spine label length */
-                var plw = Number($('plw').value) || 28; /* pocket label width */
-                var pll = Number($('pll').value) || 9; /* pocket label length */
+
+                /* Grab from OU settings, then fall back to hardcoded defaults */
+                var label_cfg = {};
+                label_cfg.spine_width = Number($('lw').value); /* spine label width */
+                if (!label_cfg.spine_width) {
+                    label_cfg.spine_width = g.data.hash.aous['cat.spine.line.width'] || 8;
+                    $('lw').value = label_cfg.spine_width;
+                }
+                label_cfg.spine_length = Number($('ll').value); /* spine label length */
+                if (!label_cfg.spine_length) {
+                    label_cfg.spine_length = g.data.hash.aous['cat.spine.line.height'] || 9;
+                    $('ll').value = label_cfg.spine_length;
+                }
+                label_cfg.spine_left_margin = Number($('lm').value); /* left margin */
+                if (!label_cfg.spine_left_margin) {
+                    label_cfg.spine_left_margin = g.data.hash.aous['cat.spine.line.margin'] || 11;
+                    $('lm').value = label_cfg.spine_left_margin;
+                }
+                label_cfg.font_size = Number( $('pt').value );  /* font size */
+                if (!label_cfg.font_size) {
+                    label_cfg.font_size = g.data.hash.aous['cat.label.font.size'] || 10;
+                    $('pt').value = label_cfg.font_size;
+                }
+                label_cfg.font_family = g.data.hash.aous['cat.label.font.family'] || 'monospace';
+                label_cfg.pocket_width = Number($('plw').value) || 28; /* pocket label width */
+                label_cfg.pocket_length = Number($('pll').value) || 9; /* pocket label length */
 
                 if (override) {
                     var gb = $('acn_' + g.volumes[override.acn].id());
                     util.widgets.remove_children('acn_' + g.volumes[override.acn].id());
-                    generate_labels(g.volumes[override.acn], gb, lw, ll, plw, pll, override);
+                    generate_labels(g.volumes[override.acn], gb, label_cfg, override);
                 } else {
                     util.widgets.remove_children('panel');
                     for (var i in g.volumes) {
                         hb.appendChild(gb); 
                         gb.setAttribute('id','acn_' + g.volumes[i].id());
 
-                        generate_labels(g.volumes[i], gb, lw, ll, plw, pll, override);
+                        generate_labels(g.volumes[i], gb, label_cfg, override);
 
                         idx++;
                     }
             }
         }
 
-        function generate_labels(volume, label_node, spine_width, spine_max_lines, pocket_width, pocket_max_lines, override) {
+        function generate_labels(volume, label_node, label_cfg, override) {
             var names;
 
             if (override && volume.id() == override.acn) {
                 names = String(volume.label()).split(/\s+/);
             }
             var j = 0;
-            while (j < spine_max_lines || j < pocket_max_lines) {
+            while (j < label_cfg.spine_length || j < label_cfg.pocket_length) {
                 var hb2 = document.createElement('hbox'); label_node.appendChild(hb2);
                 
                 /* spine */
-                if (j < spine_max_lines) {
+                if (j < label_cfg.spine_length) {
                     var tb = document.createElement('textbox'); hb2.appendChild(tb); 
                     tb.value = '';
                     tb.setAttribute('class','plain');
-                    tb.setAttribute('style','font-family: monospace');
-                    tb.setAttribute('size',spine_width+1);
-                    tb.setAttribute('maxlength',spine_width);
+                    tb.setAttribute('style','font-family: ' + label_cfg.font_family + '; font-size: ' + label_cfg.font_size);
+                    tb.setAttribute('size',label_cfg.spine_width+1);
+                    tb.setAttribute('maxlength',label_cfg.spine_width);
                     tb.setAttribute('name','spine');
                     var spine_row_id = 'acn_' + volume.id() + '_spine_' + j;
                     tb.setAttribute('id',spine_row_id);
                     if (name) {
                         name = String( name );
                         /* if the name is greater than the label width... */
-                        if (name.length > spine_width) {
+                        if (name.length > label_cfg.spine_width) {
                             /* then try to split it on periods */
                             var sname = name.split(/\./);
                             if (sname.length > 1) {
                                 /* and put all but the first one back into the names array */
                                 names = sname.slice(1).concat( names );
                                 /* if the name fragment is still greater than the label width... */
-                                if (sname[0].length > spine_width) {
+                                if (sname[0].length > label_cfg.spine_width) {
                                     /* then just truncate and throw the rest back into the names array */
-                                    tb.value = sname[0].substr(0,spine_width);
-                                    names = [ sname[0].substr(spine_width) ].concat( names );
+                                    tb.value = sname[0].substr(0,label_cfg.spine_width);
+                                    names = [ sname[0].substr(label_cfg.spine_width) ].concat( names );
                                 } else {
                                     /* otherwise we're set */
                                     tb.value = sname[0];
                                 }
                             } else {
                                 /* if we can't split on periods, then just truncate and throw the rest back into the names array */
-                                tb.value = name.substr(0,spine_width);
-                                names = [ name.substr(spine_width) ].concat( names );
+                                tb.value = name.substr(0,label_cfg.spine_width);
+                                names = [ name.substr(label_cfg.spine_width) ].concat( names );
                             }
                         } else {
                             /* otherwise we're set */
                 }
 
                 /* pocket */
-                if ($('pl').checked && j < pocket_max_lines) {
+                if ($('pl').checked && j < label_cfg.pocket_length) {
                     var tb2 = document.createElement('textbox'); hb2.appendChild(tb2); 
                     tb2.value = '';
-                    tb2.setAttribute('class','plain'); tb2.setAttribute('style','font-family: monospace');
-                    tb2.setAttribute('size',pocket_width+1); tb2.setAttribute('maxlength',pocket_width);
+                    tb2.setAttribute('class','plain'); tb2.setAttribute('style','font-family: ' + label_cfg.font_family + '; font-size: ' + label_cfg.font_size);
+                    tb2.setAttribute('size',label_cfg.pocket_width+1); tb2.setAttribute('maxlength',label_cfg.pocket_width);
                     tb2.setAttribute('name','pocket');
                     if ($('title').checked && $('title_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
                         if (volume.record().title()) {
-                            tb2.value = util.text.wrap_on_space( volume.record().title(), pocket_width )[0];
+                            tb2.value = util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[0];
                         } else {
                             tb2.value = '';
                         }
                     }
                     if ($('title_r').checked && $('title_r_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
                         if (volume.record().title()) {
-                            tb2.value = ( ($('title_r_indent').checked ? ' ' : '') + util.text.wrap_on_space( volume.record().title(), pocket_width )[1]).substr(0,pocket_width);
+                            tb2.value = ( ($('title_r_indent').checked ? ' ' : '') + util.text.wrap_on_space( volume.record().title(), label_cfg.pocket_width )[1]).substr(0,label_cfg.pocket_width);
                         } else {
                             tb2.value = '';
                         }
                     }
                     if ($('author').checked && $('author_line').value == j + 1 && instanceOf(volume.record(),mvr)) {
                         if (volume.record().author()) {
-                            tb2.value = volume.record().author().substr(0,pocket_width);
+                            tb2.value = volume.record().author().substr(0,label_cfg.pocket_width);
                         } else {
                             tb2.value = '';
                         }
                     }
                     if ($('call_number').checked && $('call_number_line').value == j + 1) {
-                        tb2.value = volume.label().substr(0,pocket_width);
+                        tb2.value = volume.label().substr(0,label_cfg.pocket_width);
                     }
                     if ($('owning_lib_shortname').checked && $('owning_lib_shortname_line').value == j + 1) {
                         var lib = volume.owning_lib();
                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
-                        tb2.value = lib.shortname().substr(0,pocket_width);
+                        tb2.value = lib.shortname().substr(0,label_cfg.pocket_width);
                     }
                     if ($('owning_lib').checked && $('owning_lib_line').value == j + 1) {
                         var lib = volume.owning_lib();
                         if (!instanceOf(lib,aou)) lib = g.data.hash.aou[ lib ];
-                        tb2.value = lib.name().substr(0,pocket_width);
+                        tb2.value = lib.name().substr(0,label_cfg.pocket_width);
                     }
                     if ($('shelving_location').checked && $('shelving_location_line').value == j + 1) {
                         tb2.value = '%location%';
         function preview(idx) {
             try {
                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-                    var pt = Number( $('pt').value ) || 10;  /* font size */
-                    var lm = Number($('lm').value); if (lm == NaN) lm = 11; /* left margin */
+                    var pt = Number( $('pt').value );  /* font size */
+                    if (!pt) {
+                        pt = g.data.hash.aous['cat.spine.font.size'] || 10;
+                        $('pt').value = pt;
+                    }
+                    var ff = g.data.hash.aous['cat.spine.font.family'] || 'monospace';
+                    var lm = Number($('lm').value); /* left margin */
+                    if (!lm) {
+                        lm = g.data.hash.aous['cat.spine.line.margin'] || 11;
+                    }
                     var mm = Number($('mm').value); if (mm == NaN) mm = 2; /* middle margin */
-                    var lw = Number($('lw').value) || 8; var ll = Number($('ll').value) || 9; /* spine label width and length */
+                    var lw = Number($('lw').value); /* spine label width */
+                    if (!lw) {
+                        lw = g.data.hash.aous['cat.spine.line.width'] || 8;
+                        $('lw').value = lw;
+                    }
+                    var ll = Number($('ll').value); /* spine label length */
+                    if (!ll) {
+                        ll = g.data.hash.aous['cat.spine.line.height'] || 9;
+                        $('ll').value = ll;
+                    }
                     var plw = Number($('plw').value) || 28; var pll = Number($('pll').value) || 9; /* pocket label width and length */
                     var html = "<html><head>";
                     html += "<link type='text/css' rel='stylesheet' href='" + xulG.url_prefix('/xul/server/skin/print.css') + "'></link>"
-                    html += "<link type='text/css' rel='stylesheet' href='data:text/css,pre{font-size:" + pt + "pt;}'></link>";
+                    html += "<link type='text/css' rel='stylesheet' href='data:text/css,pre{font-family:" + ff + ";font-size:" + pt + "pt;}'></link>";
                     html += "<title>Spine Labels</title></head><body>\n";
                     var nl = document.getElementsByAttribute('name','template');
                     for (var i = 0; i < nl.length; i++) {
index 1393eb0..d6bbc7a 100644 (file)
 
             <hbox>
                 <label value="&staff.cat.spine_labels.font_size.label;" control="pt"/>
-                <textbox id="pt" value="10" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/>
+                <textbox id="pt" value="" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/>
             </hbox>
             <grid><columns><column/><column/><column/><column/></columns><rows>
                 <row> <label class="header" value="&staff.cat.spine_labels.spine_label.label;"/><spacer/> </row>
-                <row> <label value="&staff.cat.spine_labels.spine_label.left_margin.label;" control="lm"/><textbox id="lm" value="0" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
-                <row> <label value="&staff.cat.spine_labels.spine_label.label_width.label;" control="lw"/><textbox id="lw" value="8" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
-                <row> <label value="&staff.cat.spine_labels.spine_label.label_length.label;" control="ll"/><textbox id="ll" value="9" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
+                <row> <label value="&staff.cat.spine_labels.spine_label.left_margin.label;" control="lm"/><textbox id="lm" value="" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
+                <row> <label value="&staff.cat.spine_labels.spine_label.label_width.label;" control="lw"/><textbox id="lw" value="" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
+                <row> <label value="&staff.cat.spine_labels.spine_label.label_length.label;" control="ll"/><textbox id="ll" value="" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
                 <row> <label class="header" value="&staff.cat.spine_labels.pocket_label.label;"/><checkbox id="pl" checked="false" oils_persist="checked" label="Enabled"/> </row>
                 <row> <label value="&staff.cat.spine_labels.pocket_label.middle_margin.label;" control="mm"/><textbox id="mm" value="2" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>
                 <row> <label value="&staff.cat.spine_labels.pocket_label.label_width.label;" control="plw"/><textbox id="plw" value="28" onchange="this.setAttribute('value',this.value)" oils_persist="value" context="clipboard"/> </row>