enjoy_cms 0.3.7 → 0.3.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1498d8db8ce0758077a4c20c2cec3ea63c0c228
4
- data.tar.gz: cb2ef030d270a5be3c8d80c5562cd0573a4fddff
3
+ metadata.gz: edb1ca4cc4a6285dc5cec5cdf79c7616d24c9f62
4
+ data.tar.gz: 3fccd7d654da9a4f4673cb3ea69b48a9e9827c10
5
5
  SHA512:
6
- metadata.gz: 5c48c1f6b9eacfd8d2b06dcd842250d1278480cb55cb144dc0db6216dfc9365270147214950189f6a85a12bbdf05b8af81ce50dd59c7768f3ecf582e7170f5ba
7
- data.tar.gz: d06dcaae72d76c9f9ceed2b0a984249be281891bbddf7d809ee10219ad7afed42c1e87a21aefe2093efd7c37dcaf31ed0d21761360ec10db66c907006358df91
6
+ metadata.gz: 43484a9b08f3bd5135d1961eca438da61f00957b09793d16084d624b88d123a86c5ca26660574843249813c371b8771a7f4b9d9559721a194315a89b16b6ee02
7
+ data.tar.gz: 0bcf54b781a1a2c4914ad6a725c0806197063977ea4e1cefa86e4a641e9ff3543c15ef522733e831c6a27bbfbed712a66de6c604d2e3cad158b18177e702566d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enjoy_cms (0.3.7)
4
+ enjoy_cms (0.3.7.1)
5
5
  ack_rails_admin_jcrop
6
6
  addressable
7
7
  ckeditor
@@ -4,32 +4,99 @@ if Enjoy.mongoid?
4
4
 
5
5
  module ClassMethods
6
6
  def enjoy_cms_hash_field(name, opts = {})
7
+ opts.merge!({type: Hash, default: {}})
7
8
  field "#{name}_hash", opts
8
9
 
9
- class_eval <<-EVAL
10
- def #{name}_str=(val)
11
- begin
12
- self.#{name}_hash = JSON.parse(val)
13
- rescue
14
- self[:#{name}_str] = val
15
- end
16
- end
17
- def #{name}_str
18
- self[:#{name}_str] ||= self.#{name}.to_json
19
- end
20
- def #{name}
21
- self.#{name}_hash
22
- end
10
+ meth = name
11
+ meth_str = "#{name}_str"
12
+ meth_hsh = "#{name}_hash"
13
+ meth_json = "#{name}_json"
14
+ if opts[:localize]
15
+ meth_str_t = "#{name}_str_translations"
16
+ meth_hsh_t = "#{name}_hash_translations"
17
+ class_eval <<-EVAL
18
+ def #{meth_str_t}=(val)
19
+ return self.#{meth_hsh_t} = {} if val.blank?
20
+ _hash = {}
21
+ self[:#{meth_str_t}] ||= {}
22
+ I18n.available_locales.each do |l|
23
+ begin
24
+ _hash[l] = JSON.parse(val[l])
25
+ self[:#{meth_str_t}][l]= val[l]
26
+ rescue
27
+ self[:#{meth_str_t}][l]= val[l]
28
+ end
29
+ end
30
+ self.#{meth_hsh_t} = _hash
31
+ end
32
+ def #{meth_str_t}
33
+ self[:#{meth_str_t}] ||= self.#{meth} if self.#{meth}
34
+ end
35
+ def #{meth_str}
36
+ self.#{meth_str_t}[I18n.locale] if self.#{meth_str_t}
37
+ end
38
+ def #{meth}
39
+ self.#{meth_hsh}
40
+ end
41
+ def #{meth_json}
42
+ self.#{meth_hsh}.to_json if self.#{meth_hsh}
43
+ end
44
+
45
+ validate do
46
+ unless self.#{meth_hsh_t}.nil?
47
+ _has_errors = false
48
+ I18n.available_locales.each do |l|
49
+ I18n.with_locale(l) do
50
+ puts self.#{meth_hsh_t}[l]
51
+ puts self.#{meth_str}
52
+ puts "_"
53
+ if self.#{meth_hsh_t}[l].nil? and !self[:#{meth_str_t}][l].blank?
54
+ _has_errors ||= true
55
+ _meth = "#{meth_hsh_t}_\#{l}".to_s
56
+ self.errors.add(_meth, "Неверный формат данных")
57
+ else
58
+ self[:#{meth_str_t}].delete(l) if self[:#{meth_str_t}]
59
+ end
60
+ end
61
+ end
62
+ self.remove_attribute :#{meth_str_t} unless _has_errors
63
+ end
64
+ true
65
+ end
66
+ EVAL
23
67
 
24
- validate do
25
- if self.#{name}_str != self.#{name}.to_json
26
- self.errors.add(:#{name}, "Неверный формат данных")
27
- else
28
- self.remove_attribute :#{name}_str
29
- end
30
- true
31
- end
32
- EVAL
68
+ else
69
+ class_eval <<-EVAL
70
+ def #{meth_str}=(val)
71
+ return self.#{meth_hsh} = {} if val.blank?
72
+ begin
73
+ self.#{meth_hsh} = JSON.parse(val)
74
+ rescue
75
+ self[:#{meth_str}] = val
76
+ end
77
+ end
78
+ def #{meth_str}
79
+ self[:#{meth_str}] ||= self.#{meth}.to_json if self.#{meth}
80
+ end
81
+ def #{meth}
82
+ self.#{meth_hsh}
83
+ end
84
+ def #{meth_json}
85
+ self.#{meth_hsh}.to_json if self.#{meth_hsh}
86
+ end
87
+
88
+ validate do
89
+ unless self.#{meth}.nil?
90
+ if self.#{meth_str} != self.#{meth}.to_json
91
+ self.errors.add(:#{meth}, "Неверный формат данных")
92
+ else
93
+ self.remove_attribute :#{meth_str}
94
+ end
95
+ true
96
+ end
97
+ end
98
+ EVAL
99
+ end
33
100
  end
34
101
  end
35
102
  end
@@ -8,7 +8,7 @@ if Enjoy.mongoid?
8
8
  clear_by_default = false unless clear_by_default == true
9
9
 
10
10
  field "#{name}_html", opts
11
- field "#{name}_clear", type: Boolean, default: clear_by_default
11
+ field "#{name}_clear", type: Boolean, default: clear_by_default, localize: opts[:localize]
12
12
 
13
13
  class_eval <<-EVAL
14
14
  def #{name}
@@ -6,7 +6,7 @@ module Enjoy::Mappable
6
6
  if Enjoy.mongoid?
7
7
  include ::Geocoder::Model::Mongoid
8
8
  field :coordinates, type: Array
9
- field :address, type: String
9
+ field :address, type: String, localize: Enjoy.configuration.localize
10
10
 
11
11
  field :map_address, type: String
12
12
  field :map_hint, type: String
@@ -5,4 +5,5 @@ ruby:
5
5
  _opts[:class] = 'form-control'
6
6
  _opts[:value] = field.formatted_value
7
7
  _opts[:style] = "font-family: monospace"
8
+
8
9
  = form.text_area field.string_method, _opts
@@ -0,0 +1,10 @@
1
+ ruby:
2
+ _opts = {}
3
+ _opts[:rows] = 10
4
+ _opts[:cols] = 80
5
+ _opts[:class] = 'form-control'
6
+ #_opts[:value] = field.formatted_value
7
+ _opts[:style] = "font-family: monospace"
8
+ / = form.text_area field.string_method, _opts
9
+
10
+ = render 'form', form: form, field: field, field_type: :text_area, html_attributes: _opts
@@ -10,6 +10,7 @@ ruby:
10
10
  = form.text_area field.html_method, _html_attributes
11
11
 
12
12
  label{style='display: block;'}
13
- - _html_attributes = field.html_attributes.reverse_merge({ value: field.form_value[:clear], checked: field.form_value[:clear].in?([true, '1']), required: false, class: "form-control"})
13
+ - _hash = { value: field.form_value[:clear], checked: field.form_value[:clear].in?([true, '1']), required: false, class: "form-control"}
14
+ - _html_attributes = field.html_attributes.reverse_merge(_hash)
14
15
  span{style='float: left'}= form.send field.boolean_view_helper, field.clear_method, _html_attributes
15
16
  div{style='margin-left: 35px; line-height: 40px;'} Убирать теги
@@ -0,0 +1,53 @@
1
+ ul.nav.nav-tabs
2
+ - uuid = "#{field.name}_#{field.object_id}_unique_id"
3
+ - I18n.available_locales.each do |locale|
4
+ li(class="#{'active' if locale == I18n.locale}")
5
+ a(href="##{locale}_#{uuid}" data-toggle="tab" class="#{uuid}")= locale
6
+ .tab-content
7
+ / = form.fields_for field.translations_field do |localized_field|
8
+ - I18n.available_locales.each do |locale|
9
+ - _class = "#{[( 'active' if locale == I18n.locale ), uuid].join(" ")}"
10
+ .fields.tab-pane(style='padding:5px; margin: 0;' id="#{locale}_#{uuid}" class="#{_class}")
11
+ = form.fields_for field.html_translations_field do |html_localized_field|
12
+ ruby:
13
+ js_data = {
14
+ jspath: field.location ? field.location : field.base_location + "ckeditor.js",
15
+ base_location: field.base_location,
16
+ options: {
17
+ customConfig: field.config_js ? field.config_js : field.base_location + "config.js"
18
+ }
19
+ }
20
+ _html_attributes = field.html_attributes.reverse_merge(data: {
21
+ richtext: 'ckeditor',
22
+ options: js_data.to_json
23
+ })
24
+ _html_attributes[:value] = field.form_value[:html] ? field.form_value[:html][locale] : ""
25
+ = html_localized_field.send :text_area, locale , _html_attributes
26
+
27
+ = form.fields_for field.clear_translations_field do |clear_localized_field|
28
+ label{style='display: block;'}
29
+ ruby:
30
+ _value = field.form_value[:clear] ? field.form_value[:clear][locale] : true
31
+ _hash = {
32
+ value: _value,
33
+ checked: _value.in?([true, '1']),
34
+ required: false,
35
+ class: "form-control"
36
+ }
37
+ _html_attributes = field.html_attributes.reverse_merge(_hash)
38
+ span{style='float: left'}= clear_localized_field.send field.boolean_view_helper, locale , _html_attributes
39
+ div{style='margin-left: 35px; line-height: 40px;'} Убирать теги
40
+
41
+
42
+
43
+
44
+ javascript:
45
+ var #{field.name}#{field.object_id} = (new Date().getTime()) + Math.floor(Math.random()*100000);
46
+ $("ul.nav.nav-tabs a.#{uuid}").each(function(e){
47
+ this.href = $(this).attr('href').replace('_unique_id', #{field.name}#{field.object_id});
48
+ $(this).removeClass('#{uuid}');
49
+ });
50
+ $(".tab-content .#{uuid}").each(function(e){
51
+ this.id = this.id.replace('_unique_id', #{field.name}#{field.object_id});
52
+ $(this).removeClass('#{uuid}');
53
+ });
@@ -14,24 +14,70 @@ module RailsAdmin
14
14
  "#{name}_str"
15
15
  end
16
16
 
17
- register_instance_option :allowed_methods do
18
- [string_method]
17
+ register_instance_option :hash_method do
18
+ "#{name}_hash"
19
19
  end
20
20
 
21
- register_instance_option :partial do
22
- :enjoy_hash
21
+ register_instance_option :value do
22
+ formatted_value
23
+ end
24
+
25
+ register_instance_option :tabbed do
26
+ true
27
+ end
28
+
29
+
30
+ ############ localize ######################
31
+ register_instance_option :translations_field do
32
+ (string_method.to_s + '_translations').to_sym
33
+ end
34
+
35
+ register_instance_option :localized? do
36
+ @abstract_model.model_name.constantize.public_instance_methods.include?(translations_field)
37
+ end
38
+
39
+ register_instance_option :pretty_value do
40
+ if localized?
41
+ I18n.available_locales.map { |l|
42
+ ret = nil
43
+ I18n.with_locale(l) do
44
+ _hash = bindings[:object].send(hash_method) || {}
45
+ ret = ("#{l}:<pre>" + JSON.pretty_generate(_hash) + "</pre>")
46
+ end
47
+ ret
48
+ }.join.html_safe
49
+ else
50
+ _hash = bindings[:object].send(hash_method) || {}
51
+ ("<pre>" + JSON.pretty_generate(_hash) + "</pre>").html_safe
52
+ end
23
53
  end
24
54
 
25
55
  register_instance_option :formatted_value do
26
- begin
27
- JSON.pretty_generate(JSON.parse(bindings[:object].send string_method))
28
- rescue
29
- bindings[:object].send string_method
56
+ if localized?
57
+ puts bindings[:object].send((hash_method.to_s + '_translations').to_sym)
58
+ puts '__'
59
+ _val = bindings[:object].send((hash_method.to_s + '_translations').to_sym)
60
+ _val.each_pair { |l, _hash|
61
+ begin
62
+ _val[l] = JSON.pretty_generate(_hash)
63
+ rescue
64
+ end
65
+ }
66
+ else
67
+ begin
68
+ JSON.pretty_generate(bindings[:object].send hash_method)
69
+ rescue
70
+ bindings[:object].send hash_method
71
+ end
30
72
  end
31
73
  end
32
74
 
33
- register_instance_option :pretty_value do
34
- ("<pre>" + JSON.pretty_generate(value) + "</pre>").html_safe
75
+ register_instance_option :allowed_methods do
76
+ localized? ? [string_method, translations_field] : [string_method]
77
+ end
78
+
79
+ register_instance_option :partial do
80
+ localized? ? :enjoy_hash_ml : :enjoy_hash
35
81
  end
36
82
  end
37
83
  end
@@ -10,25 +10,17 @@ module RailsAdmin
10
10
  include RailsAdmin::Engine.routes.url_helpers
11
11
 
12
12
  register_instance_option :html_method do
13
- "#{name}_html"
13
+ "#{name}_html".to_sym
14
14
  end
15
15
 
16
16
  register_instance_option :clear_method do
17
- "#{name}_clear"
17
+ "#{name}_clear".to_sym
18
18
  end
19
19
 
20
20
  register_instance_option :pretty_value do
21
21
  bindings[:object].send(html_method)
22
22
  end
23
23
 
24
- register_instance_option :form_value do
25
- {
26
- html: bindings[:object].send(html_method),
27
- clear: bindings[:object].send(clear_method)
28
- }
29
- end
30
-
31
-
32
24
  register_instance_option :formatted_value do
33
25
  pretty_value
34
26
  end
@@ -37,17 +29,48 @@ module RailsAdmin
37
29
  pretty_value
38
30
  end
39
31
 
40
-
41
32
  register_instance_option :boolean_view_helper do
42
33
  :check_box
43
34
  end
44
35
 
36
+ register_instance_option :tabbed do
37
+ true
38
+ end
39
+
40
+
41
+ ############ localize ######################
42
+ register_instance_option :html_translations_field do
43
+ (html_method.to_s + '_translations').to_sym
44
+ end
45
+ register_instance_option :clear_translations_field do
46
+ (clear_method.to_s + '_translations').to_sym
47
+ end
48
+
49
+ register_instance_option :form_value do
50
+ if localized?
51
+ {
52
+ html: bindings[:object].send(html_translations_field),
53
+ clear: bindings[:object].send(clear_translations_field)
54
+ }
55
+ else
56
+ {
57
+ html: bindings[:object].send(html_method),
58
+ clear: bindings[:object].send(clear_method)
59
+ }
60
+ end
61
+ end
62
+
63
+ register_instance_option :localized? do
64
+ @abstract_model.model_name.constantize.public_instance_methods.include?(html_translations_field) and
65
+ @abstract_model.model_name.constantize.public_instance_methods.include?(clear_translations_field)
66
+ end
67
+
45
68
  register_instance_option :allowed_methods do
46
- [html_method, clear_method]
69
+ localized? ? [html_method, clear_method, html_translations_field, clear_translations_field] : [html_method, clear_method]
47
70
  end
48
71
 
49
72
  register_instance_option :partial do
50
- :enjoy_html
73
+ localized? ? :enjoy_html_ml : :enjoy_html
51
74
  end
52
75
  end
53
76
  end
data/lib/enjoy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Enjoy
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.7.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enjoy_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kiseliev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -498,7 +498,9 @@ files:
498
498
  - app/views/rails_admin/main/_check_boxes.html.slim
499
499
  - app/views/rails_admin/main/_enjoy_connectable.html.slim
500
500
  - app/views/rails_admin/main/_enjoy_hash.html.slim
501
+ - app/views/rails_admin/main/_enjoy_hash_ml.html.slim
501
502
  - app/views/rails_admin/main/_enjoy_html.html.slim
503
+ - app/views/rails_admin/main/_enjoy_html_ml.html.slim
502
504
  - app/views/rails_admin/main/_enum_check_boxes.html.slim
503
505
  - app/views/rails_admin/main/_enum_radio_buttons.html.slim
504
506
  - app/views/rails_admin/main/_form_raw.html.slim