module Dhatu class Dhatu::PromotionAttributesController < ResourceController private def save_resource @r_object.values = params[:values].split(",") if params[:values] if @r_object.valid? @r_object.save # get_collections if @resource_options[:layout] = :table set_flash_message(I18n.translate("forms.save", item: default_item_name.titleize), :success) end set_resource_notification(@r_object) action_name = params[:action].to_s == "create" ? "new" : "edit" url = @r_object.persisted? ? resource_url(@r_object) : nil render_or_redirect(@r_object.errors.any?, url, action_name) end def get_collections @promotion = @r_object.promotion @promotion_attributes = @promotion.promotion_attributes.page(@current_page).per(@per_page) return true end def apply_filters @relation = @relation.status(@status) if @status @relation = @relation.where("promotion_id = ?", @promotion.id) if @promotion @order_by = "priority ASC, name ASC" unless @order_by @relation = @relation.order(@order_by) end def resource_url(obj) url_for(obj) end def configure_filter_settings @filter_settings = { string_filters: [ { filter_name: :query }, { filter_name: :status } ], boolean_filters: [], reference_filters: [ { filter_name: :promotion, filter_class: Dhatu::Promotion } ], variable_filters: [], } end def configure_filter_ui_settings @filter_ui_settings = { status: { object_filter: false, select_label: "Select Data Type", display_hash: Dhatu::PromotionAttribute::DATA_TYPES, current_value: @data_type, values: Dhatu::PromotionAttribute::DATA_TYPES_REVERSE, current_filters: @filters, filters_to_remove: [], filters_to_add: {}, url_method_name: 'promotion_attributes_url', show_all_filter_on_top: true } } end def resource_controller_configuration { page_title: "Promotion Attributes", js_view_path: "/kuppayam/workflows/parrot", view_path: "/dhatu/promotion_attributes", collection_name: :promotion_attributes, item_name: :promotion_attribute, class: Dhatu::PromotionAttribute, show_modal_after_create: false, show_modal_after_update: false } end def breadcrumbs_configuration { heading: "Manage Promotion Attributes", icon: "fa-list", description: "Listing all Promotion Attributes", links: [{name: "Home", link: dashboard_path, icon: 'fa-home'}, {name: "Manage Promotion Attributes", link: promotion_attributes_path, icon: 'fa-list', active: true}] } end def permitted_params params.require("dhatu/promotion_attribute").permit(:name, :data_type, :promotion_id, :display, :mandatory, :values_string, :priority) end def set_navs set_nav("dhatu/promotion_attributes") end def get_resource @r_object = @resource_options[:class].find_by_id(params[:id]) @promotion = @r_object.promotion if params[:action] == "update" @r_object.mandatory = false @r_object.display = false end end end end