SAAS-876 - More work on stream settings page

This commit is contained in:
Duncan Sommerville 2015-07-08 16:04:09 -04:00
parent 6b9d9e8063
commit ac2e1a2d4b
6 changed files with 38 additions and 72 deletions

View File

@ -248,9 +248,7 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_StreamSetting::setLiquidsoapError($i, "waiting"); Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
} }
if (Application_Model_Preference::getUsingCustomStreamSettings()) {
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data); Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
}
$this->view->statusMsg = "<div class='success'>"._("Stream Setting Updated.")."</div>"; $this->view->statusMsg = "<div class='success'>"._("Stream Setting Updated.")."</div>";
} }
} }
@ -293,6 +291,7 @@ class PreferenceController extends Zend_Controller_Action
$subform->setStreamTypes($stream_types); $subform->setStreamTypes($stream_types);
$subform->setStreamBitrates($stream_bitrates); $subform->setStreamBitrates($stream_bitrates);
$subform->startForm(); $subform->startForm();
$subform->toggleState();
$form->addSubForm($subform, "s".$i."_subform"); $form->addSubForm($subform, "s".$i."_subform");
} }

View File

@ -62,8 +62,8 @@ class Application_Form_StreamSetting extends Zend_Form
$custom = Application_Model_Preference::getUsingCustomStreamSettings(); $custom = Application_Model_Preference::getUsingCustomStreamSettings();
$customSettings = new Zend_Form_Element_Radio('customStreamSettings'); $customSettings = new Zend_Form_Element_Radio('customStreamSettings');
$customSettings->setLabel(_('Stream Settings:')); $customSettings->setLabel(_('Streaming Server:'));
$customSettings->setMultiOptions(array(_("Default"), _("Use Custom"))); $customSettings->setMultiOptions(array(_("Airtime Pro Streaming"), _("Custom / 3rd Party")));
$customSettings->setValue(!empty($custom) ? $custom : 0); $customSettings->setValue(!empty($custom) ? $custom : 0);
$this->addElement($customSettings); $this->addElement($customSettings);
} }

View File

@ -6,6 +6,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
private $stream_types; private $stream_types;
private $stream_bitrates; private $stream_bitrates;
static $customizable;
public function init() public function init()
{ {
@ -42,51 +44,41 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$this->setIsArray(true); $this->setIsArray(true);
$this->setElementsBelongTo($prefix."_data"); $this->setElementsBelongTo($prefix."_data");
$disable_all = !Application_Model_Preference::getUsingCustomStreamSettings();
$enable = new Zend_Form_Element_Checkbox('enable'); $enable = new Zend_Form_Element_Checkbox('enable');
$enable->setLabel(_('Enabled:')) $enable->setLabel(_('Enabled:'))
->setValue($setting[$prefix.'_enable'] == 'true' ? 1 : 0) ->setValue($setting[$prefix.'_enable'] == 'true' ? 1 : 0)
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$enable->setAttrib("disabled", "disabled");
}
$this->addElement($enable); $this->addElement($enable);
static::$customizable[] = $enable->getName();
$mobile = new Zend_Form_Element_Checkbox('mobile'); $mobile = new Zend_Form_Element_Checkbox('mobile');
$mobile->setLabel(_('Mobile:')); $mobile->setLabel(_('Mobile:'));
$mobile->setValue($setting[$prefix.'_mobile']); $mobile->setValue($setting[$prefix.'_mobile']);
$mobile->setDecorators(array('ViewHelper')); $mobile->setDecorators(array('ViewHelper'));
$this->addElement($mobile); $this->addElement($mobile);
static::$customizable[] = $mobile->getName();
$type = new Zend_Form_Element_Select('type'); $type = new Zend_Form_Element_Select('type');
$type->setLabel(_("Stream Type:")) $type->setLabel(_("Stream Type:"))
->setMultiOptions($stream_types) ->setMultiOptions($stream_types)
->setValue(isset($setting[$prefix.'_type'])?$setting[$prefix.'_type']:0) ->setValue(isset($setting[$prefix.'_type'])?$setting[$prefix.'_type']:0)
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$type->setAttrib("disabled", "disabled");
}
$this->addElement($type); $this->addElement($type);
static::$customizable[] = $type->getName();
$bitrate = new Zend_Form_Element_Select('bitrate'); $bitrate = new Zend_Form_Element_Select('bitrate');
$bitrate->setLabel(_("Bit Rate:")) $bitrate->setLabel(_("Bit Rate:"))
->setMultiOptions($stream_bitrates) ->setMultiOptions($stream_bitrates)
->setValue(isset($setting[$prefix.'_bitrate'])?$setting[$prefix.'_bitrate']:0) ->setValue(isset($setting[$prefix.'_bitrate'])?$setting[$prefix.'_bitrate']:0)
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$bitrate->setAttrib("disabled", "disabled");
}
$this->addElement($bitrate); $this->addElement($bitrate);
static::$customizable[] = $bitrate->getName();
$output = new Zend_Form_Element_Select('output'); $output = new Zend_Form_Element_Select('output');
$output->setLabel(_("Service Type:")) $output->setLabel(_("Service Type:"))
->setMultiOptions(array("icecast"=>"Icecast", "shoutcast"=>"SHOUTcast")) ->setMultiOptions(array("icecast"=>"Icecast", "shoutcast"=>"SHOUTcast"))
->setValue(isset($setting[$prefix.'_output'])?$setting[$prefix.'_output']:"icecast") ->setValue(isset($setting[$prefix.'_output'])?$setting[$prefix.'_output']:"icecast")
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$output->setAttrib("disabled", "disabled");
}
$this->addElement($output); $this->addElement($output);
$channels = new Zend_Form_Element_Select('channels'); $channels = new Zend_Form_Element_Select('channels');
@ -94,10 +86,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setMultiOptions(array("mono"=>_("1 - Mono"), "stereo"=>_("2 - Stereo"))) ->setMultiOptions(array("mono"=>_("1 - Mono"), "stereo"=>_("2 - Stereo")))
->setValue(isset($setting[$prefix.'_channels']) ? $setting[$prefix.'_channels'] : "stereo") ->setValue(isset($setting[$prefix.'_channels']) ? $setting[$prefix.'_channels'] : "stereo")
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$channels->setAttrib("disabled", "disabled");
}
$this->addElement($channels); $this->addElement($channels);
static::$customizable[] = $channels->getName();
$host = new Zend_Form_Element_Text('host'); $host = new Zend_Form_Element_Text('host');
$host->setLabel(_("Server")) $host->setLabel(_("Server"))
@ -105,9 +95,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[0-9a-zA-Z-_.]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[0-9a-zA-Z-_.]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$host->setAttrib("disabled", "disabled");
}
$host->setAttrib('alt', 'domain'); $host->setAttrib('alt', 'domain');
$this->addElement($host); $this->addElement($host);
@ -117,9 +104,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array(new Zend_Validate_Between(array('min'=>0, 'max'=>99999)))) ->setValidators(array(new Zend_Validate_Between(array('min'=>0, 'max'=>99999))))
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.')))) ->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.'))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$port->setAttrib("disabled", "disabled");
}
$this->addElement($port); $this->addElement($port);
$pass = new Zend_Form_Element_Text('pass'); $pass = new Zend_Form_Element_Text('pass');
@ -128,9 +112,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$pass->setAttrib("disabled", "disabled");
}
$pass->setAttrib('alt', 'regular_text'); $pass->setAttrib('alt', 'regular_text');
$this->addElement($pass); $this->addElement($pass);
@ -138,9 +119,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$genre->setLabel(_("Genre")) $genre->setLabel(_("Genre"))
->setValue(isset($setting[$prefix.'_genre'])?$setting[$prefix.'_genre']:"") ->setValue(isset($setting[$prefix.'_genre'])?$setting[$prefix.'_genre']:"")
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$genre->setAttrib("disabled", "disabled");
}
$this->addElement($genre); $this->addElement($genre);
$url = new Zend_Form_Element_Text('url'); $url = new Zend_Form_Element_Text('url');
@ -149,9 +127,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[0-9a-zA-Z\-_.:\/]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[0-9a-zA-Z\-_.:\/]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$url->setAttrib("disabled", "disabled");
}
$url->setAttrib('alt', 'url'); $url->setAttrib('alt', 'url');
$this->addElement($url); $this->addElement($url);
@ -159,18 +134,12 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$name->setLabel(_("Name")) $name->setLabel(_("Name"))
->setValue(isset($setting[$prefix.'_name'])?$setting[$prefix.'_name']:"") ->setValue(isset($setting[$prefix.'_name'])?$setting[$prefix.'_name']:"")
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$name->setAttrib("disabled", "disabled");
}
$this->addElement($name); $this->addElement($name);
$description = new Zend_Form_Element_Text('description'); $description = new Zend_Form_Element_Text('description');
$description->setLabel(_("Description")) $description->setLabel(_("Description"))
->setValue(isset($setting[$prefix.'_description'])?$setting[$prefix.'_description']:"") ->setValue(isset($setting[$prefix.'_description'])?$setting[$prefix.'_description']:"")
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$description->setAttrib("disabled", "disabled");
}
$this->addElement($description); $this->addElement($description);
$mount = new Zend_Form_Element_Text('mount'); $mount = new Zend_Form_Element_Text('mount');
@ -179,9 +148,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$mount->setAttrib("disabled", "disabled");
}
$mount->setAttrib('alt', 'regular_text'); $mount->setAttrib('alt', 'regular_text');
$this->addElement($mount); $this->addElement($mount);
@ -191,9 +157,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$user->setAttrib("disabled", "disabled");
}
$user->setAttrib('alt', 'regular_text'); $user->setAttrib('alt', 'regular_text');
$this->addElement($user); $this->addElement($user);
@ -203,9 +166,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$adminUser->setAttrib("disabled", "disabled");
}
$adminUser->setAttrib('alt', 'regular_text'); $adminUser->setAttrib('alt', 'regular_text');
$this->addElement($adminUser); $this->addElement($adminUser);
@ -215,16 +175,16 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
->setValidators(array( ->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
if ($disable_all) {
$adminPass->setAttrib("disabled", "disabled");
}
$adminPass->setAttrib('alt', 'regular_text'); $adminPass->setAttrib('alt', 'regular_text');
$this->addElement($adminPass); $this->addElement($adminPass);
$liquidsoap_error_msg = '<div class="stream-status status-info"><h3>'._('Getting information from the server...').'</h3></div>'; $liquidsoap_error_msg = '<div class="stream-status status-info"><h3>'._('Getting information from the server...').'</h3></div>';
$this->setDecorators(array( $this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml', "stream_number"=>$stream_number, "enabled"=>$enable->getValue(), "liquidsoap_error_msg"=>$liquidsoap_error_msg)) array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml',
"stream_number"=>$stream_number,
"enabled"=>$enable->getValue(),
"liquidsoap_error_msg"=>$liquidsoap_error_msg))
)); ));
} }
@ -232,7 +192,7 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
{ {
$f_data = $data['s'.$this->prefix."_data"]; $f_data = $data['s'.$this->prefix."_data"];
$isValid = parent::isValid($f_data); $isValid = parent::isValid($f_data);
if ($f_data) { if (Application_Model_Preference::getUsingCustomStreamSettings() && $f_data) {
if ($f_data['enable'] == 1) { if ($f_data['enable'] == 1) {
if ($f_data['host'] == '') { if ($f_data['host'] == '') {
$element = $this->getElement("host"); $element = $this->getElement("host");
@ -256,4 +216,16 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
return $isValid; return $isValid;
} }
public function toggleState() {
$elements = $this->getElements();
foreach ($elements as $element) {
if (Application_Model_Preference::getUsingCustomStreamSettings()) {
$element->setAttrib('disabled', null);
} else if (!(in_array($element->getName(), static::$customizable)
|| $element->getType() == 'Zend_Form_Element_Hidden')) {
$element->setAttrib('disabled', 'disabled');
}
}
}
} }

View File

@ -38,11 +38,6 @@
<?php echo $this->form->getElement('icecast_vorbis_metadata') ?> <?php echo $this->form->getElement('icecast_vorbis_metadata') ?>
</dd> </dd>
<?php
// TODO: replace this with something that looks good
echo $this->form->getElement('customStreamSettings')->render();
?>
<dt id="streamFormat-label"> <dt id="streamFormat-label">
<label class="optional"><?php echo $this->form->getElement('streamFormat')->getLabel() ?></label> <label class="optional"><?php echo $this->form->getElement('streamFormat')->getLabel() ?></label>
</dt> </dt>
@ -110,13 +105,11 @@
<fieldset class="padded"> <fieldset class="padded">
<legend><?php echo _("Output Stream Settings") ?></legend> <legend><?php echo _("Output Stream Settings") ?></legend>
<?php <?php
if (Application_Model_Preference::getUsingCustomStreamSettings()) { // TODO: replace this with something that looks good
echo $this->form->getElement('customStreamSettings')->render();
for($i=1;$i<=$this->num_stream;$i++){ for($i=1;$i<=$this->num_stream;$i++){
echo $this->form->getSubform("s".$i."_subform"); echo $this->form->getSubform("s".$i."_subform");
} }
} else {
// TODO: replace this with something that looks good
}
?> ?>
</fieldset> </fieldset>
<br /> <br />

View File

@ -1867,6 +1867,7 @@ span.errors.sp-errors{
margin:8px 0 0 0; margin:8px 0 0 0;
cursor:pointer; cursor:pointer;
position:relative; position:relative;
clear: both;
} }
.collapsible-content { .collapsible-content {
margin-top:-1px; margin-top:-1px;

View File

@ -476,10 +476,11 @@ $(document).ready(function() {
var url = baseUrl+'Preference/stream-setting'; var url = baseUrl+'Preference/stream-setting';
$.post(url, {format:"json", data: data}, function(json){ $.post(url, {format:"json", data: data}, function(json){
$('#content').empty().append(json.html); window.location.reload();
setupEventListeners(); //$('#content').empty().append(json.html);
setSliderForReplayGain(); //setupEventListeners();
setPseudoAdminPassword(json.s1_set_admin_pass, json.s2_set_admin_pass, json.s3_set_admin_pass, json.s4_set_admin_pass); //setSliderForReplayGain();
//setPseudoAdminPassword(json.s1_set_admin_pass, json.s2_set_admin_pass, json.s3_set_admin_pass, json.s4_set_admin_pass);
}); });
} }
}); });