Class: Adminpanel::AdminpanelFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/helpers/adminpanel/adminpanel_form_builder.rb

Instance Method Summary collapse

Instance Method Details

#append_field(name, *args) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 273

def append_field(name, *args)

	options = args.extract_options!

	options.reverse_merge! :label => name
	label = options['label']
	options.delete('label')

	options.reverse_merge! :symbol => "#"
	symbol = options[:symbol]
	options.delete(:symbol)

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(
			:div,
			@template.(
				:div,
				text_field_original(name, *args << options) +
				@template.(:span, symbol, :class => "add-on"),
				:class => "input-append"
			),
			:class => "controls"
		)
	end
end

#boolean(name, *args) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 135

def boolean(name, *args)
	options = args.extract_options!

	@template.(
		:div,
		@template.(
			:div,
			options['label'],
			:class => 'control-label') +
			@template.(
				:div,
				@template.(
					:label,
					check_box(
						name
					),
					:class => 'checkbox'
				),
				:class => 'controls'
			),
		:class => 'control-group'
	)
end

#checkbox(checkbox_object, form_object_name, relationship) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 123

def checkbox(checkbox_object, form_object_name, relationship)
	@template.(
		:label,
		@template.check_box_tag(
			"#{form_object_name}[#{relationship}][]",
			checkbox_object.id,
			self.object.send(relationship).include?(checkbox_object.id)
			) + checkbox_object.name,
		:class => "checkbox"
	)
end

#datepicker(name, *args) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 208

def datepicker(name, *args)

	options = args.extract_options!

	options.reverse_merge! :value => Time.now.strftime("%d-%m-%Y")
	options.reverse_merge! :label => name
	label = options['label']
	options.delete('label')

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(
			:div,
			@template.(
				:div,
				text_field_original(name, *args << options) +
				@template.(
					:span,
					@template.(
						:i,
						nil,
						:class => "icon-th"
					),
					:class => "add-on"
				),
				{
					:class => "input-append date span5 datepicker datepicker-basic",
					:data => {
						:date_format => "dd-mm-yyyy",
						:date => options[:value]
					}
				}
			),
			:class => "controls"
		)
	end
end

#file_field(name, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 22

def file_field(name, *args)
	options = args.extract_options!
	label = options['label']
	options.delete('label')


	image = @template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(:div, super(name, *args << options), :class => "controls")
	end

	if object.nil? || object.new_record?
		image
	else
		thumbnail = @template. :div, :class => 'control-group' do
			@template. :div, :class => 'controls' do
				@template.image_tag object.send("#{name}_url", :thumb)
			end
		end

		"#{thumbnail}#{image}".html_safe
	end
end


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 46

def gallery_field(name, *args)
	options = args.extract_options!
	label = options['label']
	options.delete('label')

	@template. :div, :class => "control-group" do
		label = @template.(:label, label, :class => "control-label")
		input = @template. :div, :class => "controls" do
			input = parent_file_field(name, *args << options)
			hidden_input = hidden_field(:_destroy)
			delete_button = @template.(:button, I18n.t("action.delete"), :class => "btn btn-danger remove_fields")

			if object.nil? || object.new_record?
				"#{input}#{hidden_input}#{delete_button}".html_safe
			else
				thumbnail = @template. :div, :class => 'control-group' do
					@template.image_tag object.send("#{name}_url", :thumb)
				end

				"#{thumbnail}#{input}#{hidden_input}#{delete_button}".html_safe
			end
		end
		"#{label}#{input}".html_safe
	end
end

#number_field(name, *args) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 174

def number_field(name, *args)
	options = args.extract_options!

	options.reverse_merge! :class => "span5"
	options.reverse_merge! :label => name
	label = options['label']
	options.delete('label')

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(:div, super(name, *args << options), :class => "controls")
	end
end

#parent_file_fieldObject



6
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 6

alias_method :parent_file_field, :file_field

#password_field(name, *args) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 188

def password_field(name, *args)
	options = args.extract_options!

	options.reverse_merge! :class => "span7"
	label = options['label']
	options.delete('label')

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(:div, super(name, *args << options), :class => "controls")
	end
end

#prepend_field(name, *args) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 246

def prepend_field(name, *args)

	options = args.extract_options!

	options.reverse_merge! :label => name
	label = options['label']
	options.delete('label')

	options.reverse_merge! :symbol => "#"
	symbol = options[:symbol]
	options.delete(:symbol)

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(
			:div,
			@template.(
				:div,
				@template.(:span, symbol, :class => "add-on") +
				text_field_original(name, *args << options),
				:class => "input-prepend"
			),
			:class => "controls"
		)
	end
end

#radio_button_group(name, buttons, options) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 108

def radio_button_group(name, buttons, options)
	options.reverse_merge! :label => name
	options.reverse_merge! :html => {}
	output = ""

	buttons.each do |b|
		output += @template.(:label, radio_button_original(name, b, options[:html]) + b.capitalize, :class => "radio")
	end

	@template. :div, :class => "control-group" do
		@template.(:label, options[:label], :class => "control-label") +
		@template.(:div, output, { :class => "controls"}, false)
	end
end

#select(name, select_options, *args) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 159

def select(name, select_options, *args)
	options = args.extract_options!
	label = options['label']
	options.delete('label')

	options.reverse_merge! :class => "span7"

	options.reverse_merge! :include_blank => "(Seleccione por favor)";

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(:div, super(name, select_options, *args << options), :class => "controls")
	end
end

#submit(name, *args) ⇒ Object



201
202
203
204
205
206
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 201

def submit(name, *args)
	options = args.extract_options!

	options.reverse_merge! :class => "btn btn-primary"
	super(name, *args << options)
end

#text_area(name, *args) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 90

def text_area(name, *args)
	options = args.extract_options!
	label = options['label']
	options.delete('label')

	@template.(:div, :class => 'control-group') do
		@template.(:label, label, :class => 'control-label') +
		@template.(:div, :class => 'controls') do
			super(
				name,
				class: 'span10',
				placeholder: I18n.t('wysiwyg.description'),
				rows: '4'
			)
		end
	end
end

#text_area_originalObject



7
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 7

alias_method :text_area_original, :text_area

#text_field(name, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 9

def text_field(name, *args)
	options = args.extract_options!

	options.reverse_merge! :class => "span7"
	label = options['label']
	options.delete('label')

	@template. :div, :class => "control-group" do
		@template.(:label, label, :class => "control-label") +
		@template.(:div, super(name, *args << options), :class => "controls")
	end
end

#text_field_originalObject



4
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 4

alias_method :text_field_original, :text_field

#wysiwyg_field(name, *args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/helpers/adminpanel/adminpanel_form_builder.rb', line 72

def wysiwyg_field(name, *args)
	options = args.extract_options!
	label = options['label']
	options.delete('label')

	@template.(:div, :class => 'control-group') do
		@template.(:label, label, :class => 'control-label') +
		@template.(:div, :class => 'controls') do
			text_area_original(
				name,
				class: 'wysihtml5 span10',
				placeholder: I18n.t('wysiwyg.description'),
				rows: '6'
			)
		end
	end
end