Class: Widgets::Scaffold::Base

Inherits:
ErpApp::Widgets::Base
  • Object
show all
Defined in:
app/widgets/scaffold/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.titleObject



77
78
79
# File 'app/widgets/scaffold/base.rb', line 77

def title
  "CompassAE Scaffold"
end

.widget_nameObject



81
82
83
# File 'app/widgets/scaffold/base.rb', line 81

def widget_name
  File.basename(File.dirname(__FILE__))
end

Instance Method Details

#dataObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/widgets/scaffold/base.rb', line 33

def data
  active_ext_core = setup_active_ext_core

  json_text = nil

  if request.get?
    json_text = ActiveExt::ExtHelpers::DataHelper.build_json_data(active_ext_core, :limit => params[:limit], :offset => params[:start])
  elsif request.post?
    json_text = ActiveExt::ExtHelpers::DataHelper.create_record(active_ext_core, :data => params[:data])
  elsif request.put?
    json_text = ActiveExt::ExtHelpers::DataHelper.update_record(active_ext_core, :data => params[:data], :id => params[:data][:id])
  elsif request.delete?
    json_text = ActiveExt::ExtHelpers::DataHelper.delete_record(active_ext_core, :data => params[:data], :id => params[:data][:id])
  end

  render :inline => json_text
end

#indexObject



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/widgets/scaffold/base.rb', line 4

def index
  @model_name = params[:model_name]
  @title = params[:grid][:title] || params[:model].pluralize
  @width = params[:grid][:width] || '100%'
  @height = params[:grid][:height] || 500
  @page = params[:grid][:page] || true
  @page_size = params[:grid][:page_size] || 10
  @display_msg = params[:grid][:display_msg] || 'Displaying {0} - {1} of {2}'
  @empty_msg = params[:grid][:empty_msg] || 'Empty'
  @editable = params[:editable] || false

  render :view => :index
end

#locateObject

should not be modified modify at your own risk



72
73
74
# File 'app/widgets/scaffold/base.rb', line 72

def locate
  File.dirname(__FILE__)
end

#setupObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/widgets/scaffold/base.rb', line 18

def setup
  active_ext_core = setup_active_ext_core

  columns, fields, validations = ActiveExt::ExtHelpers::TableBuilder.generate_columns_and_fields(active_ext_core)
  result = {
      :success => true,
      :use_ext_forms => active_ext_core.options[:use_ext_forms].nil? ? false : active_ext_core.options[:use_ext_forms],
      :inline_edit => active_ext_core.options[:inline_edit].nil? ? false : active_ext_core.options[:inline_edit],
      :columns => columns,
      :fields => fields,
      :validations => validations
  }
  render :inline => result.to_json
end

#setup_active_ext_coreObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/widgets/scaffold/base.rb', line 51

def setup_active_ext_core
  model_id = session[:widgets][self.uuid][:model].pluralize.singularize
  options = {
      :inline_edit => true,
      :use_ext_forms => false,
      :ignore_associations => true,
      :show_id => true,
      :show_timestamps => true,
      :only => nil
  }

  #merge in passed widget options
  options.each do |key, value|
    options[key] = session[:widgets][self.uuid][key] unless session[:widgets][self.uuid][key].blank?
  end

  ActiveExt::Core.new(model_id,options)
end