CC-5709: Airtime Analyzer

* A bunch of changes that somehow didn't make it into my last commit...
* confused
This commit is contained in:
Albert Santoni 2014-03-21 14:03:17 -04:00
parent f120caa093
commit 8f7ecafcf6
14 changed files with 212 additions and 109 deletions

View file

@ -2,11 +2,11 @@ $(document).ready(function() {
var uploader;
var self = this;
self.uploadFilter = "all";
$("#plupload_files").pluploadQueue({
// General settings
runtimes : 'gears, html5, html4',
//url : baseUrl+'Plupload/upload/format/json',
url : baseUrl+'rest/media',
//chunk_size : '5mb', //Disabling chunking since we're using the File Upload REST API now
unique_names : 'true',
@ -18,43 +18,11 @@ $(document).ready(function() {
uploader = $("#plupload_files").pluploadQueue();
uploader.bind('FileUploaded', function(up, file, json) {
var j = jQuery.parseJSON(json.response);
console.log(j);
console.log(file.name);
uploader.bind('FileUploaded', function(up, file, json)
{
//Refresh the upload table:
self.recentUploadsTable.fnDraw(); //Only works because we're using bServerSide
//In DataTables 1.10 and greater, we can use .fnAjaxReload()
/*
var j = jQuery.parseJSON(json.response);
console.log(json.response);
if (j.error !== undefined) {
var row = $("<tr/>")
.append('<td>' + file.name +'</td>')
.append('<td>' + j.error.message + '</td>');
$("#plupload_error").find("table").append(row);
$("#plupload_error table").css("display", "inline-table");
} else {
//FIXME: This should just update something in the GUI, not communicate with the backend -- Albert
/*
var tempFileName = j.tempfilepath;
$.get(baseUrl+'Plupload/copyfile/format/json/name/'+
encodeURIComponent(file.name)+'/tempname/' +
encodeURIComponent(tempFileName), function(jr){
if(jr.error !== undefined) {
var row = $("<tr/>")
.append('<td>' + file.name +'</td>')
.append('<td>' + jr.error.message + '</td>');
$("#plupload_error").find("table").append(row);
$("#plupload_error table").css("display", "inline-table");
}
});
}*/
});
var uploadProgress = false;
@ -74,8 +42,49 @@ $(document).ready(function() {
}
});
self.renderImportStatus = function ( data, type, full ) {
if (typeof data !== "number") {
console.log("Invalid data type for the import_status.");
return;
}
var statusStr = $.i18n._("Unknown");
if (data == 0)
{
statusStr = $.i18n._("Successfully imported");
}
else if (data == 1)
{
statusStr = $.i18n._("Pending import");
}
return statusStr;
};
self.renderFileActions = function ( data, type, full ) {
return '<a class="deleteFileAction">Delete</a>';
};
$("#recent_uploads_table").on("click", "a.deleteFileAction", function () {
//Grab the file object for the row that was clicked.
// Some tips from the DataTables forums:
// fnGetData is used to get the object behind the row - you can also use
// fnGetPosition if you need to get the index instead
file = $("#recent_uploads_table").dataTable().fnGetData($(this).closest("tr")[0]);
$.ajax({
type: 'DELETE',
url: '/rest/media/' + file.id,
success: function(resp) {
self.recentUploadsTable.fnDraw();
},
error: function() {
alert($.i18n._("Error: The file could not be deleted. Please try again later."));
}
});
});
self.setupRecentUploadsTable = function() {
return recentUploadsTable = $("#recent_uploads_table").dataTable({
recentUploadsTable = $("#recent_uploads_table").dataTable({
"bJQueryUI": true,
"bProcessing": false,
"bServerSide": true,
@ -83,7 +92,7 @@ $(document).ready(function() {
"sAjaxDataProp": 'files',
"bSearchable": false,
"bInfo": true,
"sScrollY": "200px",
//"sScrollY": "200px",
"bFilter": false,
"bSort": false,
"sDom": '<"H"l>frtip',
@ -92,13 +101,41 @@ $(document).ready(function() {
"aoColumns": [
{ "mData" : "artist_name", "sTitle" : $.i18n._("Creator") },
{ "mData" : "track_title", "sTitle" : $.i18n._("Title") },
{ "mData" : "state", "sTitle" : $.i18n._("Import Status")},
{ "mData" : "utime", "sTitle" : $.i18n._("Uploaded") }
]
{ "mData" : "import_status", "sTitle" : $.i18n._("Import Status"),
"mRender": self.renderImportStatus
},
{ "mData" : "utime", "sTitle" : $.i18n._("Uploaded") },
{ "mData" : "id", "sTitle" : $.i18n._("Actions"),
"mRender": self.renderFileActions
}
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "name": "uploadFilter", "value": self.uploadFilter } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
} );
}
});
return recentUploadsTable;
};
$("#upload_status_all").click(function() {
self.uploadFilter = "all";
self.recentUploadsTable.fnDraw();
});
$("#upload_status_pending").click(function() {
self.uploadFilter = "pending";
self.recentUploadsTable.fnDraw();
});
$("#upload_status_failed").click(function() {
self.uploadFilter = "failed";
self.recentUploadsTable.fnDraw();
});
//Create the recent uploads table.
self.recentUploadsTable = self.setupRecentUploadsTable();
$("#recent_uploads_table.div.fg-toolbar").prepend('<b>Custom tool bar! Text/images etc.</b>');
//$("#recent_uploads_table.div.fg-toolbar").prepend('<b>Custom tool bar! Text/images etc.</b>');
});