['$scope','$q','$location','$filter','egCore','egUser','patronSvc',
function($scope, $q, $location , $filter, egCore, egUser, patronSvc) {
+ // returns true if a redirect occurs
function redirectToAlertPanel() {
$scope.alert_penalties =
function() {return patronSvc.alert_penalties}
- if (patronSvc.alertsShown) return;
+ if (patronSvc.alertsShown) return false;
patronSvc.alertsShown = true;
// if the patron has any unshown alerts, show them now
$location
.path('/circ/patron/' + patronSvc.current.id() + '/alerts')
.search('card', null);
- return;
+ return true;
}
// no alert required. If the patron has fines and the show-bills
$location
.path('/circ/patron/' + patronSvc.current.id() + '/bills')
.search('card', null);
+
+ return true;
}
+
+ return false;
}
// called after each route-specified controller is instantiated.
var usr_id = $routeParams.id;
var statsCache = {};
- var gridQuery = {};
$scope.totals = {owed : 0, total_out : 0, overdue : 0}
- $scope.gridQuery = function() {return gridQuery}
- $scope.gridRevision = 0;
$scope.gridSort = ['create_date'];
- $scope.gridControls = {
+ var initQuery;
+ var grid = $scope.gridControls = {
+ activateItem : function(item) {
+ $location.path('/circ/patron/' + item.id + '/checkout');
+ },
itemRetrieved : function(item) {
if (statsCache[item.id]) {
$scope.totals.overdue += stats.checkouts.overdue;
});
}
+ },
+ /*
+ setQuery : function(q) {
+ if (q) initQuery = q;
+ return initQuery;
}
+ */
}
- $scope.initTab('other', $routeParams.id).then(function() {
+ $scope.initTab('other', $routeParams.id)
+ .then(function(redirect) {
+ // if we are redirecting to the alerts page, avoid updating the
+ // grid query.
+ if (redirect) return;
// let initTab() fetch the user first so we can know the usrgroup
- gridQuery = {
+
+ grid.setQuery({
usrgroup : patronSvc.current.usrgroup(),
deleted : 'f'
- }
+ });
$scope.totals.owed = patronSvc.patron_stats.fines.group_balance_owed;
});
);
});
- $q.all(promises).then(function() {$scope.gridRevision++});
+ $q.all(promises).then(function() {grid.refresh()});
}
function addUserToGroup(user) {
'open-ils.actor.patron.update',
egCore.auth.token(), user
- ).then(function() {
- $scope.gridRevision++;
- });
+ ).then(function() {grid.refresh()});
}
// fetch each user ("selected" has flattened users)
);
});
- $q.all(promises).then(function() {
- $scope.gridRevision++;
- });
+ $q.all(promises).then(function() {grid.refresh()});
}
function showMoveToGroupConfirm(barcode, selected) {
$scope.moveToGroup = function() { moveToGroup() };
$scope.moveToAnotherGroup = function(selected) { moveToGroup(selected) };
-
}])
// IDL class hint (e.g. "aou")
idlClass : '@',
- // reference to a function returning a query for the default
- // egGridFlatDataProvider handler. Any time the return value
- // changes, the grid will be refreshed.
- query : '=',
-
- // flattener-style sort array
- sort : '=',
-
// default page size
pageSize : '@',
//
// controller => $scope.myProvider === undefined
//
- // Storing the provider in the local scope just hogs
+ // Storing the provider in the local scope just uses
// resources, anyway.
//
itemsProvider : '=',
// allItems : function(allItems) {}
// selectedItems : function(selected) {}
// selectItems : function(ids) {}
+ // setQuery : function(queryStruct) {} // causes reload
+ // setSort : function(sortSturct) {} // causes reload
gridControls : '=',
-
- // if set, we watch this scope variable for changes. If it
- // changes, we refresh the grid.
- revision : '='
},
// TODO: avoid hard-coded url
$scope.items = [];
$scope.showGridConf = false;
grid.totalCount = -1;
+ $scope.selected = {};
+ // actions for selected items
$scope.actions = [];
grid.addAction = function(act) {
$scope.actions.push(act);
}
- $scope.selected = {};
-
+ // global actions
$scope.menuItems = [];
grid.addMenuItem = function(item) {
$scope.menuItems.push(item);
}
}
- grid.gridControls = $scope.gridControls || {};
+ grid.idlClass = $scope.idlClass;
+ delete $scope.idlClass;
- // items needed only by the grid; remove from scope
- angular.forEach(
- ['idlClass', 'persistKey'],
- function(field) {
- grid[field] = $scope[field];
- delete $scope[field];
- }
- );
+ grid.persistKey = $scope.persistKey;
+ delete $scope.persistKey;
grid.indexField = $scope.idField;
delete $scope.idField;
grid.columnsProvider.compileAutoColumns();
delete $scope.autoFields;
}
-
- /*
- if (grid.onSelectionChange) {
- $scope.$watch('selected', function() {
- grid.onSelectionChange(grid.getSelectedItems())
- }, true);
- }
- */
if (!grid.dataProvider) {
columnsProvider : grid.columnsProvider,
query : $scope.query
});
-
- if (!grid.dataProvider.query) {
- console.error(
- "Grid query is required when no data provider is supplied");
- return;
- }
-
- $scope.$watch(
- function() { return grid.dataProvider.query() },
- function(newVal, oldVal) {
- if (newVal !== oldVal)
- grid.dataProvider.load(true);
- },
- true // object comparison
- );
- delete $scope.query;
}
-
grid.dataProvider.sort = $scope.sort || [];
delete $scope.sort;
- if (angular.isDefined($scope.revision)) {
- $scope.$watch('revision', function(newVal, oldVal) {
- if (newVal != oldVal)
- grid.dataProvider.load(true);
- });
- }
+ $scope.itemFieldValue = grid.dataProvider.itemFieldValue;
+ $scope.indexValue = function(item) {
+ return grid.indexValue(item)
+ };
- grid.dataProvider.load = function(reset) {
- if (reset) grid.offset = 0;
- grid.collect();
- }
-
- grid.dataProvider.getSelectedItems = function() {
- return grid.getSelectedItems();
- }
+ grid.applyControlFunctions();
- grid.dataProvider.selectOneItem = function(index) {
- return grid.selectOneItem(index);
- }
+ grid.loadConfig().then(function() {
+ // link columns to scope after loadConfig(), since it
+ // replaces the columns array.
+ $scope.columns = grid.columnsProvider.columns;
+ });
+ }
+
+ // link our control functions into the gridControls scope
+ // object so the caller can access them.
+ grid.applyControlFunctions = function() {
- // only link the caller mediation functions into
- // the scope if the caller defines handlers.
- grid.gridControls.selectedItems = function() {
+ var controls = $scope.gridControls;
+
+ // link in the control functions
+ controls.selectedItems = function() {
return grid.getSelectedItems()
}
- grid.gridControls.allItems = function() {
+
+ controls.allItems = function() {
return $scope.items;
}
- grid.gridControls.selectItems = function(ids) {
+
+ controls.selectItems = function(ids) {
if (!ids) return;
$scope.selected = {};
angular.forEach(ids, function(i) {
});
}
- $scope.itemFieldValue = grid.dataProvider.itemFieldValue;
- $scope.indexValue = function(item) {
- return grid.indexValue(item)
- };
+ // if the caller provided a functional setQuery,
+ // extract the value before replacing it
+ if (controls.setQuery) {
+ grid.dataProvider.query =
+ controls.setQuery();
+ }
- // this allows the caller to pass in initializtion
- // values, like offset, for cases when the caller may
- // be caching grid data between route loads.
- if (angular.isFunction(grid.dataProvider.initialize)) {
- var conf = grid.dataProvider.initialize();
- if (conf) {
- angular.forEach(conf, function(val, key) {
- if (val !== null) grid[key] = val;
- });
- }
+ controls.setQuery = function(query) {
+ grid.dataProvider.query = query;
+ controls.refresh(true);
}
-
- grid.loadConfig().then(function() {
- // link columns to scope after loadConfig(), since it
- // replaces the columns array.
- $scope.columns = grid.columnsProvider.columns;
- //if (grid.selfManagedData) grid.collect();
- });
+
+ // if the caller provided a functional setSort
+ // extract the value before replacing it
+ if (controls.setSort) {
+ grid.dataProvider.sort =
+ controls.setSort();
+ }
+
+ controls.setSort = function(sort) {
+ controls.refresh(true);
+ }
+
+ controls.refresh = function(reset) {
+ if (reset) grid.offset = 0;
+ grid.collect();
+ }
+
+ grid.dataProvider.refresh = controls.refresh;
}
// remove the stored column configuration preferenc, then recover
// asks the dataProvider for a page of data
grid.collect = function() {
+
+ // avoid firing the collect if there is nothing to collect.
+ if (grid.selfManagedData && !grid.dataProvider.query) return;
+
if (grid.collecting) return; // avoid parallel collects()
// ensure all of our dropdowns are closed
grid.collecting = true;
grid.dataProvider.get(grid.offset, grid.limit).then(
function() {
- if (grid.gridControls.allItemsRetrieved)
- grid.gridControls.allItemsRetrieved();
+ if ($scope.gridControls.allItemsRetrieved)
+ $scope.gridControls.allItemsRetrieved();
},
null,
function(item) {
if (item) {
$scope.items.push(item)
- if (grid.gridControls.itemRetrieved)
- grid.gridControls.itemRetrieved(item);
+ if ($scope.gridControls.itemRetrieved)
+ $scope.gridControls.itemRetrieved(item);
}
})['finally'](function() { grid.collecting = false })
}
return def.promise;
}
- gridData.initialize = function() {
- return {};
- }
-
- // incrementing the provider informs the grid it's time to
- // redraw itself. If reset is true, it resets the grid paging
- // to page 0.
- gridData.increment = function(reset) {
- // if called before the grid is instantiated,
- // load() may not yet be defined.
- if (gridData.load) gridData.load(reset);
- }
+ // Calls the grid refresh function. Once instantiated, the
+ // grid will replace this function with it's own refresh()
+ gridData.refresh = function(reset) { }
// returns a promise whose notify() delivers items
gridData.get = function(index, count) {
if (obj === null || obj === undefined || obj === '') return '';
if (!idlField) return obj;
return obj;
-
- // egGridValueFilter is applied in the template.
- // not sure why this was here.. may be getting
- // called from another context
- //return $filter('egGridValueFilter')(obj, idlField);
}
}
var provider = egGridDataProvider.instance(args);
provider.get = function(offset, count) {
- if (!angular.isFunction(provider.query))
- return $q.when();
- var query = provider.query();
- if (!query || angular.equals(query, {}))
+ // no query means no call
+ if (!provider.query ||
+ angular.equals(provider.query, {}))
return $q.when();
// find all of the currently visible columns
'open-ils.fielder',
'open-ils.fielder.flattened_search',
egCore.auth.token(), provider.idlClass,
- queryFields, query,
+ queryFields, provider.query,
{ sort : provider.sort,
limit : count,
offset : offset