active_admin_modal_upload 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6c31773f8a0450f9ca0276908d39c7678e126b1
4
+ data.tar.gz: 6c429faf4ad614da812aa2ff4aec043ebb278fc6
5
+ SHA512:
6
+ metadata.gz: 3a7f184a32c35f723d2c52a051c8ab05173d0290e31df277858dedab0801c58ed1c346296a6c129eaae338169bf4170d0e9665bb24cec9a1c9709a1debb3d469
7
+ data.tar.gz: d3a400cdb31828055babb59dd3c2a683b9847f0b586bc72ace18def3ef454f30d873d3a5a00ed2b792a0529e0e5e619c3e5a2d53ed3f16b430007d6fac19e2fd
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ActiveAdminModalUpload
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ActiveAdminModalUpload'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,34 @@
1
+
2
+ .existing-upload {
3
+ margin-top: 20px;
4
+ margin-left: auto;
5
+ margin-right: auto;
6
+ width: 90%;
7
+ position: relative;
8
+ clear: both;
9
+
10
+ .file-preview {
11
+ margin: 10px;
12
+ // width: 50%;
13
+ float: left;
14
+ // display: inline-block;
15
+ // clear: both;
16
+ position: relative;
17
+ }
18
+
19
+ .remove-file {
20
+ margin-top: 10px;
21
+ display: inline-block;
22
+ float: left;
23
+ }
24
+
25
+
26
+ }
27
+
28
+ .modal-window-visible {
29
+ height: 50%;
30
+ width: 30%;
31
+ overflow-y: scroll;
32
+ overflow-x: hidden;
33
+
34
+ }
@@ -0,0 +1,41 @@
1
+ module ActiveAdminModalUpload::Uploadable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ include Rails.application.routes.url_helpers
6
+ end
7
+
8
+ module ClassMethods
9
+ def allows_upload(name)
10
+ code = <<-eoruby
11
+
12
+ after_save :delay_processing, :if => :temporary_image_url_changed?
13
+
14
+ def to_jq_upload
15
+ {
16
+ "name" => read_attribute(#{name}),
17
+ "size" => image.size,
18
+ "url" => image.url,
19
+ "thumbnail_url" => image.thumb.url,
20
+ "delete_url" => destroy_upload_admin_#{self.name.underscore}_url(self, only_path: true),
21
+ "id" => id,
22
+ "delete_type" => "DELETE"
23
+ }
24
+ end
25
+
26
+ def delay_processing
27
+ #{self.name}.delay.save_remote_file(self.id)
28
+ end
29
+
30
+ def self.save_remote_file(id)
31
+ file = #{self.name}.where(id: id).first
32
+ if file
33
+ file.remote_image_url = file.temporary_image_url
34
+ file.save!
35
+ end
36
+ end
37
+ eoruby
38
+ class_eval(code)
39
+ end
40
+ end
41
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,11 @@
1
+ require "active_admin_modal_upload/engine"
2
+ require "active_admin_modal_upload/dsl"
3
+ require "s3_direct_upload"
4
+ require "jquery-ui-rails"
5
+ require "jquery-modal-rails"
6
+ require "active_admin_modal_upload/inputs/modal_upload_input"
7
+
8
+ module ActiveAdminModalUpload
9
+ end
10
+
11
+ ::ActiveAdmin::DSL.send(:include, ActiveAdminModalUpload::DSL)
@@ -0,0 +1,36 @@
1
+ module ActiveAdminModalUpload
2
+ module DSL
3
+
4
+ def modal_uploads(options={})
5
+ config.resource_class.send(:include, ::ActiveAdminModalUpload::Uploadable)
6
+ uploader = options[:mounted_uploader] ||= :image
7
+ config.resource_class.send(:allows_upload, uploader)
8
+
9
+ collection_action :create_upload, method: :post do
10
+ @upload_model = options[:model] ||= active_admin_config.resource_class
11
+ @model = @upload_model.new(upload_resource_params)
12
+ if @model.save
13
+ respond_to do |format|
14
+ format.html {
15
+ render :json => [@model.to_jq_upload].to_json,
16
+ :content_type => 'text/html',
17
+ :layout => false
18
+ }
19
+ format.json {
20
+ render :json => { files: [@model.to_jq_upload] }, status: :created
21
+ }
22
+ end
23
+ else
24
+ render :json => [{:error => "custom_failure"}], :status => 304
25
+ end
26
+ end
27
+
28
+ member_action :destroy_upload, method: :delete do
29
+ @upload_model = options[:model] ||= active_admin_config.resource_class
30
+ @model = @upload_model.find(params[:id])
31
+ @model.destroy
32
+ render :json => true
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,4 @@
1
+ module ActiveAdminModalUpload
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,117 @@
1
+ class ModalUploadInput
2
+
3
+ include Formtastic::Inputs::Base
4
+ include Jquery::Helpers
5
+ include S3DirectUpload::UploadHelper
6
+ include ActionView::Helpers::UrlHelper
7
+ include ActionView::Helpers::FormHelper
8
+ include ActionView::Helpers::AssetTagHelper
9
+ include ActionView::Context
10
+
11
+
12
+ def js_to_append_modal
13
+ "<script type='text/javascript'>
14
+ $(document).ready(function() {
15
+ $('#main_content').append('" + modal_window + "');
16
+ });
17
+ </script>
18
+ "
19
+ end
20
+
21
+ def uploader_button
22
+ link_to_modal 'Add File', "\##{options[:resource].class.name.downcase}-#{options[:association]}-uploader-window", :class => 'button', id: "#{options[:association].underscore}_uploader"
23
+ end
24
+
25
+ def modal_window
26
+ resource = options[:resource].class.name.downcase
27
+ association = options[:association]
28
+ modal_window_id = "#{resource}-#{association}-uploader-window"
29
+ '<div id="' + modal_window_id + '" class="modal-window-visible" style="display: none;">' +
30
+ upload_form +
31
+ '</div>'
32
+ end
33
+
34
+ def upload_form
35
+ s3_uploader_form id: "#{options[:resource].class.name.downcase}-#{options[:association].underscore}-uploader" do
36
+ file_field_tag :file, multiple: true
37
+ end
38
+ end
39
+
40
+ def file_previews
41
+ options[:resource].send(options[:association].to_sym).order("image ASC").each_with_index.map { |file, index|
42
+ input_name = "#{options[:resource].class.name.downcase}[#{options[:association].underscore}_attributes][#{index}]"
43
+
44
+ image_preview = file.image.present? ? image_tag(file.image_url(options[: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
45
+
46
+ "<div class='existing-upload'>" +
47
+ "<div class='file-preview'>" +
48
+ image_preview +
49
+ "</div>" +
50
+ "<div class='remove-file'>" +
51
+ check_box_tag("#{input_name}[_destroy]") +
52
+ "<p>Remove File</p>" +
53
+ hidden_field_tag("#{input_name}[id]", file.id) +
54
+ "</div>" +
55
+ "</div>"
56
+ }
57
+ end
58
+
59
+ def upload_template
60
+ "<script id='template-upload' type='text/x-tmpl'>" +
61
+ "<div id='file-{%=o.unique_id%}'' class='upload'>" +
62
+ "{%=o.name%}" +
63
+ "<div class='progress progress-striped active' role='progressbar'><div class='bar' class='progress-bar bar progress-bar-success' style='width: 0%;'></div></div>" +
64
+ "</div>" +
65
+ "</script>"
66
+ end
67
+
68
+ def upload_js
69
+ "
70
+ <script type='text/javascript'>
71
+ $(function() {
72
+ $('\##{options[:resource].class.name.downcase}-#{options[:association].underscore}-uploader').S3Uploader({
73
+ }).on('s3_upload_complete', function(e, content) {
74
+
75
+
76
+ 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>');
77
+ var lastPreview = $('.existing-upload').last();
78
+ insertRemoteInput(content);
79
+ preview.insertAfter(lastPreview);
80
+ }).bind('s3_uploads_complete', function(e, data) {
81
+ var processingMessage = $('<h3 style=\"text-align: center; margin-top=20px;\">Uploads completed.</h3>')
82
+ processingMessage.insertAfter($('#file'));
83
+ }).on('ajax:success', function(e, data) {
84
+ insertUploadInputsForPhotographs(JSON.parse(data));
85
+ }).on('ajax:error', function(e, data) {
86
+ alert('Something went wrong');
87
+ }).bind('s3_upload_failed', function(e, content) {
88
+ return alert('' + content.filename + ' failed to upload : ' + content.error_thrown);
89
+ });
90
+ });
91
+
92
+ var insertRemoteInput = function(content) {
93
+ input = $('<input type=\"hidden\" name=\"#{options[:resource].class.name.downcase}[#{options[:association].underscore}_attributes][' + $.now() + '][temporary_image_url]\" value=\"' + content.url + '\" />');
94
+ input.insertAfter($('\##{options[:association].underscore}_uploader'));
95
+ }
96
+ </script>
97
+ "
98
+ end
99
+
100
+ def placeholder
101
+ "<div class='existing-upload'></div>"
102
+ end
103
+
104
+
105
+ def to_html
106
+ input_wrapping do
107
+ label_html <<
108
+ uploader_button <<
109
+ file_previews.join(" ").html_safe <<
110
+ placeholder.html_safe <<
111
+ upload_template.html_safe <<
112
+ js_to_append_modal.html_safe <<
113
+ upload_js.html_safe
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveAdminModalUpload
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Inserts the necessary SCSS & JS into ActiveAdmin to allow for modal-uploads
3
+
4
+ Example:
5
+ rails generate active_admin_modal_upload:initialize
6
+
7
+ This will append:
8
+ active_admin.js.cofee
9
+ active_admin.css.scss
@@ -0,0 +1,18 @@
1
+ module ActiveAdminModalUpload
2
+ class InitializeGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def add_js_assets
6
+ append_file "app/assets/javascripts/active_admin.js.coffee", "#= require jquery.ui.all\n"
7
+ append_file "app/assets/javascripts/active_admin.js.coffee", "#= require jquery.modal\n"
8
+ append_file "app/assets/javascripts/active_admin.js.coffee", "#= require s3_direct_upload\n"
9
+ end
10
+
11
+ def add_css_assets
12
+ append_file "app/assets/stylesheets/active_admin.css.scss", "@import 'jquery.ui.all';\n"
13
+ append_file "app/assets/stylesheets/active_admin.css.scss", "@import 'jquery.modal';\n"
14
+ append_file "app/assets/stylesheets/active_admin.css.scss", "@import 's3_direct_upload_progress_bars';\n"
15
+ append_file "app/assets/stylesheets/active_admin.css.scss", "@import 'active_admin_modal_upload';\n"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :active_admin_modal_upload do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin_modal_upload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Isaac Norman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: s3_direct_upload
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-ui-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jquery-modal-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sidekiq
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Allows for the upload of multiple files in the background from a modal
98
+ window in Active Admin
99
+ email:
100
+ - isaacdnorman@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - MIT-LICENSE
106
+ - README.rdoc
107
+ - Rakefile
108
+ - app/assets/stylesheets/active_admin_modal_upload.scss
109
+ - app/models/concerns/active_admin_modal_upload/uploadable.rb
110
+ - config/routes.rb
111
+ - lib/active_admin_modal_upload.rb
112
+ - lib/active_admin_modal_upload/dsl.rb
113
+ - lib/active_admin_modal_upload/engine.rb
114
+ - lib/active_admin_modal_upload/inputs/modal_upload_input.rb
115
+ - lib/active_admin_modal_upload/version.rb
116
+ - lib/generators/active_admin_modal_upload/initialize/USAGE
117
+ - lib/generators/active_admin_modal_upload/initialize/initialize_generator.rb
118
+ - lib/tasks/active_admin_modal_upload_tasks.rake
119
+ homepage: http://www.papercloud.com.au
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.0
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Modal uploads in ActiveAdmin
142
+ test_files: []