]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/acq/app.js
LP#1689325 - require most modals have explicit 'exit' or 'cancel' action inside the...
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / acq / app.js
1 angular.module('egAcquisitions',
2     ['ngRoute', 'ui.bootstrap', 'egCoreMod','egUiMod','egMarcMod'])
3
4 .config(['$routeProvider','$locationProvider','$compileProvider', 
5  function($routeProvider , $locationProvider , $compileProvider) {
6
7     $locationProvider.html5Mode(true);
8     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); 
9     var resolver = {delay : function(egStartup) {return egStartup.go()}};
10
11     var eframe_template = 
12         '<eg-embed-frame allow-escape="true" min-height="min_height" url="acq_url" handlers="funcs"></eg-embed-frame>';
13
14     $routeProvider.when('/acq/legacy/:noun/:verb', {
15         template: eframe_template,
16         controller: 'EmbedAcqCtl',
17         resolve : resolver
18     });
19
20     $routeProvider.when('/acq/legacy/:noun/:verb/:record', {
21         template: eframe_template,
22         controller: 'EmbedAcqCtl',
23         resolve : resolver
24     });
25
26     // default page 
27     $routeProvider.otherwise({
28         templateUrl : './t_splash',
29         resolve : resolver
30     });
31 }])
32
33 .controller('EmbedAcqCtl', 
34        ['$scope','$routeParams','$location','$window','$timeout','egCore','$uibModal',
35 function($scope , $routeParams , $location , $window , $timeout , egCore , $uibModal) {
36
37     var relay_url = function(url) {
38         if (url.match(/\/eg\/acq/)) {
39             var munged_url = egCore.env.basePath + 
40                 url.replace(/^.*?\/eg\/acq\//, "acq/legacy/");
41             $timeout(function() { $window.open(munged_url, '_blank') });
42         } else if (url.match(/\/eg\/vandelay/)) {
43             var munged_url = egCore.env.basePath + 
44                 url.replace(/^.*?\/eg\/vandelay\/vandelay/, "cat/catalog/vandelay");
45             $timeout(function() { $window.open(munged_url, '_blank') });
46         }
47     }
48
49     // minimal version sufficient to update copy barcodes
50     var volume_item_creator = function(params) {
51         egCore.net.request(
52             'open-ils.actor',
53             'open-ils.actor.anon_cache.set_value',
54             null, 'edit-these-copies', {
55                 copies: params.existing_copies.map(function(acp) { return acp.id(); }),
56                 raw: [],
57                 hide_vols : false,
58                 hide_copies : false
59             }
60         ).then(function(key) {
61             if (key) {
62                 var url = egCore.env.basePath + 'cat/volcopy/' + key;
63                 $timeout(function() { $window.open(url, '_blank') });
64             } else {
65                 alert('Could not create anonymous cache key!');
66             }
67         });
68     }
69
70     var edit_marc_order_record = function(li, callback) {
71         var args = {
72             'marc_xml' : li.marc()
73         };
74         $uibModal.open({
75             templateUrl: './acq/t_edit_marc_order_record',
76             size: 'lg',
77             backdrop: 'static',
78             controller:
79                 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
80                 $scope.focusMe = true;
81                 $scope.args = args;
82                 $scope.dirty_flag = false;
83                 $scope.ok = function(args) { $uibModalInstance.close(args) }
84                 $scope.cancel = function () { $uibModalInstance.dismiss() }
85             }]
86         }).result.then(function (args) {
87             li.marc(args.marc_xml);
88             egCore.net.request(
89                 'open-ils.acq',
90                 'open-ils.acq.lineitem.update',
91                 egCore.auth.token(),
92                 li
93             ).then(function() {
94                 callback(li);
95             });
96         });
97     }
98
99     $scope.funcs = {
100         ses : egCore.auth.token(),
101         relay_url : relay_url,
102         volume_item_creator : volume_item_creator,
103         edit_marc_order_record : edit_marc_order_record
104     }
105
106     var acq_path = '/eg/acq/' + 
107         $routeParams.noun + '/' + $routeParams.verb +
108         ((typeof $routeParams.record != 'undefined') ? '/' + $routeParams.record : '') +
109         location.search;
110
111     $scope.min_height = 2000; // give lots of space to start
112
113     // embed URL must include protocol/domain or it will be loaded via
114     // push-state, resulting in an infinitely nested pages.
115     $scope.acq_url = 
116         $location.absUrl().replace(/\/eg\/staff.*/, acq_path);
117
118     console.log('Loading Acq URL: ' + $scope.acq_url);
119
120 }])
121