ideyabox 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/default.js +26 -1
- data/app/assets/stylesheets/default.scss.erb +74 -2
- data/app/helpers/admin_helper.rb +29 -46
- data/ideyabox.gemspec +1 -0
- data/lib/generators/ideyabox/.DS_Store +0 -0
- data/lib/generators/ideyabox/admin/admin_generator.rb +3 -1
- data/lib/generators/ideyabox/admin/templates/locales/ru.yml +1 -1
- data/lib/generators/ideyabox/admin/templates/views/layouts/admin.html.haml +1 -0
- data/lib/generators/ideyabox/images_scaffold/.DS_Store +0 -0
- data/lib/generators/ideyabox/images_scaffold/images_scaffold_generator.rb +182 -0
- data/lib/generators/ideyabox/images_scaffold/templates/.DS_Store +0 -0
- data/lib/generators/ideyabox/images_scaffold/templates/controllers/controller.rb +45 -0
- data/lib/generators/ideyabox/images_scaffold/templates/uploader.rb +55 -0
- data/lib/generators/ideyabox/images_scaffold/templates/views/_image.html.haml +10 -0
- data/lib/generators/ideyabox/images_scaffold/templates/views/_images.html.haml +8 -0
- data/lib/generators/ideyabox/images_scaffold/templates/views/create.js.haml +4 -0
- data/lib/generators/ideyabox/images_scaffold/templates/views/destroy.js.haml +1 -0
- data/lib/generators/ideyabox/images_scaffold/templates/views/edit.html.haml +29 -0
- data/lib/generators/ideyabox/scaffold/templates/_index.html.haml +1 -1
- data/lib/generators/ideyabox/scaffold/templates/controllers/controller.rb +13 -13
- data/lib/generators/ideyabox/scaffold/templates/edit.html.haml +2 -2
- data/lib/generators/ideyabox/scaffold/templates/index.html.haml +1 -1
- data/lib/ideyabox/version.rb +1 -1
- metadata +28 -2
@@ -8,6 +8,7 @@
|
|
8
8
|
//= require jquery.ui.nestedSortable
|
9
9
|
//= require chosen.jquery.js
|
10
10
|
|
11
|
+
//
|
11
12
|
$(document).ready(function(){
|
12
13
|
$(".chosen_select").chosen();
|
13
14
|
$('.pagination').hide();
|
@@ -17,7 +18,7 @@ $(document).ready(function(){
|
|
17
18
|
return false;
|
18
19
|
});
|
19
20
|
|
20
|
-
$('.visibility a').live('click', function(e){
|
21
|
+
$('.visibility a, .toggleshow').live('click', function(e){
|
21
22
|
e.preventDefault();
|
22
23
|
$(this).find('i').toggleClass('icon-eye-open').toggleClass('icon-eye-close not-work');
|
23
24
|
|
@@ -32,4 +33,28 @@ $(document).ready(function(){
|
|
32
33
|
});
|
33
34
|
e.preventDefault();
|
34
35
|
});
|
36
|
+
|
37
|
+
$('.image_upload_form form').fileupload({
|
38
|
+
dataType: "script",
|
39
|
+
add: function (e, data) {
|
40
|
+
types = /(\.|\/)(gif|jpe?g|png)$/i;
|
41
|
+
file = data.files[0];
|
42
|
+
if (types.test(file.type) || types.test(file.name)) {
|
43
|
+
data.context = $(tmpl("template-upload", data.files[0]));
|
44
|
+
$(".image_upload_form form").append(data.context);
|
45
|
+
data.submit();
|
46
|
+
} else {
|
47
|
+
alert(file.name + " is not a gif, jpeg, ot png image file");
|
48
|
+
}
|
49
|
+
},
|
50
|
+
progress: function (e, data) {
|
51
|
+
if (data.context !== null) {
|
52
|
+
progress = parseInt(data.loaded / data.total * 100, 10);
|
53
|
+
data.context.find('.bar').css('width', progress + '%');
|
54
|
+
}
|
55
|
+
},
|
56
|
+
done: function (e, data) {
|
57
|
+
data.context.html('<span>Загрузка файла <strong>\'' + file.name + '\'</strong> завершена.</span>');
|
58
|
+
}
|
59
|
+
});
|
35
60
|
});
|
@@ -16,7 +16,7 @@ $active_color:#C4FFCB;
|
|
16
16
|
$border_color:#d4d4d4;
|
17
17
|
$shadows: rgb(150,150,150);
|
18
18
|
|
19
|
-
html {overflow-y:scroll;}
|
19
|
+
html {overflow-y:scroll;width: 100%;}
|
20
20
|
body {width: 100%;
|
21
21
|
background: $bodycolor url(<%= asset_path 'admin/background-image.png' %>);
|
22
22
|
|
@@ -62,6 +62,7 @@ a.del {
|
|
62
62
|
border-radius: 20px;
|
63
63
|
background:$deepgreen;
|
64
64
|
}
|
65
|
+
form {width:100%;}
|
65
66
|
table {
|
66
67
|
width:100%;
|
67
68
|
border-collapse:collapse;
|
@@ -69,6 +70,7 @@ table {
|
|
69
70
|
|
70
71
|
tr {
|
71
72
|
//&:first-child {border-top:1px solid $border_color;}
|
73
|
+
width:100%;
|
72
74
|
border-top:1px solid $border_color;
|
73
75
|
border-bottom:1px solid $border_color;
|
74
76
|
}
|
@@ -160,7 +162,15 @@ ul.horizontal_items {
|
|
160
162
|
span {display:none;}
|
161
163
|
}
|
162
164
|
}
|
163
|
-
|
165
|
+
textarea {
|
166
|
+
width:100%;
|
167
|
+
}
|
168
|
+
img {
|
169
|
+
max-width:100%;
|
170
|
+
}
|
171
|
+
.clear {
|
172
|
+
clear:both;
|
173
|
+
}
|
164
174
|
#launchbar {
|
165
175
|
background: $deepgreen;overflow: hidden;position: relative;text-align: left;z-index: 9999;padding: 0 3%;
|
166
176
|
-webkit-box-shadow: 0 0 5px $shadows;
|
@@ -407,4 +417,66 @@ html.login {
|
|
407
417
|
margin:0 0 5px 0;
|
408
418
|
input {width:100%}
|
409
419
|
}
|
420
|
+
}
|
421
|
+
@mixin gradient($top, $bottom) {
|
422
|
+
background: $top;
|
423
|
+
background: -moz-linear-gradient(top, $top 0%, $bottom 100%);
|
424
|
+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,$top), color-stop(100%,$bottom));
|
425
|
+
background: -webkit-linear-gradient(top, $top 0%,$bottom 100%);
|
426
|
+
background: -o-linear-gradient(top, $top 0%,$bottom 100%);
|
427
|
+
background: -ms-linear-gradient(top, $top 0%,$bottom 100%);
|
428
|
+
background: linear-gradient(to bottom, $top 0%,$bottom 100%);
|
429
|
+
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5eb6ff', endColorstr='#006ed6',GradientType=0 );
|
430
|
+
}
|
431
|
+
.image-list li{
|
432
|
+
display:inline-block;
|
433
|
+
width:47%;
|
434
|
+
margin:3px 0.5%;
|
435
|
+
padding:0;
|
436
|
+
position:relative;
|
437
|
+
border:1px solid grey;
|
438
|
+
.image_control_panel {
|
439
|
+
position:absolute;
|
440
|
+
bottom:0;
|
441
|
+
height:2.5em;
|
442
|
+
background:rgba(255,255,255,0.7);
|
443
|
+
width:100%;
|
444
|
+
}
|
445
|
+
img {width:100%;}
|
446
|
+
a {
|
447
|
+
&.delete_image {
|
448
|
+
color:#000;
|
449
|
+
position:absolute;
|
450
|
+
right:0;
|
451
|
+
bottom:0;
|
452
|
+
&:hover {
|
453
|
+
color:red;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
&.toggleshow {
|
457
|
+
color:#000;
|
458
|
+
position:absolute;
|
459
|
+
left:0;
|
460
|
+
bottom:0;
|
461
|
+
.icon-eye-close {
|
462
|
+
color:#000;
|
463
|
+
}
|
464
|
+
&:hover {
|
465
|
+
color:#53B75F;
|
466
|
+
}
|
467
|
+
}
|
468
|
+
}
|
469
|
+
}
|
470
|
+
|
471
|
+
.upload {
|
472
|
+
strong {color:#1B7726;}
|
473
|
+
margin-bottom:0.5em;
|
474
|
+
}
|
475
|
+
.progress {
|
476
|
+
border:1px solid grey;
|
477
|
+
background:#E6E6E6;
|
478
|
+
}
|
479
|
+
.bar {
|
480
|
+
@include gradient(#53B75F, #1B7726);
|
481
|
+
height: 10px;
|
410
482
|
}
|
data/app/helpers/admin_helper.rb
CHANGED
@@ -37,11 +37,11 @@ module AdminHelper
|
|
37
37
|
url_for :only_path => false, :params => params.merge(overwrite)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
def image_sortable
|
41
41
|
%Q{
|
42
42
|
<script type="text/javascript">
|
43
43
|
$(document).ready(function() {
|
44
|
-
$('
|
44
|
+
$('.image-list').sortable( {
|
45
45
|
start: function(){$(this).find("a:not(.del)").unbind("click")},
|
46
46
|
stop: function(){lightBox.reload()},
|
47
47
|
dropOnEmpty: false,
|
@@ -52,9 +52,9 @@ module AdminHelper
|
|
52
52
|
update: function() {
|
53
53
|
$.ajax( {
|
54
54
|
type: 'post',
|
55
|
-
data: $('
|
55
|
+
data: $('.image-list').sortable('serialize') + '&authenticity_token=#{u(form_authenticity_token)}',
|
56
56
|
dataType: 'script',
|
57
|
-
url: '#{
|
57
|
+
url: '#{sort_admin_post_images_path(:auth_token => current_user.authentication_token)}'})
|
58
58
|
}
|
59
59
|
});
|
60
60
|
});
|
@@ -62,49 +62,32 @@ module AdminHelper
|
|
62
62
|
}.gsub(/[\n ]+/, ' ').strip.html_safe
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
$('#photo_upload').uploadify({
|
73
|
-
script : '#{raw(url)}',
|
74
|
-
fileDataName : '#{datatype}',
|
75
|
-
uploader : '/assets/uploadify/uploadify.swf',
|
76
|
-
cancelImg : '/assets/uploadify/cancel.png',
|
77
|
-
fileDesc : 'Images',
|
78
|
-
fileExt : '*.png;*.jpg;*.gif',
|
79
|
-
sizeLimit : #{10.megabytes},
|
80
|
-
queueSizeLimit : 24,
|
81
|
-
multi : true,
|
82
|
-
auto : true,
|
83
|
-
buttonText : 'Add photo',
|
84
|
-
buttonImg : '/assets/admin/addphoto.png',
|
85
|
-
width : 202,
|
86
|
-
height : 42,
|
87
|
-
scriptData : {
|
88
|
-
'_http_accept': 'application/javascript',
|
89
|
-
'#{session_key_name}' : encodeURIComponent('#{u(cookies[session_key_name])}'),
|
90
|
-
'authenticity_token' : encodeURIComponent('#{u(form_authenticity_token)}'),
|
91
|
-
'content_id' : encodeURIComponent('#{resource.slug}')
|
92
|
-
},
|
93
|
-
onComplete : function(a, b, c, response){ eval(response); },
|
94
|
-
onError : function (a, b, c, d) {
|
95
|
-
if (d.status == 404)
|
96
|
-
alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
|
97
|
-
else if (d.type === "HTTP")
|
98
|
-
console.log(d);
|
99
|
-
else if (d.type ==="File Size")
|
100
|
-
alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
|
101
|
-
else
|
102
|
-
alert('error '+d.type+": "+d.text);
|
103
|
-
}
|
104
|
-
});
|
105
|
-
</script>
|
65
|
+
def upload_form(parent, image)
|
66
|
+
new_image = image.new
|
67
|
+
undercored_image = image.to_s.underscore
|
68
|
+
form_for [:admin, parent, new_image], :id => "upload_form" do |f|
|
69
|
+
f.file_field :image, multiple: true, name: "#{undercored_image}[image]"
|
70
|
+
end
|
71
|
+
end
|
106
72
|
|
107
|
-
|
73
|
+
def upload_script
|
74
|
+
html = ''
|
75
|
+
html << "<script id='template-upload' type=\"text/x-tmpl\">"
|
76
|
+
html << "<div class='upload'>"
|
77
|
+
html << '{%= o.name %}'
|
78
|
+
html << "<div class='progress'>"
|
79
|
+
html << "<div class='bar' style=\"width: 0%\">"
|
80
|
+
html << "</div></div></div></script>"
|
81
|
+
return raw html
|
108
82
|
end
|
109
83
|
|
84
|
+
def uploader(parent, image)
|
85
|
+
html = ''
|
86
|
+
html << "#{upload_form(parent, image)}"
|
87
|
+
html << "#{upload_script}"
|
88
|
+
return raw html
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
110
93
|
end
|
data/ideyabox.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_dependency "kaminari"
|
21
21
|
gem.add_dependency "haml", ">= 3.1.6"
|
22
22
|
gem.add_dependency "devise"
|
23
|
+
gem.add_dependency "jquery-fileupload-rails"
|
23
24
|
gem.add_dependency "mini_magick"
|
24
25
|
gem.add_dependency "sexy_validators", ">=0.0.5"
|
25
26
|
gem.add_development_dependency "haml-rails", ">= 0.3.4"
|
Binary file
|
Binary file
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
module Ideyabox
|
5
|
+
module Generators
|
6
|
+
class ImagesScaffoldGenerator < ::Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
argument :controller_path, :type => :string
|
9
|
+
argument :model_name, :type => :string, :required => false
|
10
|
+
argument :layout, :type => :string, :default => "application",
|
11
|
+
:banner => "Specify application layout"
|
12
|
+
|
13
|
+
def initialize(args, *options)
|
14
|
+
super(args, *options)
|
15
|
+
initialize_views_variables
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_views
|
19
|
+
generate_views
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_locale_templates
|
23
|
+
add_to_locales
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_resources_and_root
|
27
|
+
add_resource_route
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_to_parent_view
|
31
|
+
final_string = "\n- content_for(:page_sidebar) do\n - unless @#{parent_name}.new_record?\n = render 'admin/#{plural_resource_name}/#{plural_resource_name}'\n"
|
32
|
+
|
33
|
+
inject_into_file "app/views/admin/#{plural_parent_name}/edit.html.haml", final_string, :before => "- content_for :page_header do"
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def updating_models
|
38
|
+
inject_into_file "app/models/#{parent_name}.rb", "\n has_many :#{plural_resource_name}", :after => "class #{parent_name.capitalize} < ActiveRecord::Base"
|
39
|
+
inject_into_file "app/models/#{resource_name}.rb", "\n belongs_to :#{parent_name}\n mount_uploader :image, #{@model_name.demodulize}Uploader", :after => "class #{@model_name.demodulize} < ActiveRecord::Base"
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def initialize_views_variables
|
45
|
+
@base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
|
46
|
+
@controller_routing_path = @controller_file_path.gsub(/\//, '_')
|
47
|
+
@model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
|
48
|
+
@model_name = @model_name.camelize
|
49
|
+
end
|
50
|
+
|
51
|
+
def controller_routing_path
|
52
|
+
@controller_routing_path
|
53
|
+
end
|
54
|
+
|
55
|
+
def singular_controller_routing_path
|
56
|
+
@controller_routing_path.singularize
|
57
|
+
end
|
58
|
+
|
59
|
+
def model_name
|
60
|
+
@model_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def plural_model_name
|
64
|
+
@model_name.pluralize
|
65
|
+
end
|
66
|
+
|
67
|
+
def resource_name
|
68
|
+
@model_name.demodulize.underscore
|
69
|
+
end
|
70
|
+
|
71
|
+
def parent_name
|
72
|
+
resource_name.split("_").first
|
73
|
+
end
|
74
|
+
|
75
|
+
def plural_parent_name
|
76
|
+
parent_name.pluralize
|
77
|
+
end
|
78
|
+
|
79
|
+
def plural_resource_name
|
80
|
+
resource_name.pluralize
|
81
|
+
end
|
82
|
+
|
83
|
+
def sort_priority(column_name)
|
84
|
+
case column_name
|
85
|
+
when "position" then 1
|
86
|
+
when "visible" then 2
|
87
|
+
when "name" then 3
|
88
|
+
when "title" then 3
|
89
|
+
else 5
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def columns
|
94
|
+
begin
|
95
|
+
excluded_column_names = %w[id created_at updated_at]
|
96
|
+
@model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) || c.name.index("_id") }.sort{|a, b| sort_priority(a.name) <=> sort_priority(b.name)}.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
|
97
|
+
rescue NoMethodError
|
98
|
+
@model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) || c.name.index("_id") }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def column_names
|
103
|
+
@model_name.constantize.column_names
|
104
|
+
end
|
105
|
+
|
106
|
+
def extract_modules(name)
|
107
|
+
modules = name.include?('/') ? name.split('/') : name.split('::')
|
108
|
+
name = modules.pop
|
109
|
+
path = modules.map { |m| m.underscore }
|
110
|
+
file_path = (path + [name.underscore]).join('/')
|
111
|
+
nesting = modules.map { |m| m.camelize }.join('::')
|
112
|
+
[name, path, file_path, nesting, modules.size]
|
113
|
+
end
|
114
|
+
|
115
|
+
def generate_views
|
116
|
+
views = {
|
117
|
+
"views/edit.html.#{ext}" => "app/views/admin/#{@controller_file_path}/edit.html.#{ext}",
|
118
|
+
"views/_image.html.#{ext}" => "app/views/admin/#{@controller_file_path}/_#{resource_name}.html.#{ext}",
|
119
|
+
"views/_images.html.#{ext}" => "app/views/admin/#{@controller_file_path}/_#{plural_resource_name}.html.#{ext}",
|
120
|
+
"views/create.js.haml" => "app/views/admin/#{@controller_file_path}/create.js.haml",
|
121
|
+
"views/destroy.js.haml" => "app/views/admin/#{@controller_file_path}/destroy.js.haml",
|
122
|
+
"uploader.rb" => "app/uploaders/#{resource_name}_uploader.rb"
|
123
|
+
|
124
|
+
}
|
125
|
+
views.delete("_sort_buttons.html.#{ext}") unless column_names.include?("position")
|
126
|
+
selected_views = views
|
127
|
+
options.engine == generate_erb(selected_views)
|
128
|
+
end
|
129
|
+
|
130
|
+
def generate_erb(views)
|
131
|
+
views.each do |template_name, output_path|
|
132
|
+
template template_name, output_path
|
133
|
+
end
|
134
|
+
generate_controller
|
135
|
+
end
|
136
|
+
|
137
|
+
def ext
|
138
|
+
:haml
|
139
|
+
end
|
140
|
+
|
141
|
+
def generate_controller
|
142
|
+
template "controllers/controller.rb", "app/controllers/admin/#{plural_resource_name}_controller.rb"
|
143
|
+
end
|
144
|
+
|
145
|
+
def add_resource_route
|
146
|
+
resources_string = "\n resources :#{plural_resource_name} do\n"
|
147
|
+
sort_string = " post \"sort\", :on => :collection\n"
|
148
|
+
toggleshow_string = " get \"toggleshow\", :on => :member\n"
|
149
|
+
|
150
|
+
if column_names.include?("visible") && column_names.include?("position")
|
151
|
+
final_string = "#{resources_string}#{sort_string}#{toggleshow_string} end\n"
|
152
|
+
elsif column_names.include?("visible")
|
153
|
+
final_string = "#{resources_string}#{toggleshow_string} end\n"
|
154
|
+
elsif column_names.include?("position")
|
155
|
+
final_string = "#{resources_string}#{sort_string} end\n"
|
156
|
+
else
|
157
|
+
final_string = "\n resources :#{plural_resource_name}\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
inject_into_file "config/routes.rb", final_string, :after => "\n namespace :admin do\n"
|
161
|
+
inject_into_file "config/routes.rb", "\n resources :#{plural_resource_name}\n", :after => "\n resources :#{plural_parent_name} do"
|
162
|
+
end
|
163
|
+
|
164
|
+
def add_to_locales
|
165
|
+
locales = [:ru, :en]
|
166
|
+
|
167
|
+
attributes = column_names.collect {|column| " #{column}: \"#{column}\"\n"}
|
168
|
+
|
169
|
+
attributes_string = " #{resource_name}:\n#{attributes.join}"
|
170
|
+
|
171
|
+
locales.each do |locale|
|
172
|
+
inject_into_file "config/locales/#{locale}.yml", " #{resource_name}: \"#{resource_name}\"\n", :after => "models:\n"
|
173
|
+
inject_into_file "config/locales/#{locale}.yml", attributes_string, :after => "attributes:\n"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
Binary file
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
class Admin::<%= @model_name.demodulize.pluralize -%>Controller < Admin::ApplicationController
|
3
|
+
|
4
|
+
<%- if column_names.include?("visible") -%>
|
5
|
+
def toggleshow
|
6
|
+
@<%= plural_resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
7
|
+
@<%= plural_resource_name %>.toggle(:visible)
|
8
|
+
@<%= plural_resource_name %>.save
|
9
|
+
render :nothing => true
|
10
|
+
end
|
11
|
+
<%- end -%><%- if column_names.include?("position") -%>
|
12
|
+
def sort
|
13
|
+
params[:<%= resource_name %>].each_with_index do |id, idx|
|
14
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(id)
|
15
|
+
@<%= resource_name %>.position = idx
|
16
|
+
@<%= resource_name %>.save
|
17
|
+
end
|
18
|
+
render :nothing => true
|
19
|
+
end
|
20
|
+
<%- end -%>
|
21
|
+
|
22
|
+
def edit
|
23
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@<%= parent_name %> = <%= parent_name.capitalize -%>.find(params[:<%= parent_name %>_id])
|
28
|
+
@<%= resource_name %> = @<%= parent_name %>.<%= plural_resource_name %>.create(params[:<%= resource_name %>])
|
29
|
+
end
|
30
|
+
|
31
|
+
def update
|
32
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
33
|
+
if @<%= resource_name %>.update_attributes(params[:<%= resource_name %>])
|
34
|
+
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= @model_name.demodulize %>.model_name.human} #{t 'flash.notice.was_updated'}"
|
35
|
+
else
|
36
|
+
render 'edit'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
42
|
+
@<%= resource_name %>.destroy
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class <%= @model_name.demodulize %>Uploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
# include CarrierWave::RMagick
|
7
|
+
include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
|
10
|
+
# include Sprockets::Helpers::RailsHelper
|
11
|
+
# include Sprockets::Helpers::IsolatedHelper
|
12
|
+
|
13
|
+
# Choose what kind of storage to use for this uploader:
|
14
|
+
storage :file
|
15
|
+
# storage :fog
|
16
|
+
|
17
|
+
# Override the directory where uploaded files will be stored.
|
18
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
19
|
+
def store_dir
|
20
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
24
|
+
# def default_url
|
25
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
26
|
+
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
27
|
+
#
|
28
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
29
|
+
# end
|
30
|
+
|
31
|
+
# Process files as they are uploaded:
|
32
|
+
# process :scale => [200, 300]
|
33
|
+
#
|
34
|
+
# def scale(width, height)
|
35
|
+
# # do something
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Create different versions of your uploaded files:
|
39
|
+
version :admin_mini do
|
40
|
+
process :resize_to_fill => [160, 100]
|
41
|
+
end
|
42
|
+
|
43
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
44
|
+
# For images you might use something like this:
|
45
|
+
def extension_white_list
|
46
|
+
%w(jpg jpeg gif png)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Override the filename of the uploaded files:
|
50
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
51
|
+
# def filename
|
52
|
+
# "something.jpg" if original_filename
|
53
|
+
# end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%li{:id => "<%= resource_name %>_#{<%= resource_name %>.id}"}
|
2
|
+
= link_to [:edit, :admin, @<%= parent_name %>, <%= resource_name %>] do
|
3
|
+
= image_tag(<%= resource_name %>.image_url(:admin_mini), :class=>"admin_mini")
|
4
|
+
.image_control_panel
|
5
|
+
= link_to [:admin, @<%= parent_name %>, <%= resource_name %>], :remote => true, :method => :delete, :confirm => "#{t 'confirm.delete'}", :class=>'delete_image' do
|
6
|
+
%i{:class => "icon-trash icon-large"}
|
7
|
+
<%- if column_names.include?("visible") %>
|
8
|
+
= link_to [:toggleshow, :admin, <%= resource_name %>], :remote => true, :class=>'toggleshow' do
|
9
|
+
%i{:class => (<%= resource_name %>.visible? ? "icon-eye-open icon-large" : "icon-eye-close icon-large not-work")}
|
10
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
$("#<%= resource_name %>_#{@<%= resource_name %>.id}").remove();
|
@@ -0,0 +1,29 @@
|
|
1
|
+
- content_for :page_header do
|
2
|
+
%p= link_to t('back'), [:edit, :admin, @<%=resource_name%>.<%= parent_name %>], :class => "bright_link"
|
3
|
+
%h1
|
4
|
+
- if @<%=resource_name%>.new_record?
|
5
|
+
= "#{t 'add'} #{<%= @model_name.demodulize %>.model_name.human}"
|
6
|
+
- else
|
7
|
+
= "#{t 'edit'} #{<%= @model_name.demodulize %>.model_name.human}"
|
8
|
+
|
9
|
+
= form_for [:admin, @<%=resource_name%>.<%= parent_name %>, @<%=resource_name%>] do |f|
|
10
|
+
- if @<%=resource_name%>.errors.any?
|
11
|
+
#error_explanation
|
12
|
+
%h2= "#{t 'save_errors'}: #{@<%=resource_name%>.errors.count}"
|
13
|
+
%ul
|
14
|
+
- @<%=resource_name%>.errors.full_messages.each do |msg|
|
15
|
+
%li= msg
|
16
|
+
%table
|
17
|
+
%tr
|
18
|
+
%th{colspan: 2}
|
19
|
+
- if @<%=resource_name%>.image && @<%=resource_name%>.image_url
|
20
|
+
= image_tag @<%=resource_name%>.image_url
|
21
|
+
%br
|
22
|
+
Выберите другое изображение
|
23
|
+
%br
|
24
|
+
%tr
|
25
|
+
%th= f.label :image
|
26
|
+
%td= f.file_field :image
|
27
|
+
|
28
|
+
.actions
|
29
|
+
= f.submit t('save')
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<%- if column.name=='position' || column.name=='visible'-%>
|
6
6
|
%th{:class => <%= (column.name=='position') ? "\'position\'" : "\'visibility\'" %>}
|
7
7
|
<%- else -%>
|
8
|
-
<%= "%th= sortable_columns \"#{column.name}\", #{
|
8
|
+
<%= "%th= sortable_columns \"#{column.name}\", #{@model_name.demodulize}.human_attribute_name(\"#{column.name}\")" %>
|
9
9
|
<%- end -%>
|
10
10
|
<%- end -%>
|
11
11
|
%th
|
@@ -1,9 +1,9 @@
|
|
1
1
|
#coding: utf-8
|
2
|
-
class Admin::<%=
|
2
|
+
class Admin::<%= @model_name.demodulize.pluralize -%>Controller < Admin::ApplicationController
|
3
3
|
helper_method :sort_column, :sort_direction
|
4
4
|
<%- if column_names.include?("visible") -%>
|
5
5
|
def toggleshow
|
6
|
-
@<%= plural_resource_name %> = <%=
|
6
|
+
@<%= plural_resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
7
7
|
@<%= plural_resource_name %>.toggle(:visible)
|
8
8
|
@<%= plural_resource_name %>.save
|
9
9
|
render :nothing => true
|
@@ -11,7 +11,7 @@ class Admin::<%= plural_resource_name.capitalize -%>Controller < Admin::Applicat
|
|
11
11
|
<%- end -%><%- if column_names.include?("position") -%>
|
12
12
|
def sort
|
13
13
|
params[:<%= resource_name %>].each_with_index do |id, idx|
|
14
|
-
@<%= resource_name %> = <%=
|
14
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(id)
|
15
15
|
@<%= resource_name %>.position = idx
|
16
16
|
@<%= resource_name %>.save
|
17
17
|
end
|
@@ -19,46 +19,46 @@ class Admin::<%= plural_resource_name.capitalize -%>Controller < Admin::Applicat
|
|
19
19
|
end
|
20
20
|
<%- end -%>
|
21
21
|
def index
|
22
|
-
@<%= plural_resource_name %> = <%=
|
22
|
+
@<%= plural_resource_name %> = <%= @model_name.demodulize -%>.order(sort_column + " " + sort_direction)
|
23
23
|
end
|
24
24
|
|
25
25
|
def new
|
26
|
-
@<%= resource_name %> = <%=
|
26
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.new
|
27
27
|
render 'edit'
|
28
28
|
end
|
29
29
|
|
30
30
|
def edit
|
31
|
-
@<%= resource_name %> = <%=
|
31
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
32
32
|
end
|
33
33
|
|
34
34
|
def create
|
35
|
-
@<%= resource_name %> = <%=
|
35
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.new(params[:<%= resource_name %>])
|
36
36
|
if @<%= resource_name %>.save
|
37
|
-
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%=
|
37
|
+
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= @model_name.demodulize %>.model_name.human} #{t 'flash.notice.was_added'}"
|
38
38
|
else
|
39
39
|
render 'edit'
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def update
|
44
|
-
@<%= resource_name %> = <%=
|
44
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
45
45
|
if @<%= resource_name %>.update_attributes(params[:<%= resource_name %>])
|
46
|
-
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%=
|
46
|
+
redirect_to admin_<%= plural_resource_name %>_path, :notice => "#{<%= @model_name.demodulize %>.model_name.human} #{t 'flash.notice.was_updated'}"
|
47
47
|
else
|
48
48
|
render 'edit'
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def destroy
|
53
|
-
@<%= resource_name %> = <%=
|
53
|
+
@<%= resource_name %> = <%= @model_name.demodulize -%>.find(params[:id])
|
54
54
|
@<%= resource_name %>.destroy
|
55
|
-
redirect_to admin_<%= plural_resource_name %>_path, :alert => "#{<%=
|
55
|
+
redirect_to admin_<%= plural_resource_name %>_path, :alert => "#{<%= @model_name.demodulize %>.model_name.human} #{t 'flash.notice.was_deleted'}"
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
60
|
def sort_column
|
61
|
-
<%=
|
61
|
+
<%= @model_name.demodulize -%>.column_names.include?(params[:sort]) ? params[:sort] : <%= column_names.include?("position") ? "\'position\'" : "\'created_at\'" %>
|
62
62
|
end
|
63
63
|
|
64
64
|
def sort_direction
|
@@ -2,9 +2,9 @@
|
|
2
2
|
%p= link_to t('back'), admin_<%= controller_routing_path %>_path, :class => "bright_link"
|
3
3
|
%h1
|
4
4
|
- if @<%= resource_name %>.new_record?
|
5
|
-
= "#{t 'add'} #{<%=
|
5
|
+
= "#{t 'add'} #{<%= @model_name.demodulize %>.model_name.human}"
|
6
6
|
- else
|
7
|
-
= "#{t 'edit'} #{<%=
|
7
|
+
= "#{t 'edit'} #{<%= @model_name.demodulize %>.model_name.human}"
|
8
8
|
|
9
9
|
= form_for [:admin, @<%= resource_name %>] do |f|
|
10
10
|
- if @<%= resource_name %>.errors.any?
|
@@ -1,5 +1,5 @@
|
|
1
1
|
- content_for(:page_header) do
|
2
|
-
%p= link_to "#{t 'add'} #{<%=
|
2
|
+
%p= link_to "#{t 'add'} #{<%= @model_name.demodulize %>.model_name.human}", new_admin_<%= singular_controller_routing_path %>_path, :class => "bright_link"
|
3
3
|
%h1= link_to '<%= plural_resource_name %>', admin_<%= plural_resource_name %>_path
|
4
4
|
-#= paginate @<%= plural_resource_name %>
|
5
5
|
<%= if column_names.include?("position")
|
data/lib/ideyabox/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ideyabox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: russian
|
@@ -92,6 +92,22 @@ dependencies:
|
|
92
92
|
- - ! '>='
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: jquery-fileupload-rails
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
95
111
|
- !ruby/object:Gem::Dependency
|
96
112
|
name: mini_magick
|
97
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,6 +244,16 @@ files:
|
|
228
244
|
- lib/generators/ideyabox/admin/templates/views/layouts/admin.html.haml
|
229
245
|
- lib/generators/ideyabox/admin/templates/views/layouts/login.html.haml
|
230
246
|
- lib/generators/ideyabox/assets/assets_generator.rb
|
247
|
+
- lib/generators/ideyabox/images_scaffold/.DS_Store
|
248
|
+
- lib/generators/ideyabox/images_scaffold/images_scaffold_generator.rb
|
249
|
+
- lib/generators/ideyabox/images_scaffold/templates/.DS_Store
|
250
|
+
- lib/generators/ideyabox/images_scaffold/templates/controllers/controller.rb
|
251
|
+
- lib/generators/ideyabox/images_scaffold/templates/uploader.rb
|
252
|
+
- lib/generators/ideyabox/images_scaffold/templates/views/_image.html.haml
|
253
|
+
- lib/generators/ideyabox/images_scaffold/templates/views/_images.html.haml
|
254
|
+
- lib/generators/ideyabox/images_scaffold/templates/views/create.js.haml
|
255
|
+
- lib/generators/ideyabox/images_scaffold/templates/views/destroy.js.haml
|
256
|
+
- lib/generators/ideyabox/images_scaffold/templates/views/edit.html.haml
|
231
257
|
- lib/generators/ideyabox/scaffold/.DS_Store
|
232
258
|
- lib/generators/ideyabox/scaffold/scaffold_generator.rb
|
233
259
|
- lib/generators/ideyabox/scaffold/templates/.DS_Store
|