Module: Hancock::Catalog::Admin::Category

Defined in:
lib/hancock/catalog/admin/category.rb

Class Method Summary collapse

Class Method Details

.config(nav_label = nil, fields = {}) ⇒ Object



4
5
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
60
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
89
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/hancock/catalog/admin/category.rb', line 4

def self.config(nav_label = nil, fields = {})
  if nav_label.is_a?(Hash)
    nav_label, fields = nav_label[:nav_label], nav_label
  elsif nav_label.is_a?(Array)
    nav_label, fields = nil, nav_label
  end

  Proc.new {
    navigation_label(!nav_label.blank? ? nav_label : I18n.t("hancock.catalog"))

    list do
      scopes [:sorted, :enabled, nil]

      field :enabled, :toggle do
        searchable false
      end
      field :name do
        searchable true
      end
      if Hancock::Catalog.config.pages_support and Hancock::Catalog.configuration.can_connect_category_with_pages
        field :connected_pages, :hancock_connectable
      end
      field :add_item do
        pretty_value do
          _model = bindings[:object].item_class.rails_admin_model
          bindings[:view].link_to(
            'Добавить товар',
            bindings[:view].new_path(model_name: _model, "#{_model}[category_ids][]": bindings[:object]._id.to_s),
            class: 'label label-info'
          )
        end
        visible do
          bindings[:controller].action_name == 'index'
        end
        formatted_value {}
      end

      group :content, &Hancock::Admin.content_block
      if Hancock::Catalog.config.cache_support
        group :caching, &Hancock::Cache::Admin.caching_block
      end
    end

    edit do
      field :enabled, :toggle
      field :name

      if Hancock::Catalog.config.pages_support and Hancock::Catalog.configuration.can_connect_category_with_pages
        group :connected_pages do
          active false
          field :connected_pages, :hancock_connectable do
            read_only do
              !bindings[:view].current_user.admin?
            end
          end
        end
      end

      group :URL, &Hancock::Admin.url_block
      # group :URL do
      #   active false
      #   field :slugs, :hancock_slugs
      #   field :text_slug
      # end

      if Hancock::Catalog.config.gallery_support
        group :image, &Hancock::Gallery::Admin.images_block(:category_images)
        # group :image do
        #   active false
        #   field :image, :hancock_image
        #   field :category_images
        # end
      end


      group :content, &Hancock::Admin.content_block
      # group :content do
      #   active false
      #   field :excerpt, :hancock_html
      #   field :content, :hancock_html
      # end

      Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)

      if Hancock::Catalog.config.seo_support
        group :seo_n_sitemap, &Hancock::Seo::Admin.seo_n_sitemap_block
        # group :seo do
        #   active false
        #   field :seo
        # end
        # group :sitemap_data do
        #   active false
        #   field :sitemap_data
        # end
      end

      if Hancock::Catalog.config.cache_support
        group :caching, &Hancock::Cache::Admin.caching_block
      end

      group :items do
        active false
        field :items do
          read_only true
          help 'Список товаров'

          pretty_value do
            bindings[:object].items.to_a.map { |i|
              route = (bindings[:view] || bindings[:controller])
              model_name = i.rails_admin_model
              route.link_to(i.name, route.rails_admin.show_path(model_name: model_name, id: i.id), title: i.name)
            }.join("<br>").html_safe
          end
        end
      end
      if Hancock::Catalog.config.insertions_support
        group :insertions, &Hancock::Admin.insertions_block
      end
    end

    show do
      field :name
      field :slugs, :hancock_slugs
      field :text_slug
      field :enabled
      field :image
      field :excerpt
      field :content

      Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)

      field :items do
        read_only true

        pretty_value do
          bindings[:object].items.to_a.map { |i|
            route = (bindings[:view] || bindings[:controller])
            model_name = i.rails_admin_model
            route.link_to(i.name, route.rails_admin.show_path(model_name: model_name, id: i.id), title: i.name)
          }.join("<br>").html_safe
        end
      end
      
      if Hancock::Catalog.config.insertions_support
        group :insertions, &Hancock::Admin.insertions_block
      end
    end

    nested_set({max_depth: 2, scopes: []})

    sort_embedded(
        {
            fields: [:category_images]
        }
    )

    if defined?(RailsAdminMultipleFileUpload)
      multiple_file_upload(
          {
              fields: [:category_images]
          }
      )
    end

    if block_given?
      yield self
    end
  }
end