Skip to content

Commit

Permalink
allow to disable the image preview at each case by configure settings
Browse files Browse the repository at this point in the history
* prepare configure keys at the configure file
* make the patch based on comments on oficial repository
* inicialize and chek the config variables also when will render fields
  • Loading branch information
mckaygerhard committed Dec 24, 2018
1 parent 07013a2 commit 45767c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions application/config/grocery_crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

$config['grocery_crud_file_upload_allow_file_types'] = 'gif|jpeg|jpg|png|tiff|doc|docx|txt|odt|xls|xlsx|pdf|ppt|pptx|pps|ppsx|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|flv|avi|mpg|ogv|3gp|3g2';
$config['grocery_crud_file_upload_max_file_size'] = '20MB'; //ex. '10MB' (Mega Bytes), '1067KB' (Kilo Bytes), '5000B' (Bytes)
$config['grocery_crud_file_upload_list_image_preview'] = true; // allow preview uploads on list fields if are images
$config['grocery_crud_file_upload_edit_image_preview'] = true; // allow preview uploads on edit/add if are images
$config['grocery_crud_file_upload_view_image_preview'] = true; // allow preview uploads field at the view-only cases

// You can choose 'ckeditor','tinymce' or 'markitup'
$config['grocery_crud_default_text_editor'] = 'ckeditor';
Expand Down
8 changes: 6 additions & 2 deletions application/libraries/Grocery_CRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ protected function change_list_value($field_info, $value = null)
$file_url = base_url().$field_info->extras->upload_path."/$value";

$file_url_anchor = '<a href="'.$file_url.'"';
if($is_image)
if($is_image && $this->config->grocery_crud_file_upload_list_image_preview)

This comment has been minimized.

Copy link
@mckaygerhard

mckaygerhard Dec 24, 2018

Author

hope this maybe usefully for others, issue are at scoumbourdis#467

{
$file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">';
}
Expand Down Expand Up @@ -2786,6 +2786,7 @@ protected function get_upload_file_input($field_info, $value)
? true : false;

$image_class = $is_image ? 'image-thumbnail' : '';
$preview_file = $is_image && $this->config->grocery_crud_file_upload_edit_image_preview ? true : false;

$input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'">
<span>'.$this->l('form_upload_a_file').'</span>
Expand All @@ -2800,7 +2801,7 @@ protected function get_upload_file_input($field_info, $value)
$input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>";
$input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>";
$input .= "<a href='".$file_url."' id='file_$unique' class='open-file";
$input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value";
$input .= $preview_file ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value";
$input .= "</a> ";
$input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> ";
$input .= "</div><div style='clear:both'></div>";
Expand Down Expand Up @@ -4572,6 +4573,9 @@ protected function _initialize_variables()
$this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page');
$this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types');
$this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size');
$this->config->grocery_crud_file_upload_list_image_preview = $ci->config->item('grocery_crud_file_upload_list_image_preview');
$this->config->grocery_crud_edit_upload_list_image_preview = $ci->config->item('grocery_crud_file_upload_edit_image_preview');
$this->config->grocery_crud_view_upload_list_image_preview = $ci->config->item('grocery_crud_file_upload_view_image_preview');
$this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor');
$this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type');
$this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter');
Expand Down

0 comments on commit 45767c0

Please sign in to comment.