[open-ils-commits] [GIT] Evergreen ILS branch master updated. da8b81e52fef0e452ef093e0f9e228c81f15169c

Evergreen Git git at git.evergreen-ils.org
Mon Nov 27 13:47:38 EST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  da8b81e52fef0e452ef093e0f9e228c81f15169c (commit)
       via  c8df12a067bd7b50fec61a95f550aaa527f9b263 (commit)
       via  ec7e154092dd16cd19362827251760d23ca8bad4 (commit)
       via  810322a2acf01cb73e930e6ca44d77fd3363ae28 (commit)
       via  ac38f44743b0e088e2502c43f82beec54fd3be93 (commit)
      from  e99692f809f698c451b8feba6332fa91eacd4fcd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit da8b81e52fef0e452ef093e0f9e228c81f15169c
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Mon Nov 27 13:24:39 2017 -0500

    LP#1691269: (follow-up) fix whitespace to match local style
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

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 8a84788..a87ea1e 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
@@ -250,115 +250,116 @@ 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"] == "<HACK:KLUDGE:NULL>" ) { 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']; // so... some of the number fields are actually strings. Groovy.
-                 if ( tmp_val.match(/^[-0-9.]+$/) && !(field_name.match(/(?:loan_duration|fine_level)/))) { 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 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"] == "<HACK:KLUDGE:NULL>" ) { 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']; // so... some of the number fields are actually strings. Groovy.
+                            if ( tmp_val.match(/^[-0-9.]+$/) && !(field_name.match(/(?:loan_duration|fine_level)/))) {
+                                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.flesh = {   
         flesh : 3, 

commit c8df12a067bd7b50fec61a95f550aaa527f9b263
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Mon Nov 27 13:17:29 2017 -0500

    LP#1691269: add unit test for convert_xul_templates
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/web/js/ui/default/staff/test/unit/egVolCopy.js b/Open-ILS/web/js/ui/default/staff/test/unit/egVolCopy.js
new file mode 100644
index 0000000..2dd877a
--- /dev/null
+++ b/Open-ILS/web/js/ui/default/staff/test/unit/egVolCopy.js
@@ -0,0 +1,21 @@
+'use strict';
+
+describe('egVolCopyTest', function(){
+  beforeEach(module('egVolCopy'));
+
+  /** itemSvc tests **/
+  describe('itemSvcTests', function() {
+
+    it('itemSvc should start with empty lists', inject(function(itemSvc) {
+        expect(itemSvc.copies.length).toEqual(0);
+    }));
+
+    it('itemSvc.convert_xul_templates converts copy templates as expected', inject(function(itemSvc) {
+        var xul = JSON.parse('{"Easy Reader 1":{"Circulation Library":{"field":"circ_lib","type":"attribute","value":"4"},"Status":{"field":"status","type":"attribute","value":"0"},"Location/Collection":{"field":"location","value":"103","type":"attribute"},"Deposit?":{"field":"deposit","value":"f","type":"attribute"},"Copy Number":{"field":"copy_number","value":"1","type":"attribute"},"Price":{"type":"attribute","value":"25.55","field":"price"},"Loan Duration":{"value":"2","type":"attribute","field":"loan_duration"},"Circulate?":{"field":"circulate","type":"attribute","value":"t"},"Holdable?":{"field":"holdable","type":"attribute","value":"t"},"Circulation Modifier":{"field":"circ_modifier","value":"<HACK:KLUDGE:NULL>","type":"attribute"},"Floating?":{"field":"floating","value":"<HACK:KLUDGE:NULL>","type":"attribute"},"Owning Lib : Call Number":{"value":"4","type":"owning_lib","field":null},"Reference?":{"field":"ref","type":"attribute","value":"f"},"Quality":{"type":"attrib
 ute","value":"t","field":"mint_condition"},"Acquisition Cost":{"field":"cost","type":"attribute","value":"25.55"},"OPAC Visible?":{"type":"attribute","value":"t","field":"opac_visible"},"Deposit Amount":{"field":"deposit_amount","type":"attribute","value":"1.25"},"Fine Level":{"field":"fine_level","type":"attribute","value":"2"},"Circulate as Type":{"field":"circ_as_type","type":"attribute","value":"a"},"Age-based Hold Protection":{"value":"<HACK:KLUDGE:NULL>","type":"attribute","field":"age_protect"}},"Reference (unified)":{"volume_copy_creator.batch_class_menulist":{"field":"batch_class_menulist","type":"volume_copy_creator","value":"2"},"volume_copy_creator.batch_suffix_menulist":{"value":"1","type":"volume_copy_creator","field":"batch_suffix_menulist"},"volume_copy_creator.batch_prefix_menulist":{"type":"volume_copy_creator","value":"1","field":"batch_prefix_menulist"},"Location/Collection":{"field":"location","value":"102","type":"attribute"}}}');
+        var webstaff = JSON.parse('{"Reference (unified)":{"callnumber":{"classification":2,"prefix":1,"suffix":1},"location":102},"Easy Reader 1":{"location":103,"circ_as_type":"a","status":0,"copy_number":1,"circ_lib":4,"ref":"f","circulate":"t","mint_condition":"t","cost":25.55,"deposit_amount":1.25,"deposit":"f","price":25.55,"opac_visible":"t","fine_level":"2","loan_duration":"2","holdable":"t"}}');
+        expect(itemSvc.convert_xul_templates(xul)).toEqual(webstaff);
+    }));
+
+  });
+
+});

commit ec7e154092dd16cd19362827251760d23ca8bad4
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Mon Nov 27 12:46:33 2017 -0500

    LP#1691269: include volume fields in converted copy templates
    
    This patch insures that call number prefix, suffix, and classification
    scheme from copy templates created in the XUL unified copy editor are
    brought over to web staff copy templates.
    
    Note that in order to successfully test the call number portion of
    converted copy templates in the web staff client, the volume/copy editor
    default "Allow Call Number attributes in Copy Templates" should be
    turned on.
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

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 2097608..8a84788 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
@@ -273,7 +273,9 @@ function(egCore , $q) {
    };
 
    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.
+       // 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) {
@@ -302,7 +304,6 @@ function(egCore , $q) {
        var curr_templ;
        var stat_cats;
        var fields;
-       var field_name;
        var curr_field;
        var tmp_val;
        var i, j;
@@ -317,24 +318,34 @@ function(egCore , $q) {
 
            if (fields.length > 0) {
              for (j=0; j < fields.length; j++) {
-               field_name = fields[j];
-               curr_field = xul_t[field_name];
+               curr_field = xul_t[fields[j]];
+               var field_name = curr_field["field"];
 
-               if ( curr_field["field"] == null ) { continue; }
+               if ( field_name == null ) { continue; }
                if ( curr_field["value"] == "<HACK:KLUDGE:NULL>" ) { 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" ) {
+               // 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[curr_field["field"]] = parseInt(curr_field["value"]);
+                 stat_cats[field_name] = 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 ( tmp_val.match(/^[-0-9.]+$/) && !(field_name.match(/(?:loan_duration|fine_level)/))) { 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;
+                 }
                }
              }
 

commit 810322a2acf01cb73e930e6ca44d77fd3363ae28
Author: Galen Charlton <gmc at equinoxinitiative.org>
Date:   Mon Nov 27 11:08:23 2017 -0500

    LP#1691269: (follow-up) include new cust in seed data
    
    Also s/Copier/Copy/.
    
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

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 152f508..03f992f 100644
--- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql
+++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql
@@ -2663,6 +2663,12 @@ INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatyp
     oils_i18n_gettext('staff_client.copy_editor.templates', 'Copy Editor Template', 'cust', 'description'),
     'object');
 
+INSERT INTO config.usr_setting_type (name, label, description, datatype)
+    VALUES ('webstaff.cat.copy.templates',
+    oils_i18n_gettext('webstaff.cat.copy.templates', 'Web Client Copy Editor Templates', 'cust', 'label'),
+    oils_i18n_gettext('webstaff.cat.copy.templates', 'Web Client Copy Editor Templates', 'cust', 'description'),
+    'object');
+
 INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatype)
     VALUES ('circ.holds_behind_desk', FALSE,
     oils_i18n_gettext('circ.holds_behind_desk', 'Hold is behind Circ Desk', 'cust', 'label'),
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
index 1202751..9b9cee3 100644
--- 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
@@ -3,6 +3,6 @@ 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');
+  VALUES ('webstaff.cat.copy.templates', 'Web Client Copy Editor Templates', 'Web Client Copy Editor Templates', 'object');
 
 COMMIT;

commit ac38f44743b0e088e2502c43f82beec54fd3be93
Author: Jason Boyer <JBoyer at library.in.gov>
Date:   Sun Oct 22 15:42:02 2017 -0400

    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 <JBoyer at library.in.gov>
    Signed-off-by: Cesar Velez <cesar.velez at equinoxinitiative.org>
    Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

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 0000000..1202751
--- /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 44007e1..2097608 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
@@ -250,6 +250,105 @@ 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 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"] == "<HACK:KLUDGE:NULL>" ) { 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, 
         flesh_fields : {
@@ -1085,10 +1184,10 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
         $scope.template_name_list = [];
 
         $scope.fetchTemplates = function () {
-            egCore.hatch.getItem('cat.copy.templates').then(function(t) {
+            itemSvc.get_acp_templates().then(function(t) {
                 if (t) {
                     $scope.templates = t;
-                    $scope.template_name_list = Object.keys(t);
+                    $scope.template_name_list = Object.keys(t).sort();
                 }
             });
             egCore.hatch.getItem('cat.copy.last_template').then(function(t) {
@@ -1933,10 +2032,10 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                 $scope.template_controls = true;
 
                 $scope.fetchTemplates = function () {
-                    egCore.hatch.getItem('cat.copy.templates').then(function(t) {
+                    itemSvc.get_acp_templates().then(function(t) {
                         if (t) {
                             $scope.templates = t;
-                            $scope.template_name_list = Object.keys(t);
+                            $scope.template_name_list = Object.keys(t).sort();
                         }
                     });
                 }
@@ -1962,9 +2061,9 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                 $scope.deleteTemplate = function (n) {
                     if (n) {
                         delete $scope.templates[n]
-                        $scope.template_name_list = Object.keys($scope.templates);
+                        $scope.template_name_list = Object.keys($scope.templates).sort();
                         $scope.template_name = '';
-                        egCore.hatch.setItem('cat.copy.templates', $scope.templates);
+                        itemSvc.save_acp_templates($scope.templates);
                         $scope.$parent.fetchTemplates();
                         ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_DELETE);
                     }
@@ -1984,15 +2083,15 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                         });
             
                         $scope.templates[n] = tmpl;
-                        $scope.template_name_list = Object.keys($scope.templates);
+                        $scope.template_name_list = Object.keys($scope.templates).sort();
             
-                        egCore.hatch.setItem('cat.copy.templates', $scope.templates);
+                        itemSvc.save_acp_templates($scope.templates);
                         $scope.$parent.fetchTemplates();
 
                         $scope.dirty = false;
                     } else {
                         // save all templates, as we might do after an import
-                        egCore.hatch.setItem('cat.copy.templates', $scope.templates);
+                        itemSvc.save_acp_templates($scope.templates);
                         $scope.$parent.fetchTemplates();
                     }
                     ngToast.create(egCore.strings.VOL_COPY_TEMPLATE_SUCCESS_SAVE);
@@ -2008,9 +2107,11 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                         try {
                             var newTemplates = JSON.parse(newVal);
                             if (!Object.keys(newTemplates).length) return;
-                            $scope.templates = newTemplates;
-                            $scope.template_name_list = Object.keys(newTemplates);
-                            $scope.template_name = '';
+                            angular.forEach(Object.keys(newTemplates), function (k) {
+                                $scope.templates[k] = newTemplates[k];
+                            });
+                            itemSvc.save_acp_templates($scope.templates);
+                            $scope.fetchTemplates();
                         } catch (E) {
                             console.log('tried to import an invalid copy template file');
                         }

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/sql/Pg/950.data.seed-values.sql       |    6 +
 .../XXXX.schema.webstaff.cat.copy.templates.sql    |    8 +
 .../web/js/ui/default/staff/cat/volcopy/app.js     |  137 ++++++++++++++++++--
 .../web/js/ui/default/staff/test/unit/egVolCopy.js |   21 +++
 4 files changed, 160 insertions(+), 12 deletions(-)
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.webstaff.cat.copy.templates.sql
 create mode 100644 Open-ILS/web/js/ui/default/staff/test/unit/egVolCopy.js


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list