1 angular.module('egLocalAdmin',
2 ['ngRoute', 'ui.bootstrap', 'egCoreMod','egUiMod','egGridMod'])
4 .config(['$routeProvider','$locationProvider','$compileProvider',
5 function($routeProvider , $locationProvider , $compileProvider) {
7 $locationProvider.html5Mode(true);
8 $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|mailto|blob):/);
10 var resolver = {delay : function(egStartup) {return egStartup.go()}};
13 '<eg-embed-frame allow-escape="true" min-height="min_height" url="local_admin_url" handlers="funcs"></eg-embed-frame>';
15 // non-conify routes come first
16 $routeProvider.when('/admin/local/money/cash_reports', {
17 template: eframe_template,
18 controller: 'EmbedXHTMLCtl', // non-conify
22 // non-conify routes come first
23 $routeProvider.when('/admin/local/actor/closed_dates', {
24 template: eframe_template,
25 controller: 'EmbedXHTMLCtl', // non-conify
29 // non-conify routes come first
30 $routeProvider.when('/admin/local/asset/copy_locations', {
31 template: eframe_template,
32 controller: 'EmbedXHTMLCtl', // non-conify
36 // non-conify routes come first
37 $routeProvider.when('/admin/local/asset/org_unit_settings', {
38 template: eframe_template,
39 controller: 'EmbedXHTMLCtl', // non-conify
43 $routeProvider.when('/admin/local/config/non_cat_types', {
44 template: eframe_template,
45 controller: 'EmbedXHTMLCtl', // non-conify
49 $routeProvider.when('/admin/local/asset/stat_cat_editor', {
50 template: eframe_template,
51 controller: 'EmbedXHTMLCtl', // non-conify
55 $routeProvider.when('/admin/local/config/copy_alert_types', {
56 templateUrl: './admin/local/t_grid_editor',
57 controller: 'AutoGridEditorCtl',
60 ccs : { id : {'!=' : null} }
62 createDefaults : { 'in_renew' : 'f', 'next_status' : [] },
63 createEditOrgExpand: ['scope_org'],
64 createEditIntarray: ['next_status'],
65 createEditNullableBool : ['in_renew', 'at_circ', 'at_owning']
68 $routeProvider.when('/admin/local/actor/copy_alert_suppress', {
69 templateUrl: './admin/local/t_grid_editor',
70 controller: 'AutoGridEditorCtl',
73 ccat : { active: 't' }
75 createEditOrgExpand: ['org']
78 // Conify page handler
79 $routeProvider.when('/admin/local/:schema/:page', {
80 template: eframe_template,
81 controller: 'EmbedConifyCtl',
86 $routeProvider.otherwise({
87 templateUrl : './admin/local/t_splash',
92 .controller('EmbedConifyCtl',
93 ['$scope','$routeParams','$location','egCore',
94 function($scope , $routeParams , $location , egCore) {
97 ses : egCore.auth.token(),
100 var conify_path = '/eg/conify/global/' +
101 $routeParams.schema + '/' + $routeParams.page;
103 $scope.min_height = 800;
105 // embed URL must include protocol/domain or it will be loaded via
106 // push-state, resulting in an infinitely nested pages.
107 $scope.local_admin_url =
108 $location.absUrl().replace(/\/eg\/staff\/.*/, conify_path);
110 console.log('Loading local admin URL: ' + $scope.local_admin_url);
114 .controller('EmbedXHTMLCtl',
115 ['$scope','$location','egCore','$timeout',
116 function($scope , $location , egCore , $timeout) {
120 var xul_base = '/xul/server/admin/';
121 var page_parts = $location.path().split(/\//);
122 var url = xul_base + page_parts[page_parts.length - 1] + '.xhtml';
124 // old-school XUL admin UI's only want CGI ses values.
125 url += '?ses=' + egCore.auth.token();
127 console.log('Loading local admin URL: ' + $scope.local_admin_url);
129 $scope.local_admin_url = $location.absUrl().replace(/\/.*/, url);
132 .controller('AutoGridEditorCtl',
133 ['$scope','$route','$location','egCore','$timeout','egConfirmDialog','$uibModal',
134 function($scope , $route , $location , egCore , $timeout , egConfirmDialog , $uibModal) {
138 $scope.baseFmClass = $route.current.$$route.fmBase;
139 $scope.createEditPrefetch = $route.current.$$route.createEditPrefetch || {};
140 $scope.createEditOrgExpand = $route.current.$$route.createEditOrgExpand || [];
141 $scope.createEditNullableBool = $route.current.$$route.createEditNullableBool || [];
142 $scope.createEditIntarray = $route.current.$$route.createEditIntarray || [];
143 $scope.createDefaults = $route.current.$$route.createDefaults || {};
144 $scope.gridControls = {
145 setQuery : function(q) {
149 activateItem : function (item) {
150 $scope.editHandler([item])
153 $scope.gridControls.setQuery({id : {'!=' : null}});
155 function openCreateEditDialog(id) {
156 return $uibModal.open({
157 templateUrl : './admin/local/autoGridEditor/' + $scope.baseFmClass,
160 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
161 $scope.creating = id ? false : true;
162 angular.forEach($scope.$parent.createEditPrefetch, function(where, fmClass) {
165 {atomic : true, authoritative : true}
166 ).then(function(vals) {
167 $scope[fmClass] = vals;
170 if ($scope.creating) {
171 $scope.record = $scope.createDefaults;
173 egCore.pcrud.retrieve($scope.baseFmClass, id).then(function(to_edit) {
174 $scope.record = egCore.idl.toHash(to_edit);
175 angular.forEach($scope.createEditOrgExpand, function(ou_field) {
176 $scope.record[ou_field] = egCore.org.get($scope.record[ou_field]);
178 angular.forEach($scope.createEditIntarray, function(intarray_field) {
179 if (!($scope.record[intarray_field] == null) && $scope.record[intarray_field] != "") {
180 $scope.record[intarray_field] = $scope.record[intarray_field]
185 $scope.record[intarray_field] = [];
190 $scope.ok = function(record) { $uibModalInstance.close(record) };
191 $scope.cancel = function () { $uibModalInstance.dismiss() }
196 $scope.createHandler = function() {
197 openCreateEditDialog().result.then(function(record) {
198 var newRec = new egCore.idl[$scope.baseFmClass]();
199 angular.forEach(record, function(val, key) {
200 if (typeof(val) === 'object' && !angular.isArray(val)) {
201 newRec[key](val.id());
206 angular.forEach($scope.createEditNullableBool, function(nb_field) {
207 if (!(record[nb_field] == null) && record[nb_field] == "")
208 newRec[nb_field](null);
210 angular.forEach($scope.createEditIntarray, function(intarray_field) {
211 if (newRec[intarray_field]().length > 0) {
212 newRec[intarray_field]('{' + newRec[intarray_field]().join(',') + '}');
214 newRec[intarray_field](null);
217 return egCore.pcrud.create(newRec);
219 $scope.gridControls.refresh();
222 $scope.editHandler = function(items) {
223 openCreateEditDialog(items[0].id).result.then(function(record) {
224 var editedRec = new egCore.idl[$scope.baseFmClass]();
225 angular.forEach(record, function(val, key) {
226 if (angular.isObject(val) && !angular.isArray(val)) {
227 editedRec[key](val.id());
232 angular.forEach($scope.createEditNullableBool, function(nb_field) {
233 if (!(record[nb_field] == null) && record[nb_field] == "")
234 editedRec[nb_field](null);
236 angular.forEach($scope.createEditIntarray, function(intarray_field) {
237 if (editedRec[intarray_field]().length > 0) {
238 editedRec[intarray_field]('{' + editedRec[intarray_field]().join(',') + '}');
240 editedRec[intarray_field](null);
243 return egCore.pcrud.update(editedRec);
245 $scope.gridControls.refresh();
248 $scope.deleteHandler = function(items) {
249 egConfirmDialog.open(
250 egCore.strings.REMOVE_ITEM_CONFIRM,
253 ).result.then(function() {
254 var ids = items.map(function(s){ return s.id });
256 $scope.baseFmClass, {id : ids}, {},
257 {atomic : true, authoritative : true}
258 ).then(function(to_delete) {
259 return egCore.pcrud.remove(to_delete);
261 $scope.gridControls.refresh();