forked from rubycentral/cfp-app
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drag Unscheduled Sessions onto Schedule Grid (rubycentral#265)
- Allow for timeslots before 9am and after 7pm. - Added unscheduled session cards with filtering - Cards are draggable and droppable - Added update time slots via drag and drop - Fixed preview bar covers edit modal
- Loading branch information
Showing
17 changed files
with
587 additions
and
66 deletions.
There are no files selected for viewing
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
106 changes: 106 additions & 0 deletions
106
app/assets/javascripts/staff/program/schedule_dragging.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
(function($, window) { | ||
if (typeof(window.Schedule) === 'undefined') { | ||
window.Schedule = {} | ||
} | ||
if (typeof(window.Schedule.Drag) !== 'undefined') { | ||
return window.Schedule.Drag | ||
} | ||
|
||
function init() { | ||
if ($(".unscheduled-sessions").length ) { | ||
$('.unscheduled-sessions-toggle').on('click', toggleUnscheduledSessionsWidget) | ||
$('#session_search').on('keyup', filterSessions) | ||
|
||
var trackCssClasses = []; | ||
var trackColors = []; | ||
|
||
initTrackColors() | ||
initDraggableSessions() | ||
initDroppableSessionsWidget() | ||
} | ||
} | ||
|
||
function toggleUnscheduledSessionsWidget(e) { | ||
e.preventDefault() | ||
$('.unscheduled-sessions-widget, .search-sessions-wrapper').toggleClass('hidden') | ||
} | ||
|
||
function filterSessions() { | ||
var query = this.value.toLowerCase() | ||
var items = $('.unscheduled-sessions-widget .draggable-session-card') | ||
|
||
for (var i = 0; i < items.length; i++) { | ||
var itemText = $(items[i]).text().toLowerCase() | ||
if (itemText.indexOf(query) > -1) { | ||
$(items[i]).removeClass('hidden') | ||
} else { | ||
$(items[i]).addClass('hidden') | ||
} | ||
} | ||
} | ||
|
||
function initTrackColors() { | ||
trackCssClasses = $('#schedule').data('tracks-css'); | ||
trackColors = palette('tol-rainbow', trackCssClasses.length); | ||
} | ||
|
||
function initDraggableSessions() { | ||
var $sessions = $('.draggable-session-card') | ||
$sessions.each(function(i, session) { | ||
initDraggableSession($(session)) | ||
}) | ||
} | ||
|
||
function initDraggableSession($session) { | ||
var trackCss = $session.data('trackCss') | ||
var i = trackCssClasses.indexOf(trackCss) | ||
if (i >= 0) { | ||
$session.find('.track').css({ | ||
backgroundColor: '#' + trackColors[i] | ||
}) | ||
} | ||
$session.draggable({ | ||
helper: 'clone', | ||
revertDuration: 100, | ||
revert: 'invalid', | ||
appendTo: 'body', | ||
scroll: false, | ||
start: function(event, ui) { | ||
$(ui.helper).css({ backgroundColor: 'white' }) | ||
} | ||
}) | ||
} | ||
|
||
function initDroppableSessionsWidget() { | ||
$('.unscheduled-sessions-widget').droppable({ | ||
accept: '.draggable-session-card', | ||
drop: function(event, ui) { | ||
$(ui.draggable).detach().removeAttr('style').prependTo(this) | ||
$(ui.draggable).removeClass('small medium large') | ||
if ($(ui.draggable).data('scheduled')) { | ||
unschedule($(ui.draggable)) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
function unschedule($removed) { | ||
$.ajax({ | ||
url: $removed.data('unscheduleTimeSlotPath'), | ||
method: 'patch', | ||
data: { time_slot: { program_session_id: '' } } | ||
}) | ||
} | ||
|
||
window.Schedule.Drag = { | ||
init: init, | ||
initDraggableSession: initDraggableSession, | ||
unschedule: unschedule, | ||
} | ||
|
||
|
||
}) (jQuery, window) | ||
|
||
$(function() { | ||
window.Schedule.Drag.init() | ||
}) |
Oops, something went wrong.