public function render($name, $value = array(), $attributes = array(), $errors = array()) { $widget = array(); use_javascript('jquery.tooltip/jquery.tooltip.js'); use_stylesheet('../js/jquery.tooltip/jquery.tooltip.css'); $widget['%thumbnails%'] = ''; $widget['%thumbnails%'] .= ''; $j = 0; foreach ($value as $j => $image) { if (!isset($image['id'])) { continue; } $fileIdInput = new sfWidgetFormInputHidden(); $fileNameInput = new sfWidgetFormInputHidden(); $commentInput = new sfWidgetFormInput(array(), array('maxlength' => 255)); $largeInput = new sfWidgetFormInputHidden(); $thumbnailInput = new sfWidgetFormInputHidden(); $widget['%thumbnails%'] .= '<div class="upload_item" style="margin-bottom: 10px;" >' . '<span style="display: inline; width: 260px; float: left; text-align: center; padding-top: 10px;">' . link_to($image['name'], strval($image['Large']), array('class' => 'preview', 'rel' => strval($image['Thumbnail']))) . '</span>' . ' ' . $thumbnailInput->render($name . "[" . $j . "][Thumbnail]", strval($image['Thumbnail']), array()) . $largeInput->render($name . "[" . $j . "][Large]", strval($image['Large']), array()) . $fileNameInput->render($name . "[" . $j . "][name]", $image['name'], array()) . $fileIdInput->render($name . "[" . $j . "][id]", $image['id'], array()) . '<span>Title:</span>' . $commentInput->render($name . "[" . $j . "][description]", $image['description'], array('class' => 'text input-mercha-account')) . ' <a href="#" class="del-photo"><img src="/images/cross.gif" style="vertical-align:middle;" /></a>' . '</div>'; } $i = $j + 1; $fileInput = new sfWidgetFormInputFile(); $commentInput = new sfWidgetFormInput(); $widget['%thumbnails%'] .= '<div class="upload_item" style="margin-bottom: 10px;" >' . $fileInput->render($name . "[" . $i . "][file]", null, array('class' => '', 'style' => "padding-left:0px; width: 260px; padding:0px; ")) . ' ' . '<span>Title:</span>' . $commentInput->render($name . "[" . $i . "][description]", null, array('class' => 'text input-mercha-account')) . ' <a href="#" class="del-photo" style="vertical-align:middle;"><img src="/images/cross.gif" /></a>' . '</div>' . '<div class=" add-another-location bottom_add_new_category_link" style="padding-top: 0px; padding-bottom: 15px;">' . '<div class="plus_category">' . '<div class="left margin1"><img src="/images/plus.gif" /></div>' . '<div class="left margin_top3"><a href="#" class="add-photo">Add Another Photo</a></div>' . '</div>' . '</div>'; $js = jq_javascript_tag("\r\n jQuery(document).ready(function(){\r\n i = jQuery('.upload_item').length + 1;\r\n \r\n jQuery('a.del-photo').live('click', function(e){\r\n e.preventDefault();\r\n jQuery(this).parents('.upload_item').remove();\r\n });\r\n \r\n jQuery('.preview').tooltip({ \r\n delay: 0, \r\n showURL: false, \r\n bodyHandler: function() { \r\n return jQuery('<img/>').attr('src', jQuery(this).attr('rel')); \r\n } \r\n });\r\n \r\n jQuery('a.add-photo').live('click', function(e){\r\n \r\n e.preventDefault();\r\n \r\n var already = jQuery('.upload_item');\r\n \r\n var newUpload = '';\r\n \r\n var maxCount = " . intval($this->getOption('max_count')) . ";\r\n \r\n if ((maxCount > 0 && already.length < maxCount) || maxCount == 0) {\r\n \r\n newUpload = \r\n '<div class=\\'upload_item\\' style=\\'margin-bottom: 10px;\\'><input type=\\'file\\' name=\\'" . $name . "[' + i + '][file]" . "\\' class=\"\" style=\"padding-left:0px; width: 260px; padding:0px; \" />' +\n ' <span>Title:</span>' +\r\n '<input type=\\'text\\' name=\\'" . $name . "[' + i + '][description]" . "\\' class=\\'text input-mercha-account\\' >';\r\n \r\n newUpload += \r\n ' <a href=\\'#\\' class=\\'del-photo\\'><img src=\\'/images/cross.gif\\' style=\\'vertical-align:middle;\\' /></a>';\r\n \r\n \r\n \r\n newUpload += '</div>';\r\n \r\n jQuery(newUpload).insertBefore(jQuery(this).parents('div.add-another-location'));\r\n i++;\r\n }\r\n })\r\n \r\n });\r\n "); return $js . '<div id="uploader" style="width: 590px;">' . strtr($this->getOption('template'), $widget) . '</div>'; }
public function render($name, $value = null, $attributes = array(), $errors = array()) { $i18n = sfContext::getInstance()->getI18N(); $widget = new sfWidgetFormInputFile(array(), $attributes); $file = '<dt>' . $i18n->__($this->getOption('file_label')) . '</dt>' . '<dd>' . $widget->render($name . '[file]', null, array('id' => $this->generateId($name))) . '</dd>'; $widget = new sfWidgetFormInput(array(), $attributes); $description = '<dt>' . $i18n->__($this->getOption('description_label')) . '</dt>' . '<dd>' . $widget->render($name . '[description]') . '</dd>'; $emptyValues = $this->getOption('empty_values'); return '<dl>' . $file . $description . '</dl>'; }
/** * @param string $name The element name * @param string $value The value displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $input = parent::render($name, $value, $attributes, $errors); $object = $this->getOption('invoker'); if (!$object->exists()) { return $input; } if (class_exists('sfJSLibManager')) { sfJSLibManager::addLib('jcrop'); } if ($this->getOption('with_delete')) { $deleteName = ']' == substr($name, -1) ? substr($name, 0, -1) . '_delete]' : $name . '_delete'; $form = $this->getOption('form'); if ($form->getOption('embedded', false) && $form->getOption('parent_model', false)) { $delete = $form->getOption('parent_model')->getDeleteLinkFor($object); $deleteLabel = ''; } else { $delete = $this->renderTag('input', array_merge(array('type' => 'checkbox', 'name' => $deleteName), $attributes)); $deleteLabel = $this->renderContentTag('label', $this->getOption('delete_label'), array_merge(array('for' => $this->generateId($deleteName)))); } } else { $delete = ''; $deleteLabel = ''; } return strtr($this->getOption('template') . $this->getJCropJS(), array('%input%' => $input, '%delete%' => $delete, '%delete_label%' => $deleteLabel, '%file%' => $this->getFileAsTag($attributes))); }
/** * Renders the widget. * * @param string $name The element name * @param string $value The value displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { if ($this->getOption('multiple')) { $name .= '[]'; $attributes['multiple'] = $this->getOption('multiple'); } return parent::render($name, $value, $attributes, $errors); }
/** * @param string $name The element name * @param string $value The value displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $input = parent::render($name, $value, $attributes, $errors); if (!$this->getOption('edit_mode')) { return $input; } if ($this->getOption('with_delete')) { $deleteName = ']' == substr($name, -1) ? substr($name, 0, -1) . '_delete]' : $name . '_delete'; $delete = $this->renderTag('input', array_merge(array('type' => 'checkbox', 'name' => $deleteName), $attributes)); $deleteLabel = $this->renderContentTag('label', $this->getOption('delete_label'), array_merge(array('for' => $this->generateId($deleteName)))); } else { $delete = ''; $deleteLabel = ''; } return strtr($this->getOption('template'), array('%input%' => $input, '%delete%' => $delete, '%delete_label%' => $deleteLabel, '%file%' => $this->getFileAsTag($attributes))); }
public function render($name, $value = null, $attributes = array(), $errors = array()) { self::$INSTANCE_COUNT++; $output = parent::render($name, $value, $attributes, $errors); $widget_id = $this->getAttribute('id') ? $this->getAttribute('id') : $this->generateId($name); $session_name = ini_get('session.name'); $session_id = session_id(); $uploader = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_uploadify_path') . '/' . sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_uploader'); $cancel_img = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_uploadify_path') . '/' . sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_cancel_img'); $sim_upload_limit = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_sim_upload_limit'); $display_data = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_display_data'); $auto = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_auto'); $multi = sfConfig::get('app_ddWidgetFormInputUploadifyPlugin_multi'); $form = new BaseForm(); $csrf_token = $form->getCSRFToken(); $output .= <<<EOF <div class="swfupload-buttontarget"> <noscript> We're sorry. SWFUpload could not load. You must have JavaScript enabled to enjoy SWFUpload. </noscript> </div> <script type="text/javascript"> //<![CDATA[ \$(document).ready(function() { \$('#{$widget_id}').uploadify({ 'scriptData': {'{$session_name}':'{$session_id}', '_csrf_token':'{$csrf_token}'}, 'uploader': '{$uploader}', 'cancelImg': '{$cancel_img}', 'auto' : {$auto}, 'script': \$('#{$widget_id}').closest('form').attr('action')+'/upload', 'folder': '/', 'multi': {$multi}, 'displayData': '{$display_data}', 'fileDataName': '{$widget_id}', 'simUploadLimit': {$sim_upload_limit} }); }); //]]> </script> EOF; return $output; }
public function render($name, $value = null, $attributes = array(), $errors = array()) { self::$INSTANCE_COUNT++; //*.jpg;*.gif $extensions = is_array($this->getOption('swf_upload_file_types')) ? implode(';', $this->getOption('swf_upload_file_types')) : $this->getOption('swf_upload_file_types'); $output = parent::render($name, $value, $attributes, $errors); $widget_id = $this->getAttribute('id') ? $this->getAttribute('id') : $this->generateId($name); $button_id = $widget_id . "_swfupload_target"; $swfupload_button_image_url = $this->getOption('swfupload_button_image_url') === null ? '' : public_path($this->getOption('swfupload_button_image_url')); $max_size = $this->iniSize2Int($this->getOption('swfupload_file_size_limit')); $swfupload_post_name = $this->getOption('swfupload_post_name') === null ? $name : $this->getOption('swfupload_post_name'); $send_serialized_values = $this->getOption('send_serialized_values') ? 'true' : 'false'; $collapse_queue_on_init = $this->getOption('collapse_queue_on_init') ? 'true' : 'false'; $prevent_form_submit = $this->getOption('prevent_form_submit') ? 'true' : 'false'; $output .= <<<EOF <div class="swfupload-buttontarget" id="{$button_id}"> <noscript> We're sorry. SWFUpload could not load. You must have JavaScript enabled to enjoy SWFUpload. </noscript> </div> <script type="text/javascript"> //<![CDATA[ SWFUpload.onload = function() { new SWFUpload ({ upload_url : "{$this->getOption('swfupload_upload_url')}", flash_url : "{$this->getOption('swfupload_flash_url')}", button_placeholder_id : "{$button_id}", file_post_name : "{$swfupload_post_name}", post_params : { {$this->getOption('swfupload_post_params')} }, custom_settings : { widget_id: "{$widget_id}", send_serialized_values: {$send_serialized_values}, collapse_queue_on_init: {$collapse_queue_on_init}, prevent_form_submit: {$prevent_form_submit} }, use_query_string : false, requeue_on_error : false, assume_success_timeout : 0, file_types : "{$extensions}", file_types_description: "Web Image Files", file_size_limit : "{$max_size}", file_upload_limit : {$this->getOption('swfupload_file_upload_limit')}, file_queue_limit : {$this->getOption('swfupload_file_queue_limit')}, debug : false, prevent_swf_caching : true, preserve_relative_urls : false, button_image_url : "{$swfupload_button_image_url}", button_width : {$this->getOption('swfupload_button_width')}, button_height : {$this->getOption('swfupload_button_height')}, button_text : "{$this->getOption('swfupload_button_text')}", button_text_style : "{$this->getOption('swfupload_button_style')}", button_text_left_padding : {$this->getOption('swfupload_button_text_left_padding')}, button_text_top_padding : {$this->getOption('swfupload_button_text_top_padding')}, button_disabled : {$this->getOption('swfupload_button_disabled')}, button_cursor : {$this->getOption('swfupload_button_cursor')}, button_window_mode : {$this->getOption('swfupload_button_window_mode')}, button_action : {$this->getOption('swfupload_button_action')}, swfupload_loaded_handler : {$this->getOption('swfupload_swfupload_loaded_handler')}, file_dialog_start_handler : {$this->getOption('swfupload_file_dialog_start_handler')}, file_queued_handler : {$this->getOption('swfupload_file_queued_handler')}, file_queue_error_handler : {$this->getOption('swfupload_file_queue_error_handler')}, file_dialog_complete_handler : {$this->getOption('swfupload_file_dialog_complete_handler')}, upload_start_handler : {$this->getOption('swfupload_upload_start_handler')}, upload_progress_handler : {$this->getOption('swfupload_upload_progress_handler')}, upload_error_handler : {$this->getOption('swfupload_upload_error_handler')}, upload_success_handler : {$this->getOption('swfupload_upload_success_handler')}, upload_complete_handler : {$this->getOption('swfupload_upload_complete_handler')}, queue_complete_handler : {$this->getOption('swfupload_queue_complete_handler')}, // swf object swfupload_pre_load_handler : {$this->getOption('swfupload_swfupload_pre_load_handler')}, swfupload_load_failed_handler : {$this->getOption('swfupload_swfupload_load_failed_handler')}, minimum_flash_version : "{$this->getOption('swfupload_minimum_flash_version')}" }); } //]]> </script> EOF; return $output; }
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(1); $w = new sfWidgetFormInputFile(); // ->render() $t->diag('->render()'); $t->is($w->render('foo'), '<input type="file" name="foo" id="foo" />', '->render() renders the widget as HTML');