CC-2436: Save pulldown settings

For week and day views under Calendar page, save the change to pref db table when
user updates the interval dropdown. Same thing goes for the "show XXX entries"
dropdown found under Playlist Builder page.

When visiting these pages, we retrieves the entry from database for current user
and use those values. Defaults to 30m for interval and 10 entries for "show xxx entries"
if values were never set.
This commit is contained in:
Yuchen Wang 2011-10-18 10:10:35 -04:00
parent 3e441dc72f
commit d2fe46baf0
6 changed files with 135 additions and 9 deletions

View file

@ -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();
}
@ -79,7 +80,8 @@ class ApiController extends Zend_Controller_Action
$this->view->calendarInit = array(
"timestamp" => time(),
"timezoneOffset" => date("Z"),
"timeScale"=>Application_Model_Preference::GetCalendarTimeScale()
"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()
);
}
}

View file

@ -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);
}
}

View file

@ -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'));
}
}

View file

@ -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 */);
}
}

View file

@ -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": ""
},
"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);
}
}).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 );

View file

@ -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() {