]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/serials/app.js
LP#1736269: Mark Missing Pieces is non-functional
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / serials / app.js
1 angular.module('egSerialsApp', ['ui.bootstrap','ngRoute','egCoreMod','egGridMod','ngToast','egSerialsMod','egMfhdMod','egMarcMod','egSerialsAppDep']);
2 angular.module('egSerialsAppDep', []);
3
4 angular.module('egSerialsApp')
5 .config(['ngToastProvider', function(ngToastProvider) {
6   ngToastProvider.configure({
7     verticalPosition: 'bottom',
8     animation: 'fade'
9   });
10 }])
11
12 .config(function($routeProvider, $locationProvider, $compileProvider) {
13     $locationProvider.html5Mode(true);
14     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/); // grid export
15         
16     var resolver = {delay : function(egStartup) {return egStartup.go()}};
17
18     $routeProvider.when('/serials/:bib_id', {
19         templateUrl: './serials/t_manage',
20         controller: 'ManageCtrl',
21         resolve : resolver
22     });
23
24     $routeProvider.when('/serials/:bib_id/:active_tab', {
25         templateUrl: './serials/t_manage',
26         controller: 'ManageCtrl',
27         resolve : resolver
28     });
29
30     $routeProvider.when('/serials/:bib_id/:active_tab/:subscription_id', {
31         templateUrl: './serials/t_manage',
32         controller: 'ManageCtrl',
33         resolve : resolver
34     });
35 })
36
37 .controller('ManageCtrl',
38        ['$scope','$routeParams','$location','egSerialsCoreSvc',
39 function($scope , $routeParams , $location , egSerialsCoreSvc) {
40     $scope.bib_id = $routeParams.bib_id;
41     $scope.active_tab = $routeParams.active_tab ?  $routeParams.active_tab : 'manage-subscriptions';
42     $scope.ssub = {id : null};
43     if ($routeParams.subscription_id) {
44         egSerialsCoreSvc.verify_subscription_id($scope.bib_id, $routeParams.subscription_id)
45         .then(function(verified) {
46             if (verified) {
47                 $scope.ssub.id = $routeParams.subscription_id;
48             } else {
49                 // subscription ID is no good, so drop it from the URL
50                 $location.path('/serials/' + $scope.bib_id + '/' + $scope.active_tab);
51             }
52         });
53     }
54     $scope.$watch('ssub.id', function(newVal, oldVal) {
55         if (oldVal != newVal) {
56             $location.path('/serials/' + $scope.bib_id + '/' + $scope.active_tab +
57                            '/' + $scope.ssub.id);
58         }
59     });
60     $scope.$watch('active_tab', function(newVal, oldVal) {
61         if (oldVal != newVal) {
62                 var new_path = '/serials/' + $scope.bib_id + '/' + $scope.active_tab;
63                 if ($scope.ssub.id && $scope.active_tab != 'manage-subscriptions') {
64                     new_path += '/' + $scope.ssub.id;
65                 }
66                 $location.path(new_path);
67         }
68     });
69 }])