Class: ModalUploadInput
- Inherits:
-
Object
- Object
- ModalUploadInput
- Includes:
- ActionView::Context, ActionView::Helpers::AssetTagHelper, ActionView::Helpers::FormHelper, ActionView::Helpers::UrlHelper, Formtastic::Inputs::Base, Jquery::Helpers, S3DirectUpload::UploadHelper
- Defined in:
- lib/active_admin_modal_upload/inputs/modal_upload_input.rb
Instance Method Summary collapse
- #close_modal_button ⇒ Object
- #file_previews ⇒ Object
- #js_to_append_modal ⇒ Object
- #modal_window ⇒ Object
- #placeholder ⇒ Object
- #to_html ⇒ Object
- #upload_form ⇒ Object
- #upload_js ⇒ Object
- #upload_template ⇒ Object
- #uploader_button ⇒ Object
Instance Method Details
#close_modal_button ⇒ Object
41 42 43 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 41 def link_to 'Close Window', "", :rel => "modal:close", class: "close-this-modal" end |
#file_previews ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 45 def file_previews [:resource].send([:association].to_sym).order("image ASC").each_with_index.map { |file, index| input_name = "#{[:resource].class.name.downcase}[#{[:association].underscore}_attributes][#{index}]" image_preview = file.image.present? ? image_tag(file.image_url([:preview_image_size] ||= :thumb)) : image_tag(file.temporary_image_url, width: "150px", :style => "opacity:0.3; filter:alpha(opacity=30);") + "<br/><em>*This image is still being processed</em>".html_safe "<div class='existing-upload'>" + "<div class='file-preview'>" + image_preview + "</div>" + "<div class='remove-file'>" + check_box_tag("#{input_name}[_destroy]") + "<p>Remove File</p>" + hidden_field_tag("#{input_name}[id]", file.id) + "</div>" + "</div>" } end |
#js_to_append_modal ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 12 def js_to_append_modal "<script type='text/javascript'> $(document).ready(function() { $('#main_content').append('" + modal_window + "'); }); </script> " end |
#modal_window ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 25 def modal_window resource = [:resource].class.name.downcase association = [:association] modal_window_id = "#{resource}-#{association}-uploader-window" '<div id="' + modal_window_id + '" class="modal-window-visible" style="display: none;">' + upload_form + + '</div>' end |
#placeholder ⇒ Object
105 106 107 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 105 def placeholder "<div class='existing-upload'></div>" end |
#to_html ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 110 def to_html input_wrapping do label_html << << file_previews.join(" ").html_safe << placeholder.html_safe << upload_template.html_safe << js_to_append_modal.html_safe << upload_js.html_safe end end |
#upload_form ⇒ Object
35 36 37 38 39 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 35 def upload_form s3_uploader_form id: "#{[:resource].class.name.downcase}-#{[:association].underscore}-uploader" do file_field_tag :file, multiple: true end end |
#upload_js ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 73 def upload_js " <script type='text/javascript'> $(function() { $('\##{[:resource].class.name.downcase}-#{[:association].underscore}-uploader').S3Uploader({ }).on('s3_upload_complete', function(e, content) { var preview = $('<div class=\"existing-upload\"><div class=\"file-preview\"><img src=\"' + content['url'] + '\" style=\"width: 150px; opacity:0.3; filter:alpha(opacity=30);\"><br/><em>*This image is still being processed</em></div><div class=\"remove-file\"></div></div>'); var lastPreview = $('.existing-upload').last(); insertRemoteInput(content); preview.insertAfter(lastPreview); }).bind('s3_uploads_complete', function(e, data) { var processingMessage = $('<div id=\"all-uploads-complete\"><h3>Uploads completed.</h3></div>') processingMessage.insertAfter($('#file')); }).on('ajax:success', function(e, data) { insertUploadInputsForPhotographs(JSON.parse(data)); }).on('ajax:error', function(e, data) { alert('Something went wrong'); }).bind('s3_upload_failed', function(e, content) { return alert('' + content.filename + ' failed to upload : ' + content.error_thrown); }); }); var insertRemoteInput = function(content) { input = $('<input type=\"hidden\" name=\"#{[:resource].class.name.downcase}[#{[:association].underscore}_attributes][' + $.now() + '][temporary_image_url]\" value=\"' + content.url + '\" />'); input.insertAfter($('\##{[:association].underscore}_uploader')); } </script> " end |
#upload_template ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 64 def upload_template "<script id='template-upload' type='text/x-tmpl'>" + "<div id='file-{%=o.unique_id%}'' class='upload'>" + "{%=o.name%}" + "<div class='progress progress-striped active' role='progressbar'><div class='bar' class='progress-bar bar progress-bar-success' style='width: 0%;'></div></div>" + "</div>" + "</script>" end |
#uploader_button ⇒ Object
21 22 23 |
# File 'lib/active_admin_modal_upload/inputs/modal_upload_input.rb', line 21 def link_to_modal 'Add File', "\##{[:resource].class.name.downcase}-#{[:association]}-uploader-window", :class => 'button', id: "#{[:association].underscore}_uploader" end |