]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/local/asset/copy_tag.js
LP#1673857: admin interfaces for copy tag types and copy tags
[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             controller : [
32                         '$scope', '$uibModalInstance',
33                 function($scope ,  $uibModalInstance) {
34                     $scope.id = id;
35
36                     $scope.ok = function($event) {
37                         $uibModalInstance.close();
38                         gridControls.refresh();
39                     }
40     
41                     $scope.cancel = function($event) {
42                         $uibModalInstance.dismiss();
43                     }
44                 }
45             ]
46         });
47     }
48
49     $scope.delete_record = function(selected) {
50         if (!selected || !selected.length) return;
51
52         egCore.pcrud.retrieve('acpt', selected[0].id).then(function(rec) {
53             egConfirmDialog.open(
54                 egCore.strings.EG_CONFIRM_DELETE_RECORD_TITLE,
55                 egCore.strings.EG_CONFIRM_DELETE_RECORD_BODY,
56                 { id : rec.id() }
57             ).result.then(function() {
58                 egCore.pcrud.remove(rec).then(function() {
59                     $scope.gridControls.refresh();
60                 });
61             });
62         });
63     }
64
65     function generateQuery(orgId) {
66
67         // because the orgId is coming from a selector,
68         // it should always have a value unless the selector
69         // hasn't been fully initialized yet, in which case
70         // we want to abort to avoid fetching anything.
71         if (!orgId) return;
72
73         return {
74             'id' : { '!=' : null },
75             'owner' : egCore.org.descendants(orgId, true)
76         };
77     }
78     $scope.gridControls = {
79         setQuery : function() { return generateQuery(); },
80         setSort : function() {
81             return ['owner.name', 'label'];
82         }
83     }
84
85     $scope.org_changed = function(org) {
86         $scope.gridControls.setQuery(generateQuery(org.id()));
87         $scope.gridControls.refresh();
88     }
89
90 }])