Skip to content

Instantly share code, notes, and snippets.

@nickstamas
Created August 29, 2010 18:21
Show Gist options
  • Select an option

  • Save nickstamas/556526 to your computer and use it in GitHub Desktop.

Select an option

Save nickstamas/556526 to your computer and use it in GitHub Desktop.
function Bucket(name) {
this._name = name;
}
Bucket.prototype.toString = function () {
return this._name;
};
Bucket.MORNING = new Bucket('morning');
Bucket.AFTERNOON = new Bucket('afternoon');
Bucket.EVENING = new Bucket('evening');
$(document).ready (function() {
addCalendarBindings();
addDetailPanelBindings();
//new post
$('#new_post_btn').bind("click", function() {
if ($(this).text() == 'New Post') {
$(this).text('Cancel');
$('#new_post').slideDown("slow");
} else {
$(this).text('New Post');
$('#new_post').slideUp("slow");
}
});
//drag and drop fun
$('.postDragToken').draggable({
cursorAt: { left: 5, top: 5 }, opacity: 0.5, helper: function(event) { return $('<div class="postDragTokenIcon">' + $('#'+this.id).children('.postInfo').children('.postHeading').text() + '</div>'); }
});
addDropTargets();
highlightCurrentDay();
});
function addDropTargets() {
$('.dropTarget.available').droppable({
accept: '.postDragToken', activeClass: 'highlightDrop', hoverClass: 'highlightDropOver', drop: function(event, ui) {
if ( $(this).attr('id') == Bucket.MORNING ) {
$.post('schedule', { bucket: Bucket.MORNING, post_id: $(ui.draggable).attr('id'), current_day: $('.detailPane').attr('id') }, updateCalendar );
} else if ( $(this).attr('id') == Bucket.AFTERNOON ) {
$.post('schedule', { bucket: Bucket.AFTERNOON, post_id: $(ui.draggable).attr('id'), current_day: $('.detailPane').attr('id') }, updateCalendar );
} else if ( $(this).attr('id') == Bucket.EVENING ) {
$.post('schedule', { bucket: Bucket.EVENING, post_id: $(ui.draggable).attr('id'), current_day: $('.detailPane').attr('id') }, updateCalendar );
} else {
alert("Error adding $ drop target.");
}
$(this).effect("pulsate", { times:3 }, 1000);
}
});
}
function addCalendarBindings() {
//calendar functionality
$('.active').bind("click", function(e) {
$('#utilityArea').effect('drop', { direction: "up", mode: "hide" });
classes = e.target.className.split(" ");
if ($.inArray('dayMarker', classes) > -1) {
updateID = $(e.target).parent().attr('id');
} else {
updateID = e.target.id
}
$.get('update_detail_pane', { value: updateID }, function(data) {
updateArea = $('#utilityArea');
updateArea.html(data);
highlightCurrentDay();
addDropTargets();
addDetailPanelBindings();
updateArea.effect('drop', { direction: "down", mode: "show" });
});
});
}
function highlightCurrentDay() {
$('.day').removeClass('selectedDay');
$('#'+getCurrentDay()).addClass('selectedDay');
}
function updateCalendar(html) {
$('#calendarContent').html(html);
highlightCurrentDay();
addDropTargets();
addCalendarBindings();
addDetailPanelBindings();
}
function getCurrentDay() {
id_arr = $('.detailPane').attr('id').split('_');
day = id_arr[id_arr.length-1];
return day;
}
function addDetailPanelBindings() {
$('.deleteInstanceButton').bind("click", function(e) {
$.post('unschedule', { disp_window: e.target.id, day: getCurrentDay() }, updateCalendar );
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment