Module: ActionWebService::Scaffolding::Helpers

Defined in:
lib/action_web_service/scaffolding.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#method_parameter_input_fields(method, type, field_name_base, idx, was_structured = false) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/action_web_service/scaffolding.rb', line 165

def method_parameter_input_fields(method, type, field_name_base, idx, was_structured=false)
  if type.array?
    return ('em', "Typed array input fields not supported yet (#{type.name})")
  end
  if type.structured?
    return ('em', "Nested structural types not supported yet (#{type.name})") if was_structured
    parameters = ""
    type.each_member do |member_name, member_type|
      label = method_parameter_label(member_name, member_type)
      nested_content = method_parameter_input_fields(
        method,
        member_type,
        "#{field_name_base}[#{idx}][#{member_name}]",
        idx,
        true)
      if member_type.custom?
        parameters << ('li', label)
        parameters << ('ul', nested_content.html_safe)
      else
        parameters << ('li', (label + ' ' + nested_content).html_safe)
      end
    end
    ('ul', parameters.html_safe)
  else
    # If the data source was structured previously we already have the index set          
    field_name_base = "#{field_name_base}[#{idx}]" unless was_structured
    
    case type.type
    when :int
      text_field_tag "#{field_name_base}"
    when :string
      text_field_tag "#{field_name_base}"
    when :base64
      text_area_tag "#{field_name_base}", nil, :size => "40x5"
    when :bool
      radio_button_tag("#{field_name_base}", "true") + " True" +
      radio_button_tag("#{field_name_base}", "false") + "False"
    when :float
      text_field_tag "#{field_name_base}"
    when :time, :datetime
      time = Time.now
      i = 0
      %w|year month day hour minute second|.map do |name|
        i += 1
        send("select_#{name}", time, :prefix => "#{field_name_base}[#{i}]", :discard_type => true)
      end.join
    when :date
      date = Date.today
      i = 0
      %w|year month day|.map do |name|
        i += 1
        send("select_#{name}", date, :prefix => "#{field_name_base}[#{i}]", :discard_type => true)
      end.join
    end
  end
end

#method_parameter_label(name, type) ⇒ Object



222
223
224
# File 'lib/action_web_service/scaffolding.rb', line 222

def method_parameter_label(name, type)
  name.to_s.capitalize + ' (' + type.human_name(false) + ')'
end

#service_method_list(service) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/action_web_service/scaffolding.rb', line 226

def service_method_list(service)
  action = @scaffold_action_name + '_method_params'
  methods = service.api_methods_full.sort {|a, b| a[1] <=> b[1]}.map do |desc, name|
    ("li", link_to(name, :action => action, :service => service.name, :method => name))
  end
  ("ul", methods.join("\n").html_safe)
end