]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/serials/directives/mfhd_manager.js
LP#1689325 - require most modals have explicit 'exit' or 'cancel' action inside the...
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / serials / directives / mfhd_manager.js
1 angular.module('egSerialsAppDep')
2
3 .directive('egMfhdManager', function() {
4     return {
5         transclude: true,
6         restrict:   'E',
7         scope: {
8             bibId  : '=',
9         },
10         templateUrl: './serials/t_mfhd_manager',
11         controller:
12        ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider',
13         '$uibModal','$timeout','egMfhdCreateDialog','egConfirmDialog',
14 function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
15          $uibModal , $timeout , egMfhdCreateDialog , egConfirmDialog) {
16
17     function reload() {
18         egSerialsCoreSvc.fetch_mfhds($scope.bibId).then(function() {
19             $scope.mfhdGridDataProvider.refresh();
20         });
21     }
22     reload();
23
24     $scope.mfhdGridControls = {
25         activateItem : function (item) { } // TODO
26     };
27     $scope.mfhdGridDataProvider = egGridDataProvider.instance({
28         get : function(offset, count) {
29             return this.arrayNotifier(egSerialsCoreSvc.flatMfhdList, offset, count);
30         }
31     });
32     $scope.need_one_selected = function() {
33         var items = $scope.mfhdGridControls.selectedItems();
34         if (items.length == 1) return false;
35         return true;
36     };
37
38     $scope.createMfhd = function() {
39         egMfhdCreateDialog.open($scope.bibId).result.then(function() {
40             reload();
41         });
42     };
43
44     $scope.edit_mfhd = function() {
45         var items = $scope.mfhdGridControls.selectedItems();
46         if (items.length != 1) return;
47         var args = {
48             'marc_xml' : items[0].marc_xml
49         }
50         $uibModal.open({
51             templateUrl: './share/t_edit_mfhd',
52             backdrop: 'static',
53             size: 'lg',
54             controller:
55                 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
56                 $scope.focusMe = true;
57                 $scope.args = args;
58                 $scope.dirty_flag = false;
59                 $scope.ok = function() { $uibModalInstance.close($scope.args) }
60                 $scope.cancel = function () { $uibModalInstance.dismiss() }
61             }]
62         }).result.then(function (args) {
63             egCore.pcrud.retrieve('sre', items[0].id).then(function(sre) {
64                 sre.marc(args.marc_xml);
65                 egCore.pcrud.update(sre).then(function() {
66                     reload();
67                 });
68             });
69         });
70     };
71
72     $scope.delete_mfhds = function() {
73         var items = $scope.mfhdGridControls.selectedItems();
74         if (items.length <= 0) return;
75         
76         egConfirmDialog.open(
77             egCore.strings.CONFIRM_DELETE_MFHDS,
78             egCore.strings.CONFIRM_DELETE_MFHDS_MESSAGE,
79             {items : items.length}
80         ).result.then(function () {
81             var promises = [];
82             angular.forEach(items, function(mfhd) {
83                 var promise = $q.defer();
84                 promises.push(promise.promise);    
85                 egCore.pcrud.retrieve('sre', mfhd.id).then(function(sre) {
86                     egCore.pcrud.remove(sre).then(function() {
87                         promise.resolve();
88                     });
89                 })
90             });
91             $q.all(promises).then(function() {
92                 reload();
93             });
94         });
95     }
96 }]
97     }
98 })