Sha256: b6b75a8970cdd8e79cde9c6fd1bb9150a310959134466bed005299626750de57

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

class NetzkeFormPanelField < ActiveRecord::Base
  belongs_to :layout, :class_name => "NetzkeLayout"
  
  acts_as_list :scope => :layout

  validate :valid_ext_config
  
  expose_columns :id, 
    :name,
    :field_label,
    :hidden,
    {:name => :disabled, :renderer => "checkbox"},
    :xtype,
    :ext_config


  def self.create_layout_for_widget(widget)
    layout = NetzkeLayout.create_with_user(:widget_name => widget.id_name, :items_class => self.name)

    columns = widget.default_db_fields

    for c in columns
      config_for_create = c.merge(:layout_id => layout.id).stringify_values!
      new_field = self.new
      ext_config = {}
      for k in config_for_create.keys
        if new_field.respond_to?("#{k}=")
          new_field.send("#{k}=", config_for_create[k]) 
        else
          ext_config[k] = config_for_create[k]
        end
      end
      new_field.ext_config = ext_config.to_js
      new_field.save!
    end
    
    layout
  end
  
  private
  
  def valid_ext_config
    begin
      ActiveSupport::JSON.decode(ext_config)
    rescue
      errors.add(:ext_config, "is not valid JSON")
    end
  end
  
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
netzke-basepack-0.3.10 lib/app/models/netzke_form_panel_field.rb
netzke-basepack-0.3.7 lib/app/models/netzke_form_panel_field.rb
netzke-basepack-0.3.8 lib/app/models/netzke_form_panel_field.rb
netzke-basepack-0.3.9 lib/app/models/netzke_form_panel_field.rb
netzke-basepack-0.3.9.1 lib/app/models/netzke_form_panel_field.rb