0bad9cc4250f31969b16dcd20a74927eb072e9c8
[myslice.git] / plugins / scheduler2 / static / js / scheduler-SchedulerCtrl.js
1 var myApp = angular.module('myApp', []);\r
2 myApp.config(function ($interpolateProvider) {\r
3     $interpolateProvider.startSymbol('{[{').endSymbol('}]}');\r
4 });\r
5 myApp.factory('$exceptionHandler', function () {\r
6     return function (exception, cause) {\r
7         if (exception.message.contains('leases')) {\r
8             console.log(exception.message);\r
9             \r
10             var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
11             tmpScope.initSlots(_schedulerCurrentCellPosition, _schedulerCurrentCellPosition + SchedulerTotalVisibleCells);\r
12         }\r
13             \r
14     };\r
15 });\r
16 \r
17 // Create a private execution space for our controller. When\r
18 // executing this function expression, we're going to pass in\r
19 // the Angular reference and our application module.\r
20 (function (ng, app) {\r
21 \r
22 \r
23     // Define our Controller constructor.\r
24     function Controller($scope) {\r
25 \r
26         // Store the scope so we can reference it in our\r
27         // class methods\r
28         this.scope = $scope;\r
29 \r
30         // Set up the default scope value.\r
31         this.scope.errorMessage = null;\r
32         this.scope.name = "";\r
33         //Pagin\r
34         this.scope.totalPages = 4;\r
35         this.scope.curPage = 0;\r
36         this.scope.pageSize = 25;\r
37 \r
38         $scope.resources = SchedulerDataViewData;\r
39         $scope.slots = SchedulerSlotsViewData;\r
40         //$scope.msg = "hello";\r
41 \r
42         angular.element(document).ready(function() {\r
43             //console.log('Hello World');\r
44             //alert('Hello World');\r
45             //afterAngularRendered();\r
46         });\r
47 \r
48         $scope.initSchedulerResources = function (pageSize, filter) {\r
49             for (var k = 0; k < pageSize; k++) {\r
50                 if ($scope.resources.length < SchedulerData.length)\r
51                     $scope.resources.push(jQuery.extend(true, {}, SchedulerData[k]));\r
52                 $scope.resources[k].leases = [];\r
53             }\r
54             $scope.pageSize = pageSize;\r
55             $scope.curPage = 0;\r
56             $scope.totalPages = parseInt(Math.ceil(SchedulerData.length / $scope.pageSize));\r
57             $scope.initSlots(0, SchedulerTotalVisibleCells);\r
58         };\r
59 \r
60         $scope.setPage = function(page) {\r
61             var tmpFrm = $scope.pageSize * page;\r
62             var tmpTo = tmpFrm + $scope.pageSize;\r
63             $scope.curPage = page;\r
64             $scope.resources = [];\r
65             for (var k = tmpFrm; k < tmpTo; k++) {\r
66                 if ($scope.resources.length < SchedulerData.length)\r
67                     $scope.resources.push(jQuery.extend(true, {}, SchedulerData[k]));\r
68                 $scope.resources[k].leases = [];\r
69             }\r
70             $scope.initSlots(0, SchedulerTotalVisibleCells);\r
71         };\r
72 \r
73         $scope.initSlots = function (from, to) {\r
74             //init\r
75             $scope.slots = [];\r
76             //set\r
77             for (var i = from; i < to; i++) {\r
78                 $scope.slots.push(SchedulerSlots[i]);\r
79                 for (var j = 0; j < $scope.resources.length; j++) {\r
80                     $scope.resources[j].leases.push(SchedulerData[j].leases[i]);\r
81                 }\r
82             }\r
83             //apply\r
84             $scope.$apply();\r
85         };\r
86 \r
87         $scope.moveFrontSlot = function(from, to) {\r
88             //$scope.slots.shift();\r
89             //$scope.slots.push(SchedulerSlots[to]);\r
90             //for (var j = 0; j < $scope.resources.length; j++) {\r
91             //    $scope.resources[j].leases.shift();\r
92             //    $scope.resources[j].leases.push(SchedulerData[j].leases[to]);\r
93             //}\r
94             //try {\r
95             //    $scope.$digest();\r
96             //    //$scope.$apply();\r
97             //} catch (err) {\r
98             //    $scope.initSlots(from, to);\r
99             //}\r
100             $scope.initSlots(from, to);\r
101         };\r
102 \r
103         $scope.moveBackSlot = function(from, to) {\r
104             $scope.$apply(function() {\r
105                 //try {\r
106                 //    $scope.slots.pop();\r
107                 //    $scope.slots.unshift(SchedulerSlots[from]);\r
108                 //    for (var j = 0; j < $scope.resources.length; j++) {\r
109                 //        $scope.resources[j].leases.pop();\r
110                 //        $scope.resources[j].leases.unshift(SchedulerData[j].leases[from]);\r
111                 //    }\r
112                 //} catch (err) {\r
113                 //    alert("error");\r
114                 //}\r
115 \r
116                 $scope.initSlots(from, to);\r
117             });\r
118         };\r
119 \r
120         $scope.getTimes = function (n) {\r
121             return new Array(n);\r
122         };\r
123 \r
124         // Return this object reference.\r
125         return (this);\r
126 \r
127     }\r
128 \r
129 \r
130     // Define the Controller as the constructor function.\r
131     app.controller("SchedulerCtrl", Controller);\r
132 \r
133 \r
134 })(angular, myApp);