module CamaleonCms module Admin module PostTypeHelper # taxonomy -> (categories || post_tags) def post_type_html_inputs(post_type, taxonomy = 'categories', name = 'categories', type = 'checkbox', values = [], class_cat = 'categorychecklist', required = false) categories = post_type.send(taxonomy) categories = categories.eager_load(:children, :post_type_parent, :parent) if %w[categories children].include?(taxonomy) post_type_taxonomy_html_(categories, taxonomy, name, type, values, class_cat, required) end def post_type_status(status, color = 'default') "#{status}" end # taxonomies -> (categories || post_tags) def post_type_list_taxonomy(taxonomies, color = 'primary') html = '' taxonomies.decorate.each do |f| html += "#{f.the_title} " end html end # sort array of posts to build post's tree # skip_non_parent_posts: don't include post's where root post doesn't exist # internal control for recursive items def cama_hierarchy_post_list(posts_list, parent_id = nil, skip_non_parent_posts = false) res = [] @_cama_hierarchy_post_list_no_parent ||= posts_list.clone posts_list.each do |element| next unless element.post_parent.to_s == parent_id.to_s res << element @_cama_hierarchy_post_list_no_parent.delete_item(element) res += cama_hierarchy_post_list(posts_list, element.id) end if !parent_id.present? && !skip_non_parent_posts @_cama_hierarchy_post_list_no_parent.each do |element| element.show_title_with_parent = true res << element res += cama_hierarchy_post_list(posts_list, element.id) end end res end private def post_type_taxonomy_html_(categories, taxonomy = 'categories', name = 'categories', type = 'checkbox', values = [], class_cat = '', required = false) if categories.count < 1 return t('camaleon_cms.admin.post_type.message.no_created_html', taxonomy: taxonomy == 'categories' ? t('camaleon_cms.admin.table.categories') : t('camaleon_cms.admin.table.tags')).to_s end html = "
" html end end end end