Netzke::Basepack::FormPanel::Services

Public Instance Methods

configuration_panel__fields__get_combobox_options(params) click to toggle source

Overriding configuration_panel’s get_combobox_options endpoint call

    # File lib/netzke/basepack/form_panel/services.rb, line 35
35:         def configuration_panel__fields__get_combobox_options(params)
36:           query = params[:query]
37:           {:data => (default_columns.map{ |c| c[:name].to_s }).grep(/^#{query}/).map{ |n| [n] }}.to_nifty_json
38:         end
netzke_submit(params) click to toggle source

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

    # File lib/netzke/basepack/form_panel/services.rb, line 50
50:         def netzke_submit(params)
51:           data = ActiveSupport::JSON.decode(params[:data])
52:           success = create_or_update_record(data)
53: 
54:           if success
55:             {:set_form_values => values, :set_result => "ok"}
56:           else
57:             # flash eventual errors
58:             @record.errors.to_a.each do |msg|
59:               flash :error => msg
60:             end
61:             {:feedback => @flash}
62:           end
63:         end
values() click to toggle source

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

  @record && @record.to_array(fields)

end

    # File lib/netzke/basepack/form_panel/services.rb, line 45
45:         def values
46:           record && record.to_hash(fields)
47:         end

Private Instance Methods

create_or_update_record(hsh) click to toggle source

Creates/updates a record from hash

    # File lib/netzke/basepack/form_panel/services.rb, line 68
68:           def create_or_update_record(hsh)
69: 
70:             hsh.merge!(config[:strong_default_attrs]) if config[:strong_default_attrs]
71:             @record ||= data_class.find(:first, :conditions => {data_class.primary_key => hsh.delete(data_class.primary_key)}) # only pick up the record specified in the params if it was not provided in the configuration
72:             success = true
73: 
74:             @record = data_class.new if @record.nil?
75: 
76:             hsh.each_pair do |k,v|
77:               @record.set_value_for_attribute(fields[k.to_sym].nil? ? {:name => k} : fields[k.to_sym], v)
78:             end
79: 
80:             #hsh.each_pair do |k,v|
81:               #begin
82:                 #@record.send("#{k}=",v)
83:               #rescue StandardError => exc
84:                 #flash :error => exc.message
85:                 #success = false
86:                 #break
87:               #end
88:             #end
89: 
90:             # did we have complete success?
91:             success && @record.save
92:           end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.