module InPlaceMacrosHelper

OpenIrekia v4.0.0

Copyright 2009-2013 eFaber, S.L. Copyright 2009-2013 Ejie, S.A. Copyrigth 2009-2013 Dirección de Gobierno Abierto y Comunicación en Internet;

Gobernu Irekirako eta Interneteko Komunikaziorako Zuzendaritza; Lehendakaritza.
Gobierno Vasco – Eusko Jaurlaritza

Licencia con arreglo a la EUPL, Versión 1.1 o –en cuanto sean aprobadas por la Comisión Europea– versiones posteriores de la EUPL (la Licencia); Solo podrá usarse esta obra si se respeta la Licencia. Puede obtenerse una copia de la Licencia en: ec.europa.eu/idabc/eupl Salvo cuando lo exija la legislación aplicable o se acuerde por escrito, el programa distribuido con arreglo a la Licencia se distribuye TAL CUAL, SIN GARANTÍAS NI CONDICIONES DE NINGÚN TIPO, ni expresas ni implícitas. Véase la Licencia en el idioma concreto que rige los permisos y limitaciones que establece la Licencia

http://open.irekia.net, openirekia@efaber.net

Public Instance Methods

in_place_editor_field_with_auto_complete(object, method, tag_options = {}, in_place_editor_options = {}, completion_options = {}) click to toggle source

Renders the value of the specified object and method with in-place and autocomplete editing capabilities.

# File lib/in_place_with_auto_complete.rb, line 65
def in_place_editor_field_with_auto_complete(object, method, tag_options = {}, in_place_editor_options = {}, completion_options = {})
  tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)
  tag_options = {:nil_content_replacement => "--", :tag => "span", :id => "#{object}_#{method}_#{tag.object.id}_in_place_editor", :class => "in_place_editor_field"}.merge!(tag_options)

  value = tag.value(tag.object)
  if (value.blank?)
    value = tag_options.delete(:nil_content_replacement)
  end
  
  in_place_editor_options[:url] = in_place_editor_options[:url] || url_for({ :action => "set_#{object}_#{method}", :id => tag.object.id })
  in_place_editor_options[:cancel_text] ||= 'cancelar'
  in_place_editor_options[:click_to_edit_text] ||= 'click para modificar'
  in_place_editor_options[:loading_text] ||= 'leyendo ...'
  in_place_editor_options[:saving_text] ||= 'guardando ...'
  
  completion_options = completion_options.merge({:input_id => "#{object}_#{method}", :autocompleter_url => url_for(:action => "auto_complete_for_#{object}_#{method}", :id => tag.object.id)})
  
  tag.content_tag(tag_options.delete(:tag), value, tag_options) + 
  content_tag("div", "", :id => "#{object}_#{method}_auto_complete", :class => "auto_complete") +
  in_place_editor_with_autocompleter(tag_options[:id], in_place_editor_options.merge(completion_options))
end
in_place_editor_with_autocompleter(field_id, options = {}) click to toggle source
# File lib/in_place_with_auto_complete.rb, line 24
def in_place_editor_with_autocompleter(field_id, options = {})
  function =  "new Ajax.InPlaceEditorWithAutocompleter("
  function << "'#{field_id}', "
  function << "'#{url_for(options[:url])}'"
  js_options = {}

  if protect_against_forgery?
    options[:with] ||= "Form.serialize(form)"
    options[:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')"
  end
  js_options['cancelText'] = %Q('#{options[:cancel_text]}') if options[:cancel_text]
  js_options['okText'] = %Q('#{options[:save_text]}') if options[:save_text]    
  js_options['loadingText'] = %Q('#{options[:loading_text]}') if options[:loading_text]
  js_options['savingText'] = %Q('#{options[:saving_text]}') if options[:saving_text]
  js_options['rows'] = options[:rows] if options[:rows]
  js_options['cols'] = options[:cols] if options[:cols]
  js_options['size'] = options[:size] if options[:size]
  js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control]
  js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url]       
 
  js_options['ajaxOptions'] = options[:options] if options[:options]
  js_options['htmlResponse'] = !options[:script] if options[:script]
  js_options['callback']   = "function(form) { return #{options[:with]} }" if options[:with]
  js_options['clickToEditText'] = %Q('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]
  js_options['textBetweenControls'] = %Q('#{options[:text_between_controls]}') if options[:text_between_controls]
  
  js_options['onComplete'] = "function(form) { return #{options[:complete]} }" if options[:complete]
  
  js_options['inputID'] = %Q('#{options[:input_id]}') if options[:input_id]
  js_options['autocompleterUrl'] = %Q('#{options[:autocompleter_url]}') if options[:autocompleter_url]
  js_options['indicator'] = %Q('#{options[:indicator]}') if options[:indicator]

  function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
  
  function << ')'
  
  javascript_tag(function)
end