Last active
November 16, 2015 08:27
-
-
Save grekko/6e140845fc4d36f7fbf8 to your computer and use it in GitHub Desktop.
HTW: Doodle prefill Dates configurable time slots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.__startDate = function(startHours, startMinutes) { | |
dateStr = $('.timesTable .first').data('date-string').toString(); | |
date = new Date(dateStr.substr(0, 4), dateStr.substr(4, 2), dateStr.substr(6, 2)); | |
date.setHours(startHours); | |
date.setMinutes(startMinutes); | |
return date; | |
}; | |
window.__dateIncMinutes = function(date, minutes) { | |
var ms = date.getTime(); | |
var newDateMs = ms + (1000 * 60 * minutes); | |
return new Date(newDateMs); | |
}; | |
window.__add = function() { | |
$('#add-timeslots').click(); | |
}; | |
window.__fillOut = function(limit, startDate, minutesPerSlot) { | |
var nextDate = startDate; | |
$('.time-field.form-control').each(function(i, el) { | |
var slot = i+1; | |
if(slot > limit) return; | |
var hoursString = nextDate.getHours().toString(); | |
var minutesString = nextDate.getMinutes().toString(); | |
if(hoursString.length == 1) { | |
hoursString = '0' + hoursString; | |
} | |
if(minutesString.length == 1) { | |
minutesString = '0' + minutesString; | |
} | |
var nextDateString = hoursString + ':' + minutesString; | |
$el = $(el); | |
$el.val(nextDateString); | |
nextDate = __dateIncMinutes(nextDate, minutesPerSlot); | |
}); | |
}; | |
window.__start = function() { | |
var time = window.prompt('Time? E.g. 16:30', '16:30'); | |
var minutesPerSlot = parseInt(window.prompt('How many minutes per Slot?', '5')); | |
var hours = time.split(':')[0]; | |
var minutes = time.split(':')[1]; | |
var startDate = __startDate(hours, minutes); | |
setTimeout(window.__add, 200); | |
setTimeout(window.__add, 400); | |
setTimeout(window.__add, 600); | |
setTimeout(function() { window.__fillOut(10, startDate, minutesPerSlot) }, 800); | |
}; | |
__start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment