]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/local/asset/copy_tag.js
LP#1689325 - require most modals have explicit 'exit' or 'cancel' action inside the...
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / admin / local / asset / copy_tag.js
1 angular.module('egAdminConfig',
2     ['ngRoute','ui.bootstrap','egCoreMod','egUiMod','egGridMod','egFmRecordEditorMod'])
3
4 .controller('CopyTag',
5        ['$scope','$q','$timeout','$location','$window','$uibModal','egCore','egGridDataProvider',
6         'egConfirmDialog',
7 function($scope , $q , $timeout , $location , $window , $uibModal , egCore , egGridDataProvider ,
8          egConfirmDialog) {
9
10     egCore.startup.go(); // standalone mode requires manual startup
11
12     $scope.new_record = function() {
13         spawn_editor();
14     }
15
16     $scope.edit_record = function(items) {
17         if (items.length != 1) return;
18         spawn_editor(items[0].id);
19     }
20
21     spawn_editor = function(id) {
22         var templ;
23         if (arguments.length == 1) {
24             templ = '<eg-edit-fm-record idl-class="acpt" mode="update" record-id="id" on-save="ok" on-cancel="cancel"></eg-edit-fm-record>';
25         } else {
26             templ = '<eg-edit-fm-record idl-class="acpt" mode="create" on-save="ok" on-cancel="cancel"></eg-edit-fm-record>';
27         }
28         gridControls = $scope.gridControls;
29         $uibModal.open({
30             template : templ,
31             backdrop: 'static',
32             controller : [
33                         '$scope', '$uibModalInstance',
34                 function($scope ,  $uibModalInstance) {
35                     $scope.id = id;
36
37                     $scope.ok = function($event) {
38                         $uibModalInstance.close();
39                         gridControls.refresh();
40                     }
41     
42                     $scope.cancel = function($event) {
43                         $uibModalInstance.dismiss();
44                     }
45                 }
46             ]
47         });
48     }
49
50     $scope.delete_record = function(selected) {
51         if (!selected || !selected.length) return;
52
53         egCore.pcrud.retrieve('acpt', selected[0].id).then(function(rec) {
54             egConfirmDialog.open(
55                 egCore.strings.EG_CONFIRM_DELETE_RECORD_TITLE,
56                 egCore.strings.EG_CONFIRM_DELETE_RECORD_BODY,
57                 { id : rec.id() }
58             ).result.then(function() {
59                 egCore.pcrud.remove(rec).then(function() {
60                     $scope.gridControls.refresh();
61                 });
62             });
63         });
64     }
65
66     function generateQuery(orgId) {
67
68         // because the orgId is coming from a selector,
69         // it should always have a value unless the selector
70         // hasn't been fully initialized yet, in which case
71         // we want to abort to avoid fetching anything.
72         if (!orgId) return;
73
74         return {
75             'id' : { '!=' : null },
76             'owner' : egCore.org.descendants(orgId, true)
77         };
78     }
79     $scope.gridControls = {
80         setQuery : function() { return generateQuery(); },
81         setSort : function() {
82             return ['owner.name', 'label'];
83         }
84     }
85
86     $scope.org_changed = function(org) {
87         $scope.gridControls.setQuery(generateQuery(org.id()));
88         $scope.gridControls.refresh();
89     }
90
91 }])