Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[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 \r
34         $scope.resources = SchedulerDataViewData;\r
35         $scope.slots = SchedulerSlotsViewData;\r
36         //$scope.msg = "hello";\r
37 \r
38         angular.element(document).ready(function() {\r
39             //console.log('Hello World');\r
40             //alert('Hello World');\r
41             //afterAngularRendered();\r
42         });\r
43 \r
44         $scope.moveFrontSlot = function(from, to) {\r
45             //$scope.slots.shift();\r
46             //$scope.slots.push(SchedulerSlots[to]);\r
47             //for (var j = 0; j < $scope.resources.length; j++) {\r
48             //    $scope.resources[j].leases.shift();\r
49             //    $scope.resources[j].leases.push(SchedulerData[j].leases[to]);\r
50             //}\r
51             //try {\r
52             //    $scope.$digest();\r
53             //    //$scope.$apply();\r
54             //} catch (err) {\r
55             //    $scope.initSlots(from, to);\r
56             //}\r
57             $scope.initSlots(from, to);\r
58         };\r
59 \r
60         $scope.moveBackSlot = function(from, to) {\r
61             $scope.$apply(function() {\r
62                 //try {\r
63                 //    $scope.slots.pop();\r
64                 //    $scope.slots.unshift(SchedulerSlots[from]);\r
65                 //    for (var j = 0; j < $scope.resources.length; j++) {\r
66                 //        $scope.resources[j].leases.pop();\r
67                 //        $scope.resources[j].leases.unshift(SchedulerData[j].leases[from]);\r
68                 //    }\r
69                 //} catch (err) {\r
70                 //    alert("error");\r
71                 //}\r
72 \r
73                 $scope.initSlots(from, to);\r
74             });\r
75         };\r
76 \r
77         $scope.SetSchedulerResources = function (start, to, filter) {\r
78             for (var k = start; k < to; 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             $scope.initSlots(0, SchedulerTotalVisibleCells);\r
84         };\r
85 \r
86         $scope.initSlots = function(from, to) {\r
87             //init\r
88             $scope.slots = [];\r
89             //set\r
90             for (var i = from; i < to; i++) {\r
91                 $scope.slots.push(SchedulerSlots[i]);\r
92                 for (var j = 0; j < $scope.resources.length; j++) {\r
93                     $scope.resources[j].leases.push(SchedulerData[j].leases[i]);\r
94                 }\r
95             }\r
96             //apply\r
97             $scope.$apply();\r
98         };\r
99 \r
100 \r
101         // Return this object reference.\r
102         return (this);\r
103 \r
104     }\r
105 \r
106 \r
107     // Define the Controller as the constructor function.\r
108     app.controller("SchedulerCtrl", Controller);\r
109 \r
110 \r
111 })(angular, myApp);