# frozen_string_literal: true class SunriseFormatCategory < Sunrise::AbstractModel self.resource_name = 'Formats::Category' available_index_views [:thumbs] index :thumbs do scope { Formats::Category.normal } group :search do field :title field :service_id, collection: -> { Formats::Service.all } end end show do field :title field :description field :service, url: lambda { |record| { model_name: :format_services, action: :show, id: record.service_id } } field :items, label: 'Items', url: lambda { |record| { model_name: :format_items, action: :index, search: { category_id: record.id } } } field :items, label: 'Items', items: lambda { |record| record.items.map do |item| [ { image: item.icon.try(:url, :thumb) || 'sunrise/default_ava.png' }, { url: { model_name: :format_items, action: :show, id: item.id }, class: 'item-title', content: -> { item.title }, style: 'display: block; float: left; width: 590px; overflow: hidden;' }, { tag: :div, content: lambda { "
".html_safe } } ] end } # field :items, label: 'Service categories', items: -> (record) { # record.items.map { |i| { image: i.icon.try(:url, :thumb) } } # } end form do field :title, as: :text, translate: true, input_html: { rows: 2, style: 'width:800px;' } field :service_id, collection: -> { Formats::Service.all }, include_blank: false field :description, as: :ckeditor, translate: true, input_html: { height: 400, width: 900 } end end