make copy alert suppression editor feature-complete
authorGalen Charlton <gmc@esilibrary.com>
Fri, 11 Dec 2015 03:35:57 +0000 (22:35 -0500)
committerMike Rylander <mrylander@gmail.com>
Thu, 31 Aug 2017 17:18:18 +0000 (13:18 -0400)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/templates/staff/admin/local/autoGridEditor/acas.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/admin/local/app.js

diff --git a/Open-ILS/src/templates/staff/admin/local/autoGridEditor/acas.tt2 b/Open-ILS/src/templates/staff/admin/local/autoGridEditor/acas.tt2
new file mode 100644 (file)
index 0000000..301834d
--- /dev/null
@@ -0,0 +1,29 @@
+<!-- use <form> so we get submit-on-enter for free -->
+<form class="form-validated" novalidate name="form" ng-submit="ok(record)">
+  <div>
+    <div class="modal-header">
+      <button type="button" class="close" 
+        ng-click="cancel()" aria-hidden="true">&times;</button>
+      <h4 ng-if="creating"  class="modal-title">[% l('Create copy alert suppression rule') %]</h4>
+      <h4 ng-if="!creating" class="modal-title">[% l('Update copy alert suppression rule') %]</h4>
+    </div>
+    <div class="modal-body">
+      <div class="form-group">
+        <label for="copy-alert-type-selector">[% l('Alert Type') %]</label>
+        <select id="copy-alert-type-selector" class="form-control"
+          ng-model="record.alert_type"
+          ng-options="at.id() as at.name() for at in ccat">
+        </select>
+      </div>
+      <div class="form-group">
+        <label for="select-org-unit">[% l('Org Unit') %]</label>
+        <eg-org-selector selected="record.org"></eg-org-selector>
+      </div>
+    </div>
+    <div class="modal-footer">
+      <input type="submit" ng-disabled="form.$invalid" 
+          class="btn btn-primary" value="[% l('Save') %]"/>
+      <button class="btn btn-warning" ng-click="cancel()">[% l('Cancel') %]</button>
+    </div>
+  </div> <!-- modal-content -->
+</form>
index fcceb0b..9d0e802 100644 (file)
@@ -60,7 +60,11 @@ angular.module('egLocalAdmin',
     $routeProvider.when('/admin/local/actor/copy_alert_suppress', {
         templateUrl: './admin/local/t_grid_editor',
         controller: 'AutoGridEditorCtl',
-        fmBase: 'acas'
+        fmBase: 'acas',
+        createEditPrefetch: {
+            ccat : { active: 't' }
+        },
+        createEditOrgExpand: ['org']
     });
 
     // Conify page handler
@@ -124,6 +128,8 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $mo
     $scope.funcs = {};
 
     $scope.baseFmClass = $route.current.$$route.fmBase;
+    $scope.createEditPrefetch = $route.current.$$route.createEditPrefetch || {};
+    $scope.createEditOrgExpand = $route.current.$$route.createEditOrgExpand || [];
     $scope.gridControls = {
         setQuery : function(q) {
             if (q) query = q;
@@ -132,9 +138,66 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $mo
     };
     $scope.gridControls.setQuery({id : {'!=' : null}});
 
+    function openCreateEditDialog(id) {
+        return $modal.open({
+            templateUrl : './admin/local/autoGridEditor/' + $scope.baseFmClass,
+            scope : $scope,
+            controller :
+                ['$scope', '$modalInstance', function($scope, $modalInstance) {
+                $scope.creating = id ? false : true;
+                angular.forEach($scope.$parent.createEditPrefetch, function(where, fmClass) {
+                    egCore.pcrud.search(
+                        fmClass, where, {},
+                        {atomic : true, authoritative : true}
+                    ).then(function(vals) {
+                        $scope[fmClass] = vals;
+                    });
+                });
+                if ($scope.creating) {
+                    $scope.record = {};
+                } else {
+                    egCore.pcrud.retrieve($scope.baseFmClass, id).then(function(to_edit) {
+                        $scope.record = egCore.idl.toHash(to_edit);
+                        angular.forEach($scope.createEditOrgExpand, function(ou_field) {
+                            $scope.record[ou_field] = egCore.org.get($scope.record[ou_field]);
+                        });
+                    });
+                }
+                $scope.ok = function(record) { $modalInstance.close(record) };
+                $scope.cancel = function () { $modalInstance.dismiss() }
+            }]
+        });
+    }
+
     $scope.createHandler = function() {
+        openCreateEditDialog().result.then(function(record) {
+            var newRec = new egCore.idl[$scope.baseFmClass]();
+            angular.forEach(record, function(val, key) {
+                if (typeof(val) === 'object') {
+                    newRec[key](val.id());
+                } else {
+                    newRec[key](val);
+                }
+            });
+            return egCore.pcrud.create(newRec);
+        }).then(function(){
+            $scope.gridControls.refresh();
+        });
     };
     $scope.editHandler = function(items) {
+        openCreateEditDialog(items[0].id).result.then(function(record) {
+            var editedRec = new egCore.idl[$scope.baseFmClass]();
+            angular.forEach(record, function(val, key) {
+                if (typeof(val) === 'object') {
+                    editedRec[key](val.id());
+                } else {
+                    editedRec[key](val);
+                }
+            });
+            return egCore.pcrud.update(editedRec);
+        }).then(function(){
+            $scope.gridControls.refresh();
+        });
     };
     $scope.deleteHandler = function(items) {
         egConfirmDialog.open(