rails_admin_globalize 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = RailsAdminGlobalize
2
+
3
+ = Usage
4
+
5
+ add the gem to your bundler
6
+
7
+ gem "rails_admin"
8
+ gem "globalize3"
9
+ gem "rails_admin_globalize"
10
+
11
+ ######
12
+
13
+
14
+
15
+
16
+ ######
17
+
18
+
19
+ add globalize to the list of actions in rails_admin's initializer
20
+
21
+ RailsAdmin.config do |config|
22
+
23
+ config.actions do
24
+ dashboard do ; end
25
+ globalize do ; end
26
+ index do ; end
27
+ new do ; end
28
+ export do ; end
29
+ bulk_delete do ; end
30
+ show do ; end
31
+ edit do ; end
32
+ delete do ; end
33
+ history_show do ; end
34
+ show_in_app do ; end
35
+ end
36
+ end
37
+
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RailsAdminGlobalize'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,6 @@
1
+ $(function() {
2
+ $("#target_locale_select").live("change", function(e) {
3
+ var url = $("#target_locale_select").data("target-url");
4
+ location.replace(url+"?target_locale="+$("#target_locale_select").val());
5
+ });
6
+ });
@@ -0,0 +1,28 @@
1
+ .globalize-form {
2
+ h4 {
3
+ font-size: 22px;
4
+ margin: 60px 0 15px;
5
+ padding: 0;
6
+ strong {
7
+ color: #9D261D;
8
+ font-size: 26px;
9
+ padding: 0 0 0 7px;
10
+ }
11
+ }
12
+ h5 {
13
+ border-bottom: 1px solid #dddddd;
14
+ font-size: 16px;
15
+ margin: 40px 0 15px;
16
+ padding: 0 0 15px;
17
+ }
18
+ .controls.well {
19
+ &.string_type {
20
+ padding: 4px 19px;
21
+ }
22
+ &.text_type {
23
+ overflow-x: auto;
24
+ overflow-y: auto;
25
+ height: 310px;
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,40 @@
1
+ - in_error = object.errors.present? && object.errors.messages.keys.include?(field.method_name)
2
+ .control-group{:class=>("#{field.css_class} #{field.type}_type #{'error' if in_error}")}
3
+ .controls{:class => field.type.eql?('text') ? 'well' : ''}
4
+ - if field.type==:text
5
+ :ruby
6
+ if field.ckeditor
7
+ richtext = 'ckeditor'
8
+ js_data = {
9
+ :jspath => field.ckeditor_location ? field.ckeditor_location : field.ckeditor_base_location + "ckeditor.js",
10
+ :base_location => field.ckeditor_base_location,
11
+ :options => {
12
+ :customConfig => field.ckeditor_config_js ? field.ckeditor_config_js : field.ckeditor_base_location + "config.js"
13
+ }
14
+ }
15
+ elsif field.codemirror
16
+ richtext = 'codemirror'
17
+ js_data = {
18
+ :csspath => field.codemirror_css_location,
19
+ :jspath => field.codemirror_js_location,
20
+ :options => field.codemirror_config,
21
+ :locations => field.codemirror_assets
22
+ }
23
+ elsif field.bootstrap_wysihtml5
24
+ richtext = 'bootstrap-wysihtml5'
25
+ js_data = {
26
+ :csspath => field.bootstrap_wysihtml5_css_location,
27
+ :jspath => field.bootstrap_wysihtml5_js_location,
28
+ :config_options => field.bootstrap_wysihtml5_config_options.to_json
29
+ }
30
+ else
31
+ richtext = false
32
+ js_data = {}
33
+ end
34
+
35
+ = form.text_area field.method_name, field.html_attributes.reverse_merge(:data => { :richtext => richtext, :options => js_data.to_json }).reverse_merge(:value => object.send(field.name))
36
+ - else
37
+ = form.send(field.view_helper, field.method_name, field.html_attributes)
38
+ -if in_error
39
+ -I18n.with_locale @current_locale do
40
+ =content_tag(:span, "#{object.errors.messages[field.method_name]}", :class => 'help-inline', :style=>"color: #B94A48").html_safe
@@ -0,0 +1,97 @@
1
+ = javascript_include_tag "rails_admin/custom/rails_admin_globalize.js"
2
+ = stylesheet_link_tag "rails_admin/custom/rails_admin_globalize.css"
3
+
4
+ %h2= I18n.translate("admin.actions.globalize.title")
5
+ %p= raw I18n.translate("admin.actions.globalize.subtitle", :locale_name => "<strong>#{I18n.locale}</strong>".upcase)
6
+
7
+ - translations_field = @object.translated_attributes.keys.collect(&:to_sym)
8
+
9
+ - default_locale = I18n.locale
10
+ - target_locale = @target_locale
11
+
12
+ - rails_admin_proxy = @model_config
13
+
14
+ - rails_admin_fields = @object.class.rails_admin.edit.with(:view=>self, :object=>@object, :controller=>@controller).visible_fields.inject({}) { |a,f| a[f.name] = f if translations_field.include?(f.name) ; a }
15
+
16
+ = form_for @object, :url => rails_admin.globalize_path(@object.class.to_s.split("::").map(&:underscore).join("~"), @object.id), :html => {:class => 'globalize-form'} do |form|
17
+ = select_tag 'target_locale', options_for_select( @available_locales, @target_locale ), :id => "target_locale_select", :"data-target-url" => rails_admin.globalize_path(@object.class.to_s.split("::").map(&:underscore).join("~"), @object.id)
18
+
19
+ - rails_admin_fields.keys.each do |t|
20
+ %h5= t
21
+ .row-fluid
22
+ .span4
23
+ .controls.well{ :class => "#{rails_admin_fields[t].type}_type" }
24
+ .original-content= raw @object.send(t)
25
+ .span8
26
+ - I18n.with_locale target_locale do
27
+ = render :partial => "globalize_field", :locals => {:object => @object, :form => form, :field => rails_admin_fields[t]}
28
+
29
+ - @associated_translations = @object.class.reflect_on_all_associations(:has_many).collect{|r| r.name if r.klass.respond_to?(:translation_options) }.compact
30
+ - @associated_translations += @object.class.reflect_on_all_associations(:has_one).collect{|r| r.name if r.klass.respond_to?(:translation_options) }.compact
31
+
32
+
33
+ - @associated_translations = @object.associated_translations if @object.respond_to?("associated_translations")
34
+ - @associated_translations = @associated_translations.compact.flatten.uniq
35
+ - if @associated_translations
36
+ - @associated_translations.each do |association|
37
+
38
+ - collection = @object.send(association)
39
+ - if collection.present?
40
+ - collection = [collection].flatten.uniq
41
+ - translations_field = collection.first.translated_attributes.keys.collect(&:to_sym)
42
+ - rails_admin_proxy = collection.first.class.rails_admin
43
+ - rails_admin_fields = rails_admin_proxy.edit.with(:view=>self, :object=>collection.first, :controller=>@controller).visible_fields.inject({}) { |a,f| a[f.name] = f if translations_field.include?(f.name) ; a }
44
+ = form.fields_for association.to_sym do |subform|
45
+ - obj = subform.object
46
+ %h4= raw I18n.translate("admin.actions.globalize.associated_translations", :associated_model => "<strong>#{rails_admin_proxy.label_plural}</strong>")
47
+ - rails_admin_fields.each do |t, field|
48
+ %h5= t
49
+ .row-fluid
50
+ .span4
51
+ .controls.well{ :class => "#{rails_admin_fields[t].type}_type" }
52
+ .original-content= raw obj.send(t)
53
+ .span8
54
+ - I18n.with_locale target_locale do
55
+ = render :partial => "globalize_field", :locals => {:field => field, :object => obj, :form => subform}
56
+
57
+ - @sub_associated_translations = collection.first.class.associated_model_to_globalize rescue nil
58
+
59
+ - if @sub_associated_translations.present?
60
+
61
+ - if @sub_associated_translations[:has_many].present?
62
+ - @sub_associated_translations[:has_many].each do |has_many_associated_model|
63
+
64
+ - associated_model = obj.send(has_many_associated_model)
65
+ - associated_translations_field = associated_model.first.translated_attributes.keys.collect(&:to_sym)
66
+ - associated_rails_admin_proxy = associated_model.first.class.rails_admin
67
+ - associated_rails_admin_fields = associated_rails_admin_proxy.visible_fields.inject({}) { |a,f| a[f.name] = f if associated_translations_field.include?(f.name) ;a }
68
+
69
+ = subform.fields_for has_many_associated_model.to_sym do |subsubform|
70
+ - sub_obj = subsubform.object
71
+ - associated_rails_admin_fields.each do |t, field|
72
+ %h5= t
73
+ .row-fluid
74
+ .span4
75
+ .controls.well{ :class => "#{associated_rails_admin_fields[t].type}_type" }
76
+ .original-content= raw sub_obj.send(t)
77
+ .span8
78
+ - I18n.with_locale target_locale do
79
+ = render :partial => "globalize_field", :locals => {:field => field, :object => sub_obj, :form => subsubform}
80
+
81
+ - if @sub_associated_translations[:has_one].present?
82
+ - @sub_associated_translations[:has_one].each do |has_one_associated_model|
83
+ = # TODO
84
+
85
+
86
+ %input{:type => :hidden, :name => 'return_to', :value => (params[:return_to].presence || request.referer)}
87
+ .form-actions
88
+ %button.btn.btn-primary{:type => "submit", :name => "_save", :'data-disable-with' => t("admin.form.save")}
89
+ %i.icon-white.icon-ok
90
+ = t("admin.form.save")
91
+ %span.extra_buttons
92
+ - if authorized? :globalize, @abstract_model
93
+ %button.btn.btn-info{:type => "submit", :name => "_add_edit", :'data-disable-with' => t("admin.form.save_and_edit")}
94
+ = t("admin.form.save_and_edit")
95
+ %button.btn{:type => "submit", :name => "_continue", :'data-disable-with' => t("admin.form.cancel")}
96
+ %i.icon-remove
97
+ = t("admin.form.cancel")
@@ -0,0 +1,14 @@
1
+ en:
2
+ admin:
3
+ actions:
4
+ globalize:
5
+ title: "Globalize"
6
+ subtitle: "Insert translations from %{locale_name} to selected locale:"
7
+ menu: "Translate"
8
+ breadcrumb: "Globalize"
9
+ link: "Globalize"
10
+ bulk_link: "Globalize selected %{model_label_plural}"
11
+ done: "Globalized"
12
+ rails_admin:
13
+ globalize:
14
+ success: Translation saved
@@ -0,0 +1,15 @@
1
+ it:
2
+ admin:
3
+ actions:
4
+ globalize:
5
+ title: Traduci
6
+ subtitle: "Inserisci la traduzione dalla lingua %{locale_name} alla lingua selezionata:"
7
+ menu: Traduci
8
+ breadcrumb: Traduci
9
+ link: Traduci
10
+ bulk_link: "Traduci %{model_label_plural}"
11
+ done: Tradotto
12
+ associated_translations: "Traduzioni per %{associated_model}"
13
+ rails_admin:
14
+ globalize:
15
+ success: Traduzione salvata correttamente
@@ -0,0 +1,68 @@
1
+ require "rails_admin_globalize/engine"
2
+
3
+ module RailsAdminGlobalize
4
+ end
5
+
6
+ require 'rails_admin/config/actions'
7
+
8
+ module RailsAdmin
9
+ module Config
10
+ module Actions
11
+
12
+ class Globalize < Base
13
+
14
+ RailsAdmin::Config::Actions.register(self)
15
+
16
+ register_instance_option :member? do
17
+ true
18
+ end
19
+
20
+ register_instance_option :visible? do
21
+ authorized? && bindings[:object].class.respond_to?("translated_attribute_names")
22
+ end
23
+
24
+ register_instance_option :link_icon do
25
+ 'icon-globe'
26
+ end
27
+
28
+ register_instance_option :member? do
29
+ true
30
+ end
31
+
32
+ register_instance_option :http_methods do
33
+ [:get,:put]
34
+ end
35
+
36
+ register_instance_option :controller do
37
+
38
+ Proc.new do
39
+ @available_locales = (I18n.available_locales - [I18n.locale])
40
+ @available_locales = @object.available_locales if @object.respond_to?("available_locales")
41
+
42
+ if request.get?
43
+ @target_locale = params[:target_locale] || @available_locales.first || I18n.locale
44
+
45
+ else
46
+ loc = @current_locale = I18n.locale
47
+ @target_locale = params[:target_locale]
48
+ I18n.locale = @target_locale
49
+
50
+ result = @object.update_attributes(params[@abstract_model.param_key])
51
+
52
+ I18n.locale = loc
53
+ if result
54
+ flash[:notice] = I18n.t("rails_admin.globalize.success")
55
+ redirect_to back_or_index
56
+ else
57
+ flash[:alert] = I18n.t("rails_admin.globalize.error")
58
+ end
59
+ end
60
+ @object.inspect
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ module RailsAdminGlobalize
2
+ class Engine < ::Rails::Engine
3
+
4
+ if Rails.version >= '3.1'
5
+ initializer :assets do |config|
6
+ Rails.application.config.assets.precompile += %w( rails_admin/custom/rails_admin_globalize.js rails_admin/custom/rails_admin_globalize.css )
7
+ end
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminGlobalize
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_globalize
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Andrea Zaupa
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 3
31
+ - 2
32
+ version: "3.2"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rails_admin
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 19
44
+ segments:
45
+ - 0
46
+ - 3
47
+ - 0
48
+ version: 0.3.0
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: globalize3
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 0
62
+ - 2
63
+ - 0
64
+ version: 0.2.0
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ description: RailsAdminGlobalize.
68
+ email:
69
+ - azaupa@gmail.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - app/assets/javascripts/rails_admin/custom/rails_admin_globalize.js
78
+ - app/assets/stylesheets/rails_admin/custom/rails_admin_globalize.css.scss
79
+ - app/views/rails_admin/main/_globalize_field.haml
80
+ - app/views/rails_admin/main/globalize.html.haml
81
+ - config/locales/globalize.en.yml
82
+ - config/locales/globalize.it.yml
83
+ - lib/rails_admin_globalize/engine.rb
84
+ - lib/rails_admin_globalize/version.rb
85
+ - lib/rails_admin_globalize.rb
86
+ - MIT-LICENSE
87
+ - Rakefile
88
+ - README.rdoc
89
+ homepage: https://github.com/andreazaupa/rails_admin_globalize
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.10
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Translation action to rails_admin + globalize3
122
+ test_files: []
123
+