Chrysostomos for scheduler
[unfold.git] / plugins / scheduler2 / static / js / scheduler2.js
index dd0c8f8..10eaa9a 100755 (executable)
 */\r
 \r
 /* some params */\r
-var init_start_visible_index = 10;\r
-var init_end_visible_index = 21;\r
-var rsvrTblNm = "scheduler-reservation-table";\r
-var SchedulerResources = [];\r
-var schdlr_totalColums = 0;\r
-var SetPerFun = null;\r
-var Sched2 = null;\r
-var Debug = true;\r
-var schdlr_PartsInOneHour = 6;\r
-\r
-(function ($) {\r
-    var Scheduler2 = Plugin.extend({\r
-\r
-        /** XXX to check\r
+var scheduler2;\r
+var scheduler2Instance;\r
+//is ctrl keyboard button pressed\r
+var schedulerCtrlPressed = false;\r
+//table Id\r
+var schedulerTblId = "scheduler-reservation-table";\r
+var schedulerTblFirstColWidth = 150;\r
+//Some Data\r
+var schedulerSlotsPerHour = 6;\r
+var schedulerMaxRows = 12;\r
+var SchedulerData = [];\r
+var SchedulerSlots = [];\r
+var SchedulerDateSelected = new Date();\r
+var SchedulerDataViewData = [];\r
+var SchedulerSlotsViewData = [];\r
+var SchedulerTotalCells;\r
+var SchedulerTotalVisibleCells;\r
+//Help Variables\r
+var _schedulerCurrentCellPosition = 0;\r
+var _leasesDone = false;\r
+var _resourcesDone = false;\r
+//Enable Debug\r
+var schedulerDebug = true;\r
+//tmp to delete\r
+var tmpSchedulerLeases = [];\r
+\r
+(function($) {\r
+        scheduler2 = Plugin.extend({\r
+\r
+            /** XXX to check\r
          * @brief Plugin constructor\r
          * @param options : an associative array of setting values\r
          * @param element : \r
          * @return : a jQuery collection of objects on which the plugin is\r
          *     applied, which allows to maintain chainability of calls\r
          */\r
-        init: function (options, element) {\r
-            // Call the parent constructor, see FAQ when forgotten\r
-            this._super(options, element);\r
-\r
-            schdlr_totalColums = $("#scheduler-reservation-table th").length;\r
-\r
-            //selection from table \r
-            $(window).keydown(function (evt) {\r
-                if (evt.which == 17) { // ctrl\r
-                    ctrlPressed = true;\r
+            init: function(options, element) {\r
+                this.classname = "scheduler2";\r
+                // Call the parent constructor, see FAQ when forgotten\r
+                this._super(options, element);\r
+                scheduler2Instance = this;\r
+                // We need to remember the active filter for datatables filtering\r
+                this.filters = Array();\r
+\r
+\r
+                SchedulerSlots = schedulerGetSlots(60 / schedulerSlotsPerHour);\r
+                //selection from table \r
+                $(window).keydown(function(evt) {\r
+                    if (evt.which == 17) { // ctrl\r
+                        schedulerCtrlPressed = true;\r
+                    }\r
+                }).keyup(function(evt) {\r
+                    if (evt.which == 17) { // ctrl\r
+                        schedulerCtrlPressed = false;\r
+                    }\r
+                });\r
+                $("#" + schedulerTblId).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove);\r
+\r
+                // Explain this will allow query events to be handled\r
+                // What happens when we don't define some events ?\r
+                // Some can be less efficient\r
+\r
+                if (schedulerDebug) console.time("Listening_to_queries");\r
+                /* Listening to queries */\r
+\r
+                this.listen_query(options.query_uuid);\r
+                //this.listen_query(options.query_all_uuid, 'all');\r
+                this.listen_query(options.query_all_resources_uuid, 'all_resources');\r
+                this.listen_query(options.query_lease_uuid, 'lease');\r
+                this.listen_query(options.query_all_leases_uuid, 'all_leases');\r
+                if (schedulerDebug) console.timeEnd("Listening_to_queries");\r
+\r
+            },\r
+\r
+            /* Handlers */\r
+\r
+            /* all_ev QUERY HANDLERS Start */\r
+            on_all_ev_clear_records: function(data) {\r
+                //alert('all_ev clear_records');\r
+            },\r
+            on_all_ev_query_in_progress: function(data) {\r
+                // alert('all_ev query_in_progress');\r
+            },\r
+            on_all_ev_new_record: function(data) {\r
+                //alert('all_ev new_record');\r
+            },\r
+            on_all_ev_query_done: function(data) {\r
+                //alert('all_ev query_done');\r
+            },\r
+            //another plugin has modified something, that requires you to update your display. \r
+            on_all_ev_field_state_changed: function(data) {\r
+                //alert('all_ev query_done');\r
+            },\r
+            /* all_ev QUERY HANDLERS End */\r
+            /* all_resources QUERY HANDLERS Start */\r
+            on_all_resources_clear_records: function(data) {\r
+                //data is empty on load\r
+            },\r
+            on_all_resources_query_in_progress: function(data) {\r
+                //data is empty on load\r
+            },\r
+            on_all_resources_new_record: function(data) {\r
+                //alert(data.toSource());\r
+                if (data.exclusive == true) {\r
+                    var tmpGran = schedulerDebug && data.granularity == null ? 1800 : data.granularity;\r
+                    SchedulerData.push({\r
+                        id: data.urn,\r
+                        index: SchedulerData.length,\r
+                        name: data.hrn,\r
+                        granularity: tmpGran,\r
+                        leases: schedulerGetLeases(60 / schedulerSlotsPerHour, tmpGran),\r
+                        type: data.type,\r
+                        org_resource: data\r
+                    });\r
+                    /*if (schedulerDebug && SchedulerData[SchedulerData.length - 1].org_resource.network_hrn == 'omf') {\r
+                        SchedulerData[SchedulerData.length - 1].granularity = 1800;\r
+                    }*/\r
                 }\r
-            }).keyup(function (evt) {\r
-                if (evt.which == 17) { // ctrl\r
-                    ctrlPressed = false;\r
+                //alert(data.toSource());\r
+\r
+            },\r
+            on_all_resources_query_done: function(data) {\r
+                _resourcesDone = true;\r
+                this._initScheduler();\r
+            },\r
+            //another plugin has modified something, that requires you to update your display. \r
+            on_all_resources_field_state_changed: function(data) {\r
+                //alert('all_resources query_done');\r
+            },\r
+            /* all_resources QUERY HANDLERS End */\r
+            /* lease QUERY HANDLERS Start */\r
+            on_lease_clear_records: function(data) { console.log('clear_records'); },\r
+            on_lease_query_in_progress: function(data) { console.log('lease_query_in_progress'); },\r
+            on_all_leases_new_record: function(data) {\r
+                if (data.resource.indexOf("nitos") > -1) {\r
+                    tmpSchedulerLeases.push({\r
+                        id: schedulerGetSlotId(data.start_time, data.duration, data.granularity),\r
+                        end_id: schedulerGetSlotId(data.end_time, data.duration, data.granularity),\r
+                        slice: data.slice,\r
+                        status: 'reserved',\r
+                        resource: data.resource,\r
+                        network: data.network,\r
+                        start_time: new Date(data.start_time * 1000),\r
+                        start_time_unixtimestamp: data.start_time,\r
+                        end_time: new Date(data.end_time * 1000),\r
+                        end_time_unixtimestamp: data.end_time,\r
+                        lease_type: data.lease_type,\r
+                        granularity: data.granularity,\r
+                        duration: data.duration\r
+                    });\r
                 }\r
-            });\r
-            $("#" + rsvrTblNm).on('mousedown', 'td', rangeMouseDown).on('mouseup', 'td', rangeMouseUp).on('mousemove', 'td', rangeMouseMove);\r
-\r
-            // Explain this will allow query events to be handled\r
-            // What happens when we don't define some events ?\r
-            // Some can be less efficient\r
-\r
-            if (Debug) console.time("Listening_to_queries");\r
-            /* Listening to queries */\r
-            this.listen_query(options.query_uuid, 'all_ev');\r
-            this.listen_query(options.query_all_resources_uuid, 'all_resources');\r
-            this.listen_query(options.query_lease_uuid, 'lease');\r
-            //this.listen_query(options.query_lease_uuid, 'lease');\r
-            if (Debug) console.timeEnd("Listening_to_queries");\r
-\r
-        },\r
-\r
-        /* PLUGIN EVENTS */\r
-        // on_show like in querytable\r
-\r
-\r
-        /* GUI EVENTS */\r
-\r
-        // a function to bind events here: click change\r
-        // how to raise manifold events\r
+                //console.log(data.toSource()); console.log('lease_new_record');\r
+            },\r
+            on_all_leases_query_done: function(data) {\r
+                _leasesDone = true;\r
+                this._initScheduler();\r
+                // console.log('lease_query_done');\r
+            },\r
+            //another plugin has modified something, that requires you to update your display. \r
+            on_lease_field_state_changed: function(data) { console.log('lease_field_state_changed'); },\r
+            /* lease QUERY HANDLERS End */\r
+\r
+\r
+            // no prefix\r
+            on_filter_added: function(filter) {\r
+                this.filters.push(filter);\r
+                this._SetFiletredResources(this.filters);\r
+                //angular and UI\r
+                var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
+                if (SchedulerDataViewData.length == 0) {\r
+                    $("#plugin-scheduler").hide();\r
+                    $("#plugin-scheduler-empty").show();\r
+                    tmpScope.clearStuff();\r
+                } else {\r
+                    $("#plugin-scheduler-empty").hide();\r
+                    $("#plugin-scheduler").show();\r
+                    tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length);\r
+                }\r
+            },\r
 \r
+            on_filter_removed: function(filter) {\r
+                // Remove corresponding filters\r
+                this.filters = $.grep(this.filters, function(x) {\r
+                    return x == filter;\r
+                });\r
+                this._SetFiletredResources(this.filters);\r
+                //angular and UI\r
+                var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
+                if (SchedulerDataViewData.length == 0) {\r
+                    $("#plugin-scheduler").hide();\r
+                    $("#plugin-scheduler-empty").show();\r
+                    tmpScope.clearStuff();\r
+                } else {\r
+                    $("#plugin-scheduler-empty").hide();\r
+                    $("#plugin-scheduler").show();\r
+                    tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length);\r
+                }\r
+            },\r
+\r
+            on_filter_clear: function() {\r
+                this.filters = [];\r
+                this._SetFiletredResources(this.filters);\r
+                //angular and UI\r
+                var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
+                if (SchedulerDataViewData.length == 0) {\r
+                    $("#plugin-scheduler").hide();\r
+                    $("#plugin-scheduler-empty").show();\r
+                    tmpScope.clearStuff();\r
+                } else {\r
+                    $("#plugin-scheduler-empty").hide();\r
+                    $("#plugin-scheduler").show();\r
+                    tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length);\r
+                }\r
+            },\r
 \r
-        /* GUI MANIPULATION */\r
+            on_all_leases_filter_added: function(filter) {\r
+                console.log("Filter on Leases added !");\r
+            },\r
 \r
-        // We advise you to write function to change behaviour of the GUI\r
-        // Will use naming helpers to access content _inside_ the plugin\r
-        // always refer to these functions in the remaining of the code\r
+            // ... be sure to list all events here\r
 \r
-        show_hide_button: function () {\r
-            // this.id, this.el, this.cl, this.elts\r
-            // same output as a jquery selector with some guarantees\r
-        },\r
+            /* RECORD HANDLERS */\r
+            on_all_new_record: function(record) {\r
+                //alert('on_all_new_record');\r
+            },\r
 \r
-        drawResources: function () {\r
-            \r
-            //if (Debug) this.debug('foo');\r
-            if (Debug) console.time("each:SchedulerResources");\r
-\r
-            //scheduler-reservation-table main table columns\r
-            totalColums = $("#scheduler-reservation-table thead tr th").length;\r
-            //var totalCell = [];\r
-            //for (var i = 0; i < totalColums; i++) { totalCell.push("<td></td>"); }\r
-            //var srt_body = [];\r
-            var totalCell = "";\r
-            for (var i = 0; i < totalColums; i++) totalCell +="<td></td>"; \r
-            var srt_body = "";\r
-\r
-            $.each(SchedulerResources, function (i, group) {\r
-                //var groupTR = $("#ShedulerNodes tbody").html('<tr><td class="no-image verticalIndex" rowspan="' + group.resources.length + '"><div class="verticalText">' + group.groupName + '</div></td><td id="schdlr_frstTD" class="info fixed"></td></tr>');\r
-                var groupTR = $("#ShedulerNodes tbody").html('<tr><td class="no-image verticalIndex" rowspan="' + 30 + '"><div class="verticalText">' + group.groupName + '</div></td><td id="schdlr_frstTD" class="info fixed"></td></tr>');\r
-                \r
-                $.each(group.resources.slice(0,30), function (i, resource) {\r
-                    if (i == 0) {\r
-                        //$("#ShedulerNodes tbody tr:first").append('<td class="info fixed">' + resource.hostname + '</td>');\r
-                        $(groupTR).find("#schdlr_frstTD").html(resource.hostname);\r
-                        //$(srt_body).html("<tr>" + totalCell + "</tr>");\r
+            debug: function(logTxt) {\r
+                if (typeof window.console != 'undefined') {\r
+                    console.debug(logTxt);\r
+                }\r
+            },\r
+\r
+            /* INTERNAL FUNCTIONS */\r
+            _initScheduler: function() {\r
+                if (_resourcesDone && _leasesDone) {\r
+                    SchedulerDataViewData = SchedulerData;\r
+                    /* GUI setup and event binding */\r
+                    this._FixLeases();\r
+                    this._initUI();\r
+                }\r
+            },\r
+\r
+            _initUI: function() {\r
+                //alert(1);\r
+                if (schedulerDebug) console.time("_initUI");\r
+                //init DatePicker Start\r
+                $("#DateToRes").datepicker({\r
+                    dateFormat: "yy-mm-dd",\r
+                    minDate: 0,\r
+                    numberOfMonths: 3\r
+                }).change(function() {\r
+                    //Scheduler2.loadWithDate();\r
+                    SchedulerDateSelected = $("#DateToRes").datepicker("getDate");\r
+                    if (SchedulerDateSelected != null && SchedulerDateSelected != '') {\r
+                        for (var i = 0; i < SchedulerData.length; i++) {\r
+                            SchedulerData[i].leases = schedulerGetLeases(60 / schedulerSlotsPerHour, SchedulerData[i].granularity);\r
+                        }\r
+                        scheduler2Instance._FixLeases();\r
+                        $('#tblSlider').slider('value', 0);\r
+                        var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
+                        tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length);\r
+\r
+                        //console.log(SchedulerDateSelected);\r
+                        //console.log(SchedulerDateSelected.getTime()/1000);\r
+                        var tomorrow = new Date(SchedulerDateSelected);\r
+                        tomorrow.setDate(SchedulerDateSelected.getDate()+1);\r
+                        //console.log(tomorrow);\r
+                        //console.log(tomorrow.getTime()/1000);\r
+                        \r
+                        // Remove previous date interval\r
+                        manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_REMOVED, ['start_time', '>']);\r
+                        manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_REMOVED, ['start_time', '<']);\r
+\r
+                        // Add new date interval\r
+                        manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_ADDED, ['start_time', '>', SchedulerDateSelected.getTime()/1000]);\r
+                        manifold.raise_event(scheduler2Instance.options.query_all_leases_uuid, FILTER_ADDED, ['start_time', '<', tomorrow.getTime()/1000]);\r
                     } else {\r
-                        $(groupTR).find("tr:last").after('<tr><td class="info fixed">' + resource.hostname + '</td></tr>');\r
-                        //$(srt_body).find("tr:last").after("<tr>" + totalCell + "</tr>");\r
+                        alert("Please select a date, so the scheduler can reserve leases.");\r
+                    }\r
+                }).datepicker('setDate', SchedulerDateSelected);\r
+                /*.click(function () {\r
+                $("#ui-datepicker-div").css("z-index", 5);\r
+            })*/\r
+                //End init DatePicker\r
+\r
+                //init Table\r
+                this._FixTable();\r
+                //End init Table\r
+\r
+                //init Slider\r
+                $('#tblSlider').slider({\r
+                    min: 0,\r
+                    max: SchedulerTotalCells - SchedulerTotalVisibleCells,\r
+                    value: 0,\r
+                    slide: function(event, ui) {\r
+                        //$("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);\r
+                        //console.log(ui.value);\r
+                        var angScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
+                        if (_schedulerCurrentCellPosition > ui.value) {\r
+                            angScope.moveBackSlot(ui.value, ui.value + SchedulerTotalVisibleCells);\r
+                        } else if (_schedulerCurrentCellPosition < ui.value) {\r
+                            angScope.moveFrontSlot(ui.value, ui.value + SchedulerTotalVisibleCells);\r
+                        }\r
+                        _schedulerCurrentCellPosition = ui.value;\r
                     }\r
-                    srt_body += "<tr>" + totalCell + "</tr>";\r
-                    //srt_body.push('<tr>'); srt_body = srt_body.concat(totalCell.concat()); srt_body.push('/<tr>');\r
                 });\r
-            });\r
-\r
-            //$("#scheduler-reservation-table tbody").html(srt_body.join(""));\r
-            $("#scheduler-reservation-table tbody").html(srt_body);\r
-\r
-            if (Debug) console.timeEnd("each:SchedulerResources");\r
-            \r
-\r
-            $("#" + rsvrTblNm + " tbody tr").each(function (index) { $(this).attr("data-trindex", index); });\r
-\r
-        },\r
-\r
-        /* TEMPLATES */\r
-\r
-        // see in the html template\r
-        // How to load a template, use of mustache\r
-\r
-        /* QUERY HANDLERS */\r
-        loadWithDate: function () {\r
-            // only convention, not strictly enforced at the moment\r
+                //End init Slider\r
+\r
+\r
+                //btn Submit leases\r
+                $('#btnSchedulerSubmit').click(function () {\r
+                    console.log("click btnSchedulerSubmit");\r
+                    var leasesForCommit = new Array();\r
+                    var tmpDateTime = SchedulerDateSelected;\r
+                    console.log(SchedulerData);\r
+                    for (var i = 0; i < SchedulerData.length; i++)\r
+                    {\r
+                        var tpmR = SchedulerData[i];\r
+                        //for capturing start and end of the lease\r
+                        var newLeaseStarted = false;\r
+                        for (var j = 0; j < tpmR.leases.length; j++) {\r
+                            var tpmL = tpmR.leases[j];\r
+                            if (newLeaseStarted == false && tpmL.status == 'selected') {\r
+                                //get date of the slot\r
+                                tmpDateTime = schedulerGetDateTimeFromSlotId(tpmL.id, tmpDateTime);\r
+                                var unixStartTime = tmpDateTime.getTime() / 1000;\r
+                                //add lease object\r
+                                leasesForCommit.push({\r
+                                    resource: tpmR.id,\r
+                                    //granularity: tpmR.granularity,\r
+                                    //lease_type: null,\r
+                                    //slice: null,\r
+                                    start_time: unixStartTime,\r
+                                    end_time: null,\r
+                                    //duration: null\r
+                                });\r
+                                console.log(tpmR.id);\r
+                                newLeaseStarted = true;\r
+                            } else if (newLeaseStarted == true && tpmL.status != 'selected') {\r
+                                //get date of the slot\r
+                                tmpDateTime = schedulerGetDateTimeFromSlotId(tpmL.id, tmpDateTime);\r
+                                var unixEndTime = tmpDateTime.getTime() / 1000;\r
+                                //upate end_time\r
+                                var tmpCL = leasesForCommit[leasesForCommit.length - 1];\r
+                                tmpCL.end_time = unixEndTime;\r
+                                //tmpCL.duration = schedulerFindDuration(tmpCL.start_time, tmpCL.end_time, tmpCL.granularity);\r
+                                newLeaseStarted = false;\r
+                            }\r
+                        }\r
+                    }\r
+                    console.log(leasesForCommit);\r
+                    for (var i = 0; i < leasesForCommit.length; i++) {\r
+                        manifold.raise_event(scheduler2Instance.options.query_lease_uuid, SET_ADD, leasesForCommit[i]);\r
+                    }\r
+                });\r
+                //\r
+\r
+\r
+                //End btn Submit leases\r
+\r
+                //other stuff\r
+                $("#plugin-scheduler-loader").hide();\r
+                $("#plugin-scheduler").show();\r
+                //fixOddEvenClasses();\r
+                //$("#" + schedulerTblId + " td:not([class])").addClass("free");\r
+                if (schedulerDebug) console.timeEnd("_initUI");\r
+            },\r
+\r
+        _FixLeases  : function () {\r
+            for (var i = 0; i < tmpSchedulerLeases.length; i++) {\r
+                var tmpLea = tmpSchedulerLeases[i];\r
+                if ((schedulerCompareOnDay(tmpLea.start_time, SchedulerDateSelected) == 0) ||\r
+                                (tmpLea.start_time <= SchedulerDateSelected && SchedulerDateSelected <= tmpLea.end_time) || \r
+                                (schedulerCompareOnDay(tmpLea.end_time, SchedulerDateSelected) == 0)) {\r
+                    var tmpRes = schedulerFindResourceById(SchedulerData, tmpLea.resource);\r
+                    if (tmpRes != null) {\r
+                        //Replace Lease with current lease from the manifold\r
+                        var orgLease = tmpRes.leases[tmpLea.id];\r
+                        tmpLea['groupid'] = orgLease.groupid;\r
+                        tmpLea['groupIndex'] = orgLease.groupIndex;\r
+                        if (orgLease.groupIndex != 0) {\r
+                            if (!window.console) {\r
+                                console.warn('there is an error with the leases of the resource :' + tmpRes.name + '\n The lease start in the middle of the granularity!' + '\n The Scheduler plugin might not work!');\r
+                            }\r
+                        }\r
+                        tmpRes.leases[tmpLea.id] = tmpLea;\r
+                        this._ExtractLeaseSlots(tmpRes, tmpRes.leases[tmpLea.id]);\r
+                    }\r
+                }\r
+            }\r
         },\r
-        // How to make sure the plugin is not desynchronized\r
-        // He should manifest its interest in filters, fields or records\r
-        // functions triggered only if the proper listen is done\r
 \r
-        /* all_ev QUERY HANDLERS Start */\r
-        on_all_ev_clear_records: function (data) {\r
-            //alert('all_ev clear_records');\r
-        },\r
-        on_all_ev_query_in_progress: function (data) {\r
-           // alert('all_ev query_in_progress');\r
-        },\r
-        on_all_ev_new_record: function (data) {\r
-            //alert('all_ev new_record');\r
-        },\r
-        on_all_ev_query_done: function (data) {\r
-            //alert('all_ev query_done');\r
-        },\r
-        //another plugin has modified something, that requires you to update your display. \r
-        on_all_ev_field_state_changed: function (data) {\r
-            //alert('all_ev query_done');\r
-        },\r
-        /* all_ev QUERY HANDLERS End */\r
-        /* all_resources QUERY HANDLERS Start */\r
-        on_all_resources_clear_records: function (data) {\r
-            //data is empty on load\r
-        },\r
-        on_all_resources_query_in_progress: function (data) {\r
-            //data is empty on load\r
-        },\r
-        on_all_resources_new_record: function (data) {\r
-            var tmpGroup = lookup(SchedulerResources, 'groupName', data.type);\r
-            if (tmpGroup == null) {\r
-                tmpGroup = { groupName: data.type, resources: [] };\r
-                SchedulerResources.push(tmpGroup);\r
-                //if (data.type != "node")  alert('not all node');\r
+        _ExtractLeaseSlots: function (tmpRes, lease) {\r
+            var tmpStartDate = lease.start_time;\r
+            var tmpEndDate = lease.end_time;\r
+            var startLoop; var toLoop;\r
+            if (schedulerCompareOnDay(lease.start_time,lease.end_time) == 0) {\r
+                //in the same date\r
+                startLoop = lease.id;\r
+                toLoop = lease.end_id;\r
+            } else if (lease.start_time < SchedulerDateSelected && SchedulerDateSelected < lease.end_time) {\r
+                //one hole day (more than 3days)\r
+                startLoop = 0;\r
+                toLoop = tmpRes.leases.length;\r
+            } else if (schedulerCompareOnDay(lease.start_time, SchedulerDateSelected) == 0) {\r
+                //the same day and extends\r
+                startLoop = lease.id;\r
+                toLoop = tmpRes.leases.length;\r
+            } else if (schedulerCompareOnDay(lease.end_time, SchedulerDateSelected) == 0) {\r
+                //extends to the last say\r
+                startLoop = 0;\r
+                toLoop = lease.end_id;\r
             }\r
-            tmpGroup.resources.push(data);\r
-            //alert('new_record');\r
-        },\r
-        on_all_resources_query_done: function (data) {\r
-            this.drawResources();\r
-            //data is empty on load\r
-            /* GUI setup and event binding */\r
-            this._initUI();\r
-            this._SetPeriodInPage(init_start_visible_index, init_end_visible_index);\r
-            this.loadWithDate();\r
-        },\r
-        //another plugin has modified something, that requires you to update your display. \r
-        on_all_resources_field_state_changed: function (data) {\r
-            //alert('all_resources query_done');\r
+            //var minutGran = tmpRes.granularity * 60;\r
+            for (var li = lease.id; li < toLoop; li++) {\r
+                tmpRes.leases[li].status = 'reserved';\r
+            }\r
+            \r
+            //reserved\r
+            //tmpRes.leases[tmpLea.id\r
         },\r
-        /* all_resources QUERY HANDLERS End */\r
-        /* lease QUERY HANDLERS Start */\r
-        on_lease_clear_records: function (data) { alert('clear_records'); },\r
-        on_lease_query_in_progress: function (data) { alert('query_in_progress'); },\r
-        on_lease_new_record: function (data) { alert('new_record'); },\r
-        on_lease_query_done: function (data) { alert('query_done'); },\r
-        //another plugin has modified something, that requires you to update your display. \r
-        on_lease_field_state_changed: function (data) { alert('query_done'); },\r
-        /* lease QUERY HANDLERS End */\r
-\r
 \r
-        // no prefix\r
-\r
-        on_filter_added: function (filter) {\r
+        _FixTable: function () {\r
+            var colWidth = 50;\r
+            SchedulerTotalCells = SchedulerSlots.length;\r
+            $('#' + schedulerTblId + ' thead tr th:eq(0)').css("width", schedulerTblFirstColWidth); //.css("display", "block");\r
+            //this get width might need fix depending on the template \r
+            var tblwidth = $('#scheduler-tab').parent().outerWidth();\r
+            SchedulerTotalVisibleCells = parseInt((tblwidth - schedulerTblFirstColWidth) / colWidth);\r
+\r
+            //if (SchedulerData.length == 0) {\r
+            //    //puth some test data\r
+            //    SchedulerData.push({ name: 'xyz+aaa', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+aaa', type: 'node' });\r
+            //    SchedulerData.push({ name: 'xyz+bbb', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+bbb', type: 'node' });\r
+            //    SchedulerData.push({ name: 'xyz+ccc', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'xyz+ccc', type: 'node' });\r
+            //    SchedulerData.push({ name: 'nitos1', leases: schedulerGetLeases(60 / schedulerSlotsPerHour), urn: 'nitos1', type: 'node' });\r
+            //}\r
+            var tmpScope = angular.element(document.getElementById('SchedulerCtrl')).scope();\r
+            tmpScope.initSchedulerResources(schedulerMaxRows < SchedulerDataViewData.length ? schedulerMaxRows : SchedulerDataViewData.length);\r
 \r
         },\r
 \r
-        // ... be sure to list all events here\r
-\r
-        /* RECORD HANDLERS */\r
-        on_all_new_record: function (record) {\r
-            //\r
-            alert('on_all_new_record');\r
+        _SetFiletredResources : function (filters) {\r
+            if (filters.length > 0) {\r
+                SchedulerDataViewData = new Array();\r
+                var tmpAddIt = true;\r
+                for (var i = 0; i < SchedulerData.length; i++) {\r
+                    loopfilters:\r
+                    for (var f = 0; f < filters.length; f++) {\r
+                        tmpAddIt = this._FilterResource(SchedulerData[i], filters[f]);\r
+                        if (tmpAddIt == false) break loopfilters;\r
+                    }\r
+                    if (tmpAddIt) {\r
+                        SchedulerDataViewData.push(SchedulerData[i]);\r
+                    }\r
+                }\r
+            } else {\r
+                SchedulerDataViewData = SchedulerData;\r
+            }\r
         },\r
 \r
-        debug : function (log_txt) {\r
-            if (typeof window.console != 'undefined') {\r
-                console.debug(log_txt);\r
+        _FilterResource: function (resource, filter) {\r
+            var key = filter[0];\r
+            var op = filter[1];\r
+            var value = filter[2];\r
+            var colValue = resource.org_resource[key];\r
+            var ret = true;\r
+            if (schedulerDebug &&  colValue == 'omf') colValue = 'nitos';\r
+\r
+            if (op == '=' || op == '==') {\r
+                if (colValue != value || colValue == null || colValue == "" || colValue == "n/a")\r
+                    ret = false;\r
+            } else if (op == 'included') {\r
+                $.each(value, function (i, x) {\r
+                    if (x == colValue) {\r
+                        ret = true;\r
+                        return false;\r
+                    } else {\r
+                        ret = false;\r
+                    }\r
+                });\r
+            } else if (op == '!=') {\r
+                if (colValue == value || colValue == null || colValue == "" || colValue == "n/a")\r
+                    ret = false;\r
             }\r
-        },\r
 \r
-        /* INTERNAL FUNCTIONS */\r
-        _initUI: function () {\r
-            if (Debug) console.time("_initUI");\r
-            //fix margins in tables\r
-            mtNodesTbl = $("#" + rsvrTblNm + " tr:first").outerHeight() + 6;\r
-            mtSchrollCon = $("#nodes").outerWidth();\r
-            $("#nodes").css("margin-top", mtNodesTbl);\r
-            $("#reservation-table-scroll-container").css("margin-left", mtSchrollCon);\r
-            SetPerFun = this._SetPeriodInPage;\r
-            //slider\r
-            $("#time-range").slider({\r
-                range: true,\r
-                min: 0,\r
-                max: 24,\r
-                step: 0.5,\r
-                values: [init_start_visible_index, init_end_visible_index],\r
-                slide: function (event, ui) {\r
-                    SetPerFun(ui.values[0], ui.values[1]);\r
-                }\r
-            });\r
-            $("#DateToRes").datepicker({\r
-                dateFormat: "yy-mm-dd",\r
-                minDate: 0,\r
-                numberOfMonths: 3\r
-            }).change(function () {\r
-                //Scheduler2.loadWithDate();\r
-            }).click(function () {\r
-                $("#ui-datepicker-div").css("z-index", 5);\r
-            });\r
-            //other stuff\r
-            fixOddEvenClasses();\r
-            $("#" + rsvrTblNm + " td:not([class])").addClass("free");\r
-            if (Debug) console.timeEnd("_initUI");\r
+            return ret;\r
         },\r
-        _SetPeriodInPage: function (start, end) {\r
-            if (Debug) console.time("_SetPeriodInPage");\r
-            ClearTableSelection();\r
-            $("#lbltime").html(GetTimeFromInt(start) + " - " + GetTimeFromInt(end));\r
-            \r
-            var start_visible_index = (start * schdlr_PartsInOneHour) + 1;\r
-            var end_visible_index = (end * schdlr_PartsInOneHour);\r
 \r
-            //hide - show\r
-            for (i = 0; i < start_visible_index; i++) {\r
-                $("#" + rsvrTblNm + " td:nth-child(" + i + "), #" + rsvrTblNm + " th:nth-child(" + i + ")").hide();\r
-            }\r
-            for (i = end_visible_index + 1; i <= schdlr_totalColums; i++) {\r
-                $("#" + rsvrTblNm + " td:nth-child(" + i + "), #" + rsvrTblNm + " th:nth-child(" + i + ")").hide();\r
-            }\r
-            /*$("#" + rsvrTblNm + " td:not([class*='info']), #" + rsvrTblNm + " th:not([class*='fixed'])").hide();*/\r
-            for (i = start_visible_index; i <= end_visible_index; i++) {\r
-                $("#" + rsvrTblNm + " td:nth-child(" + i + "), #" + rsvrTblNm + " th:nth-child(" + i + ")").show();\r
-            }\r
-\r
-            if ($("#" + rsvrTblNm + " th:visible:first").width() > 105) {\r
-                $("#" + rsvrTblNm + " th span").css("display", "inline")\r
-            } else {\r
-                $("#" + rsvrTblNm + " th span").css("display", "block");\r
-            }\r
-            mtNodesTbl = $("#" + rsvrTblNm + " tr:first").outerHeight() + 6;\r
-            $("#nodes").css("margin-top", mtNodesTbl);\r
-            //$("#scroll_container").width($("#Search").width() - $("#nodes").width());\r
-            //$("#nodes th").height($("#tblReservation th:visible:first").height() - 2);\r
-            if (Debug) console.timeEnd("_SetPeriodInPage");\r
+        _SetPeriodInPage: function (start, end) {\r
         }\r
     });\r
 \r
     //Sched2 = new Scheduler2();\r
 \r
     /* Plugin registration */\r
-    $.plugin('Scheduler2', Scheduler2);\r
+    $.plugin('Scheduler2', scheduler2);\r
 \r
     // TODO Here use cases for instanciating plugins in different ways like in the pastie.\r
 \r