brainsome_typus 4.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +488 -0
- data/Gemfile +60 -0
- data/Gemfile.lock +205 -0
- data/MIT-LICENSE +20 -0
- data/README.md +94 -0
- data/Rakefile +33 -0
- data/TODO.md +32 -0
- data/app/assets/javascripts/typus/application.js +11 -0
- data/app/assets/javascripts/typus/custom.js +2 -0
- data/app/assets/javascripts/typus/jquery-1.8.3-min.js +2 -0
- data/app/assets/javascripts/typus/jquery.application.js +33 -0
- data/app/assets/stylesheets/typus/application.css +5 -0
- data/app/assets/stylesheets/typus/custom.css +4 -0
- data/app/assets/stylesheets/typus/overrides.css.scss +46 -0
- data/app/controllers/admin/account_controller.rb +47 -0
- data/app/controllers/admin/base_controller.rb +44 -0
- data/app/controllers/admin/dashboard_controller.rb +5 -0
- data/app/controllers/admin/resource_controller.rb +7 -0
- data/app/controllers/admin/resources_controller.rb +256 -0
- data/app/controllers/admin/session_controller.rb +42 -0
- data/app/controllers/concerns/admin/actions.rb +88 -0
- data/app/controllers/concerns/admin/acts_as_list.rb +26 -0
- data/app/controllers/concerns/admin/ancestry.rb +26 -0
- data/app/controllers/concerns/admin/autocomplete.rb +11 -0
- data/app/controllers/concerns/admin/bulk.rb +76 -0
- data/app/controllers/concerns/admin/featured_image.rb +22 -0
- data/app/controllers/concerns/admin/filters.rb +57 -0
- data/app/controllers/concerns/admin/format.rb +48 -0
- data/app/controllers/concerns/admin/headless.rb +23 -0
- data/app/controllers/concerns/admin/hooks.rb +4 -0
- data/app/controllers/concerns/admin/multisite.rb +10 -0
- data/app/controllers/concerns/admin/navigation.rb +26 -0
- data/app/controllers/concerns/admin/trash.rb +65 -0
- data/app/helpers/admin/base_helper.rb +59 -0
- data/app/helpers/admin/resources/data_types/belongs_to_helper.rb +91 -0
- data/app/helpers/admin/resources/data_types/boolean_helper.rb +28 -0
- data/app/helpers/admin/resources/data_types/date_helper.rb +16 -0
- data/app/helpers/admin/resources/data_types/datetime_helper.rb +19 -0
- data/app/helpers/admin/resources/data_types/dragonfly_helper.rb +56 -0
- data/app/helpers/admin/resources/data_types/float_helper.rb +2 -0
- data/app/helpers/admin/resources/data_types/has_and_belongs_to_many_helper.rb +53 -0
- data/app/helpers/admin/resources/data_types/has_many_helper.rb +66 -0
- data/app/helpers/admin/resources/data_types/has_one_helper.rb +36 -0
- data/app/helpers/admin/resources/data_types/integer_helper.rb +10 -0
- data/app/helpers/admin/resources/data_types/paperclip_helper.rb +36 -0
- data/app/helpers/admin/resources/data_types/position_helper.rb +20 -0
- data/app/helpers/admin/resources/data_types/selector_helper.rb +11 -0
- data/app/helpers/admin/resources/data_types/string_helper.rb +32 -0
- data/app/helpers/admin/resources/data_types/text_helper.rb +7 -0
- data/app/helpers/admin/resources/data_types/transversal_helper.rb +8 -0
- data/app/helpers/admin/resources/data_types/tree_helper.rb +26 -0
- data/app/helpers/admin/resources/display_helper.rb +27 -0
- data/app/helpers/admin/resources/filters_helper.rb +28 -0
- data/app/helpers/admin/resources/form_helper.rb +84 -0
- data/app/helpers/admin/resources/list_helper.rb +31 -0
- data/app/helpers/admin/resources/pagination_helper.rb +28 -0
- data/app/helpers/admin/resources/relationships_helper.rb +34 -0
- data/app/helpers/admin/resources/sidebar_helper.rb +40 -0
- data/app/helpers/admin/resources/table_helper.rb +66 -0
- data/app/helpers/admin/resources_helper.rb +25 -0
- data/app/mailers/admin/mailer.rb +20 -0
- data/app/views/admin/account/_form.html.erb +11 -0
- data/app/views/admin/account/forgot_password.html.erb +19 -0
- data/app/views/admin/account/new.html.erb +13 -0
- data/app/views/admin/dashboard/_sidebar.html.erb +14 -0
- data/app/views/admin/dashboard/index.html.erb +6 -0
- data/app/views/admin/dashboard/styles.html.erb +153 -0
- data/app/views/admin/dashboard/widgets/_applications.html.erb +44 -0
- data/app/views/admin/dashboard/widgets/_default.html.erb +46 -0
- data/app/views/admin/dashboard/widgets/_models.html.erb +23 -0
- data/app/views/admin/dashboard/widgets/_models_extended.html.erb +25 -0
- data/app/views/admin/dashboard/widgets/_resources.html.erb +23 -0
- data/app/views/admin/dashboard/widgets/_users.html.erb +23 -0
- data/app/views/admin/mailer/reset_password_instructions.html.erb +7 -0
- data/app/views/admin/mailer/reset_password_instructions.text.erb +7 -0
- data/app/views/admin/resources/_actions.html.erb +23 -0
- data/app/views/admin/resources/_edit.html.erb +0 -0
- data/app/views/admin/resources/_form.html.erb +41 -0
- data/app/views/admin/resources/_form_javascripts.html.erb +0 -0
- data/app/views/admin/resources/_form_modal.html.erb +13 -0
- data/app/views/admin/resources/_index.html.erb +0 -0
- data/app/views/admin/resources/_new.html.erb +0 -0
- data/app/views/admin/resources/_pagination.html.erb +15 -0
- data/app/views/admin/resources/_show.html.erb +0 -0
- data/app/views/admin/resources/edit/_actions.html.erb +7 -0
- data/app/views/admin/resources/edit/_recently_edited.html.erb +8 -0
- data/app/views/admin/resources/edit.html.erb +22 -0
- data/app/views/admin/resources/index.html.erb +81 -0
- data/app/views/admin/resources/new.html.erb +21 -0
- data/app/views/admin/resources/show.html.erb +27 -0
- data/app/views/admin/session/new.html.erb +21 -0
- data/app/views/admin/shared/_head.html.erb +15 -0
- data/app/views/admin/shared/_modals.html.erb +3 -0
- data/app/views/admin/shared/_sidebar_placeholder.html.erb +0 -0
- data/app/views/admin/templates/README.md +5 -0
- data/app/views/admin/templates/_belongs_to.html.erb +13 -0
- data/app/views/admin/templates/_boolean.html.erb +6 -0
- data/app/views/admin/templates/_date.html.erb +6 -0
- data/app/views/admin/templates/_datetime.html.erb +7 -0
- data/app/views/admin/templates/_dragonfly.html.erb +8 -0
- data/app/views/admin/templates/_dragonfly_form_preview.html.erb +23 -0
- data/app/views/admin/templates/_dragonfly_preview.html.erb +12 -0
- data/app/views/admin/templates/_has_and_belongs_to_many.html.erb +21 -0
- data/app/views/admin/templates/_has_many.html.erb +20 -0
- data/app/views/admin/templates/_has_one.html.erb +14 -0
- data/app/views/admin/templates/_paperclip.html.erb +7 -0
- data/app/views/admin/templates/_paperclip_preview.html.erb +3 -0
- data/app/views/admin/templates/_password.html.erb +6 -0
- data/app/views/admin/templates/_position.html.erb +6 -0
- data/app/views/admin/templates/_profile_sidebar.html.erb +4 -0
- data/app/views/admin/templates/_selector.html.erb +6 -0
- data/app/views/admin/templates/_string.html.erb +6 -0
- data/app/views/admin/templates/_string_with_preview.html.erb +11 -0
- data/app/views/admin/templates/_text.html.erb +11 -0
- data/app/views/admin/templates/_text_with_ckeditor.html.erb +24 -0
- data/app/views/admin/templates/_text_with_ckeditor_and_assets.html.erb +38 -0
- data/app/views/admin/templates/_time.html.erb +9 -0
- data/app/views/admin/templates/_tree.html.erb +6 -0
- data/app/views/admin/templates/modals/_belongs_to.html.erb +56 -0
- data/app/views/admin/templates/modals/_dragonfly.html.erb +9 -0
- data/app/views/admin/templates/modals/_has_and_belongs_to_many.html.erb +19 -0
- data/app/views/admin/templates/modals/_has_many.html.erb +53 -0
- data/app/views/helpers/admin/base/_apps.html.erb +38 -0
- data/app/views/helpers/admin/base/_breadcrumbs.html.erb +6 -0
- data/app/views/helpers/admin/base/_flash_message.html.erb +3 -0
- data/app/views/helpers/admin/base/_login_info.html.erb +37 -0
- data/app/views/helpers/admin/dashboard/_resources.html.erb +19 -0
- data/app/views/helpers/admin/resources/_actions.html.erb +18 -0
- data/app/views/helpers/admin/resources/_errors.html.erb +12 -0
- data/app/views/helpers/admin/resources/_filters.html.erb +14 -0
- data/app/views/helpers/admin/resources/_search.html.erb +14 -0
- data/app/views/helpers/admin/resources/_sidebar.html.erb +17 -0
- data/app/views/helpers/admin/resources/_table.html.erb +47 -0
- data/app/views/layouts/admin/base.html.erb +40 -0
- data/app/views/layouts/admin/headless.html.erb +1 -0
- data/app/views/layouts/admin/session.html.erb +44 -0
- data/config/locales/typus.ca.models.yml +17 -0
- data/config/locales/typus.ca.yml +78 -0
- data/config/locales/typus.de.models.yml +17 -0
- data/config/locales/typus.de.yml +98 -0
- data/config/locales/typus.el.models.yml +17 -0
- data/config/locales/typus.el.yml +79 -0
- data/config/locales/typus.es.models.yml +18 -0
- data/config/locales/typus.es.yml +91 -0
- data/config/locales/typus.fr.models.yml +18 -0
- data/config/locales/typus.fr.yml +83 -0
- data/config/locales/typus.hu.models.yml +17 -0
- data/config/locales/typus.hu.yml +77 -0
- data/config/locales/typus.it.models.yml +18 -0
- data/config/locales/typus.it.yml +86 -0
- data/config/locales/typus.locale.models.yml.template +17 -0
- data/config/locales/typus.locale.yml.template +78 -0
- data/config/locales/typus.pt-BR.models.yml +17 -0
- data/config/locales/typus.pt-BR.yml +77 -0
- data/config/locales/typus.pt-PT.models.yml +17 -0
- data/config/locales/typus.pt-PT.yml +85 -0
- data/config/locales/typus.ru.models.yml +17 -0
- data/config/locales/typus.ru.yml +77 -0
- data/config/locales/typus.zh-CN.models.yml +17 -0
- data/config/locales/typus.zh-CN.yml +76 -0
- data/config/routes.rb +46 -0
- data/lib/generators/templates/config/initializers/typus.rb +35 -0
- data/lib/generators/templates/config/initializers/typus_authentication.rb +18 -0
- data/lib/generators/templates/config/initializers/typus_resources.rb +24 -0
- data/lib/generators/templates/config/typus/README +58 -0
- data/lib/generators/templates/config/typus/application.yml +3 -0
- data/lib/generators/templates/config/typus/application_roles.yml +4 -0
- data/lib/generators/templates/config/typus/typus.yml +15 -0
- data/lib/generators/templates/config/typus/typus_roles.yml +4 -0
- data/lib/generators/templates/controller.erb +2 -0
- data/lib/generators/templates/migration.erb +22 -0
- data/lib/generators/templates/view.html.erb +13 -0
- data/lib/generators/typus/config_generator.rb +67 -0
- data/lib/generators/typus/controller_generator.rb +25 -0
- data/lib/generators/typus/initializers_generator.rb +20 -0
- data/lib/generators/typus/migration_generator.rb +94 -0
- data/lib/generators/typus/typus_generator.rb +52 -0
- data/lib/generators/typus/views_generator.rb +19 -0
- data/lib/support/active_record.rb +42 -0
- data/lib/support/fake_user.rb +47 -0
- data/lib/support/hash.rb +12 -0
- data/lib/support/object.rb +9 -0
- data/lib/support/string.rb +40 -0
- data/lib/tasks/typus.rake +11 -0
- data/lib/typus/authentication/base.rb +24 -0
- data/lib/typus/authentication/devise.rb +19 -0
- data/lib/typus/authentication/http_basic.rb +18 -0
- data/lib/typus/authentication/none.rb +15 -0
- data/lib/typus/authentication/none_with_role.rb +15 -0
- data/lib/typus/authentication/session.rb +123 -0
- data/lib/typus/configuration.rb +41 -0
- data/lib/typus/engine.rb +17 -0
- data/lib/typus/i18n.rb +48 -0
- data/lib/typus/orm/active_record/admin_user.rb +84 -0
- data/lib/typus/orm/active_record/class_methods.rb +104 -0
- data/lib/typus/orm/active_record/instance_methods.rb +76 -0
- data/lib/typus/orm/active_record/search.rb +44 -0
- data/lib/typus/orm/active_record.rb +10 -0
- data/lib/typus/orm/base/class_methods.rb +184 -0
- data/lib/typus/orm/base/search.rb +70 -0
- data/lib/typus/regex.rb +11 -0
- data/lib/typus/resources.rb +55 -0
- data/lib/typus/version.rb +10 -0
- data/lib/typus.rb +212 -0
- data/typus.gemspec +32 -0
- data/vendor/assets/adapt/css/1200.css +357 -0
- data/vendor/assets/adapt/css/1200.min.css +1 -0
- data/vendor/assets/adapt/css/1560.css +357 -0
- data/vendor/assets/adapt/css/1560.min.css +1 -0
- data/vendor/assets/adapt/css/720.css +357 -0
- data/vendor/assets/adapt/css/720.min.css +1 -0
- data/vendor/assets/adapt/css/960.css +357 -0
- data/vendor/assets/adapt/css/960.min.css +1 -0
- data/vendor/assets/adapt/css/fluid.css +345 -0
- data/vendor/assets/adapt/css/fluid.min.css +1 -0
- data/vendor/assets/adapt/css/master.css +120 -0
- data/vendor/assets/adapt/css/mobile.css +20 -0
- data/vendor/assets/adapt/css/mobile.min.css +1 -0
- data/vendor/assets/adapt/css/reset.css +202 -0
- data/vendor/assets/adapt/css/text.css +81 -0
- data/vendor/assets/adapt/images/h1.png +0 -0
- data/vendor/assets/adapt/js/adapt.js +135 -0
- data/vendor/assets/adapt/js/adapt.min.js +1 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap-responsive.css +1109 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap-responsive.min.css +9 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap.css +6167 -0
- data/vendor/assets/bootstrap-2.3.2/css/bootstrap.min.css +9 -0
- data/vendor/assets/bootstrap-2.3.2/img/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/bootstrap-2.3.2/img/glyphicons-halflings.png +0 -0
- data/vendor/assets/bootstrap-2.3.2/js/bootstrap.js +2280 -0
- data/vendor/assets/bootstrap-2.3.2/js/bootstrap.min.js +6 -0
- data/vendor/assets/chosen/LICENSE.md +24 -0
- data/vendor/assets/chosen/chosen-sprite.png +0 -0
- data/vendor/assets/chosen/chosen.css +390 -0
- data/vendor/assets/chosen/chosen.jquery.js +902 -0
- data/vendor/assets/formalize/css/formalize.css +395 -0
- data/vendor/assets/formalize/images/button.png +0 -0
- data/vendor/assets/formalize/images/select_arrow.gif +0 -0
- data/vendor/assets/formalize/js/jquery.formalize.min.js +1 -0
- metadata +329 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Admin
|
4
|
+
module Navigation
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_filter :set_resources_action_on_lists, :only => [:index, :trash]
|
10
|
+
before_filter :set_resources_action, :only => [:new, :create, :edit, :show]
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_resources_action_on_lists
|
14
|
+
add_resources_action("Add", {:action => "new"})
|
15
|
+
end
|
16
|
+
private :set_resources_action_on_lists
|
17
|
+
|
18
|
+
def set_resources_action
|
19
|
+
unless params[:_popup] && !params[:_input]
|
20
|
+
add_resources_action('Back to list', {:action => 'index', :id => nil})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
private :set_resources_action
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Module designed to work with `rails-trash`.
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module Admin
|
6
|
+
module Trash
|
7
|
+
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
before_filter :set_predefined_filter_for_trash, :only => [:index, :trash]
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_predefined_filter_for_trash
|
15
|
+
if admin_user.can?('edit', @resource.model_name)
|
16
|
+
add_predefined_filter("Trash", "trash", "deleted")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
private :set_predefined_filter_for_trash
|
20
|
+
|
21
|
+
def trash
|
22
|
+
set_deleted
|
23
|
+
|
24
|
+
get_objects
|
25
|
+
|
26
|
+
respond_to do |format|
|
27
|
+
format.html do
|
28
|
+
# Actions by resource.
|
29
|
+
add_resource_action 'Restore', { :action => 'restore' }, { :data => { :confirm => Typus::I18n.t("Restore %{resource}?", :resource => @resource.model_name.human) } }
|
30
|
+
add_resource_action 'Delete Permanently', { :action => 'wipe' }, { :data => { :confirm => Typus::I18n.t("Delete Permanently?") } }
|
31
|
+
# Generate and render.
|
32
|
+
get_paginated_data
|
33
|
+
render 'index'
|
34
|
+
end
|
35
|
+
|
36
|
+
format.csv { generate_csv }
|
37
|
+
format.json { export(:json) }
|
38
|
+
format.xml { export(:xml) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def restore
|
43
|
+
begin
|
44
|
+
@resource.restore(params[:id])
|
45
|
+
message = "%{resource} recovered from trash."
|
46
|
+
rescue ActiveRecord::RecordNotFound
|
47
|
+
message = "%{resource} can't be recovered from trash."
|
48
|
+
end
|
49
|
+
|
50
|
+
redirect_to :back, :notice => Typus::I18n.t(message, :resource => @resource.model_name.human)
|
51
|
+
end
|
52
|
+
|
53
|
+
def wipe
|
54
|
+
item = @resource.find_in_trash(params[:id])
|
55
|
+
item.disable_trash { item.destroy }
|
56
|
+
redirect_to :back, :notice => Typus::I18n.t("%{resource} has been successfully removed from trash.", :resource => @resource.model_name.human)
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_deleted
|
60
|
+
@resource = @resource.deleted
|
61
|
+
end
|
62
|
+
private :set_deleted
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Admin::BaseHelper
|
2
|
+
|
3
|
+
def admin_title(page_title = nil)
|
4
|
+
if page_title
|
5
|
+
content_for(:title) { page_title }
|
6
|
+
else
|
7
|
+
setting = defined?(Admin::Setting) && Admin::Setting.admin_title
|
8
|
+
setting || Typus.admin_title
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def admin_sign_out_path
|
13
|
+
case Typus.authentication
|
14
|
+
when :devise
|
15
|
+
send("destroy_#{Typus.user_class_name.underscore}_session_path")
|
16
|
+
else
|
17
|
+
destroy_admin_session_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def admin_edit_user_path(user)
|
22
|
+
{ :controller => "/admin/#{Typus.user_class.to_resource}",
|
23
|
+
:action => "edit",
|
24
|
+
:id => user.id }
|
25
|
+
end
|
26
|
+
|
27
|
+
def admin_display_flash_message
|
28
|
+
if flash.any?
|
29
|
+
String.new.tap do |html|
|
30
|
+
flash.each do |type, message|
|
31
|
+
if type == :notice
|
32
|
+
type = 'info'
|
33
|
+
end
|
34
|
+
html << content_tag(:div, message, :id => 'flash', :class => "alert alert-#{type}")
|
35
|
+
end
|
36
|
+
end.html_safe
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_modal_options_for(klass)
|
41
|
+
{ "data-toggle" => "modal",
|
42
|
+
"data-controls-modal" => "modal-from-dom-#{klass.model_name.param_key}",
|
43
|
+
"data-backdrop" => "true",
|
44
|
+
"data-keyboard" => "true",
|
45
|
+
"class" => "ajax-modal",
|
46
|
+
"url" => "override-this" }
|
47
|
+
end
|
48
|
+
|
49
|
+
def body_class
|
50
|
+
if params[:controller] == 'admin/dashboard'
|
51
|
+
"base dashboard #{params[:action].parameterize}"
|
52
|
+
else
|
53
|
+
classes = ['base', params[:action].parameterize]
|
54
|
+
classes << ['resource', @resource.model_name.param_key] if @resource
|
55
|
+
classes.flatten.join(" ")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Admin::Resources::DataTypes::BelongsToHelper
|
2
|
+
|
3
|
+
def typus_belongs_to_field(attribute, form)
|
4
|
+
association = @resource.reflect_on_association(attribute.to_sym)
|
5
|
+
|
6
|
+
related = if defined?(set_belongs_to_context)
|
7
|
+
set_belongs_to_context.send(attribute.pluralize.to_sym)
|
8
|
+
else
|
9
|
+
association.class_name.constantize
|
10
|
+
end
|
11
|
+
|
12
|
+
related_fk = association.foreign_key
|
13
|
+
html_options = {}
|
14
|
+
label_text = @resource.human_attribute_name(attribute)
|
15
|
+
options = { :attribute => "#{@resource.name.underscore}_#{related_fk}" }
|
16
|
+
|
17
|
+
label_text = @resource.human_attribute_name(attribute)
|
18
|
+
if (text = build_label_text_for_belongs_to(related, html_options, options))
|
19
|
+
label_text += " <small>#{text}</small>"
|
20
|
+
end
|
21
|
+
|
22
|
+
values = if related.respond_to?(:roots)
|
23
|
+
expand_tree_into_select_field(related.roots, related_fk)
|
24
|
+
else
|
25
|
+
related.order(related.typus_order_by).map { |p| [p.to_label, p.id] }
|
26
|
+
end
|
27
|
+
|
28
|
+
attribute_id = "#{@resource.name.underscore}_#{attribute}_id".gsub("/", "_")
|
29
|
+
|
30
|
+
render "admin/templates/belongs_to",
|
31
|
+
:attribute => attribute,
|
32
|
+
:attribute_id => attribute_id,
|
33
|
+
:form => form,
|
34
|
+
:related_fk => related_fk,
|
35
|
+
:related => related,
|
36
|
+
:label_text => label_text.html_safe,
|
37
|
+
:values => values,
|
38
|
+
:html_options => html_options,
|
39
|
+
:options => { :include_blank => true }
|
40
|
+
end
|
41
|
+
|
42
|
+
def table_belongs_to_field(attribute, item)
|
43
|
+
if att_value = item.send(attribute)
|
44
|
+
action = item.send(attribute).class.typus_options_for(:default_action_on_item)
|
45
|
+
message = att_value.to_label
|
46
|
+
if !params[:_popup] && admin_user.can?(action, att_value.class.name)
|
47
|
+
message = link_to(message, :controller => "/admin/#{att_value.class.to_resource}", :action => action, :id => att_value.id)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
message || mdash
|
52
|
+
end
|
53
|
+
|
54
|
+
def display_belongs_to(item, attribute)
|
55
|
+
data = item.send(attribute)
|
56
|
+
|
57
|
+
options = {
|
58
|
+
:controller => data.class.to_resource,
|
59
|
+
:action => params[:action],
|
60
|
+
:id => data.id
|
61
|
+
}
|
62
|
+
|
63
|
+
params[:_popup] ? data.to_label : link_to(data.to_label, options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def belongs_to_filter(filter)
|
67
|
+
att_assoc = @resource.reflect_on_association(filter.to_sym)
|
68
|
+
class_name = att_assoc.options[:class_name] || filter.capitalize.camelize
|
69
|
+
resource = class_name.constantize
|
70
|
+
|
71
|
+
items = [[Typus::I18n.t("View all %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase.pluralize), ""]]
|
72
|
+
items += resource.order(resource.typus_order_by).map { |v| [v.to_label, v.id] }
|
73
|
+
end
|
74
|
+
|
75
|
+
def build_label_text_for_belongs_to(klass, html_options, options)
|
76
|
+
if html_options[:disabled] == true
|
77
|
+
Typus::I18n.t("Read only")
|
78
|
+
elsif admin_user.can?('create', klass) && !headless_mode?
|
79
|
+
build_add_new_for_belongs_to(klass, options)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_add_new_for_belongs_to(klass, options)
|
84
|
+
html_options = set_modal_options_for(klass)
|
85
|
+
html_options["data-controls-modal"] = "modal-from-dom-#{options[:attribute]}"
|
86
|
+
html_options["url"] = "/admin/#{klass.to_resource}/new?_popup=true"
|
87
|
+
|
88
|
+
link_to Typus::I18n.t("Add"), { :anchor => html_options['data-controls-modal'] }, html_options
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Admin::Resources::DataTypes::BooleanHelper
|
2
|
+
|
3
|
+
def display_boolean(item, attribute)
|
4
|
+
data = item.send(attribute)
|
5
|
+
boolean_assoc = item.class.typus_boolean(attribute)
|
6
|
+
(data ? boolean_assoc.rassoc("true") : boolean_assoc.rassoc("false")).first
|
7
|
+
end
|
8
|
+
|
9
|
+
def table_boolean_field(attribute, item)
|
10
|
+
status = item.send(attribute)
|
11
|
+
boolean_assoc = item.class.typus_boolean(attribute)
|
12
|
+
human_boolean = (status ? boolean_assoc.rassoc("true") : boolean_assoc.rassoc("false")).first
|
13
|
+
|
14
|
+
options = { :controller => "/admin/#{item.class.to_resource}",
|
15
|
+
:action => "toggle",
|
16
|
+
:id => item.id,
|
17
|
+
:field => attribute.gsub(/\?$/, '') }
|
18
|
+
confirm = Typus::I18n.t("Change %{attribute}?", :attribute => item.class.human_attribute_name(attribute).downcase)
|
19
|
+
link_to Typus::I18n.t(human_boolean), options, :data => { :confirm => confirm }
|
20
|
+
end
|
21
|
+
|
22
|
+
def boolean_filter(filter)
|
23
|
+
values = @resource.typus_boolean(filter)
|
24
|
+
items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
|
25
|
+
items += values.map { |k, v| [Typus::I18n.t(k.humanize), v] }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Admin::Resources::DataTypes::DateHelper
|
2
|
+
|
3
|
+
def date_filter(filter)
|
4
|
+
values = { :all_day => "Today",
|
5
|
+
:all_week => "This week",
|
6
|
+
:all_month => "This month",
|
7
|
+
:all_year => "This year" }
|
8
|
+
|
9
|
+
items = [[@resource.human_attribute_name(filter).capitalize, ""]]
|
10
|
+
items += values.map { |k, v| [Typus::I18n.t(v), k] }
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method :datetime_filter, :date_filter
|
14
|
+
alias_method :timestamp_filter, :date_filter
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Admin::Resources::DataTypes::DatetimeHelper
|
2
|
+
|
3
|
+
def table_datetime_field(attribute, item)
|
4
|
+
if field = item.send(attribute)
|
5
|
+
I18n.localize(field, :format => item.class.typus_date_format(attribute))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
alias_method :table_date_field, :table_datetime_field
|
10
|
+
alias_method :table_time_field, :table_datetime_field
|
11
|
+
alias_method :table_timestamp_field, :table_datetime_field
|
12
|
+
|
13
|
+
def display_datetime(item, attribute)
|
14
|
+
I18n.l(item.send(attribute), :format => @resource.typus_date_format(attribute))
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :display_date, :display_datetime
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Admin::Resources::DataTypes::DragonflyHelper
|
2
|
+
|
3
|
+
def table_dragonfly_field(attribute, item)
|
4
|
+
typus_dragonfly_preview(item, attribute)
|
5
|
+
end
|
6
|
+
|
7
|
+
def link_to_detach_attribute_for_dragonfly(attribute)
|
8
|
+
validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map(&:attributes).flatten.map(&:to_s)
|
9
|
+
attachment = @item.send(attribute)
|
10
|
+
|
11
|
+
if attachment.present? && !validators.include?(attribute) && attachment
|
12
|
+
attribute_i18n = @item.class.human_attribute_name(attribute)
|
13
|
+
label_text = <<-HTML
|
14
|
+
#{attribute_i18n}
|
15
|
+
<small>#{link_to Typus::I18n.t("Remove"), { :action => 'update', :id => @item.id, :_nullify => attribute, :_continue => true }, { :data => { :confirm => Typus::I18n.t("Are you sure?") } } }</small>
|
16
|
+
HTML
|
17
|
+
label_text.html_safe
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def typus_dragonfly_preview(item, attachment)
|
22
|
+
data = item.send(attachment)
|
23
|
+
return unless data
|
24
|
+
|
25
|
+
if data.mime_type =~ /^image\/.+/
|
26
|
+
render "admin/templates/dragonfly_preview",
|
27
|
+
:attachment => data,
|
28
|
+
:preview => data.process(:thumb, Typus.image_preview_size).url,
|
29
|
+
:thumb => data.process(:thumb, Typus.image_table_thumb_size).url,
|
30
|
+
:item => item,
|
31
|
+
:attribute => attachment
|
32
|
+
else
|
33
|
+
params[:_popup] ? data.name : link_to(data.name, data.url)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def typus_dragonfly_form_preview(item, attachment, options = {})
|
38
|
+
data = item.send(attachment)
|
39
|
+
return unless data
|
40
|
+
|
41
|
+
if data.mime_type =~ /^image\/.+/
|
42
|
+
render "admin/templates/dragonfly_form_preview",
|
43
|
+
:attachment => data,
|
44
|
+
:preview => data.process(:thumb, Typus.image_preview_size).url,
|
45
|
+
:thumb => data.process(:thumb, Typus.image_thumb_size).url,
|
46
|
+
:options => options,
|
47
|
+
:item => item,
|
48
|
+
:attribute => attachment
|
49
|
+
else
|
50
|
+
html = params[:_popup] ? data.name : link_to(data.name, data.url)
|
51
|
+
# OPTIMIZE: Generate the tag with Ruby.
|
52
|
+
"<p>#{html}</p>".html_safe
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Admin::Resources::DataTypes::HasAndBelongsToManyHelper
|
2
|
+
|
3
|
+
def table_has_and_belongs_to_many_field(attribute, item)
|
4
|
+
item.send(attribute).map(&:to_label).join(", ")
|
5
|
+
end
|
6
|
+
|
7
|
+
alias_method :table_has_many_field, :table_has_and_belongs_to_many_field
|
8
|
+
|
9
|
+
def typus_has_and_belongs_to_many_field(attribute, form)
|
10
|
+
klass = @resource.reflect_on_association(attribute.to_sym).class_name.constantize
|
11
|
+
|
12
|
+
resource_ids = "#{attribute.singularize}_ids"
|
13
|
+
html_options = {}
|
14
|
+
model = @resource.name.underscore.gsub("/", "_")
|
15
|
+
options = { :attribute => "#{model}_#{attribute}" }
|
16
|
+
|
17
|
+
label_text = @resource.human_attribute_name(attribute)
|
18
|
+
if (text = build_label_text_for_has_and_belongs_to_many(klass, html_options, options))
|
19
|
+
label_text += " <small>#{text}</small>"
|
20
|
+
end
|
21
|
+
|
22
|
+
locals = { :attribute => attribute,
|
23
|
+
:attribute_id => "#{model}_#{attribute}",
|
24
|
+
:related_klass => klass,
|
25
|
+
:related_items => @item.send(attribute),
|
26
|
+
:related_ids => "#{model}[#{resource_ids}][]",
|
27
|
+
:values => klass,
|
28
|
+
:form => form,
|
29
|
+
:label_text => label_text.html_safe,
|
30
|
+
:html_options => html_options }
|
31
|
+
|
32
|
+
render "admin/templates/has_and_belongs_to_many", locals
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_label_text_for_has_and_belongs_to_many(klass, html_options, options = {})
|
36
|
+
if html_options[:disabled] == true
|
37
|
+
Typus::I18n.t("Read only")
|
38
|
+
elsif admin_user.can?('create', klass) && !headless_mode?
|
39
|
+
build_add_new_for_has_and_belongs_to_many(klass, options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_add_new_for_has_and_belongs_to_many(klass, options)
|
44
|
+
html_options = set_modal_options_for(klass)
|
45
|
+
html_options["url"] = url_for(:controller => "/admin/#{klass.to_resource}", :action => :new, :_popup => true)
|
46
|
+
html_options["data-controls-modal"] = "modal-from-dom-#{options[:attribute]}"
|
47
|
+
|
48
|
+
options = { :anchor => html_options["data-controls-modal"] }
|
49
|
+
|
50
|
+
link_to Typus::I18n.t("Add"), options, html_options
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Admin::Resources::DataTypes::HasManyHelper
|
2
|
+
|
3
|
+
def has_many_filter(filter)
|
4
|
+
att_assoc = @resource.reflect_on_association(filter.to_sym)
|
5
|
+
class_name = att_assoc.options[:class_name] || filter.classify
|
6
|
+
resource = class_name.constantize
|
7
|
+
|
8
|
+
items = [[Typus::I18n.t("View all %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase.pluralize), ""]]
|
9
|
+
items += resource.order(resource.typus_order_by).map { |v| [v.to_label, v.id] }
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :has_and_belongs_to_many_filter, :has_many_filter
|
13
|
+
|
14
|
+
def typus_form_has_many(field)
|
15
|
+
setup_relationship(field)
|
16
|
+
|
17
|
+
options = { "resource[#{@reflection.foreign_key}]" => @item.id }
|
18
|
+
|
19
|
+
if @reflection.options && (as = @reflection.options[:as])
|
20
|
+
klass = @resource.is_sti? ? @resource.superclass : @resource
|
21
|
+
options.merge!("#{as}_type" => klass)
|
22
|
+
end
|
23
|
+
|
24
|
+
build_pagination
|
25
|
+
set_has_many_resource_actions
|
26
|
+
|
27
|
+
locals = { :association_name => @association_name,
|
28
|
+
:add_new => build_add_new_for_has_many(@model_to_relate, field, options),
|
29
|
+
:table => build_relationship_table }
|
30
|
+
|
31
|
+
render "admin/templates/has_many", locals
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_add_new_for_has_many(klass, field, options = {})
|
35
|
+
if admin_user.can?("create", klass)
|
36
|
+
|
37
|
+
html_options = set_modal_options_for(klass)
|
38
|
+
html_options["url"] = "/admin/#{klass.to_resource}/new?_popup=true"
|
39
|
+
html_options["url"] << "&" + options.to_param
|
40
|
+
|
41
|
+
link_to Typus::I18n.t("Add"), "##{html_options['data-controls-modal']}", html_options
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_has_many_resource_actions
|
46
|
+
klass = @model_to_relate
|
47
|
+
@resource_actions = [set_has_many_resource_edit_action(klass),
|
48
|
+
set_has_many_resource_show_action(klass),
|
49
|
+
set_has_many_resource_destroy_action(klass)]
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_has_many_resource_edit_action(klass)
|
53
|
+
html_options = set_modal_options_for(klass)
|
54
|
+
[ "Edit", { :action => 'edit', :anchor => html_options['data-controls-modal'] }, html_options ]
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_has_many_resource_show_action(klass)
|
58
|
+
html_options = set_modal_options_for(klass)
|
59
|
+
[ "Show", { :action => 'show', :anchor => html_options['data-controls-modal'] }, html_options ]
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_has_many_resource_destroy_action(klass)
|
63
|
+
[ "Trash", { :action => 'destroy' }, { :confirm => "Trash?" } ]
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Admin::Resources::DataTypes::HasOneHelper
|
2
|
+
|
3
|
+
def typus_form_has_one(field)
|
4
|
+
setup_relationship(field)
|
5
|
+
|
6
|
+
related_items = @item.send(field)
|
7
|
+
@items = related_items ? [related_items] : []
|
8
|
+
|
9
|
+
set_has_one_resource_actions
|
10
|
+
|
11
|
+
locals = { :association_name => @association_name, :table => build_relationship_table, :add_new => nil }
|
12
|
+
|
13
|
+
if @items.empty?
|
14
|
+
options = { "resource[#{@reflection.foreign_key}]" => @item.id }
|
15
|
+
locals[:add_new] = build_add_new_for_has_one(@model_to_relate, field, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
render "admin/templates/has_one", locals
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_add_new_for_has_one(klass, field, options = {})
|
22
|
+
if admin_user.can?("create", klass)
|
23
|
+
default_options = { :controller => "/admin/#{klass.to_resource}",
|
24
|
+
:action => "new",
|
25
|
+
:_popup => true }
|
26
|
+
|
27
|
+
link_to Typus::I18n.t("Add"), default_options.merge(options), { :class => "iframe_with_page_reload" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_has_one_resource_actions
|
32
|
+
@resource_actions = [["Edit", { :action => "edit" }, {}],
|
33
|
+
["Trash", { :action => "destroy" }, { :data => { :confirm => Typus::I18n.t("Trash?") } }]]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Admin::Resources::DataTypes::IntegerHelper
|
2
|
+
|
3
|
+
def integer_filter(filter)
|
4
|
+
values = set_context.send(filter.to_s.pluralize).to_a
|
5
|
+
items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
|
6
|
+
array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
|
7
|
+
items += array
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Admin::Resources::DataTypes::PaperclipHelper
|
2
|
+
|
3
|
+
def table_paperclip_field(attribute, item)
|
4
|
+
options = { :width => 25 }
|
5
|
+
typus_paperclip_preview(item, attribute, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def link_to_detach_attribute_for_paperclip(attribute)
|
9
|
+
validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map(&:attributes).flatten.map(&:to_s)
|
10
|
+
attachment = @item.send(attribute)
|
11
|
+
|
12
|
+
if attachment.exists? && !validators.include?("#{attribute}_file_name") && attachment
|
13
|
+
attribute_i18n = @item.class.human_attribute_name(attribute)
|
14
|
+
label_text = <<-HTML
|
15
|
+
#{attribute_i18n}
|
16
|
+
<small>#{link_to Typus::I18n.t("Remove"), { :action => 'update', :id => @item.id, :_nullify => attribute, :_continue => true }, { :data => { :confirm => Typus::I18n.t("Are you sure?") } } }</small>
|
17
|
+
HTML
|
18
|
+
label_text.html_safe
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def typus_paperclip_preview(item, attachment, options = {})
|
23
|
+
if (data = item.send(attachment)).exists?
|
24
|
+
styles = data.styles.keys
|
25
|
+
if data.content_type =~ /^image\/.+/ && styles.include?(Typus.file_preview) && styles.include?(Typus.file_thumbnail)
|
26
|
+
render "admin/templates/paperclip_preview",
|
27
|
+
:preview => data.url(Typus.file_preview, false),
|
28
|
+
:thumb => data.url(Typus.file_thumbnail, false),
|
29
|
+
:options => options
|
30
|
+
else
|
31
|
+
link_to data.original_filename, data.url(:original, false)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Admin::Resources::DataTypes::PositionHelper
|
2
|
+
|
3
|
+
def table_position_field(attribute, item, connector = " / ")
|
4
|
+
locals = { :html_position => [], :connector => connector, :item => item }
|
5
|
+
positions = { :move_to_top => "Top", :move_higher => "Up", :move_lower => "Down", :move_to_bottom => "Bottom" }
|
6
|
+
|
7
|
+
positions.each do |key, value|
|
8
|
+
first_item = item.respond_to?(:first?) && ([:move_higher, :move_to_top].include?(key) && item.first?)
|
9
|
+
last_item = item.respond_to?(:last?) && ([:move_lower, :move_to_bottom].include?(key) && item.last?)
|
10
|
+
|
11
|
+
unless first_item || last_item
|
12
|
+
options = { :controller => "/admin/#{item.class.to_resource}", :action => "position", :id => item.id, :go => key }
|
13
|
+
locals[:html_position] << link_to(Typus::I18n.t(value), params.merge(options), { :class => Typus::I18n.t(value).downcase })
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
render "admin/templates/position", locals
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Admin::Resources::DataTypes::StringHelper
|
2
|
+
|
3
|
+
def display_string(item, attribute)
|
4
|
+
item.send(attribute)
|
5
|
+
end
|
6
|
+
|
7
|
+
alias_method :display_decimal, :display_string
|
8
|
+
alias_method :display_float, :display_string
|
9
|
+
alias_method :display_integer, :display_string
|
10
|
+
alias_method :display_position, :display_string
|
11
|
+
alias_method :display_text, :display_string
|
12
|
+
alias_method :display_virtual, :display_string
|
13
|
+
|
14
|
+
def string_filter(filter)
|
15
|
+
values = set_context.send(filter.to_s.pluralize).to_a
|
16
|
+
|
17
|
+
items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
|
18
|
+
array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
|
19
|
+
items += array
|
20
|
+
end
|
21
|
+
|
22
|
+
def table_string_field(attribute, item)
|
23
|
+
(raw_content = item.send(attribute)).present? ? raw_content : mdash
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method :table_decimal_field, :table_string_field
|
27
|
+
alias_method :table_float_field, :table_string_field
|
28
|
+
alias_method :table_integer_field, :table_string_field
|
29
|
+
alias_method :table_virtual_field, :table_string_field
|
30
|
+
alias_method :table_password_field, :table_string_field
|
31
|
+
|
32
|
+
end
|