X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fscheduler2%2Fstatic%2Fjs%2Fscheduler-helpers.js;h=383cf1cf8b42edaf0c3766c34df15f92f5b6aa1c;hb=436b2227713f8cd5e0b7da6e9d1216eb17c2a941;hp=5de21cb91d4a9d11b9324225012efa7008f63281;hpb=0e79f5650ff7bd234d756214d1e3fdbf1302a0eb;p=unfold.git diff --git a/plugins/scheduler2/static/js/scheduler-helpers.js b/plugins/scheduler2/static/js/scheduler-helpers.js index 5de21cb9..383cf1cf 100755 --- a/plugins/scheduler2/static/js/scheduler-helpers.js +++ b/plugins/scheduler2/static/js/scheduler-helpers.js @@ -61,6 +61,7 @@ function schedulerGetSlots(slotSpan) { } function schedulerGetLeases(slotSpan, granularity) { + granularity = granularity / 60; if (slotSpan == 0) slotSpan = 10; var slots = []; var d = new Date(2014, 1, 1, 0, 0, 0, 0); @@ -84,6 +85,7 @@ function schedulerGetLeases(slotSpan, granularity) { // //GetSlotId from time function schedulerGetSlotId(startTime, duration, granularity) { + //granularity in seconds startTime = parseInt(startTime); var d = new Date(startTime * 1000); var timespan = 60 / schedulerSlotsPerHour; @@ -92,15 +94,69 @@ function schedulerGetSlotId(startTime, duration, granularity) { slotid += d.getMinutes() / timespan; return slotid; } +// +//GetSlotId from time +function schedulerGetDateTimeFromSlotId(slotId, tmpDateTime) { + + var timespan = 60 / schedulerSlotsPerHour; + var totalMinutes = slotId * timespan; + var totalHours = totalMinutes / 60; + if (totalHours >= 1) { + totalHours = Math.floor(totalHours); + totalMinutes = totalMinutes - totalHours * 60; + } else { + totalHours = 0; + } + tmpDateTime.setHours(totalHours, totalMinutes, 0, 0); + + return tmpDateTime; +} +// +//GetSlotId from time +function schedulerFindDuration(startTime, endTime, granularity) { + var duration = 0; + var fd = new Date(startTime * 1000); + var td = new Date(endTime * 1000); + while (fd < td) { + duration++; + fd.setMinutes(fd.getMinutes() + granularity); + } + return duration; +} +// +// Set Select - Free Slots *******Start function schedulerSelectSlot(slotId, rowIndex, resourceIndex) { - SchedulerDataViewData[rowIndex].leases[slotId].status = 'selected'; - SchedulerData[resourceIndex].leases[slotId].status = 'selected'; + console.log('timeslot selected'); + _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, 'selected'); } function schedulerFreeSlot(slotId, rowIndex, resourceIndex) { - SchedulerDataViewData[rowIndex].leases[slotId].status = 'free'; - SchedulerData[resourceIndex].leases[slotId].status = 'free'; + _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, 'free'); +} + +function _schedulerSetStatusSlot(slotId, rowIndex, resourceIndex, classText) { + var tmpVS = SchedulerDataViewData[rowIndex].leases[slotId]; // for the display + var tmpS = SchedulerData[resourceIndex].leases[slotId]; // for the data + console.log(SchedulerData[resourceIndex].id); + tmpVS.status = classText; + tmpS.status = classText; + //select other from the group in the same granularity + var slotSpan = 60 / schedulerSlotsPerHour; + var maxg = (SchedulerData[resourceIndex].granularity / 60) / slotSpan; + + var startSlotId = tmpVS.groupIndex == 0 ? 0 : slotId - tmpVS.groupIndex; + for (var s = 0; s < maxg; s++) { + if (tmpVS.groupIndex != s) { + SchedulerDataViewData[rowIndex].leases[startSlotId].status = classText; + SchedulerData[resourceIndex].leases[startSlotId].status = classText; + } + startSlotId++; + } + } +// +// Set Select - Free Slots *******End + // //Find Resource By Id function schedulerFindResourceById(Resources, id) { @@ -142,4 +198,4 @@ function schedulerCompareOnDay(dateOne, dateTwo) { return 0; } -} \ No newline at end of file +}