Skip to content

Commit

Permalink
Use category autocompletion for templates, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jan 21, 2010
1 parent 49887a7 commit c0f1415
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 29 deletions.
35 changes: 27 additions & 8 deletions comp/widgets/tmpl_prof/edit_meta.html
Expand Up @@ -51,15 +51,34 @@
key => 'priority',
&>

<& '/widgets/select_object/select_object.mc',
object => 'category',
constrain => { site_id => $fa->get_site_id },
field => 'uri',
sort_field => 'uri',
name => 'category_id',
disp => 'Category',
selected => $fa->get_category_id
<& /widgets/profile/text.mc,
disp => 'Category',
name => 'new_category_autocomplete',
id => 'new_category_uri',
req => 1,
value => $fa->get_category_path,
&>
<div id="category_autocomplete_choices" class="autocomplete"></div><span id="new_cat_warning" style="display: none"><img src="/media/images/dialog-warning.gif" alt="Warning" /> <% $lang->maketext(qq{Unable to add category that does not exist}) %></span>
<script type="text/javascript">
// add throbber after Primary Category text field
var throbber = new Element('img', { id: 'category_autocomplete_indicator',
src: '/media/images/busy_indicator.gif' });
Element.hide(throbber);
$('new_category_uri').insert({ after: throbber });

new Ajax.Autocompleter(
"new_category_uri",
"category_autocomplete_choices",
"/widgets/profile/autocomplete_categories.html",
{
onEmpty: function() { Element.show('new_cat_warning'); },
onNotEmpty: function() { Element.hide('new_cat_warning') },
minChars: 2,
indicator: 'category_autocomplete_indicator',
parameters: 'site_id=<% $fa->get_site_id %>&key=template'
}
);
</script>

<& '/widgets/profile/displayFormElement.mc',
objref => $fa,
Expand Down
40 changes: 29 additions & 11 deletions comp/widgets/tmpl_prof/edit_new.html
Expand Up @@ -82,18 +82,36 @@
req => 1,
'disp' => 'Output Channel');

$m->comp('/widgets/select_object/select_object.mc',
'object' => 'category',
'name' => $widget.'|cat_id',
selected => $param->{"$widget|cat_id"},
'reset_key' => $rk,
'field' => 'uri',
sort_field => 'uri',
constrain => { site_id => $site_id },
exclude => $excl_sub,
req => 1,
'disp' => 'Category');
$m->comp('/widgets/profile/text.mc',
disp => 'Category',
name => 'new_category_autocomplete',
id => 'new_category_uri',
req => 1,
value => $param->{new_category_autocomplete},
);
</%perl>
<div id="category_autocomplete_choices" class="autocomplete"></div><span id="new_cat_warning" style="display: none"><img src="/media/images/dialog-warning.gif" alt="Warning" /> <% $lang->maketext(qq{Unable to add category that does not exist}) %></span>
<script type="text/javascript">
// add throbber after Primary Category text field
var throbber = new Element('img', { id: 'category_autocomplete_indicator',
src: '/media/images/busy_indicator.gif' });
Element.hide(throbber);
$('new_category_uri').insert({ after: throbber });

new Ajax.Autocompleter(
"new_category_uri",
"category_autocomplete_choices",
"/widgets/profile/autocomplete_categories.html",
{
onEmpty: function() { Element.show('new_cat_warning'); },
onNotEmpty: function() { Element.hide('new_cat_warning') },
minChars: 1,
indicator: 'category_autocomplete_indicator',
parameters: 'site_id=<% $site_id %>&key=template'
}
);
</script>
<%perl>;
$m->comp('/widgets/profile/displayFormElement.mc',
key => "priority",
vals => $pmeth);
Expand Down
39 changes: 31 additions & 8 deletions lib/Bric/App/Callback/Profile/Template.pm
Expand Up @@ -436,12 +436,24 @@ $save_meta = sub {
$param->{"$widget|code"} =~ s/\r\n?/\n/g;
$fa->set_data($param->{"$widget|code"});
}
if (exists $param->{category_id}) {
my $curi = $param->{new_category_autocomplete};
unless (defined $curi && $curi ne '') {
$self->raise_conflict("Please select a primary category.");
return;
}
my ($cat_id) = Bric::Biz::Category->list_ids({
uri => $curi,
site_id => $fa->get_site_id,
}) or $self->raise_conflict(
'Unable to add category that does not exist'
) and return;

if ($fa->get_category_id != $cat_id) {
# Remove the existing version from the user's sand box.
my $sb = Bric::Util::Burner->new({user_id => get_user_id() });
$sb->undeploy($fa);
# Set the new category.
$fa->set_category_id($param->{category_id});
$fa->set_category_id($cat_id);
}
return set_state_data($widget, 'template', $fa);
};
Expand Down Expand Up @@ -602,12 +614,23 @@ $create_fa = sub {
my ($self, $widget, $param) = @_;
my $at_id = $param->{$widget.'|at_id'};
my $oc_id = $param->{$widget.'|oc_id'};
my $cat_id = $param->{$widget.'|cat_id'};
my $tplate_type = $param->{tplate_type};
my $work_id = get_state_data($widget, 'work_id');
my $wf = Bric::Biz::Workflow->lookup({ id => $work_id });

# Determine.
my $curi = $param->{new_category_autocomplete};
unless (defined $curi && $curi ne '') {
$self->raise_conflict("Please select a primary category.");
return;
}

my $site_id = Bric::Biz::Workflow->lookup({
id => get_state_data($widget => 'work_id')
})->get_site_id;
my ($cat_id) = Bric::Biz::Category->list_ids({
uri => $curi,
site_id => $wf->get_site_id,
}) or $self->raise_conflict(
'Unable to add category that does not exist'
) and return;

my ($at, $name);
if ($tplate_type == Bric::Biz::Asset::Template::ELEMENT_TEMPLATE) {
Expand Down Expand Up @@ -642,7 +665,7 @@ $create_fa = sub {
priority => $param->{priority},
name => $name,
user__id => get_user_id(),
site_id => $site_id,
site_id => $wf->get_site_id,
});
};

Expand All @@ -657,7 +680,7 @@ $create_fa = sub {
output_channel_id => $oc_id,
category_id => $cat_id,
element_type_id => $at_id,
site_id => $site_id,
site_id => $wf->get_site_id,
});
if (defined $fa) {
$self->add_message('Deactivated template was reactivated.');
Expand Down
5 changes: 3 additions & 2 deletions lib/Bric/Changes.pod
Expand Up @@ -54,8 +54,9 @@ the same option added to the "Check In" menu on desks and My Workspace.

=item *

Category selection when editing a media document now uses an autocomplete
feild rather than a select list, just like the story profile does. [David]
Category selection when editing a media document or a template now uses an
autocomplete feild rather than a select list, just like the story profile
does. [David]

=back

Expand Down

0 comments on commit c0f1415

Please sign in to comment.