=begin Camaleon CMS is a content management system Copyright (C) 2015 by Owen Peredo Diaz Email: owenperedo@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License (GPLv3) for more details. =end #encoding: utf-8 module CamaleonCms::Admin::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 taxonomy == "categories" || taxonomy == "children" post_type_taxonomy_html_(categories,taxonomy, name, type, values, class_cat, required) end def post_type_status(status, color="default") html = "#{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 return 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| if 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 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) 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') )}" if categories.count < 1 html = "
" return html end end