From ae6c1ac6df2ad3aa74a33e45dfa1855f0040e5eb Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Wed, 26 Mar 2008 19:03:46 +0000 Subject: [PATCH] Thingy now shows all field types when editing a field. --- lib/WebGUI/Asset/Wobject/Thingy.pm | 78 ++++++++++++++++++----------- www/extras/wobject/Thingy/thingy.js | 19 ++++--- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 0ac4aaff0..6075834ab 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -347,10 +347,11 @@ returns the form that will be used in the edit dialog for Thingy_fields. sub getEditFieldForm { my $self = shift; + my $session = $self->session; my $field = shift; my (%fieldStatus, $f, %fieldTypes, $things); my $fieldId = $field->{fieldId} || "new"; - my $i18n = WebGUI::International->new($self->session, 'Asset_Thingy'); + my $i18n = WebGUI::International->new($session, 'Asset_Thingy'); my $defaultValue; tie %fieldStatus, 'Tie::IxHash'; tie %fieldTypes, 'Tie::IxHash'; @@ -362,26 +363,14 @@ sub getEditFieldForm { "required" => $i18n->get('fieldstatus required label'), ); - %fieldTypes = ( - "dateTime" => "dateTime", - "TimeField" => "TimeField", - "float" => "float", - "zipcode" => "zipcode", - "text" => "text", - "textarea" => "textarea", - "HTMLArea" => "HTMLArea", - "url" => "url", - "date" => "date", - "email" => "email", - "phone" => "phone", - "integer" => "integer", - "yesNo" => "yesNo", - "selectList" => "select", - "radioList" => "radioList", - "checkList" => "checkList", - "selectBox" => "selectBox", - "file" => "file", - ); + foreach my $fieldType ( sort @{ WebGUI::Form::FieldType->new($session)->get("types") }) { + my $form = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$fieldType, "new", [$session]) }; + if ($@) { + $session->errorHandler->error($@); + next; + } + $fieldTypes{$fieldType} = $form->getName($self->session); + } $things = $self->session->db->read('select thingId, label from Thingy_things where assetId =?',[$self->getId]); while (my $thing = $things->hashRef) { @@ -423,7 +412,7 @@ sub getEditFieldForm { -name=>"fieldType", -label=>$i18n->get('field type label'), -hoverHelp=>$i18n->get('field type description'), - -value=>$field->{fieldType} || "text", + -value=>ucfirst $field->{fieldType} || "Text", -options=>\%fieldTypes, -id=>$dialogPrefix."_fieldType_formId", ); @@ -618,10 +607,11 @@ sub getFormElement { $param{vertical} = $data->{vertical}; $param{fieldType} = $data->{fieldType}; - if ($data->{fieldType} eq "checkbox") { + if ($data->{fieldType} eq "Checkbox") { $param{value} = ($data->{defaultValue} =~ /checked/xi) ? 1 : ""; } - if (WebGUI::Utility::isIn($data->{fieldType},qw(selectList checkList selectBox))) { + + if (WebGUI::Utility::isIn($data->{fieldType},qw(SelectList CheckList SelectBox))) { my @defaultValues; if ($self->session->form->param($name)) { @defaultValues = $self->session->form->selectList($name); @@ -633,7 +623,8 @@ sub getFormElement { } $param{value} = \@defaultValues; } - if (WebGUI::Utility::isIn($data->{fieldType},qw(selectList selectBox checkList radioList))) { + + if (WebGUI::Utility::isIn($data->{fieldType},qw(SelectList SelectBox CheckList RadioList))) { delete $param{size}; my %options; tie %options, 'Tie::IxHash'; @@ -643,13 +634,15 @@ sub getFormElement { } $param{options} = \%options; } - if ($data->{fieldType} eq "yesNo") { + + if ($data->{fieldType} eq "YesNo") { if ($data->{defaultValue} =~ /yes/xi) { $param{value} = 1; } elsif ($data->{defaultValue} =~ /no/xi) { $param{value} = 0; } } + if ($data->{fieldType} =~ m/^otherThing/x){ my $otherThingId = $data->{fieldType}; $otherThingId =~ s/^otherThing_(.*)/$1/x; @@ -1078,6 +1071,7 @@ sub www_editThing { my $session = $self->session; my ($tabForm, $output, %properties, $tab, %afterSave, %defaultView, $fields); my ($fieldsHTML, $fieldsViewScreen, $fieldsSearchScreen); + my (@hasHeightWidth,@hasSize,@hasVertical,@hasValues); tie %afterSave, 'Tie::IxHash'; return $session->privilege->insufficient() unless $self->canEdit; my $i18n = WebGUI::International->new($session, "Asset_Thingy"); @@ -1137,6 +1131,34 @@ sub www_editThing { $tab = $tabForm->getTab('fields'); + foreach my $fieldType ( sort @{ WebGUI::Form::FieldType->new($session)->get("types") }) { + my $form = eval { WebGUI::Pluggable::instanciate("WebGUI::Form::".$fieldType, "new", [$session]) }; + my $definition = $form->definition($session); + if ($@) { + $session->errorHandler->error($@); + next; + } + if ($form->get("height")){ + push(@hasHeightWidth, $fieldType); + } + if ($form->get("size")){ + push(@hasSize, $fieldType); + } + if (defined $definition->[0]->{vertical}->{defaultValue}){ + push(@hasVertical, $fieldType); + } + if ($form->get("options")){ + push(@hasValues, $fieldType); + } + + } + $tab->raw(""); + $tab->text( -name => 'label', -label => $i18n->get('thing name label'), @@ -1184,7 +1206,7 @@ sub www_editThing { $fields = $self->session->db->read('select * from Thingy_fields where assetId = '.$self->session->db->quote($self->get("assetId")).' and thingId = '.$self->session->db->quote($thingId).' order by sequenceNumber'); while (my $field = $fields->hashRef) { my $formElement; - if ($field->{fieldType} eq "file"){ + if ($field->{fieldType} eq "File"){ $formElement = ""; } else{ @@ -1570,7 +1592,7 @@ sub www_editFieldSave { $newFieldId = $self->setCollateral("Thingy_fields","fieldId",\%properties,1,1,"thingId",$thingId); } - if ($properties{fieldType} eq "file"){ + if ($properties{fieldType} eq "File"){ $formElement = ""; } else{ diff --git a/www/extras/wobject/Thingy/thingy.js b/www/extras/wobject/Thingy/thingy.js index fce3b2b09..9462c1883 100644 --- a/www/extras/wobject/Thingy/thingy.js +++ b/www/extras/wobject/Thingy/thingy.js @@ -30,35 +30,34 @@ function initOptionalFields(prefix,fieldId) { YAHOO.util.Event.addListener(prefix+"_fieldType_formId", "change", checkFieldType); function checkFieldType(){ - - if (this.value == "HTMLArea" || this.value == "textarea"){ + if (this.value in hasHeightWidth){ height_module.show(); width_module.show() }else{ height_module.hide(); width_module.hide() } - if (this.value == "radioList" || this.value == "checkList"){ + if (this.value in hasVertical){ vertical_module.show(); }else{ vertical_module.hide(); } - if (this.value == "HTMLArea" || this.value == "textarea" || this.value == "radioList" || this.value == "checkList" || this.value == "zipcode"){ - size_module.hide() + if (this.value in hasSize){ + size_module.show() }else{ - size_module.show(); + size_module.hide(); } - if (this.value == "selectList" || this.value == "selectBox" || this.value == "radioList" || this.value == "checkList"){ + if (this.value in hasValues){ values_module.show(); }else{ values_module.hide(); } var valueStart = this.value.slice(0,10); - if(valueStart == "otherThing" || this.value == "file"){ - defaultValue_module.hide(); - }else{ + if (valueStart != "otherThing"){ defaultValue_module.show(); + }else{ + defaultValue_module.hide(); } if(valueStart == "otherThing"){ var thingId = this.value.slice(11);