Chrysostomos for scheduler
[unfold.git] / plugins / scheduler2 / static / js / scheduler2.js
index 8f786de..27300e3 100755 (executable)
@@ -53,277 +53,347 @@ var schedulerDebug = true;
 //tmp to delete\r
 var tmpSchedulerLeases = [];\r
 \r
-(function ($) {\r
-    scheduler2 = Plugin.extend({\r
+(function($) {\r
+        scheduler2 = Plugin.extend({\r
 \r
-        /** XXX to check\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
-            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
-            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
+            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
-                    schedulerCtrlPressed = 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
-            $("#" + 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
-
-            this.listen_query(options.query_uuid);
-            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_lease_uuid, 'lease');\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
-                SchedulerData.push({\r
-                    id: data.urn,\r
-                    index: SchedulerData.length,\r
-                    name: data.hrn,\r
-                    granularity: data.granularity,\r
-                    leases: schedulerGetLeases(60 / schedulerSlotsPerHour, data.granularity),\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
+                //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
-            //alert(data.toSource());\r
+            },\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_lease_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
+            on_filter_removed: function(filter) {\r
+                // Remove corresponding filters\r
+                this.filters = $.grep(this.filters, function(x) {\r
+                    return x == filter;\r
                 });\r
-            }\r
-            //console.log(data.toSource()); console.log('lease_new_record');\r
-        },\r
-        on_lease_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
-        },
-
-        on_filter_removed: function (filter) {
-            // Remove corresponding filters
-            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
-        },
-
-        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
-        // ... be sure to list all events here\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
-        /* RECORD HANDLERS */\r
-        on_all_new_record: function (record) {\r
-            //alert('on_all_new_record');\r
-        },\r
+            on_all_leases_filter_added: function(filter) {\r
+                console.log("Filter on Leases added !");\r
+            },\r
 \r
-        debug : function (logTxt) {\r
-            if (typeof window.console != 'undefined') {\r
-                console.debug(logTxt);\r
-            }\r
-        },\r
+            // ... be sure to list all events here\r
 \r
-        /* INTERNAL FUNCTIONS */\r
-        _initScheduler: function () {\r
-            if (_resourcesDone && _leasesDone)\r
-            {\r
-                SchedulerDataViewData = SchedulerData;\r
-                /* GUI setup and event binding */\r
-                this._FixLeases();\r
-                this._initUI();\r
-            }\r
-        },\r
+            /* RECORD HANDLERS */\r
+            on_all_new_record: function(record) {\r
+                //alert('on_all_new_record');\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
-                } else {\r
-                    alert("Please select a date, so the scheduler can reserve leases.");\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
-            }).datepicker('setDate', SchedulerDateSelected);\r
-            /*.click(function () {\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
+                        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
+                //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
+                });\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
-                    else if (_schedulerCurrentCellPosition < ui.value) {\r
-                        angScope.moveFrontSlot(ui.value, ui.value + SchedulerTotalVisibleCells);\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
-                    _schedulerCurrentCellPosition = ui.value;\r
-                }\r
-            });\r
-            //End init Slider\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
+                //\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
@@ -427,7 +497,7 @@ var tmpSchedulerLeases = [];
             if (schedulerDebug &&  colValue == 'omf') colValue = 'nitos';\r
 \r
             if (op == '=' || op == '==') {\r
-                if (colValue != value || colValue == null || colValue == "" || colValue == "n/a")
+                if (colValue != value || colValue == null || colValue == "" || colValue == "n/a")\r
                     ret = false;\r
             } else if (op == 'included') {\r
                 $.each(value, function (i, x) {\r
@@ -439,7 +509,7 @@ var tmpSchedulerLeases = [];
                     }\r
                 });\r
             } else if (op == '!=') {\r
-                if (colValue == value || colValue == null || colValue == "" || colValue == "n/a")
+                if (colValue == value || colValue == null || colValue == "" || colValue == "n/a")\r
                     ret = false;\r
             }\r
 \r