Merge commit 'v7.10.17' into 8
Conflicts: docs/upgrades/upgrade_7.9.13-7.10.0.pl lib/WebGUI.pm lib/WebGUI/Asset/Template/TemplateToolkit.pm lib/WebGUI/Asset/Wobject/AssetReport.pm lib/WebGUI/Asset/Wobject/Thingy.pm lib/WebGUI/Form/Captcha.pm lib/WebGUI/Macro/AdminBar.pm lib/WebGUI/Shop/Cart.pm lib/WebGUI/Shop/PayDriver.pm lib/WebGUI/Shop/PayDriver/PayPal/ExpressCheckout.pm lib/WebGUI/Shop/PayDriver/PayPal/PayPalStd.pm lib/WebGUI/Shop/Transaction.pm lib/WebGUI/Workflow/Instance.pm lib/WebGUI/Workflow/Spectre.pm lib/WebGUI/i18n/English/PayDriver.pm t/Asset/Asset.t t/Asset/AssetExportHtml.t t/Asset/AssetLineage.t t/Asset/Wobject/Thingy.t
This commit is contained in:
commit
795d88e7e5
69 changed files with 972 additions and 170 deletions
|
|
@ -169,10 +169,13 @@ sub getTemplateVars {
|
|||
#Build the data for all the assets on the page
|
||||
$var->{'asset_loop'} = [];
|
||||
my $data = $p->getPageData;
|
||||
ROW: foreach my $row (@{$data}) {
|
||||
foreach my $row (@{$data}) {
|
||||
my $returnAsset = eval { WebGUI::Asset->newById($session, $row->{assetId}); };
|
||||
next ROW if Exception::Class->caught();
|
||||
push(@{$var->{'asset_loop'}}, $returnAsset->get);
|
||||
push(@{$var->{'asset_loop'}}, {
|
||||
%{$returnAsset->get},
|
||||
%{$returnAsset->getMetaDataAsTemplateVariables}
|
||||
});
|
||||
}
|
||||
|
||||
#Append template variables
|
||||
|
|
|
|||
|
|
@ -650,6 +650,17 @@ sub editThingDataSave {
|
|||
$fieldValue = $field->{defaultValue};
|
||||
#WebGUI::Macro::process($self->session,\$fieldValue);
|
||||
}
|
||||
|
||||
if ($field->{isUnique}) {
|
||||
|
||||
unless ( $self->isUniqueEntry($thingId,$fieldName,$fieldValue,$thingDataId)) {
|
||||
push (@errors,{
|
||||
"error_message"=>$field->{label}. $i18n->get('needs to be unique error'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$thingData{$fieldName} = $fieldValue;
|
||||
}
|
||||
|
||||
|
|
@ -836,6 +847,15 @@ sub getEditFieldForm {
|
|||
options=>\@fieldTypes,
|
||||
id=>$dialogPrefix."_fieldType_formId",
|
||||
);
|
||||
|
||||
$f->addField( "yesNo",
|
||||
name=>'isUnique',
|
||||
label=>$i18n->get('unique label'),
|
||||
hoverHelp=>$i18n->get('unique description'),
|
||||
value=>$field->{isUnique},
|
||||
id=>$dialogPrefix."_isUnique_formId",
|
||||
);
|
||||
|
||||
$f->addField( "ReadOnly",
|
||||
name => "${dialogPrefix}_fieldInThing_module",
|
||||
value => $self->getHtmlWithModuleWrapper($dialogPrefix."_fieldInThing_module")
|
||||
|
|
@ -1377,6 +1397,68 @@ sub hasEnteredMaxPerUser {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 hasEnteredMaxEntries
|
||||
|
||||
Check whether the the maximum number of entries allowed for this thing has been reached.
|
||||
|
||||
=head3 thingId
|
||||
|
||||
The unique id of a thing.
|
||||
|
||||
=cut
|
||||
|
||||
sub hasEnteredMaxEntries {
|
||||
my ($self,$thingId) = @_;
|
||||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
my $maxEntriesTotal = $db->quickScalar("select maxEntriesTotal from Thingy_things where thingId=?",[$thingId]);
|
||||
|
||||
return 0 unless $maxEntriesTotal;
|
||||
|
||||
my $numberOfEntries = $session->db->quickScalar("select count(*) "
|
||||
."from ".$session->db->dbh->quote_identifier("Thingy_".$thingId));
|
||||
|
||||
if($numberOfEntries < $maxEntriesTotal){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isUniqueEntry ( thingId,fieldName,fieldValue, thingDataId )
|
||||
|
||||
Checks if the data entered in thingy record is unique
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
sub isUniqueEntry {
|
||||
|
||||
my ($self,$thingId,$fieldName,$fieldValue,$thingDataId) = @_;
|
||||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
my $nrOfEntries = $session->db->quickScalar("select count(*) "
|
||||
."from ".$session->db->dbh->quote_identifier("Thingy_".$thingId)." where " .
|
||||
$session->db->dbh->quote_identifier($fieldName) ."=? and thingDataId !=?",[$fieldValue,$thingDataId]);
|
||||
if ($nrOfEntries > 0) { return 0; }
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 hasPrivileges ( groupId )
|
||||
|
|
@ -1991,8 +2073,9 @@ sub www_editThing {
|
|||
thingsPerPage=>25,
|
||||
exportMetaData=>undef,
|
||||
maxEntriesPerUser=>undef,
|
||||
maxEntriesTotal=>undef,
|
||||
);
|
||||
$thingId = "new";
|
||||
$thingId = $self->addThing(\%properties,0);
|
||||
}
|
||||
else{
|
||||
%properties = %{$self->getThing($thingId)};
|
||||
|
|
@ -2197,6 +2280,14 @@ sub www_editThing {
|
|||
-hoverHelp=> $i18n->get('max entries per user description'),
|
||||
-label => $i18n->get('max entries per user label')
|
||||
);
|
||||
|
||||
$tab->integer(
|
||||
-name=> "maxEntriesTotal",
|
||||
-value=> $properties{maxEntriesTotal},
|
||||
-hoverHelp => $i18n->get('max entries total description'),
|
||||
-label => $i18n->get('max entries total label')
|
||||
);
|
||||
|
||||
$tab->group(
|
||||
-name=> "groupIdAdd",
|
||||
-value=> $properties{groupIdAdd},
|
||||
|
|
@ -2429,9 +2520,10 @@ sub www_editThingSave {
|
|||
sortBy => $form->process("sortBy") || '',
|
||||
exportMetaData => $form->process("exportMetaData") || '',
|
||||
maxEntriesPerUser => $form->process("maxEntriesPerUser") || '',
|
||||
maxEntriesTotal => $form->process("maxEntriesTotal") || '',
|
||||
};
|
||||
$self->setCollateral("Thingy_things", "thingId", $thing, 0, 1);
|
||||
|
||||
|
||||
if($fields->rows < 1){
|
||||
$self->session->log->warn("Thing failed to create because it had no fields");
|
||||
my $i18n = WebGUI::International->new($self->session, "Asset_Thingy");
|
||||
|
|
@ -2465,7 +2557,6 @@ sub www_editField {
|
|||
return $session->privilege->insufficient() unless $self->canEdit;
|
||||
$fieldId = $session->form->process("fieldId");
|
||||
$thingId = $session->form->process("thingId");
|
||||
|
||||
%properties = $session->db->quickHash("select * from Thingy_fields where thingId=? and fieldId=? and assetId=?",
|
||||
[$thingId,$fieldId,$self->getId]);
|
||||
if($session->form->process("copy")){
|
||||
|
|
@ -2502,12 +2593,12 @@ sub www_editFieldSave {
|
|||
my $log = $session->log;
|
||||
my $defaultValue = $session->form->process("defaultValue");
|
||||
my $fieldType = $session->form->process("fieldType") || "ReadOnly";
|
||||
my $uniqueField = $session->form->process("isUnique");
|
||||
|
||||
|
||||
if ($fieldType =~ m/^otherThing/){
|
||||
$defaultValue = $session->form->process("defaultFieldInThing");
|
||||
}
|
||||
|
||||
$thingId = $self->addThing({ thingId => 'new' },0) if $thingId eq 'new';
|
||||
|
||||
$fieldId = $session->form->process("fieldId");
|
||||
%properties = (
|
||||
|
|
@ -2515,6 +2606,7 @@ sub www_editFieldSave {
|
|||
thingId => $thingId,
|
||||
label => $label,
|
||||
fieldType => $fieldType,
|
||||
isUnique => $uniqueField,
|
||||
defaultValue => $defaultValue,
|
||||
possibleValues => $session->form->process("possibleValues"),
|
||||
pretext => $session->form->process("pretext"),
|
||||
|
|
@ -2572,7 +2664,7 @@ sub www_editFieldSave {
|
|||
# Make sure we send debug information along with the field.
|
||||
$log->preventDebugOutput;
|
||||
|
||||
$session->output->print($thingId.$newFieldId.$listItemHTML);
|
||||
$session->output->print($newFieldId.$listItemHTML);
|
||||
return "chunked";
|
||||
}
|
||||
|
||||
|
|
@ -2732,7 +2824,7 @@ sub editThingData {
|
|||
$var->{"delete_confirm"} = "onclick=\"return confirm('".$i18n->get("delete thing data warning")."')\"";
|
||||
}
|
||||
|
||||
if($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId)){
|
||||
if($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId) && !$self->hasEnteredMaxEntries($thingId)){
|
||||
$var->{"add_url"} = $session->url->append($url,'func=editThingData;thingId='.$thingId.';thingDataId=new');
|
||||
}
|
||||
if($self->hasPrivileges($thingProperties->{groupIdSearch})){
|
||||
|
|
@ -2798,6 +2890,15 @@ sub editThingData {
|
|||
delete $var->{field_loop};
|
||||
$var->{editInstructions} = $i18n->get("has entered max per user message");
|
||||
}
|
||||
if($thingDataId eq 'new' && $self->hasEnteredMaxEntries($thingId)){
|
||||
delete $var->{form_start};
|
||||
delete $var->{form_end};
|
||||
delete $var->{form_submit};
|
||||
delete $var->{field_loop};
|
||||
$var->{editInstructions} = $i18n->get("has entered max total message");
|
||||
}
|
||||
|
||||
|
||||
return $self->processTemplate($var,$thingProperties->{editTemplateId});
|
||||
}
|
||||
|
||||
|
|
@ -2827,6 +2928,10 @@ sub www_editThingDataSave {
|
|||
if($thingDataId eq 'new' && $self->hasEnteredMaxPerUser($thingId)){
|
||||
return $i18n->get("has entered max per user message");
|
||||
}
|
||||
if($thingDataId eq 'new' && $self->hasEnteredMaxEntries($thingId)){
|
||||
return $i18n->get("has entered max total message");
|
||||
}
|
||||
|
||||
|
||||
($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId);
|
||||
|
||||
|
|
@ -2897,6 +3002,10 @@ sub www_editThingDataSaveViaAjax {
|
|||
$session->response->status(400);
|
||||
return JSON->new->encode({message => $i18n->get("has entered max per user message")});
|
||||
}
|
||||
if($thingDataId eq 'new' && $self->hasEnteredMaxEntries($thingId)){
|
||||
$session->http->setStatus("400", "Bad Request");
|
||||
return JSON->new->encode({message => $i18n->get("has entered max total message")});
|
||||
}
|
||||
|
||||
my ($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId);
|
||||
|
||||
|
|
@ -3083,6 +3192,9 @@ sub www_import {
|
|||
my ($sql,$fields,@fields,$fileName,@insertColumns);
|
||||
my ($handleDuplicates,$newThingDataId);
|
||||
|
||||
my $i18n = WebGUI::International->new($self->session, "Asset_Thingy");
|
||||
|
||||
|
||||
my $thingId = $session->form->process('thingId');
|
||||
my $thingProperties = $self->getThing($thingId);
|
||||
return $session->privilege->insufficient() unless $self->hasPrivileges($thingProperties->{groupIdImport});
|
||||
|
|
@ -3183,9 +3295,27 @@ sub www_import {
|
|||
$log->info("Skipping line");
|
||||
next;
|
||||
}
|
||||
$thingData{lastUpdated} = time();
|
||||
$thingData{updatedByName} = $session->user->username;
|
||||
$thingData{updatedById} = $session->user->userId;
|
||||
|
||||
# Is this a new record or are we updating an existing record?
|
||||
if ($thingData{thingDataId} eq 'new') {
|
||||
$thingData{dateCreated} = time();
|
||||
$thingData{createdById} = $session->user->userId;
|
||||
}
|
||||
else {
|
||||
$thingData{lastUpdated} = time();
|
||||
$thingData{updatedByName} = $session->user->username;
|
||||
$thingData{updatedById} = $session->user->userId;
|
||||
}
|
||||
|
||||
$thingData{ipAddress} = $session->request->address;
|
||||
|
||||
if($thingData{thingDataId} eq 'new' && $self->hasEnteredMaxPerUser($thingId)){
|
||||
last;
|
||||
}
|
||||
if($thingData{thingDataId} eq 'new' && $self->hasEnteredMaxEntries($thingId)){
|
||||
last;
|
||||
}
|
||||
|
||||
$self->setCollateral("Thingy_".$thingId,"thingDataId",\%thingData,0,0) if ($thingData{thingDataId});
|
||||
}
|
||||
close $importFile;
|
||||
|
|
@ -3509,7 +3639,7 @@ sub getSearchTemplateVars {
|
|||
if ($self->hasPrivileges($thingProperties->{groupIdImport})){
|
||||
$var->{"import_url"} = $session->url->append($url, 'func=importForm;thingId='.$thingId);
|
||||
}
|
||||
if ($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId)){
|
||||
if ($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId) && !$self->hasEnteredMaxEntries($thingId) ){
|
||||
$var->{"add_url"} = $session->url->append($url,'func=editThingData;thingId='.$thingId.';thingDataId=new');
|
||||
}
|
||||
$var->{searchScreenTitle} = $thingProperties->{searchScreenTitle};
|
||||
|
|
@ -3810,7 +3940,7 @@ sub www_viewThingData {
|
|||
.$thingId.';thingDataId='.$thingDataId);
|
||||
$var->{"delete_confirm"} = "onclick=\"return confirm('".$i18n->get("delete thing data warning")."')\"";
|
||||
}
|
||||
if($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId)){
|
||||
if($self->hasPrivileges($thingProperties->{groupIdAdd}) && !$self->hasEnteredMaxPerUser($thingId) && !$self->hasEnteredMaxEntries($thingId) ){
|
||||
$var->{"add_url"} = $session->url->append($url, 'func=editThingData;thingId='.$thingId.';thingDataId=new');
|
||||
}
|
||||
if($self->hasPrivileges($thingProperties->{groupIdSearch})){
|
||||
|
|
@ -3823,8 +3953,10 @@ sub www_viewThingData {
|
|||
my $template;
|
||||
if( $templateId )
|
||||
{
|
||||
$template = WebGUI::Asset::Template->newByUrl( $session, $templateId ) ||
|
||||
WebGUI::Asset::Template->newById( $session, $templateId );
|
||||
$template = eval { WebGUI::Asset::Template->newByUrl( $session, $templateId ) };
|
||||
if ( $@ ) {
|
||||
$template = eval { WebGUI::Asset::Template->newById( $session, $templateId ) };
|
||||
}
|
||||
}
|
||||
|
||||
return $self->processStyle(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue