var AIRTIME = (function(AIRTIME) {
var mod;
if (AIRTIME.library === undefined) {
AIRTIME.library = {};
}
mod = AIRTIME.library;
mod.checkAddButton = function() {
var selected = mod.getChosenItemsLength(), $cursor = $('tr.sb-selected'), check = false,
shows = $('tr.sb-header'), current = $('tr.sb-current-show'),
// TODO: this is an ugly way of doing this... we should find a more robust way of checking which view we're in.
btnText = (window.location.href.toLowerCase().indexOf("schedule") > -1) ? $.i18n._('Add to show') : $.i18n._('Add to next show');
// make sure library items are selected and a cursor is selected.
if (selected !== 0) {
check = true;
}
var sortable = $(".spl_sortable");
if ($("#show_builder_table").is(":visible")) {
if (shows.length === 0) {
check = false;
}
if ($cursor.length !== 0) {
btnText = $.i18n._('Add after selected items');
} else if (current.length !== 0) {
btnText = $.i18n._('Add to current show');
}
} else if (sortable.length > 0 && sortable.is(":visible")) {
var objType = $('.active-tab .obj_type').val();
if (objType === 'block') {
btnText = $.i18n._('Add to current smart block');
} else {
btnText = $.i18n._('Add to current playlist');
}
} else {
check = false;
}
if (check) {
AIRTIME.button.enableButton("btn-group #library-plus", false);
} else {
AIRTIME.button.disableButton("btn-group #library-plus", false);
}
AIRTIME.library.changeAddButtonText($('.btn-group #library-plus #lib-plus-text'), btnText);
};
mod.fnRowCallback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
var $nRow = $(nRow);
if (aData.ftype === "audioclip") {
$nRow.addClass("lib-audio");
$image = $nRow.find('td.library_type');
if (!isAudioSupported(aData.mime)) {
$image.html('');
aData.image = '';
}
} else if (aData.ftype === "stream") {
$nRow.addClass("lib-stream");
} else {
$nRow.addClass("lib-pl");
}
$nRow.attr("id", aData["tr_id"]).data("aData", aData).data("screen",
"timeline");
};
/**
* Draw a placeholder for the given table to show if it has no data.
*
* @param {jQuery} table jQuery object containing the table DOM node
*/
mod.drawEmptyPlaceholder = function (table) {
var emptyRow = table.find('tr:has(td.dataTables_empty)'),
wrapper = table.closest(".dataTables_wrapper");
var libEmpty = wrapper.find('.empty_placeholder');
if (emptyRow.length > 0) {
emptyRow.hide();
var mediaType = parseInt($('.media_type_selector.selected').data('selection-id')),
img = wrapper.find('.empty_placeholder_image');
if (isNaN(mediaType)) { return; }
// Remove all classes for when we change between empty media types
img.removeClass(function() { return $(this).attr("class"); });
if (table[0] == AIRTIME.library.podcastEpisodeDataTable[0]) {
img.addClass("empty_placeholder_image icon-white icon-th-list");
wrapper.find('.empty_placeholder_text').html(
$.i18n._("This podcast doesn't have any episodes!")
+ "
" + $.i18n._("Make sure the RSS feed contains audio items (with enclosure tags).")
+ "
" + $.i18n._("Learn about podcasts") + ""
);
} else {
var opts = AIRTIME.library.placeholder(mediaType);
img.addClass("empty_placeholder_image icon-white " + opts.icon);
wrapper.find('.empty_placeholder_text').html(
$.i18n._("You haven't added any " + opts.media + ".")
+ "
" + $.i18n._(opts.subtext)
+ "
" + $.i18n._("Learn about " + opts.media) + ""
);
}
libEmpty.show();
} else {
libEmpty.hide();
}
};
mod.fnDrawCallback = function fnLibDrawCallback() {
var table = $('#library_display'),
cb = table.find('th[class*="checkbox"]');
if (cb.find("input").length == 0) {
cb.append("");
}
mod.redrawChosen();
mod.checkToolBarIcons();
mod.drawEmptyPlaceholder(table);
var sortable;
if ($("#show_builder_table").is(":visible")) {
sortable = "#show_builder_table";
} else {
sortable = ".active-tab .spl_sortable";
}
$('#library_display tr[class*="lib-"]')
.draggable(
{
helper: function () {
var $el = $(this), selected = mod
.getChosenItemsLength(), container, thead = $("#show_builder_table thead"), colspan = thead
.find("th").length, width = $el.width(), message;
// dragging an element that has an unselected
// checkbox.
if (mod.isChosenItem($el) === false) {
selected++;
}
if (selected === 1) {
message = $.i18n._("Adding 1 Item");
} else {
message = sprintf($.i18n._("Adding %s Items"), selected);
}
container = $('