CC-4583: Use AJAX calls instead of refreshing entire page

-done
This commit is contained in:
denise 2012-10-26 18:09:30 -04:00
parent 0ab1353564
commit 3a7700eaac
12 changed files with 185 additions and 82 deletions

View File

@ -34,37 +34,47 @@ class PreferenceController extends Zend_Controller_Action
$form = new Application_Form_Preferences();
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$values = $form->getValues();
$params = $request->getPost();
$postData = explode('&', $params['data']);
foreach($postData as $k=>$v) {
$v = explode('=', $v);
$values[$v[0]] = urldecode($v[1]);
}
if ($form->isValid($values)) {
Application_Model_Preference::SetHeadTitle($values["preferences_general"]["stationName"], $this->view);
Application_Model_Preference::SetDefaultFade($values["preferences_general"]["stationDefaultFade"]);
Application_Model_Preference::SetAllow3rdPartyApi($values["preferences_general"]["thirdPartyApi"]);
Application_Model_Preference::SetTimezone($values["preferences_general"]["timezone"]);
Application_Model_Preference::SetWeekStartDay($values["preferences_general"]["weekStartDay"]);
Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view);
Application_Model_Preference::SetDefaultFade($values["stationDefaultFade"]);
Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]);
Application_Model_Preference::SetTimezone($values["timezone"]);
Application_Model_Preference::SetWeekStartDay($values["weekStartDay"]);
if (!$isSaas) {
Application_Model_Preference::SetEnableSystemEmail($values["preferences_email_server"]["enableSystemEmail"]);
Application_Model_Preference::SetSystemEmail($values["preferences_email_server"]["systemEmail"]);
Application_Model_Preference::SetMailServerConfigured($values["preferences_email_server"]["configureMailServer"]);
Application_Model_Preference::SetMailServer($values["preferences_email_server"]["mailServer"]);
Application_Model_Preference::SetMailServerEmailAddress($values["preferences_email_server"]["email"]);
Application_Model_Preference::SetMailServerPassword($values["preferences_email_server"]["ms_password"]);
Application_Model_Preference::SetMailServerPort($values["preferences_email_server"]["port"]);
Application_Model_Preference::SetMailServerRequiresAuth($values["preferences_email_server"]["msRequiresAuth"]);
Application_Model_Preference::SetEnableSystemEmail($values["enableSystemEmail"]);
Application_Model_Preference::SetSystemEmail($values["systemEmail"]);
Application_Model_Preference::SetMailServerConfigured($values["configureMailServer"]);
Application_Model_Preference::SetMailServer($values["mailServer"]);
Application_Model_Preference::SetMailServerEmailAddress($values["email"]);
Application_Model_Preference::SetMailServerPassword($values["ms_password"]);
Application_Model_Preference::SetMailServerPort($values["port"]);
Application_Model_Preference::SetMailServerRequiresAuth($values["msRequiresAuth"]);
}
Application_Model_Preference::SetAutoUploadRecordedShowToSoundcloud($values["preferences_soundcloud"]["UseSoundCloud"]);
Application_Model_Preference::SetUploadToSoundcloudOption($values["preferences_soundcloud"]["UploadToSoundcloudOption"]);
Application_Model_Preference::SetSoundCloudDownloadbleOption($values["preferences_soundcloud"]["SoundCloudDownloadbleOption"]);
Application_Model_Preference::SetSoundCloudUser($values["preferences_soundcloud"]["SoundCloudUser"]);
Application_Model_Preference::SetSoundCloudPassword($values["preferences_soundcloud"]["SoundCloudPassword"]);
Application_Model_Preference::SetSoundCloudTags($values["preferences_soundcloud"]["SoundCloudTags"]);
Application_Model_Preference::SetSoundCloudGenre($values["preferences_soundcloud"]["SoundCloudGenre"]);
Application_Model_Preference::SetSoundCloudTrackType($values["preferences_soundcloud"]["SoundCloudTrackType"]);
Application_Model_Preference::SetSoundCloudLicense($values["preferences_soundcloud"]["SoundCloudLicense"]);
Application_Model_Preference::SetAutoUploadRecordedShowToSoundcloud($values["UseSoundCloud"]);
Application_Model_Preference::SetUploadToSoundcloudOption($values["UploadToSoundcloudOption"]);
Application_Model_Preference::SetSoundCloudDownloadbleOption($values["SoundCloudDownloadbleOption"]);
Application_Model_Preference::SetSoundCloudUser($values["SoundCloudUser"]);
Application_Model_Preference::SetSoundCloudPassword($values["SoundCloudPassword"]);
Application_Model_Preference::SetSoundCloudTags($values["SoundCloudTags"]);
Application_Model_Preference::SetSoundCloudGenre($values["SoundCloudGenre"]);
Application_Model_Preference::SetSoundCloudTrackType($values["SoundCloudTrackType"]);
Application_Model_Preference::SetSoundCloudLicense($values["SoundCloudLicense"]);
$this->view->statusMsg = "<div class='success'>Preferences updated.</div>";
$this->view->form = $form;
die(json_encode(array("valid"=>"true", "html"=>$this->view->render('preference/index.phtml'))));
} else {
$this->view->form = $form;
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('preference/index.phtml'))));
}
}
$this->view->form = $form;
@ -77,7 +87,6 @@ class PreferenceController extends Zend_Controller_Action
$request = $this->getRequest();
$baseUrl = Application_Common_OsPath::getBaseDir();
Logging::info($baseUrl);
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/preferences/support-setting.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->statusMsg = "";
@ -207,10 +216,37 @@ class PreferenceController extends Zend_Controller_Action
$form->addSubForm($subform, "s".$i."_subform");
}
if ($request->isPost()) {
$values = $request->getPost();
$params = $request->getPost();
/* Parse through post data and put in format
* $form->isValid() is expecting it in
*/
$postData = explode('&', $params['data']);
$s1_data = array();
$s2_data = array();
$s3_data = array();
foreach($postData as $k=>$v) {
$v = explode('=', urldecode($v));
if (strpos($v[0], "s1_data") !== false) {
/* In this case $v[0] may be 's1_data[enable]' , for example.
* We only want the 'enable' part
*/
preg_match('/\[(.*)\]/', $v[0], $matches);
$s1_data[$matches[1]] = $v[1];
} elseif (strpos($v[0], "s2_data") !== false) {
preg_match('/\[(.*)\]/', $v[0], $matches);
$s2_data[$matches[1]] = $v[1];
} elseif (strpos($v[0], "s3_data") !== false) {
preg_match('/\[(.*)\]/', $v[0], $matches);
$s3_data[$matches[1]] = $v[1];
} else {
$values[$v[0]] = $v[1];
}
}
$values["s1_data"] = $s1_data;
$values["s2_data"] = $s2_data;
$values["s3_data"] = $s3_data;
$error = false;
if ($form->isValid($values)) {
if (!$isSaas) {
$values['output_sound_device'] = $form->getValue('output_sound_device');
@ -271,12 +307,23 @@ class PreferenceController extends Zend_Controller_Action
}
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
$live_stream_subform->updateVariables();
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form;
$this->view->num_stream = $num_of_stream;
$this->view->statusMsg = "<div class='success'>Stream Setting Updated.</div>";
die(json_encode(array("valid"=>"true", "html"=>$this->view->render('preference/stream-setting.phtml'))));
} else {
$live_stream_subform->updateVariables();
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form;
$this->view->num_stream = $num_of_stream;
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('preference/stream-setting.phtml'))));
}
}
$live_stream_subform->updateVariables();
$this->view->confirm_pypo_restart_text = "If you change the username or password values for an enabled stream the playout engine will be rebooted and your listeners will hear silence for 5-10 seconds. Changing the following fields will NOT cause a reboot: Stream Label (Global Settings), and Switch Transition Fade(s), Master Username, and Master Password (Input Stream Settings). If Airtime is recording, and if the change causes a playout engine restart, the recording will be interrupted.";
$this->view->num_stream = $num_of_stream;
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();

View File

@ -38,39 +38,53 @@ class UserController extends Zend_Controller_Action
$this->view->successMessage = "";
if ($request->isPost()) {
if ($form->isValid($request->getPost())) {
$params = $request->getPost();
$postData = explode('&', $params['data']);
foreach($postData as $k=>$v) {
$v = explode('=', $v);
$formData[$v[0]] = urldecode($v[1]);
}
if ($form->isValid($formData)) {
$formdata = $form->getValues();
if (isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1
&& $formdata['login'] == 'admin'
&& $formdata['user_id'] != 0) {
&& $formData['login'] == 'admin'
&& $formData['user_id'] != 0) {
$this->view->form = $form;
$this->view->successMessage = "<div class='errors'>Specific action is not allowed in demo version!</div>";
} elseif ($form->validateLogin($formdata)) {
$user = new Application_Model_User($formdata['user_id']);
$user->setFirstName($formdata['first_name']);
$user->setLastName($formdata['last_name']);
$user->setLogin($formdata['login']);
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('user/add-user.phtml'))));
} elseif ($form->validateLogin($formData)) {
$user = new Application_Model_User($formData['user_id']);
$user->setFirstName($formData['first_name']);
$user->setLastName($formData['last_name']);
$user->setLogin($formData['login']);
// We don't allow 6 x's as a password.
// The reason is because we that as a password placeholder
// on the client side.
if ($formdata['password'] != "xxxxxx") {
$user->setPassword($formdata['password']);
if ($formData['password'] != "xxxxxx") {
$user->setPassword($formData['password']);
}
$user->setType($formdata['type']);
$user->setEmail($formdata['email']);
$user->setCellPhone($formdata['cell_phone']);
$user->setSkype($formdata['skype']);
$user->setJabber($formdata['jabber']);
$user->setType($formData['type']);
$user->setEmail($formData['email']);
$user->setCellPhone($formData['cell_phone']);
$user->setSkype($formData['skype']);
$user->setJabber($formData['jabber']);
$user->save();
$form->reset();
$this->view->form = $form;
if (strlen($formdata['user_id']) == 0) {
if (strlen($formData['user_id']) == 0) {
$this->view->successMessage = "<div class='success'>User added successfully!</div>";
} else {
$this->view->successMessage = "<div class='success'>User updated successfully!</div>";
}
die(json_encode(array("valid"=>"true", "html"=>$this->view->render('user/add-user.phtml'))));
}
} else {
$this->view->form = $form;
die(json_encode(array("valid"=>"false", "html"=>$this->view->render('user/add-user.phtml'))));
}
}

View File

@ -11,6 +11,8 @@ class Application_Form_AddUser extends Zend_Form
'validate');
* */
$this->setAttrib('id', 'user_form');
$hidden = new Zend_Form_Element_Hidden('user_id');
$hidden->setDecorators(array('ViewHelper'));
$this->addElement($hidden);
@ -85,11 +87,11 @@ class Application_Form_AddUser extends Zend_Form
$select->setRequired(true);
$this->addElement($select);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setAttrib('class', 'ui-button ui-state-default right-floated');
$submit->setIgnore(true);
$submit->setLabel('Save');
$this->addElement($submit);
$saveBtn = new Zend_Form_Element_Button('save_user');
$saveBtn->setAttrib('class', 'btn btn-small right-floated');
$saveBtn->setIgnore(true);
$saveBtn->setLabel('Save');
$this->addElement($saveBtn);
}
public function validateLogin($data)

View File

@ -8,7 +8,6 @@ class Application_Form_Preferences extends Zend_Form
{
$baseUrl = Application_Common_OsPath::getBaseDir();
$this->setAction($baseUrl . '/Preference');
$this->setMethod('post');
$isSaas = Application_Model_Preference::GetPlanLevel() == 'disabled'?false:true;
@ -29,13 +28,11 @@ class Application_Form_Preferences extends Zend_Form
$soundcloud_pref = new Application_Form_SoundcloudPreferences();
$this->addSubForm($soundcloud_pref, 'preferences_soundcloud');
$this->addElement('submit', 'submit', array(
'class' => 'ui-button ui-state-default right-floated',
'ignore' => true,
'label' => 'Save',
'decorators' => array(
'ViewHelper'
)
));
$saveBtn = new Zend_Form_Element_Button('pref_save');
$saveBtn->setAttrib('class', 'btn btn-small right-floated');
$saveBtn->setIgnore(true);
$saveBtn->setLabel('Save');
$this->addElement($saveBtn);
}
}

View File

@ -1,4 +1,4 @@
<form method="<?php echo $this->element->getMethod() ?>" action="<?php echo $this->element->getAction() ?>" enctype="multipart/form-data">
<form method="<?php echo $this->element->getMethod() ?>" enctype="multipart/form-data">
<?php echo $this->element->getSubform('preferences_general') ?>
@ -15,8 +15,6 @@
<?php echo $this->element->getSubform('preferences_soundcloud') ?>
</div>
<div class="button-bar bottom" id="submit-element">
<?php echo $this->element->getElement('submit') ?>
</div>
<?php echo $this->element->getElement('pref_save') ?>
</form>

View File

@ -1,11 +1,9 @@
<div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong preferences">
<h2 style="float:left">Preferences</h2>
<?php $baseUrl = Application_Common_OsPath::getBaseDir(); ?>
<form method="post" action=<?php echo $baseUrl . "/Preference/index"?> enctype="application/x-www-form-urlencoded">
<form method="post" id="pref_form" enctype="application/x-www-form-urlencoded">
<div class="button-bar bottom" id="submit-element" style="float:right">
<input type="submit" class="ui-button ui-state-default right-floated" value="Save" id="Save" name="Save" />
</div>
<button name="pref_save" id="pref_save" type="button" class="btn btn-small right-floated">Save</button>
<div style="clear:both"></div>
<?php

View File

@ -2,10 +2,8 @@
<h2 <?php if($this->enable_stream_conf == "true"){?>style="float:left"<?php }?>>Stream Settings</h2>
<?php $baseUrl = Application_Common_OsPath::getBaseDir(); ?>
<?php if($this->enable_stream_conf == "true"){?>
<form method="post" action=<?php echo $baseUrl . "/Preference/stream-setting"?> enctype="application/x-www-form-urlencoded" onsubmit="return confirm('<?php echo $this->confirm_pypo_restart_text ?>');">
<div class="button-bar bottom" id="submit-element" style="float:right">
<input type="submit" class="ui-button ui-state-default right-floated" value="Save" id="Save" name="Save" />
</div>
<form method="post" id="stream_form" enctype="application/x-www-form-urlencoded">
<button name="stream_save" id="stream_save" type="button" class="btn btn-small right-floated">Save</button>
<div style="clear:both"></div>
<?php }?>
<?php echo $this->statusMsg;?>
@ -79,9 +77,8 @@
?>
</fieldset>
<?php if($this->enable_stream_conf == "true"){?>
<div class="button-bar bottom" id="submit-element">
<input type="submit" class="ui-button ui-state-default right-floated" value="Save" id="Save" name="Save" />
</div>
<br />
<button name="stream_save" id="stream_save" type="button" class="btn btn-small right-floated">Save</button>
<?php }?>
</div>
</form>

View File

@ -109,3 +109,9 @@ function openPreviewWindow(url) {
function pad(number, length) {
return sprintf("%'0"+length+"d", number);
}
function removeSuccessMsg() {
var $status = $('.success');
$status.fadeOut("slow", function(){$status.empty()});
}

View File

@ -483,12 +483,6 @@ function callback(data, type) {
setTimeout(removeSuccessMsg, 5000);
}
function removeSuccessMsg() {
var $status = $('.success');
$status.fadeOut("slow", function(){$status.empty()});
}
function appendAddButton() {
var add_button = "<a class='btn btn-small' id='criteria_add'>" +
"<i class='icon-white icon-plus'></i></a>";

View File

@ -88,6 +88,17 @@ $(document).ready(function() {
$(this).toggleClass("closed");
return false;
}).next().hide();
$('#pref_save').live('click', function() {
var data = $('#pref_form').serialize();
var url = baseUrl+'/Preference/index';
$.post(url, {format: "json", data: data}, function(data){
var json = $.parseJSON(data);
$('#content').empty().append(json.html);
setTimeout(removeSuccessMsg, 5000);
});
});
showErrorSections();

View File

@ -352,4 +352,22 @@ $(document).ready(function() {
at: "right center"
},
})
$('#stream_save').live('click', function(){
var confirm_pypo_restart_text = "If you change the username or password values for an enabled stream the "
+ "playout engine will be rebooted and your listeners will hear silence for"
+ "5-10 seconds. Changing the following fields will NOT cause a reboot: "
+ "Stream Label (Global Settings), and Switch Transition Fade(s), Master "
+ "Username, and Master Password (Input Stream Settings). If Airtime is recording"
+ ", and if the change causes a playout engine restart, the recording will be interrupted.";
if (confirm(confirm_pypo_restart_text)) {
var data = $('#stream_form').serialize();
var url = baseUrl+'/Preference/stream-setting';
$.post(url, {format:"json", data: data}, function(data){
var json = $.parseJSON(data);
$('#content').empty().append(json.html);
});
}
});
});

View File

@ -60,7 +60,7 @@ function rowCallback( nRow, aData, iDisplayIndex ){
return nRow;
}
$(document).ready(function() {
function populateUserTable() {
$('#users_datatable').dataTable( {
"bProcessing": true,
"bServerSide": true,
@ -92,11 +92,32 @@ $(document).ready(function() {
"sDom": '<"H"lf<"dt-process-rel"r>>t<"F"ip>',
});
}
$(document).ready(function() {
populateUserTable();
//$('#user_details').hide();
var newUser = {login:"", first_name:"", last_name:"", type:"G", id:""};
$('#add_user_button').click(function(){populateForm(newUser)});
$('#add_user_button').live('click', function(){populateForm(newUser)});
$('#save_user').live('click', function(){
var data = $('#user_form').serialize();
var url = baseUrl+'/User/add-user';
$.post(url, {format: "json", data: data}, function(data){
var json = $.parseJSON(data);
if (json.valid === "true") {
$('#content').empty().append(json.html);
populateUserTable();
} else {
//if form is invalid we only need to redraw the form
$('#user_form').empty().append($(json.html).find('#user_form').children());
}
setTimeout(removeSuccessMsg, 5000);
});
});
});