Class: ErpForms::ErpApp::Desktop::DynamicForms::ModelsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

create a dynamic form model


41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb', line 41

def create
  DynamicFormModel.create({
    :model_name => params[:model_name],
    :allow_comments => params[:allow_comments],
    :allow_files => params[:allow_files],
    :file_security_default => params[:file_security_default]
  })
	
  render :json => {:success => true}
end

#deleteObject

delete a dynamic form model


34
35
36
37
38
# File 'app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb', line 34

def delete
  DynamicFormModel.destroy(params[:id])
	
  render :json => {:success => true}
end

#indexObject

get dynamic form models used in dynamic forms widget combo box


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb', line 5

def index
  models = []
  dynamic_form_models = DynamicFormModel.where("model_name != 'DynamicFormDocument'").order('model_name ASC')
  dynamic_form_models.each do |m|
    model_hash = {
      :id => m.id,
      :model_name => m.model_name,
      :file_security_default => m.file_security_default,
      :show_in_multitask => m.show_in_multitask
    }
    
    models << model_hash
  end
  
  render :json => models
end

#set_default_formObject

set default form for this model


23
24
25
26
27
28
29
30
31
# File 'app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb', line 23

def set_default_form
  myDynamicObject = DynamicFormModel.get_constant(params[:model_name])    
  myDynamicObject.set_default(params[:id])
	
  # update solr config for model
  DynamicFormModel.get_constant(params[:model_name]).sunspot_setup if ErpForms.use_solr?

  render :json => {:success => true}
end

#updateObject

update a dynamic form model


53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/erp_forms/erp_app/desktop/dynamic_forms/models_controller.rb', line 53

def update
  m = DynamicFormModel.find(params[:id])
  m.allow_comments = params[:allow_comments] unless params[:allow_comments].nil?
  m.allow_files = params[:allow_files] unless params[:allow_files].nil?
  m.file_security_default = params[:file_security_default] unless params[:file_security_default].blank?
  m.show_in_multitask = params[:show_in_multitask] unless params[:show_in_multitask].nil?
  m.save
  
  render :json => {:success => true}
end