rest update
[unfold.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             angular.element(document.getElementById('SchedulerCtrl')).scope().initSlots(_schedulerCurrentCellPosition, _schedulerCurrentCellPosition + SchedulerTotalVisibleCells);\r
10         }\r
11             \r
12     };\r
13 });\r
14 \r
15 // Create a private execution space for our controller. When\r
16 // executing this function expression, we're going to pass in\r
17 // the Angular reference and our application module.\r
18 (function (ng, app) {\r
19 \r
20 \r
21     // Define our Controller constructor.\r
22     function Controller($scope) {\r
23 \r
24         // Store the scope so we can reference it in our\r
25         // class methods\r
26         this.scope = $scope;\r
27 \r
28         // Set up the default scope value.\r
29         this.scope.errorMessage = null;\r
30         this.scope.name = "";\r
31 \r
32         $scope.resources = SchedulerDataViewData;\r
33         $scope.slots = SchedulerSlotsViewData;\r
34         //$scope.msg = "hello";\r
35 \r
36         angular.element(document).ready(function() {\r
37             //console.log('Hello World');\r
38             //alert('Hello World');\r
39             //afterAngularRendered();\r
40         });\r
41 \r
42         $scope.moveFrontSlot = function(from, to) {\r
43             //$scope.slots.shift();\r
44             //$scope.slots.push(SchedulerSlots[to]);\r
45             //for (var j = 0; j < $scope.resources.length; j++) {\r
46             //    $scope.resources[j].leases.shift();\r
47             //    $scope.resources[j].leases.push(SchedulerData[j].leases[to]);\r
48             //}\r
49             //try {\r
50             //    $scope.$digest();\r
51             //    //$scope.$apply();\r
52             //} catch (err) {\r
53             //    $scope.initSlots(from, to);\r
54             //}\r
55             $scope.initSlots(from, to);\r
56         };\r
57 \r
58         $scope.moveBackSlot = function(from, to) {\r
59             $scope.$apply(function() {\r
60                 //try {\r
61                 //    $scope.slots.pop();\r
62                 //    $scope.slots.unshift(SchedulerSlots[from]);\r
63                 //    for (var j = 0; j < $scope.resources.length; j++) {\r
64                 //        $scope.resources[j].leases.pop();\r
65                 //        $scope.resources[j].leases.unshift(SchedulerData[j].leases[from]);\r
66                 //    }\r
67                 //} catch (err) {\r
68                 //    alert("error");\r
69                 //}\r
70 \r
71                 $scope.initSlots(from, to);\r
72             });\r
73         };\r
74 \r
75         $scope.initSlots = function(from, to) {\r
76             //init\r
77             $scope.slots = [];\r
78             for (var k = 0; k < SchedulerData.length; k++) {\r
79                 if ($scope.resources.length < SchedulerData.length)\r
80                     $scope.resources.push(jQuery.extend(true, {}, SchedulerData[k]));\r
81                 $scope.resources[k].leases = [];\r
82             }\r
83             //set\r
84             for (var i = from; i < to; i++) {\r
85                 $scope.slots.push(SchedulerSlots[i]);\r
86                 for (var j = 0; j < $scope.resources.length; j++) {\r
87                     $scope.resources[j].leases.push(SchedulerData[j].leases[i]);\r
88                 }\r
89             }\r
90             //apply\r
91             $scope.$apply();\r
92         };\r
93 \r
94 \r
95         // Return this object reference.\r
96         return (this);\r
97 \r
98     }\r
99 \r
100 \r
101     // Define the Controller as the constructor function.\r
102     app.controller("SchedulerCtrl", Controller);\r
103 \r
104 \r
105 })(angular, myApp);