forma 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forma/helpers.rb +1 -1
- data/lib/forma/table.rb +33 -6
- data/lib/forma/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5d99ebcbdee2fe99c2b5d5a2559a8e183f56308
|
4
|
+
data.tar.gz: 2ebcf83d7e30b49b1ff9d76e8fe0b0c64a41dd91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0926824b2c20ed74d2fa12da09ae3a1157f8a4b18ef385363c997c3e152743bc5e90eba652d908288da81f409103450cdd47e1c3da51fdbc329a764b43e04ff6
|
7
|
+
data.tar.gz: c1907dbc1170607cd8759e330237582652368cbcfc5dc5968e4455ee903bf18b6a5ec8654fb67f95675cf75c6ff750a2dbe90162559cb971ff3dac57ee2d8fa6
|
data/lib/forma/helpers.rb
CHANGED
data/lib/forma/table.rb
CHANGED
@@ -5,7 +5,7 @@ module Forma
|
|
5
5
|
include Forma::FieldHelper
|
6
6
|
include Forma::WithTitleElement
|
7
7
|
attr_reader :collapsible, :collapsed, :icon, :title
|
8
|
-
attr_reader :title_actions
|
8
|
+
attr_reader :title_actions, :row_class, :checkboxes
|
9
9
|
attr_accessor :models
|
10
10
|
|
11
11
|
def initialize(h = {})
|
@@ -23,6 +23,9 @@ module Forma
|
|
23
23
|
# actions
|
24
24
|
@title_actions = h[:title_actions] || []
|
25
25
|
@item_actions = h[:item_actions] || []
|
26
|
+
# row class
|
27
|
+
@row_class = h[:row_class]
|
28
|
+
@checkboxes = h[:checkboxes]
|
26
29
|
# context
|
27
30
|
@context = h[:context]
|
28
31
|
end
|
@@ -57,6 +60,9 @@ module Forma
|
|
57
60
|
@paginate_options = h
|
58
61
|
end
|
59
62
|
|
63
|
+
def row_class(clazz); @row_class = clazz end
|
64
|
+
def checkboxes(val=true); @checkboxes = val end
|
65
|
+
|
60
66
|
private
|
61
67
|
|
62
68
|
def body_element
|
@@ -71,7 +77,13 @@ module Forma
|
|
71
77
|
|
72
78
|
def table_element
|
73
79
|
def table_header_element
|
74
|
-
children =
|
80
|
+
children = []
|
81
|
+
if @checkboxes
|
82
|
+
children << el('th', attrs: { style: {width: '10px'} }, children: [
|
83
|
+
el('input', attrs: { id: "all-models", type: 'checkbox' })
|
84
|
+
])
|
85
|
+
end
|
86
|
+
children += @fields.map { |f|
|
75
87
|
f.model = @models.first
|
76
88
|
label_text = f.localized_label
|
77
89
|
label_hint = f.localized_hint
|
@@ -84,20 +96,32 @@ module Forma
|
|
84
96
|
el('tr', children: children)
|
85
97
|
])
|
86
98
|
end
|
99
|
+
|
87
100
|
def table_row(model)
|
88
|
-
children =
|
101
|
+
children = []
|
102
|
+
if @checkboxes
|
103
|
+
children << el('td', children: [
|
104
|
+
el('input', attrs: { id: "model-#{model.id}", type: 'checkbox' })
|
105
|
+
])
|
106
|
+
end
|
107
|
+
children += @fields.map { |fld|
|
89
108
|
fld.model = model
|
90
109
|
el('td', children: [ fld.to_html(false) ])
|
91
110
|
}
|
92
111
|
if @item_actions.any?
|
93
112
|
children << el('td', children: @item_actions.map { |act| act.to_html(model) })
|
94
113
|
end
|
95
|
-
|
114
|
+
############################################################################################
|
115
|
+
options = { children: children }
|
116
|
+
options[:attrs] = { class: eval_with_model(@row_class, model: model) } if @row_class
|
117
|
+
############################################################################################
|
118
|
+
html = el('tr', options)
|
96
119
|
end
|
120
|
+
|
97
121
|
def table_body_element
|
98
|
-
children =
|
99
|
-
el('tbody', children: @models.map { |model| table_row(model) })
|
122
|
+
children = el('tbody', children: @models.map { |model| table_row(model) })
|
100
123
|
end
|
124
|
+
|
101
125
|
if @models and @models.any?
|
102
126
|
el('table', attrs: { class: 'ff-common-table' }, children: [ table_header_element, table_body_element ])
|
103
127
|
else
|
@@ -119,5 +143,8 @@ module Forma
|
|
119
143
|
])
|
120
144
|
end
|
121
145
|
end
|
146
|
+
|
147
|
+
private
|
148
|
+
def eval_with_model(val, h={}); val.is_a?(Proc) ? val.call(h[:model] || self.model) : val.to_s end
|
122
149
|
end
|
123
150
|
end
|
data/lib/forma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Kurashvili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.4.1
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: rich forms for ruby
|