Merge branch 'saas-showbuilder' of github.com:sourcefabric/Airtime into saas-showbuilder

This commit is contained in:
Albert Santoni 2015-08-12 16:45:07 -04:00
commit 61d1e6bb50
18 changed files with 1618 additions and 118 deletions

View file

@ -1,5 +1,6 @@
var previewWidth = 482,
previewHeight = 110;
previewHeight = 110,
USABILITY_HINT_PADDING = 40;
$(document).ready(function() {
@ -12,6 +13,9 @@ $(document).ready(function() {
//this statement tells the browser to fade out any success message after 5 seconds
setTimeout(function(){$(".success").fadeOut("slow", function(){$(this).empty()});}, 5000);
if ($('.usability_hint:visible')) {
$(".wrapper").css("padding-top", USABILITY_HINT_PADDING); // Account for usability hint
}
});
/*
@ -162,6 +166,17 @@ function removeSuccessMsg() {
$status.fadeOut("slow", function(){$status.empty()});
}
function hideHint(h) {
h.hide("slow").addClass("hidden");
$(".wrapper").css("padding-top", 10);
}
function showHint(h) {
console.log("test");
h.show("slow").removeClass("hidden");
$(".wrapper").css("padding-top", USABILITY_HINT_PADDING); // Account for usability hint
}
function getUsabilityHint() {
var pathname = window.location.pathname;
$.getJSON("/api/get-usability-hint", {"format": "json", "userPath": pathname}, function(json) {
@ -169,26 +184,25 @@ function getUsabilityHint() {
var current_hint = $hint_div.html();
if (json === "") {
// there are no more hints to display to the user
$hint_div.hide("slow").addClass("hidden");
hideHint($hint_div);
} else if (current_hint !== json) {
// we only change the message if it is new
if ($hint_div.is(":visible")) {
$hint_div.hide("slow").addClass("hidden");
hideHint($hint_div);
}
$hint_div.html(json);
$hint_div.show("slow").removeClass("hidden");
showHint($hint_div);
} else {
// hint is the same before we hid it so we just need to show it
if ($hint_div.is(":hidden")) {
$hint_div.show("slow").removeClass("hidden");
showHint($hint_div);
}
}
});
}
$(document).mouseup(function (e) {
var mb = $("#menu-btn"),
w = $(window).width();
var mb = $("#menu-btn"), w = $(window).width();
if (!mb.is(e.target) && mb.has(e.target).length === 0 && w <= 970) {
$('#nav .responsive-menu').slideUp();
}

View file

@ -539,36 +539,36 @@ var AIRTIME = (function(AIRTIME) {
//IMPORTANT: WHEN ADDING A NEW COLUMN PLEASE CONSULT WITH THE WIKI
// https://wiki.sourcefabric.org/display/CC/Adding+a+new+library+datatable+column
"aoColumns": [
/* ftype */ { "sTitle" : "" , "mDataProp" : "ftype" , "bSearchable" : false , "bVisible" : false } ,
/* Checkbox */ { "sTitle" : "" , "mDataProp" : "checkbox" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_checkbox" } ,
/* Type */ { "sTitle" : "" , "mDataProp" : "image" , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_type" , "iDataSort" : 0 } ,
/* Is Scheduled */ { "sTitle" : $.i18n._("Scheduled") , "mDataProp" : "is_scheduled" , "bVisible" : false , "bSearchable" : false , "sWidth" : "90px" , "sClass" : "library_is_scheduled"} ,
/* ftype */ { "sTitle" : "" , "mDataProp" : "ftype" , "bSearchable" : false , "bVisible" : false },
/* Checkbox */ { "sTitle" : "" , "mDataProp" : "checkbox" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_checkbox" },
/* Type */ { "sTitle" : "" , "mDataProp" : "image" , "bSortable" : false , "bSearchable" : false , "sWidth" : "16px" , "sClass" : "library_type" , "iDataSort" : 0 },
/* Is Scheduled */ { "sTitle" : $.i18n._("Scheduled") , "mDataProp" : "is_scheduled" , "bVisible" : false , "bSearchable" : false , "sWidth" : "90px" , "sClass" : "library_is_scheduled" },
///* Is Playlist */ { "sTitle" : $.i18n._("Playlist / Block") , "mDataProp" : "is_playlist" , "bSearchable" : false , "sWidth" : "110px" , "sClass" : "library_is_playlist"} ,
/* Title */ { "sTitle" : $.i18n._("Title") , "mDataProp" : "track_title" , "sClass" : "library_title" , "sWidth" : "170px" } ,
/* Creator */ { "sTitle" : $.i18n._("Creator") , "mDataProp" : "artist_name" , "sClass" : "library_creator" , "sWidth" : "160px" } ,
/* Album */ { "sTitle" : $.i18n._("Album") , "mDataProp" : "album_title" , "sClass" : "library_album" , "sWidth" : "150px" } ,
/* Title */ { "sTitle" : $.i18n._("Title") , "mDataProp" : "track_title" , "sClass" : "library_title" , "sWidth" : "170px" },
/* Creator */ { "sTitle" : $.i18n._("Creator") , "mDataProp" : "artist_name" , "sClass" : "library_creator" , "sWidth" : "160px" },
/* Album */ { "sTitle" : $.i18n._("Album") , "mDataProp" : "album_title" , "sClass" : "library_album" , "sWidth" : "150px" },
/* Bit Rate */ { "sTitle" : $.i18n._("Bit Rate") , "mDataProp" : "bit_rate" , "bVisible" : false , "sClass" : "library_bitrate" , "sWidth" : "80px" },
/* BPM */ { "sTitle" : $.i18n._("BPM") , "mDataProp" : "bpm" , "bVisible" : false , "sClass" : "library_bpm" , "sWidth" : "50px" },
/* Composer */ { "sTitle" : $.i18n._("Composer") , "mDataProp" : "composer" , "bVisible" : false , "sClass" : "library_composer" , "sWidth" : "150px" },
/* Conductor */ { "sTitle" : $.i18n._("Conductor") , "mDataProp" : "conductor" , "bVisible" : false , "sClass" : "library_conductor" , "sWidth" : "125px" },
/* Copyright */ { "sTitle" : $.i18n._("Copyright") , "mDataProp" : "copyright" , "bVisible" : false , "sClass" : "library_copyright" , "sWidth" : "125px" },
/* Cue In */ { "sTitle" : $.i18n._("Cue In") , "mDataProp" : "cuein" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" },
/* Cue Out */ { "sTitle" : $.i18n._("Cue Out") , "mDataProp" : "cueout" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" },
/* Cue In */ { "sTitle" : $.i18n._("Cue In") , "mDataProp" : "cuein" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" },
/* Cue Out */ { "sTitle" : $.i18n._("Cue Out") , "mDataProp" : "cueout" , "bVisible" : false , "sClass" : "library_length" , "sWidth" : "80px" },
/* Encoded */ { "sTitle" : $.i18n._("Encoded By") , "mDataProp" : "encoded_by" , "bVisible" : false , "sClass" : "library_encoded" , "sWidth" : "150px" },
/* Genre */ { "sTitle" : $.i18n._("Genre") , "mDataProp" : "genre" , "bVisible" : false , "sClass" : "library_genre" , "sWidth" : "100px" },
/* ISRC Number */ { "sTitle" : $.i18n._("ISRC") , "mDataProp" : "isrc_number" , "bVisible" : false , "sClass" : "library_isrc" , "sWidth" : "150px" },
/* Label */ { "sTitle" : $.i18n._("Label") , "mDataProp" : "label" , "bVisible" : false , "sClass" : "library_label" , "sWidth" : "125px" },
/* Language */ { "sTitle" : $.i18n._("Language") , "mDataProp" : "language" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" },
/* Last Modified */ { "sTitle" : $.i18n._("Last Modified") , "mDataProp" : "mtime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "125px" },
/* Last Played */ { "sTitle" : $.i18n._("Last Played") , "mDataProp" : "lptime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "125px" },
/* Length */ { "sTitle" : $.i18n._("Length") , "mDataProp" : "length" , "sClass" : "library_length" , "sWidth" : "80px" } ,
/* Last Modified */ { "sTitle" : $.i18n._("Last Modified") , "mDataProp" : "mtime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "155px" },
/* Last Played */ { "sTitle" : $.i18n._("Last Played") , "mDataProp" : "lptime" , "bVisible" : false , "sClass" : "library_modified_time" , "sWidth" : "155px" },
/* Length */ { "sTitle" : $.i18n._("Length") , "mDataProp" : "length" , "sClass" : "library_length" , "sWidth" : "80px" },
/* Mime */ { "sTitle" : $.i18n._("Mime") , "mDataProp" : "mime" , "bVisible" : false , "sClass" : "library_mime" , "sWidth" : "80px" },
/* Mood */ { "sTitle" : $.i18n._("Mood") , "mDataProp" : "mood" , "bVisible" : false , "sClass" : "library_mood" , "sWidth" : "70px" },
/* Owner */ { "sTitle" : $.i18n._("Owner") , "mDataProp" : "owner_id" , "bVisible" : false , "sClass" : "library_language" , "sWidth" : "125px" },
/* Replay Gain */ { "sTitle" : $.i18n._("Replay Gain") , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_replay_gain" , "sWidth" : "80px" },
/* Sample Rate */ { "sTitle" : $.i18n._("Sample Rate") , "mDataProp" : "sample_rate" , "bVisible" : false , "sClass" : "library_sr" , "sWidth" : "80px" },
/* Track Number */ { "sTitle" : $.i18n._("Track Number") , "mDataProp" : "track_number" , "bVisible" : false , "sClass" : "library_track" , "sWidth" : "65px" },
/* Upload Time */ { "sTitle" : $.i18n._("Uploaded") , "mDataProp" : "utime" , "bVisible" : false , "sClass" : "library_upload_time" , "sWidth" : "125px" } ,
/* Replay Gain */ { "sTitle" : $.i18n._("Replay Gain") , "mDataProp" : "replay_gain" , "bVisible" : false , "sClass" : "library_replay_gain" , "sWidth" : "125px" },
/* Sample Rate */ { "sTitle" : $.i18n._("Sample Rate") , "mDataProp" : "sample_rate" , "bVisible" : false , "sClass" : "library_sr" , "sWidth" : "125px" },
/* Track Number */ { "sTitle" : $.i18n._("Track Number") , "mDataProp" : "track_number" , "bVisible" : false , "sClass" : "library_track" , "sWidth" : "125px" },
/* Upload Time */ { "sTitle" : $.i18n._("Uploaded") , "mDataProp" : "utime" , "bVisible" : false , "sClass" : "library_upload_time" , "sWidth" : "155px" },
/* Website */ { "sTitle" : $.i18n._("Website") , "mDataProp" : "info_url" , "bVisible" : false , "sClass" : "library_url" , "sWidth" : "150px" },
/* Year */ { "sTitle" : $.i18n._("Year") , "mDataProp" : "year" , "bVisible" : false , "sClass" : "library_year" , "sWidth" : "60px" }
],

View file

@ -477,7 +477,9 @@ var AIRTIME = (function(AIRTIME){
return;
}
newTab.tab.on("click", function() {
AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab);
if (!$(this).hasClass('active')) {
AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab);
}
});
newTab.wrapper.find(".md-cancel").on("click", function() {
closeTab();
@ -491,9 +493,11 @@ var AIRTIME = (function(AIRTIME){
return;
}
newTab.tab.on("click", function() {
AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab);
$.post(baseUrl+'new-playlist/edit',
{format: "json", id: newTab.pane.find(".obj_id").val(), type: newTab.pane.find(".obj_type").val()});
if (!$(this).hasClass('active')) {
AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab);
$.post(baseUrl+'new-playlist/edit',
{format: "json", id: newTab.pane.find(".obj_id").val(), type: newTab.pane.find(".obj_type").val()});
}
});
AIRTIME.playlist.init();
@ -515,16 +519,22 @@ var AIRTIME = (function(AIRTIME){
}
function closeTab(id) {
var pane = id ? $(".pl-content[tab-id='" + id + "']") : $(".active-tab"),
var curr = $(".active-tab"),
pane = id ? $(".pl-content[tab-id='" + id + "']") : curr,
tab = id ? $(".nav.nav-tabs [tab-id='" + id + "']") : $(".nav.nav-tabs .active"),
toPane = pane.next().length > 0 ? pane.next() : pane.prev(),
toTab = tab.next().length > 0 ? tab.next() : tab.prev(),
objId = id ? id : pane.find(".obj_id").val();
delete $openTabs[tab.attr("tab-type") + objId];
objId = pane.find(".obj_id").val(),
pl = id ? pane : $pl;
delete $openTabs[tab.attr("tab-type") + objId]; // Remove the closed tab from our open tabs array
// Remove the relevant DOM elements (the tab and the tab content)
tab.remove();
$pl.remove();
AIRTIME.showbuilder.switchTab(toPane, toTab);
pl.remove();
if (pane.get(0) == curr.get(0)) { // Closing the current tab, otherwise we don't need to switch tabs
AIRTIME.showbuilder.switchTab(toPane, toTab);
}
}
mod.closeTab = function(id) {
@ -586,7 +596,7 @@ var AIRTIME = (function(AIRTIME){
position: {
my: "left bottom",
at: "right center"
},
}
})
} else {
$(value).bind("click", openAudioPreview);
@ -917,9 +927,9 @@ var AIRTIME = (function(AIRTIME){
$(this).unbind("click"); // Prevent repeated clicks in quick succession from closing multiple tabs
var tabId = $(this).closest("li").attr("tab-id");
AIRTIME.showbuilder.switchTab($("#pl-tab-content-" + tabId), $("#pl-tab-" + tabId));
//AIRTIME.showbuilder.switchTab($("#pl-tab-content-" + tabId), $("#pl-tab-" + tabId));
//$pl.hide();
$pl.hide();
// We need to update the text on the add button
AIRTIME.library.checkAddButton();
// We also need to run the draw callback to update how dragged items are drawn
@ -930,9 +940,9 @@ var AIRTIME = (function(AIRTIME){
if ((name == "Untitled Playlist"
|| name == "Untitled Smart Block")
&& $pl.find(".spl_sortable .spl_empty").length == 1) {
mod.fnDelete();
mod.fnDelete(undefined, tabId);
} else {
closeTab();
closeTab(tabId);
}
$.ajax( {
@ -968,7 +978,6 @@ var AIRTIME = (function(AIRTIME){
alert(json.error);
}
if (json.html !== undefined) {
console.log(json);
closeTab();
openPlaylist(json);
}
@ -1144,20 +1153,19 @@ var AIRTIME = (function(AIRTIME){
};
mod.fnDelete = function(plid) {
var url, id, lastMod;
mod.fnDelete = function(plid, tabId) {
var url, id, lastMod, type, pl = (tabId === undefined) ? $pl : $('#pl-tab-content' + tabId);
stopAudioPreview();
id = (plid === undefined) ? getId() : plid;
lastMod = getModified();
type = $pl.find('.obj_type').val();
type = pl.find('.obj_type').val();
url = baseUrl+'new-playlist/delete';
$.post(url,
{format: "json", ids: id, modified: lastMod, type: type},
function(json) {
closeTab();
// openPlaylist(json);
closeTab(tabId);
redrawLib();
});
};
@ -1547,8 +1555,8 @@ var AIRTIME = (function(AIRTIME){
mod.onResize = function() {
var h = $(".panel-header .nav").height();
$(".pl-content").css("margin-top", h + 4); // 8px extra for padding
$("#show_builder_table_wrapper").css("top", h + 4);
$(".pl-content").css("margin-top", h + 5); // 8px extra for padding
$("#show_builder_table_wrapper").css("top", h + 5);
};
return AIRTIME;

View file

@ -0,0 +1,609 @@
$(document).ready(function() {
setSmartBlockEvents();
});
function setSmartBlockEvents() {
var activeTab = $('.active-tab'),
form = activeTab.find('.smart-block-form');
/********** ADD CRITERIA ROW **********/
form.find('#criteria_add').live('click', function(){
var div = $('dd[id="sp_criteria-element"]').children('div:visible:last');
div.find('.db-logic-label').text('and').show();
div = div.next().show();
div.children().removeAttr('disabled');
div = div.next();
if (div.length === 0) {
$(this).hide();
}
appendAddButton();
appendModAddButton();
removeButtonCheck();
});
/********** ADD MODIFIER ROW **********/
form.find('a[id^="modifier_add"]').live('click', function(){
var criteria_value = $(this).siblings('select[name^="sp_criteria_field"]').val();
//make new modifier row
var newRow = $(this).parent().clone(),
newRowCrit = newRow.find('select[name^="sp_criteria_field"]'),
newRowMod = newRow.find('select[name^="sp_criteria_modifier"]'),
newRowVal = newRow.find('input[name^="sp_criteria_value"]'),
newRowExtra = newRow.find('input[name^="sp_criteria_extra"]'),
newRowRemove = newRow.find('a[id^="criteria_remove"]');
//remove error msg
if (newRow.children().hasClass('errors sp-errors')) {
newRow.find('span[class="errors sp-errors"]').remove();
}
//hide the critieria field select box
newRowCrit.addClass('sp-invisible');
//keep criteria value the same
newRowCrit.val(criteria_value);
//reset all other values
newRowMod.val('0');
newRowVal.val('');
newRowExtra.val('');
disableAndHideExtraField(newRowVal);
sizeTextBoxes(newRowVal, 'sp_extra_input_text', 'sp_input_text');
//remove the 'criteria add' button from new modifier row
newRow.find('#criteria_add').remove();
$(this).parent().after(newRow);
reindexElements();
appendAddButton();
appendModAddButton();
removeButtonCheck();
});
/********** REMOVE ROW **********/
form.find('a[id^="criteria_remove"]').live('click', function(){
var curr = $(this).parent();
var curr_pos = curr.index();
var list = curr.parent();
var list_length = list.find("div:visible").length;
var count = list_length - curr_pos;
var next = curr.next();
var item_to_hide;
var prev;
var index;
//remove error message from current row, if any
var error_element = curr.find('span[class="errors sp-errors"]');
if (error_element.is(':visible')) {
error_element.remove();
}
/* assign next row to current row for all rows below and including
* the row getting removed
*/
for (var i=0; i<count; i++) {
index = getRowIndex(curr);
var criteria = next.find('[name^="sp_criteria_field"]').val();
curr.find('[name^="sp_criteria_field"]').val(criteria);
var modifier = next.find('[name^="sp_criteria_modifier"]').val();
populateModifierSelect(curr.find('[name^="sp_criteria_field"]'), false);
curr.find('[name^="sp_criteria_modifier"]').val(modifier);
var criteria_value = next.find('[name^="sp_criteria_value"]').val();
curr.find('[name^="sp_criteria_value"]').val(criteria_value);
/* if current and next row have the extra criteria value
* (for 'is in the range' modifier), then assign the next
* extra value to current and remove that element from
* next row
*/
if (curr.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled"
&& next.find('#extra_criteria').is(':visible')) {
var criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
disableAndHideExtraField(next.find(':first-child'), getRowIndex(next));
/* if only the current row has the extra criteria value,
* then just remove the current row's extra criteria element
*/
} else if (curr.find('[name^="sp_criteria_extra"]').attr("disabled") != "disabled"
&& next.find('#extra_criteria').not(':visible')) {
disableAndHideExtraField(curr.find(':first-child'), index);
/* if only the next row has the extra criteria value,
* then add the extra criteria element to current row
* and assign next row's value to it
*/
} else if (next.find('#extra_criteria').is(':visible')) {
criteria_extra = next.find('[name^="sp_criteria_extra"]').val();
enableAndShowExtraField(curr.find(':first-child'), index);
curr.find('[name^="sp_criteria_extra"]').val(criteria_extra);
}
/* determine if current row is a modifier row
* if it is, make the criteria select invisible
*/
prev = curr.prev();
if (curr.find('[name^="sp_criteria_field"]').val() == prev.find('[name^="sp_criteria_field"]').val()) {
if (!curr.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
curr.find('select[name^="sp_criteria_field"]').addClass('sp-invisible');
}
} else {
if (curr.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
curr.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible');
}
}
curr = next;
next = curr.next();
}
/* Disable the last visible row since it holds the values the user removed
* Reset the values to empty and resize the criteria value textbox
* in case the row had the extra criteria textbox
*/
item_to_hide = list.find('div:visible:last');
item_to_hide.children().attr('disabled', 'disabled');
if (item_to_hide.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
item_to_hide.find('select[name^="sp_criteria_field"]').removeClass('sp-invisible');
}
item_to_hide.find('[name^="sp_criteria_field"]').val(0).end()
.find('[name^="sp_criteria_modifier"]').val(0).end()
.find('[name^="sp_criteria_value"]').val('').end()
.find('[name^="sp_criteria_extra"]').val('');
sizeTextBoxes(item_to_hide.find('[name^="sp_criteria_value"]'), 'sp_extra_input_text', 'sp_input_text');
item_to_hide.hide();
list.next().show();
//check if last row is a modifier row
var last_row = list.find('div:visible:last');
if (last_row.find('[name^="sp_criteria_field"]').val() == last_row.prev().find('[name^="sp_criteria_field"]').val()) {
if (!last_row.find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
last_row.find('select[name^="sp_criteria_field"]').addClass('sp-invisible');
}
}
// always put '+' button on the last enabled row
appendAddButton();
reindexElements();
// always put '+' button on the last modifier row
appendModAddButton();
// remove the 'x' button if only one row is enabled
removeButtonCheck();
});
/********** SAVE ACTION **********/
// moved to spl.js
/********** GENERATE ACTION **********/
activeTab.find('button[id="generate_button"]').live("click", function(){
buttonClickAction('generate', 'new-playlist/smart-block-generate');
});
/********** SHUFFLE ACTION **********/
activeTab.find('button[id="shuffle_button"]').live("click", function(){
buttonClickAction('shuffle', 'new-playlist/smart-block-shuffle');
});
/********** CHANGE PLAYLIST TYPE **********/
form.find('dd[id="sp_type-element"]').live("change", function(){
setupUI();
AIRTIME.library.checkAddButton();
});
/********** CRITERIA CHANGE **********/
form.find('select[id^="sp_criteria"]:not([id^="sp_criteria_modifier"])').live("change", function(){
var index = getRowIndex($(this).parent());
//need to change the criteria value for any modifier rows
var critVal = $(this).val();
var divs = $(this).parent().nextAll(':visible');
$.each(divs, function(i, div){
var critSelect = $(div).children('select[id^="sp_criteria_field"]');
if (critSelect.hasClass('sp-invisible')) {
critSelect.val(critVal);
/* If the select box is visible we know the modifier rows
* have ended
*/
} else {
return false;
}
});
// disable extra field and hide the span
disableAndHideExtraField($(this), index);
populateModifierSelect(this, true);
});
/********** MODIFIER CHANGE **********/
form.find('select[id^="sp_criteria_modifier"]').live("change", function(){
var criteria_value = $(this).next(),
index_num = getRowIndex($(this).parent());
if ($(this).val() == 'is in the range') {
enableAndShowExtraField(criteria_value, index_num);
} else {
disableAndHideExtraField(criteria_value, index_num);
}
});
setupUI();
appendAddButton();
appendModAddButton();
removeButtonCheck();
}
function getRowIndex(ele) {
var id = ele.find('[name^="sp_criteria_field"]').attr('id'),
delimiter = '_',
start = 3,
tokens = id.split(delimiter).slice(start),
index = tokens.join(delimiter);
return index;
}
/* This function appends a '+' button for the last
* modifier row of each criteria.
* If there are no modifier rows, the '+' button
* remains at the criteria row
*/
function appendModAddButton() {
var divs = $('.active-tab .smart-block-form').find('div select[name^="sp_criteria_modifier"]').parent(':visible');
$.each(divs, function(i, div){
if (i > 0) {
/* If the criteria field is hidden we know it is a modifier row
* and can hide the previous row's modifier add button
*/
if ($(div).find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
$(div).prev().find('a[id^="modifier_add"]').addClass('sp-invisible');
} else {
$(div).prev().find('a[id^="modifier_add"]').removeClass('sp-invisible');
}
}
//always add modifier add button to the last row
if (i+1 == divs.length) {
$(div).find('a[id^="modifier_add"]').removeClass('sp-invisible');
}
});
}
/* This function re-indexes all the form elements.
* We need to do this everytime a row gets deleted
*/
function reindexElements() {
var divs = $('.active-tab .smart-block-form').find('div select[name^="sp_criteria_field"]').parent(),
index = 0,
modIndex = 0;
/* Hide all logic labels
* We will re-add them as each row gets indexed
*/
$('.db-logic-label').text('').hide();
$.each(divs, function(i, div){
if (i > 0 && index < 26) {
/* If the current row's criteria field is hidden we know it is
* a modifier row
*/
if ($(div).find('select[name^="sp_criteria_field"]').hasClass('sp-invisible')) {
if ($(div).is(':visible')) {
$(div).prev().find('.db-logic-label').text('or').show();
}
modIndex++;
} else {
if ($(div).is(':visible')) {
$(div).prev().find('.db-logic-label').text('and').show();
}
index++;
modIndex = 0;
}
$(div).find('select[name^="sp_criteria_field"]').attr('name', 'sp_criteria_field_'+index+'_'+modIndex);
$(div).find('select[name^="sp_criteria_field"]').attr('id', 'sp_criteria_field_'+index+'_'+modIndex);
$(div).find('select[name^="sp_criteria_modifier"]').attr('name', 'sp_criteria_modifier_'+index+'_'+modIndex);
$(div).find('select[name^="sp_criteria_modifier"]').attr('id', 'sp_criteria_modifier_'+index+'_'+modIndex);
$(div).find('input[name^="sp_criteria_value"]').attr('name', 'sp_criteria_value_'+index+'_'+modIndex);
$(div).find('input[name^="sp_criteria_value"]').attr('id', 'sp_criteria_value_'+index+'_'+modIndex);
$(div).find('input[name^="sp_criteria_extra"]').attr('name', 'sp_criteria_extra_'+index+'_'+modIndex);
$(div).find('input[name^="sp_criteria_extra"]').attr('id', 'sp_criteria_extra_'+index+'_'+modIndex);
$(div).find('a[name^="modifier_add"]').attr('id', 'modifier_add_'+index);
$(div).find('a[id^="criteria_remove"]').attr('id', 'criteria_remove_'+index+'_'+modIndex);
} else if (i > 0) {
$(div).remove();
}
});
}
function buttonClickAction(clickType, url){
var data = $('.active-tab .smart-block-form').serializeArray(),
obj_id = $('.active-tab .obj_id').val();
enableLoadingIcon();
$.post(url, {format: "json", data: data, obj_id: obj_id}, function(data){
callback(data, clickType);
disableLoadingIcon();
});
}
function setupUI() {
var activeTab = $('.active-tab'),
playlist_type = activeTab.find('input:radio[name=sp_type]:checked').val();
/* Activate or Deactivate shuffle button
* It is only active if playlist is not empty
*/
var sortable = activeTab.find('.spl_sortable'),
plContents = sortable.children(),
shuffleButton = activeTab.find('.sp-button, #pl-bl-clear-content');
if (!plContents.hasClass('spl_empty')) {
if (shuffleButton.hasClass('ui-state-disabled')) {
shuffleButton.removeClass('ui-state-disabled');
shuffleButton.removeAttr('disabled');
}
} else if (!shuffleButton.hasClass('ui-state-disabled')) {
shuffleButton.addClass('ui-state-disabled');
shuffleButton.attr('disabled', 'disabled');
}
if (activeTab.find('.obj_type').val() == 'block') {
if (playlist_type == "0") {
shuffleButton.parent().show();
sortable.show();
} else {
shuffleButton.parent().hide();
sortable.hide();
}
}
$(".playlist_type_help_icon").qtip({
content: {
text: $.i18n._("A static smart block will save the criteria and generate the block content immediately. This allows you to edit and view it in the Library before adding it to a show.")+"<br /><br />" +
$.i18n._("A dynamic smart block will only save the criteria. The block content will get generated upon adding it to a show. You will not be able to view and edit the content in the Library.")
},
hide: {
delay: 500,
fixed: true
},
style: {
border: {
width: 0,
radius: 4
},
classes: "ui-tooltip-dark ui-tooltip-rounded"
},
position: {
my: "left bottom",
at: "right center"
}
});
$(".repeat_tracks_help_icon").qtip({
content: {
text: sprintf($.i18n._("The desired block length will not be reached if %s cannot find enough unique tracks to match your criteria. Enable this option if you wish to allow tracks to be added multiple times to the smart block."), PRODUCT_NAME)
},
hide: {
delay: 500,
fixed: true
},
style: {
border: {
width: 0,
radius: 4
},
classes: "ui-tooltip-dark ui-tooltip-rounded"
},
position: {
my: "left bottom",
at: "right center"
}
});
}
function enableAndShowExtraField(valEle, index) {
var spanExtra = valEle.nextAll("#extra_criteria");
spanExtra.children('#sp_criteria_extra_'+index).removeAttr("disabled");
spanExtra.show();
//make value input smaller since we have extra element now
var criteria_val = $('#sp_criteria_value_'+index);
sizeTextBoxes(criteria_val, 'sp_input_text', 'sp_extra_input_text');
}
function disableAndHideExtraField(valEle, index) {
var spanExtra = valEle.nextAll("#extra_criteria");
spanExtra.children('#sp_criteria_extra_'+index).val("").attr("disabled", "disabled");
spanExtra.hide();
//make value input larger since we don't have extra field now
var criteria_value = $('#sp_criteria_value_'+index);
sizeTextBoxes(criteria_value, 'sp_extra_input_text', 'sp_input_text');
}
function sizeTextBoxes(ele, classToRemove, classToAdd) {
if (ele.hasClass(classToRemove)) {
ele.removeClass(classToRemove).addClass(classToAdd);
}
}
function populateModifierSelect(e, popAllMods) {
var criteria_type = getCriteriaOptionType(e),
index = getRowIndex($(e).parent()),
divs;
if (popAllMods) {
index = index.substring(0, 1);
}
divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+index+'"]');
$.each(divs, function(i, div){
$(div).children().remove();
if (criteria_type == 's') {
$.each(stringCriteriaOptions, function(key, value){
$(div).append($('<option></option>')
.attr('value', key)
.text(value));
});
} else {
$.each(numericCriteriaOptions, function(key, value){
$(div).append($('<option></option>')
.attr('value', key)
.text(value));
});
}
});
}
function getCriteriaOptionType(e) {
var criteria = $(e).val();
return criteriaTypes[criteria];
}
function callback(json, type) {
var dt = $('table[id="library_display"]').dataTable(),
form = $('.active-tab .smart-block-form');
if (type == 'shuffle' || type == 'generate') {
if (json.error !== undefined) {
alert(json.error);
}
AIRTIME.playlist.closeTab();
AIRTIME.playlist.fnOpenPlaylist(json);
if (json.result == "0") {
if (type == 'shuffle') {
form.find('.success').text($.i18n._('Smart block shuffled'));
} else if (type == 'generate') {
form.find('.success').text($.i18n._('Smart block generated and criteria saved'));
//redraw library table so the length gets updated
dt.fnStandingRedraw();
}
form.find('.success').show();
}
form.find('#smart_block_options').removeClass("closed");
} else {
AIRTIME.playlist.closeTab();
AIRTIME.playlist.fnOpenPlaylist(json);
if (json.result == "0") {
$('.active-tab #sp-success-saved').text($.i18n._('Smart block saved')).show();
//redraw library table so the length gets updated
dt.fnStandingRedraw();
}
form.find('#smart_block_options').removeClass("closed");
}
setTimeout(removeSuccessMsg, 5000);
}
function appendAddButton() {
var add_button = "<a class='btn btn-small' id='criteria_add'>" +
"<i class='icon-white icon-plus'></i></a>";
var rows = $('.active-tab #smart_block_options'),
enabled = rows.find('select[name^="sp_criteria_field"]:enabled');
rows.find('#criteria_add').remove();
if (enabled.length > 1) {
rows.find('select[name^="sp_criteria_field"]:enabled:last')
.siblings('a[id^="criteria_remove"]')
.after(add_button);
} else {
enabled.siblings('span[id="extra_criteria"]')
.after(add_button);
}
}
function removeButtonCheck() {
var rows = $('.active-tab dd[id="sp_criteria-element"]').children('div'),
enabled = rows.find('select[name^="sp_criteria_field"]:enabled'),
rmv_button = enabled.siblings('a[id^="criteria_remove"]');
if (enabled.length == 1) {
rmv_button.attr('disabled', 'disabled');
rmv_button.hide();
} else {
rmv_button.removeAttr('disabled');
rmv_button.show();
}
}
function enableLoadingIcon() {
$(".side_playlist.active-tab").block({
message: $.i18n._("Processing..."),
theme: true,
allowBodyStretch: true,
applyPlatformOpacityRules: false
});
}
function disableLoadingIcon() {
$(".side_playlist.active-tab").unblock()
}
// We need to know if the criteria value will be a string
// or numeric value in order to populate the modifier
// select list
var criteriaTypes = {
0 : "",
"album_title" : "s",
"bit_rate" : "n",
"bpm" : "n",
"composer" : "s",
"conductor" : "s",
"copyright" : "s",
"cuein" : "n",
"cueout" : "n",
"artist_name" : "s",
"encoded_by" : "s",
"utime" : "n",
"mtime" : "n",
"lptime" : "n",
"genre" : "s",
"isrc_number" : "s",
"label" : "s",
"language" : "s",
"length" : "n",
"mime" : "s",
"mood" : "s",
"owner_id" : "s",
"replay_gain" : "n",
"sample_rate" : "n",
"track_title" : "s",
"track_number" : "n",
"info_url" : "s",
"year" : "n"
};
var stringCriteriaOptions = {
"0" : $.i18n._("Select modifier"),
"contains" : $.i18n._("contains"),
"does not contain" : $.i18n._("does not contain"),
"is" : $.i18n._("is"),
"is not" : $.i18n._("is not"),
"starts with" : $.i18n._("starts with"),
"ends with" : $.i18n._("ends with")
};
var numericCriteriaOptions = {
"0" : $.i18n._("Select modifier"),
"is" : $.i18n._("is"),
"is not" : $.i18n._("is not"),
"is greater than" : $.i18n._("is greater than"),
"is less than" : $.i18n._("is less than"),
"is in the range" : $.i18n._("is in the range")
};

View file

@ -331,7 +331,7 @@ function reindexElements() {
function buttonClickAction(clickType, url){
var data = $('#smart-block-form').serializeArray(),
obj_id = $('input[id="obj_id"]').val();
obj_id = $('.obj_id').val();
enableLoadingIcon();
$.post(url, {format: "json", data: data, obj_id: obj_id}, function(data){

View file

@ -584,7 +584,7 @@ var AIRTIME = (function(AIRTIME){
$node.empty();
}
sSeparatorHTML = '<span>'+$.i18n._("Show Empty")+'</span>';
sSeparatorHTML = '<span>'+$.i18n._("Drag tracks here from the library")+'</span>';
cl = cl + " sb-empty odd";
fnPrepareSeparatorRow(sSeparatorHTML, cl, 1);
@ -773,12 +773,12 @@ var AIRTIME = (function(AIRTIME){
"sAjaxDataProp": "schedule",
"oLanguage": datatables_dict,
"sAjaxSource": baseUrl+"showbuilder/builder-feed" ,
"sAjaxSource": baseUrl+"showbuilder/builder-feed",
"bScrollCollapseY": false
});
$sbTable.find("tbody").on("mousedown", "tr:not(.sb-past, .sb-empty)", function(ev) {
$sbTable.find("tbody").on("mousedown", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) {
var $tr = $(this),
// Get the ID of the selected row
$rowId = $tr.attr("id");
@ -814,7 +814,7 @@ var AIRTIME = (function(AIRTIME){
$previouslySelected = $tr;
});
$sbTable.find("tbody").on("click", "tr:not(.sb-past, .sb-empty)", function(ev) {
$sbTable.find("tbody").on("click", "tr:not(.sb-header, .sb-footer, .sb-past, .sb-empty, :has(td.dataTables_empty))", function(ev) {
if (flagForDeselection) {
flagForDeselection = false;
$(this).removeClass(SB_SELECTED_CLASS);

View file

@ -165,8 +165,10 @@ AIRTIME = (function(AIRTIME) {
$builder = $("#show_builder");
$fs = $builder.find('fieldset');
$("#timeline-tab").on("click", function() {
AIRTIME.showbuilder.switchTab($("#show_builder .outer-datatable-wrapper"), $(this));
$("#schedule-tab").on("click", function() {
if (!$(this).hasClass('active')) {
AIRTIME.showbuilder.switchTab($("#show_builder .outer-datatable-wrapper"), $(this));
}
});
/*