lolita-file-upload 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/.rspec +2 -2
- data/Gemfile +21 -21
- data/LICENSE.txt +20 -20
- data/README.rdoc +27 -27
- data/Rakefile +39 -39
- data/VERSION +1 -1
- data/app/controllers/lolita/uploads_controller.rb +58 -0
- data/app/models/lolita/upload/file.rb +43 -43
- data/app/uploaders/file_uploader.rb +20 -20
- data/app/views/components/lolita/configuration/tab/files/_cells.html.erb +10 -4
- data/app/views/components/lolita/configuration/tab/files/_destroy.js.erb +2 -2
- data/app/views/components/lolita/configuration/tab/files/_display.html.erb +10 -11
- data/app/views/components/lolita/configuration/tab/files/_edit.js.erb +1 -1
- data/app/views/components/lolita/configuration/tab/files/_file.html.erb +5 -0
- data/app/views/components/lolita/configuration/tab/files/_fixed_gallery.html.haml +33 -0
- data/app/views/components/lolita/configuration/tab/files/_form.html.erb +7 -3
- data/app/views/components/lolita/configuration/tab/files/_list.html.erb +13 -13
- data/app/views/components/lolita/configuration/tab/files/_list_form.html.erb +5 -5
- data/app/views/components/lolita/configuration/tab/files/_row.html.erb +5 -2
- data/app/views/components/lolita/configuration/tab/files/_update.js.erb +1 -1
- data/app/views/components/lolita/configuration/tab/files/_upload_script.html.erb +79 -77
- data/config/locales/en.yml +18 -18
- data/features/configuration_for_tab.feature +25 -25
- data/features/connect_with_lolita.feature +14 -14
- data/features/extend_resources_with_new_routes.feature +16 -16
- data/features/step_definitions/lolita_steps.rb +112 -112
- data/features/support/env.rb +15 -15
- data/features/support_byte_converter.feature +31 -31
- data/features/upload_file.feature +15 -15
- data/lib/generators/lolita_file_upload/assets_generator.rb +12 -12
- data/lib/generators/lolita_file_upload/install_generator.rb +19 -19
- data/lib/generators/lolita_file_upload/templates/migration.rb +24 -24
- data/lib/lolita-file-upload.rb +35 -36
- data/lib/lolita-file-upload/configuration/tab/files.rb +108 -57
- data/lib/lolita-file-upload/module.rb +10 -6
- data/lib/lolita-file-upload/rails.rb +7 -7
- data/lib/lolita-file-upload/rails/file_upload_routes.rb +14 -19
- data/lib/support/bytes.rb +58 -58
- data/lolita-file-upload.gemspec +9 -13
- data/public/javascripts/lolita/upload/I18n/lv.js +21 -21
- data/public/javascripts/lolita/upload/I18n/ru.js +21 -21
- data/public/javascripts/lolita/upload/plupload.full.js +1 -1
- data/public/stylesheets/lolita/upload/jquery.ui.plupload.css +139 -139
- data/public/stylesheets/lolita/upload/plupload.queue.css +177 -177
- data/spec/configuration/tab/files_spec.rb +36 -36
- data/spec/lolita/support/bytes_spec.rb +35 -35
- data/spec/models/file_spec.rb +33 -33
- data/spec/spec_helper.rb +32 -29
- data/spec/support/post.rb +2 -2
- data/spec/uploaders/file_uploader_spec.rb +11 -11
- data/test_orm/active_record.rb +11 -11
- data/test_orm/active_record/news.rb +11 -11
- data/test_orm/active_record/post.rb +12 -12
- data/test_orm/active_record/tag.rb +2 -2
- data/test_orm/config/active_record.yml +1 -1
- data/test_orm/coverage.rb +18 -18
- data/test_orm/db/migrate/01_create_posts.rb +14 -14
- data/test_orm/db/migrate/02_create_files.rb +19 -19
- data/test_orm/db/migrate/03_create_news.rb +16 -16
- data/test_orm/db/migrate/04_create_tags.rb +14 -14
- data/test_orm/files/large_file.txt +201 -201
- data/test_orm/files/normal_file.txt +1 -1
- data/test_orm/rails/config/application.rb +7 -7
- data/test_orm/rails/config/enviroment.rb +4 -4
- data/test_orm/rails/config/routes.rb +2 -2
- data/test_orm/rails/log/development.log +7 -7
- data/test_orm/support.rb +26 -26
- data/test_orm/uploaders/list_image_uploader.rb +5 -5
- data/test_orm/uploaders/main_image_uploader.rb +5 -5
- metadata +19 -23
- data/app/controllers/lolita/upload/files_controller.rb +0 -51
- data/app/controllers/lolita/upload/images_controller.rb +0 -52
- data/lib/lolita-file-upload/configuration/tab/images.rb +0 -20
- data/spec/configuration/tab/images_spec.rb +0 -16
- data/upload/lolita/upload/file/201105/1/large_file.txt +0 -201
- data/upload/lolita/upload/file/201106/1/large_file.txt +0 -201
- data/upload/misc/large_file.txt +0 -201
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
lib/**/*.rb
|
2
|
-
bin/*
|
3
|
-
-
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE.txt
|
1
|
+
lib/**/*.rb
|
2
|
+
bin/*
|
3
|
+
-
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE.txt
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--color
|
2
|
-
--format d
|
1
|
+
--color
|
2
|
+
--format d
|
data/Gemfile
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gem "lolita", "~>3.1.
|
4
|
-
gem "carrierwave", "~> 0.5.2"
|
5
|
-
group :test do
|
6
|
-
gem "rspec-rails", "~> 2.6"
|
7
|
-
gem "ffaker"
|
8
|
-
gem "factory_girl"
|
9
|
-
gem "sqlite3"
|
10
|
-
gem "rspec", "~> 2.6"
|
11
|
-
gem 'cover_me', '>= 1.0.0.rc6'
|
12
|
-
gem '
|
13
|
-
end
|
14
|
-
|
15
|
-
group :development do
|
16
|
-
gem "cucumber", "~> 0.10"
|
17
|
-
gem "cucumber-rails", "~> 0.5.2"
|
18
|
-
gem "bundler", "~> 1.0"
|
19
|
-
gem "jeweler", "~> 1.5"
|
20
|
-
end
|
21
|
-
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "lolita", "~>3.1.9"
|
4
|
+
gem "carrierwave", "~> 0.5.2"
|
5
|
+
group :test do
|
6
|
+
gem "rspec-rails", "~> 2.6"
|
7
|
+
gem "ffaker"
|
8
|
+
gem "factory_girl"
|
9
|
+
gem "sqlite3"
|
10
|
+
gem "rspec", "~> 2.6"
|
11
|
+
gem 'cover_me', '>= 1.0.0.rc6'
|
12
|
+
gem 'rails', "~> 3.0.9"
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
16
|
+
gem "cucumber", "~> 0.10"
|
17
|
+
gem "cucumber-rails", "~> 0.5.2"
|
18
|
+
gem "bundler", "~> 1.0"
|
19
|
+
gem "jeweler", "~> 1.5"
|
20
|
+
end
|
21
|
+
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2011 Arturs Meisters
|
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.
|
1
|
+
Copyright (c) 2011 Arturs Meisters
|
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
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
= Lolita file upload
|
2
|
-
|
3
|
-
File upload gem for Lolita.
|
4
|
-
|
5
|
-
==Instalation
|
6
|
-
* gem install lolita-file-upload
|
7
|
-
* include in gemfile like this:
|
8
|
-
gem "lolita-file-upload", ">=0.1.0"
|
9
|
-
* cd your_project_path
|
10
|
-
* rails g lolita_file_upload:install
|
11
|
-
|
12
|
-
Install will copy all assets and migrations to your project.
|
13
|
-
If you update to newest version of gem, than run <i>rails g lolita_file_upload:assets</i>
|
14
|
-
|
15
|
-
==Configuration
|
16
|
-
|
17
|
-
Gem will not used until any of lolita configuration blocks define tab with type :files. Like this
|
18
|
-
class Post
|
19
|
-
include Lolita::Configuration
|
20
|
-
has_many :files, :as=>:fileable, :class_name=>"Lolita::Upload::File"
|
21
|
-
|
22
|
-
lolita do
|
23
|
-
tab(:content)
|
24
|
-
tab(:files)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
1
|
+
= Lolita file upload
|
2
|
+
|
3
|
+
File upload gem for Lolita.
|
4
|
+
|
5
|
+
==Instalation
|
6
|
+
* gem install lolita-file-upload
|
7
|
+
* include in gemfile like this:
|
8
|
+
gem "lolita-file-upload", ">=0.1.0"
|
9
|
+
* cd your_project_path
|
10
|
+
* rails g lolita_file_upload:install
|
11
|
+
|
12
|
+
Install will copy all assets and migrations to your project.
|
13
|
+
If you update to newest version of gem, than run <i>rails g lolita_file_upload:assets</i>
|
14
|
+
|
15
|
+
==Configuration
|
16
|
+
|
17
|
+
Gem will not used until any of lolita configuration blocks define tab with type :files. Like this
|
18
|
+
class Post
|
19
|
+
include Lolita::Configuration
|
20
|
+
has_many :files, :as=>:fileable, :class_name=>"Lolita::Upload::File"
|
21
|
+
|
22
|
+
lolita do
|
23
|
+
tab(:content)
|
24
|
+
tab(:files)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/Rakefile
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
11
|
-
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "lolita-file-upload"
|
16
|
-
gem.homepage = "http://github.com/ithouse/lolita-file-upload"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{File upload gem for Lolita CMS}
|
19
|
-
gem.description = %Q{File upload gem for Lolita with with fulll integration - models, controller, views}
|
20
|
-
gem.email = "support@ithouse.lv"
|
21
|
-
gem.authors = ["ITHouse","Arturs Meisters"]
|
22
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
task :default => :test
|
30
|
-
|
31
|
-
require 'rake/rdoctask'
|
32
|
-
Rake::RDocTask.new do |rdoc|
|
33
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
34
|
-
|
35
|
-
rdoc.rdoc_dir = 'rdoc'
|
36
|
-
rdoc.title = "lolita-file-upload #{version}"
|
37
|
-
rdoc.rdoc_files.include('README*')
|
38
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "lolita-file-upload"
|
16
|
+
gem.homepage = "http://github.com/ithouse/lolita-file-upload"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{File upload gem for Lolita CMS}
|
19
|
+
gem.description = %Q{File upload gem for Lolita with with fulll integration - models, controller, views}
|
20
|
+
gem.email = "support@ithouse.lv"
|
21
|
+
gem.authors = ["ITHouse","Arturs Meisters"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
task :default => :test
|
30
|
+
|
31
|
+
require 'rake/rdoctask'
|
32
|
+
Rake::RDocTask.new do |rdoc|
|
33
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
34
|
+
|
35
|
+
rdoc.rdoc_dir = 'rdoc'
|
36
|
+
rdoc.title = "lolita-file-upload #{version}"
|
37
|
+
rdoc.rdoc_files.include('README*')
|
38
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Lolita::UploadsController < ApplicationController
|
2
|
+
include Lolita::Controllers::UserHelpers
|
3
|
+
include Lolita::Controllers::InternalHelpers
|
4
|
+
before_filter :authenticate_lolita_user!
|
5
|
+
before_filter :set_tab, :only=>[:edit,:update,:destroy,:create]
|
6
|
+
before_filter :set_resource, :only=>[:create,:edit,:update,:destroy]
|
7
|
+
before_filter :set_file, :only=>[:edit,:update,:destroy,:create]
|
8
|
+
|
9
|
+
respond_to :js,:html
|
10
|
+
|
11
|
+
def create
|
12
|
+
@file.send(:"#{@tab.uploader}=",params[:file])
|
13
|
+
@file.save!
|
14
|
+
render_component *@tab.build("",:row,:file=>@file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def edit
|
18
|
+
render_component *@tab.build("",:edit,:file=>@file)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@file.update_attributes!(params[:file])
|
23
|
+
render_component *@tab.build("",:update,:file=>@file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
@file.destroy
|
28
|
+
render_component *@tab.build("",:destroy,:file=>@file)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def set_resource
|
34
|
+
association_id = params["#{lolita_mapping.singular}_id"] || params[:upload]["#{lolita_mapping.singular}_id"] || params[:upload]["#{@tab.association.options[:as]}_id"]
|
35
|
+
self.resource = resource_class.find_by_id(association_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_file
|
39
|
+
@file = @tab.association.klass.new
|
40
|
+
params[:upload].each do |k,v|
|
41
|
+
@file[k] = v
|
42
|
+
end
|
43
|
+
@file
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_file
|
47
|
+
dbi=Lolita::DBI::Base.new(@tab.association.klass)
|
48
|
+
@file = dbi.find_by_id(params[:id]) || build_file
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_tab
|
52
|
+
@tab=tab_by_association(params[:association])
|
53
|
+
end
|
54
|
+
|
55
|
+
def tab_by_association name
|
56
|
+
resource_class.lolita.tabs.detect{|tab| tab.type == :files && (tab.try(:association) && tab.association.name == name.to_sym)}
|
57
|
+
end
|
58
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
module Lolita
|
2
|
-
module Upload
|
3
|
-
class File < ActiveRecord::Base
|
4
|
-
set_table_name :lolita_files
|
5
|
-
|
6
|
-
mount_uploader :asset, FileUploader
|
7
|
-
belongs_to :fileable, :polymorphic=>true
|
8
|
-
|
9
|
-
validate :size_limit
|
10
|
-
before_save :set_metadata
|
11
|
-
before_create :singularize_files
|
12
|
-
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def singularize_files
|
17
|
-
if self.fileable && lolita = self.fileable.class.lolita
|
18
|
-
if lolita.tabs.by_type(:files).association_type == :one
|
19
|
-
self.class.destroy_all(["fileable_type = :type AND fileable_id = :id AND fileable_id > 0",:type => fileable_type,:id => fileable_id])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def size_limit
|
25
|
-
if self.fileable && lolita=self.fileable.class.lolita
|
26
|
-
maxsize=lolita.tabs.by_type(:files).maxfilesize
|
27
|
-
if maxsize.to_i>0 && self.asset.file.size>maxsize
|
28
|
-
bytes=Lolita::Support::Bytes.new(maxsize)
|
29
|
-
self.errors.add(:asset,I18n.t("lolita.upload.errors.file too big",:value=>bytes.value,:unit=>bytes.unit))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def set_metadata
|
35
|
-
self.name||=::File.basename(self.asset.store_path)
|
36
|
-
self.asset_size=self.asset.file.size
|
37
|
-
self.asset_extension=::File.extname(self.asset.store_path).gsub(".","")
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
1
|
+
module Lolita
|
2
|
+
module Upload
|
3
|
+
class File < ActiveRecord::Base
|
4
|
+
set_table_name :lolita_files
|
5
|
+
|
6
|
+
mount_uploader :asset, FileUploader
|
7
|
+
belongs_to :fileable, :polymorphic=>true
|
8
|
+
|
9
|
+
validate :size_limit
|
10
|
+
before_save :set_metadata
|
11
|
+
before_create :singularize_files
|
12
|
+
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def singularize_files
|
17
|
+
if self.fileable && lolita = self.fileable.class.lolita
|
18
|
+
if lolita.tabs.by_type(:files).association_type == :one
|
19
|
+
self.class.destroy_all(["fileable_type = :type AND fileable_id = :id AND fileable_id > 0",:type => fileable_type,:id => fileable_id])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def size_limit
|
25
|
+
if self.fileable && lolita=self.fileable.class.lolita
|
26
|
+
maxsize=lolita.tabs.by_type(:files).maxfilesize
|
27
|
+
if maxsize.to_i>0 && self.asset.file.size>maxsize
|
28
|
+
bytes=Lolita::Support::Bytes.new(maxsize)
|
29
|
+
self.errors.add(:asset,I18n.t("lolita.upload.errors.file too big",:value=>bytes.value,:unit=>bytes.unit))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_metadata
|
35
|
+
self.name||=::File.basename(self.asset.store_path)
|
36
|
+
self.asset_size=self.asset.file.size
|
37
|
+
self.asset_extension=::File.extname(self.asset.store_path).gsub(".","")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -1,21 +1,21 @@
|
|
1
|
-
class FileUploader < CarrierWave::Uploader::Base
|
2
|
-
storage :file
|
3
|
-
def timestamp
|
4
|
-
time=if model
|
5
|
-
model.created_at || Time.now
|
6
|
-
else
|
7
|
-
Time.now
|
8
|
-
end
|
9
|
-
time.strftime("%Y%m")
|
10
|
-
end
|
11
|
-
|
12
|
-
# With slash in first place it will be absolute url, otherwise relative to Rails.root+"/public"
|
13
|
-
def store_dir
|
14
|
-
if model
|
15
|
-
"upload/#{model.class.to_s.underscore}/#{timestamp}/#{model.id}"
|
16
|
-
else
|
17
|
-
"upload/misc"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
1
|
+
class FileUploader < CarrierWave::Uploader::Base
|
2
|
+
storage :file
|
3
|
+
def timestamp
|
4
|
+
time=if model
|
5
|
+
model.created_at || Time.now
|
6
|
+
else
|
7
|
+
Time.now
|
8
|
+
end
|
9
|
+
time.strftime("%Y%m")
|
10
|
+
end
|
11
|
+
|
12
|
+
# With slash in first place it will be absolute url, otherwise relative to Rails.root+"/public"
|
13
|
+
def store_dir
|
14
|
+
if model
|
15
|
+
"upload/#{model.class.to_s.underscore}/#{timestamp}/#{model.id}"
|
16
|
+
else
|
17
|
+
"upload/misc"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
21
|
end
|
@@ -1,5 +1,11 @@
|
|
1
|
-
<td
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<td style="margin-top: 3px; border-bottom: 2px solid #E1E1E1; width: 600px;font-weight: bold; color: #737373; font-size: 14px; padding: 7px 20px; vertical-align: middle;">
|
2
|
+
<% if file.send(tab.uploader).to_s =~ /(jpg|jpeg|png|gif)$/i %>
|
3
|
+
<%= link_to image_tag(file.send(tab.uploader).url, :style=>"width:300px; height 160px;"), file.send(tab.uploader).url %>
|
4
|
+
<% else %>
|
5
|
+
<%= link_to file.send(tab.uploader).url, file.send(tab.uploader).url %>
|
6
|
+
<% end %>
|
7
|
+
</td>
|
8
|
+
<td style="margin-top: 3px; border-bottom: 2px solid #E1E1E1; width: 55px;text-align: center; font-size: 14px; padding: 7px 20px; vertical-align: middle;">
|
9
|
+
<%= link_to image_tag("edit.png"),send(:"edit_lolita_#{tab.dbi.klass.model_name.singular}_upload_path", "#{tab.dbi.klass.model_name.singular}_id" => resource.nil? ? 0 : resource.id, :association => tab.association.name, :id=>file),:remote=>true %>
|
10
|
+
<%= link_to image_tag("delete_picture.png"),send(:"lolita_#{tab.dbi.klass.model_name.singular}_upload_path", "#{tab.dbi.klass.model_name.singular}_id" => resource.nil? ? 0 : resource.id, :association => tab.association.name, :id=>file.id),:method=>:delete,:remote=>true,:confirm=>"Are you sure?" %>
|
5
11
|
</td>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
$("#upload_<%=tab.
|
2
|
-
$("input.<%=tab.
|
1
|
+
$("#upload_<%=tab.association.name%>_row_<%=file.id%>").remove()
|
2
|
+
$("input.<%=tab.association.name%>-ids[value=<%=file.id%>]").remove()
|