]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/server/config/marc_field.js
fe6f93ff4a3f8c0816481c6b15640afb3ba89560
[working/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             controller : [
40                         '$scope', '$uibModalInstance',
41                 function($scope ,  $uibModalInstance) {
42                     $scope.id = id;
43
44                     $scope.ok = function($event) {
45                         $uibModalInstance.close();
46                         gridControls.refresh();
47                     }
48     
49                     $scope.cancel = function($event) {
50                         $uibModalInstance.dismiss();
51                     }
52                 }
53             ]
54         });
55     }
56
57     $scope.delete_record = function(selected) {
58         if (!selected || !selected.length) return;
59
60         egCore.pcrud.retrieve('cmrcfld', selected[0].id).then(function(rec) {
61             egConfirmDialog.open(
62                 egCore.strings.EG_CONFIRM_DELETE_RECORD_TITLE,
63                 egCore.strings.EG_CONFIRM_DELETE_RECORD_BODY,
64                 { id : rec.id() } // TODO replace with selector if available?
65             ).result.then(function() {
66                 egCore.pcrud.remove(rec).then(function() {
67                     $scope.gridControls.refresh();
68                 });
69             });
70         });
71     }
72
73     function generateQuery(marc_record_type) {
74         return {
75             'id' : { '!=' : null },
76             'marc_record_type' : marc_record_type
77         }
78     }
79
80     $scope.gridControls = {
81         setQuery : function() {
82             return generateQuery($scope.marc_record_type);
83         },
84         setSort : function() {
85             return ['tag'];
86         }
87     }
88 }])