Module: Netzke::Form::Services

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/netzke/form/services.rb

Instance Method Summary collapse

Instance Method Details

#submit(data, client) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/netzke/form/services.rb', line 6

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

  success = create_or_update_record(data)

  if success
    client.netzke_set_form_values(js_record_data)
    client.success = true # respond to classic form submission with {success: true}
    client.netzke_on_submit_success # inform the Netzke endpoint caller about success
  else
    errors = model_adapter.errors_array(@record).map do |error|
      {level: :error, msg: error}
    end
    client.netzke_display_form_errors(errors)
    client.netzke_apply_form_errors(build_form_errors(record))
  end
end

#valuesObject



27
28
29
# File 'lib/netzke/form/services.rb', line 27

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