& '/widgets/wrappers/table_top.mc',
caption => 'Current Categories',
&>
<& '/widgets/listManager/listManager.mc',
object => 'category',
userSort => 0,
sortBy => 'uri',
title => 'Current Categories',
objs => \@categories,
profile => undef,
fields => [qw(uri site name primary)],
field_titles => { primary => 'Primary' },
field_values => $primary_sub,
select => $category_select,
addition => '',
no_pagination => 1,
state_key => 'story_category',
&>
<& '/widgets/wrappers/table_bottom.mc' &>
<& /widgets/search/search.mc,
object => 'category',
field => 'uri',
type => 'singular',
use_form_tag => 0,
state_key => 'story_category',
&>
<& '/widgets/wrappers/table_top.mc',
caption => 'Choose Categories',
&>
<& /widgets/listManager/listManager.mc,
object => 'category',
title => 'Choose Categories',
select => undef,
profile => $category_choose_profile,
exclude => $exclude_cats,
fields => [qw(uri site name)],
addition => '',
behavior => 'expand',
state_key => 'story_category',
&>
<& '/widgets/wrappers/table_bottom.mc' &>
<& '/widgets/buttons/submit.mc',
disp => 'Save',
widget => $widget,
cb => 'save_category_cb',
button => 'save_red',
value => 'Save',
useTable => 0
&>
<& '/widgets/buttons/submit.mc',
disp => 'Save and Stay',
widget => $widget,
cb => 'save_and_stay_category_cb',
button => 'save_and_stay_lgreen',
value => 'Save and Stay',
useTable => 0
&>
<& '/widgets/buttons/submit.mc',
disp => 'Return',
widget => $widget,
cb => 'leave_category_cb',
button => 'return_dgreen',
value => 'Return',
useTable => 0
&>
<%args>
$widget
%args>
<%init>
my $story = get_state_data($widget, 'story');
my @categories = $story->get_categories();
my $exclude_cats = sub {
my $cat = shift;
# exclude unauthorized categories
return 1 unless chk_authz($cat, READ, 1);
# exclude already-associated categories
my $cid = $cat->get_id;
foreach my $ex (@categories) {
return 1 if $cid == $ex->get_id;
}
# exclude cats not in story's site
return 1 if $cat->get_site_id != $story->get_site_id;
return 0;
};
%init>
<%once>
my $primary_sub = sub {
return unless $_[1] eq 'primary';
my $cat = shift;
my $widget = 'story_prof';
my $story = get_state_data($widget, 'story');
my $primary_cat = $story->get_primary_category;
my $cid = $cat->get_id;
# Output the radio button.
$m->scomp('/widgets/profile/radio.mc',
name => "$widget|set_primary_category",
disp => '',
value => $cid,
checked => $cid == $primary_cat->get_id,
useTable => 0,
);
};
my $category_choose_profile = sub {
my $cat = shift;
my $widget = 'story_prof';
return ['Associate', $r->uri, "$widget|assoc_category_cb=" . $cat->get_id];
};
my $category_select = sub {
my $cat = shift;
my $widget = 'story_prof';
my $story = get_state_data($widget, 'story');
my $primary_cat = $story->get_primary_category;
if ($cat->get_id == $primary_cat->get_id) {
return;
} else {
return ['Delete', "$widget|delete_id"];
}
};
%once>