From 0b79baf4dca1090bc6332da218b9ab38248595e4 Mon Sep 17 00:00:00 2001 From: dbs Date: Thu, 26 Aug 2010 00:16:11 +0000 Subject: [PATCH] Make spine label settings configurable as org unit settings 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 | 2 +- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 53 +++++++++++ .../src/sql/Pg/upgrade/0380.data.spine_label.sql | 56 ++++++++++++ .../xul/staff_client/server/cat/spine_labels.js | 101 ++++++++++++++------- .../xul/staff_client/server/cat/spine_labels.xul | 8 +- 5 files changed, 184 insertions(+), 36 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0380.data.spine_label.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 46cfd93fb..cf7c4cba3 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -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, diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index a11e08861..8ee21df8e 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -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 index 000000000..76ef2d0bf --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0380.data.spine_label.sql @@ -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; diff --git a/Open-ILS/xul/staff_client/server/cat/spine_labels.js b/Open-ILS/xul/staff_client/server/cat/spine_labels.js index 509459183..1be57e864 100644 --- a/Open-ILS/xul/staff_client/server/cat/spine_labels.js +++ b/Open-ILS/xul/staff_client/server/cat/spine_labels.js @@ -77,15 +77,37 @@ 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) { @@ -104,7 +126,7 @@ 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++; } @@ -114,7 +136,7 @@ } } - 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) { @@ -125,17 +147,17 @@ 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); @@ -143,7 +165,7 @@ 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) { @@ -153,18 +175,18 @@ /* 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 */ @@ -175,45 +197,45 @@ } /* 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%'; @@ -390,14 +412,31 @@ 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 += "" - html += ""; + html += ""; html += "Spine Labels\n"; var nl = document.getElementsByAttribute('name','template'); for (var i = 0; i < nl.length; i++) { diff --git a/Open-ILS/xul/staff_client/server/cat/spine_labels.xul b/Open-ILS/xul/staff_client/server/cat/spine_labels.xul index 1393eb0e9..d6bbc7ab2 100644 --- a/Open-ILS/xul/staff_client/server/cat/spine_labels.xul +++ b/Open-ILS/xul/staff_client/server/cat/spine_labels.xul @@ -49,13 +49,13 @@ - - - + + + -- 2.11.0