diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index d57271fee..0c7dbf00b 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -18,8 +18,31 @@ use WebGUI::Utility; use WebGUI::Text; use WebGUI::Form::File; use WebGUI::DateTime; -use base 'WebGUI::Asset::Wobject'; -use Data::Dumper; +use WebGUI::Definition::Asset; + +extends 'WebGUI::Asset::Wobject'; +aspect assetName => ['assetName', 'Asset_Thingy']; +aspect icon => 'thingy.gif'; +aspect tableName => 'Thingy'; +property templateId => ( + fieldType => "template", + default => 'ThingyTmpl000000000001', + tab => "display", + namespace => "Thingy", + hoverHelp => ['thingy template description', 'Asset_Thingy'], + label => ['thingy template label', 'Asset_Thingy'], + ); +property defaultThingId => ( + default => undef, + fieldType => "selectBox", + label => ["default thing label", 'Asset_Thingy'], + options => \&_defaultThingId_options, + ); +sub _defaultThingId_options { + my $self = shift; + my $things = $self->session->db->buildHashRef('select thingId, label from Thingy_things where assetId = ?',[$self->getId]); + return $things; +} #------------------------------------------------------------------- @@ -231,51 +254,6 @@ sub badOtherThing { return undef; } -#------------------------------------------------------------------- - -=head2 definition ( ) - -defines wobject properties for Thingy instances. If you choose to "autoGenerateForms", the -getEditForm method is unnecessary/redundant/useless. - -=cut - -sub definition { - my $class = shift; - my $session = shift; - my $definition = shift; - my $i18n = WebGUI::International->new($session, 'Asset_Thingy'); - my %properties; - tie %properties, 'Tie::IxHash'; - - %properties = ( - templateId =>{ - fieldType=>"template", - defaultValue=>'ThingyTmpl000000000001', - tab=>"display", - noFormPost=>0, - namespace=>"Thingy", - hoverHelp=>$i18n->get('thingy template description'), - label=>$i18n->get('thingy template label'), - }, - defaultThingId => { - autoGenerate => 0, - default=>undef, - fieldType=>"selectBox", - }, - ); - push(@{$definition}, { - assetName=>$i18n->get('assetName'), - icon=>'thingy.gif', - autoGenerateForms=>1, - tableName=>'Thingy', - className=>'WebGUI::Asset::Wobject::Thingy', - properties=>\%properties - }); - return $class->SUPER::definition($session, $definition); -} - - #------------------------------------------------------------------- =head2 duplicate ( ) @@ -289,7 +267,7 @@ sub duplicate { my $options = shift; my $newAsset = $self->SUPER::duplicate($options); my $db = $self->session->db; - my $assetId = $self->get("assetId"); + my $assetId = $self->getId; my $fields; my $otherThingFields = $db->buildHashRefOfHashRefs( @@ -328,7 +306,7 @@ sub duplicate { where fieldInOtherThingId = ? and assetId = ?', [$otherThingFields->{$otherThingField}->{newFieldType}, $otherThingFields->{$otherThingField}->{newFieldId}, - $otherThingFields->{$otherThingField}->{fieldInOtherThingId}, $newAsset->get('assetId')]); + $otherThingFields->{$otherThingField}->{fieldInOtherThingId}, $newAsset->getId]); } return $newAsset; } @@ -560,7 +538,7 @@ sub editThingDataSave { ); $fields = $session->db->read('select * from Thingy_fields where assetId = ? and thingId = ? order by sequenceNumber', - [$self->get("assetId"),$thingId]); + [$self->getId,$thingId]); while (my $field = $fields->hashRef) { my $fieldName = 'field_'.$field->{fieldId}; my $fieldValue; @@ -623,7 +601,7 @@ sub exportAssetData { my $self = shift; my $data = $self->SUPER::exportAssetData; my $db = $self->session->db; - my $assetId = $self->get("assetId"); + my $assetId = $self->getId; $data->{things} = $db->buildArrayRefOfHashRefs('select * from Thingy_things where assetId = ?',[$assetId]); $data->{fields} = $db->buildArrayRefOfHashRefs('select * from Thingy_fields where assetId = ?',[$assetId]); @@ -836,38 +814,6 @@ sub getEditFieldForm { #------------------------------------------------------------------- -=head2 getEditForm ( ) - -Returns the tabform object that will be used in generating the edit page for Thingy's. -Adds the defaultThingId selectBox to the tabform object, because the options for this selectBox depends on already -existing Things. The rest of the form is auto-generated. - -=cut - -sub getEditForm { - - my $self = shift; - my $i18n = WebGUI::International->new($self->session, 'Asset_Thingy'); - - my $tabform = $self->SUPER::getEditForm(); - - my $things = $self->session->db->buildHashRef('select thingId, label from Thingy_things where assetId = ?',[$self->get("assetId")]); - - if (scalar(keys(%{$things}))) { - $tabform->getTab("display")->selectBox( - -name=>"defaultThingId", - -value=>$self->get("defaultThingId"), - -label=>$i18n->get("default thing label"), - -options=>$things, - ); - } - - - return $tabform; -} - -#------------------------------------------------------------------- - =head2 getFieldValue ( value, field ) Processes the field value for date(Time) fields and Other Thing fields. @@ -1148,7 +1094,7 @@ sub getViewThingVars { if (%thingData) { my $fields = $db->read('select * from Thingy_fields where assetId = ? and thingId = ? order by sequenceNumber', - [$self->get('assetId'),$thingId]); + [$self->getId,$thingId]); while (my %field = $fields->hash) { next unless ($field{display} eq '1'); my $hidden = ($field{status} eq "hidden" && !$self->session->var->isAdminOn); @@ -1328,7 +1274,7 @@ sub importAssetCollateralData { } # delete deleted fields my $fieldsInDatabase = $session->db->read('select fieldId, thingId from Thingy_fields where assetId = ?', - [$self->get("assetId")]); + [$self->getId]); while (my $fieldInDataBase = $fieldsInDatabase->hashRef) { if (!WebGUI::Utility::isIn($fieldInDataBase->{fieldId},@importFields)){ # delete field @@ -1351,11 +1297,11 @@ See WebGUI::Asset::prepareView() for details. sub prepareView { my $self = shift; $self->SUPER::prepareView(); - my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); + my $template = WebGUI::Asset::Template->new($self->session, $self->templateId); if (!$template) { WebGUI::Error::ObjectNotFound::Template->throw( error => qq{Template not found}, - templateId => $self->get("templateId"), + templateId => $self->templateId, assetId => $self->getId, ); } @@ -1499,7 +1445,7 @@ sub view { $var->{"manage_url"} = $session->url->append($url, 'func=manage'); #Get this Thingy's default thing - $defaultThingId = $self->get("defaultThingId"); + $defaultThingId = $self->defaultThingId; $self->appendThingsVars($var, $defaultThingId); if ($defaultThingId ne ""){ @@ -1688,7 +1634,7 @@ sub www_editThing { return $self->www_view unless ($thingId); if($thingId eq "new"){ - my $groupIdEdit = $self->get("groupIdEdit"); + my $groupIdEdit = $self->groupIdEdit; %properties = ( thingId=>$thingId, label=>$i18n->get('thing name label'), @@ -1815,7 +1761,7 @@ sub www_editThing { ."