diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 74c324ee9..82602021f 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -25,6 +25,7 @@ class ApiController extends Zend_Controller_Action ->addActionContext('register-component', 'json') ->addActionContext('update-liquidsoap-error', 'json') ->addActionContext('update-liquidsoap-connection', 'json') + ->addActionContext('library-init', 'json') ->initContext(); } @@ -77,9 +78,10 @@ class ApiController extends Zend_Controller_Action } $this->view->calendarInit = array( - "timestamp"=>time(), - "timezoneOffset"=> date("Z"), - "timeScale"=>Application_Model_Preference::GetCalendarTimeScale() + "timestamp" => time(), + "timezoneOffset" => date("Z"), + "timeScale" => Application_Model_Preference::GetCalendarTimeScale(), + "timeInterval" => Application_Model_Preference::GetCalendarTimeInterval() ); } @@ -731,5 +733,25 @@ class ApiController extends Zend_Controller_Action // setting error_msg as "" when there is no error_msg Application_Model_StreamSetting::setLiquidsoapError($stream_id, ""); } + + /** + * Sets up and send init values used in the Library. + * This is being used by library.js + */ + public function libraryInitAction(){ + $this->view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + if(is_null(Zend_Auth::getInstance()->getStorage()->read())) { + header('HTTP/1.0 401 Unauthorized'); + print 'You are not allowed to access this resource.'; + return; + } + + $this->view->libraryInit = array( + "numEntries"=>Application_Model_Preference::GetLibraryNumEntries() + ); + + } } diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index c959c66f5..0f61c406f 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -15,6 +15,7 @@ class LibraryController extends Zend_Controller_Action ->addActionContext('get-file-meta-data', 'html') ->addActionContext('upload-file-soundcloud', 'json') ->addActionContext('get-upload-to-soundcloud-status', 'json') + ->addActionContext('set-num-entries', 'json') ->initContext(); $this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME); @@ -269,4 +270,14 @@ class LibraryController extends Zend_Controller_Action $this->view->error_msg = $file->getSoundCloudErrorMsg(); } } + + /** + * Stores the number of entries user chose to show in the Library + * to the pref db + */ + public function setNumEntriesAction() { + $request = $this->getRequest(); + $numEntries = $request->getParam('numEntries'); + Application_Model_Preference::SetLibraryNumEntries($numEntries); + } } diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 716051390..6e8e445fa 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -29,6 +29,7 @@ class ScheduleController extends Zend_Controller_Action ->addActionContext('upload-to-sound-cloud', 'json') ->addActionContext('content-context-menu', 'json') ->addActionContext('set-time-scale', 'json') + ->addActionContext('set-time-interval', 'json') ->initContext(); $this->sched_sess = new Zend_Session_Namespace("schedule"); @@ -737,6 +738,14 @@ class ScheduleController extends Zend_Controller_Action public function setTimeScaleAction() { Application_Model_Preference::SetCalendarTimeScale($this->_getParam('timeScale')); } + +/** + * Sets the user specific preference for which time interval to use in Calendar. + * This is only being used by schedule.js at the moment. + */ + public function setTimeIntervalAction() { + Application_Model_Preference::SetCalendarTimeInterval($this->_getParam('timeInterval')); + } } diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index e58dafb5f..7e7ab9334 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -501,5 +501,37 @@ class Application_Model_Preference public static function GetCalendarTimeScale() { return self::GetValue("calendar_time_scale", true /* user specific */); } + + /** + * Sets the number of entries to show preference in library under Playlist Builder. + * + * @param $numEntries new number of entries to show + */ + public static function SetLibraryNumEntries($numEntries) { + return self::SetValue("library_num_entries", $numEntries, true /* user specific */); + } + + /** + * Retrieves the number of entries to show preference in library under Playlist Builder. + */ + public static function GetLibraryNumEntries() { + return self::GetValue("library_num_entries", true /* user specific */); + } + + /** + * Sets the time interval preference in Calendar. + * + * @param $timeInterval new time interval + */ + public static function SetCalendarTimeInterval($timeInterval) { + return self::SetValue("calendar_time_interval", $timeInterval, true /* user specific */); + } + + /** + * Retrieves the time interval preference for the current user. + */ + public static function GetCalendarTimeInterval() { + return self::GetValue("calendar_time_interval", true /* user specific */); + } } diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index 6408e5c97..b63d3bf19 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -275,11 +275,20 @@ function addMetadataQtip(){ }) } -$(document).ready(function() { +/** + * Use user preference for number of entries to show; + * defaults to 10 if preference was never set + */ +function getNumEntriesPreference(data) { + var numEntries = data.libraryInit.numEntries; + if(numEntries == '') { + numEntries = '10'; + } + return parseInt(numEntries); +} - $('.tabs').tabs(); - - $('#library_display').dataTable( { +function createDataTable(data) { + var dTable = $('#library_display').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "/Library/contents/format/json", @@ -309,8 +318,28 @@ $(document).ready(function() { "bAutoWidth": false, "oLanguage": { "sSearch": "" - } - }).fnSetFilteringDelay(350); + }, + "iDisplayLength": getNumEntriesPreference(data) + }); + 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); + } + }); + }); +} + +$(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 ); diff --git a/airtime_mvc/public/js/airtime/schedule/schedule.js b/airtime_mvc/public/js/airtime/schedule/schedule.js index 61a6e085c..3f3445b52 100644 --- a/airtime_mvc/public/js/airtime/schedule/schedule.js +++ b/airtime_mvc/public/js/airtime/schedule/schedule.js @@ -308,6 +308,17 @@ function getTimeScalePreference(data) { return timeScale; } +/** + * Use user preference for time interval; defaults to 30m if preference was never set + */ +function getTimeIntervalPreference(data) { + var timeInterval = data.calendarInit.timeInterval; + if(timeInterval == '') { + timeInterval = '30'; + } + return parseInt(timeInterval); +} + function createFullCalendar(data){ serverTimezoneOffset = data.calendarInit.timezoneOffset; @@ -321,6 +332,7 @@ function createFullCalendar(data){ right: 'agendaDay, agendaWeek, month' }, defaultView: getTimeScalePreference(data), + slotMinutes: getTimeIntervalPreference(data), editable: false, allDaySlot: false, axisFormat: 'H:mm', @@ -355,6 +367,17 @@ function createFullCalendar(data){ } }); }); + + //Update time interval preference when dropdown is updated + $(".schedule_change_slots.input_select").change(function() { + var url = '/Schedule/set-time-interval/format/json'; + $.post(url, {timeInterval: $(this).val()}, + function(json){ + if(json.error) { + alert(json.error); + } + }); + }); } $(window).load(function() {