From 84d7c20fed7b56c35cabf827bc07c506a1aecc5f Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 16 Oct 2008 19:02:13 +0000 Subject: [PATCH] - Added Guid form control. - Moved Asset ID and Class Name fields to the Meta tab of all assets. - Made Classname from control a subclass of ReadOnly. --- docs/changelog/7.x.x.txt | 3 ++ lib/WebGUI/Asset.pm | 30 +++++++------ lib/WebGUI/Form/ClassName.pm | 31 +------------ lib/WebGUI/Form/Guid.pm | 84 ++++++++++++++++++++++++++++++++++++ lib/WebGUI/Form/ReadOnly.pm | 28 ++++++------ 5 files changed, 119 insertions(+), 57 deletions(-) create mode 100644 lib/WebGUI/Form/Guid.pm diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9dd64ca49..55cb9eef4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,8 @@ 7.6.2 - fixed #8839: Documentation is wrong for Stock Ticker + - Added Guid form control. + - Moved Asset ID and Class Name fields to the Meta tab of all assets. + - Made Classname from control a subclass of ReadOnly. - Fixed a limit bug in the asset discovery service. 7.6.1 diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 8fe06328b..58dfa78de 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -818,21 +818,19 @@ sub getEditForm { name=>"func", value=>"editSave" }); + my $assetId; + my $class; if ($self->getId eq "new") { - $tabform->hidden({ - name=>"assetId", - value=>"new" - }); - $tabform->hidden({ - name=>"class", - value=>$self->session->form->process("class","className") - }); + $assetId = "new"; + $class = $self->session->form->process("class","className"); } else { # revision history + $assetId = $self->getId; + $class = $self->get('className'); my $ac = $self->getAdminConsole; $ac->addSubmenuItem($self->getUrl("func=manageRevisions"),$i18n->get("revisions").":"); - my $rs = $self->session->db->read("select revisionDate from assetData where assetId=? order by revisionDate desc limit 5", [$self->getId]); + my $rs = $self->session->db->read("select revisionDate from assetData where assetId=? order by revisionDate desc limit 5", [$assetId]); while (my ($version) = $rs->array) { my ($interval, $units) = $self->session->datetime->secondsToInterval(time() - $version); $ac->addSubmenuItem($self->getUrl("func=edit;revision=".$version), $interval." ".$units." ".$ago); @@ -875,11 +873,19 @@ sub getEditForm { tie my %baseProperties, 'Tie::IxHash'; %baseProperties = ( assetId => { - fieldType => "readOnly", + fieldType => "guid", label => $i18n->get("asset id"), - value => $self->get("assetId"), + value => $assetId, hoverHelp => $i18n->get('asset id description'), - tab => "properties", + uiLevel => 9, + tab => "meta", + }, + class => { + fieldType => "className", + label => $i18n->get("class name",'WebGUI'), + value => $class, + uiLevel => 9, + tab => "meta", }, keywords => { label => $i18n->get('keywords'), diff --git a/lib/WebGUI/Form/ClassName.pm b/lib/WebGUI/Form/ClassName.pm index 6867cb5e1..ca4f3c05e 100644 --- a/lib/WebGUI/Form/ClassName.pm +++ b/lib/WebGUI/Form/ClassName.pm @@ -15,7 +15,7 @@ package WebGUI::Form::ClassName; =cut use strict; -use base 'WebGUI::Form::Text'; +use base 'WebGUI::Form::ReadOnly'; use WebGUI::International; =head1 NAME @@ -28,7 +28,7 @@ Creates a field for typing in perl class names which is validated for taint safe =head1 SEE ALSO -This is a subclass of WebGUI::Form::Text. +This is a subclass of WebGUI::Form::ReadOnly. =head1 METHODS @@ -65,32 +65,5 @@ sub getValue { return $value; } -#------------------------------------------------------------------- - -=head2 isDynamicCompatible ( ) - -Returns 0. - -=cut - -sub isDynamicCompatible { - return 0; -} - -#------------------------------------------------------------------- - -=head2 toHtml ( ) - -Renders a class name field. - -=cut - -sub toHtml { - my $self = shift; - $self->session->style->setScript($self->session->url->extras('inputCheck.js'),{ type=>'text/javascript' }); - $self->set("extras", $self->get('extras') . ' onkeyup="doInputCheck(document.getElementById(\''.$self->get("id").'\'),\'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:_\')" '); - return $self->SUPER::toHtml; -} - 1; diff --git a/lib/WebGUI/Form/Guid.pm b/lib/WebGUI/Form/Guid.pm new file mode 100644 index 000000000..bb82a80ec --- /dev/null +++ b/lib/WebGUI/Form/Guid.pm @@ -0,0 +1,84 @@ +package WebGUI::Form::Guid; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::ReadOnly'; +use WebGUI::International; + +=head1 NAME + +Package WebGUI::Form::Guid + +=head1 DESCRIPTION + +Creates a form control for feeding WebGUI IDs (which are called GUIDs or Global Unique IDs) through forms. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::ReadOnly. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + + +#------------------------------------------------------------------- + +=head2 getDatabaseFieldType ( ) + +Returns "char(22) binary" + +=cut + +sub getDatabaseFieldType { + return "char(22) binary"; +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return 'GUID'; +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) + +Returns a class name which has been taint checked. + +=cut + +sub getValue { + my $self = shift; + my $value = $self->SUPER::getValue(@_); + if ($value =~ m/[A-Za-z0-9\-_]{1,22}/) { + return $value; + } + return undef; +} + + +1; + diff --git a/lib/WebGUI/Form/ReadOnly.pm b/lib/WebGUI/Form/ReadOnly.pm index b5976eb26..8f9880c5e 100644 --- a/lib/WebGUI/Form/ReadOnly.pm +++ b/lib/WebGUI/Form/ReadOnly.pm @@ -52,18 +52,6 @@ sub getName { #------------------------------------------------------------------- -=head2 getValue ( ) - -Returns undef. - -=cut - -sub getValue { - return undef; -} - -#------------------------------------------------------------------- - =head2 isDynamicCompatible ( ) A class method that returns a boolean indicating whether this control is compatible with the DynamicField control. @@ -71,31 +59,39 @@ A class method that returns a boolean indicating whether this control is compati =cut sub isDynamicCompatible { - return 1; + return 0; } #------------------------------------------------------------------- =head2 toHtml ( ) -Renders the value. +Renders the value and a hidden input type if a "name" attribute was specified. =cut sub toHtml { my $self = shift; - return $self->getOriginalValue; + my $out = $self->getOriginalValue; + if ($self->get('name') ne '') { + $out .= $self->toHtmlAsHidden; + } + return $out; } #------------------------------------------------------------------- =head2 toHtmlAsHidden ( ) -Outputs nothing. +Outputs nothing unless a "name" attribute was specified. =cut sub toHtmlAsHidden { + my $self = shift; + if ($self->get('name') ne '') { + return $self->SUPER::toHtmlAsHidden; + } return undef; }