add multi-select for setting copy alert type next status field
authorGalen Charlton <gmc@esilibrary.com>
Fri, 26 Aug 2016 23:39:04 +0000 (19:39 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 27 Mar 2017 20:23:17 +0000 (16:23 -0400)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/templates/staff/admin/local/autoGridEditor/ccat.tt2
Open-ILS/web/js/ui/default/staff/admin/local/app.js

index 36a2874..727bfd9 100644 (file)
       </div>
       <div class="form-group">
         <label for="edit-alert-next-statuses">[% l('Next Status') %]</label>
-        <input type="text" class="form-control" focus-me='focusMe' 
-          id="edit-alert-next-statuses" ng-model="record.next_status" />
+        <select id="edit-alert-next-statuses" class="form-control" focus-me='focusMe'
+                multiple="multiple" ng-model="record.next_status">
+            <option ng-repeat="s in ccs" value="{{s.id()}}">{{s.name()}}</option>
+        </select>
       </div>
       <div class="form-group">
         <label for="inrenew-selector">[% l('Renewing?') %]</label>
index 4462ce8..c8bfba4 100644 (file)
@@ -58,8 +58,9 @@ angular.module('egLocalAdmin',
         createEditPrefetch: {
             ccs : { id : {'!=' : null} }
         },
-        createDefaults : { 'in_renew' : 'f' },
+        createDefaults : { 'in_renew' : 'f', 'next_status' : [] },
         createEditOrgExpand: ['scope_org'],
+        createEditIntarray: ['next_status'],
         createEditNullableBool : ['in_renew', 'at_circ', 'at_owning']
     });
 
@@ -137,6 +138,7 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $ui
     $scope.createEditPrefetch = $route.current.$$route.createEditPrefetch || {};
     $scope.createEditOrgExpand = $route.current.$$route.createEditOrgExpand || [];
     $scope.createEditNullableBool = $route.current.$$route.createEditNullableBool || [];
+    $scope.createEditIntarray = $route.current.$$route.createEditIntarray || [];
     $scope.createDefaults = $route.current.$$route.createDefaults || [];
     $scope.gridControls = {
         setQuery : function(q) {
@@ -172,6 +174,16 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $ui
                         angular.forEach($scope.createEditOrgExpand, function(ou_field) {
                             $scope.record[ou_field] = egCore.org.get($scope.record[ou_field]);
                         });
+                        angular.forEach($scope.createEditIntarray, function(intarray_field) {
+                            if (!($scope.record[intarray_field] == null) && $scope.record[intarray_field] != "") {
+                                $scope.record[intarray_field] = $scope.record[intarray_field]
+                                                    .replace('{', '')
+                                                    .replace('}', '')
+                                                    .split(',');
+                            } else {
+                                $scope.record[intarray_field] = [];
+                            }
+                        });
                     });
                 }
                 $scope.ok = function(record) { $uibModalInstance.close(record) };
@@ -184,7 +196,7 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $ui
         openCreateEditDialog().result.then(function(record) {
             var newRec = new egCore.idl[$scope.baseFmClass]();
             angular.forEach(record, function(val, key) {
-                if (typeof(val) === 'object') {
+                if (typeof(val) === 'object' && !angular.isArray(val)) {
                     newRec[key](val.id());
                 } else {
                     newRec[key](val);
@@ -194,6 +206,13 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $ui
                 if (!(record[nb_field] == null) && record[nb_field] == "")
                     newRec[nb_field](null);
             });
+            angular.forEach($scope.createEditIntarray, function(intarray_field) {
+                if (newRec[intarray_field]().length > 0) {
+                    newRec[intarray_field]('{' + newRec[intarray_field]().join(',') + '}');
+                } else {
+                    newRec[intarray_field](null);
+                }
+            });
             return egCore.pcrud.create(newRec);
         }).then(function(){
             $scope.gridControls.refresh();
@@ -203,7 +222,7 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $ui
         openCreateEditDialog(items[0].id).result.then(function(record) {
             var editedRec = new egCore.idl[$scope.baseFmClass]();
             angular.forEach(record, function(val, key) {
-                if (angular.isObject(val)) {
+                if (angular.isObject(val) && !angular.isArray(val)) {
                     editedRec[key](val.id());
                 } else {
                     editedRec[key](val);
@@ -213,6 +232,13 @@ function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $ui
                 if (!(record[nb_field] == null) && record[nb_field] == "")
                     editedRec[nb_field](null);
             });
+            angular.forEach($scope.createEditIntarray, function(intarray_field) {
+                if (editedRec[intarray_field]().length > 0) {
+                    editedRec[intarray_field]('{' + editedRec[intarray_field]().join(',') + '}');
+                } else {
+                    editedRec[intarray_field](null);
+                }
+            });
             return egCore.pcrud.update(editedRec);
         }).then(function(){
             $scope.gridControls.refresh();