From ac2e1a2d4bc55b29027f280839407d492121077c Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Wed, 8 Jul 2015 16:04:09 -0400 Subject: [PATCH] SAAS-876 - More work on stream settings page --- .../controllers/PreferenceController.php | 5 +- .../application/forms/StreamSetting.php | 4 +- .../forms/StreamSettingSubForm.php | 76 ++++++------------- .../scripts/preference/stream-setting.phtml | 15 +--- airtime_mvc/public/css/styles.css | 1 + .../js/airtime/preferences/streamsetting.js | 9 ++- 6 files changed, 38 insertions(+), 72 deletions(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 16c2bf2b3..3ee1be528 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -248,9 +248,7 @@ class PreferenceController extends Zend_Controller_Action 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 = "
"._("Stream Setting Updated.")."
"; } } @@ -293,6 +291,7 @@ class PreferenceController extends Zend_Controller_Action $subform->setStreamTypes($stream_types); $subform->setStreamBitrates($stream_bitrates); $subform->startForm(); + $subform->toggleState(); $form->addSubForm($subform, "s".$i."_subform"); } diff --git a/airtime_mvc/application/forms/StreamSetting.php b/airtime_mvc/application/forms/StreamSetting.php index 1f149eae4..bbef95ca3 100644 --- a/airtime_mvc/application/forms/StreamSetting.php +++ b/airtime_mvc/application/forms/StreamSetting.php @@ -62,8 +62,8 @@ class Application_Form_StreamSetting extends Zend_Form $custom = Application_Model_Preference::getUsingCustomStreamSettings(); $customSettings = new Zend_Form_Element_Radio('customStreamSettings'); - $customSettings->setLabel(_('Stream Settings:')); - $customSettings->setMultiOptions(array(_("Default"), _("Use Custom"))); + $customSettings->setLabel(_('Streaming Server:')); + $customSettings->setMultiOptions(array(_("Airtime Pro Streaming"), _("Custom / 3rd Party"))); $customSettings->setValue(!empty($custom) ? $custom : 0); $this->addElement($customSettings); } diff --git a/airtime_mvc/application/forms/StreamSettingSubForm.php b/airtime_mvc/application/forms/StreamSettingSubForm.php index 435d465da..fe6c95d89 100644 --- a/airtime_mvc/application/forms/StreamSettingSubForm.php +++ b/airtime_mvc/application/forms/StreamSettingSubForm.php @@ -6,6 +6,8 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm private $stream_types; private $stream_bitrates; + static $customizable; + public function init() { @@ -42,51 +44,41 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm $this->setIsArray(true); $this->setElementsBelongTo($prefix."_data"); - $disable_all = !Application_Model_Preference::getUsingCustomStreamSettings(); - $enable = new Zend_Form_Element_Checkbox('enable'); $enable->setLabel(_('Enabled:')) ->setValue($setting[$prefix.'_enable'] == 'true' ? 1 : 0) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $enable->setAttrib("disabled", "disabled"); - } $this->addElement($enable); + static::$customizable[] = $enable->getName(); $mobile = new Zend_Form_Element_Checkbox('mobile'); $mobile->setLabel(_('Mobile:')); $mobile->setValue($setting[$prefix.'_mobile']); $mobile->setDecorators(array('ViewHelper')); $this->addElement($mobile); + static::$customizable[] = $mobile->getName(); $type = new Zend_Form_Element_Select('type'); $type->setLabel(_("Stream Type:")) ->setMultiOptions($stream_types) ->setValue(isset($setting[$prefix.'_type'])?$setting[$prefix.'_type']:0) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $type->setAttrib("disabled", "disabled"); - } $this->addElement($type); + static::$customizable[] = $type->getName(); $bitrate = new Zend_Form_Element_Select('bitrate'); $bitrate->setLabel(_("Bit Rate:")) ->setMultiOptions($stream_bitrates) ->setValue(isset($setting[$prefix.'_bitrate'])?$setting[$prefix.'_bitrate']:0) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $bitrate->setAttrib("disabled", "disabled"); - } $this->addElement($bitrate); + static::$customizable[] = $bitrate->getName(); $output = new Zend_Form_Element_Select('output'); $output->setLabel(_("Service Type:")) ->setMultiOptions(array("icecast"=>"Icecast", "shoutcast"=>"SHOUTcast")) ->setValue(isset($setting[$prefix.'_output'])?$setting[$prefix.'_output']:"icecast") ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $output->setAttrib("disabled", "disabled"); - } $this->addElement($output); $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"))) ->setValue(isset($setting[$prefix.'_channels']) ? $setting[$prefix.'_channels'] : "stereo") ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $channels->setAttrib("disabled", "disabled"); - } $this->addElement($channels); + static::$customizable[] = $channels->getName(); $host = new Zend_Form_Element_Text('host'); $host->setLabel(_("Server")) @@ -105,9 +95,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[0-9a-zA-Z-_.]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $host->setAttrib("disabled", "disabled"); - } $host->setAttrib('alt', 'domain'); $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)))) ->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.')))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $port->setAttrib("disabled", "disabled"); - } $this->addElement($port); $pass = new Zend_Form_Element_Text('pass'); @@ -128,9 +112,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $pass->setAttrib("disabled", "disabled"); - } $pass->setAttrib('alt', 'regular_text'); $this->addElement($pass); @@ -138,9 +119,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm $genre->setLabel(_("Genre")) ->setValue(isset($setting[$prefix.'_genre'])?$setting[$prefix.'_genre']:"") ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $genre->setAttrib("disabled", "disabled"); - } $this->addElement($genre); $url = new Zend_Form_Element_Text('url'); @@ -149,9 +127,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[0-9a-zA-Z\-_.:\/]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $url->setAttrib("disabled", "disabled"); - } $url->setAttrib('alt', 'url'); $this->addElement($url); @@ -159,18 +134,12 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm $name->setLabel(_("Name")) ->setValue(isset($setting[$prefix.'_name'])?$setting[$prefix.'_name']:"") ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $name->setAttrib("disabled", "disabled"); - } $this->addElement($name); $description = new Zend_Form_Element_Text('description'); $description->setLabel(_("Description")) ->setValue(isset($setting[$prefix.'_description'])?$setting[$prefix.'_description']:"") ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $description->setAttrib("disabled", "disabled"); - } $this->addElement($description); $mount = new Zend_Form_Element_Text('mount'); @@ -179,9 +148,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $mount->setAttrib("disabled", "disabled"); - } $mount->setAttrib('alt', 'regular_text'); $this->addElement($mount); @@ -191,9 +157,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $user->setAttrib("disabled", "disabled"); - } $user->setAttrib('alt', 'regular_text'); $this->addElement($user); @@ -203,9 +166,6 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $adminUser->setAttrib("disabled", "disabled"); - } $adminUser->setAttrib('alt', 'regular_text'); $this->addElement($adminUser); @@ -215,16 +175,16 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm ->setValidators(array( array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered'))))) ->setDecorators(array('ViewHelper')); - if ($disable_all) { - $adminPass->setAttrib("disabled", "disabled"); - } $adminPass->setAttrib('alt', 'regular_text'); $this->addElement($adminPass); $liquidsoap_error_msg = '

'._('Getting information from the server...').'

'; $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"]; $isValid = parent::isValid($f_data); - if ($f_data) { + if (Application_Model_Preference::getUsingCustomStreamSettings() && $f_data) { if ($f_data['enable'] == 1) { if ($f_data['host'] == '') { $element = $this->getElement("host"); @@ -256,4 +216,16 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm 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'); + } + } + } } diff --git a/airtime_mvc/application/views/scripts/preference/stream-setting.phtml b/airtime_mvc/application/views/scripts/preference/stream-setting.phtml index 32d1b034d..a2abe8835 100644 --- a/airtime_mvc/application/views/scripts/preference/stream-setting.phtml +++ b/airtime_mvc/application/views/scripts/preference/stream-setting.phtml @@ -38,11 +38,6 @@ form->getElement('icecast_vorbis_metadata') ?> - form->getElement('customStreamSettings')->render(); - ?> -
@@ -110,12 +105,10 @@
num_stream;$i++){ - echo $this->form->getSubform("s".$i."_subform"); - } - } else { - // TODO: replace this with something that looks good + // TODO: replace this with something that looks good + echo $this->form->getElement('customStreamSettings')->render(); + for($i=1;$i<=$this->num_stream;$i++){ + echo $this->form->getSubform("s".$i."_subform"); } ?>
diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 5d9bc4a67..e6b1e1082 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -1867,6 +1867,7 @@ span.errors.sp-errors{ margin:8px 0 0 0; cursor:pointer; position:relative; + clear: both; } .collapsible-content { margin-top:-1px; diff --git a/airtime_mvc/public/js/airtime/preferences/streamsetting.js b/airtime_mvc/public/js/airtime/preferences/streamsetting.js index 54e397da6..8c4cc9c14 100644 --- a/airtime_mvc/public/js/airtime/preferences/streamsetting.js +++ b/airtime_mvc/public/js/airtime/preferences/streamsetting.js @@ -476,10 +476,11 @@ $(document).ready(function() { var url = baseUrl+'Preference/stream-setting'; $.post(url, {format:"json", data: data}, function(json){ - $('#content').empty().append(json.html); - setupEventListeners(); - setSliderForReplayGain(); - setPseudoAdminPassword(json.s1_set_admin_pass, json.s2_set_admin_pass, json.s3_set_admin_pass, json.s4_set_admin_pass); + window.location.reload(); + //$('#content').empty().append(json.html); + //setupEventListeners(); + //setSliderForReplayGain(); + //setPseudoAdminPassword(json.s1_set_admin_pass, json.s2_set_admin_pass, json.s3_set_admin_pass, json.s4_set_admin_pass); }); } });