diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index 1d9f76612..6ec7d72e5 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -84,7 +84,7 @@ class PreferenceController extends Zend_Controller_Action $form = new Application_Form_SupportSettings(); if ($request->isPost()) { $values = $request->getPost(); - if ($form->isValid($values)) { + if ($form->isValid($values)) { Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view); Application_Model_Preference::SetPhone($values["Phone"]); Application_Model_Preference::SetEmail($values["Email"]); diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 46bbe710d..eb6e70d63 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -1,5 +1,8 @@ _getParam('data'); $data = array(); @@ -566,9 +568,9 @@ class ScheduleController extends Zend_Controller_Action $service_show = new Application_Service_ShowService(null, $data); // TODO: move this to js - $data['add_show_hosts'] = $this->_getParam('hosts'); - $data['add_show_day_check'] = $this->_getParam('days'); - + $data['add_show_hosts'] = $this->_getParam('hosts'); + $data['add_show_day_check'] = $this->_getParam('days'); + if ($data['add_show_day_check'] == "") { $data['add_show_day_check'] = null; } @@ -580,13 +582,17 @@ class ScheduleController extends Zend_Controller_Action $log_vars["params"]["form_data"] = $data; Logging::info($log_vars); - $request = $this->getRequest(); - Logging::info($request); - $forms = $this->createShowFormAction(); $this->view->addNewShow = true; - + + /* + * hack to prevent validating the file upload field since it + * isn't passed into $data + */ + $upload = $forms["style"]->getElement("upload"); + $forms["style"]->removeElement("upload"); + if ($service_showForm->validateShowForms($forms, $data)) { $service_show->addUpdateShow($data); @@ -596,11 +602,25 @@ class ScheduleController extends Zend_Controller_Action Logging::debug("Show creation succeeded"); } else { + // re-add the element + $forms["style"]->addElement($upload); + $this->view->form = $this->view->render('schedule/add-show-form.phtml'); Logging::debug("Show creation failed"); } } - + + /** + * Since the form is being submitted via jQuery, this function accepts + * a second AJAX request and writes the file (sent as a FormData object) + */ + public function uploadImageAction() + { + Rest_MediaController::processUploadedImage( + $_FILES["show-image"]["tmp-name"], + $_FILES["show-image"]["name"]); + } + public function createShowFormAction($populateDefaults=false) { $service_showForm = new Application_Service_ShowFormService(); @@ -682,7 +702,7 @@ class ScheduleController extends Zend_Controller_Action $paramsPop = str_replace('#id#', $id, $params); - // added for downlaod + // added for download $id = $this->_getParam('id'); $file_id = $this->_getParam('id', null); @@ -707,7 +727,7 @@ class ScheduleController extends Zend_Controller_Action 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. */ @@ -753,4 +773,5 @@ class ScheduleController extends Zend_Controller_Action $this->_helper->json->sendJson($localTime); } + } diff --git a/airtime_mvc/application/forms/AddShowStyle.php b/airtime_mvc/application/forms/AddShowStyle.php index addcf75eb..fe0dac740 100644 --- a/airtime_mvc/application/forms/AddShowStyle.php +++ b/airtime_mvc/application/forms/AddShowStyle.php @@ -46,7 +46,6 @@ class Application_Form_AddShowStyle extends Zend_Form_SubForm // Add show image input $fileCountValidator = Application_Form_Helper_ValidationTypes::overrideFileCountValidator(1); - $fileSizeValidator = Application_Form_Helper_ValidationTypes::overrideFileSizeValidator(array('max' => '5120000')); $fileExtensionValidator = Application_Form_Helper_ValidationTypes::overrideFileExtensionValidator('jpg,png,gif'); $upload = new Zend_Form_Element_File('upload'); @@ -58,31 +57,13 @@ class Application_Form_AddShowStyle extends Zend_Form_SubForm 'class' => 'big', 'placement' => false )))) - ->addValidator('Count', false, 1) - ->addValidator('Extension', false, 'jpg,jpeg,png,gif') + ->addValidators(array( + $fileCountValidator, + $fileExtensionValidator + )) ->addFilter('ImageSize'); + $this->addElement($upload); - -// $this->addElement('file', 'add_show_image', array( -// 'disableLoadDefaultDecorators' => true, -// 'decorators' => array('File', array('ViewScript', array( -// 'viewScript' => 'form/add-show-style.phtml', -// 'class' => 'big', -// 'placement' => false -// ))), -// 'label' => _('Show Image:'), -// 'class' => 'input_file', -// 'required' => false, -// 'validators' => array( -// $fileCountValidator, -// $fileSizeValidator, -// $fileExtensionValidator), -// 'destination' => '../public/images/upload', -// 'method' => 'post' -// )); - - // Change form enctype to accommodate file upload - $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART); } public function disable() diff --git a/airtime_mvc/application/forms/helpers/ValidationTypes.php b/airtime_mvc/application/forms/helpers/ValidationTypes.php index 0ea46964a..5a2bc52f1 100644 --- a/airtime_mvc/application/forms/helpers/ValidationTypes.php +++ b/airtime_mvc/application/forms/helpers/ValidationTypes.php @@ -105,18 +105,6 @@ Class Application_Form_Helper_ValidationTypes { return $validator; } - public static function overrideFileSizeValidator($p_fileSize) - { - $validator = new Zend_Validate_File_Size($p_fileSize); - - $validator->setMessage( - _("The uploaded file is too large. Please limit your upload to '%max%'"), - Zend_Validate_File_Size::TOO_BIG - ); - - return $validator; - } - public static function overrideFileExtensionValidator($p_fileExtensions) { $validator = new Zend_Validate_File_Extension($p_fileExtensions); diff --git a/airtime_mvc/application/views/scripts/schedule/upload-image.phtml b/airtime_mvc/application/views/scripts/schedule/upload-image.phtml new file mode 100644 index 000000000..e69de29bb diff --git a/airtime_mvc/public/images/upload/OVERWERK - Alive.mp3 b/airtime_mvc/public/images/upload/OVERWERK - Alive.mp3 new file mode 100644 index 000000000..dfb488ba9 Binary files /dev/null and b/airtime_mvc/public/images/upload/OVERWERK - Alive.mp3 differ diff --git a/airtime_mvc/public/images/upload/test_image.jpg b/airtime_mvc/public/images/upload/test_image.jpg new file mode 100644 index 000000000..739c47bb1 Binary files /dev/null and b/airtime_mvc/public/images/upload/test_image.jpg differ diff --git a/airtime_mvc/public/js/airtime/schedule/add-show.js b/airtime_mvc/public/js/airtime/schedule/add-show.js index 3dbd74b8a..34b0b040f 100644 --- a/airtime_mvc/public/js/airtime/schedule/add-show.js +++ b/airtime_mvc/public/js/airtime/schedule/add-show.js @@ -8,7 +8,7 @@ function openAddShowForm() { if($("#add-show-form").length == 1) { if( ($("#add-show-form").css('display')=='none')) { $("#add-show-form").show(); - $("#add-show-form").prop("enctype", "multipart/form-data"); + $("#upload").prop("accept", "image/*"); /* var windowWidth = $(window).width(); @@ -581,7 +581,7 @@ function setAddShowEvents(form) { } }) - form.find("#schedule-show-style input .input_text").ColorPicker({ + form.find("#schedule-show-style .input_text").ColorPicker({ onChange: function (hsb, hex, rgb, el) { $(el).val(hex); }, @@ -630,37 +630,48 @@ function setAddShowEvents(form) { var start_date = $("#add_show_start_date").val(); var end_date = $("#add_show_end_date").val(); var action = baseUrl+"Schedule/"+String(addShowButton.attr("data-action")); + + var image = new FormData(); + image.append('show-image', $('#upload')[0].files[0]); - $.post(action, {format: "json", data: data, hosts: hosts, days: days}, function(json){ - - $('#schedule-add-show').unblock(); - - var $addShowForm = $("#add-show-form"); - - if (json.form) { - - redrawAddShowForm($addShowForm, json.form); + $.ajax({ + url: action, + data: {format: "json", data: data, hosts: hosts, days: days}, + success: function(json) { + $.ajax({ + url: '/Schedule/upload-image', + data: image, + cache: false, + contentType: false, + processData: false, + type: 'POST' + }); - $("#add_show_end_date").val(end_date); - $("#add_show_start_date").val(start_date); - showErrorSections(); - } - else if (json.edit) { - - $("#schedule_calendar").removeAttr("style") - .fullCalendar('render'); - - $addShowForm.hide(); - $.get(baseUrl+"Schedule/get-form", {format:"json"}, function(json){ - redrawAddShowForm($addShowForm, json.form); - }); - makeAddShowButton(); - } - else { - - redrawAddShowForm($addShowForm, json.newForm); - scheduleRefetchEvents(json); - } + $('#schedule-add-show').unblock(); + + var $addShowForm = $("#add-show-form"); + + if (json.form) { + + redrawAddShowForm($addShowForm, json.form); + + $("#add_show_end_date").val(end_date); + $("#add_show_start_date").val(start_date); + showErrorSections(); + } else if (json.edit) { + $("#schedule_calendar").removeAttr("style") + .fullCalendar('render'); + + $addShowForm.hide(); + $.get(baseUrl+"Schedule/get-form", {format:"json"}, function(json){ + redrawAddShowForm($addShowForm, json.form); + }); + makeAddShowButton(); + } else { + redrawAddShowForm($addShowForm, json.newForm); + scheduleRefetchEvents(json); + } + } }); });