plugged in rest of group mods creation/deletion. just need whole group deletion now
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 27 May 2009 21:05:44 +0000 (21:05 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 27 May 2009 21:05:44 +0000 (21:05 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13252 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/conify/global/config/circ_matrix_matchpoint.js

index 1bc6ff8..3004406 100644 (file)
@@ -50,6 +50,8 @@ function addCircModGroup(node, tableTmpl, group) {
     if(group) {
         entries = new openils.PermaCrud().search('ccmcmtm', {circ_mod_test : group.id()});
         table.setAttribute('group', group.id());
+        circModGroupCache[group.id()] = group;
+        circModEntryCache[group.id()] = entries;
     }
 
     function addMod(code, name) {
@@ -113,6 +115,26 @@ function applyCircModChanges() {
 
 
         } else {
+
+            var existing = circModEntryCache[group.id()];
+            dojo.forEach(mods, function(mod) {
+                
+                // new circ mod for this group
+                if(!existing.filter(function(i){ return (i.circ_mod() == mod)})[0]) {
+                    var entry = new fieldmapper.ccmcmtm();
+                    entry.isnew(true);
+                    entry.circ_mod(mod);
+                    entries.push(entry);
+                    entry.circ_mod_test(group.id());
+                }
+            });
+
+            dojo.forEach(existing, function(eMod) {
+                if(!mods.filter(function(i){ return (i == eMod.circ_mod()) })[0]) {
+                    eMod.isdeleted(true);
+                    entries.push(eMod);
+                }
+            });
         }
 
         group.items_out(count);
@@ -134,8 +156,39 @@ function applyCircModChanges() {
 
         } else {
 
+            pcrud.update(group, {
+                oncomplete : function(r) {
+                    openils.Util.readResponse(r);
+                    var newOnes = entries.filter(function(e) { return e.isnew() });
+                    var delOnes = entries.filter(function(e) { return e.isdeleted() });
+                    if(!delOnes.length && !newOnes.length) {
+                        progressDialog.hide();
+                        return;
+                    }
+                    if(newOnes.length) {
+                        pcrud.create(newOnes, {
+                            oncomplete : function() {
+                                if(delOnes.length) {
+                                    pcrud.delete(delOnes, {
+                                        oncomplete : function() {
+                                            progressDialog.hide();
+                                        }
+                                    });
+                                } else {
+                                    progressDialog.hide();
+                                }
+                            }
+                        });
+                    } else {
+                        pcrud.delete(delOnes, {
+                            oncomplete : function() {
+                                progressDialog.hide();
+                            }
+                        });
+                    }
+                }
+            });
         }
-
     }
 }