Class: ErpApp::Desktop::ConfigurationManagement::BaseController

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

Instance Method Summary collapse

Methods inherited from BaseController

#index

Instance Method Details

#add_typeObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 6

def add_type
  configuration = ::Configuration.find(params[:configuration_id])
  type          = ConfigurationItemType.find(params[:type_id])

  render :json => if configuration.configuration_item_types << type
    {:success => true}
  else
    {:success => false}
  end
end

#configurable_modelsObject



60
61
62
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 60

def configurable_models
  render :json => {:success => true, :models => Website.all.collect{|site| {:description => site.name, :id => site.id}}}
end

#configuration_templatesObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 38

def configuration_templates
  configurations = [].tap do |configured_items|
    ::Configuration.templates.each do |config|
      configured_items << build_configuration_tree(config, false)
    end
  end

  render :json => configurations
end

#configuration_templates_storeObject



56
57
58
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 56

def configuration_templates_store
  render :json => {:success => true, :templates => ::Configuration.templates.collect{|template| {:description => template.description, :id => template.id}}}
end

#configurationsObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 28

def configurations
  configurations = [].tap do |configured_items|
    ::Configuration.where('is_template = ?', false).all.each do |config|
      configured_items << build_configuration_tree(config)
    end
  end

  render :json => configurations
end

#copy_templateObject



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 85

def copy_template
  template = ::Configuration.find(params[:template])
  clone    = template.clone
  clone.is_template = true
  clone.internal_identifier = params[:name].gsub(//,'').underscore
  clone.description = params[:name]

  if clone.save
    render :json => {:success => true}
  else
    render :json => {:success => false}
  end
end

#create_configurationObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 64

def create_configuration
  model = params[:type].constantize.find(params[:model])
  model.configurations.destroy_all
  configuration = ::Configuration.find(params[:template]).send(params[:configuration_action].to_sym)
  unless params[:name].blank?
    configuration.description = params[:name]
    configuration.save
  end
  model.configurations << configuration

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

#create_templateObject



77
78
79
80
81
82
83
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 77

def create_template
  if ::Configuration.create(:description => params[:name], :is_template => true, :internal_identifier => params[:name].gsub(//,'').underscore)
    render :json => {:success => true}
  else
    render :json => {:success => false}
  end
end

#destroyObject



48
49
50
51
52
53
54
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 48

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

#remove_typeObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/erp_app/desktop/configuration_management/base_controller.rb', line 17

def remove_type
  configuration = ::Configuration.find(params[:configuration_id])
  type          = ConfigurationItemType.find(params[:type_id])

  render :json => if configuration.configuration_item_types.delete(type)
    {:success => true}
  else
    {:success => false}
  end
end