CC-3174 : showbuilder

mostly done with new context menu, need to finish
add/delete button actions on lib table for both screens.
This commit is contained in:
Naomi Aro 2012-02-05 18:19:22 +01:00
parent da5e1ac302
commit 6c2475bf1f
9 changed files with 305 additions and 424 deletions

View file

@ -1,66 +0,0 @@
function addRemove(el) {
var id, span;
id = $(el).attr("id").split("_").pop();
span = $('<a href="#" id="search_remove_'+id+'" class="ui-button ui-button-icon-only ui-widget ui-state-default"><span class="ui-icon ui-icon-closethick"></span><span class="ui-button-text">Remove</span></a>').click(function(){
$(this).parent().parent().remove();
});
$(el).find("dl input").after(span);
}
function ajaxAddRow() {
var group_id;
group_id = $(this).parent().parent().attr("id").split("_").pop();
var url = '/Search/newfield/format/json';
$.post(url, {group: group_id}, function(json) {
var newRow = $(json.html).find("#fieldset-row_"+json.row);
addRemove(newRow);
$("#fieldset-group_"+group_id+" dl:first").append(newRow);
});
}
function removeGroup() {
$(this).parent().parent().remove();
}
function ajaxAddGroup() {
var url = '/Search/newgroup/format/json';
$.post(url, function(json) {
var group = $(json.html);
addRemove(group);
group.find('[id$="search_add_row"]').click(ajaxAddRow);
group.find('[id$="search_remove_group"]').click(removeGroup);
$(".zend_form").append(group);
});
}
function advancedSearchSubmit() {
var data = $("#advancedSearch form").serializeArray();
$.post("/Search/index", {format: "json", data: data}, function(json){
var x;
});
}
$(document).ready(function() {
$("#search_add_group").click(ajaxAddGroup);
$("#search_submit").click(advancedSearchSubmit);
$('[id$="search_add_row"]').click(ajaxAddRow);
$('[id$="search_remove_group"]').click(removeGroup);
$('[id^="fieldset-row_"]').each(function(i, el){
addRemove(el);
});
});

View file

@ -1,61 +1,67 @@
function fnLibraryTableRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var AIRTIME = (function(AIRTIME){
var mod;
if (AIRTIME.library === undefined) {
AIRTIME.library = {}
}
AIRTIME.library.events = {};
mod = AIRTIME.library.events;
mod.fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var $nRow = $(nRow);
$nRow.attr("id", aData["tr_id"])
.data("aData", aData)
.data("screen", "playlist");
}
mod.fnDrawCallback = function() {
$('#library_display tr[id ^= "au"]').draggable({
helper: 'clone',
/* customize the helper on dragging to look like a pl item
*
helper: function(ev) {
var data, li;
data = $(ev.currentTarget).data("aData");
li = $("<li></li>");
li.append(data.track_title);
return li;
},
*/
cursor: 'pointer',
connectToSortable: '#spl_sortable'
});
}
/*
* @param oTable the datatables instance for the library.
*/
mod.setupLibraryToolbar = function( oLibTable ) {
var aButtons,
fnResetCol;
fnResetCol = function () {
ColReorder.fnReset( oLibTable );
return false;
};
//[0] = button text
//[1] = id
//[2] = enabled
//[3] = click event
aButtons = [["Reset Order", "library_order_reset", true, fnResetCol],
["Delete", "library_group_delete", true],
["Add", "library_group_add", true]];
addToolBarButtonsLibrary(aButtons);
}
$(nRow).attr("id", aData["tr_id"]);
$(nRow).data("aData", aData);
//var oTT = TableTools.fnGetInstance('library_display');
//oTT.fnSelect(el);
/*
$(nRow).find('td')
.jjmenu("rightClick",
[{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}],
{id: aData["id"], type: aData["ftype"]},
{xposition: "mouse", yposition: "mouse"});
*/
}
function fnLibraryTableDrawCallback() {
return AIRTIME;
$('#library_display tr[id ^= "au"]').draggable({
helper: 'clone',
/*
helper: function(ev) {
var data, li;
data = $(ev.currentTarget).data("aData");
li = $("<li></li>");
li.append(data.track_title);
return li;
},
*/
cursor: 'pointer',
connectToSortable: '#spl_sortable'
});
}
/*
* @param oTable the datatables instance for the library.
*/
function setupLibraryToolbar(oLibTable) {
var aButtons,
oLibTT = TableTools.fnGetInstance('library_display'),
fnResetCol;
fnResetCol = function () {
ColReorder.fnReset( oLibTable );
return false;
};
//[0] = button text
//[1] = id
//[2] = enabled
//[3] = click event
aButtons = [["Reset Order", "library_order_reset", true, fnResetCol],
["Delete", "library_group_delete", true],
["Add", "library_group_add", true]];
addToolBarButtonsLibrary(aButtons);
}
}(AIRTIME || {}));

View file

@ -1,80 +1,92 @@
function fnLibraryTableRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var jRow = $(nRow);
var AIRTIME = (function(AIRTIME){
var mod;
jRow.attr("id", aData["tr_id"]);
jRow.addClass("lib-sb");
//save some info for reordering purposes.
jRow.data({"aData": aData});
}
function fnLibraryTableDrawCallback() {
if (AIRTIME.library === undefined) {
AIRTIME.library = {}
}
$('#library_display tr:not(:first)').draggable({
helper: 'clone',
cursor: 'pointer',
connectToSortable: '#show_builder_table'
});
}
function setupLibraryToolbar(oLibTable) {
var aButtons,
fnTest,
fnResetCol,
fnAddSelectedItems,
oSchedTable = $("#show_builder_table").dataTable(),
oLibTT = TableTools.fnGetInstance('library_display'),
oSchedTT = TableTools.fnGetInstance('show_builder_table');
AIRTIME.library.events = {};
mod = AIRTIME.library.events;
fnTest = function() {
alert("hi");
};
fnResetCol = function () {
ColReorder.fnReset( oLibTable );
return false;
};
fnAddSelectedItems = function() {
var aData = oLibTT.fnGetSelectedData(),
item,
temp,
aMediaIds = [],
aSchedIds = [];
mod.fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var $nRow = $(nRow);
//process selected files/playlists.
for (item in aData) {
temp = aData[item];
if (temp !== null && temp.hasOwnProperty('id')) {
aMediaIds.push({"id": temp.id, "type": temp.ftype});
}
}
$nRow.attr("id", aData["tr_id"])
.data("aData", aData)
.data("screen", "timeline");
}
aData = oSchedTT.fnGetSelectedData();
mod.fnDrawCallback = function() {
//process selected schedule rows to add media after.
for (item in aData) {
temp = aData[item];
if (temp !== null && temp.hasOwnProperty('id')) {
aSchedIds.push({"id": temp.id, "instance": temp.instance});
}
}
$.post("/showbuilder/schedule-add",
{"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds},
function(json){
oLibTT.fnSelectNone();
oSchedTT.fnSelectNone();
oSchedTable.fnDraw();
});
};
//[0] = button text
//[1] = id
//[2] = enabled
//[3] = click event
aButtons = [["Reset Order", "library_order_reset", true, fnResetCol],
["Delete", "library_group_delete", true, fnTest],
["Add", "library_group_add", true, fnAddSelectedItems]];
$('#library_display tr:not(:first)').draggable({
helper: 'clone',
cursor: 'pointer',
connectToSortable: '#show_builder_table'
});
}
addToolBarButtonsLibrary(aButtons);
}
mod.setupLibraryToolbar = function(oLibTable) {
var aButtons,
fnTest,
fnResetCol,
fnAddSelectedItems,
fnTest = function() {
alert("hi");
};
fnResetCol = function () {
ColReorder.fnReset( oLibTable );
return false;
};
fnAddSelectedItems = function() {
var aData = oLibTT.fnGetSelectedData(),
item,
temp,
aMediaIds = [],
aSchedIds = [],
oSchedTable = $("#show_builder_table").dataTable(),
oLibTT = TableTools.fnGetInstance('library_display'),
oSchedTT = TableTools.fnGetInstance('show_builder_table');;
//process selected files/playlists.
for (item in aData) {
temp = aData[item];
if (temp !== null && temp.hasOwnProperty('id')) {
aMediaIds.push({"id": temp.id, "type": temp.ftype});
}
}
aData = oSchedTT.fnGetSelectedData();
//process selected schedule rows to add media after.
for (item in aData) {
temp = aData[item];
if (temp !== null && temp.hasOwnProperty('id')) {
aSchedIds.push({"id": temp.id, "instance": temp.instance});
}
}
$.post("/showbuilder/schedule-add",
{"format": "json", "mediaIds": aMediaIds, "schedIds": aSchedIds},
function(json){
oLibTT.fnSelectNone();
oSchedTT.fnSelectNone();
oSchedTable.fnDraw();
});
};
//[0] = button text
//[1] = id
//[2] = enabled
//[3] = click event
aButtons = [["Reset Order", "library_order_reset", true, fnResetCol],
["Delete", "library_group_delete", true, fnTest],
["Add", "library_group_add", true, fnAddSelectedItems]];
addToolBarButtonsLibrary(aButtons);
}
return AIRTIME;
}(AIRTIME || {}));

View file

@ -37,39 +37,6 @@ function disableGroupBtn(btnId) {
}
}
function deleteItem(type, id) {
var tr_id, tr, dt;
tr_id = type+"_"+id;
tr = $("#"+tr_id);
dt = $("#library_display").dataTable();
dt.fnDeleteRow( tr );
}
function deleteAudioClip(json) {
if(json.message) {
alert(json.message);
return;
}
if (json.ids != undefined) {
for (var i = json.ids.length - 1; i >= 0; i--) {
deleteItem("au", json.ids[i]);
}
}
else if (json.id != undefined) {
deleteItem("au", json.id);
}
location.reload(true);
}
function confirmDeleteGroup() {
if(confirm('Are you sure you want to delete the selected items?')){
groupDelete();
}
}
function checkImportStatus(){
$.getJSON('/Preference/is-import-in-progress', function(data){
var div = $('#import_status');
@ -81,40 +48,41 @@ function checkImportStatus(){
});
}
function deletePlaylist(json) {
if(json.message) {
alert(json.message);
return;
}
if (json.ids != undefined) {
for (var i = json.ids.length - 1; i >= 0; i--) {
deleteItem("pl", json.ids[i]);
}
} else if (json.id != undefined) {
deleteItem("pl", json.id);
}
window.location.reload();
}
function addProgressIcon(id) {
if($("#au_"+id).find("td.library_title").find("span").length > 0){
$("#au_"+id).find("td.library_title").find("span").removeClass();
$("span[id="+id+"]").addClass("small-icon progress");
}else{
$("#au_"+id).find("td.library_title").append('<span id="'+id+'" class="small-icon progress"></span>');
var tr = $("#au_"+id),
span;
span = tr.find("td.library_title").find("span");
if (span.length > 0){
span.removeClass()
.addClass("small-icon progress");
}
else{
tr.find("td.library_title")
.append('<span class="small-icon progress"></span>');
}
}
function checkSCUploadStatus(){
var url = '/Library/get-upload-to-soundcloud-status/format/json';
var url = '/Library/get-upload-to-soundcloud-status';
$("span[class*=progress]").each(function(){
var id = $(this).attr("id");
var span, id;
span = $(this);
id = span.parentsUntil('tr').attr("id").split("_").pop();
$.post(url, {format: "json", id: id, type:"file"}, function(json){
if(json.sc_id > 0){
$("span[id="+id+"]").removeClass("progress").addClass("soundcloud");
}else if(json.sc_id == "-3"){
$("span[id="+id+"]").removeClass("progress").addClass("sc-error");
if (json.sc_id > 0) {
span.removeClass("progress")
.addClass("soundcloud");
}
else if (json.sc_id == "-3") {
span.removeClass("progress")
.addClass("sc-error");
}
});
});
@ -280,10 +248,9 @@ function createDataTable(data) {
"success": testCallback
} );
},
"fnRowCallback": fnLibraryTableRowCallback,
"fnRowCallback": AIRTIME.library.events.fnRowCallback,
"fnCreatedRow": fnCreatedRow,
"fnCreatedRowCallback": fnCreatedRow,
"fnDrawCallback": fnLibraryTableDrawCallback,
"fnDrawCallback": AIRTIME.library.events.fnDrawCallback,
"fnHeaderCallback": function(nHead) {
$(nHead).find("input[type=checkbox]").attr("checked", false);
},
@ -353,7 +320,7 @@ function createDataTable(data) {
});
oTable.fnSetFilteringDelay(350);
setupLibraryToolbar(oTable);
AIRTIME.library.events.setupLibraryToolbar(oTable);
$('[name="pl_cb_all"]').click(function(){
var oTT = TableTools.fnGetInstance('library_display');
@ -385,9 +352,11 @@ $(document).ready(function() {
ignoreRightClick: true,
build: function($el, e) {
var x, request, data, items, callback;
var x, request, data, screen, items, callback, $tr;
data = $el.parent().data("aData");
$tr = $el.parent();
data = $tr.data("aData");
screen = $tr.data("screen");
function processMenuItems(oItems) {
@ -400,11 +369,46 @@ $(document).ready(function() {
};
}
else {
callback = function() {
AIRTIME.playlist.fnEdit(data.id);
};
}
oItems.edit.callback = callback;
}
//define a delete callback.
if (oItems.del !== undefined) {
//delete through the playlist controller, will reset
//playlist screen if this is the currently edited playlist.
if (data.ftype === "playlist" && screen === "playlist") {
callback = function() {
if (confirm('Are you sure you want to delete the selected item?')) {
AIRTIME.playlist.fnDelete(data.id);
}
};
}
else {
callback = function() {
var media = [];
if (confirm('Are you sure you want to delete the selected item?')) {
media.push({"id": data.id, "type": data.ftype});
$.post(oItems.del.url, {format: "json", media: media }, function(json){
var oTable, tr;
oTable = $("#library_display").dataTable();
oTable.fnDeleteRow( $tr[0] );
});
}
};
}
oItems.del.callback = callback;
}
//define a download callback.
if (oItems.download !== undefined) {
@ -444,7 +448,7 @@ $(document).ready(function() {
request = $.ajax({
url: "/library/context-menu",
type: "GET",
data: {id : data.id, type: data.ftype, format: "json"},
data: {id : data.id, type: data.ftype, format: "json", "screen": screen},
dataType: "json",
async: false,
success: function(json){
@ -452,16 +456,7 @@ $(document).ready(function() {
}
});
// this callback is executed every time the menu is to be shown
// its results are destroyed every time the menu is hidden
// e is the original contextmenu event, containing e.pageX and e.pageY (amongst other data)
return {
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: items,
determinePosition : function($menu, x, y) {
$menu.css('display', 'block')

View file

@ -538,15 +538,26 @@ var AIRTIME = (function(AIRTIME){
});
}
mod.fnEdit = function() {
mod.fnEdit = function(id) {
var url;
stopAudioPreview();
url = '/Playlist/edit';
$.post(url,
{format: "json", id: id},
function(json){
openPlaylist(json);
//redrawLib();
});
}
mod.fnDelete = function() {
mod.fnDelete = function(plid) {
var url, id, lastMod;
stopAudioPreview();
id = getId();
id = (plid === undefined) ? getId() : plid;
lastMod = getModified();
url = '/Playlist/delete';