Created
September 13, 2013 17:15
-
-
Save bradorego/6553412 to your computer and use it in GitHub Desktop.
JS for calendar
This file contains 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
if (windowPathname.indexOf("/upcoming") > -1) { | |
var $calRadios = document.getElementsByTagName('input'), | |
$lastActive = document.getElementsByClassName('active')[0], | |
$calList = document.getElementById('planIdeaList'), | |
$couldDoIndicator = document.getElementById('indicator'), | |
$couldDo = document.getElementById('couldDo') | |
$couldDoWrap = document.getElementById('couldDoWrap'); | |
addActionButtonListeners(document.getElementsByClassName('actionButton')); | |
if ($couldDoWrap) { | |
$couldDoWrap.addEventListener(touchEvent, function (e) { | |
$couldDoIndicator.innerText = ($couldDoIndicator.innerText === ">") ? "v" : ">"; | |
$couldDo.toggleClass('hidden'); | |
}); | |
} | |
$calRadios.addEventListener('change', function (e) { | |
if ($lastActive) { | |
$lastActive.removeClass('active'); | |
} | |
this.parentNode.addClass('active'); | |
$lastActive = this.parentNode; | |
var date = this.parentNode.getAttribute('data-date'); | |
$loading.removeClass('hidden'); | |
sendAJAX('/upcoming?date=' + date + '&selected=' + date + '&list', "GET", function (resp) { | |
if (resp.status === 200) { | |
$calList.innerHTML = resp.responseText; | |
$couldDo = document.getElementById('couldDo'); | |
$couldDoIndicator = document.getElementById('indicator'); | |
$couldDoWrap = document.getElementById('couldDoWrap'); | |
if ($couldDoWrap) { | |
$couldDoWrap.addEventListener(touchEvent, function (e) { | |
$couldDoIndicator.innerText = ($couldDoIndicator.innerText === ">") ? "v" : ">"; | |
$couldDo.toggleClass('hidden'); | |
}); | |
$couldDo.getElementsByTagName('li').addEventListener(touchEvent, function (e) { | |
e.stopPropagation(); | |
}); | |
} | |
addActionButtonListeners(document.getElementsByClassName('actionButton')); | |
} else { | |
alert(resp.status + " - " + resp.statusText + "\n" + resp.responseText); | |
} | |
$loading.addClass('hidden'); | |
}); | |
}); | |
//// note: prev/next month/week assume the date prototypes I've provided before for thisWeek, thisMonth, nextWeek, and nextMonth. I can provide them again if needed | |
document.getElementById('prevWeek').addEventListener(touchEvent, function (e) { | |
var date = getURLParameter('date'), | |
now = (date) ? new Date(date) : new Date(); | |
now = now.thisWeek().start; | |
now.setDate(now.getDate() - 14); | |
window.location = "/upcoming?date=" + now.toISOString() + "&selected=" + now.toISOString(); | |
}); | |
document.getElementById('nextWeek').addEventListener(touchEvent, function (e) { | |
var date = getURLParameter('date'), | |
now = (date) ? new Date(date) : new Date(); | |
now = now.nextWeek().end; | |
now.setDate(now.getDate() + 1); | |
window.location = "/upcoming?date=" + now.toISOString() + "&selected=" + now.toISOString(); | |
}); | |
document.getElementById('prevMonth').addEventListener(touchEvent, function (e) { | |
var date = getURLParameter('date'), | |
now = (date) ? new Date(date) : new Date(); | |
now.setMonth(now.getMonth() - 1); | |
now.setDate(1); | |
window.location = "/upcoming?date=" + now.thisMonth().start.toISOString() + "&selected=" + now.thisMonth().start.toISOString(); | |
}); | |
document.getElementById('nextMonth').addEventListener(touchEvent, function (e) { | |
var date = getURLParameter('date'), | |
now = (date) ? new Date(date) : new Date(); | |
window.location = "/upcoming?date=" + now.nextMonth().start.toISOString() + "&selected=" + now.nextMonth().start.toISOString(); | |
}); | |
} | |
function addActionButtonListeners(buttons) { | |
for (var i = 0; i < buttons.length; i++) { | |
buttons[i].addEventListener('change', function (e) { | |
var id = this.name, | |
status = this.parentNode.getElementsByTagName('span')[0].innerText.toLowerCase(); | |
$loading.removeClass('hidden'); | |
sendAJAX("/plans/" + id + "/rollcall?status=" + status, "POST", function (resp) { | |
if (resp.status === 200) { | |
alert("Status updated"); | |
} | |
else if (resp.status === 432) { | |
/// do nothing | |
} else if (resp.status === 401) { | |
alert("Invalid authorization. User logged out"); | |
deleteCookie(CREDENTIALS_COOKIE_NAME); | |
window.location = "/sign-in"; | |
} else { | |
alert("An error occurred. HTTP error " + resp.responseText) | |
} | |
$loading.addClass('hidden'); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment