var AIRTIME = (function(AIRTIME){ var mod, oSchedTable, SB_SELECTED_CLASS = "sb-selected", CURSOR_SELECTED_CLASS = "cursor-selected-row", NOW_PLAYING_CLASS = "sb-now-playing", $sbContent, $sbTable, $toolbar, $ul, $lib, cursors = [], cursorIds = [], showInstanceIds = [], headerFooter = []; if (AIRTIME.showbuilder === undefined) { AIRTIME.showbuilder = {}; } mod = AIRTIME.showbuilder; function checkError(json) { if (json.error !== undefined) { alert(json.error); } } mod.timeout = undefined; mod.timestamp = -1; mod.showInstances = []; mod.resetTimestamp = function() { mod.timestamp = -1; }; mod.setTimestamp = function(timestamp) { mod.timestamp = timestamp; }; mod.updateCalendarStatusIcon = function(json) { if (window.location.pathname.toLowerCase() != baseUrl+"schedule") { return; } var instance_id = json.schedule[0].instance; var lastElem = json.schedule[json.schedule.length-1]; var $elem = $($(".fc-event-inner.fc-event-skin .fc-event-title#"+instance_id).parent()); $elem.find(".small-icon").remove(); if (json.schedule[1].empty) { $elem .find(".fc-event-title") .after(''); } else if (lastElem["fRuntime"][0] == "-") { $elem .find(".fc-event-title") .after(''); } } mod.getTimestamp = function() { if (mod.timestamp !== undefined) { return mod.timestamp; } else { return -1; } }; mod.setShowInstances = function(showInstances) { mod.showInstances = showInstances; }; mod.getShowInstances = function() { return mod.showInstances; }; mod.refresh = function(schedId) { mod.resetTimestamp(); // once a track plays out we need to check if we can update // the is_scheduled flag in cc_files $.post(baseUrl+"schedule/update-future-is-scheduled", {"format": "json", "schedId": schedId}, function(data) { if (data.redrawLibTable !== undefined && data.redrawLibTable) { $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); } }); oSchedTable.fnDraw(); }; mod.checkSelectButton = function() { var $selectable = $sbTable.find("tbody").find("input:checkbox"); if ($selectable.length !== 0) { AIRTIME.button.enableButton("btn-group #timeline-select", false); } else { AIRTIME.button.disableButton("btn-group #timeline-select", false); } //need to check if the 'Select' button is disabled if ($(".btn-group #timeline-select").is(":disabled")) { $(".btn-group #timeline-select").removeAttr("disabled"); } }; mod.checkTrimButton = function() { var $over = $sbTable.find(".sb-over.sb-allowed"); if ($over.length !== 0) { AIRTIME.button.enableButton("icon-cut", true); } else { AIRTIME.button.disableButton("icon-cut", true); } }; mod.checkDeleteButton = function() { var $selected = $sbTable.find("tbody").find("input:checkbox").filter(":checked"); if ($selected.length !== 0) { AIRTIME.button.enableButton("icon-trash", true); } else { AIRTIME.button.disableButton("icon-trash", true); } }; mod.checkJumpToCurrentButton = function() { var $current = $sbTable.find("."+NOW_PLAYING_CLASS); if ($current.length !== 0) { AIRTIME.button.enableButton("icon-step-forward", true); } else { AIRTIME.button.disableButton("icon-step-forward", true); } }; mod.checkCancelButton = function() { var $current = $sbTable.find(".sb-current-show"), //this user type should be refactored into a separate users module later //when there's more time and more JS will need to know user data. userType = localStorage.getItem('user-type'), canCancel = false; if ($current.length !== 0 && $current.hasClass("sb-allowed")) { canCancel = true; } else if ($current.length !== 0 && (userType === 'A' || userType === 'P')) { canCancel = true; } if (canCancel === true) { AIRTIME.button.enableButton("icon-ban-circle", true); } else { AIRTIME.button.disableButton("icon-ban-circle", true); } }; mod.checkToolBarIcons = function() { AIRTIME.library.checkAddButton(); mod.checkSelectButton(); mod.checkTrimButton(); mod.checkDeleteButton(); mod.checkJumpToCurrentButton(); mod.checkCancelButton(); }; mod.selectCursor = function($el) { $el.addClass(CURSOR_SELECTED_CLASS); mod.checkToolBarIcons(); }; mod.removeCursor = function($el) { $el.removeClass(CURSOR_SELECTED_CLASS); mod.checkToolBarIcons(); }; /* * sNot is an optional string to filter selected elements by. (ex removing the currently playing item) */ mod.getSelectedData = function(sNot) { var $selected = $sbTable.find("tbody").find("input:checkbox").filter(":checked").parents("tr"), aData = [], i, length, $item; if (sNot !== undefined) { $selected = $selected.not("."+sNot); } for (i = 0, length = $selected.length; i < length; i++) { $item = $($selected.get(i)); aData.push($item.data('aData')); } return aData.reverse(); }; mod.selectAll = function () { $inputs = $sbTable.find("input:checkbox"); $inputs.attr("checked", true); $trs = $inputs.parents("tr"); $trs.addClass(SB_SELECTED_CLASS); mod.checkToolBarIcons(); }; mod.selectNone = function () { $inputs = $sbTable.find("input:checkbox"); $inputs.attr("checked", false); $trs = $inputs.parents("tr"); $trs.removeClass(SB_SELECTED_CLASS); mod.checkToolBarIcons(); }; mod.disableUI = function() { $lib.block({ message: "", theme: true, applyPlatformOpacityRules: false }); $sbContent.block({ message: "", theme: true, applyPlatformOpacityRules: false }); }; mod.enableUI = function() { $lib.unblock(); $sbContent.unblock(); //Block UI changes the postion to relative to display the messages. $lib.css("position", "static"); $sbContent.css("position", "static"); }; mod.fnItemCallback = function(json) { checkError(json); mod.getSelectedCursors(); oSchedTable.fnDraw(); mod.enableUI(); $("#library_content").find("#library_display").dataTable().fnStandingRedraw(); }; mod.getSelectedCursors = function() { cursorIds = []; /* We need to keep record of which show the cursor belongs to * in the case where more than one show is displayed in the show builder * because header and footer rows have the same id */ showInstanceIds = []; /* Keeps track if the row is a footer. We need to do this because * header and footer rows have the save cursorIds and showInstanceId * so both will be selected in the draw callback */ headerFooter = []; cursors = $(".cursor-selected-row"); for (i = 0; i < cursors.length; i++) { cursorIds.push(($(cursors.get(i)).attr("id"))); showInstanceIds.push(($(cursors.get(i)).attr("si_id"))); if ($(cursors.get(i)).hasClass("sb-footer")) { headerFooter.push("f"); } else { headerFooter.push("n"); } } }; mod.fnAdd = function(aMediaIds, aSchedIds) { mod.disableUI(); $.post(baseUrl+"showbuilder/schedule-add", {"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds}, mod.fnItemCallback ); }; mod.fnMove = function(aSelect, aAfter) { mod.disableUI(); $.post(baseUrl+"showbuilder/schedule-move", {"format": "json", "selectedItem": aSelect, "afterItem": aAfter}, mod.fnItemCallback ); }; mod.fnRemove = function(aItems) { mod.disableUI(); if (confirm($.i18n._("Delete selected item(s)?"))) { $.post( baseUrl+"showbuilder/schedule-remove", {"items": aItems, "format": "json"}, mod.fnItemCallback ); }else{ mod.enableUI(); } }; mod.fnRemoveSelectedItems = function() { var aData = mod.getSelectedData(), i, length, temp, aItems = []; for (i=0, length = aData.length; i < length; i++) { temp = aData[i]; aItems.push({"id": temp.id, "instance": temp.instance, "timestamp": temp.timestamp}); } mod.fnRemove(aItems); }; mod.fnServerData = function fnBuilderServerData( sSource, aoData, fnCallback ) { aoData.push( { name: "timestamp", value: mod.getTimestamp()} ); aoData.push( { name: "instances", value: mod.getShowInstances()} ); aoData.push( { name: "format", value: "json"} ); if (mod.fnServerData.hasOwnProperty("start")) { aoData.push( { name: "start", value: mod.fnServerData.start} ); } if (mod.fnServerData.hasOwnProperty("end")) { aoData.push( { name: "end", value: mod.fnServerData.end} ); } if (mod.fnServerData.hasOwnProperty("ops")) { aoData.push( { name: "myShows", value: mod.fnServerData.ops.myShows} ); aoData.push( { name: "showFilter", value: mod.fnServerData.ops.showFilter} ); } $.ajax({ "dataType": "json", "type": "POST", "url": sSource, "data": aoData, "success": function(json) { mod.updateCalendarStatusIcon(json) mod.setTimestamp(json.timestamp); mod.setShowInstances(json.instances); mod.getSelectedCursors(); fnCallback(json); } }); }; mod.jumpToCurrentTrack = function() { var $scroll = $sbContent.find(".dataTables_scrolling"); var scrolled = $scroll.scrollTop(); var scrollingTop = $scroll.offset().top; var oTable = $('#show_builder_table').dataTable(); var current = $sbTable.find("."+NOW_PLAYING_CLASS); var currentTop = current.offset().top; $scroll.scrollTop(currentTop - scrollingTop + scrolled); } mod.builderDataTable = function() { $sbContent = $('#show_builder'); $lib = $("#library_content"), $sbTable = $sbContent.find('table'); var isInitialized = false; oSchedTable = $sbTable.dataTable( { "aoColumns": [ /* checkbox */ {"mDataProp": "allowed", "sTitle": "", "sWidth": "15px", "sClass": "sb-checkbox"}, /* Type */ {"mDataProp": "image", "sTitle": "", "sClass": "library_image sb-image", "sWidth": "16px"}, /* starts */ {"mDataProp": "starts", "sTitle": $.i18n._("Start"), "sClass": "sb-starts", "sWidth": "60px"}, /* ends */ {"mDataProp": "ends", "sTitle": $.i18n._("End"), "sClass": "sb-ends", "sWidth": "60px"}, /* runtime */ {"mDataProp": "runtime", "sTitle": $.i18n._("Duration"), "sClass": "library_length sb-length", "sWidth": "65px"}, /* title */ {"mDataProp": "title", "sTitle": $.i18n._("Title"), "sClass": "sb-title"}, /* creator */ {"mDataProp": "creator", "sTitle": $.i18n._("Creator"), "sClass": "sb-creator"}, /* album */ {"mDataProp": "album", "sTitle": $.i18n._("Album"), "sClass": "sb-album"}, /* cue in */ {"mDataProp": "cuein", "sTitle": $.i18n._("Cue In"), "bVisible": false, "sClass": "sb-cue-in"}, /* cue out */ {"mDataProp": "cueout", "sTitle": $.i18n._("Cue Out"), "bVisible": false, "sClass": "sb-cue-out"}, /* fade in */ {"mDataProp": "fadein", "sTitle": $.i18n._("Fade In"), "bVisible": false, "sClass": "sb-fade-in"}, /* fade out */ {"mDataProp": "fadeout", "sTitle": $.i18n._("Fade Out"), "bVisible": false, "sClass": "sb-fade-out"}, /* Mime */ {"mDataProp" : "mime", "sTitle" : $.i18n._("Mime"), "bVisible": false, "sClass": "sb-mime"} ], "bJQueryUI": true, "bSort": false, "bFilter": false, "bProcessing": true, "bServerSide": true, "bInfo": false, "bAutoWidth": false, "bStateSave": true, "fnStateSaveParams": function (oSettings, oData) { //remove oData components we don't want to save. delete oData.oSearch; delete oData.aoSearchCols; }, "fnStateSave": function fnStateSave(oSettings, oData) { localStorage.setItem('datatables-timeline', JSON.stringify(oData)); $.ajax({ url: baseUrl+"usersettings/set-timeline-datatable", type: "POST", data: {settings : oData, format: "json"}, dataType: "json" }); }, "fnStateLoad": function fnBuilderStateLoad(oSettings) { var settings = localStorage.getItem('datatables-timeline'); if (settings !== "") { return JSON.parse(settings); } }, "fnStateLoadParams": function (oSettings, oData) { var i, length, a = oData.abVisCols; //putting serialized data back into the correct js type to make //sure everything works properly. for (i = 0, length = a.length; i < length; i++) { if (typeof(a[i]) === "string") { a[i] = (a[i] === "true") ? true : false; } } a = oData.ColReorder; for (i = 0, length = a.length; i < length; i++) { if (typeof(a[i]) === "string") { a[i] = parseInt(a[i], 10); } } oData.iCreate = parseInt(oData.iCreate, 10); }, "fnServerData": mod.fnServerData, "fnRowCallback": function fnRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { var i, length, sSeparatorHTML, fnPrepareSeparatorRow, $node, cl="", //background-color to imitate calendar color. r,g,b,a, $nRow = $(nRow), $image, $div, headerIcon; fnPrepareSeparatorRow = function fnPrepareSeparatorRow(sRowContent, sClass, iNodeIndex) { $node = $(nRow.children[iNodeIndex]); $node.html(sRowContent); $node.attr('colspan',100); for (i = iNodeIndex + 1, length = nRow.children.length; i < length; i = i+1) { $node = $(nRow.children[i]); $node.html(""); $node.attr("style", "display : none"); } $nRow.addClass(sClass); }; if (aData.header === true) { //remove the column classes from all tds. $nRow.find('td').removeClass(); $node = $(nRow.children[0]); $node.html(""); cl = 'sb-header'; if (aData.record === true) { headerIcon = (aData.soundcloud_id > 0) ? "soundcloud" : "recording"; $div = $("
", { "class": "small-icon " + headerIcon }); $node.append($div); } else if (aData.rebroadcast === true) { $div = $("", { "class": "small-icon rebroadcast" }); $node.append($div); } sSeparatorHTML = ''+aData.title+''; if (aData.rebroadcast === true) { sSeparatorHTML += ''+aData.rebroadcast_title+''; } sSeparatorHTML += ''; if (aData.startDate === aData.endDate) { sSeparatorHTML += ''+aData.startDate+''+aData.startTime+''; sSeparatorHTML +='-'+aData.endTime+''; } else { sSeparatorHTML += ''+aData.startDate+''+aData.startTime+''; sSeparatorHTML +='-'+aData.endDate+''+aData.endTime+''; } sSeparatorHTML += ''; fnPrepareSeparatorRow(sSeparatorHTML, cl, 1); } else if (aData.footer === true) { //remove the column classes from all tds. $nRow.find('td').removeClass(); $node = $(nRow.children[0]); cl = 'sb-footer'; //check the show's content status. if (aData.runtime > 0) { $node.html(''); cl = cl + ' ui-state-highlight'; } else { $node.html(''); cl = cl + ' ui-state-error'; } sSeparatorHTML = ''+aData.fRuntime+''; fnPrepareSeparatorRow(sSeparatorHTML, cl, 1); } else if (aData.empty === true) { //remove the column classes from all tds. $nRow.find('td').removeClass(); $node = $(nRow.children[0]); $node.html(''); sSeparatorHTML = ''+$.i18n._("Show Empty")+''; cl = cl + " sb-empty odd"; fnPrepareSeparatorRow(sSeparatorHTML, cl, 1); } else if (aData.record === true) { //remove the column classes from all tds. $nRow.find('td').removeClass(); $node = $(nRow.children[0]); $node.html(''); sSeparatorHTML = ''+$.i18n._("Recording From Line In")+''; cl = cl + " sb-record odd"; fnPrepareSeparatorRow(sSeparatorHTML, cl, 1); } else { //add the play function if the file exists on disk. $image = $nRow.find('td.sb-image'); //check if the file exists. if (aData.image === true) { $nRow.addClass("lib-audio"); if (!isAudioSupported(aData.mime)) { $image.html(''); } else { $image.html('