sunrise-cms 1.0.0.rc3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f16976245e13fe93bc1c0de8d3f07e0925dea26e
4
- data.tar.gz: b973a2726856b5732fef592accf355a1aaaf9b6e
3
+ metadata.gz: 2819a7488e62a5f523822bdca65a69cb2f5fd6e7
4
+ data.tar.gz: 0bec11e0682db1e225acc930db2c9d51ebfa4d5f
5
5
  SHA512:
6
- metadata.gz: 4fd90d5b0a8d6139fc3f3a69ca1c6a65b72edc728755a4bdefb27383fbeb3327ef197632534a6b95536374da21b68fa5cd5d4b284219700cdab30386c7ebf41a
7
- data.tar.gz: dd1b9a847686bc41a4e415b2fc92989a150c9be553036096aeeea70623819743fec770876d99e18f6ceb0fb0f7e815ef4df5c1cfeded121395079ca22f3c8f9c
6
+ metadata.gz: 86b59f3ff4fc1276e849d80e19afe0b5b03d54caf5c414fd2f06d2b4e5ce69900495b4f0e89a2b813cc4a889e6fd6d9a4a457798963fb80632cf68af38931b9c
7
+ data.tar.gz: 2bad669260567f6e11729ffeca563e55da0e5270ece2cfec22138a9d34e96e1e923fe893db96382820e2c82112aca271c09ea92795768ddae1d9da8aa56cfee8
data/README.md CHANGED
@@ -99,6 +99,11 @@ class SunriseProduct < Sunrise::AbstractModel
99
99
  field :total_stock, :html => { :style => 'width:100%;clear:both;' }
100
100
  field :item_model_id, :collection => lambda { ItemModel.all }, :include_blank => false
101
101
  end
102
+
103
+ nested_attributes :project_fields, multiply: true, sort: true do
104
+ field :name
105
+ field :value
106
+ end
102
107
 
103
108
  field :picture, :as => :uploader
104
109
  end
@@ -166,6 +166,26 @@ class Sunrise
166
166
 
167
167
  $(link).closest("div.nested_item").hide()
168
168
 
169
+ initSortFields: (dom_id) ->
170
+ container = $(dom_id)
171
+
172
+ container.sortable
173
+ cursor: 'move'
174
+ handle: '.nested_input_handle'
175
+ items: '.nested_item'
176
+ opacity: 0.8
177
+ update: (event, ui) =>
178
+ this.updateSortField(event, ui)
179
+
180
+ container.disableSelection()
181
+
182
+ updateSortField: (event, ui) ->
183
+ element = $(ui.item)
184
+ container = element.parents('div.nested')
185
+
186
+ container.find(".nested_item").each (index, item) ->
187
+ $(item).find(".nested_input_sort").val(index)
188
+
169
189
  $(document).ready ->
170
190
  window['sunrise'] ?= new Sunrise(window.location.pathname)
171
191
  window['sunrise'].setup()
@@ -285,3 +285,8 @@ div.input.boolean input {
285
285
  .uploader-button span {
286
286
  line-height: 30px;
287
287
  }
288
+
289
+ .nested_input_handle {
290
+ float: left;
291
+ cursor: move;
292
+ }
@@ -14,6 +14,14 @@
14
14
  <%= manage_add_child_link t('manage.buttons.add_nested_field'), form, field, {:partial=>"nested_field"} %>
15
15
  </div>
16
16
  <% end -%>
17
+
18
+ <% if field.sort? %>
19
+ <script type="text/javascript">
20
+ $(document).ready(function(){
21
+ window['sunrise'].initSortFields("#<%= field.dom_id %>");
22
+ });
23
+ </script>
24
+ <% end -%>
17
25
  </div>
18
26
  <% elsif field.association? -%>
19
27
  <%= form.association field.name.to_sym, field.input_options.merge(options) %>
@@ -1,4 +1,10 @@
1
1
  <div class="nested_item">
2
2
  <%= manage_remove_child_link('', form, :class => "close-but") if field.multiply? %>
3
+
4
+ <% if field.sort? %>
5
+ <%= image_tag 'sunrise/tree_dnd1.png', :class => "nested_input_handle" %>
6
+ <%= form.hidden_field field.sort_column, :class => "nested_input_sort" if field.sort_hidden_field? %>
7
+ <% end -%>
8
+
3
9
  <%= render :partial => 'field', :collection => field.fields, :locals => {:form => form} %>
4
10
  </div>
@@ -12,6 +12,8 @@ module Sunrise
12
12
  attr_reader :unless_condition
13
13
 
14
14
  def initialize(abstract_model, parent, options = {})
15
+ options = {:multiply => false, :sort => false}.merge(options)
16
+
15
17
  super(abstract_model, parent, options)
16
18
 
17
19
  # Build conditionals
@@ -36,7 +38,7 @@ module Sunrise
36
38
  css << "grey-but" if input_options[:boolean]
37
39
  css << "tags-edit" if association?
38
40
 
39
- {:class => css}.merge(input_options[:html] || {})
41
+ {:class => css, :id => dom_id}.merge(input_options[:html] || {})
40
42
  end
41
43
 
42
44
  def association?
@@ -50,7 +52,11 @@ module Sunrise
50
52
  def nested?
51
53
  false
52
54
  end
53
-
55
+
56
+ def dom_id
57
+ @dom_id ||= "#{name}_field"
58
+ end
59
+
54
60
  protected
55
61
 
56
62
  # Verifies that the conditionals for this field evaluate to true for the
@@ -22,6 +22,33 @@ module Sunrise
22
22
  def multiply?
23
23
  @config_options[:multiply] != false
24
24
  end
25
+
26
+ def sort?
27
+ @config_options[:sort] != false
28
+ end
29
+
30
+ def sort_hidden_field?
31
+ sort? && sort_options[:hidden_field]
32
+ end
33
+
34
+ def sort_column
35
+ sort_options[:column]
36
+ end
37
+
38
+ def sort_options
39
+ @sort_options ||= build_sort_options
40
+ end
41
+
42
+ protected
43
+
44
+ def build_sort_options
45
+ options = (@config_options[:sort].is_a?(Hash) ? @config_options[:sort] : {}).symbolize_keys
46
+
47
+ {
48
+ :column => :sort_order,
49
+ :hidden_field => true
50
+ }.merge(options)
51
+ end
25
52
  end
26
53
  end
27
54
  end
@@ -1,3 +1,3 @@
1
1
  module Sunrise
2
- VERSION = "1.0.0.rc3".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunrise-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Galeta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-10 00:00:00.000000000 Z
12
+ date: 2014-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -722,9 +722,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
722
722
  version: '0'
723
723
  required_rubygems_version: !ruby/object:Gem::Requirement
724
724
  requirements:
725
- - - '>'
725
+ - - '>='
726
726
  - !ruby/object:Gem::Version
727
- version: 1.3.1
727
+ version: '0'
728
728
  requirements: []
729
729
  rubyforge_project: sunrise-cms
730
730
  rubygems_version: 2.1.11