From 60b4bf41d8994176d5ec59d71c56fb3d73f418b7 Mon Sep 17 00:00:00 2001 From: Jason Boyer Date: Sun, 22 Oct 2017 15:42:02 -0400 Subject: [PATCH] LP1691269: Webstaff Copy Editor Templates This branch will translate and transfer your XUL client templates the first time you load the web client copy editor. From that point on the two diverge with no further connection to each other. This branch also allows your copy templates to travel with you between browsers, machines, and so on, while still allowing users that share a browser but not usernames to have their own templates. Signed-off-by: Jason Boyer Signed-off-by: Cesar Velez Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander --- .../XXXX.schema.webstaff.cat.copy.templates.sql | 8 + .../web/js/ui/default/staff/cat/volcopy/app.js | 208 ++++++++++----------- 2 files changed, 106 insertions(+), 110 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.webstaff.cat.copy.templates.sql diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.webstaff.cat.copy.templates.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.webstaff.cat.copy.templates.sql new file mode 100644 index 0000000000..1202751c0e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.webstaff.cat.copy.templates.sql @@ -0,0 +1,8 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +INSERT INTO config.usr_setting_type (name, label, description, datatype) + VALUES ('webstaff.cat.copy.templates', 'Web Client Copier Editor Templates', 'Web Client Copy Editor Templates', 'object'); + +COMMIT; diff --git a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js index 90f9dcf260..7cf1b068d0 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js @@ -279,116 +279,104 @@ function(egCore , $q) { }; - service.get_acp_templates = function() { - // Already downloaded for this user? Return local copy. Changing users or logging out causes another download - // so users always have their own templates, and any changes made on other machines appear as expected. - if (egCore.hatch.getSessionItem('cat.copy.templates.usr') == egCore.auth.user().id()) { - return egCore.hatch.getItem('cat.copy.templates').then(function(templ) { - return templ; - }); - } else { - // this can be disabled for debugging to force a re-download and translation of test templates - egCore.hatch.setSessionItem('cat.copy.templates.usr', egCore.auth.user().id()); - return service.load_remote_acp_templates(); - } - - }; - - service.save_acp_templates = function(t) { - egCore.hatch.setItem('cat.copy.templates', t); - egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update', - egCore.auth.token(), egCore.auth.user().id(), { "webstaff.cat.copy.templates": t }); - // console.warn('Saved ' + JSON.stringify({"webstaff.cat.copy.templates": t})); - }; - - service.load_remote_acp_templates = function() { - // After the XUL Client is completely removed everything related - // to staff_client.copy_editor.templates and convert_xul_templates - // can be thrown away. - return egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative', - egCore.auth.token(), egCore.auth.user().id(), - ['webstaff.cat.copy.templates','staff_client.copy_editor.templates']).then(function(settings) { - if (settings['webstaff.cat.copy.templates']) { - egCore.hatch.setItem('cat.copy.templates', settings['webstaff.cat.copy.templates']); - return settings['webstaff.cat.copy.templates']; - } else { - if (settings['staff_client.copy_editor.templates']) { - var new_templ = service.convert_xul_templates(settings['staff_client.copy_editor.templates']); - egCore.hatch.setItem('cat.copy.templates', new_templ); - // console.warn('Saving: ' + JSON.stringify({'webstaff.cat.copy.templates' : new_templ})); - egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update', - egCore.auth.token(), egCore.auth.user().id(), {'webstaff.cat.copy.templates' : new_templ}); - return new_templ; - } - } - return {}; - }); - }; - - service.convert_xul_templates = function(xultempl) { - var conv_templ = {}; - var templ_names = Object.keys(xultempl); - var name; - var xul_t; - var curr_templ; - var stat_cats; - var fields; - var curr_field; - var tmp_val; - var i, j; - - if (templ_names) { - for (i=0; i < templ_names.length; i++) { - name = templ_names[i]; - curr_templ = {}; - stat_cats = {}; - xul_t = xultempl[name]; - fields = Object.keys(xul_t); - - if (fields.length > 0) { - for (j=0; j < fields.length; j++) { - curr_field = xul_t[fields[j]]; - var field_name = curr_field["field"]; - - if ( field_name == null ) { continue; } - if ( curr_field["value"] == "" ) { continue; } - - // floating changed from a boolean to an integer at one point; - // take this opportunity to remove the boolean from any old templates - if ( curr_field["type"] === "attribute" && field_name === "floating" ) { - if ( curr_field["value"].match(/[tf]/) ) { continue; } - } - - if ( curr_field["type"] === "stat_cat" ) { - stat_cats[field_name] = parseInt(curr_field["value"]); - } else { - tmp_val = curr_field['value']; - if ( tmp_val.toString().match(/^[-0-9.]+$/)) { - tmp_val = parseFloat(tmp_val); - } - - if (field_name.match(/^batch_.*_menulist$/)) { - // special handling for volume fields - if (!("callnumber" in curr_templ)) curr_templ["callnumber"] = {}; - if (field_name === "batch_class_menulist") curr_templ["callnumber"]["classification"] = tmp_val; - if (field_name === "batch_prefix_menulist") curr_templ["callnumber"]["prefix"] = tmp_val; - if (field_name === "batch_suffix_menulist") curr_templ["callnumber"]["suffix"] = tmp_val; - } else { - curr_templ[field_name] = tmp_val; - } - } - } - - if ( (Object.keys(stat_cats)).length > 0 ) { - curr_templ["statcats"] = stat_cats; - } - - conv_templ[name] = curr_templ; - } - } - } - return conv_templ; - }; + service.get_acp_templates = function() { + // Already downloaded for this user? Return local copy. Changing users or logging out causes another download + // so users always have their own templates, and any changes made on other machines appear as expected. + if (egCore.hatch.getSessionItem('cat.copy.templates.usr') == egCore.auth.user().id()) { + return egCore.hatch.getItem('cat.copy.templates').then(function(templ) { + return templ; + }); + } else { + // this can be disabled for debugging to force a re-download and translation of test templates + egCore.hatch.setSessionItem('cat.copy.templates.usr', egCore.auth.user().id()); + return service.load_remote_acp_templates(); + } + + }; + + service.save_acp_templates = function(t) { + egCore.hatch.setItem('cat.copy.templates', t); + egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update', + egCore.auth.token(), egCore.auth.user().id(), { "webstaff.cat.copy.templates": t }); + // console.warn('Saved ' + JSON.stringify({"webstaff.cat.copy.templates": t})); + }; + + service.load_remote_acp_templates = function() { + // After the XUL Client is completely removed everything related to staff_client.copy_editor.templates and convert_xul_templates can be thrown away. + return egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.retrieve.authoritative', + egCore.auth.token(), egCore.auth.user().id(), + ['webstaff.cat.copy.templates','staff_client.copy_editor.templates']).then(function(settings) { + if (settings['webstaff.cat.copy.templates']) { + egCore.hatch.setItem('cat.copy.templates', settings['webstaff.cat.copy.templates']); + return settings['webstaff.cat.copy.templates']; + } else { + if (settings['staff_client.copy_editor.templates']) { + var new_templ = service.convert_xul_templates(settings['staff_client.copy_editor.templates']); + egCore.hatch.setItem('cat.copy.templates', new_templ); + // console.warn('Saving: ' + JSON.stringify({'webstaff.cat.copy.templates' : new_templ})); + egCore.net.request('open-ils.actor', 'open-ils.actor.patron.settings.update', + egCore.auth.token(), egCore.auth.user().id(), {'webstaff.cat.copy.templates' : new_templ}); + return new_templ; + } + } + return {}; + }); + }; + + service.convert_xul_templates = function(xultempl) { + var conv_templ = {}; + var templ_names = Object.keys(xultempl); + var name; + var xul_t; + var curr_templ; + var stat_cats; + var fields; + var field_name; + var curr_field; + var tmp_val; + var i, j; + + if (templ_names){ + for (i=0; i < templ_names.length; i++) { + name = templ_names[i]; + curr_templ = {}; + stat_cats = {}; + xul_t = xultempl[name]; + fields = Object.keys(xul_t); + + if (fields.length > 0) { + for (j=0; j < fields.length; j++) { + field_name = fields[j]; + curr_field = xul_t[field_name]; + + if ( curr_field["field"] == null ) { continue; } + if ( curr_field["value"] == "" ) { continue; } + + // floating changed from a boolean to an integer at one point; take this opportunity to remove the boolean from any old templates + if ( curr_field["type"] === "attribute" && curr_field["field"] === "floating" ) { + if ( curr_field["value"].match(/[tf]/) ) { continue; } + } + + if ( curr_field["type"] === "stat_cat" ) { + stat_cats[curr_field["field"]] = parseInt(curr_field["value"]); + } + else { + tmp_val = curr_field['value']; // so... some of the number fields are actually strings. Groovy. + if ( tmp_val.match(/^[-0-9.]+$/) && !(curr_field["field"].match(/(?:loan_duration|fine_level)/))) { tmp_val = parseFloat(tmp_val); } + curr_templ[curr_field["field"]] = tmp_val; + } + } + + if ( (Object.keys(stat_cats)).length > 0 ){ + curr_templ["statcats"] = stat_cats; + } + + conv_templ[name] = curr_templ; + } + } + } + return conv_templ; + }; service.flesh = { flesh : 3, -- 2.11.0