* Edit controller!
*/
.controller('EditCtrl',
- ['$scope','$q','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc',
-function($scope , $q , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
+ ['$scope','$q','$window','$routeParams','$location','$timeout','egCore','egNet','egGridDataProvider','itemSvc',
+function($scope , $q , $window , $routeParams , $location , $timeout , egCore , egNet , egGridDataProvider , itemSvc) {
$scope.defaults = { // If defaults are not set at all, allow everything
statcats : true,
$scope.fetchDefaults();
$scope.dirty = false;
+ $scope.$watch('dirty',
+ function(newVal, oldVal) {
+ if (newVal && newVal != oldVal) {
+ $($window).on('beforeunload.edit', function(){
+ return 'There is unsaved data!'
+ });
+ } else {
+ $($window).off('beforeunload.edit');
+ }
+ }
+ );
$scope.show_vols = true;
$scope.show_copies = true;
if ($scope.workingGridControls && $scope.workingGridControls.selectedItems) {
angular.forEach(
$scope.workingGridControls.selectedItems(),
- function (cp) { cp[field](newval); cp.ischanged(1); }
+ function (cp) {
+ if (cp[field]() !== newval) {
+ cp[field](newval);
+ cp.ischanged(1);
+ $scope.dirty = true;
+ }
+ }
);
}
}
angular.forEach(
$scope.workingGridControls.selectedItems(),
function (cp) {
+ $scope.dirty = true;
+
cp.stat_cat_entries(
angular.forEach( cp.stat_cat_entries(), function (e) {
if (e.stat_cat() == id) { // mark deleted
angular.forEach(copies, function(cp) {
if (typeof $scope.batch.classification != 'undefined' && $scope.batch.classification != '')
cp.call_number().label_class($scope.batch.classification);
+ $scope.dirty = true;
if (typeof $scope.batch.prefix != 'undefined' && $scope.batch.prefix != '')
cp.call_number().prefix($scope.batch.prefix);
+ $scope.dirty = true;
if (typeof $scope.batch.label != 'undefined' && $scope.batch.label != '')
cp.call_number().label($scope.batch.label);
+ $scope.dirty = true;
if (typeof $scope.batch.suffix != 'undefined' && $scope.batch.suffix != '')
cp.call_number().suffix($scope.batch.suffix);
+ $scope.dirty = true;
});
});
});
createSimpleUpdateWatcher('opac_visible');
createSimpleUpdateWatcher('ref');
- $scope.saveCompletedCopies = function () {
+ $scope.saveCompletedCopies = function (and_exit) {
var cnHash = {};
var perCnCopies = {};
angular.forEach( $scope.completed_copies, function (cp) {
} else {
perCnCopies[cn_id].push(cp);
}
+ cp.call_number(cn_id); // prevent loops in JSON-ification
});
angular.forEach(perCnCopies, function (v, k) {
egNet.request(
'open-ils.cat',
'open-ils.cat.asset.volume.fleshed.batch.update.override',
- cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
+ egCore.auth.token(), cnList, 1, { auto_merge_vols : 1, create_parts : 1 }
).then(function(update_count) {
alert(update_count + ' call numbers updated');
+ if (and_exit) {
+ $scope.dirty = false;
+ $timeout(function(){$window.close()});
+ }
});
}
+ $scope.saveAndExit = function () {
+ $scope.saveCompletedCopies(true);
+ }
+
}
}])
replace: true,
template: '<div ng-include="'+"'/eg/staff/cat/volcopy/t_attr_edit'"+'"></div>',
scope: { },
- controller : ['$scope','itemSvc','egCore',
- function ( $scope , itemSvc , egCore ) {
+ controller : ['$scope','$window','itemSvc','egCore',
+ function ( $scope , $window , itemSvc , egCore ) {
$scope.defaults = { // If defaults are not set at all, allow everything
statcats : true,
$scope.fetchDefaults();
$scope.dirty = false;
+ $scope.$watch('dirty',
+ function(newVal, oldVal) {
+ if (newVal && newVal != oldVal) {
+ $($window).on('beforeunload.template', function(){
+ return 'There is unsaved template data!'
+ });
+ } else {
+ $($window).off('beforeunload.template');
+ }
+ }
+ );
+
$scope.template_controls = true;
$scope.fetchTemplates = function () {
egCore.hatch.setItem('cat.copy.templates', $scope.templates);
$scope.$parent.fetchTemplates();
+
+ $scope.dirty = false;
}
}
var newval = $scope.working.statcats[id];
if (typeof newval != 'undefined') {
+ $scope.dirty = true;
if (angular.isObject(newval)) { // we'll use the pkey
newval = newval.id();
}
}
});
$scope.working.circ_lib = undefined; // special
+ $scope.dirty = false;
}
$scope.working = {};