From: <mp...@kr...> - 2007-02-27 18:35:11
|
Revision: 3567 Author: mpeters Date: 2007-02-27 13:33:49 -0500 (Tue, 27 Feb 2007) Log Message: ----------- actually support "hidden" elements by not showing them in the UI Modified Paths: -------------- trunk/krang/lib/Krang/CGI/ElementEditor.pm trunk/krang/lib/Krang/Element.pm Modified: trunk/krang/lib/Krang/CGI/ElementEditor.pm =================================================================== --- trunk/krang/lib/Krang/CGI/ElementEditor.pm 2007-02-27 18:32:37 UTC (rev 3566) +++ trunk/krang/lib/Krang/CGI/ElementEditor.pm 2007-02-27 18:33:49 UTC (rev 3567) @@ -238,6 +238,7 @@ $template->param(no_delete => 1) if not $avail_del; foreach my $child (@children) { + next if $child->hidden; # setup form, making it invalid if needed my $form = $child->input_form(query => $query, order => $index, @@ -975,7 +976,7 @@ # save data $index = 0; foreach my $child ($element->children()) { - $child->load_query_data(query => $query); + $child->load_query_data(query => $query) unless $child->hidden; $index++; } @@ -999,8 +1000,9 @@ my $element = _find_element($root, $path); # get list of existing children and their query parameters - my @old = $element->children(); + my @old = grep { !$_->hidden } $element->children(); my @old_names = map { [ $_->param_names ] } @old; + my @hidden = grep { $_->hidden } $element->children(); # compute new list of children and rearrange query data my (@new, @old_to_new, @msgs); @@ -1031,7 +1033,7 @@ assert(not(grep { not defined $_ } @new)) if ASSERT; # do the reorder - $element->reorder_children(@new) if $op eq 'reorder'; + $element->reorder_children(@new, @hidden) if $op eq 'reorder'; # get a list of new param names my @new_names = map { [ $_->param_names ] } @new; Modified: trunk/krang/lib/Krang/Element.pm =================================================================== --- trunk/krang/lib/Krang/Element.pm 2007-02-27 18:32:37 UTC (rev 3566) +++ trunk/krang/lib/Krang/Element.pm 2007-02-27 18:33:49 UTC (rev 3567) @@ -637,20 +637,21 @@ =item C<< @classes = $element->available_child_classes() >> -Taking into account C<< $child->class->max >>, returns a list of -available child classes for new children. +Taking into account C<< $child->class->max >>, and C<< $child->class->hidden >> +returns a list of available child classes for new children. =cut sub available_child_classes { my $self = shift; - my ($name, $max, %max); + my ($name, $max, %max, %hidden); - # find maximums + # find maximums and hiddens foreach my $child_class ($self->{class}->children()) { $name = $child_class->name; $max = $child_class->max; $max{$name} = $max == 0 ? ~0 : $max; + $hidden{$name} = 1 if $child_class->hidden; } # loop through children, removing classes that have reached their max @@ -661,7 +662,7 @@ delete $max{$name} if --$max{$name} == 0; } - return grep { exists $max{$_->name} } $self->{class}->children; + return grep { exists $max{$_->name} or $hidden{$_->name} } $self->{class}->children; } =item C<< $element = Krang::Element->load(element_id => $id, object => $object) >> |