Skip to content

Commit

Permalink
Got the delete graphic to disappear when no more container elements a…
Browse files Browse the repository at this point in the history
…re allowed to be deleted. This is read to merge into trunk!
  • Loading branch information
theory committed Apr 20, 2008
1 parent 95bc840 commit f2828a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion comp/widgets/container_prof/container.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@


<%flags> <%flags>
inherit => undef inherit => undef
</%flags> </%flags>
12 changes: 6 additions & 6 deletions comp/widgets/container_prof/container.mc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,18 +78,17 @@ Container.updateOrder('element_<% $id %>');
</fieldset> </fieldset>
% } % }
% unless ($top_level) { % if ( $parent && !$top_level) {
% my $parent = $element->get_parent; % my $sub_type = $parent->get_element_type->get_containers($element->get_key_name);
% my $sub_type = $parent->get_element_type->get_containers($element->get_key_name); % if ( $sub_type->get_min_occurrence < $parent->get_elem_occurrence($element->get_key_name) ) {
% if ( $sub_type->get_min_occurrence < $parent->get_elem_occurrence($element->get_key_name) ) {
<div class="delete"> <div class="delete">
<& '/widgets/profile/button.mc', <& '/widgets/profile/button.mc',
disp => $lang->maketext("Delete"), disp => $lang->maketext("Delete"),
name => 'delete_' . $name, name => 'delete_' . $name,
button => 'delete', button => 'delete',
extension => 'png', extension => 'png',
globalImage => 1, globalImage => 1,
js => qq|onclick="Container.deleteElement(| . $element->get_parent_id . qq|, '$name'); return false;"|, js => q{onclick="Container.deleteElement(} . $element->get_parent_id . qq{, '$name'); return false;"},
useTable => 0 useTable => 0
&> &>
</div> </div>
Expand All @@ -101,9 +100,10 @@ Container.updateOrder('element_<% $id %>');
<%args> <%args>
$widget $widget
$element $element
$parent => undef
</%args> </%args>
<%init> <%init>;
my $story = get_state_data('story_prof', 'story'); my $story = get_state_data('story_prof', 'story');
my $type = $element->get_element_type; my $type = $element->get_element_type;
my $id = $element->get_id; my $id = $element->get_id;
Expand Down
11 changes: 8 additions & 3 deletions t/Bric/Biz/Element/Container/DevTest.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ sub test_field_occurrence : Test(80) {


############################################################################## ##############################################################################
# Test element occurrence. # Test element occurrence.
sub test_zelem_occurrence : Test(89) { sub test_zelem_occurrence : Test(93) {
my $self = shift->create_element_types; my $self = shift->create_element_types;
my $class = $self->class; my $class = $self->class;
my $story_type = $self->{story_type}; my $story_type = $self->{story_type};
Expand Down Expand Up @@ -337,14 +337,19 @@ sub test_zelem_occurrence : Test(89) {
], 'Should get the correct maketext array'; ], 'Should get the correct maketext array';


# Try adding a few that are subelements of the story # Try adding a few that are subelements of the story
ok my $cont1 = $elem->add_container($ets[0]), 'Add a subelement ' . $ets[0]->get_key_name; my $kn = $ets[0]->get_key_name;
ok my $cont2 = $elem->add_container($ets[0]), 'Add another ' . $ets[0]->get_key_name; ok my $cont1 = $elem->add_container($ets[0]), "Add a $kn subelement";
ok my $cont2 = $elem->add_container($ets[0]), "Add another $kn subelement";


# Save it # Save it
ok $elem->save, 'Make it so'; ok $elem->save, 'Make it so';


# Delete them and add them again # Delete them and add them again
is $elem->get_elem_occurrence, 2, 'There should be 2 subelements';
is $elem->get_elem_occurrence($kn), 2, "There should be 2 $kn subelements";
ok $elem->delete_elements([ $cont1, $cont2 ]), 'Deleting the containers'; ok $elem->delete_elements([ $cont1, $cont2 ]), 'Deleting the containers';
is $elem->get_elem_occurrence, 0, 'There should now be 0 subelements';
is $elem->get_elem_occurrence($kn), 0, "There should now be 0 $kn subelements";
ok $elem->save, 'Make it so'; ok $elem->save, 'Make it so';
ok $cont1 = $elem->add_container($ets[0]), 'Add a subelement ' . $ets[0]->get_key_name; ok $cont1 = $elem->add_container($ets[0]), 'Add a subelement ' . $ets[0]->get_key_name;
ok $cont2 = $elem->add_container($ets[0]), 'Add another ' . $ets[0]->get_key_name; ok $cont2 = $elem->add_container($ets[0]), 'Add another ' . $ets[0]->get_key_name;
Expand Down

0 comments on commit f2828a3

Please sign in to comment.