optimacms 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/optimacms/admin/pages_controller.rb +1 -1
- data/app/helpers/optimacms/application_helper.rb +5 -3
- data/app/views/optimacms/admin/pages/_form.html.haml +1 -1
- data/lib/optimacms/filters/form_filter.rb +224 -0
- data/lib/optimacms/version.rb +1 -1
- data/test/dummy/app/helpers/application_helper.rb +1 -0
- data/test/dummy/app/views/my/hello.html.haml +1 -1
- data/test/dummy/app/views/pages/about.html.erb +5 -1
- data/test/dummy/log/development.log +3762 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/04ae6be2750ab3b000694652ae79e604 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/40fab08fc41a745053c9911c090805f6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/694d1c75e6635b4bd2cf34c3d185dd7d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/828e78bfab0b839ebb61b42566c8419f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/994b8fff192124a777d8ffafe086fd4b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9e46c94109ce7a669c23328880ffe8f7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ca5f6b9f50ca76e64e7f8f820d60f5d7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ddca267916e0a1d2d670a2976ce3f65c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/e7f07e91bcda72aac16f20920558ea76 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- metadata +16 -3
- data/lib/simple_filter/controller.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7423961f90b9cefc9804eba62c7a24a34ab07cb5
|
4
|
+
data.tar.gz: c5db0f9c93e7397db548504094fbd9d038a7c1a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae063cca5a45779f75f469eb98c16fa9f443261b066c7797b8c588b7bc128ebda303d4006cc2f5a1c4b5e70d96f0fc68d3e3ab744250b56498f864eec260b184
|
7
|
+
data.tar.gz: 5b36846f5bd8ba734bd139184291708f0dda10bb16200a9eb41092ef379597a876a413d49ca22dbde5e62c7a57b83682780d971dbbb5e92230be2001583eed98
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Optimacms
|
2
2
|
module ApplicationHelper
|
3
3
|
|
4
|
+
include ActionView::Helpers::ApplicationHelper
|
5
|
+
|
4
6
|
def method_missing(method, *args, &block)
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
main_app.send(method, *args, &block)
|
8
|
+
rescue NoMethodError
|
9
|
+
super
|
8
10
|
end
|
9
11
|
|
10
12
|
def tinymce_editor_insert_block
|
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
= f.input :controller_action, as: :string, label: "Controller", :hint=>'controller#action. ex.: news#index'
|
17
17
|
|
18
|
-
= f.association :layout, label: "Layout", collection: @layouts
|
18
|
+
= f.association :layout, label: "Layout", collection: @layouts, label_method: :title
|
19
19
|
|
20
20
|
.form-group.page_template
|
21
21
|
%label(for="inputTemplate" class="col-sm-2 col-md-1 control-label")
|
@@ -0,0 +1,224 @@
|
|
1
|
+
module Optimacms
|
2
|
+
module Filters
|
3
|
+
class FormFilter
|
4
|
+
|
5
|
+
FIELD_TYPE_TEXT = 'text'
|
6
|
+
FIELD_TYPE_HIDDEN = 'hidden'
|
7
|
+
FIELD_TYPE_SELECT_AUTO = 'select_auto' # text with autocomplete
|
8
|
+
|
9
|
+
DBTYPE_STRING = 'string'
|
10
|
+
DBTYPE_INT = 'int'
|
11
|
+
DBTYPE_DATE = 'date'
|
12
|
+
|
13
|
+
#
|
14
|
+
attr_accessor :prefix # session prefix
|
15
|
+
attr_accessor :fields
|
16
|
+
attr_accessor :data
|
17
|
+
#attr_accessor :order # [ ["order_column", "asc|desc"], ..]
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
def initialize(_session, _prefix)
|
22
|
+
@prefix = _prefix
|
23
|
+
@session = _session
|
24
|
+
|
25
|
+
@fields ||={}
|
26
|
+
|
27
|
+
# init data
|
28
|
+
data()
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
############
|
33
|
+
# fields
|
34
|
+
############
|
35
|
+
|
36
|
+
def add_field(f)
|
37
|
+
@fields[f[:name]] = f
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_fields_from_array(a)
|
42
|
+
a.each do |fa|
|
43
|
+
add_field fa
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def field_def_value(name)
|
50
|
+
if (@fields.has_key? name) && (@fields[name].has_key? :def)
|
51
|
+
return @fields[name][:def]
|
52
|
+
end
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
############
|
57
|
+
# sessions
|
58
|
+
############
|
59
|
+
|
60
|
+
def session_get(name, def_value)
|
61
|
+
@session[prefix+name] || def_value
|
62
|
+
end
|
63
|
+
|
64
|
+
def session_save(name, v)
|
65
|
+
@session[prefix+name] = v
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
############
|
70
|
+
# data
|
71
|
+
############
|
72
|
+
|
73
|
+
|
74
|
+
def data
|
75
|
+
return @data unless @data.nil?
|
76
|
+
|
77
|
+
# from session
|
78
|
+
@data_sess = session_get 'data', nil
|
79
|
+
unless @data_sess.nil?
|
80
|
+
@data = @data_sess
|
81
|
+
else
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
@data ||= {}
|
87
|
+
|
88
|
+
session_save('data', @data)
|
89
|
+
|
90
|
+
#
|
91
|
+
@data
|
92
|
+
end
|
93
|
+
|
94
|
+
def v(name, v_def=nil)
|
95
|
+
if (data.has_key? name) && (!data[name].nil?)
|
96
|
+
return data[name]
|
97
|
+
end
|
98
|
+
|
99
|
+
field_def_value(name) || v_def
|
100
|
+
end
|
101
|
+
|
102
|
+
def v_empty?(name)
|
103
|
+
if (data.has_key? name) && (!data[name].nil?)
|
104
|
+
return true
|
105
|
+
end
|
106
|
+
|
107
|
+
# if v == default value
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
def set(field_name,v)
|
112
|
+
data[field_name] = v
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def clear_data
|
117
|
+
session_save 'data', {}
|
118
|
+
end
|
119
|
+
|
120
|
+
def set_data_from_form(params)
|
121
|
+
# search for fields like filter[XXX]
|
122
|
+
params.each do |name, v|
|
123
|
+
#if f =~ /^filter\[([^\]]+)\]$/
|
124
|
+
#name = Regexp.last_match(1)
|
125
|
+
|
126
|
+
next unless @fields.has_key? name
|
127
|
+
|
128
|
+
if @fields[name][:dbtype]==DBTYPE_INT
|
129
|
+
data[name] = (v.to_i rescue 0)
|
130
|
+
else
|
131
|
+
data[name] = v
|
132
|
+
end
|
133
|
+
|
134
|
+
#end
|
135
|
+
end
|
136
|
+
|
137
|
+
# default values from fields
|
138
|
+
@fields.each do |name, f|
|
139
|
+
next if @data.has_key? name
|
140
|
+
|
141
|
+
@data[name] = field_def_value name
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
####
|
149
|
+
# order
|
150
|
+
####
|
151
|
+
|
152
|
+
def order
|
153
|
+
return @order unless @order.nil?
|
154
|
+
|
155
|
+
# from session
|
156
|
+
@v_sess = session_get 'order', nil
|
157
|
+
@order = @v_sess unless @v_sess.nil?
|
158
|
+
|
159
|
+
#
|
160
|
+
@order ||= []
|
161
|
+
|
162
|
+
session_save 'order', @order
|
163
|
+
|
164
|
+
#
|
165
|
+
@order
|
166
|
+
end
|
167
|
+
|
168
|
+
def order= (value)
|
169
|
+
@order = value
|
170
|
+
|
171
|
+
session_save 'order', @order
|
172
|
+
end
|
173
|
+
|
174
|
+
def set_order_default(order_by, order_dir)
|
175
|
+
return false if !order.nil? && !order.empty?
|
176
|
+
|
177
|
+
set_order(order_by, order_dir)
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
def set_order(order_by, order_dir)
|
183
|
+
self.order = [[order_by, order_dir]]
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_order
|
187
|
+
order[0] if order.count>0
|
188
|
+
order[0]
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
def get_opposite_order_dir_for_column(name)
|
193
|
+
return 'asc' if order.empty?
|
194
|
+
|
195
|
+
|
196
|
+
if order[0][0] == name
|
197
|
+
return opposite_order_dir(order[0][1])
|
198
|
+
end
|
199
|
+
|
200
|
+
return 'asc'
|
201
|
+
end
|
202
|
+
|
203
|
+
def opposite_order_dir(order_dir)
|
204
|
+
return 'asc' if order_dir=='desc'
|
205
|
+
return 'desc' if order_dir=='asc'
|
206
|
+
'asc'
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
#helper methods
|
212
|
+
|
213
|
+
def html_style(name)
|
214
|
+
return '' unless @fields[name].has_key?(:opt)
|
215
|
+
|
216
|
+
s = ''
|
217
|
+
opt = @fields[name][:opt]
|
218
|
+
unless opt[:width].nil?
|
219
|
+
s << "width: #{opt[:width]}px; "
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/lib/optimacms/version.rb
CHANGED