From 78c7170c4e629a887799b116fdf9cbe41abc3ea3 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Fri, 27 Feb 2015 17:19:37 -0500 Subject: [PATCH 1/5] Reformatted logo remove button to use Zend --- airtime_mvc/application/forms/GeneralPreferences.php | 7 +++++++ .../views/scripts/form/preferences_general.phtml | 6 ++++-- airtime_mvc/public/css/styles.css | 7 ++++++- airtime_mvc/public/js/airtime/preferences/preferences.js | 9 +++++---- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/forms/GeneralPreferences.php b/airtime_mvc/application/forms/GeneralPreferences.php index 52f14332a..aa2906d82 100644 --- a/airtime_mvc/application/forms/GeneralPreferences.php +++ b/airtime_mvc/application/forms/GeneralPreferences.php @@ -49,6 +49,13 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm $stationLogoUpload->setAttrib('accept', 'image/*'); $this->addElement($stationLogoUpload); + $stationLogoRemove = new Zend_Form_Element_Button('stationLogoRemove'); + $stationLogoRemove->setLabel(_('Remove')); + $stationLogoRemove->setAttrib('class', 'btn'); + $stationLogoRemove->setAttrib('id', 'logo-remove-btn'); + $stationLogoRemove->setAttrib('onclick', 'removeLogo();'); + $this->addElement($stationLogoRemove); + //Default station crossfade duration $this->addElement('text', 'stationDefaultCrossfadeDuration', array( 'class' => 'input_text', diff --git a/airtime_mvc/application/views/scripts/form/preferences_general.phtml b/airtime_mvc/application/views/scripts/form/preferences_general.phtml index 99cb4384c..85e9a9b7e 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_general.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_general.phtml @@ -7,10 +7,12 @@ element->getElement('stationLogo')->render() ?> - + element->getElement('stationLogoRemove')->render() ?> + +
- +
element->getElement('locale')->render() ?> diff --git a/airtime_mvc/public/css/styles.css b/airtime_mvc/public/css/styles.css index 05987d876..44e0db75b 100644 --- a/airtime_mvc/public/css/styles.css +++ b/airtime_mvc/public/css/styles.css @@ -2187,12 +2187,17 @@ dd.radio-inline-list, .preferences dd.radio-inline-list, .stream-config dd.radio height: 120px; } +.preferences #stationLogoRemove-label { + display: none; +} + .preferences #logo-remove-btn { float: right; + margin-bottom: 4px; } .preferences #Logo-img-container { - float: left; + margin-top: 30px; } #show_time_info { diff --git a/airtime_mvc/public/js/airtime/preferences/preferences.js b/airtime_mvc/public/js/airtime/preferences/preferences.js index f7875ec7b..faef03218 100644 --- a/airtime_mvc/public/js/airtime/preferences/preferences.js +++ b/airtime_mvc/public/js/airtime/preferences/preferences.js @@ -96,6 +96,11 @@ function setSoundCloudCheckBoxListener() { }); } +function removeLogo() { + $.post(baseUrl+'Preference/remove-logo', function(json){}); + location.reload(); +} + $(document).ready(function() { $('.collapsible-header').live('click',function() { @@ -104,10 +109,6 @@ $(document).ready(function() { return false; }).next().hide(); - $('#logo-remove-btn').click(function() { - $.post(baseUrl+'Preference/remove-logo', function(json){}); - }); - /* No longer using AJAX for this form. Zend + our code makes it needlessly hard to deal with. -- Albert $('#pref_save').live('click', function() { var data = $('#pref_form').serialize(); From 13bd0b758934d4fe229fde33560b459d5cdcd424 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 2 Mar 2015 14:57:50 -0500 Subject: [PATCH 2/5] Fixed removing image when saving preferences with no upload --- .../application/controllers/PreferenceController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 09188b93d..7d23a958e 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -51,7 +51,11 @@ class PreferenceController extends Zend_Controller_Action $logoUploadElement = $form->getSubForm('preferences_general')->getElement('stationLogo'); $logoUploadElement->receive(); $imagePath = $logoUploadElement->getFileName(); - Application_Model_Preference::SetStationLogo($imagePath); + + // Only update the image logo if the new logo is non-empty + if (!is_null($imagePath) && $imagePath != "") { + Application_Model_Preference::SetStationLogo($imagePath); + } Application_Model_Preference::SetEnableSystemEmail($values["enableSystemEmail"]); Application_Model_Preference::SetSystemEmail($values["systemEmail"]); From b6a6f038a96711ef09799b31284177c268566e9a Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 2 Mar 2015 15:10:04 -0500 Subject: [PATCH 3/5] Added call to setStationDescription in preferences action --- airtime_mvc/application/controllers/PreferenceController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 7d23a958e..0e13eb3ec 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -40,6 +40,7 @@ class PreferenceController extends Zend_Controller_Action if ($form->isValid($values)) { Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); + Application_Model_Preference::SetStationDescription($values["stationDescription"]); Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]); Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]); Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]); From 0272eaef444892263afd6b626c1d13cc122f7a6e Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 2 Mar 2015 15:25:52 -0500 Subject: [PATCH 4/5] Changed is_null to empty --- airtime_mvc/application/controllers/PreferenceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 0e13eb3ec..25aae1d10 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -54,7 +54,7 @@ class PreferenceController extends Zend_Controller_Action $imagePath = $logoUploadElement->getFileName(); // Only update the image logo if the new logo is non-empty - if (!is_null($imagePath) && $imagePath != "") { + if (!empty($imagePath) && $imagePath != "") { Application_Model_Preference::SetStationLogo($imagePath); } From 17d51eb0f9e133e8dd64bd4a03eb8f8fd1c1e44a Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 2 Mar 2015 16:00:11 -0500 Subject: [PATCH 5/5] Added csrf verification to show image upload and deletion --- airtime_mvc/application/forms/AddShowStyle.php | 10 +++++++++- airtime_mvc/public/js/airtime/schedule/add-show.js | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/airtime_mvc/application/forms/AddShowStyle.php b/airtime_mvc/application/forms/AddShowStyle.php index d6e97e019..7d79a90e9 100644 --- a/airtime_mvc/application/forms/AddShowStyle.php +++ b/airtime_mvc/application/forms/AddShowStyle.php @@ -79,7 +79,7 @@ class Application_Form_AddShowStyle extends Zend_Form_SubForm ->addValidator('Count', false, 1) ->addValidator('Extension', false, 'jpg,jpeg,png,gif') ->addFilter('ImageSize'); - + $this->addElement($upload); // Add image preview @@ -93,6 +93,14 @@ class Application_Form_AddShowStyle extends Zend_Form_SubForm 'class' => 'big' )))); $preview->setAttrib('disabled','disabled'); + + $csrf_namespace = new Zend_Session_Namespace('csrf_namespace'); + $csrf_element = new Zend_Form_Element_Hidden('csrf'); + $csrf_element->setValue($csrf_namespace->authtoken) + ->setRequired('true') + ->removeDecorator('HtmlTag') + ->removeDecorator('Label'); + $this->addElement($csrf_element); } public function disable() diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index aee048fd8..a8c9f76e7 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -668,7 +668,7 @@ function setAddShowEvents(form) { var showId = $("#add_show_id").attr("value"); if (showId && $("#add_show_logo_current").attr("src") !== "") { - var action = '/rest/show-image?id=' + showId; + var action = '/rest/show-image?csrf_token=' + $('#csrf').val() + '&id=' + showId; $.ajax({ url: action, @@ -748,7 +748,7 @@ function setAddShowEvents(form) { data: {format: "json", data: data, hosts: hosts, days: days}, success: function(json) { if (json.showId && image) { // Successfully added the show, and it contains an image to upload - var imageAction = '/rest/show-image?id=' + json.showId; + var imageAction = '/rest/show-image?csrf_token=' + $('#csrf').val() + '&id=' + json.showId; // perform a second xhttprequest in order to send the show image $.ajax({