Module: ActionView::Helpers::JavaScriptMacrosHelper

Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_scaffold_in_place_editor_js(field_id, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 40

def active_scaffold_in_place_editor_js(field_id, options = {})
  function =  "new Ajax.InPlaceEditor("
  function << "'#{field_id}', "
  function << "'#{url_for(options[:url])}'"

  js_options = {}
  js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]
  js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]
  js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]
  js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text]
  js_options['rows'] = options[:rows] if options[:rows]
  js_options['htmlResponse'] = options[:html_response] if options.has_key?(:html_response)
  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['evalScripts'] = options[:script] if options[:script]
  js_options['callback']   = "function(form) { return #{options[:with]} }" if options[:with]
  js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]
  function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
  
  function << ')'

  javascript_tag(function)
end

#active_scaffold_inplace_edit_2(record, column, options = {}) ⇒ Object

Allow in_place_editor to pass along nested information so the update_column can call refresh_record properly.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 84

def active_scaffold_inplace_edit_2(record, column, options = {})
  formatted_column = options[:formatted_column] || format_inplace_edit_column(record, column)
  id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s}
  tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"}
  in_place_editor_options = {:url => {:controller => params_for[:controller], :action => "update_column", :eid => params[:eid], :parent_model => params[:parent_model], :column => column.name, :id => record.id.to_s},
   :click_to_edit_text => as_(:click_to_edit),
   :cancel_text => as_(:cancel),
   :loading_text => as_(:loading),
   :save_text => as_(:update),
   :saving_text => as_(:saving),
   :script => true}.merge(column.options)
  html =  html_for_inplace_display(formatted_column, tag_options[:id], in_place_editor_options)
  html << form_for_inplace_display(record, column, tag_options[:id], in_place_editor_options, options)
end

#check_for_choices(options) ⇒ Object

Raises:

  • (ArgumentError)


99
100
101
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 99

def check_for_choices(options)
  raise ArgumentError, "Missing choices for select! Specify options[:choices] for in_place_select" if options[:choices].nil?
end

#field_for_inplace_editing(record, options, column) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 134

def field_for_inplace_editing(record, options, column)
  input_type = column.list_ui
  options[:class] = "inplace_#{input_type}"
  htm_opts = {:class => options[:class] }
  case input_type
  when :textarea
    text_area_tag('value', record.send(column.name), options )
  when :select          
    select_tag('value', options_for_select(options.delete(:choices), record.send(column.name)), options.merge(htm_opts))
  # when :date_select
  #   calendar_date_select( :record, column.name, options)
  else
    text_field_tag('value', record.send(column.name), options)
  end
end

#form_for_inplace_display(record, column, id_string, in_place_editor_options, options) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 112

def form_for_inplace_display(record, column, id_string, in_place_editor_options, options)
  retval = ""
  in_place_editor_options[:url] ||= {}
  in_place_editor_options[:url][:action] ||= "set_record_#{column.name}"
  in_place_editor_options[:url][:id] ||= record.id
  loader_message = in_place_editor_options[:saving_text] || as_(:saving_)
  retval << form_remote_tag(:url => in_place_editor_options[:url],
    :method => in_place_editor_options[:http_method] || :post,
    :loading => "$('#{id_string}_form').hide(); $('loader_#{id_string}').show();",
    :complete => "$('loader_#{id_string}').hide();",
    :html => {:class => "in_place_editor_form", :id => "#{id_string}_form", :style => "display:none" } )

  retval << field_for_inplace_editing(record, options, column )
  retval << (:br) if in_place_editor_options[:br]
  retval << submit_tag(as_(:ok), :class => "inplace_submit")
  retval << link_to_function( "Cancel", "$('#{id_string}_form').hide();$('#{id_string}').show() ", {:class => "inplace_cancel" })
  retval << "</form>"
  # #FIXME 2008-01-14 (EJM) Level=0 - Use AS's spinner
  # retval << invisible_loader( loader_message, "loader_#{id_string}", "inplace_loader")
  retval << (:br)
end

#format_inplace_edit_column(record, column) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 31

def format_inplace_edit_column(record,column)
  value = record.send(column.name)
  if column.list_ui == :checkbox
    active_scaffold_column_checkbox(column, record)
  else
    clean_column_value(format_value(value))
  end
end

#html_for_inplace_display(display_text, id_string, in_place_editor_options) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 103

def html_for_inplace_display(display_text, id_string, in_place_editor_options)
  (:span, display_text,
    :onclick => "Element.hide(this);$('#{id_string}_form').show();", 
    :onmouseover => visual_effect(:highlight, id_string), 
    :title => in_place_editor_options[:click_to_edit_text], 
    :id => id_string,
    :class => "inplace_span")
end

#in_place_editor(field_id, options = {}) ⇒ Object

Fix html_escape issues with url_for.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/extensions/java_script_macros_helper.rb', line 5

def in_place_editor(field_id, options = {})
  function =  "new Ajax.InPlaceEditor("
  function << "'#{field_id}', "
  function << "'#{url_for(options[:url])}'".gsub("&amp;", "&")

  js_options = {}
  js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text]
  js_options['okText'] = %('#{options[:save_text]}') if options[:save_text]
  js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text]
  js_options['savingText'] = %('#{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['evalScripts'] = options[:script] if options[:script]
  js_options['callback']   = "function(form) { return #{options[:with]} }" if options[:with]
  js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text]
  function << (', ' + options_for_javascript(js_options)) unless js_options.empty?
  
  function << ')'

  javascript_tag(function)
end