]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/server/config/marc_field.js
LP#1689325 - require most modals have explicit 'exit' or 'cancel' action inside the...
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / admin / server / config / marc_field.js
1 angular.module('egAdminConfig',
2     ['ngRoute','ui.bootstrap','egCoreMod','egUiMod','egGridMod','egFmRecordEditorMod'])
3
4 .controller('MarcField',
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.marc_record_type = 'biblio';
13     $scope.$watch('marc_record_type', function(newVal, oldVal) {
14         if (newVal != oldVal) {
15             $scope.gridControls.setQuery(generateQuery($scope.marc_record_type));
16             $scope.gridControls.refresh();
17         }
18     });
19
20     $scope.new_record = function() {
21         spawn_editor();
22     }
23
24     $scope.edit_record = function(items) {
25         if (items.length != 1) return;
26         spawn_editor(items[0].id);
27     }
28
29     spawn_editor = function(id) {
30         var templ;
31         if (arguments.length == 1) {
32             templ = '<eg-edit-fm-record idl-class="cmrcfld" mode="update" record-id="id" on-save="ok" on-cancel="cancel"></eg-edit-fm-record>';
33         } else {
34             templ = '<eg-edit-fm-record idl-class="cmrcfld" mode="create" on-save="ok" on-cancel="cancel"></eg-edit-fm-record>';
35         }
36         gridControls = $scope.gridControls;
37         $uibModal.open({
38             template : templ,
39             backdrop: 'static',
40             controller : [
41                         '$scope', '$uibModalInstance',
42                 function($scope ,  $uibModalInstance) {
43                     $scope.id = id;
44
45                     $scope.ok = function($event) {
46                         $uibModalInstance.close();
47                         gridControls.refresh();
48                     }
49     
50                     $scope.cancel = function($event) {
51                         $uibModalInstance.dismiss();
52                     }
53                 }
54             ]
55         });
56     }
57
58     $scope.delete_record = function(selected) {
59         if (!selected || !selected.length) return;
60
61         egCore.pcrud.retrieve('cmrcfld', selected[0].id).then(function(rec) {
62             egConfirmDialog.open(
63                 egCore.strings.EG_CONFIRM_DELETE_RECORD_TITLE,
64                 egCore.strings.EG_CONFIRM_DELETE_RECORD_BODY,
65                 { id : rec.id() } // TODO replace with selector if available?
66             ).result.then(function() {
67                 egCore.pcrud.remove(rec).then(function() {
68                     $scope.gridControls.refresh();
69                 });
70             });
71         });
72     }
73
74     function generateQuery(marc_record_type) {
75         return {
76             'id' : { '!=' : null },
77             'marc_record_type' : marc_record_type
78         }
79     }
80
81     $scope.gridControls = {
82         setQuery : function() {
83             return generateQuery($scope.marc_record_type);
84         },
85         setSort : function() {
86             return ['tag'];
87         }
88     }
89 }])