lib/netzke/basepack/grid_panel/services.rb in netzke-basepack-0.6.1 vs lib/netzke/basepack/grid_panel/services.rb in netzke-basepack-0.6.2

- old
+ new

@@ -8,19 +8,12 @@ module Services extend ActiveSupport::Concern included do - endpoint :get_data do |*args| - params = args.first || {} # params are optional - if !config[:prohibit_read] - records = get_records(params) - {:data => records.map{|r| r.to_array(columns)}, :total => config[:enable_pagination] && records.total_entries} - else - flash :error => "You don't have permissions to read data" - {:feedback => @flash} - end + endpoint :get_data do |params| + get_data(params) end endpoint :post_data do |params| mod_records = {} [:create, :update].each do |operation| @@ -151,12 +144,24 @@ {:feedback => @flash}.to_nifty_json end end # When providing the edit_form component, fill in the form with the requested record - def deliver_component(params) + def deliver_component_endpoint(params) components[:edit_form][:items].first.merge!(:record_id => params[:record_id].to_i) if params[:name] == 'edit_form' super + end + + # Implementation for the "get_data" endpoint + def get_data(*args) + params = args.first || {} # params are optional! + if !config[:prohibit_read] + records = get_records(params) + {:data => records.map{|r| r.to_array(columns)}, :total => config[:enable_pagination] && records.total_entries} + else + flash :error => "You don't have permissions to read data" + {:feedback => @flash} + end end protected def get_records(params)