From cee5310eb751aed14670d68e8a524480bc94cb52 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 28 Aug 2015 17:46:06 -0400 Subject: [PATCH] webstaff: Stat cat editing, templating, and defaults Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- .../templates/staff/cat/volcopy/t_attr_edit.tt2 | 134 +++++----- .../src/templates/staff/cat/volcopy/t_defaults.tt2 | 6 +- .../src/templates/staff/cat/volcopy/t_edit.tt2 | 2 + .../web/js/ui/default/staff/cat/volcopy/app.js | 273 +++++++++++++++++++-- 4 files changed, 341 insertions(+), 74 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 b/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 index e8fe8bcc2d..b38db523a2 100644 --- a/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 +++ b/Open-ILS/src/templates/staff/cat/volcopy/t_attr_edit.tt2 @@ -1,48 +1,48 @@
-
-
-
[% l('Template') %]
-
-
- -
-
- -
-
-
-
-
- - +
+
+
[% l('Template') %]
+
+
+ +
+
+ +
+
+
+
+
+ + +
-
-
-
- - +
+
+ + +
+
+ +
-
- -
-
-
+
-
-
- [% l('Circulate?') %] -
-
- [% l('Status') %] -
-
- [% l('Statistical Catagories') %] +
+
+ [% l('Circulate?') %] +
+
+ [% l('Status') %] +
+
+ [% l('Statistical Catagories') %] +
-
@@ -66,8 +66,8 @@
+ ng-options="s.id() as s.name() for s in status_list"> +
@@ -158,7 +158,7 @@
-
+
+ ng-options="t.code() as t.value() for t in circ_type_list"> + +
@@ -318,22 +319,41 @@
-
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
- statcats
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+ {{ sc.owner().name() }} : {{ sc.name() }} +
+
+
+
+ +
+
+
+
+
diff --git a/Open-ILS/src/templates/staff/cat/volcopy/t_defaults.tt2 b/Open-ILS/src/templates/staff/cat/volcopy/t_defaults.tt2 index 9f74e13d8e..44c28d88a6 100644 --- a/Open-ILS/src/templates/staff/cat/volcopy/t_defaults.tt2 +++ b/Open-ILS/src/templates/staff/cat/volcopy/t_defaults.tt2 @@ -241,7 +241,7 @@
@@ -254,6 +254,10 @@
+
diff --git a/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 b/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 index c663610079..9c43e98cdc 100644 --- a/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 +++ b/Open-ILS/src/templates/staff/cat/volcopy/t_edit.tt2 @@ -85,6 +85,8 @@ features="startSelected,-pagination,-actions,-picker,-index" items-provider="workingGridDataProvider" grid-controls="workingGridControls" + on-select="handleItemSelect" + after-select="afterItemSelect" persist-key="cat.volcopy.copies"> 0) { + $scope.in_item_select = true; + + angular.forEach(Object.keys($scope.defaults.attributes), function (attr) { + + var value_hash = {}; + angular.forEach(item_list, function (item) { + if (item[attr]) { + var v = item[attr]() + if (angular.isObject(v)) { + if (v.id) v = v.id(); + else if (v.code) v = v.code(); + } + value_hash[v] = 1; + } + }); + + if (Object.keys(value_hash).length == 1) { + if (attr == 'circ_lib') { + $scope.working[attr] = egCore.org.get(item_list[0][attr]()); + } else { + $scope.working[attr] = item_list[0][attr](); + } + } else { + $scope.working[attr] = undefined; + } + }); + + angular.forEach($scope.statcats, function (sc) { + + var counter = -1; + var value_hash = {}; + var none = false; + angular.forEach(item_list, function (item) { + if (item.stat_cat_entries().length > 0) { + var right_sc = item.stat_cat_entries().filter(function (e) { + return e.stat_cat() == sc.id() && !Boolean(e.isdeleted()); + }); + + if (right_sc.length > 0) { + value_hash[right_sc[0].stat_cat_entry()] = right_sc[0].stat_cat_entry(); + } else { + none = true; + } + } else { + none = true; + } + }); + + if (!none && Object.keys(value_hash).length == 1) { + $scope.working.statcats[sc.id()] = value_hash[Object.keys(value_hash)[0]]; + } else { + $scope.working.statcats[sc.id()] = undefined; + } + }); + + } else { + $scope.clearWorking(); + } + + } + $scope.$watch('data.copies.length', function () { if ($scope.data.copies) { var base_orgs = $scope.data.copies.map(function(cp){ return cp.circ_lib() - }).filter(function(e,i,a){ + }).concat( + $scope.data.copies.map(function(cp){ + return cp.call_number().owning_lib() + }) + ).concat( + [egCore.auth.user().ws_ou()] + ).filter(function(e,i,a){ return a.lastIndexOf(e) === i; }); @@ -729,6 +889,28 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg }); $scope.location_list = list; }); + + $scope.statcat_filter_list = []; + angular.forEach($scope.location_orgs, function (o) { + $scope.statcat_filter_list.push(egCore.org.get(o)); + }); + + itemSvc.get_statcats($scope.location_orgs).then(function(list){ + $scope.statcats = list; + angular.forEach($scope.statcats, function (s) { + + if (!$scope.working) + $scope.working = { statcats: {}, statcat_filter: undefined}; + if (!$scope.working.statcats) + $scope.working.statcats = {}; + + if (!$scope.in_item_select) { + $scope.working.statcats[s.id()] = undefined; + } + createStatcatUpdateWatcher(s.id()); + }); + $scope.in_item_select = false; + }); } } } @@ -811,6 +993,7 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg function ( $scope , itemSvc , egCore ) { $scope.defaults = { // If defaults are not set at all, allow everything + statcats : true, attributes : { status : true, loan_duration : true, @@ -837,6 +1020,7 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg egCore.hatch.getItem('cat.copy.defaults').then(function(t) { if (t) { $scope.defaults = t; + $scope.working.statcat_filter = $scope.defaults.statcat_filter; } }); } @@ -857,10 +1041,16 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg $scope.applyTemplate = function (n) { angular.forEach($scope.templates[n], function (v,k) { - $scope.working[k] = angular.copy(v); + if (!angular.isObject(v)) { + $scope.working[k] = angular.copy(v); + } else { + angular.forEach(v, function (sv,sk) { + $scope.working[k][sk] = angular.copy(sv); + }); + } }); } - + $scope.deleteTemplate = function (n) { if (n) { delete $scope.templates[n] @@ -919,7 +1109,7 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg else if (newval.code) $scope.working[field] = newval.code(); } - if (newval == "") { + if (""+newval == "" || newval == null) { $scope.working[field] = undefined; } @@ -927,13 +1117,45 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg }); } + $scope.working = { + statcats: {}, + statcat_filter: undefined + }; + + createStatcatUpdateWatcher = function (id) { + return $scope.$watch('working.statcats[' + id + ']', function () { + if ($scope.working.statcats) { + var newval = $scope.working.statcats[id]; + + if (typeof newval != 'undefined') { + if (angular.isObject(newval)) { // we'll use the pkey + newval = newval.id(); + } + + if (""+newval == "" || newval == null) { + $scope.working.statcats[id] = undefined; + newval = null; + } + + } + } + }); + } + $scope.clearWorking = function () { - angular.forEach($scope.working, function (v,k) { - if (typeof v != 'undefined') - $scope.working[k] = undefined; + angular.forEach($scope.working, function (v,k,o) { + if (!angular.isObject(v)) { + if (typeof v != 'undefined') + $scope.working[k] = undefined; + } else if (k != 'circ_lib') { + angular.forEach(v, function (sv,sk) { + $scope.working[k][sk] = undefined; + }); + } }); + $scope.working.circ_lib = undefined; // special } - + $scope.working = {}; $scope.location_orgs = []; $scope.location_cache = {}; @@ -945,6 +1167,25 @@ function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , eg $scope.location_list = list; }); createSimpleUpdateWatcher('location'); + + $scope.statcat_filter_list = egCore.org.fullPath( egCore.auth.user().ws_ou() ); + + $scope.statcats = []; + itemSvc.get_statcats( + egCore.org.fullPath( egCore.auth.user().ws_ou(), true ) + ).then(function(list){ + $scope.statcats = list; + angular.forEach($scope.statcats, function (s) { + + if (!$scope.working) + $scope.working = { statcats: {}, statcat_filter: undefined}; + if (!$scope.working.statcats) + $scope.working.statcats = {}; + + $scope.working.statcats[s.id()] = undefined; + createStatcatUpdateWatcher(s.id()); + }); + }); $scope.status_list = []; itemSvc.get_statuses().then(function(list){ -- 2.11.0