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 +4 -4
- data/app/assets/javascripts/lalala/modules/calendar.module.js +25 -2
- data/app/assets/javascripts/lalala/modules/grid.module.js +3 -0
- data/app/assets/stylesheets/lalala/modules/_grid.css.scss +1 -1
- data/lib/formtastic/inputs/grid_input.rb +138 -59
- data/lib/lalala/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85ab922bcd762d6346607b0910afa1cbf3b44080
|
4
|
+
data.tar.gz: ecac7d2acab2bf0f4af49de9047483d9a08b57a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
});
|
@@ -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
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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("✕"), 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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
61
|
+
template.raw <<-EOS
|
62
|
+
#{inputs.join}
|
63
|
+
<a class="close-button">✕</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
|
-
|
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
|
data/lib/lalala/version.rb
CHANGED
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.
|
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-
|
16
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: carrierwave
|