Skip to content

Commit

Permalink
#457 - enable autocomplete for single-ticket-reservation and a flag f…
Browse files Browse the repository at this point in the history
…or disabling it
  • Loading branch information
cbellone committed May 30, 2018
1 parent 5fe173a commit 79f5d81
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import javax.servlet.http.HttpServletRequest;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static alfio.model.system.Configuration.getSystemConfiguration;
Expand Down Expand Up @@ -114,7 +115,9 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
return redirectReservation(Optional.of(reservation), eventName, reservationId);
}

Configuration.ConfigurationPathKey forceAssignmentKey = Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION);
Function<ConfigurationKeys, Configuration.ConfigurationPathKey> partialConfig = Configuration.from(event.getOrganizationId(), event.getId());

Configuration.ConfigurationPathKey forceAssignmentKey = partialConfig.apply(FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION);
boolean forceAssignment = configurationManager.getBooleanConfigValue(forceAssignmentKey, false);

List<Ticket> ticketsInReservation = ticketReservationManager.findTicketsInReservation(reservationId);
Expand Down Expand Up @@ -162,7 +165,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
}

boolean invoiceAllowed = configurationManager.hasAllConfigurationsForInvoice(event) || vatChecker.isVatCheckingEnabledFor(event.getOrganizationId());
boolean onlyInvoice = invoiceAllowed && configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.GENERATE_ONLY_INVOICE), false);
boolean onlyInvoice = invoiceAllowed && configurationManager.getBooleanConfigValue(partialConfig.apply(ConfigurationKeys.GENERATE_ONLY_INVOICE), false);
PaymentForm paymentForm = PaymentForm.fromExistingReservation(reservation);
model.addAttribute("multiplePaymentMethods" , activePaymentMethods.size() > 1 )
.addAttribute("orderSummary", orderSummary)
Expand All @@ -180,8 +183,9 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
.addAttribute("invoiceIsAllowed", invoiceAllowed)
.addAttribute("onlyInvoice", onlyInvoice)
.addAttribute("vatNrIsLinked", orderSummary.isVatExempt() || paymentForm.getHasVatCountryCode())
.addAttribute("attendeeAutocompleteEnabled", ticketsInReservation.size() == 1 && configurationManager.getBooleanConfigValue(partialConfig.apply(ENABLE_ATTENDEE_AUTOCOMPLETE), true))
.addAttribute("billingAddressLabel", invoiceAllowed ? "reservation-page.billing-address" : "reservation-page.receipt-address")
.addAttribute("customerReferenceEnabled", configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_CUSTOMER_REFERENCE), false));
.addAttribute("customerReferenceEnabled", configurationManager.getBooleanConfigValue(partialConfig.apply(ENABLE_CUSTOMER_REFERENCE), false));

boolean includeStripe = !orderSummary.getFree() && activePaymentMethods.contains(PaymentProxy.STRIPE);
model.addAttribute("includeStripe", includeStripe);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/alfio/model/system/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public enum ConfigurationKeys {
ASSIGNMENT_REMINDER_INTERVAL("How long should be the 'quiet period' (in days) between the reminders? (default: 3 days)", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),
OPTIONAL_DATA_REMINDER_ENABLED("Send a reminder for optional data? (default: true)", false, SettingCategory.GENERAL, ComponentType.BOOLEAN, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),
RESERVATION_TIMEOUT("The amount of time, in MINUTES, that the user have to complete the reservation process (default: 25 min)", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),
FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION("Force ticket owner assignment at reservation time", false, SettingCategory.GENERAL, ComponentType.BOOLEAN, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),
ENABLE_CUSTOMER_REFERENCE("Enable Customer Reference (Purchase Order) field in contact detail (default: false)", false, SettingCategory.GENERAL, ComponentType.BOOLEAN, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),

FORCE_TICKET_OWNER_ASSIGNMENT_AT_RESERVATION("Force ticket owner assignment at reservation time", false, SettingCategory.RESERVATION_UI, ComponentType.BOOLEAN, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),
ENABLE_CUSTOMER_REFERENCE("Enable Customer Reference (Purchase Order) field in contact detail (default: false)", false, SettingCategory.RESERVATION_UI, ComponentType.BOOLEAN, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),
ENABLE_ATTENDEE_AUTOCOMPLETE("Enable attendee autocomplete for 1-ticket reservations (default: true)", false, SettingCategory.RESERVATION_UI, ComponentType.BOOLEAN, false, EnumSet.of(SYSTEM, ORGANIZATION, EVENT), true),

//
MAILER_TYPE("Mailer type (if not set, default will be disabled)", false, SettingCategory.MAIL, ComponentType.TEXT, true, EnumSet.of(SYSTEM), true),//valid values: smtp | mailgun
Expand Down Expand Up @@ -167,6 +169,7 @@ public enum ConfigurationKeys {
@Getter
public enum SettingCategory {
GENERAL("General settings"),
RESERVATION_UI("Reservation Process UI"),
PAYMENT("Payment"),
PAYMENT_STRIPE("Stripe.com settings"),
PAYMENT_PAYPAL("PayPal settings"),
Expand Down
10 changes: 5 additions & 5 deletions src/main/webapp/WEB-INF/templates/event/reservation-page.ms
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@
<div class="col-xs-12 col-sm-6">
<div class="form-group {{#field-has-error}}[firstName] has-error{{/field-has-error}}">
<label for="first-name" class="control-label">{{#i18n}}common.first-name{{/i18n}}</label>
<input type="text" name="firstName" id="first-name" required class="form-control" autocomplete="fname" maxlength="255" value="{{paymentForm.firstName}}">
<input type="text" name="firstName" id="first-name" required class="form-control {{#attendeeAutocompleteEnabled}}autocomplete-src{{/attendeeAutocompleteEnabled}}" autocomplete="fname" maxlength="255" value="{{paymentForm.firstName}}">
{{#field-has-error}}[firstName]<span class="help-block text-danger">{{#i18n}}{{#field-error}}firstName{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group {{#field-has-error}}[lastName] has-error{{/field-has-error}}">
<label for="last-name" class="control-label">{{#i18n}}common.last-name{{/i18n}}</label>
<input type="text" name="lastName" id="last-name" required class="form-control" autocomplete="lname" maxlength="255" value="{{paymentForm.lastName}}">
<input type="text" name="lastName" id="last-name" required class="form-control {{#attendeeAutocompleteEnabled}}autocomplete-src{{/attendeeAutocompleteEnabled}}" autocomplete="lname" maxlength="255" value="{{paymentForm.lastName}}">
{{#field-has-error}}[lastName]<span class="help-block text-danger">{{#i18n}}{{#field-error}}lastName{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
Expand All @@ -152,7 +152,7 @@
{{^useFirstAndLastName}}
<div class="form-group {{#field-has-error}}[fullName] has-error{{/field-has-error}}">
<label for="full-name" class="control-label">{{#i18n}}common.full-name{{/i18n}}</label>
<input type="text" name="fullName" id="full-name" required class="form-control" autocomplete="name" maxlength="255" value="{{paymentForm.fullName}}">
<input type="text" name="fullName" id="full-name" required class="form-control {{#attendeeAutocompleteEnabled}}autocomplete-src{{/attendeeAutocompleteEnabled}}" autocomplete="name" maxlength="255" value="{{paymentForm.fullName}}">
{{#field-has-error}}[fullName]<span class="help-block text-danger">{{#i18n}}{{#field-error}}fullName{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
{{/useFirstAndLastName}}
Expand All @@ -162,7 +162,7 @@
<div class="col-xs-12 {{#captchaRequestedFreeOfCharge}}col-md-6{{/captchaRequestedFreeOfCharge}}">
<div class="form-group {{#field-has-error}}[email] has-error{{/field-has-error}}">
<label for="email" class="control-label">{{#i18n}}common.email{{/i18n}}</label>
<input type="email" name="email" id="email" required class="form-control" autocomplete="email" maxlength="255" value="{{paymentForm.email}}">
<input type="email" name="email" id="email" required class="form-control {{#attendeeAutocompleteEnabled}}autocomplete-src{{/attendeeAutocompleteEnabled}}" autocomplete="email" maxlength="255" value="{{paymentForm.email}}">
{{#field-has-error}}[email]<span class="help-block text-danger">{{#i18n}}{{#field-error}}email{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
Expand Down Expand Up @@ -199,7 +199,7 @@
{{#ticketsByCategory}}
{{#value}}
<li class="list-group-item">
<h3><i class="fa fa-ticket"></i> {{#i18n}}reservation-page-complete.ticket-nr{{/i18n}}<span class="ticket-counter"></span> - <small>{{key.name}}</small> {{#-first}}<button type="button" id="copy-from-contact-data" class="btn btn-xs btn-default"><i class="fa fa-clone"></i> {{#i18n}}reservation-page.copy-attendee{{/i18n}}</button>{{/-first}}</h3>
<h3><i class="fa fa-ticket"></i> {{#i18n}}reservation-page-complete.ticket-nr{{/i18n}}<span class="ticket-counter"></span> <span class="hidden-xs hidden-xs">- <small>{{key.name}}</small></span>{{^attendeeAutocompleteEnabled}}{{#-first}}<button type="button" id="copy-from-contact-data" class="btn btn-xs btn-default tooltip-handler pull-right" title="{{#i18n}}reservation-page.copy-attendee{{/i18n}}"><i class="fa fa-clone"></i><span class="sr-only">{{#i18n}}reservation-page.copy-attendee{{/i18n}}</span></button>{{/-first}}{{/attendeeAutocompleteEnabled}}</h3>
<div class="form-horizontal">
<div data-collapse-enabled="true" class="collapsible-container">
{{> /event/attendee-fields }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ <h2>General</h2>
</div>
</div>

<div class="page-header">
<h2>Reservation Process</h2>
<span>Customizations for the public-facing reservation process</span>
</div>
<div>
<div data-ng-repeat="setting in eventConf.reservationUi.settings">
<setting data-obj="setting" data-display-delete-if-needed="true" data-delete-handler="eventConf.delete(config)"></setting>
</div>
</div>

<div class="page-header" data-ng-if="eventConf.mail">
<h2>E-Mail</h2>
<span>E-Mail settings <span class="label label-info">system</span></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ <h2>General</h2>
</div>
</div>

<div class="page-header">
<h2>Reservation Process</h2>
<span>Customizations for the public-facing reservation process</span>
</div>
<div>
<div data-ng-repeat="setting in organizationConf.reservationUi.settings">
<setting data-obj="setting" data-display-delete-if-needed="true" data-delete-handler="organizationConf.delete(config)"></setting>
</div>
</div>

<div class="page-header">
<h2>E-Mail</h2>
<span>E-Mail settings</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ <h2>General</h2>
</div>
</div>

<div class="page-header">
<h2>Reservation Process</h2>
<span>Customizations for the public-facing reservation process</span>
</div>
<div>
<div data-ng-repeat="setting in systemConf.reservationUi.settings">
<setting data-obj="setting" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)"></setting>
</div>
</div>

<div class="page-header">
<h2>E-Mail</h2>
<span>E-Mail settings</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
}
}

_.forEach(['PAYMENT', 'PAYMENT_STRIPE', 'PAYMENT_PAYPAL', /*'PAYMENT_MOLLIE',*/ 'PAYMENT_OFFLINE', 'INVOICE_EU', 'TRANSLATIONS', 'ALFIO_PI'], function(group) {
_.forEach(['PAYMENT', 'PAYMENT_STRIPE', 'PAYMENT_PAYPAL', /*'PAYMENT_MOLLIE',*/ 'PAYMENT_OFFLINE', 'INVOICE_EU', 'TRANSLATIONS', 'RESERVATION_UI', 'ALFIO_PI'], function(group) {
if(angular.isDefined(original[group]) && original[group].length > 0) {
transformed[_.camelCase(group)] = {
settings: original[group]
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/resources/js/event/bootstrap-handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
'use strict';
jQuery(function($) {
$('i.tooltip-handler').tooltip();
$('.tooltip-handler').tooltip();
});
})();
15 changes: 15 additions & 0 deletions src/main/webapp/resources/js/event/reservation-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@
});
}

$('#first-name.autocomplete-src, #last-name.autocomplete-src').change(function() {
fillAttendeeData($('#first-name').val(), $('#last-name').val());
});
$('#full-name.autocomplete-src').change(function() {
fillAttendeeData($(this).val());
});
$('#email.autocomplete-src').change(function() {
updateIfNotTouched($('#attendeesData').find('.attendee-email').first(), $(this).val());
});

$('#attendeesData').find('.attendee-full-name,.attendee-first-name,.attendee-last-name,.attendee-email').first()
.change(function() {
$(this).removeClass('untouched');
});

$('#copy-from-contact-data').click(function() {
var firstOrFullName = $('#first-name').val() || $('#full-name').val();
fillAttendeeData(firstOrFullName, $('#last-name').val());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ public void testSaveOnlyValidConfiguration() {
@Test
public void testLoadOrganizationConfiguration() {
Map<ConfigurationKeys.SettingCategory, List<Configuration>> orgConf = configurationManager.loadOrganizationConfig(event.getOrganizationId(), USERNAME);
assertEquals(9, orgConf.size());
assertFalse(orgConf.isEmpty());
assertEquals(ConfigurationKeys.byPathLevel(ConfigurationPathLevel.ORGANIZATION).size(), orgConf.values().stream().flatMap(Collection::stream).count());
String value = "MY-ACCOUNT_NUMBER";
configurationRepository.insertOrganizationLevel(event.getOrganizationId(), ConfigurationKeys.BANK_ACCOUNT_NR.getValue(), value, "empty");
orgConf = configurationManager.loadOrganizationConfig(event.getOrganizationId(), USERNAME);
assertEquals(9, orgConf.size());
assertFalse(orgConf.isEmpty());
assertEquals(ConfigurationKeys.byPathLevel(ConfigurationPathLevel.ORGANIZATION).size(), orgConf.values().stream().flatMap(Collection::stream).count());
assertEquals(value, orgConf.get(SettingCategory.PAYMENT_OFFLINE).stream().filter(c -> c.getConfigurationKey() == ConfigurationKeys.BANK_ACCOUNT_NR).findFirst().orElseThrow(IllegalStateException::new).getValue());
}
Expand Down

0 comments on commit 79f5d81

Please sign in to comment.