SAAS-1184 - bugfixes and polish

This commit is contained in:
Duncan Sommerville 2015-11-10 15:10:36 -05:00
parent f352b61707
commit bb7f8c1ed3
10 changed files with 105 additions and 24 deletions

View file

@ -1255,7 +1255,9 @@ var AIRTIME = (function(AIRTIME) {
* @param table the table to show
*/
mod.setCurrentTable = function (table) {
if (oTable) oTable.fnClearTable();
if (oTable && oTable === $datatables[mod.DataTableTypeEnum.PODCAST_EPISODES]) {
oTable.fnClearTable();
}
var dt = $datatables[table],
wrapper = $(dt).closest(".dataTables_wrapper");
$("#library_content").find(".dataTables_wrapper").hide();
@ -1718,8 +1720,9 @@ var validationTypes = {
$(document).ready(function() {
AIRTIME.library.initPodcastDatatable();
if (window.location.href.indexOf("showbuilder") > -1) {
AIRTIME.library.initPodcastDatatable();
}
$("#advanced-options").on("click", function() {
resizeAdvancedSearch();

View file

@ -146,10 +146,21 @@ var AIRTIME = (function (AIRTIME) {
* Sets up the internal datatable.
*/
PodcastController.prototype.initialize = function() {
var self = this;
// TODO: this solves a race condition, but we should look for the root cause
AIRTIME.tabs.onResize();
this.$scope.tab.setName(this.$scope.podcast.title);
this._initTable();
self.$scope.tab.setName(self.$scope.podcast.title);
self._initTable();
// Add an onclose hook to the tab to remove the table object and the
// import listener so we don't cause memory leaks.
if (self.episodeTable) {
self.$scope.tab.assignOnCloseHandler(function () {
self.episodeTable.destroy();
self.episodeTable = null;
self.$scope.tab = null;
self.$scope.$destroy();
});
}
};
/**
@ -444,6 +455,7 @@ var AIRTIME = (function (AIRTIME) {
self.importListener = setInterval(function () {
var podcastId = self.config.podcastId, pendingRows = [];
if (!podcastId) return false;
console.log(self);
var dt = self.getDatatable(), data = dt.fnGetData();
// Iterate over the table data to check for any rows pending import
$.each(data, function () {
@ -475,6 +487,13 @@ var AIRTIME = (function (AIRTIME) {
}
}, 10000); // Run every 10 seconds
};
/**
* Explicit destructor
*/
PodcastEpisodeTable.prototype.destroy = function () {
clearInterval(this.importListener);
}
}
/**
@ -552,9 +571,9 @@ var AIRTIME = (function (AIRTIME) {
*/
mod.editSelectedEpisodes = function (episodes) {
$.each(episodes, function () {
if (!Object.keys(this.file).length > 0) return false;
var uid = AIRTIME.library.MediaTypeStringEnum.FILE + "_" + this.file.id;
$.get(baseUrl + "library/edit-file-md/id/" + this.file.id, {format: "json"}, function (json) {
if (this.file && !Object.keys(this.file).length > 0) return false;
var fileId = this.file_id || this.file.id, uid = AIRTIME.library.MediaTypeStringEnum.FILE + "_" + fileId;
$.get(baseUrl + "library/edit-file-md/id/" + fileId, {format: "json"}, function (json) {
AIRTIME.playlist.fileMdEdit(json, uid);
});
});
@ -568,7 +587,7 @@ var AIRTIME = (function (AIRTIME) {
*/
mod.importSelectedEpisodes = function (episodes, dt) {
$.each(episodes, function () {
if (Object.keys(this.file).length > 0) return false;
if (this.file && Object.keys(this.file).length > 0) return false;
var podcastId = this.podcast_id;
$.post(endpoint + podcastId + '/episodes', JSON.stringify({
csrf_token: $("#csrf").val(),

View file

@ -59,7 +59,7 @@ var AIRTIME = (function (AIRTIME) {
}
});
if (Object.keys(data).length > 0) {
if (data && Object.keys(data).length > 0) {
$http.put(endpoint + mediaId + '/publish', {csrf_token: jQuery("#csrf").val(), sources: data})
.success(function () {
init();

View file

@ -216,7 +216,7 @@ function buildScheduleDialog (json, instance_id) {
buttons: [
{
text: $.i18n._("Ok"),
"class": "btn",
class: "btn",
click: function() {
$(this).dialog("close");
//getUsabilityHint();

View file

@ -136,6 +136,13 @@ var AIRTIME = (function(AIRTIME){
});
};
/**
* Internal destructor. Can be assigned via assignOnCloseHandler
*
* @private
*/
Tab.prototype._destroy = function () {}
/**
* Assign the given function f as the click handler for the tab
*
@ -164,6 +171,15 @@ var AIRTIME = (function(AIRTIME){
this.tab.find(".lib_pl_close").unbind("click").click(f);
};
/**
* Assign an implicit destructor
*
* @param {function} fn function to run when this Tab is destroyed
*/
Tab.prototype.assignOnCloseHandler = function (fn) {
this._destroy = fn;
};
/**
* Open this tab in the right-hand pane and set it as the currently active tab
*/
@ -205,6 +221,8 @@ var AIRTIME = (function(AIRTIME){
} else {
mod.onResize();
}
self._destroy();
};
/**