From 1fd29def278e3490aa595e5c833e0c2d78bb2ec3 Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Wed, 16 Nov 2011 16:12:58 -0500 Subject: [PATCH] CC-2436: Save pulldown settings Move the code that updates the database for the "show entries" dropdown to a more appropriate place. --- airtime_mvc/application/models/Preference.php | 9 ++- .../public/js/airtime/library/library.js | 67 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 010daa713..e528308e8 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -574,7 +574,7 @@ class Application_Model_Preference public static function GetCalendarTimeScale() { $val = self::GetValue("calendar_time_scale", true /* user specific */); if(strlen($val) == 0) { - $val = 'month'; + $val = "month"; } return $val; } @@ -590,9 +590,14 @@ class Application_Model_Preference /** * Retrieves the number of entries to show preference in library under Playlist Builder. + * Defaults to 10 if no entry exists */ public static function GetLibraryNumEntries() { - return self::GetValue("library_num_entries", true /* user specific */); + $val = self::GetValue("library_num_entries", true /* user specific */); + if(strlen($val) == 0) { + $val = "10"; + } + return $val; } /** diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 46b29b29c..ec04a37c7 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -122,6 +122,7 @@ function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { function dtDrawCallback() { addLibraryItemEvents(); addMetadataQtip(); + saveNumEntriesSetting(); } function addProgressIcon(id) { @@ -280,19 +281,24 @@ function addMetadataQtip(){ } /** - * Use user preference for number of entries to show; - * defaults to 10 if preference was never set + * Updates pref db when user changes the # of entries to show + */ +function saveNumEntriesSetting() { + $('select[name=library_display_length]').change(function() { + var url = '/Library/set-num-entries/format/json'; + $.post(url, {numEntries: $(this).val()}); + }); +} + +/** + * Use user preference for number of entries to show */ function getNumEntriesPreference(data) { - var numEntries = data.libraryInit.numEntries; - if(numEntries == '') { - numEntries = '10'; - } - return parseInt(numEntries); + return parseInt(data.libraryInit.numEntries); } function createDataTable(data) { - var dTable = $('#library_display').dataTable( { + var dTable = $('#library_display').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "/Library/contents/format/json", @@ -320,35 +326,24 @@ function createDataTable(data) { "sPaginationType": "full_numbers", "bJQueryUI": true, "bAutoWidth": false, - "oLanguage": { - "sSearch": "" - }, - "iDisplayLength": getNumEntriesPreference(data), - "bStateSave": true - }); - dTable.fnSetFilteringDelay(350); - - // Updates pref db when user changes the # of entries to show - $('select[name=library_display_length]').change(function() { - var url = '/Library/set-num-entries/format/json'; - $.post(url, {numEntries: $(this).val()}, - function(json){ - if(json.error) { - alert(json.error); - } - }); - }); + "oLanguage": { + "sSearch": "" + }, + "iDisplayLength": getNumEntriesPreference(data), + "bStateSave": true + }); + dTable.fnSetFilteringDelay(350); } $(document).ready(function() { - $('.tabs').tabs(); - - $.ajax({ url: "/Api/library-init/format/json", dataType:"json", success:createDataTable - , error:function(jqXHR, textStatus, errorThrown){}}); - - checkImportStatus() - setInterval( "checkImportStatus()", 5000 ); - setInterval( "checkSCUploadStatus()", 5000 ); - - addQtipToSCIcons() + $('.tabs').tabs(); + + $.ajax({ url: "/Api/library-init/format/json", dataType:"json", success:createDataTable, + error:function(jqXHR, textStatus, errorThrown){}}); + + checkImportStatus() + setInterval( "checkImportStatus()", 5000 ); + setInterval( "checkSCUploadStatus()", 5000 ); + + addQtipToSCIcons() });