Sha256: 200131bfbc5797a27eeb679a9e01dd6235171249cd3c47bbc1855b50b2f9d67f

Contents?: true

Size: 1.18 KB

Versions: 12

Compression:

Stored size: 1.18 KB

Contents

module Netzke
  # GUI for Preference class
  class PreferenceGrid < PropertyGrid
    def initialize(*args)
      super
      config[:default_properties] ||= []
      NetzkePreference.custom_field = config[:host_widget_name]
      
      # Create default properties
      config[:default_properties].each do |p|
        NetzkePreference[p[:name]] = p[:value] if NetzkePreference[p[:name]].nil?
      end
    end
    
    def load_source(params = {})
      # config[:data_class_name] = 'NetzkePreference'
      config[:conditions] ||= {}
      
      data_class = NetzkePreference
      records = data_class.find(:all, :conditions => {:custom_field => config[:host_widget_name]})
      
      NetzkePreference.custom_field = config[:host_widget_name]
      
      source = {}
      records.each do |r|
        source.merge!(r.name => NetzkePreference[r.name])
      end
      
      {:source => source}
    end
    
    def submit_source(params = {})
      data = JSON.parse(params[:data])
      NetzkePreference.custom_field = config[:host_widget_name]
      data.each_pair do |k,v|
        NetzkePreference[k.underscore] = v
      end
      
      {:success => true, :flash => @flash}
    end
    
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
skozlov-netzke-basepack-0.1.0.1 lib/netzke/preference_grid.rb
skozlov-netzke-basepack-0.1.0 lib/netzke/preference_grid.rb
skozlov-netzke-basepack-0.1.1.1 lib/netzke/preference_grid.rb
skozlov-netzke-basepack-0.1.1.2 lib/netzke/preference_grid.rb
skozlov-netzke-basepack-0.1.1 lib/netzke/preference_grid.rb
skozlov-netzke_basepack-0.1.0 lib/netzke/preference_grid.rb
skozlov-netzke_core-0.1.0 lib/netzke/preference_grid.rb
netzke-basepack-0.1.2.1 lib/netzke/preference_grid.rb
netzke-basepack-0.1.4.1 lib/netzke/preference_grid.rb
netzke-basepack-0.1.3 lib/netzke/preference_grid.rb
netzke-basepack-0.1.2 lib/netzke/preference_grid.rb
netzke-basepack-0.1.3.1 lib/netzke/preference_grid.rb