webstaff: implement deleting multiple spts
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 7 Jul 2017 20:06:31 +0000 (16:06 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 7 Jul 2017 20:06:31 +0000 (16:06 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/admin/serials/pattern_template.tt2
Open-ILS/src/templates/staff/serials/share/serials_strings.tt2
Open-ILS/web/js/ui/default/staff/admin/serials/pattern_template.js

index cf90693..8ff7928 100644 (file)
     id-field="id"
     idl-class="spt"
     grid-controls="gridControls"
-    features="-multiselect"
     persist-key="admin.serials.pattern_template">
 
     <eg-grid-menu-item handler="new_record" label="[% l('New Record') %]"></eg-grid-menu-item>
-    <eg-grid-action handler="edit_record" label="[% l('Edit Record') %]"></eg-grid-action>
-    <eg-grid-action handler="delete_record" label="[% l('Delete Record') %]"></eg-grid-action>
+    <eg-grid-action handler="edit_record" label="[% l('Edit Record') %]" disabled="need_one_selected"></eg-grid-action>
+    <eg-grid-action handler="delete_selected" label="[% l('Delete Selected') %]"></eg-grid-action>
 
     <eg-grid-field label="[% l('Name') %]"           path="name"></eg-grid-field>
     <eg-grid-field label="[% l('Pattern Code') %]"   path="pattern_code"></eg-grid-field>
index f4ccc70..80f32ae 100644 (file)
@@ -18,6 +18,10 @@ angular.module('egCoreMod').run(['egStrings', function(s) {
     s.CHRON_LABEL_WEEK   = "[% l('Week') %]";
     s.CHRON_LABEL_DAY    = "[% l('Day') %]";
     s.CHRON_LABEL_HOUR   = "[% l('Hour') %]";
+    s.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_TITLE = "[% l('Confirm Prediction Pattern Template Deletion') %]";
+    s.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_BODY = "[% l('Delete {{count}} template(s)?') %]";
+    s.PATTERN_TEMPLATE_SUCCESS_DELETE = "[% l('Deleted prediation pattern template(s)') %]";
+    s.PATTERN_TEMPLATE_FAIL_DELETE = "[% l('Failed to delete prediction template(s)') %]";
 }]);
 </script>
 
index 603ecc3..c20956f 100644 (file)
@@ -3,9 +3,9 @@ angular.module('egAdminConfig',
 
 .controller('PatternTemplate',
        ['$scope','$q','$timeout','$location','$window','$uibModal','egCore','egGridDataProvider',
-        'egConfirmDialog',
+        'egConfirmDialog','ngToast',
 function($scope , $q , $timeout , $location , $window , $uibModal , egCore , egGridDataProvider ,
-         egConfirmDialog) {
+         egConfirmDialog , ngToast) {
 
     egCore.startup.go(); // standalone mode requires manual startup
 
@@ -13,6 +13,12 @@ function($scope , $q , $timeout , $location , $window , $uibModal , egCore , egG
         spawn_editor();
     }
 
+    $scope.need_one_selected = function() {
+        var items = $scope.gridControls.selectedItems();
+        if (items.length == 1) return false;
+        return true;
+    };
+
     $scope.edit_record = function(items) {
         if (items.length != 1) return;
         spawn_editor(items[0].id);
@@ -79,17 +85,31 @@ function($scope , $q , $timeout , $location , $window , $uibModal , egCore , egG
         });
     }
 
-    $scope.delete_record = function(selected) {
+    $scope.delete_selected = function(selected) {
         if (!selected || !selected.length) return;
+        var ids = selected.map(function(rec) { return rec.id });
 
-        egCore.pcrud.retrieve('spt', selected[0].id).then(function(rec) {
-            egConfirmDialog.open(
-                egCore.strings.EG_CONFIRM_DELETE_RECORD_TITLE,
-                egCore.strings.EG_CONFIRM_DELETE_RECORD_BODY,
-                { id : rec.id() } // TODO replace with selector if available?
-            ).result.then(function() {
-                egCore.pcrud.remove(rec).then(function() {
+        egConfirmDialog.open(
+            egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_TITLE,
+            egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_BODY,
+            { count : ids.length }
+        ).result.then(function() {
+            var promises = [];
+            var list = [];
+            angular.forEach(selected, function(rec) {
+                promises.push(
+                    egCore.pcrud.retrieve('spt', rec.id).then(function(r) {
+                        list.push(r);
+                    })
+                );
+            })
+            $q.all(promises).then(function() {
+                egCore.pcrud.remove(list).then(function() {
+                    ngToast.success(egCore.strings.PATTERN_TEMPLATE_SUCCESS_DELETE);
                     $scope.gridControls.refresh();
+                },
+                function() {
+                    ngToast.success(egCore.strings.PATTERN_TEMPLATE_FAIL_DELETE);
                 });
             });
         });