3 # Copyright (c) 2013 NITLab, University of Thessaly, CERTH, Greece
\r
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
\r
6 # of this software and associated documentation files (the "Software"), to deal
\r
7 # in the Software without restriction, including without limitation the rights
\r
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
9 # copies of the Software, and to permit persons to whom the Software is
\r
10 # furnished to do so, subject to the following conditions:
\r
12 # The above copyright notice and this permission notice shall be included in
\r
13 # all copies or substantial portions of the Software.
\r
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 # This is a MySlice plugin for the NITOS Scheduler
\r
25 # Nitos Scheduler v1
\r
30 //is ctrl keyboard button pressed
\r
31 var schedulerCtrlPressed = false;
\r
33 var schedulerTblId = "scheduler-reservation-table";
\r
34 var schedulerTblFirstColWidth = 150;
\r
36 var schedulerSlotsPerHour = 6;
\r
37 var schedulerMaxRows = 50;
\r
38 var SchedulerData = [];
\r
39 var SchedulerSlots = [];
\r
40 var SchedulerDataViewData = [];
\r
41 var SchedulerSlotsViewData = [];
\r
42 var SchedulerTotalCells;
\r
43 var SchedulerTotalVisibleCells;
\r
45 var _schedulerCurrentCellPosition = 0;
\r
47 var schedulerDebug = true;
\r
50 var scheduler2 = Plugin.extend({
\r
53 * @brief Plugin constructor
\r
54 * @param options : an associative array of setting values
\r
56 * @return : a jQuery collection of objects on which the plugin is
\r
57 * applied, which allows to maintain chainability of calls
\r
59 init: function (options, element) {
\r
60 this.classname="scheduler2";
\r
61 // Call the parent constructor, see FAQ when forgotten
\r
62 this._super(options, element);
\r
64 SchedulerSlots = schedulerGetSlots(60/schedulerSlotsPerHour);
\r
65 //selection from table
\r
66 $(window).keydown(function (evt) {
\r
67 if (evt.which == 17) { // ctrl
\r
68 schedulerCtrlPressed = true;
\r
70 }).keyup(function (evt) {
\r
71 if (evt.which == 17) { // ctrl
\r
72 schedulerCtrlPressed = false;
\r
75 //$("#" + schedulerTblId).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove);
\r
77 // Explain this will allow query events to be handled
\r
78 // What happens when we don't define some events ?
\r
79 // Some can be less efficient
\r
81 if (schedulerDebug) console.time("Listening_to_queries");
\r
82 /* Listening to queries */
\r
83 this.listen_query(options.query_uuid, 'all_ev');
\r
84 this.listen_query(options.query_all_resources_uuid, 'all_resources');
\r
85 this.listen_query(options.query_lease_uuid, 'lease');
\r
86 //this.listen_query(options.query_lease_uuid, 'lease');
\r
87 if (schedulerDebug) console.timeEnd("Listening_to_queries");
\r
93 /* all_ev QUERY HANDLERS Start */
\r
94 on_all_ev_clear_records: function (data) {
\r
95 //alert('all_ev clear_records');
\r
97 on_all_ev_query_in_progress: function (data) {
\r
98 // alert('all_ev query_in_progress');
\r
100 on_all_ev_new_record: function (data) {
\r
101 //alert('all_ev new_record');
\r
103 on_all_ev_query_done: function (data) {
\r
104 //alert('all_ev query_done');
\r
106 //another plugin has modified something, that requires you to update your display.
\r
107 on_all_ev_field_state_changed: function (data) {
\r
108 //alert('all_ev query_done');
\r
110 /* all_ev QUERY HANDLERS End */
\r
111 /* all_resources QUERY HANDLERS Start */
\r
112 on_all_resources_clear_records: function (data) {
\r
113 //data is empty on load
\r
115 on_all_resources_query_in_progress: function (data) {
\r
116 //data is empty on load
\r
118 on_all_resources_new_record: function (data) {
\r
119 if (SchedulerData.length < schedulerMaxRows)
\r
120 SchedulerData.push({ name: data.hrn, leases: schedulerGetLeases(schedulerSlotsPerHour), urn: data.urn, type: data.type });
\r
121 //alert(data.toSource());
\r
123 on_all_resources_query_done: function (data) {
\r
124 /* GUI setup and event binding */
\r
126 //this.loadWithDate();
\r
128 //another plugin has modified something, that requires you to update your display.
\r
129 on_all_resources_field_state_changed: function (data) {
\r
130 //alert('all_resources query_done');
\r
132 /* all_resources QUERY HANDLERS End */
\r
133 /* lease QUERY HANDLERS Start */
\r
134 on_lease_clear_records: function (data) { console.log('clear_records'); },
\r
135 on_lease_query_in_progress: function (data) { console.log('lease_query_in_progress'); },
\r
136 on_lease_new_record: function (data) { alert(data.toSource()); console.log('lease_new_record'); },
\r
137 on_lease_query_done: function (data) { console.log('lease_query_done'); },
\r
138 //another plugin has modified something, that requires you to update your display.
\r
139 on_lease_field_state_changed: function (data) { console.log('lease_field_state_changed'); },
\r
140 /* lease QUERY HANDLERS End */
\r
145 on_filter_added: function (filter) {
\r
149 // ... be sure to list all events here
\r
151 /* RECORD HANDLERS */
\r
152 on_all_new_record: function (record) {
\r
153 //alert('on_all_new_record');
\r
156 debug : function (logTxt) {
\r
157 if (typeof window.console != 'undefined') {
\r
158 console.debug(logTxt);
\r
162 /* INTERNAL FUNCTIONS */
\r
163 _initUI: function () {
\r
164 if (schedulerDebug) console.time("_initUI");
\r
165 //init DatePicker Start
\r
166 $("#DateToRes").datepicker({
\r
167 dateFormat: "yy-mm-dd",
\r
170 }).change(function () {
\r
171 //Scheduler2.loadWithDate();
\r
172 }).click(function () {
\r
173 $("#ui-datepicker-div").css("z-index", 5);
\r
175 //End init DatePicker
\r
182 $('#tblSlider').slider({
\r
184 max: SchedulerTotalCells - SchedulerTotalVisibleCells - 1,
\r
186 slide: function (event, ui) {
\r
187 //$("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
\r
188 //console.log(ui.value);
\r
189 if (_schedulerCurrentCellPosition > ui.value)
\r
190 angular.element(document.getElementById('SchedulerCtrl')).scope().moveBackSlot(ui.value, ui.value + SchedulerTotalVisibleCells);
\r
191 else if (_schedulerCurrentCellPosition < ui.value)
\r
192 angular.element(document.getElementById('SchedulerCtrl')).scope().moveFrontSlot(ui.value, ui.value + SchedulerTotalVisibleCells);
\r
193 _schedulerCurrentCellPosition = ui.value;
\r
199 //fixOddEvenClasses();
\r
200 //$("#" + schedulerTblId + " td:not([class])").addClass("free");
\r
201 if (schedulerDebug) console.timeEnd("_initUI");
\r
203 _FixTable: function () {
\r
205 SchedulerTotalCells = SchedulerSlots.length;
\r
206 $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", schedulerTblFirstColWidth);
\r
207 //this get width might need fix depending on the template
\r
208 var tblwidth = $('#scheduler-tab').parent().outerWidth();
\r
209 SchedulerTotalVisibleCells = parseInt((tblwidth - schedulerTblFirstColWidth) / colWidth);
\r
211 if (SchedulerData.length == 0) {
\r
212 //puth some test data
\r
213 SchedulerData.push({ name: 'xyz+aaa', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+aaa', type: 'node' });
\r
214 SchedulerData.push({ name: 'xyz+bbb', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+bbb', type: 'node' });
\r
215 SchedulerData.push({ name: 'xyz+ccc', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+ccc', type: 'node' });
\r
216 SchedulerData.push({ name: 'nitos1', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'nitos1', type: 'node' });
\r
218 angular.element(document.getElementById('SchedulerCtrl')).scope().initSlots(0, SchedulerTotalVisibleCells);
\r
220 _SetPeriodInPage: function (start, end) {
\r
224 //Sched2 = new Scheduler2();
\r
226 /* Plugin registration */
\r
227 $.plugin('Scheduler2', scheduler2);
\r
229 // TODO Here use cases for instanciating plugins in different ways like in the pastie.
\r