--- /dev/null
+
+<div class="strong-text-2">[% l('Group Member Details') %]</div>
+<div class="pad-vert"></div>
+<eg-grid
+ idl-class="au"
+ query="gridQuery"
+ sort="gridSort"
+ revision="gridRevision"
+ grid-controls="gridControls"
+ menu-label="[% l('Group Actions') %]">
+
+ <eg-grid-menu-item handler="moveToGroup"
+ label="[% l('Move Another Patron To This Group') %]"></eg-grid-menu-item>
+
+ <eg-grid-action label="[% l('Remove Selected From Group') %]"
+ handler="removeFromGroup"></eg-grid-action>
+
+ <eg-grid-field path="active"></eg-grid-field>
+ <eg-grid-field path="barred"></eg-grid-field>
+ <eg-grid-field path="dob"></eg-grid-field>
+ <eg-grid-field path="family_name"></eg-grid-field>
+ <eg-grid-field path="first_given_name"></eg-grid-field>
+ <eg-grid-field path="master_account"></eg-grid-field>
+ <eg-grid-field path="second_given_name"></eg-grid-field>
+ <eg-grid-field path="stats.fines.balance_owed" nonsortable label="[% l('Balance Owed') %]"></eg-grid-field>
+ <eg-grid-field path="stats.checkouts.count" nonsortable label="[% l('Items Out') %]"></eg-grid-field>
+ <eg-grid-field path="stats.checkouts.overdue" nonsortable label="[% l('Items Overdue') %]"></eg-grid-field>
+
+ <!-- needed for query, sorting -->
+ <eg-grid-field path="id" hidden required></eg-grid-field>
+ <eg-grid-field path="usrgroup" hidden required></eg-grid-field>
+ <eg-grid-field path="deleted" hidden required></eg-grid-field>
+ <eg-grid-field path="create_date" hidden required></eg-grid-field>
+
+ <!--
+ <eg-grid-field path=".*"></eg-grid-field>
+ -->
+
+</eg-grid>
resolve : resolver
});
+ $routeProvider.when('/circ/patron/:id/group', {
+ templateUrl: './circ/patron/t_group',
+ controller: 'PatronGroupCtrl',
+ resolve : resolver
+ });
+
$routeProvider.otherwise({redirectTo : '/circ/patron/search'});
})
return deferred.promise;
}
+ service.fetchGroupFines = function() {
+ return egCore.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.usergroup.members.balance_owed',
+ egCore.auth.token(), service.current.usrgroup()
+ ).then(function(list) {
+ var total = 0;
+ angular.forEach(list, function(u) {
+ total += 100 * Number(u.balance_owed)
+ });
+ service.patron_stats.fines.group_balance_owed = total / 100;
+ });
+ }
- // grab additional circ info
- service.fetchUserStats = function() {
+ service.getUserStats = function(id) {
return egCore.net.request(
'open-ils.actor',
'open-ils.actor.user.opac.vital_stats.authoritative',
- egCore.auth.token(), service.current.id()
+ egCore.auth.token(), id
).then(
function(stats) {
// force numeric to ensure correct boolean handling in templates
stats.checkouts.claims_returned =
Number(stats.checkouts.claims_returned);
stats.checkouts.lost = Number(stats.checkouts.lost);
- service.patron_stats = stats
+ return stats;
}
- )
+ );
+ }
+
+
+ // grab additional circ info
+ service.fetchUserStats = function() {
+ return service.getUserStats(service.current.id())
+ .then(function(stats) {
+ service.patron_stats = stats
+ return service.fetchGroupFines();
+ });
}
// Avoid using parens [e.g. (1.23)] to indicate negative numbers,
refreshPage();
}])
+.controller('PatronGroupCtrl',
+ ['$scope','$routeParams','$q','$location','egCore',
+ 'patronSvc','$modal','egPromptDialog','egConfirmDialog',
+function($scope, $routeParams , $q , $location , egCore ,
+ patronSvc , $modal , egPromptDialog , egConfirmDialog) {
+
+ var usr_id = $routeParams.id;
+
+ var statsCache = {};
+ var gridQuery = {};
+
+ $scope.gridQuery = function() {return gridQuery}
+ $scope.gridRevision = 0;
+ $scope.gridSort = ['create_date'];
+ $scope.gridControls = {
+ itemRetrieved : function(item) {
+
+ if (statsCache[item.id]) {
+ item.stats = statsCache[item.id];
+ } else {
+ // user retrieved, flesh their stats
+ patronSvc.getUserStats(item.id).then(function(stats) {
+ item.stats = statsCache[item.id] = stats;
+ });
+ }
+ }
+ }
+
+ $scope.initTab('other', $routeParams.id).then(function() {
+ // let initTab() fetch the user first so we can know the usrgroup
+ gridQuery = {
+ usrgroup : patronSvc.current.usrgroup(),
+ deleted : 'f'
+ }
+ });
+
+ $scope.removeFromGroup = function(selected) {
+ var promises = [];
+ angular.forEach(selected, function(user) {
+ console.debug('removing user ' + user.id + ' from group');
+
+ promises.push(
+ egCore.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.usergroup.new',
+ egCore.auth.token(), user.id, true
+ )
+ );
+ });
+
+ $q.all(promises).then(function() {$scope.gridRevision++});
+ }
+
+ function addUserToGroup(user) {
+ user.usrgroup(patronSvc.current.usrgroup());
+ user.ischanged(true);
+ egCore.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.patron.update',
+ egCore.auth.token(), user
+
+ ).then(function() {
+ $scope.gridRevision++;
+ });
+ }
+
+ function showMoveToGroupConfirm(barcode) {
+
+ // find the user
+ egCore.pcrud.search('ac', {barcode : barcode})
+
+ // fetch the fleshed user
+ .then(function(card) {
+
+ if (!card) return; // TODO: warn user
+
+ egCore.pcrud.retrieve('au', card.usr())
+ .then(function(user) {
+ user.card(card);
+ $modal.open({
+ templateUrl: './circ/patron/t_add_to_group_dialog',
+ controller: [
+ '$scope','$modalInstance',
+ function($scope , $modalInstance) {
+ $scope.user = user;
+ $scope.ok =
+ function(count) { $modalInstance.close() }
+ $scope.cancel =
+ function () { $modalInstance.dismiss() }
+ }
+ ]
+ }).result.then(function() {
+ addUserToGroup(user);
+ });
+ });
+ });
+ }
+
+ $scope.moveToGroup = function() {
+ egPromptDialog.open(
+ egCore.strings.GROUP_ADD_USER, '',
+ {ok : function(value) {
+ if (value)
+ showMoveToGroupConfirm(value);
+ }}
+ );
+ }
+
+}])
+
idl_field.datatype == 'link' ||
idl_field.datatype == 'org_unit')) {
class_obj = egCore.idl.classes[idl_field['class']];
- } else {
- if (path_idx < (path_parts.length - 1)) {
- // we ran out of classes to hop through before
- // we ran out of path components
- console.error("egGrid: invalid IDL path: " + path);
- }
}
+ // else, path is not in the IDL, which is fine
}
if (!idl_field) return null;
gridData.select = function(items) {
}
+ // attempts a flat field lookup first. If the column is not
+ // found on the top-level object, attempts a nested lookup
+ gridData.itemFieldValue = function(item, column) {
+ if (column.name in item) {
+ if (typeof item[column.name] == 'function') {
+ return item[column.name]();
+ } else {
+ return item[column.name];
+ }
+ } else {
+ return gridData.nestedItemFieldValue(item, column);
+ }
+ }
+
gridData.flatItemFieldValue = function(item, column) {
return item[column.name];
}
}
);
}
- provider.itemFieldValue = provider.flatItemFieldValue;
+ //provider.itemFieldValue = provider.flatItemFieldValue;
return provider;
}
};