Class: ErpApp::Desktop::SystemManagement::TypesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- ErpApp::Desktop::SystemManagement::TypesController
- Defined in:
- app/controllers/erp_app/desktop/system_management/types_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/erp_app/desktop/system_management/types_controller.rb', line 61 def create begin ActiveRecord::Base.transaction do record = params[:klass].constantize.new(description: params[:description].strip, internal_identifier: params[:internal_identifier].strip) record.save! if params[:parent_id].present? record.move_to_child_of(params[:klass].constantize.find(params[:parent_id])) end render json: {success: true, type: { server_id: record.id, description: record.description, internal_identifier: record.internal_identifier, klass: params[:klass] }} end rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") # email error ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier render json: {success: false, message: 'Application Error'} end end |
#destroy ⇒ Object
117 118 119 120 121 |
# File 'app/controllers/erp_app/desktop/system_management/types_controller.rb', line 117 def destroy params[:klass].constantize.find(params[:id]).destroy render json: {success: true} end |
#index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/erp_app/desktop/system_management/types_controller.rb', line 6 def index types = [] if params[:klass].present? and params[:parent_id].present? compass_ae_type = params[:klass].constantize.find(params[:parent_id]) compass_ae_type.children.each do |compass_ae_type_child| types.push({ server_id: compass_ae_type_child.id, description: compass_ae_type_child.description, internal_identifier: compass_ae_type_child.internal_identifier, klass: params[:klass] }) end elsif params[:klass].present? compass_ae_type = params[:klass].constantize if compass_ae_type.respond_to?(:roots) compass_ae_type.roots.each do |record| types.push({ server_id: record.id, description: record.description, internal_identifier: record.internal_identifier, klass: params[:klass] }) end else compass_ae_type.all.each do |record| types.push({ server_id: record.id, description: record.description, internal_identifier: record.internal_identifier, klass: params[:klass], leaf: true }) end end else compass_ae_types = ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsErpType.models types = compass_ae_types.collect do |compass_ae_type| { description: compass_ae_type.to_s, klass: compass_ae_type.to_s, leaf: false } end end render json: {success: true, types: types} end |
#update ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/erp_app/desktop/system_management/types_controller.rb', line 90 def update record = params[:klass].constantize.find(params[:id]) begin ActiveRecord::Base.transaction do record.description = params[:description].strip record.internal_identifier = params[:internal_identifier].strip record.save! render json: {success: true, type: { server_id: record.id, description: record.description, internal_identifier: record.internal_identifier, klass: params[:klass] }} end rescue => ex Rails.logger.error ex. Rails.logger.error ex.backtrace.join("\n") # email error ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier render json: {success: false, message: 'Application Error'} end end |