Class: Kaui::CustomFieldsController
- Inherits:
-
EngineController
- Object
- ApplicationController
- EngineController
- Kaui::CustomFieldsController
- Defined in:
- app/controllers/kaui/custom_fields_controller.rb
Constant Summary
Constants included from EngineControllerUtil
EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD
Instance Method Summary collapse
Methods inherited from EngineController
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user
Instance Method Details
#create ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/kaui/custom_fields_controller.rb', line 44 def create @custom_field = Kaui::CustomField.new(params.require(:custom_field)) model = case @custom_field.object_type.to_sym when :ACCOUNT Kaui::Account.new(:account_id => @custom_field.object_id) when :BUNDLE Kaui::Bundle.new(:bundle_id => @custom_field.object_id) when :SUBSCRIPTION Kaui::Subscription.new(:subscription_id => @custom_field.object_id) when :INVOICE Kaui::Invoice.new(:invoice_id => @custom_field.object_id) when :PAYMENT Kaui::Payment.new(:payment_id => @custom_field.object_id) when :INVOICE_ITEM Kaui::InvoiceItem.new(:invoice_item_id => @custom_field.object_id) else flash.now[:error] = "Invalid object type #{@custom_field.object_type}" render :new and return end model.add_custom_field(@custom_field, current_user.kb_username, params[:reason], params[:comment], ) redirect_to custom_fields_path, :notice => 'Custom field was successfully created' end |
#index ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/controllers/kaui/custom_fields_controller.rb', line 3 def index @search_query = params[:q] @ordering = params[:ordering] || (@search_query.blank? ? 'desc' : 'asc') @offset = params[:offset] || 0 @limit = params[:limit] || 50 @max_nb_records = @search_query.blank? ? Kaui::CustomField.list_or_search(nil, 0, 0, ).pagination_max_nb_records : 0 end |
#new ⇒ Object
40 41 42 |
# File 'app/controllers/kaui/custom_fields_controller.rb', line 40 def new @custom_field = Kaui::CustomField.new end |
#pagination ⇒ Object
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 |
# File 'app/controllers/kaui/custom_fields_controller.rb', line 13 def pagination searcher = lambda do |search_key, offset, limit| Kaui::CustomField.list_or_search(search_key, offset, limit, ) end data_extractor = lambda do |custom_field, column| [ custom_field.object_id, custom_field.object_type, custom_field.name, custom_field.value ][column] end formatter = lambda do |custom_field| url_for_object = view_context.url_for_object(custom_field.object_id, custom_field.object_type) [ url_for_object ? view_context.link_to(custom_field.object_id, url_for_object) : custom_field.object_id, custom_field.object_type, custom_field.name, custom_field.value ] end paginate searcher, data_extractor, formatter end |