From f9cc8cd8d9de3042285fb36903d84e678a2dfbad Mon Sep 17 00:00:00 2001 From: dbs Date: Mon, 30 Aug 2010 14:14:12 +0000 Subject: [PATCH] Backport spine label prefix/suffix and printing fixes for XUL 1.9.0 from trunk git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@17368 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 2 + Open-ILS/src/sql/Pg/040.schema.asset.sql | 2 + Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql | 8 ++ .../staff_client/server/admin/copy_locations.js | 20 ++++ .../staff_client/server/admin/copy_locations.xhtml | 6 + .../xul/staff_client/server/cat/spine_labels.js | 121 ++++++++++++++++++--- 6 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 5ad05601e0..46cd589f98 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2523,6 +2523,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index 47234c8adc..206843889e 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -29,6 +29,8 @@ CREATE TABLE asset.copy_location ( hold_verify BOOL NOT NULL DEFAULT FALSE, opac_visible BOOL NOT NULL DEFAULT TRUE, circulate BOOL NOT NULL DEFAULT TRUE, + label_prefix TEXT, + label_suffix TEXT, CONSTRAINT acl_name_once_per_lib UNIQUE (name, owning_lib) ); diff --git a/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql new file mode 100644 index 0000000000..9f87794d7d --- /dev/null +++ b/Open-ILS/src/sql/Pg/1.6.1-1.6.2-upgrade-db.sql @@ -0,0 +1,8 @@ +BEGIN; + +-- Start picking up call number label prefixes and suffixes +-- from asset.copy_location +ALTER TABLE asset.copy_location ADD COLUMN label_prefix TEXT; +ALTER TABLE asset.copy_location ADD COLUMN label_suffix TEXT; + +COMMIT; diff --git a/Open-ILS/xul/staff_client/server/admin/copy_locations.js b/Open-ILS/xul/staff_client/server/admin/copy_locations.js index 253942ff68..1ca934d4b0 100644 --- a/Open-ILS/xul/staff_client/server/admin/copy_locations.js +++ b/Open-ILS/xul/staff_client/server/admin/copy_locations.js @@ -160,6 +160,8 @@ function clBuildRow( tbody, row, cl ) { appendClear($n( row, 'cl_hold_verify'), (isTrue(cl.hold_verify())) ? _TRUE.cloneNode(true) : _FALSE.cloneNode(true) ); appendClear($n( row, 'cl_visible'), (isTrue(cl.opac_visible())) ? _TRUE.cloneNode(true) : _FALSE.cloneNode(true) ); appendClear($n( row, 'cl_circulate'), (isTrue(cl.circulate())) ? _TRUE.cloneNode(true) : _FALSE.cloneNode(true) ); + $n( row, 'cl_label_prefix').appendChild(text(cl.label_prefix())); + $n( row, 'cl_label_suffix').appendChild(text(cl.label_suffix())); var edit = $n( row, 'cl_edit'); edit.onclick = function() { clEdit( cl, tbody, row ); }; @@ -192,6 +194,22 @@ function clEdit( cl, tbody, row ) { if(isTrue(cl.hold_verify())) arr[6].checked = true; else arr[7].checked = true; + var label_prefix = $n(r, 'cl_edit_label_prefix'); + if (cl.label_prefix()) { + label_prefix.setAttribute('size', cl.label_prefix().length + 3); + } else { + label_prefix.setAttribute('size', 3); + } + label_prefix.value = cl.label_prefix(); + + var label_suffix = $n(r, 'cl_edit_label_suffix'); + if (cl.label_suffix()) { + label_suffix.setAttribute('size', cl.label_suffix().length + 3); + } else { + label_suffix.setAttribute('size', 3); + } + label_suffix.value = cl.label_suffix(); + $n(r, 'cl_edit_cancel').onclick = function(){cleanTbody(tbody,'edit');} $n(r, 'cl_edit_commit').onclick = function(){clEditCommit( tbody, r, cl ); } @@ -225,6 +243,8 @@ function clEditCommit( tbody, r, cl ) { if(arr[6].checked) cl.hold_verify(1); else cl.hold_verify(0); cl.name($n(r, 'cl_edit_name').value); + cl.label_prefix($n(r, 'cl_edit_label_prefix').value); + cl.label_suffix($n(r, 'cl_edit_label_suffix').value); var req = new Request( UPDATE_CL, SESSION, cl ); req.send(true); diff --git a/Open-ILS/xul/staff_client/server/admin/copy_locations.xhtml b/Open-ILS/xul/staff_client/server/admin/copy_locations.xhtml index 7be5e240a7..cb9998f7b9 100644 --- a/Open-ILS/xul/staff_client/server/admin/copy_locations.xhtml +++ b/Open-ILS/xul/staff_client/server/admin/copy_locations.xhtml @@ -112,6 +112,8 @@ &staff.server.admin.copy_locations.editor.hold_verify; &staff.server.admin.copy_locations.editor.opac_visible; &staff.server.admin.copy_locations.editor.circulate; + Label prefix + Label suffix &staff.server.admin.copy_locations.editor.edit; &staff.server.admin.copy_locations.editor.delete; @@ -124,6 +126,8 @@ + + @@ -187,6 +191,8 @@ + + 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 dd88df46cb..9d6e029e38 100644 --- a/Open-ILS/xul/staff_client/server/cat/spine_labels.js +++ b/Open-ILS/xul/staff_client/server/cat/spine_labels.js @@ -33,11 +33,18 @@ for (var i = 0; i < g.barcodes.length; i++) { var copy = g.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE.authoritative', [ g.barcodes[i] ] ); if (typeof copy.ilsevent != 'undefined') throw(copy); + var label_prefix = copy.location().label_prefix() || ''; + var label_suffix = copy.location().label_suffix() || ''; if (!g.volumes[ copy.call_number() ]) { var volume = g.network.simple_request( 'FM_ACN_RETRIEVE.authoritative', [ copy.call_number() ] ); if (typeof volume.ilsevent != 'undefined') throw(volume); var record = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative', [ volume.record() ]); volume.record( record ); + + /* Jam the prefixes and suffixes into the volume object */ + volume.prefix = label_prefix; + volume.suffix = label_suffix; + g.volumes[ volume.id() ] = volume; } if (g.volumes[ copy.call_number() ].copies()) { @@ -144,14 +151,44 @@ function generate_labels(volume, label_node, label_cfg, override) { var names; + var callnum; if (override && volume.id() == override.acn) { /* If we're calling ourself, we'll have an altered label */ - names = String(override.label).split(/\s+/); + callnum = String(override.label); } else { /* take the call number and split it on whitespace */ - names = String(volume.label()).split(/\s+/); + callnum = String(volume.label()); + } + + /* for LC, split between classification subclass letters and numbers */ + var lc_class_re = /^([A-Z]{1,3})([0-9]+.*?)$/i; + var lc_class_match = lc_class_re.exec(callnum); + if (lc_class_match && lc_class_match.length > 1) { + callnum = lc_class_match[1] + ' ' + lc_class_match[2]; + } + + /* for LC, split between Cutter numbers */ + var lc_cutter_re = /^(.*)(\.[A-Z]{1}[0-9]+.*?)$/ig; + var lc_cutter_match = lc_cutter_re.exec(callnum); + if (lc_cutter_match && lc_cutter_match.length > 1) { + callnum = ''; + for (var i = 1; i < lc_cutter_match.length; i++) { + callnum += lc_cutter_match[i] + ' '; + } + } + + /* Only add the prefixes and suffixes once */ + if (!override || volume.id() != override.acn) { + if (volume.prefix) { + callnum = volume.prefix + ' ' + callnum; + } + if (volume.suffix) { + callnum += ' ' + volume.suffix; + } } + + names = callnum.split(/\s+/); var j = 0; while (j < label_cfg.spine_length || j < label_cfg.pocket_length) { var hb2 = document.createElement('hbox'); label_node.appendChild(hb2); @@ -171,9 +208,11 @@ tb.setAttribute('name','spine'); var spine_row_id = 'acn_' + volume.id() + '_spine_' + j; tb.setAttribute('id',spine_row_id); + var name = names.shift(); if (name) { name = String( name ); + /* if the name is greater than the label width... */ if (name.length > label_cfg.spine_width) { /* then try to split it on periods */ @@ -341,7 +380,7 @@ case dojo.keys.BACKSPACE : { /* Delete line if at the start of an input box */ - if (sel_start == 0) { + if (sel_start == 0 && sel_end == sel_start) { var new_label = ''; var chunk; var x = 0; @@ -366,6 +405,13 @@ generate({"acn": row_id.acn, "label": new_label}); $(row_id.prefix + row_id.spine).focus(); } + if (sel_start == 0) { + /* Move to the previous row */ + var prev_row = $(row_id.prefix + (parseInt(row_id.spine) - 1)); + if (prev_row) { + prev_row.focus(); + } + } break; } @@ -505,22 +551,65 @@ } } html += ''; - var loc = ( urls.XUL_BROWSER ); - xulG.new_tab( - loc, - { - 'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title') - }, - { - 'url' : 'data:text/html;charset=utf-8,'+window.escape(html), - 'html_source' : html, - 'show_print_button' : 1, - 'no_xulG' : 1 - } - ); + + /* From https://developer.mozilla.org/en/Using_nsIXULAppInfo */ + var appInfo = Components.classes["@mozilla.org/xre/app-info;1"] + .getService(Components.interfaces.nsIXULAppInfo); + var platformVer = appInfo.platformVersion; + + /* We need to use different print strategies for different + * XUL versions, apparently + */ + if (platformVer.substr(0, 5) == '1.9.0') { + preview_xul_190(html); + } else { + preview_xul_192(html); + } + + } catch(E) { g.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.spine_labels.preview.std_unexpected_err'),E); } } + function preview_xul_190(html) { + JSAN.use('util.window'); var win = new util.window(); + var loc = ( urls.XUL_REMOTE_BROWSER ); + //+ '?url=' + window.escape('about:blank') + '&show_print_button=1&alternate_print=1&no_xulG=1&title=' + window.escape('Spine Labels'); + var w = win.open( loc, 'spine_preview', 'chrome,resizable,width=750,height=550'); + w.xulG = { + 'url' : 'about:blank', + 'show_print_button' : 1, + 'alternate_print' : 1, + 'no_xulG' : 1, + 'title' : $("catStrings").getString('staff.cat.spine_labels.preview.title'), + 'on_url_load' : function(b) { + try { + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); + if (typeof w.xulG.written == 'undefined') { + w.xulG.written = true; + w.g.browser.get_content().document.write(html); + w.g.browser.get_content().document.close(); + } + } catch(E) { + alert(E); + } + } + }; + } + function preview_xul_192(html) { + var loc = ( urls.XUL_BROWSER ); + xulG.new_tab( + loc, + { + 'tab_name' : $("catStrings").getString('staff.cat.spine_labels.preview.title') + }, + { + 'url' : 'data:text/html;charset=utf-8,'+window.escape(html), + 'html_source' : html, + 'show_print_button' : 1, + 'no_xulG' : 1 + } + ); + } -- 2.11.0