| Module | Flvorful::SuperInplaceControls::HelperMethods |
| In: |
vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb
|
These methods are mixed into the view as helpers. Common options for the helpers:
:action - the action to submit the change to
:saving_text - text to show while the request is processing. Default is "Saving..."
:object - the object to create the control for, if other than an instance variable. (Useful for iterations.)
:display_text - the text to be display before the update. Used when you want to use an
in_place control for an association field. Defaults to method
:br - add a <br /> tag after the field and before the submit tag. Defaults to
false/nil
Creates an "active" collection of checkbox controls that submits any changes to the server using an in_place_edit-style action. Extra Options:
:choices - (required) An array of choices (see method "select")
By default the value of the object‘s attribute will be selected, or blank. Example:
<%= in_place_check_box_collection :product, :category_ids, :choices => Category.find(:all).map { |e| [e.id, e.title] } %>
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 219
219: def in_place_check_box_collection(object, method, options = {})
220: check_for_choices(options)
221: options[:display_text] = :collection
222: in_place_field(:check_box, object, method, options)
223: end
Creates an "active" date select control that submits any changes to the server using an in_place_edit-style action. Extra Options:
:time - Allows users to select the Time as well as the date. Defaults to false.
By default the value of the object‘s attribute will be selected, or blank. Example:
<%= in_place_date_select :product, :display_begin_date %>
Note*: If you are using jQuery, you must have jquery-ui installed for the datepicker
to function properly. Otherwise, nothing will happen.
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 177
177: def in_place_date_select(object, method, options = {})
178: options[:time] ||= false
179: in_place_field(:date_select, object, method, options)
180: end
Creates an "active" collection of radio controls that submits any changes to the server using an in_place_edit-style action. Extra Options:
:choices - (required) An array of choices (see method "select") :columns - breaks up the collection into :columns number of columns
By default the value of the object‘s attribute will be selected, or blank. Example:
<%= in_place_radio_collection :product, :price, :choices => %w(199 299 399 499 599 699 799 899 999).map { |e| [e, e] } %>
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 233
233: def in_place_radio_collection(object, method, options = {})
234: check_for_choices(options)
235: in_place_field(:radio, object, method, options)
236: end
Creates an "active" select box control that submits any changes to the server using an in_place_edit-style action. Extra Options:
:choices - (required) An array of choices (see method "select")
By default the value of the object‘s attribute will be selected, or blank. Example:
<%= in_place_select :employee, :manager_id, :choices => Manager.find_all.map { |e| [e.name, e.id] } %>
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 189
189: def in_place_select(object, method, options = {})
190: check_for_choices(options)
191: in_place_field(:select, object, method, options)
192: end
Creates an "active" text area control that submits any changes to the server using an in_place_edit-style action. By default the value of the object‘s attribute will be filled in or blank. Example:
<%= in_place_text_area :product, :description %>
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 208
208: def in_place_text_area(object, method, options = {})
209: in_place_field(:text_area, object, method, options)
210: end
Creates an "active" text field control that submits any changes to the server using an in_place_edit-style action. By default the value of the object‘s attribute will be filled in or blank. Example:
<%= in_place_text_field :product, :title %>
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 199
199: def in_place_text_field(object, method, options = {})
200: in_place_field(:text_field, object, method, options)
201: end
Creates an div container for error_messages
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 239
239: def inplace_error_div(div_id = "error_messages", div_class = "error_messages")
240: content_tag(:div, "", :id => div_id, :class => div_class, :style => "display:none")
241: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 244
244: def jquery_calendar_picker( object_name, method_name, options )
245: ret = text_field(object_name, method_name, options )
246: ret << javascript_tag do
247: update_page do |page|
248: page << "if (jQuery.isFunction(jQuery.fn.datepicker)) { jQuery('.inplace_date_select').datepicker() }"
249: end
250: end
251: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 261
261: def check_for_choices(options)
262: raise ArgumentError, "Missing choices for select! Specify options[:choices] for in_place_select" if options[:choices].nil?
263: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 341
341: def field_for_inplace_editing(object_name, method_name, object, options , input_type)
342: options[:class] = "inplace_#{input_type}"
343: htm_opts = {:class => options[:class] }
344: case input_type
345: when :text_field
346: text_field(object_name, method_name, options )
347: when :text_area
348: text_area(object_name, method_name, options )
349: when :select
350: select(object_name, method_name, options[:choices], options, htm_opts )
351: when :check_box
352: options[:label_class] = "inplace_#{input_type}_label"
353: checkbox_collection(object_name, method_name, object, options[:choices], options )
354: when :radio
355: options[:label_class] = "inplace_#{input_type}_label"
356: radio_collection(object_name, method_name, object, options[:choices], options )
357: when :date_select
358: jquery_enabled? ?
359: jquery_calendar_picker( object_name, method_name, options ) :
360: calendar_date_select( object_name, method_name, options)
361: end
362: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 312
312: def form_for_inplace_display(object_name, method_name, input_type, object, opts)
313: retval = ""
314: id_string = id_string_for(object_name, method_name, object)
315: set_method = opts[:action] || "set_#{object_name}_#{method_name}"
316: save_button_text = opts[:save_button_text] || "OK"
317: loader_message = opts[:saving_text] || "Saving..."
318: retval << form_remote_tag(:url => { :action => set_method, :id => object.id },
319: :method => opts[:http_method] || :post,
320: :loading => update_page do |page|
321: page.show "loader_#{id_string}"
322: page.hide "#{id_string}_form"
323: end,
324: :complete => update_page do |page|
325: page.hide "loader_#{id_string}"
326: end,
327: :html => {:class => "in_place_editor_form", :id => "#{id_string}_form", :style => "display:none" } )
328:
329: retval << field_for_inplace_editing(object_name, method_name, object, opts, input_type )
330: retval << content_tag(:br) if opts[:br]
331: retval << submit_tag( save_button_text, :class => "inplace_submit")
332: retval << link_to_function( "Cancel", update_page do |page|
333: page.show "#{id_string}"
334: page.hide "#{id_string}_form"
335: end, {:class => "inplace_cancel" })
336: retval << "</form>"
337: retval << invisible_loader( loader_message, "loader_#{id_string}", "inplace_loader")
338: retval << content_tag(:br)
339: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 296
296: def html_for_inplace_display(object_name, method_name, object, display_text)
297: id_string = id_string_for(object_name, method_name, object)
298: content_tag(:span, display_text,
299: :onclick => update_page do |page|
300: page.hide "#{id_string}"
301: page.show "#{id_string }_form"
302: end,
303: :onmouseover => visual_effect(:highlight, id_string),
304: :title => "Click to Edit",
305: :id => id_string ,
306: :class => "inplace_span #{"empty_inplace" if display_text.blank?}"
307: )
308:
309:
310: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 292
292: def id_string_for(object_name, method_name, object)
293: "#{object_name}_#{method_name}_#{object.id}"
294: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 265
265: def in_place_field(field_type, object, method, options)
266: object_name = object.to_s
267: method_name = method.to_s
268: @object = self.instance_variable_get("@#{object}") || options[:object]
269: display_text = set_display_text(@object, method_name, options)
270: ret = html_for_inplace_display(object_name, method_name, @object, display_text)
271: ret << form_for_inplace_display(object_name, method_name, field_type, @object, options)
272: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 256
256: def jquery_enabled?
257: ActionView::Helpers::PrototypeHelper.const_defined?("JQUERY_VAR")
258: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 274
274: def set_blank_text(text, number_of_spaces = 7)
275: blank = " " * number_of_spaces
276: text = blank if text.blank?
277: text
278: end
# File vendor/plugins/super_inplace_controls/lib/super_inplace_controls.rb, line 280
280: def set_display_text(object, attribute, options)
281: display_text = ""
282: if options[:display_text] == :collection
283: display_text = object.send(attribute.to_s.gsub("_ids", "").pluralize).map do |e|
284: e.title || e.name
285: end.join(", ")
286: else
287: display_text = options[:display_text] || object.send(attribute)
288: end
289: h display_text
290: end