1 angular.module('egAcqAdmin',
2 ['ngRoute', 'ui.bootstrap', 'egCoreMod','egUiMod'])
4 .config(['$routeProvider','$locationProvider','$compileProvider',
5 function($routeProvider , $locationProvider , $compileProvider) {
7 $locationProvider.html5Mode(true);
8 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/);
9 var resolver = {delay : function(egStartup) {return egStartup.go()}};
11 $routeProvider.when('/admin/acq/edi_attr_set', {
12 templateUrl: './admin/acq/t_edi_attr_set',
13 controller: 'EDIAttrSet',
18 '<eg-embed-frame allow-escape="true" min-height="min_height" url="acq_admin_url" handlers="funcs"></eg-embed-frame>';
20 $routeProvider.when('/admin/acq/:noun/:verb/:extra?', {
21 template: eframe_template,
22 controller: 'EmbedAcqCtl',
27 $routeProvider.otherwise({
28 templateUrl : './admin/acq/t_splash',
33 .controller('EmbedAcqCtl',
34 ['$scope','$routeParams','$location','egCore',
35 function($scope , $routeParams , $location , egCore) {
38 ses : egCore.auth.token(),
41 var acq_path = '/eg/';
43 if ($routeParams.noun == 'conify') {
44 acq_path += 'conify/global/acq/' + $routeParams.verb
45 + (typeof $routeParams.extra != 'undefined'
46 ? '/' + $routeParams.extra
51 + $routeParams.noun + '/' + $routeParams.verb
52 + (typeof $routeParams.extra != 'undefined'
53 ? '/' + $routeParams.extra
58 $scope.min_height = 2000; // give lots of space to start
60 // embed URL must include protocol/domain or it will be loaded via
61 // push-state, resulting in an infinitely nested pages.
62 $scope.acq_admin_url =
63 $location.absUrl().replace(/\/eg\/staff.*/, acq_path);
65 console.log('Loading Admin Acq URL: ' + $scope.acq_admin_url);
69 .controller('EDIAttrSet',
70 ['$scope','$q','egCore','ngToast','egConfirmDialog',
71 function($scope , $q , egCore , ngToast , egConfirmDialog) {
73 $scope.cur_attr_set = null;
75 // fetch all the data needed to render the page.
76 function load_data() {
78 return egCore.pcrud.retrieveAll('aea', {},
79 {atomic : true, authoritative : true})
83 return egCore.pcrud.retrieveAll('aeas',
84 {flesh : 1, flesh_fields : {'aeas' : ['attr_maps']}},
85 {atomic : true, authoritative : true}
89 ).then(function(sets) {
90 $scope.attr_sets = sets.sort(function(a, b) {
91 return a.label() < b.label() ? -1 : 1;
94 // create a simple true/false attr_set => attr mapping
96 angular.forEach(sets, function(set) {
98 angular.forEach(set.attr_maps(), function(map) {
99 set._local_map[map.attr()] = true;
102 if ($scope.cur_attr_set && set.id()
103 == $scope.cur_attr_set.id()) {
108 $scope.select_set(select_me || $scope.attr_sets[0]);
112 function create_sets() {
113 var new_sets = $scope.attr_sets.filter(function(set) {
114 if (set.isnew() && set.label()) {
115 console.debug('creating new set: ' + set.label());
121 if (new_sets.length == 0) return $q.when();
123 // create the new attrs sets and collect the newly generated
124 // ID in the local data store.
125 return egCore.pcrud.apply(new_sets).then(
128 $scope.attr_sets = $scope.attr_sets.filter(
129 function(set) { return (set.label() && !set.isnew()) });
133 var old_set = new_sets.filter(function(s) {
134 return (s.isnew() && s.label() == new_set.label()) })[0];
135 old_set.id(new_set.id());
136 old_set.isnew(false);
141 function modify_maps() {
142 var update_maps = [];
144 angular.forEach($scope.attr_sets, function(set) {
145 console.debug('inspecting attr set ' + set.label());
147 // find maps that need deleting
148 angular.forEach(set.attr_maps(), function(oldmap) {
149 if (!set._local_map[oldmap.attr()]) {
150 console.debug('\tdeleting map for ' + oldmap.attr());
151 oldmap.isdeleted(true);
152 update_maps.push(oldmap);
156 // find maps that need creating
157 angular.forEach(set._local_map, function(value, key) {
160 var existing = set.attr_maps().filter(
161 function(emap) { return emap.attr() == key })[0];
163 if (existing) return;
165 console.debug('\tcreating map for ' + key);
167 var newmap = new egCore.idl.aeasm();
170 newmap.attr_set(set.id());
171 update_maps.push(newmap);
175 return egCore.pcrud.apply(update_maps);
178 // mark the currently selected attr set as the main display set.
179 $scope.select_set = function(set) {
180 $scope.cur_attr_set_uses = 0; // how many edi accounts use this set
182 $scope.cur_attr_set = set;
184 egCore.pcrud.search('acqedi', {attr_set : set.id()}, {},
185 {idlist : true, atomic : true}
186 ).then(function(accts) {
187 $scope.cur_attr_set_uses = accts.length;
188 $scope.cur_attr_set = set;
193 $scope.new_set = function() {
194 var set = new egCore.idl.aeas();
198 $scope.select_set(set);
199 $scope.attr_sets.push(set);
202 $scope.apply = function() {
203 $scope.save_in_progress = true;
208 ngToast.create(egCore.strings.ATTR_SET_SUCCESS)
211 ngToast.warning(egCore.strings.ATTR_SET_ERROR);
216 function() { $scope.save_in_progress = false; }
220 // Delete the currently selected attr set.
221 // Attr set maps will cascade delete.
222 $scope.remove = function() {
223 egConfirmDialog.open(
224 egCore.strings.ATTR_SET_DELETE_CONFIRM,
225 $scope.cur_attr_set.label()
226 ).result.then(function() {
227 $scope.save_in_progress = true;
228 ( // remove from server if necessary
229 $scope.cur_attr_set.isnew() ?
231 egCore.pcrud.remove($scope.cur_attr_set)
233 // remove from the local att_sets list
235 ngToast.create(egCore.strings.ATTR_SET_SUCCESS);
236 $scope.attr_sets = $scope.attr_sets.filter(
238 return set.id() != $scope.cur_attr_set.id()
241 $scope.cur_attr_set = $scope.attr_sets[0];
243 function() { ngToast.warning(egCore.strings.ATTR_SET_ERROR) }
246 function() { $scope.save_in_progress = false; }