maintain a list of applied templates so that we can re-apply them as items get added...
authorJason Etheridge <jason@esilibrary.com>
Mon, 28 Feb 2011 20:36:21 +0000 (15:36 -0500)
committerJason Etheridge <jason@esilibrary.com>
Wed, 2 Mar 2011 15:20:58 +0000 (10:20 -0500)
Open-ILS/xul/staff_client/server/cat/copy_editor.js

index 1b8f5aa..9b9d57f 100644 (file)
@@ -176,6 +176,9 @@ function my_init() {
                 try {
                     g.copies = xulG.copies;
                     g.original_copies = js2JSON( g.copies );
+                    for (var i = 0; i < g.applied_templates.length; i++) {
+                        g._apply_template( g.applied_templates[i] );
+                    }
                     g.summarize( g.copies );
                     g.render();
                     g.check_for_unmet_required_fields();
@@ -241,10 +244,26 @@ g.retrieve_templates = function() {
 /******************************************************************************************************/
 /* Apply Template */
 
+g.applied_templates = [];
+
 g.apply_template = function() {
     try {
         var name = g.template_menu.value;
         if (g.templates[ name ] != 'undefined') {
+            g.applied_templates.push( name );
+            g._apply_template(name);
+            g.summarize( g.copies );
+            g.render();
+            g.check_for_unmet_required_fields();
+        }
+    } catch(E) {
+        g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_editor.apply_templates.error'), E);
+    }
+}
+
+g._apply_template = function(name) {
+    try {
+        if (g.templates[ name ] != 'undefined') {
             var template = g.templates[ name ];
             for (var i in template) {
                 g.changed[ i ] = template[ i ];
@@ -260,12 +279,9 @@ g.apply_template = function() {
                     break;
                 }
             }
-            g.summarize( g.copies );
-            g.render();
-            g.check_for_unmet_required_fields();
         }
     } catch(E) {
-        g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_editor.apply_templates.error'), E);
+        alert('Error in copy_editor.js, g._apply_template('+name+'): ' + E);
     }
 }
 
@@ -425,6 +441,7 @@ g.import_templates = function() {
 /* Restore backup copies */
 
 g.reset = function() {
+    g.applied_templates = [];
     g.changed = {};
     g.copies = JSON2js( g.original_copies );
     g.summarize( g.copies );