added ability to clone event_def environment when an event_def is cloned
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 1 Sep 2009 18:40:37 +0000 (18:40 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 1 Sep 2009 18:40:37 +0000 (18:40 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13941 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/conify/global/action_trigger/event_definition.js
Open-ILS/web/templates/default/conify/global/action_trigger/event_definition.tt2

index ff4ad74..f869cc4 100644 (file)
@@ -21,6 +21,37 @@ function loadEventDef() {
     dojo.connect(eventDefTabs,'selectChild', tabLoader);
 }
 
+/**
+ * After an event def is cloned, see if the user wants to also clone the event def environment
+ * @param {Object} oldItem Grid store item that was cloned
+ * @param {Object} newObject Newly created fieldmapper object
+ */
+function cloneEventEnv(oldItem, newObject) {
+    if(!confirm('Clone event definition environment as well?')) return; // TODO i18n
+    progressDialog.show(true);
+    var pcrud = new openils.PermaCrud();
+
+    // fetch the env list for the cloned object
+    var env_list = pcrud.search('atenv', {event_def : edGrid.store.getValue(oldItem, 'id')});
+
+    if(env_list && env_list.length) {
+        
+        // clone the environment 
+        env_list = env_list.map(
+            function(item) { 
+                item.id(null);
+                item.event_def(newObject.id()); 
+                return item; 
+            }
+        );
+    
+        // create the cloned environment list
+        pcrud.create(env_list);
+    }
+
+    progressDialog.hide();
+}
+
 function loadEventDefData() { 
     var pcrud = new openils.PermaCrud();
     eventDef = pcrud.retrieve('atevdef', eventDefId);
index 1d04b81..55da5c2 100644 (file)
@@ -1,7 +1,9 @@
 [% WRAPPER default/base.tt2 %]
+[% ctx.page_title = 'Event Definitions' %]
 <script src='[% ctx.media_prefix %]/js/ui/default/conify/global/action_trigger/event_definition.js'> </script>
 <script>openils.Util.addOnLoad(loadEventDef)</script>
 
+
 <div dojoType="dijit.layout.TabContainer" style='height:100%;' jsId='eventDefTabs'>
 
     <div dojoType="dijit.layout.ContentPane" title='Event Definitions' id='tab-atevdef'>
@@ -9,7 +11,7 @@
             <div>Trigger Event Definitions</div>
             <div>
                 <button dojoType='dijit.form.Button' onClick='edGrid.showCreatePane()'>New</button>
-                <button dojoType='dijit.form.Button' onClick='edGrid.showClonePane()'>Clone Selected</button>
+                <button dojoType='dijit.form.Button' onClick='edGrid.showClonePane(cloneEventEnv)'>Clone Selected</button>
                 <button dojoType='dijit.form.Button' onClick='edGrid.deleteSelected()'>Delete Selected</button>
             </div>
         </div>
         </div>
     </div>
 
+</div>
+
+<div jsId='progressDialog' dojoType='openils.widget.ProgressDialog' indeterminate='true'></div>
 
 [% END %]