use of com.willshex.blogwt.shared.api.datatype.Field in project blogwt by billy1380.
the class FormPart method onFormSubmit.
@UiHandler("frmForm")
void onFormSubmit(SubmitEvent se) {
if (isValid()) {
loading();
Form form = new Form();
form.name = name;
// add fields to form
final int count = pnlFields.getWidgetCount();
Widget current;
Field field;
for (int i = 0; i < count; i++) {
current = pnlFields.getWidget(i);
field = null;
if (current instanceof FormField) {
field = new Field().name(((FormField) current).name()).value(((FormField) current).value());
if (form.fields == null) {
form.fields = new ArrayList<Field>();
}
form.fields.add(field);
if (current instanceof TextBoxPart) {
field.type(FieldTypeType.FieldTypeTypeText);
} else if (current instanceof TextAreaPart) {
field.type(FieldTypeType.FieldTypeTypeLongText);
} else if (current instanceof ListBoxPart) {
field.type(FieldTypeType.FieldTypeTypeSingleOption);
} else if (current instanceof ReCaptchaPart) {
field.type(FieldTypeType.FieldTypeTypeCaptcha);
}
}
}
FormController.get().submitForm(form);
}
se.cancel();
}
use of com.willshex.blogwt.shared.api.datatype.Field in project blogwt by billy1380.
the class SubmitFormActionHandler method handle.
/* (non-Javadoc)
*
* @see
* com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
* gson.web.service.shared.Request,
* com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(SubmitFormRequest input, SubmitFormResponse output) throws Exception {
// send an email with the submitted fields
ApiValidator.request(input, SubmitFormRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
if (input.session != null) {
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
}
input.form = FormValidator.validate(input.form, "input.form");
Property email = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.OUTGOING_EMAIL);
Property title = PropertyServiceProvider.provide().getNamedProperty(PropertyHelper.TITLE);
StringBuffer body = new StringBuffer();
for (Field field : input.form.fields) {
if (field.type != FieldTypeType.FieldTypeTypeCaptcha) {
body.append(field.name);
body.append(":");
body.append(field.value);
body.append("\n\n");
}
}
if (!EmailHelper.sendEmail(email.value, title.value, "Submit form", body.toString(), false))
ApiValidator.throwServiceError(ServiceException.class, ApiError.FailedToSendEmail, "input.form");
}
Aggregations