LP#849008: Delete button in Admin > Server Settings > Z39.50 Servers doesn't work
authorMark Cooper <markchristophercooper@gmail.com>
Fri, 12 Oct 2012 02:03:41 +0000 (19:03 -0700)
committerMark Cooper <markchristophercooper@gmail.com>
Fri, 12 Oct 2012 02:03:41 +0000 (19:03 -0700)
Button now initiates process to delete Z server attributes before deleting the Z source.

Signed-off-by: Mark Cooper <markchristophercooper@gmail.com>
Open-ILS/src/templates/conify/global/config/z3950_source.tt2
Open-ILS/web/js/ui/default/conify/global/config/z3950_source.js

index 1ec8c6a..2568ea0 100644 (file)
@@ -56,7 +56,7 @@
         <div>Z39.50 Servers</div>
         <div>
             <button dojoType='dijit.form.Button' onClick='zsGrid.showCreateDialog()'>New Z39.50 Server</button>
-            <button dojoType='dijit.form.Button' onClick='zsGrid.deleteSelected()'>Delete Selected</button>
+            <button dojoType='dijit.form.Button' onClick='deleteAttributesThenSources()'>Delete Selected</button>
         </div>
     </div>
 
index 23998e5..8c7c199 100644 (file)
@@ -74,6 +74,28 @@ function cloneFromSource() {
     attrCloneDialog.hide();
 }
 
+// relies on access to global zsGrid
+function deleteAttributesThenSources() {
+    var sources = zsGrid.getSelectedItems();
+    if(sources.length > 0) {
+        dojo.forEach(sources,
+            function(zsrc) {
+                var pcrud = new openils.PermaCrud({authtoken : openils.User.authtoken});
+                var source_code = zsrc['name'];
+                // retrieve attributes
+                var sourceAttrs = pcrud.search('cza', {source : source_code});
+                pcrud.eliminate(sourceAttrs);
+            }
+        );
+        //now attributes are gone it's ok to delete
+        zsGrid.deleteSelected();
+        alert('Deleted selected Z39.50 servers');
+    }
+    else {
+        alert('No Z39.50 servers selected');
+    }
+}
+
 openils.Util.addOnLoad(buildZSGrid);