Merge branch 'cc-5709-airtime-analyzer' into cc-5709-airtime-analyzer-saas
Conflicts: airtime_mvc/public/index.php * Reverted some SaaS-only thing Martin did a year ago. Looks benign but only one way to find out...
This commit is contained in:
commit
1c5e2d6205
59 changed files with 1851 additions and 140 deletions
|
@ -1,12 +1,24 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
var uploader;
|
||||
var self = this;
|
||||
self.uploadFilter = "all";
|
||||
|
||||
self.IMPORT_STATUS_CODES = {
|
||||
0 : { message: $.i18n._("Successfully imported")},
|
||||
1 : { message: $.i18n._("Pending import")},
|
||||
2 : { message: $.i18n._("Import failed.")},
|
||||
UNKNOWN : { message: $.i18n._("Unknown")}
|
||||
};
|
||||
if (Object.freeze) {
|
||||
Object.freeze(self.IMPORT_STATUS_CODES);
|
||||
}
|
||||
|
||||
$("#plupload_files").pluploadQueue({
|
||||
// General settings
|
||||
runtimes : 'gears, html5, html4',
|
||||
url : baseUrl+'Plupload/upload/format/json',
|
||||
chunk_size : '5mb',
|
||||
url : baseUrl+'rest/media',
|
||||
//chunk_size : '5mb', //Disabling chunking since we're using the File Upload REST API now
|
||||
unique_names : 'true',
|
||||
multiple_queues : 'true',
|
||||
filters : [
|
||||
|
@ -16,37 +28,17 @@ $(document).ready(function() {
|
|||
|
||||
uploader = $("#plupload_files").pluploadQueue();
|
||||
|
||||
uploader.bind('FileUploaded', function(up, file, json) {
|
||||
var j = jQuery.parseJSON(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{
|
||||
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");
|
||||
}
|
||||
});
|
||||
}
|
||||
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 uploadProgress = false;
|
||||
|
||||
uploader.bind('QueueChanged', function(){
|
||||
uploadProgress = (uploader.files.length > 0)
|
||||
uploadProgress = (uploader.files.length > 0);
|
||||
});
|
||||
|
||||
uploader.bind('UploadComplete', function(){
|
||||
|
@ -59,5 +51,140 @@ $(document).ready(function() {
|
|||
"\n", "\n");
|
||||
}
|
||||
});
|
||||
|
||||
self.renderImportStatus = function ( data, type, full ) {
|
||||
if (typeof data !== "number") {
|
||||
console.log("Invalid data type for the import_status.");
|
||||
return;
|
||||
}
|
||||
var statusStr = self.IMPORT_STATUS_CODES.UNKNOWN.message;
|
||||
var importStatusCode = data;
|
||||
if (self.IMPORT_STATUS_CODES[importStatusCode]) {
|
||||
statusStr = self.IMPORT_STATUS_CODES[importStatusCode].message;
|
||||
};
|
||||
|
||||
return statusStr;
|
||||
};
|
||||
|
||||
self.renderFileActions = function ( data, type, full ) {
|
||||
if (full.import_status == 0) {
|
||||
return '<a class="deleteFileAction">' + $.i18n._('Delete from Library') + '</a>';
|
||||
} else if (full.import_status == 1) {
|
||||
//No actions for pending files
|
||||
return $.i18n._('N/A');
|
||||
} else { //Failed downloads
|
||||
return '<a class="deleteFileAction">' + $.i18n._('Clear') + '</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() {
|
||||
recentUploadsTable = $("#recent_uploads_table").dataTable({
|
||||
"bJQueryUI": true,
|
||||
"bProcessing": false,
|
||||
"bServerSide": true,
|
||||
"sAjaxSource": '/Plupload/recent-uploads/format/json',
|
||||
"sAjaxDataProp": 'files',
|
||||
"bSearchable": false,
|
||||
"bInfo": true,
|
||||
//"sScrollY": "200px",
|
||||
"bFilter": false,
|
||||
"bSort": false,
|
||||
"sDom": '<"H"l>frtip',
|
||||
"bPaginate" : true,
|
||||
"sPaginationType": "full_numbers",
|
||||
"aoColumns": [
|
||||
{ "mData" : "artist_name", "sTitle" : $.i18n._("Creator") },
|
||||
{ "mData" : "track_title", "sTitle" : $.i18n._("Title") },
|
||||
{ "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);
|
||||
if (json.files) {
|
||||
var areAnyFileImportsPending = false;
|
||||
for (var i = 0; i < json.files.length; i++) {
|
||||
//console.log(file);
|
||||
var file = json.files[i];
|
||||
if (file.import_status == 1)
|
||||
{
|
||||
areAnyFileImportsPending = true;
|
||||
}
|
||||
}
|
||||
if (areAnyFileImportsPending) {
|
||||
//alert("pending uploads, starting refresh on timer");
|
||||
self.startRefreshingRecentUploads();
|
||||
} else {
|
||||
self.stopRefreshingRecentUploads();
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
});
|
||||
|
||||
return recentUploadsTable;
|
||||
};
|
||||
|
||||
self.startRefreshingRecentUploads = function()
|
||||
{
|
||||
if (self.isRecentUploadsRefreshTimerActive()) { //Prevent multiple timers from running
|
||||
return;
|
||||
}
|
||||
self.recentUploadsRefreshTimer = setInterval("self.recentUploadsTable.fnDraw()", 3000);
|
||||
};
|
||||
|
||||
self.isRecentUploadsRefreshTimerActive = function()
|
||||
{
|
||||
return (self.recentUploadsRefreshTimer != null);
|
||||
};
|
||||
|
||||
self.stopRefreshingRecentUploads = function()
|
||||
{
|
||||
clearInterval(self.recentUploadsRefreshTimer);
|
||||
self.recentUploadsRefreshTimer = null;
|
||||
};
|
||||
|
||||
$("#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>');
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue