More work on show image uploads
This commit is contained in:
parent
cb80423fdd
commit
5434311f7d
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
$filepath = realpath (dirname(__FILE__));
|
||||
require_once($filepath."/../modules/rest/controllers/MediaController.php");
|
||||
|
||||
class ScheduleController extends Zend_Controller_Action
|
||||
{
|
||||
|
||||
|
@ -553,7 +556,6 @@ class ScheduleController extends Zend_Controller_Action
|
|||
public function addShowAction()
|
||||
{
|
||||
$service_showForm = new Application_Service_ShowFormService(null);
|
||||
//$service_show = new Application_Service_ShowService();
|
||||
|
||||
$js = $this->_getParam('data');
|
||||
$data = array();
|
||||
|
@ -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);
|
||||
|
@ -753,4 +773,5 @@ class ScheduleController extends Zend_Controller_Action
|
|||
|
||||
$this->_helper->json->sendJson($localTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 939 B |
|
@ -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);
|
||||
},
|
||||
|
@ -631,7 +631,21 @@ function setAddShowEvents(form) {
|
|||
var end_date = $("#add_show_end_date").val();
|
||||
var action = baseUrl+"Schedule/"+String(addShowButton.attr("data-action"));
|
||||
|
||||
$.post(action, {format: "json", data: data, hosts: hosts, days: days}, function(json){
|
||||
var image = new FormData();
|
||||
image.append('show-image', $('#upload')[0].files[0]);
|
||||
|
||||
$.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'
|
||||
});
|
||||
|
||||
$('#schedule-add-show').unblock();
|
||||
|
||||
|
@ -644,9 +658,7 @@ function setAddShowEvents(form) {
|
|||
$("#add_show_end_date").val(end_date);
|
||||
$("#add_show_start_date").val(start_date);
|
||||
showErrorSections();
|
||||
}
|
||||
else if (json.edit) {
|
||||
|
||||
} else if (json.edit) {
|
||||
$("#schedule_calendar").removeAttr("style")
|
||||
.fullCalendar('render');
|
||||
|
||||
|
@ -655,12 +667,11 @@ function setAddShowEvents(form) {
|
|||
redrawAddShowForm($addShowForm, json.form);
|
||||
});
|
||||
makeAddShowButton();
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
redrawAddShowForm($addShowForm, json.newForm);
|
||||
scheduleRefetchEvents(json);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue