Module: Netzke::Basepack::FormPanel::Services

Extended by:
ActiveSupport::Concern
Defined in:
lib/netzke/basepack/form_panel/services.rb

Instance Method Summary collapse

Instance Method Details

#configuration_panel__fields__get_combobox_options(params) ⇒ Object

Overriding configuration_panel’s get_combobox_options endpoint call



38
39
40
41
# File 'lib/netzke/basepack/form_panel/services.rb', line 38

def configuration_panel__fields__get_combobox_options(params)
  query = params[:query]
  {:data => (default_columns.map{ |c| c[:name].to_s }).grep(/^#{query}/).map{ |n| [n] }}.to_nifty_json
end

#netzke_submit(params) ⇒ Object

Implementation for the “netzke_submit” endpoint (for backward compatibility)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/netzke/basepack/form_panel/services.rb', line 53

def netzke_submit(params)
  data = ActiveSupport::JSON.decode(params[:data])
  data.each_pair do |k,v|
    data[k]=nil if v.blank? || v == "null" # Ext JS returns "null" on empty date fields, or "" for not filled optional integer fields, which gives errors when passed to model (at least in DataMapper)
  end

  # File uploads are in raw params instead of "data" hash, so, mix them in into "data"
  if config[:file_upload]
    Netzke::Core.controller.params.each_pair do |k,v|
      data[k] = v if v.is_a?(ActionDispatch::Http::UploadedFile)
    end
  end

  success = create_or_update_record(data)

  if success
    {:set_form_values => js_record_data, :set_result => true}
  else
    # flash eventual errors
    data_adapter.errors_array(@record).each do |error|
      flash :error => error
    end
    {:netzke_feedback => @flash, :apply_form_errors => build_form_errors(record)}
  end
end

#valuesObject

Returns array of form values according to the configured columns def array_of_values

@record && @record.netzke_array(fields)

end



48
49
50
# File 'lib/netzke/basepack/form_panel/services.rb', line 48

def values
  record && record.netzke_hash(fields)
end