lalala 4.0.0.dev.161 → 4.0.0.dev.162

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: 6496dddb416bf30955bfda92c6b846b259141c15
4
- data.tar.gz: a4e3ee6537a65917e5348c4f591b5cc26de16006
3
+ metadata.gz: 85ab922bcd762d6346607b0910afa1cbf3b44080
4
+ data.tar.gz: ecac7d2acab2bf0f4af49de9047483d9a08b57a0
5
5
  SHA512:
6
- metadata.gz: f2e010c20df7eccad07a8e03ba9eeee5ba440ec66c5382b86cddd3512b64eb7699f00be11c2e39f0f674e5ebb59aa370c200d3b3dbf8b93095bf6db64b383b90
7
- data.tar.gz: b920dd7d2f5a69c6d3829b2650ddc79e74eebfc83cd44029a1c3e0500696a4e2dcfe7507dcc09ecab41bb5aaf1559138613ae4bfc8091bbeafcf47a8133d95c6
6
+ metadata.gz: 3abf89d212e5fec3606f2df68c96af433a5c61ce61310fd64c126d509510eab129ea3d3b62af780263be6c0fa80b2f75f714d4a9488da04ee6d09d2231516973
7
+ data.tar.gz: 71a4da8d9ea4de8ccccf3d5fa157796335d5ee65563072de23f8dd57204abd5af24725c1f72dfd3421618161c2afda3add4a0cd59b9ad4f8136c6271fcd4b8f2
@@ -73,17 +73,40 @@ Calendar = (function() {
73
73
  }
74
74
  });
75
75
 
76
+ cal.setDate(date);
77
+
76
78
  this.$el.data("calendar", cal);
77
79
  };
78
80
 
79
81
 
80
82
  Cal.prototype.get_date_from_hidden_fields = function() {
81
- var values = [];
83
+ var fields = [], values = [], new_date;
82
84
 
83
85
  this.$fieldset.find('input[type="hidden"]').each(function() {
84
- values.push( $(this).val() );
86
+ var name = $(this).attr("name");
87
+ fields.push(name);
85
88
  });
86
89
 
90
+ fields = fields.sort();
91
+ new_date = new Date();
92
+
93
+ for (var i=0,j=fields.length; i<j; ++i) {
94
+ var value = this.$fieldset.find('input[name="' + fields[i] + '"]').val();
95
+ var date_part_id = fields[i].match(/\(([^\)]+)\)/)[1];
96
+
97
+ if (!value) {
98
+ switch (date_part_id) {
99
+ case "1i": value = new_date.getFullYear(); break;
100
+ case "2i": value = new_date.getMonth() + 1; break;
101
+ case "3i": value = new_date.getDate(); break;
102
+ case "4i": value = "00"; break;
103
+ case "5i": value = "00"; break;
104
+ }
105
+ }
106
+
107
+ values.push(value);
108
+ }
109
+
87
110
  // return js date
88
111
  return new Date(values[0], values[1] - 1, values[2]);
89
112
  };
@@ -39,8 +39,11 @@ Grid = (function() {
39
39
  var grid_piece = document.createElement("li");
40
40
  grid_piece.className = "asset";
41
41
  grid_piece.innerHTML = this.innerHTML.replace("<a", "<a class=\"thumbnail\"");
42
+
42
43
  var overlay = document.createElement("div");
43
44
  overlay.className = "overlay";
45
+ $(overlay).attr("title", $(this).attr("title"));
46
+
44
47
  grid_piece.appendChild(overlay);
45
48
  fragment.appendChild(grid_piece);
46
49
  });
@@ -87,7 +87,7 @@
87
87
  }
88
88
 
89
89
  // label
90
- .asset label {
90
+ .asset .filename {
91
91
  @include border-radius(2px);
92
92
  background: #fff;
93
93
  bottom: 6px;
@@ -4,77 +4,156 @@ class Formtastic::Inputs::GridInput
4
4
  def to_html
5
5
  object = builder.object
6
6
  assets = object.send(method)
7
+ asset_model_class = builder.object.class.reflect_on_association(method).class_name.constantize
7
8
 
8
- asset_model_class = object.class.reflect_on_association(method).class_name.constantize
9
+ # build html
10
+ ul = template.content_tag :ul do
11
+ html = []
12
+ html << Formtastic::Inputs::GridInput.build_assets(assets, asset_model_class, builder, template, method)
13
+ html << Formtastic::Inputs::GridInput.build_errors(assets, asset_model_class, builder, template, method)
14
+ html << Formtastic::Inputs::GridInput.build_actions(assets, asset_model_class, builder, template, method)
15
+ template.raw html.join("")
16
+ end
17
+
18
+ input_wrapping { ul }
19
+ end
20
+
21
+ private
22
+
23
+ #
24
+ # Asset blocks (+ their attributes)
25
+ #
26
+ def self.build_assets(assets, asset_model_class, builder, template, method)
27
+ html = []
28
+
29
+ # collect attribute names
9
30
  asset_attributes = asset_model_class.accessible_attributes.to_a
10
31
  asset_attributes.select! { |x| x.size > 0 and !%w(asset translations_writer).include?(x) }
11
32
 
12
- ul = template.content_tag :ul do
13
- html = template.raw("")
14
- asset_errors = []
15
-
16
- assets.each_with_index do |asset, idx|
17
- html += template.content_tag :li, class: "asset" do
18
- builder.fields_for(method, asset) do |f|
19
- asset_errors.concat(asset.errors.to_a)
20
-
21
- lalala_thumb = if f.object.asset.respond_to?(:lalala_thumb)
22
- f.object.asset.lalala_thumb
23
- end
24
-
25
- if url = lalala_thumb.try(:url)
26
- link_inner_html = template.image_tag(url)
27
- else
28
- link_inner_html = template.content_tag(:span, "", class: "file-icon")
29
- end
30
-
31
- asset_html = template.raw("")
32
- asset_html << template.link_to(link_inner_html, f.object.asset.url)
33
- asset_html << template.content_tag(:ol, { class: "attributes" }) do
34
- inputs = asset_attributes.map do |ia|
35
- if ia.include?("_id")
36
- collection_name = ia.chomp("_id").pluralize.to_sym
37
- if f.object.respond_to?(collection_name)
38
- f.input ia.to_sym, as: :select, collection: f.object.send(collection_name)
39
- else
40
- f.input ia.to_sym, placeholder: ia
41
- end
42
- else
43
- f.input ia.to_sym, placeholder: ia
44
- end
45
- end
46
-
47
- template.raw(inputs.join) + template.content_tag(
48
- :a, template.raw("&#10005;"), class: "close-button"
49
- )
50
- end
51
-
52
- asset_html
53
- end
33
+ # build each
34
+ assets.each_with_index do |asset, idx|
35
+ li = template.content_tag :li, class: "asset", title: asset.asset.file.filename do
36
+ builder.fields_for(method, asset) do |f|
37
+ Formtastic::Inputs::GridInput.build_asset(asset, asset_attributes, f, template)
54
38
  end
55
39
  end
56
40
 
57
- if asset_errors.present?
58
- html += template.content_tag :li, class: "errors" do
59
- template.content_tag :ul do
60
- errors_html = template.raw("")
61
- asset_errors.each do |error|
62
- errors_html += template.content_tag(:li, error)
63
- end
64
- errors_html
65
- end
66
- end
41
+ html << li
42
+ end
43
+
44
+ template.raw(html.join(""))
45
+ end
46
+
47
+
48
+
49
+ def self.build_asset(asset, asset_attributes, f, template)
50
+ html = []
51
+
52
+ # html -> link
53
+ html << Formtastic::Inputs::GridInput.build_asset_link(f, template)
54
+
55
+ # html -> attributes
56
+ html << template.content_tag(:ol, { class: "attributes" }) do
57
+ inputs = asset_attributes.map do |attribute|
58
+ Formtastic::Inputs::GridInput.build_asset_attribute(attribute, f)
67
59
  end
68
60
 
69
- html += template.content_tag :li, class: "actions" do
70
- builder.fields_for(method, assets.build) do |f|
71
- f.file_field :asset, multiple: true, accept: asset_model_class.extension_white_list
72
- end
61
+ template.raw <<-EOS
62
+ #{inputs.join}
63
+ <a class="close-button">&#10005;</a>
64
+ EOS
65
+ end
66
+
67
+ # return
68
+ template.raw(html.join(""))
69
+ end
70
+
71
+
72
+
73
+ def self.build_asset_link(f, template)
74
+ inner_html = template.raw("")
75
+ filename = f.object.asset.file.filename
76
+
77
+ # get thumbnail
78
+ lalala_thumb = if f.object.asset.respond_to?(:lalala_thumb)
79
+ f.object.asset.lalala_thumb
80
+ end
81
+
82
+ # thumbnail or file-icon + filename
83
+ inner_html << if url = lalala_thumb.try(:url)
84
+ template.image_tag(url)
85
+ else
86
+ combo = template.raw("")
87
+ combo << template.content_tag(:span, "", class: "file-icon")
88
+ combo << template.content_tag(:span, filename, class: "filename")
89
+ combo
90
+ end
91
+
92
+ # return
93
+ template.link_to(inner_html, f.object.asset.url)
94
+ end
95
+
96
+
97
+
98
+ def self.build_asset_attribute(attribute, f)
99
+ args = [attribute.to_sym]
100
+ collection_name = attribute.chomp("_id").pluralize.to_sym
101
+
102
+ if attribute.include?("_id") && f.object.respond_to?(collection_name)
103
+ args << {
104
+ as: :select,
105
+ collection: f.object.send(collection_name)
106
+ }
107
+ else
108
+ args << {
109
+ placeholder: attribute
110
+ }
111
+ end
112
+
113
+ f.input(*args)
114
+ end
115
+
116
+
117
+
118
+ #
119
+ # Errors
120
+ #
121
+ def self.build_errors(assets, asset_model_class, builder, template, method)
122
+ html = ""
123
+
124
+ asset_errors = assets.map do |asset|
125
+ asset.errors.to_a
126
+ end.flatten
127
+
128
+ if asset_errors.present?
129
+ html = <<-EOS
130
+ <li class="errors">
131
+ <ul>%{items}</ul>
132
+ </li>
133
+ EOS
134
+
135
+ errors_html = template.raw("")
136
+ asset_errors.each do |error|
137
+ errors_html << template.content_tag(:li, error)
73
138
  end
74
139
 
75
- html
140
+ html.sub("%{items}", errors_html)
76
141
  end
77
142
 
78
- input_wrapping { ul }
143
+ template.raw(html)
79
144
  end
145
+
146
+
147
+
148
+ #
149
+ # Actions
150
+ #
151
+ def self.build_actions(assets, asset_model_class, builder, template, method)
152
+ template.content_tag :li, class: "actions" do
153
+ builder.fields_for(method, assets.build) do |f|
154
+ f.file_field :asset, multiple: true, accept: asset_model_class.extension_white_list
155
+ end
156
+ end
157
+ end
158
+
80
159
  end
@@ -1,6 +1,6 @@
1
1
  module Lalala
2
2
  VERSION = "4.0.0"
3
- BUILD = "161"
3
+ BUILD = "162"
4
4
 
5
5
  if BUILD != ("{{BUILD_NUMBER" + "}}") # prevent sed replacement (see script/ci)
6
6
  BUILD_VERSION = "#{VERSION}.dev.#{BUILD}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lalala
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.dev.161
4
+ version: 4.0.0.dev.162
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-05-22 00:00:00.000000000 Z
16
+ date: 2013-05-23 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: carrierwave