]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/serials/pattern_template.js
Docs: incorporating offline circ docs
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / admin / serials / pattern_template.js
1 angular.module('egAdminConfig',
2     ['ngRoute','ui.bootstrap','egCoreMod','egUiMod','egGridMod','egFmRecordEditorMod','egSerialsMod','egSerialsAppDep'])
3
4 .controller('PatternTemplate',
5        ['$scope','$q','$timeout','$location','$window','$uibModal','egCore','egGridDataProvider',
6         'egConfirmDialog','ngToast',
7 function($scope , $q , $timeout , $location , $window , $uibModal , egCore , egGridDataProvider ,
8          egConfirmDialog , ngToast) {
9
10     egCore.startup.go(); // standalone mode requires manual startup
11
12     $scope.new_record = function() {
13         spawn_editor();
14     }
15
16     $scope.need_one_selected = function() {
17         var items = $scope.gridControls.selectedItems();
18         if (items.length == 1) return false;
19         return true;
20     };
21
22     $scope.edit_record = function(items) {
23         if (items.length != 1) return;
24         spawn_editor(items[0].id);
25     }
26
27     spawn_editor = function(id) {
28         var templ;
29         if (arguments.length == 1) {
30             templ = '<eg-edit-fm-record idl-class="spt" mode="update" record-id="id" on-save="ok" on-cancel="cancel" custom-field-templates="customFieldTemplates"></eg-edit-fm-record>';
31         } else {
32             templ = '<eg-edit-fm-record idl-class="spt" mode="create" on-save="ok" on-cancel="cancel" custom-field-templates="customFieldTemplates" org-default-allowed="owning_lib"></eg-edit-fm-record>';
33         }
34         gridControls = $scope.gridControls;
35         $uibModal.open({
36             template : templ,
37             backdrop: 'static',
38             controller : [
39                         '$scope', '$uibModalInstance',
40                 function($scope ,  $uibModalInstance) {
41                     $scope.id = id;
42
43                     $scope.openPatternEditorDialog = function(pred) {
44                         $uibModal.open({
45                             templateUrl: './serials/t_pattern_editor_dialog',
46                             size: 'lg',
47                             windowClass: 'eg-wide-modal',
48                             backdrop: 'static',
49                             controller:
50                                 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
51                                 $scope.focusMe = true;
52                                 $scope.showShare = false;
53                                 $scope.patternCode = pred.pattern_code;
54                                 $scope.ok = function(patternCode) { $uibModalInstance.close(patternCode) }
55                                 $scope.cancel = function () { $uibModalInstance.dismiss() }
56                             }]
57                         }).result.then(function (patternCode) {
58                             if (pred.pattern_code !== patternCode) {
59                                 pred.pattern_code = patternCode;
60                             }
61                         });
62                     }
63
64                     $scope.customFieldTemplates = {
65                         share_depth : {
66                             template : '<eg-share-depth-selector ng-model="rec_flat[field.name]">'
67                         },
68                         pattern_code : {
69                             handlers : {
70                                 openPatternEditorDialog : $scope.openPatternEditorDialog
71                             },
72                             template : '<button class="btn btn-default" ng-click="field.handlers.openPatternEditorDialog(rec_flat)">Pattern Wizard</button>' + // FIXME i18n
73                                        // using a required hidden input as a way to ensure that
74                                        // the pattern wizard has been used
75                                        '<input type="hidden" required ng-model="rec_flat[field.name]">'
76                         }
77                     }
78
79                     $scope.ok = function($event) {
80                         $uibModalInstance.close();
81                         gridControls.refresh();
82                     }
83     
84                     $scope.cancel = function($event) {
85                         $uibModalInstance.dismiss();
86                     }
87                 }
88             ]
89         });
90     }
91
92     $scope.delete_selected = function(selected) {
93         if (!selected || !selected.length) return;
94         var ids = selected.map(function(rec) { return rec.id });
95
96         egConfirmDialog.open(
97             egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_TITLE,
98             egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_BODY,
99             { count : ids.length }
100         ).result.then(function() {
101             var promises = [];
102             var list = [];
103             angular.forEach(selected, function(rec) {
104                 promises.push(
105                     egCore.pcrud.retrieve('spt', rec.id).then(function(r) {
106                         list.push(r);
107                     })
108                 );
109             })
110             $q.all(promises).then(function() {
111                 egCore.pcrud.remove(list).then(function() {
112                     ngToast.success(egCore.strings.PATTERN_TEMPLATE_SUCCESS_DELETE);
113                     $scope.gridControls.refresh();
114                 },
115                 function() {
116                     ngToast.success(egCore.strings.PATTERN_TEMPLATE_FAIL_DELETE);
117                 });
118             });
119         });
120     }
121
122     function generateQuery() {
123         return {
124             'id' : { '!=' : null },
125         }
126     }
127
128     $scope.gridControls = {
129         setQuery : function() {
130             return generateQuery();
131         },
132         setSort : function() {
133             return ['owning_lib.name','name'];
134         }
135     }
136 }])