]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/admin/actor/org_unit/app.js
change to delete to remove, since JS uses delete
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / admin / actor / org_unit / app.js
1 angular.module('egOrgUnitApp',
2     ['ngRoute', 'ui.bootstrap', 'treeControl', 'egCoreMod', 'egUiMod', 'ngToast'])
3
4 .config(['ngToastProvider', function(ngToastProvider) {
5   ngToastProvider.configure({
6     verticalPosition: 'bottom',
7     animation: 'fade'
8   });
9 }])
10
11 .config(function($routeProvider, $locationProvider, $compileProvider) {
12     $locationProvider.html5Mode(true);
13     $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|blob):/); // grid export
14
15     var resolver = {delay :
16         ['egStartup', function(egStartup) {return egStartup.go()}]}
17
18     $routeProvider.when('/admin/actor/org_unit/:org_id', {
19         templateUrl: './admin/actor/org_unit/t_index',
20         controller: 'OrgUnitCtrl',
21         resolve : resolver
22     });
23
24     $routeProvider.when('/admin/actor/org_unit/', {
25         templateUrl: './admin/actor/org_unit/t_index',
26         controller: 'OrgUnitCtrl',
27         resolve : resolver
28     });
29
30     $routeProvider.otherwise({redirectTo : '/admin/actor/org_unit/'});
31 })
32
33 .controller('OrgUnitCtrl',
34        ['$scope','$q','$routeParams','$window','egCore','egOrg','ngToast',
35 function($scope , $q , $routeParams , $window , egCore , egOrg , ngToast ) {
36
37     $scope.reset = function() {
38         $scope.org = angular.copy($scope.selectedNode);
39     };
40
41     $scope.reset();
42
43     // the org tree
44
45     function init(id) {
46         $scope.treedata = [ egCore.idl.toHash( egOrg.tree() ) ];
47         function find_org(tree,id) {
48             if (tree.id==id) {
49                 return tree;
50             }
51             for (var i in tree.children) {
52                 var child = tree.children[i];
53                 ou = find_org( child, id );
54                 if (ou) { return ou; }
55             }
56             return null;
57         }
58         $scope.selected = find_org($scope.treedata,id) || $scope.treedata[0]; // FIXME -- why no work?
59         $scope.expandedNodes = [ $scope.treedata[0], $scope.selected ];
60     }
61     init(1);
62
63     window.phasefx = {
64          'scope' : $scope
65         ,'egorg' : egOrg
66         ,'egcore' : egCore
67     };
68
69     $scope.showSelected = function(sel) {
70         $scope.selectedNode = sel;
71         $scope.org = angular.copy($scope.selectedNode);
72     };
73
74     // the tabs
75     $scope.org_tab = 'main';
76     $scope.set_org_tab = function(tab) {
77         $scope.org_tab = tab;
78
79         switch(tab) {
80
81             case 'main':
82                 break;
83
84             case 'hours':
85                 break;
86
87             case 'addresses':
88                 break;
89         }
90     }
91
92     // main tab behavior
93
94     $scope.update = function() {
95         var new_org = egOrg.get($scope.org.id);
96         new_org.name( $scope.org.name );
97         new_org.shortname( $scope.org.shortname );
98         new_org.email( $scope.org.email );
99         new_org.phone( $scope.org.phone );
100         egCore.pcrud.update(new_org).then(
101             function(res) { // success
102                 window.sessionStorage.removeItem('eg.env.aou.tree');
103                 egCore.env.load();
104                 init(0);
105                 ngToast.create(egCore.strings.ORG_UPDATE_SUCCESS);
106             },
107             function(res) { // failure
108                 ngToast.create(egCore.strings.ORG_UPDATE_FAILURE);
109             },
110             function(res) { // progress
111             }
112         );
113     };
114
115     $scope.remove = function() {
116         var new_org = egOrg.get($scope.org.id);
117         egCore.pcrud.remove(new_org).then(
118             function(res) { // success
119                 window.sessionStorage.removeItem('eg.env.aou.tree');
120                 egCore.env.load();
121                 init(0);
122                 ngToast.create(egCore.strings.ORG_DELETE_SUCCESS);
123             },
124             function(res) { // failure
125                 ngToast.create(egCore.strings.ORG_DELETE_FAILURE);
126             },
127             function(res) { // progress
128             }
129         );
130     };
131
132 }])
133