Class: ErpApp::Desktop::ConfigurationManagement::OptionsController

Inherits:
BaseController show all
Defined in:
app/controllers/erp_app/desktop/configuration_management/options_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_or_updateObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/erp_app/desktop/configuration_management/options_controller.rb', line 31

def create_or_update
  option = params[:model_id].blank? ? ConfigurationOption.new : ConfigurationOption.find(params[:model_id])
  option.value = params[:value]
  option.internal_identifier = params[:internal_identifier]
  option.comment = params[:comment]
  option.description = params[:description]
  if option.save
    render :json => {:success => true}
  else
    render :json => {:success => false}
  end
end

#destroyObject



44
45
46
47
48
49
50
# File 'app/controllers/erp_app/desktop/configuration_management/options_controller.rb', line 44

def destroy
  if ConfigurationOption.destroy(params[:id])
    render :json => {:success => true}
  else
    render :json => {:success => false}
  end
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/erp_app/desktop/configuration_management/options_controller.rb', line 6

def index
  options_tbl = ConfigurationOption.arel_table
  arel_query = ConfigurationOption.where(options_tbl[:value].matches("%#{params[:query]}%")
    .or(options_tbl[:internal_identifier].matches("%#{params[:query]}%")))
    .where(options_tbl[:user_defined].eq(false))
    .limit(params[:limit])
    .offset(params[:start])
  options = arel_query.all

  respond_to do |format|
    format.json {
      render :json => {
        :success => true,
        :total_count => options.count,
        :options => options.collect{|option|option.to_hash(:only => [:id, :description, :comment, :value, :internal_identifier])}}
    }
    format.tree {
      render :json => options.collect{|option| option.to_hash(:only => [:internal_identifier, :value, :comment, :description],
                                      :methods => [{:description => :text}, {:id => :model_id}],
                                      :additional_values => {:iconCls => 'icon-document', :leaf => true, :children => []})}
    }
  end

end