Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #144 from elizabethfinedev/hotfix/schedules-cleanu…
Browse files Browse the repository at this point in the history
…p-139

Cleanup for issue #139
  • Loading branch information
copperwater authored Oct 2, 2016
2 parents 6817698 + ddedc75 commit 463b014
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions app/assets/javascripts/views/schedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Yacs.views.schedule = function (target) {
target.innerHTML = HandlebarsTemplates.schedules();

var scheduleElement = target.querySelector('#schedule-container');
var selectionElement = target.querySelector('#selection-container')
var selectionElement = target.querySelector('#selection-container');
var leftSwitchElement = target.querySelector('#left-switch');
var rightSwitchElement = target.querySelector('#right-switch');
var clearButtonElement = target.querySelector('#clear-btn');
Expand All @@ -27,7 +27,7 @@ Yacs.views.schedule = function (target) {
var toMinutes = function (timeString) {
var int = parseInt(timeString);
return Math.floor(int / 100) * 60 + int % 100;
}
};

/**
* Translate schedules returned by the API into a displayable form.
Expand All @@ -49,7 +49,7 @@ Yacs.views.schedule = function (target) {
courseIds.push(section.course_id);
color = courseIds.length - 1;
}
crns.push(section.crn)
crns.push(section.crn);
section.periods.forEach(function (period) {
start = Math.min(start, toMinutes(period.start));
end = Math.max(end, toMinutes(period.end));
Expand Down Expand Up @@ -86,9 +86,9 @@ Yacs.views.schedule = function (target) {
timeSpan: Math.ceil((data.end - data.start) / 60) * 60 });
scheduleCountElement.textContent = scheduleData.length;
if (scheduleData.length > 0) {
show(0);
showSchedule(0);
} else {
show(-1);
showSchedule(-1);
if (Yacs.user.getSelections().length > 0) {
scheduleStatusElement.textContent = "No schedules found :( Try removing some courses";
} else {
Expand Down Expand Up @@ -123,10 +123,10 @@ Yacs.views.schedule = function (target) {
};

/**
* Show schdule at given index, and display corresponding CRNs.
* Show schedule at given index, and display corresponding CRNs.
* If index is -1, show nil schedule.
*/
var show = function (index) {
var showSchedule = function (index) {
if (index == -1) {
scheduleStatusElement.textContent = "";
scheduleNumElement.textContent = 0;
Expand All @@ -141,31 +141,31 @@ Yacs.views.schedule = function (target) {
/**
* Switch to schedule [[n + 1] % n] in the sequence
*/
var next = function () {
var nextSchedule = function () {
if (scheduleData.length > 0) {
scheduleIndex = (++scheduleIndex < scheduleData.length ? scheduleIndex : 0);
show(scheduleIndex);
showSchedule(scheduleIndex);
}
}
};

/**
* Switch to schedule [[n - 1] % n] in the sequence
*/
var previous = function () {
var prevSchedule = function () {
if (scheduleData.length > 0) {
scheduleIndex = (--scheduleIndex < 0 ? scheduleData.length - 1 : scheduleIndex);
show(scheduleIndex);
showSchedule(scheduleIndex);
}
}
};

/**
* Show next schedule if right is clicked or pressed,
* show previous schedule if left is clicked or pressed
*/
Yacs.on('click', leftSwitchElement, previous);
Yacs.on('click', rightSwitchElement, next);
Yacs.on('keydown', document, function (elem, event) { if (event.keyCode == 37) previous(); });
Yacs.on('keydown', document, function (elem, event) { if (event.keyCode == 39) next(); });
Yacs.on('click', leftSwitchElement, prevSchedule);
Yacs.on('click', rightSwitchElement, nextSchedule);
Yacs.on('keydown', document, function (elem, event) { if (event.keyCode == 37) prevSchedule(); });
Yacs.on('keydown', document, function (elem, event) { if (event.keyCode == 39) nextSchedule(); });

/**
* Clear selections in cookie when clear button is pressed, and update
Expand Down

0 comments on commit 463b014

Please sign in to comment.