object-map.tcl

This entry page for different object in ACS that need to manage which categories that can be mapped to contained objects.

Location:
/packages/categories/www/cadmin/object-map.tcl
Author:
Timo Hentschel <timo@timohentschel.de>
CVS ID:
$Id: object-map.tcl,v 1.11.2.2 2019/12/20 21:18:10 gustafn Exp $

Related Files

[ hide source ] | [ make this the default ]

File Contents

ad_page_contract {
    
    This entry page for different object in ACS that
    need to manage which categories that can be mapped
    to contained objects. 

    @author Timo Hentschel (timo@timohentschel.de)
    @cvs-id $Id: object-map.tcl,v 1.11.2.2 2019/12/20 21:18:10 gustafn Exp $
} {
    object_id:naturalnum,notnull
    ctx_id:naturalnum,optional
    {locale:word ""}
} -properties {
    page_title:onevalue
    context:onevalue
    locale:onevalue
    mapped_trees:multirow
    unmapped_trees:multirow
    object_name:onevalue
}

set user_id [auth::require_login]
permission::require_permission -object_id $object_id -privilege admin

set context_bar [category::get_object_context $object_id]
set object_name [lindex $context_bar 1]
set page_title [_ categories.cadmin]
set context_bar [list $context_bar $page_title]

template::multirow create mapped_trees tree_name tree_id \
    site_wide_p assign_single_p require_category_p widget view_url unmap_url edit_url

db_foreach get_mapped_trees {} {
    set tree_name [category_tree::get_name $tree_id $locale]
    if {$subtree_category_id ne ""} {
      append tree_name " :: [category::get_name $subtree_category_id $locale]"
    }
    template::multirow append mapped_trees $tree_name $tree_id $site_wide_p \
    $assign_single_p $require_category_p $widget \
    [export_vars -no_empty -base tree-view { tree_id locale object_id ctx_id}] \
    [export_vars -no_empty -base tree-unmap { tree_id locale object_id ctx_id}] \
    [export_vars -no_empty -base tree-map-2 { tree_id locale object_id {edit_p 1} ctx_id}]
}

template::multirow sort mapped_trees -dictionary tree_name

template::multirow create unmapped_trees tree_id tree_name site_wide_p view_url map_url subtree_url

db_foreach get_unmapped_trees {
    select tree_id, site_wide_p,
          acs_permission.permission_p(tree_id, :user_id, 'category_tree_read') as has_read_permission
     from category_trees t
    where not exists (select 1 from category_tree_map m
                       where m.object_id = :object_id
                         and m.tree_id = t.tree_id)
    order by t.tree_id
} {
    if { $has_read_permission == "t" || $site_wide_p == "t" } {
    set tree_name [category_tree::get_name $tree_id $locale]

    template::multirow append unmapped_trees $tree_id $tree_name $site_wide_p \
    [export_vars -no_empty -base tree-view { tree_id locale object_id ctx_id}] \
    [export_vars -no_empty -base tree-map-2 { tree_id locale object_id ctx_id}] \
    [export_vars -no_empty -base tree-map { tree_id locale object_id ctx_id}]
    }
}

template::multirow sort unmapped_trees -dictionary tree_name

template::list::create \
    -name mapped_trees \
    -no_data "#categories.None#" \
    -elements {
    tree_name {
        label "#acs-subsite.Name#"
        link_url_col view_url
    }
        flags {
        display_template {
        (<if @mapped_trees.site_wide_p;literal@ true>#categories.#SiteWide_tree#, </if>
                 <if @mapped_trees.widget@ ne "">@mapped_trees.widget@, </if>
         <if @mapped_trees.assign_single_p;literal@ true>#categories.single#, </if><else>#categories.multiple#, </else>
         <if @mapped_trees.require_category_p;literal@ true>#categories.required#) </if><else>#categories.optional#) </else>
        }
    }
    action {
        label "#categories.Action#"
        display_template {
        <a href="@mapped_trees.unmap_url@">#categories.Unmap#</a> &nbsp; &nbsp;
        <a href="@mapped_trees.edit_url@">#categories.Edit_parameters#</a>
        }
    }
    }

template::list::create \
    -name unmapped_trees \
    -no_data "#categories.None#" \
    -elements {
    tree_name {
        label "#acs-subsite.Name#"
        link_url_col view_url
    }
    site_wide_p {
        display_template {
        <if @unmapped_trees.site_wide_p;literal@ true> (#categories.SiteWide_tree#) </if>
        }
    }
    action {
        label "#categories.Action#"
        display_template {
        <a href="@unmapped_trees.map_url@">#categories.Map_tree#</a> &nbsp; &nbsp;
        <a href="@unmapped_trees.subtree_url@">#categories.Map_subtree#</a>
        }
    }
    }

set create_url [export_vars -no_empty -base tree-form { locale object_id ctx_id }]

ad_return_template

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: