Permalink
Browse files

Got the delete graphic to disappear when no more container elements a…

…re allowed to be deleted. This is read to merge into trunk!
  • Loading branch information...
1 parent 95bc840 commit f2828a322b51c221343c72a1acbdd85d1f6d135f @theory theory committed Apr 20, 2008
@@ -28,4 +28,4 @@
<%flags>
inherit => undef
-</%flags>
+</%flags>
@@ -78,18 +78,17 @@ Container.updateOrder('element_<% $id %>');
</fieldset>
% }
-% unless ($top_level) {
-% my $parent = $element->get_parent;
-% 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 ( $parent && !$top_level) {
+% 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) ) {
<div class="delete">
<& '/widgets/profile/button.mc',
disp => $lang->maketext("Delete"),
name => 'delete_' . $name,
button => 'delete',
extension => 'png',
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
&>
</div>
@@ -101,9 +100,10 @@ Container.updateOrder('element_<% $id %>');
<%args>
$widget
$element
+$parent => undef
</%args>
-<%init>
+<%init>;
my $story = get_state_data('story_prof', 'story');
my $type = $element->get_element_type;
my $id = $element->get_id;
@@ -255,7 +255,7 @@ sub test_field_occurrence : Test(80) {
##############################################################################
# Test element occurrence.
-sub test_zelem_occurrence : Test(89) {
+sub test_zelem_occurrence : Test(93) {
my $self = shift->create_element_types;
my $class = $self->class;
my $story_type = $self->{story_type};
@@ -337,14 +337,19 @@ sub test_zelem_occurrence : Test(89) {
], 'Should get the correct maketext array';
# 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;
- ok my $cont2 = $elem->add_container($ets[0]), 'Add another ' . $ets[0]->get_key_name;
+ my $kn = $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
ok $elem->save, 'Make it so';
# 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';
+ 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 $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;

0 comments on commit f2828a3

Please sign in to comment.