From 7990d6a71c8e1e17744a1ea21ce54334211da30a Mon Sep 17 00:00:00 2001 From: Naomi Aro Date: Tue, 8 Apr 2014 23:34:05 -0400 Subject: [PATCH] CC-5788 : Library Cleanup sorting out event clash from register.js fixing datatables so that things are always loaded and initialized properly. --- airtime_mvc/application/Bootstrap.php | 17 ++----- .../controllers/ShowbuilderController.php | 42 ++++++++-------- .../js/airtime/audiopreview/jPlayerWindow.js | 2 +- .../js/airtime/library/lib_separate_table.js | 49 +++++++++++-------- .../public/js/airtime/nowplaying/register.js | 4 +- .../public/js/airtime/showbuilder/builder.js | 19 +++++-- .../plugin/dataTables.columnFilter.js | 6 +-- 7 files changed, 75 insertions(+), 64 deletions(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 4f65761e3..08e39d422 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -51,15 +51,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $baseUrl = Application_Common_OsPath::getBaseDir(); $view->headScript()->appendScript("var baseUrl = '$baseUrl'"); - - $user = Application_Model_User::GetCurrentUser(); - if (!is_null($user)){ - $userType = $user->getType(); - } else { - $userType = ""; - } - $view->headScript()->appendScript("var userType = '$userType';"); - } protected function _initHeadLink() @@ -105,10 +96,10 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendFile($baseUrl.'locale/general-translation-table?'.$CC_CONFIG['airtime_version'],'text/javascript'); $view->headScript()->appendFile($baseUrl.'locale/datatables-translation-table?'.$CC_CONFIG['airtime_version'],'text/javascript'); $view->headScript()->appendScript("$.i18n.setDictionary(general_dict)"); - + $view->headScript()->appendFile($baseUrl.'js/timepicker/jquery-ui-timepicker-addon.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - + + $view->headScript()->appendScript("var baseUrl='$baseUrl'"); //These timezones are needed to adjust javascript Date objects on the client to make sense to the user's set timezone @@ -133,7 +124,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $view->headScript()->appendFile($baseUrl.'js/tipsy/jquery.tipsy.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $view->headScript()->appendFile($baseUrl.'js/airtime/common/common.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - + //scripts for the jPlayer preview bar. $view->headScript()->appendFile($baseUrl.'js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); $view->headScript()->appendFile($baseUrl.'js/airtime/audiopreview/jPlayerWindow.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index dc67a8a9b..bacbbcf15 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -18,32 +18,32 @@ class ShowbuilderController extends Zend_Controller_Action ->addActionContext('context-menu', 'json') ->initContext(); } - + private function getStartEnd() { $request = $this->getRequest(); - + $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $utcTimezone = new DateTimeZone("UTC"); $utcNow = new DateTime("now", $utcTimezone); - + $start = $request->getParam("start"); $end = $request->getParam("end"); - + if (empty($start) || empty($end)) { $startsDT = clone $utcNow; $endsDT = clone $utcNow; $endsDT->add(new DateInterval("P1D")); } else { - + try { $startsDT = new DateTime($start, $userTimezone); $startsDT->setTimezone($utcTimezone); - + $endsDT = new DateTime($end, $userTimezone); $endsDT->setTimezone($utcTimezone); - + if ($startsDT > $endsDT) { throw new Exception("start greater than end"); } @@ -51,14 +51,14 @@ class ShowbuilderController extends Zend_Controller_Action catch (Exception $e) { Logging::info($e); Logging::info($e->getMessage()); - + $startsDT = clone $utcNow; $startsDT->sub(new DateInterval("P1D")); $endsDT = clone $utcNow; } - + } - + return array($startsDT, $endsDT); } @@ -91,7 +91,7 @@ class ShowbuilderController extends Zend_Controller_Action $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/dataTables.colVis.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/dataTables.colReorder.css?'.$CC_CONFIG['airtime_version']); - + $refer_sses = new Zend_Session_Namespace('referrer'); if ($request->isPost()) { @@ -167,7 +167,7 @@ class ShowbuilderController extends Zend_Controller_Action } $this->view->disableLib = $disableLib; $this->view->showLib = $showLib; - + //TODO remove this when it's implemented. $disableLib = false; $showLib = true; @@ -177,13 +177,13 @@ class ShowbuilderController extends Zend_Controller_Action //only include library things on the page if the user can see it. if (!$disableLib) { + //set media columns for display of data. + $mediaService = new Application_Service_MediaService(); + $this->view->headScript()->appendScript($mediaService->createLibraryColumnsJavascript()); + $this->view->headScript()->appendScript($mediaService->createLibraryColumnSettingsJavascript()); + $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/lib_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/lib_separate_table.js?'.$CC_CONFIG['airtime_version'], 'text/javascript'); - - //set media columns for display of data. - $mediaService = new Application_Service_MediaService(); - $this->view->headScript()->appendScript($mediaService->createLibraryColumnsJavascript()); - $this->view->headScript()->appendScript($mediaService->createLibraryColumnSettingsJavascript()); } $data = Application_Model_Preference::getTimelineDatatableSetting(); @@ -195,7 +195,7 @@ class ShowbuilderController extends Zend_Controller_Action } list($startsDT, $endsDT) = $this->getStartEnd(); - + $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone()); $startsDT->setTimezone($userTimezone); $endsDT->setTimezone($userTimezone); @@ -261,7 +261,7 @@ class ShowbuilderController extends Zend_Controller_Action } $displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone()); - + $start = $instance->getDbStarts(null); $start->setTimezone($displayTimeZone); $end = $instance->getDbEnds(null); @@ -287,7 +287,7 @@ class ShowbuilderController extends Zend_Controller_Action $instances = $request->getParam("instances", array()); list($startsDT, $endsDT) = $this->getStartEnd(); - + $opts = array("myShows" => $my_shows, "showFilter" => $show_filter); $showBuilder = new Application_Model_ShowBuilder($startsDT, $endsDT, $opts); @@ -300,7 +300,7 @@ class ShowbuilderController extends Zend_Controller_Action public function builderFeedAction() { $current_time = time(); - + $request = $this->getRequest(); $show_filter = intval($request->getParam("showFilter", 0)); $show_instance_filter = intval($request->getParam("showInstanceFilter", 0)); diff --git a/airtime_mvc/public/js/airtime/audiopreview/jPlayerWindow.js b/airtime_mvc/public/js/airtime/audiopreview/jPlayerWindow.js index 49fa075e4..1108fd8c7 100644 --- a/airtime_mvc/public/js/airtime/audiopreview/jPlayerWindow.js +++ b/airtime_mvc/public/js/airtime/audiopreview/jPlayerWindow.js @@ -104,7 +104,7 @@ var AIRTIME = (function(AIRTIME) { } }); - $( "#open_playlist" ).click(function() { + $("#open_playlist").click(function() { $(".jp-playlist").toggleClass("open"); $(this).toggleClass("selected"); }); diff --git a/airtime_mvc/public/js/airtime/library/lib_separate_table.js b/airtime_mvc/public/js/airtime/library/lib_separate_table.js index dd1ee12b0..afe7309cc 100644 --- a/airtime_mvc/public/js/airtime/library/lib_separate_table.js +++ b/airtime_mvc/public/js/airtime/library/lib_separate_table.js @@ -209,9 +209,23 @@ var AIRTIME = (function(AIRTIME) { mod.checkToolBarIcons(); } + function stackTrace() { + var err = new Error(); + console.log(err.stack); + } + function libraryNeedSave(oData) { var settings = getCurrentDatatableSettings(); + //This will happen when we have nothing saved in cc_pref for this table. + if (settings["abVisCols"] === undefined || settings["ColReorder"] === undefined) { + + settings["abVisCols"] = oData.abVisCols; + settings["ColReorder"] = oData.ColReorder; + + return true; + } + if (settings["abVisCols"].join() === oData.abVisCols.join() && settings["ColReorder"].join() === oData.ColReorder.join()) { return false; @@ -223,7 +237,6 @@ var AIRTIME = (function(AIRTIME) { function createDatatable(config) { var key = "datatables-"+config.type+"-aoColumns", columns = JSON.parse(localStorage.getItem(key)), - abVisible, i, len, searchConfig; @@ -250,7 +263,8 @@ var AIRTIME = (function(AIRTIME) { //save the tables based on tableId "bStateSave": true, "fnStateSaveParams": function (oSettings, oData) { - // remove oData components we don't want to save. + + // remove oData components we don't want to save. delete oData.oSearch; delete oData.aoSearchCols; }, @@ -272,12 +286,13 @@ var AIRTIME = (function(AIRTIME) { try { return JSON.parse(settings); - } catch (e) { + } + catch (e) { return null; } }, "fnStateLoadParams": function (oSettings, oData) { - var i, + var i, length, a = oData.abVisCols, settings = getCurrentDatatableSettings(); @@ -301,10 +316,6 @@ var AIRTIME = (function(AIRTIME) { settings["ColReorder"] = a.slice(0); - //abVisible indices belong to the original column order. - //use to fix up advanced search. - abVisible = oData.abVisCols; - oData.iEnd = parseInt(oData.iEnd, 10); oData.iLength = parseInt(oData.iLength, 10); oData.iStart = parseInt(oData.iStart, 10); @@ -348,22 +359,18 @@ var AIRTIME = (function(AIRTIME) { "fnInitComplete": function(oSettings, json) { var $panel = $(table[0]).parents("div.ui-tabs-panel"); + var settings = getCurrentDatatableSettings(); - //fnStateLoadParams will have already run. - //fix up advanced search from saved settings. - for (i = 0, len = abVisible.length; i < len; i++) { - setAdvancedSearchColumnDisplay(i, abVisible[i], config.type); + for (i = 0, len = settings.abVisCols.length; i < len; i++) { + setAdvancedSearchColumnDisplay(i, settings.abVisCols[i], config.type); } table.columnFilter({ aoColumns: searchConfig, sPlaceHolder: "head:before" }); - - //append a search button - //$panel.find(".dataTables_filter").append(''); - - //only search on enter. + + //search on enter. $panel.on("keypress", ".advanced_search input", function(e) { if (e.which === 13) { table.fnDraw(); @@ -708,11 +715,11 @@ var AIRTIME = (function(AIRTIME) { } }); - $library.on("click", "legend", function() { - var $fs = $(this).parents("fieldset"); + $library.on("click", "legend", function() { + var $fs = $(this).parents("fieldset"); - $fs.toggleClass("closed"); - }); + $fs.toggleClass("closed"); + }); $library.on("click", "#lib_new_webstream", function(e) { var url = baseUrl+"webstream/new/format/json"; diff --git a/airtime_mvc/public/js/airtime/nowplaying/register.js b/airtime_mvc/public/js/airtime/nowplaying/register.js index 58a5b1f21..55b6b4b23 100644 --- a/airtime_mvc/public/js/airtime/nowplaying/register.js +++ b/airtime_mvc/public/js/airtime/nowplaying/register.js @@ -112,8 +112,8 @@ $(document).ready(function(){ button.attr('disabled', 'disabled' ).addClass('ui-state-disabled'); } - $('.toggle legend').live('click',function() { - $('.toggle').toggleClass('closed'); + $('#register_popup .toggle legend').live('click',function() { + $('#register_popup .toggle').toggleClass('closed'); return false; }); diff --git a/airtime_mvc/public/js/airtime/showbuilder/builder.js b/airtime_mvc/public/js/airtime/showbuilder/builder.js index 39f13807e..bd4b8a9d6 100644 --- a/airtime_mvc/public/js/airtime/showbuilder/builder.js +++ b/airtime_mvc/public/js/airtime/showbuilder/builder.js @@ -370,9 +370,19 @@ var AIRTIME = (function(AIRTIME){ } function builderNeedSave(oData) { + var settings = currentDatatablesSettings; - if (currentDatatablesSettings["abVisCols"].join() === oData.abVisCols.join() - && currentDatatablesSettings["ColReorder"].join() === oData.ColReorder.join()) { + //This will happen when we have nothing saved in cc_pref for this table. + if (settings["abVisCols"] === undefined || settings["ColReorder"] === undefined) { + + settings["abVisCols"] = oData.abVisCols; + settings["ColReorder"] = oData.ColReorder; + + return true; + } + + if (settings["abVisCols"].join() === oData.abVisCols.join() + && settings["ColReorder"].join() === oData.ColReorder.join()) { return false; } @@ -434,8 +444,11 @@ var AIRTIME = (function(AIRTIME){ "fnStateLoad": function fnBuilderStateLoad(oSettings) { var settings = localStorage.getItem('datatables-timeline'); - if (settings !== "") { + try { return JSON.parse(settings); + } + catch (e) { + return null; } }, "fnStateLoadParams": function (oSettings, oData) { diff --git a/airtime_mvc/public/js/datatables/plugin/dataTables.columnFilter.js b/airtime_mvc/public/js/datatables/plugin/dataTables.columnFilter.js index 499fe5020..acb840501 100644 --- a/airtime_mvc/public/js/datatables/plugin/dataTables.columnFilter.js +++ b/airtime_mvc/public/js/datatables/plugin/dataTables.columnFilter.js @@ -50,9 +50,9 @@ var properties = $.extend(defaults, options); function _fnColumnIndex(iColumnIndex) { - var s = oTable.fnSettings(), - order = s.oLoadedState.ColReorder, - index = order.indexOf(iColumnIndex); + var colOrder = new $.fn.dataTable.ColReorder(oTable); + var order = colOrder.fnOrder(); + var index = order.indexOf(iColumnIndex); //iColumnIndex is the original column index. //to match the rest of the data sent to the server it must give