From a57fc80a183cd7daf7368da19eff0dee81294cf8 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Tue, 24 Mar 2009 17:08:33 +0000 Subject: [PATCH] Added rfe #9098 Thingy thing-copy function and added some context to thingy's i18n --- docs/changelog/7.x.x.txt | 3 +- .../templates_thingy-default.wgpkg | Bin 0 -> 1214 bytes lib/WebGUI/Asset/Wobject/Thingy.pm | 58 ++++++++++++++++ lib/WebGUI/Help/Asset_Thingy.pm | 2 + lib/WebGUI/i18n/English/Asset_Thingy.pm | 64 ++++++++++++++++++ t/Asset/Wobject/Thingy.t | 10 ++- 6 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 docs/upgrades/packages-7.7.1/templates_thingy-default.wgpkg diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9d742fa8a..a9c6defbd 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,7 +1,8 @@ 7.7.1 - - rfe #9353: Welcome message template + - rfe #9353: Welcome message template (SDH Consulting Group) - rfe #10007: New Month and Year question type. If required, Month must be selected and a 4 digit year must be entered. - fixed #10011: Wrong spelling of "Descendant" in Navigation Asset Help function (Rob Schipper/NFIA India) + - rfe #9098: Thingy Thing-copy function (SDH Consulting Group) 7.7.0 - fixed #9913: New Content Side Bar missing in Asset window diff --git a/docs/upgrades/packages-7.7.1/templates_thingy-default.wgpkg b/docs/upgrades/packages-7.7.1/templates_thingy-default.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..025ed65b37d60539605a6e77d3235526fb35a9ce GIT binary patch literal 1214 zcmV;v1VQ^BiwFP!000001MOCAbJ{o%=5v3A#~*HznG|dYp%9L_^wKtT+9uaRGo9ng z2wMRqMsg$pac}zHZ?!VWxJj?qN$yk33M2laXwHiCM^3xlu`RyW{&`RTt0kfi-S>X} zyLzbvzb7Q%{a}Cp&ipq+5N_wc0VPuLfX#=09xDIUhlhS25&nJxP3S8vB$-m*>v(_u zwTDZo6e*ROQD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sy8q@_| z)^4i|yyI;X5j2CKaS%Ln5g~ujOF6tt{wcmbz8b!NcGEgr*6FMF;q~CiHy6pTPrlyA cJ@wJYBLj~NJTmae!2L4t4{~&C4*(PZ0Q1d4P5=M^ literal 0 HcmV?d00001 diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index af0dcaa6d..ad996c24a 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -308,6 +308,42 @@ sub duplicate { return $newAsset; } +#------------------------------------------------------------------- + +=head2 duplicateThing ( thingId ) + +Duplicates a thing. + +=head3 thingId + +The id of the Thing that will be duplicated. + +=cut + +sub duplicateThing { + + my $self = shift; + my $oldThingId = shift; + my $db = $self->session->db; + + my $thingProperties = $self->getThing($oldThingId); + $thingProperties->{thingId} = 'new'; + $thingProperties->{label} = $thingProperties->{label}.' (copy)'; + + my $newThingId = $self->addThing($thingProperties); + my $fields = $db->buildArrayRefOfHashRefs('select * from Thingy_fields where assetId=? and thingId=?' + ,[$self->getId,$oldThingId]); + foreach my $field (@$fields) { + # set thingId to newly created thing's id. + $field->{thingId} = $newThingId; + $self->addField($field,0); + } + + return $newThingId; + +} + + #------------------------------------------------------------------- =head2 deleteField ( fieldId , thingId ) @@ -1436,6 +1472,26 @@ sub www_deleteFieldConfirm { return 1; } + +#------------------------------------------------------------------- + +=head2 www_duplicateThing ( ) + +Duplicates a Thing. + +=cut + +sub www_duplicateThing { + my $self = shift; + my $session = $self->session; + my $thingId = $session->form->process("thingId"); + return $session->privilege->insufficient() unless $self->canEdit; + + $self->duplicateThing($thingId); + + return $self->www_manage; +} + #------------------------------------------------------------------- =head2 www_copyThingData( ) @@ -2868,6 +2924,8 @@ sub www_manage { "",$i18n->get('delete thing warning')), 'thing_editUrl' => $session->url->append($url, 'func=editThing;thingId='.$thing->{thingId}), 'thing_editIcon' => $session->icon->edit('func=editThing;thingId='.$thing->{thingId}), + 'thing_copyUrl' => $session->url->append($url, 'func=duplicateThing;thingId='.$thing->{thingId}), + 'thing_copyIcon' => $session->icon->copy('func=duplicateThing;thingId='.$thing->{thingId}), 'thing_addUrl' => $session->url->append($url, 'func=editThingData;thingId='.$thing->{thingId}.';thingDataId=new'), 'thing_searchUrl' => $session->url->append($url, 'func=search;thingId='.$thing->{thingId}), diff --git a/lib/WebGUI/Help/Asset_Thingy.pm b/lib/WebGUI/Help/Asset_Thingy.pm index 366d22969..d740ed4f5 100644 --- a/lib/WebGUI/Help/Asset_Thingy.pm +++ b/lib/WebGUI/Help/Asset_Thingy.pm @@ -26,6 +26,8 @@ our $HELP = { { 'name' => 'thing_deleteUrl' }, { 'name' => 'thing_searchUrl' }, { 'name' => 'thing_addUrl' }, + { 'name' => 'thing_copyUrl' }, + { 'name' => 'thing_copyIcon' }, ] }, ], diff --git a/lib/WebGUI/i18n/English/Asset_Thingy.pm b/lib/WebGUI/i18n/English/Asset_Thingy.pm index 3c7a987eb..96cce408a 100644 --- a/lib/WebGUI/i18n/English/Asset_Thingy.pm +++ b/lib/WebGUI/i18n/English/Asset_Thingy.pm @@ -652,47 +652,68 @@ Braces, quotes and all. You simply replace "key1"/"value1" with your own name/v 'canEditThings' => { message => q|Is true if the current user can view the Things that are defined for this Thingy Asset|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'things_loop' => { message => q|A loop containing the Things that are defined for this Thingy Asset, with links to management functions for those Things|, lastUpdated => 1104630516, + context => q|Description of a tmpl_loop for the template help.|, }, 'thing_editIcon' => { message => q|An icon with a link to the edit screen for this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_editUrl' => { message => q|A link to the edit screen for this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, + }, + + 'thing_copyIcon' => { + message => q|An icon with a link to copy this Thing|, + lastUpdated => 0, + context => q|Description of a tmpl_var for the template help.|, + }, + + 'thing_copyUrl' => { + message => q|A link to copy this Thing|, + lastUpdated => 0, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_viewIcon' => { message => q|An icon with a link to default screen for this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_searchUrl' => { message => q|A link to the search screen for this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_addUrl' => { message => q|A link to the add screen for this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_deleteIcon' => { message => q|An icon with a link to delete this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_deleteUrl' => { message => q|A link to delete this Thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'thing_label' => { @@ -708,31 +729,37 @@ functions for those Things|, 'manage_url' => { message => q|This Url will lead to a screen to manage the Things in this Thingy Asset.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'addThing_url' => { message => q|This Url leads to the screen to add a new Thing to this Thingy Asset.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'delete_url' => { message => q|The Url to delete the current thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'delete_confirm' => { message => q|This contains an onclick property for the delete link that adds a javascript confirmation|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'search_url' => { message => q|Url that leads to the search screen|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'add_url' => { message => q|Url to the add screen for this thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'editScreenTitle' => { @@ -749,16 +776,19 @@ functions for those Things|, message => q|A loop containing error information, for instance if someone doesn't fill out a required field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_loop for the template help.|, }, 'error_message' => { message => q|An error message indicating what the user might have done wrong.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_loop' => { message => q|A loop containing the visible fields for this thing|, lastUpdated => 1104630516, + context => q|Description of a tmpl_loop for the template help.|, }, 'listOfThings' => { @@ -788,73 +818,87 @@ field.|, 'field_isHidden' => { message => q|A conditional indicating whether this field is supposed to be hidden.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_isRequired' => { message => q|A conditional indicating whether this field is required.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_isVisible' => { message => q|A conditional indicating whether this field is supposed to be visible but not editable.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_form' => { message => q|The form element for this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_name' => { message => q|The name of the form element for this field|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_label' => { message => q|The label of this field|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_url' => { message => q|An optional url that this field should link to, used i.e. for fields in other things.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_value' => { message => q|The value of this field|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'field_pretext' => { message => q|An extra description of the field so that users know what to put in the field. To be displayed above/before the form element.|, lastUpdated => 1224518799, + context => q|Description of a tmpl_var for the template help.|, }, 'field_subtext' => { message => q|A description of the field so that users know what to put in the field. To be displayed below/after the form element.|, lastUpdated => 1224518799, + context => q|Description of a tmpl_var for the template help.|, }, 'form_start' => { message => q|The start tag of the form|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'form_submit' => { message => q|A form button to submit the form data.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'form_end' => { message => q|The end of the form|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'edit_url' => { message => q|Url to the current things edit screen.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'viewScreenTitle' => { @@ -865,12 +909,14 @@ below/after the form element.|, 'import_url' => { message => q|Url to import data into this Thing from a csv file|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'export_url' => { message => q|Url to export the data in a search result into a csv file. This is only available after a search has been done.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchScreenTitle' => { @@ -886,86 +932,103 @@ search has been done.|, 'searchFields_loop' => { message => q|A loop that contains the fields that are searchable|, lastUpdated => 1104630516, + context => q|Description of a tmpl_loop for the template help.|, }, 'searchFields_label' => { message => q|The label of a searchable field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchFields_fieldId' => { message => q|The fieldId of a searchable field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchFields_form' => { message => q|A form element corresponding to this fields fieldType to search this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchFields_textForm' => { message => q|A text input to search this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchFields_is__fieldType__' => { message => q|A boolean indicating wether this field is of type __fieldType__. The first letter of __fieldType__ is always uppercase. Example: for a select box the value of <tmpl_var searchFields_isSelectBox> is true.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'displayInSearchFields_loop' => { message => q|A loop containing the fields that are displayed in the search results.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_loop for the template help.|, }, 'displayInSearchFields_orderByUrl' => { message => q|Url to order the search results by this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'displayInSearchFields_label' => { message => q|The label of this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'displayInSearchFields_fieldId' => { message => q|The fieldId of this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchResult_loop' => { message => q|A loop containing the search results.|, lastUpdated => 1206472126, + context => q|Description of a tmpl_loop for the template help.|, }, 'searchResult_id' => { message => q|The id of a search result.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchResult_view_url' => { message => q|Url to the view screen of this search result|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchResult_edit_icon' => { message => q|Edit icon that links to the edit screen of this search result.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchResult_delete_icon' => { message => q|Delete icon to delete this search result.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'searchResult_field_loop' => { message => q|A loop containing the fields that are to be displayed for this search result.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_loop for the template help.|, }, 'field_id' => { message => q|The id of this field.|, lastUpdated => 1104630516, + context => q|Description of a tmpl_var for the template help.|, }, 'no field values message' => { @@ -1011,6 +1074,7 @@ search has been done.|, 'view_url' => { message => q|The URL that will take the user back to the Thingy default view.|, lastUpdated => 1227737813, + context => q|Description of a tmpl_var for the template help.|, }, 'other thing field missing message' => { diff --git a/t/Asset/Wobject/Thingy.t b/t/Asset/Wobject/Thingy.t index 9902a1c5f..ed5ad0a40 100644 --- a/t/Asset/Wobject/Thingy.t +++ b/t/Asset/Wobject/Thingy.t @@ -17,7 +17,7 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::PseudoRequest; -use Test::More tests => 16; # increment this value for each test you create +use Test::More tests => 17; # increment this value for each test you create use Test::Deep; use JSON; use WebGUI::Asset::Wobject::Thingy; @@ -192,6 +192,14 @@ my ($fieldLabel, $columnType, $Null, $Key, $Default, $Extra) = $session->db->qui is($fieldLabel,"field_".$fieldId,"A column for the new field Field_$fieldId exists."); is($columnType,"longtext","The columns is the right type"); +# Test duplicating a Thing + +my $copyThingId = $thingy->duplicateThing($thingId); + +$isValidId = $session->id->valid($copyThingId); + +is($isValidId,1,"duplicating a Thing: duplicateThing returned a valid id: ".$copyThingId); + # Test adding, editing, getting and deleting thing data my ($newThingDataId,$errors) = $thingy->editThingDataSave($thingId,'new',{"field_".$fieldId => 'test value'});