adminpanel 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -2
- data/.ruby-version +1 -0
- data/.travis.yml +8 -8
- data/Gemfile +26 -24
- data/README.md +57 -57
- data/adminpanel.gemspec +41 -39
- data/app/assets/fonts/fontawesome-webfont.svg +254 -254
- data/app/assets/javascripts/adminpanel/bootstrap-datepicker.js +1159 -1159
- data/app/assets/javascripts/adminpanel/bootstrap-timepicker.js +803 -803
- data/app/assets/javascripts/adminpanel/bootstrap.js +2170 -2170
- data/app/assets/javascripts/adminpanel/{products.js → images_form.js} +13 -13
- data/app/assets/javascripts/adminpanel/imagesloaded.js +12 -12
- data/app/assets/javascripts/adminpanel/jquery.dataTables.min.js +155 -155
- data/app/assets/javascripts/adminpanel/jquery.facybox.js +395 -395
- data/app/assets/javascripts/adminpanel/jquery.masonry.min.js +9 -9
- data/app/assets/javascripts/adminpanel/jquery.slimscroll.min.js +13 -13
- data/app/assets/javascripts/adminpanel/medium-editor.js +702 -702
- data/app/assets/javascripts/adminpanel/realm.js +87 -87
- data/app/assets/javascripts/adminpanel/tables.js +126 -126
- data/app/assets/javascripts/application-admin.js +15 -15
- data/app/assets/stylesheets/adminpanel/_clearfix.css.scss +7 -7
- data/app/assets/stylesheets/adminpanel/alertify.css +241 -241
- data/app/assets/stylesheets/adminpanel/bootstrap.css +6103 -6103
- data/app/assets/stylesheets/adminpanel/colorpicker.css +6 -6
- data/app/assets/stylesheets/adminpanel/datepicker.css +9 -9
- data/app/assets/stylesheets/adminpanel/elfinder.min.css +59 -59
- data/app/assets/stylesheets/adminpanel/facybox.css +146 -146
- data/app/assets/stylesheets/adminpanel/font-awesome.min.css +33 -33
- data/app/assets/stylesheets/adminpanel/fullcalendar.css +618 -618
- data/app/assets/stylesheets/adminpanel/fullcalendar.print.css +61 -61
- data/app/assets/stylesheets/adminpanel/select2.css +524 -524
- data/app/assets/stylesheets/adminpanel/theme.css +1571 -1571
- data/app/assets/stylesheets/adminpanel/timepicker.css +82 -82
- data/app/assets/stylesheets/application-admin.css +13 -13
- data/app/controllers/adminpanel/application_controller.rb +32 -17
- data/app/controllers/adminpanel/galleries_controller.rb +80 -80
- data/app/controllers/adminpanel/sections_controller.rb +45 -45
- data/app/controllers/adminpanel/sessions_controller.rb +26 -26
- data/app/controllers/adminpanel/users_controller.rb +84 -84
- data/app/helpers/adminpanel/application_helper.rb +41 -51
- data/app/helpers/adminpanel/breadcrumbs_helper.rb +16 -0
- data/app/helpers/adminpanel/custom_form_builder.rb +248 -0
- data/app/helpers/adminpanel/images_helper.rb +9 -9
- data/app/helpers/adminpanel/rest_actions_helper.rb +47 -0
- data/app/helpers/adminpanel/router_helper.rb +33 -0
- data/app/helpers/adminpanel/sessions_helper.rb +25 -25
- data/app/models/adminpanel/gallery.rb +60 -60
- data/app/models/adminpanel/image.rb +14 -14
- data/app/models/adminpanel/section.rb +22 -22
- data/app/models/adminpanel/user.rb +35 -35
- data/app/uploaders/adminpanel/gallery_uploader.rb +55 -55
- data/app/uploaders/adminpanel/image_uploader.rb +57 -57
- data/app/views/adminpanel/galleries/_galleries_table.html.erb +14 -14
- data/app/views/adminpanel/galleries/create.html.erb +2 -2
- data/app/views/adminpanel/galleries/delete.html.erb +2 -2
- data/app/views/adminpanel/galleries/edit.html.erb +25 -25
- data/app/views/adminpanel/galleries/index.html.erb +51 -51
- data/app/views/adminpanel/galleries/new.html.erb +17 -17
- data/app/views/adminpanel/galleries/show.html.erb +17 -17
- data/app/views/adminpanel/galleries/update.html.erb +2 -2
- data/app/views/adminpanel/sections/_image_fields.html.erb +23 -23
- data/app/views/adminpanel/sections/_sections_table.html.erb +16 -16
- data/app/views/adminpanel/sections/create.html.erb +2 -2
- data/app/views/adminpanel/sections/destroy.html.erb +2 -2
- data/app/views/adminpanel/sections/edit.html.erb +41 -41
- data/app/views/adminpanel/sections/index.html.erb +44 -44
- data/app/views/adminpanel/sections/new.html.erb +26 -26
- data/app/views/adminpanel/sections/show.html.erb +30 -30
- data/app/views/adminpanel/sections/update.html.erb +2 -2
- data/app/views/adminpanel/sessions/new.html.erb +25 -25
- data/app/views/adminpanel/users/_user_form.html.erb +20 -20
- data/app/views/adminpanel/users/edit.html.erb +5 -5
- data/app/views/adminpanel/users/index.html.erb +49 -49
- data/app/views/adminpanel/users/new.html.erb +5 -5
- data/app/views/adminpanel/users/show.html.erb +20 -20
- data/app/views/layouts/_shim.html.erb +3 -3
- data/app/views/layouts/_side_menu.html.erb +49 -43
- data/app/views/layouts/_top_bar.html.erb +43 -43
- data/app/views/layouts/admin-login.html.erb +28 -28
- data/app/views/layouts/admin.html.erb +41 -39
- data/app/views/shared/_breadcrumb.html.erb +6 -6
- data/app/views/shared/_error_messages.html.erb +16 -16
- data/app/views/shared/_form_fields.html.erb +25 -0
- data/app/views/{adminpanel/products → shared}/_image_fields.html.erb +23 -23
- data/app/views/shared/_init_editor.html.erb +24 -0
- data/app/views/shared/edit.html.erb +28 -0
- data/app/views/shared/index.html.erb +94 -0
- data/app/views/shared/new.html.erb +28 -0
- data/app/views/shared/show.html.erb +63 -0
- data/config/locales/en.yml +5 -5
- data/config/locales/es.yml +127 -129
- data/config/routes.rb +24 -16
- data/lib/adminpanel.rb +9 -7
- data/lib/adminpanel/active_record_extension.rb +38 -0
- data/lib/adminpanel/engine.rb +5 -5
- data/lib/adminpanel/version.rb +3 -3
- data/lib/generators/adminpanel/initialize/initialize_generator.rb +17 -0
- data/lib/generators/adminpanel/{install/templates/migrations → initialize/templates}/create_adminpanel_tables.rb +45 -64
- data/lib/generators/adminpanel/resource/resource_generator.rb +105 -0
- data/lib/generators/adminpanel/resource/templates/controller.rb +4 -0
- data/lib/generators/adminpanel/resource/templates/migration.rb +9 -0
- data/lib/generators/adminpanel/resource/templates/resource.rb +19 -0
- data/spec/dummy/.gitignore +17 -17
- data/spec/dummy/README.rdoc +261 -261
- data/spec/dummy/Rakefile +7 -7
- data/{app/views/adminpanel/categories/show.html.erb → spec/dummy/app/adminpanel/products.rb} +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -13
- data/spec/dummy/app/assets/stylesheets/application.css +13 -13
- data/spec/dummy/app/controllers/adminpanel/.gitkeep +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -11
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/views/layouts/application.html.erb +14 -14
- data/spec/dummy/config.ru +4 -4
- data/spec/dummy/config/application.rb +62 -62
- data/spec/dummy/config/boot.rb +9 -9
- data/spec/dummy/config/carrierwve.rb +5 -5
- data/spec/dummy/config/database.yml +24 -24
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +41 -41
- data/spec/dummy/config/environments/production.rb +72 -72
- data/spec/dummy/config/environments/test.rb +41 -41
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/inflections.rb +15 -15
- data/spec/dummy/config/initializers/mime_types.rb +5 -5
- data/spec/dummy/config/initializers/secret_token.rb +8 -8
- data/spec/dummy/config/initializers/session_store.rb +8 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +5 -5
- data/spec/dummy/config/routes.rb +4 -4
- data/spec/dummy/db/schema.rb +15 -15
- data/spec/dummy/public/404.html +26 -26
- data/spec/dummy/public/422.html +26 -26
- data/spec/dummy/public/500.html +25 -25
- data/spec/dummy/public/uploads/gallery/file/1/hipster.jpg +0 -0
- data/spec/dummy/public/uploads/gallery/file/1/thumb_hipster.jpg +0 -0
- data/spec/dummy/script/rails +6 -6
- data/spec/features/authentication_pages_spec.rb +43 -43
- data/spec/features/galleries_pages_spec.rb +124 -124
- data/spec/features/section_pages_spec.rb +37 -37
- data/spec/features/user_pages_spec.rb +48 -48
- data/spec/generators/initialize_spec.rb +9 -0
- data/spec/generators/resource_spec.rb +122 -0
- data/spec/models/gallery_spec.rb +21 -21
- data/spec/models/section_spec.rb +66 -66
- data/spec/models/user_spec.rb +105 -105
- data/spec/spec_helper.rb +32 -31
- data/spec/support/define_factory_models.rb +25 -36
- data/spec/support/helper_methods.rb +26 -26
- data/spec/support/submit_forms_without_button.rb +16 -16
- data/spec/support/test_database.rb +45 -58
- data/spec/uploaders/gallery_uploader_spec.rb +36 -30
- data/spec/uploaders/image_uploader_spec.rb +30 -29
- metadata +208 -64
- checksums.yaml +0 -7
- data/app/assets/javascripts/adminpanel/init_editor.js +0 -28
- data/app/controllers/adminpanel/categories_controller.rb +0 -41
- data/app/controllers/adminpanel/products_controller.rb +0 -88
- data/app/helpers/custom_form_builder.rb +0 -219
- data/app/models/adminpanel/category.rb +0 -7
- data/app/models/adminpanel/product.rb +0 -24
- data/app/views/adminpanel/categories/edit.html.erb +0 -18
- data/app/views/adminpanel/categories/index.html.erb +0 -55
- data/app/views/adminpanel/categories/new.html.erb +0 -18
- data/app/views/adminpanel/products/.DS_Store +0 -0
- data/app/views/adminpanel/products/_product_form.html.erb +0 -31
- data/app/views/adminpanel/products/edit.html.erb +0 -10
- data/app/views/adminpanel/products/index.html.erb +0 -51
- data/app/views/adminpanel/products/new.html.erb +0 -10
- data/app/views/adminpanel/products/show.html.erb +0 -61
- data/config/database.yml +0 -24
- data/lib/generators/adminpanel/install/install_generator.rb +0 -12
- data/spec/features/categories_pages_spec.rb +0 -44
- data/spec/features/product_pages_spec.rb +0 -64
- data/spec/models/category_spec.rb +0 -58
- data/spec/models/product_spec.rb +0 -51
@@ -1,10 +1,10 @@
|
|
1
|
-
module Adminpanel
|
2
|
-
module ImagesHelper
|
3
|
-
|
4
|
-
def is_class?(name)
|
5
|
-
Module.const_get(name).is_a?(Class)
|
6
|
-
rescue NameError
|
7
|
-
return false
|
8
|
-
end
|
9
|
-
end
|
1
|
+
module Adminpanel
|
2
|
+
module ImagesHelper
|
3
|
+
|
4
|
+
def is_class?(name)
|
5
|
+
Module.const_get(name).is_a?(Class)
|
6
|
+
rescue NameError
|
7
|
+
return false
|
8
|
+
end
|
9
|
+
end
|
10
10
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Adminpanel
|
2
|
+
module RestActionsHelper
|
3
|
+
def index
|
4
|
+
index! do |format|
|
5
|
+
format.html { render "shared/index" }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
show! do |format|
|
11
|
+
format.html { render "shared/show" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def new
|
16
|
+
new! do |format|
|
17
|
+
format.html { render "shared/new" }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def create
|
22
|
+
create! do |success, failure|
|
23
|
+
success.html { render "shared/index" }
|
24
|
+
failure.html { render "shared/new"}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def edit
|
29
|
+
edit! do |format|
|
30
|
+
format.html { render "shared/edit" }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
update! do |success, failure|
|
36
|
+
success.html { render "shared/index" }
|
37
|
+
failure.html { render "shared/update" }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
destroy! do |format|
|
43
|
+
format.html { render "shared/index" }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Adminpanel
|
2
|
+
module RouterHelper
|
3
|
+
def adminpanel_resources
|
4
|
+
@files ||= find_resources
|
5
|
+
end
|
6
|
+
|
7
|
+
def find_resources
|
8
|
+
resources_path
|
9
|
+
if File.directory?(resources_path)
|
10
|
+
files = Dir.entries(resources_path).collect do |f|
|
11
|
+
unless default_controllers.include?(f)
|
12
|
+
file_path = "#{resources_path}#{f}"
|
13
|
+
File.file?(file_path) ? file_path.sub!(resources_path, '').sub!('_controller.rb', '') : nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
files.compact!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def menu_items
|
22
|
+
@menu ||= adminpanel_resources.each.collect { |resource| resource.classify }
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_controllers
|
26
|
+
["application_controller.rb", "sessions_controller.rb", "galleries_controller.rb", "users_controller.rb", "sections_controller.rb"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def resources_path
|
30
|
+
"#{Rails.root.to_s}/app/controllers/adminpanel/"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
module Adminpanel
|
2
|
-
module SessionsHelper
|
3
|
-
|
4
|
-
def sign_in(user)
|
5
|
-
cookies.permanent[:remember_token] = user.remember_token
|
6
|
-
self.current_user = user
|
7
|
-
end
|
8
|
-
|
9
|
-
def signed_in?
|
10
|
-
!current_user.nil?
|
11
|
-
end
|
12
|
-
|
13
|
-
def current_user=(user)
|
14
|
-
@current_user = user
|
15
|
-
end
|
16
|
-
|
17
|
-
def current_user
|
18
|
-
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
|
19
|
-
end
|
20
|
-
|
21
|
-
def sign_out
|
22
|
-
self.current_user = nil
|
23
|
-
cookies.delete(:remember_token)
|
24
|
-
end
|
25
|
-
end
|
1
|
+
module Adminpanel
|
2
|
+
module SessionsHelper
|
3
|
+
|
4
|
+
def sign_in(user)
|
5
|
+
cookies.permanent[:remember_token] = user.remember_token
|
6
|
+
self.current_user = user
|
7
|
+
end
|
8
|
+
|
9
|
+
def signed_in?
|
10
|
+
!current_user.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_user=(user)
|
14
|
+
@current_user = user
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_user
|
18
|
+
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
|
19
|
+
end
|
20
|
+
|
21
|
+
def sign_out
|
22
|
+
self.current_user = nil
|
23
|
+
cookies.delete(:remember_token)
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
@@ -1,61 +1,61 @@
|
|
1
|
-
require "carrierwave"
|
2
|
-
require "carrierwave/orm/activerecord"
|
3
|
-
module Adminpanel
|
4
|
-
class Gallery < ActiveRecord::Base
|
5
|
-
attr_accessible :file
|
6
|
-
|
7
|
-
mount_uploader :file, Adminpanel::GalleryUploader
|
8
|
-
validates_presence_of :file
|
9
|
-
before_create :set_position
|
10
|
-
before_destroy :rearrange_positions
|
11
|
-
|
12
|
-
|
13
|
-
default_scope { order("position ASC")}
|
14
|
-
|
15
|
-
|
16
|
-
def move_to_better_position
|
17
|
-
if position > 1
|
18
|
-
conflicting_gallery = Gallery.find_by_position(position - 1)
|
19
|
-
update_attribute(:position, position - 1)
|
20
|
-
conflicting_gallery.update_attribute(
|
21
|
-
:position, conflicting_gallery.position + 1
|
22
|
-
)
|
23
|
-
true
|
24
|
-
else
|
25
|
-
false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def move_to_worst_position
|
30
|
-
records = Gallery.count
|
31
|
-
if position < records
|
32
|
-
conflicting_gallery = Gallery.find_by_position(position + 1)
|
33
|
-
update_attribute(:position, position + 1)
|
34
|
-
conflicting_gallery.update_attribute(
|
35
|
-
:position, conflicting_gallery.position - 1
|
36
|
-
)
|
37
|
-
true
|
38
|
-
else
|
39
|
-
false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def rearrange_positions
|
45
|
-
unarranged_galleries = Gallery.where("position > ?", position)
|
46
|
-
unarranged_galleries.each do |gallery|
|
47
|
-
gallery.update_attribute(:position, gallery.position - 1)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
def set_position
|
53
|
-
last_record = Gallery.last
|
54
|
-
if last_record.nil?
|
55
|
-
self.position = 1
|
56
|
-
else
|
57
|
-
self.position = last_record.position + 1
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
1
|
+
require "carrierwave"
|
2
|
+
require "carrierwave/orm/activerecord"
|
3
|
+
module Adminpanel
|
4
|
+
class Gallery < ActiveRecord::Base
|
5
|
+
attr_accessible :file
|
6
|
+
|
7
|
+
mount_uploader :file, Adminpanel::GalleryUploader
|
8
|
+
validates_presence_of :file
|
9
|
+
before_create :set_position
|
10
|
+
before_destroy :rearrange_positions
|
11
|
+
|
12
|
+
|
13
|
+
default_scope { order("position ASC")}
|
14
|
+
|
15
|
+
|
16
|
+
def move_to_better_position
|
17
|
+
if position > 1
|
18
|
+
conflicting_gallery = Gallery.find_by_position(position - 1)
|
19
|
+
update_attribute(:position, position - 1)
|
20
|
+
conflicting_gallery.update_attribute(
|
21
|
+
:position, conflicting_gallery.position + 1
|
22
|
+
)
|
23
|
+
true
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def move_to_worst_position
|
30
|
+
records = Gallery.count
|
31
|
+
if position < records
|
32
|
+
conflicting_gallery = Gallery.find_by_position(position + 1)
|
33
|
+
update_attribute(:position, position + 1)
|
34
|
+
conflicting_gallery.update_attribute(
|
35
|
+
:position, conflicting_gallery.position - 1
|
36
|
+
)
|
37
|
+
true
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def rearrange_positions
|
45
|
+
unarranged_galleries = Gallery.where("position > ?", position)
|
46
|
+
unarranged_galleries.each do |gallery|
|
47
|
+
gallery.update_attribute(:position, gallery.position - 1)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_position
|
53
|
+
last_record = Gallery.last
|
54
|
+
if last_record.nil?
|
55
|
+
self.position = 1
|
56
|
+
else
|
57
|
+
self.position = last_record.position + 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
61
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module Adminpanel
|
2
|
-
class Image < ActiveRecord::Base
|
3
|
-
extend ImagesHelper
|
4
|
-
|
5
|
-
attr_accessible :file, :foreign_key, :model
|
6
|
-
validates_presence_of :model
|
7
|
-
validates_presence_of :file
|
8
|
-
|
9
|
-
if is_class?("
|
10
|
-
mount_uploader :file,
|
11
|
-
else
|
12
|
-
mount_uploader :file, Adminpanel::ImageUploader
|
13
|
-
end
|
14
|
-
end
|
1
|
+
module Adminpanel
|
2
|
+
class Image < ActiveRecord::Base
|
3
|
+
extend ImagesHelper
|
4
|
+
|
5
|
+
attr_accessible :file, :foreign_key, :model
|
6
|
+
validates_presence_of :model
|
7
|
+
validates_presence_of :file
|
8
|
+
|
9
|
+
if is_class?("CustomImageUploader")
|
10
|
+
mount_uploader :file, CustomImageUploader
|
11
|
+
else
|
12
|
+
mount_uploader :file, Adminpanel::ImageUploader
|
13
|
+
end
|
14
|
+
end
|
15
15
|
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require 'carrierwave'
|
2
|
-
require 'carrierwave/orm/activerecord'
|
3
|
-
module Adminpanel
|
4
|
-
class Section < ActiveRecord::Base
|
5
|
-
attr_accessible :description, :has_image, :key, :page, :name, :has_description, :images_attributes
|
6
|
-
has_many :images, :foreign_key => "foreign_key", :conditions => { :model => "Section" }
|
7
|
-
accepts_nested_attributes_for :images, :allow_destroy => true
|
8
|
-
validates_length_of :description, :minimum => 10, :maximum => 10, :on => :update, :if => lambda{|section| section.key == "telephone"}
|
9
|
-
validates_presence_of :description, :minimum => 9, :on => :update, :if => lambda{|section| section.has_description == true}
|
10
|
-
validates :description, :numericality => { :only_integer => true }, :on => :update, :if => lambda{|section| section.key == "telephone"}
|
11
|
-
validates_presence_of :key
|
12
|
-
validates_presence_of :name
|
13
|
-
validates_presence_of :page
|
14
|
-
|
15
|
-
default_scope { order("page ASC")}
|
16
|
-
|
17
|
-
scope :of_page, lambda{|page| where(:page => page)}
|
18
|
-
|
19
|
-
def simple_name
|
20
|
-
"Section"
|
21
|
-
end
|
22
|
-
end
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/orm/activerecord'
|
3
|
+
module Adminpanel
|
4
|
+
class Section < ActiveRecord::Base
|
5
|
+
attr_accessible :description, :has_image, :key, :page, :name, :has_description, :images_attributes
|
6
|
+
has_many :images, :foreign_key => "foreign_key", :conditions => { :model => "Section" }
|
7
|
+
accepts_nested_attributes_for :images, :allow_destroy => true
|
8
|
+
validates_length_of :description, :minimum => 10, :maximum => 10, :on => :update, :if => lambda{|section| section.key == "telephone"}
|
9
|
+
validates_presence_of :description, :minimum => 9, :on => :update, :if => lambda{|section| section.has_description == true}
|
10
|
+
validates :description, :numericality => { :only_integer => true }, :on => :update, :if => lambda{|section| section.key == "telephone"}
|
11
|
+
validates_presence_of :key
|
12
|
+
validates_presence_of :name
|
13
|
+
validates_presence_of :page
|
14
|
+
|
15
|
+
default_scope { order("page ASC")}
|
16
|
+
|
17
|
+
scope :of_page, lambda{|page| where(:page => page)}
|
18
|
+
|
19
|
+
def simple_name
|
20
|
+
"Section"
|
21
|
+
end
|
22
|
+
end
|
23
23
|
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
module Adminpanel
|
2
|
-
class User < ActiveRecord::Base
|
3
|
-
attr_accessible :email, :name, :password, :password_confirmation
|
4
|
-
has_secure_password
|
5
|
-
|
6
|
-
#name validations
|
7
|
-
validates_presence_of :name
|
8
|
-
validates_length_of :name, :maximum => 25
|
9
|
-
|
10
|
-
#password validations
|
11
|
-
validates_confirmation_of :password
|
12
|
-
validates_presence_of :password
|
13
|
-
validates_length_of :password, :minimum => 6
|
14
|
-
|
15
|
-
#password_confirmation validations
|
16
|
-
validates_presence_of :password_confirmation
|
17
|
-
|
18
|
-
#email validations
|
19
|
-
validates_presence_of :email
|
20
|
-
validates_uniqueness_of :email
|
21
|
-
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
22
|
-
validates_format_of :email, :with => VALID_EMAIL_REGEX
|
23
|
-
|
24
|
-
before_save{ email.downcase! }
|
25
|
-
before_save :create_remember_token
|
26
|
-
|
27
|
-
def has_role?(role_sym)
|
28
|
-
roles.any? { |r| r.name.underscore.to_sym == role_sym }
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def create_remember_token
|
33
|
-
self.remember_token = SecureRandom.base64.tr("+/", "-_")
|
34
|
-
end
|
35
|
-
end
|
1
|
+
module Adminpanel
|
2
|
+
class User < ActiveRecord::Base
|
3
|
+
attr_accessible :email, :name, :password, :password_confirmation
|
4
|
+
has_secure_password
|
5
|
+
|
6
|
+
#name validations
|
7
|
+
validates_presence_of :name
|
8
|
+
validates_length_of :name, :maximum => 25
|
9
|
+
|
10
|
+
#password validations
|
11
|
+
validates_confirmation_of :password
|
12
|
+
validates_presence_of :password
|
13
|
+
validates_length_of :password, :minimum => 6
|
14
|
+
|
15
|
+
#password_confirmation validations
|
16
|
+
validates_presence_of :password_confirmation
|
17
|
+
|
18
|
+
#email validations
|
19
|
+
validates_presence_of :email
|
20
|
+
validates_uniqueness_of :email
|
21
|
+
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
22
|
+
validates_format_of :email, :with => VALID_EMAIL_REGEX
|
23
|
+
|
24
|
+
before_save{ email.downcase! }
|
25
|
+
before_save :create_remember_token
|
26
|
+
|
27
|
+
def has_role?(role_sym)
|
28
|
+
roles.any? { |r| r.name.underscore.to_sym == role_sym }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def create_remember_token
|
33
|
+
self.remember_token = SecureRandom.base64.tr("+/", "-_")
|
34
|
+
end
|
35
|
+
end
|
36
36
|
end
|
@@ -1,56 +1,56 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module Adminpanel
|
3
|
-
class GalleryUploader < CarrierWave::Uploader::Base
|
4
|
-
|
5
|
-
# Include RMagick or MiniMagick support:
|
6
|
-
include CarrierWave::RMagick
|
7
|
-
# include CarrierWave::MiniMagick
|
8
|
-
|
9
|
-
# Choose what kind of storage to use for this uploader:
|
10
|
-
storage :file
|
11
|
-
# storage :fog
|
12
|
-
|
13
|
-
def root
|
14
|
-
Rails.root.join 'public/'
|
15
|
-
end
|
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/gallery/#{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
|
-
# # ActionController::Base.helpers.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 :resize_to_fill => [1024, 450]
|
33
|
-
#
|
34
|
-
# def scale(width, height)
|
35
|
-
# # do something
|
36
|
-
# end
|
37
|
-
|
38
|
-
# Create different versions of your uploaded files:
|
39
|
-
version :thumb do
|
40
|
-
process :resize_to_limit => [200, 200]
|
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 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
|
1
|
+
# encoding: utf-8
|
2
|
+
module Adminpanel
|
3
|
+
class GalleryUploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
include CarrierWave::RMagick
|
7
|
+
# include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Choose what kind of storage to use for this uploader:
|
10
|
+
storage :file
|
11
|
+
# storage :fog
|
12
|
+
|
13
|
+
def root
|
14
|
+
Rails.root.join 'public/'
|
15
|
+
end
|
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/gallery/#{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
|
+
# # ActionController::Base.helpers.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 :resize_to_fill => [1024, 450]
|
33
|
+
#
|
34
|
+
# def scale(width, height)
|
35
|
+
# # do something
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Create different versions of your uploaded files:
|
39
|
+
version :thumb do
|
40
|
+
process :resize_to_limit => [200, 200]
|
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 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
|
56
56
|
end
|