sintonia/public/js/airtime/library/library.js

96 lines
1.9 KiB
JavaScript

function getId() {
var tr_id = $(this.triggerElement).attr("id");
tr_id = tr_id.split("_");
return tr_id[1];
}
function getType() {
var tr_id = $(this.triggerElement).attr("id");
tr_id = tr_id.split("_");
return tr_id[0];
}
function deleteItem(type, id) {
var tr_id;
tr_id = type+"_"+id;
$("#library_display tr#" +tr_id).remove();
}
function deleteAudioClip(json) {
if(json.message) {
alert(json.message);
return;
}
deleteItem("au", json.id);
}
function deletePlaylist(json) {
if(json.message) {
alert(json.message);
return;
}
deleteItem("pl", json.id);
}
function addLibraryItemEvents() {
$('#library_display tr[id ^= "au"]')
.draggable({
helper: 'clone'
});
$('#library_display tr:not(:first-child)')
.jjmenu("rightClick",
[{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}],
{id: getId, type: getType},
{xposition: "mouse", yposition: "mouse"});
}
function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var id = aData[6].substring(0,2) + "_" + aData[0];
$(nRow).attr("id", id);
return nRow;
}
function dtDrawCallback() {
addLibraryItemEvents();
}
function setUpLibrary() {
$('#library_display').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Library/contents/format/json",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
},
"fnRowCallback": dtRowCallback,
"fnDrawCallback": dtDrawCallback,
"aoColumns": [
/* Id */ { "sName": "id", "bSearchable": false, "bVisible": false },
/* Title */ { "sName": "track_title" },
/* Creator */ { "sName": "artist_name" },
/* Album */ { "sName": "album_title" },
/* Track */ { "sName": "track_number" },
/* Length */ { "sName": "length" },
/* Type */ { "sName": "type" }
]
} );
}