From 32e1e7041844ced744dde3e8930d8b7084c9920a Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 12 Aug 2015 15:50:32 -0400 Subject: [PATCH] SAAS-948 - update tab functionality --- airtime_mvc/public/js/airtime/library/_spl.js | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/airtime_mvc/public/js/airtime/library/_spl.js b/airtime_mvc/public/js/airtime/library/_spl.js index 28b6888f2..47329dded 100644 --- a/airtime_mvc/public/js/airtime/library/_spl.js +++ b/airtime_mvc/public/js/airtime/library/_spl.js @@ -477,7 +477,9 @@ var AIRTIME = (function(AIRTIME){ return; } newTab.tab.on("click", function() { - AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab); + if (!$(this).hasClass('active')) { + AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab); + } }); newTab.wrapper.find(".md-cancel").on("click", function() { closeTab(); @@ -491,9 +493,11 @@ var AIRTIME = (function(AIRTIME){ return; } newTab.tab.on("click", function() { - AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab); - $.post(baseUrl+'new-playlist/edit', - {format: "json", id: newTab.pane.find(".obj_id").val(), type: newTab.pane.find(".obj_type").val()}); + if (!$(this).hasClass('active')) { + AIRTIME.showbuilder.switchTab(newTab.pane, newTab.tab); + $.post(baseUrl+'new-playlist/edit', + {format: "json", id: newTab.pane.find(".obj_id").val(), type: newTab.pane.find(".obj_type").val()}); + } }); AIRTIME.playlist.init(); @@ -515,16 +519,22 @@ var AIRTIME = (function(AIRTIME){ } function closeTab(id) { - var pane = id ? $(".pl-content[tab-id='" + id + "']") : $(".active-tab"), + var curr = $(".active-tab"), + pane = id ? $(".pl-content[tab-id='" + id + "']") : curr, tab = id ? $(".nav.nav-tabs [tab-id='" + id + "']") : $(".nav.nav-tabs .active"), toPane = pane.next().length > 0 ? pane.next() : pane.prev(), toTab = tab.next().length > 0 ? tab.next() : tab.prev(), - objId = id ? id : pane.find(".obj_id").val(); - delete $openTabs[tab.attr("tab-type") + objId]; + objId = pane.find(".obj_id").val(), + pl = id ? pane : $pl; + delete $openTabs[tab.attr("tab-type") + objId]; // Remove the closed tab from our open tabs array + // Remove the relevant DOM elements (the tab and the tab content) tab.remove(); - $pl.remove(); - AIRTIME.showbuilder.switchTab(toPane, toTab); + pl.remove(); + + if (pane.get(0) == curr.get(0)) { // Closing the current tab, otherwise we don't need to switch tabs + AIRTIME.showbuilder.switchTab(toPane, toTab); + } } mod.closeTab = function(id) { @@ -917,9 +927,9 @@ var AIRTIME = (function(AIRTIME){ $(this).unbind("click"); // Prevent repeated clicks in quick succession from closing multiple tabs var tabId = $(this).closest("li").attr("tab-id"); - AIRTIME.showbuilder.switchTab($("#pl-tab-content-" + tabId), $("#pl-tab-" + tabId)); + //AIRTIME.showbuilder.switchTab($("#pl-tab-content-" + tabId), $("#pl-tab-" + tabId)); + //$pl.hide(); - $pl.hide(); // We need to update the text on the add button AIRTIME.library.checkAddButton(); // We also need to run the draw callback to update how dragged items are drawn @@ -930,9 +940,9 @@ var AIRTIME = (function(AIRTIME){ if ((name == "Untitled Playlist" || name == "Untitled Smart Block") && $pl.find(".spl_sortable .spl_empty").length == 1) { - mod.fnDelete(); + mod.fnDelete(undefined, tabId); } else { - closeTab(); + closeTab(tabId); } $.ajax( { @@ -1143,20 +1153,19 @@ var AIRTIME = (function(AIRTIME){ }; - mod.fnDelete = function(plid) { - var url, id, lastMod; + mod.fnDelete = function(plid, tabId) { + var url, id, lastMod, type, pl = (tabId === undefined) ? $pl : $('#pl-tab-content' + tabId); stopAudioPreview(); id = (plid === undefined) ? getId() : plid; lastMod = getModified(); - type = $pl.find('.obj_type').val(); + type = pl.find('.obj_type').val(); url = baseUrl+'new-playlist/delete'; $.post(url, {format: "json", ids: id, modified: lastMod, type: type}, function(json) { - closeTab(); - // openPlaylist(json); + closeTab(tabId); redrawLib(); }); };