Search in sources :

Example 1 with BootstrapSubmitButton

use of com.helger.photon.bootstrap4.button.BootstrapSubmitButton in project phoss-directory by phax.

the class PagePublicContact method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final boolean bShowForm = true;
    final FormErrorList aFormErrors = new FormErrorList();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        final String sName = StringHelper.trim(aWPEC.params().getAsString(FIELD_NAME));
        final String sEmail = StringHelper.trim(aWPEC.params().getAsString(FIELD_EMAIL));
        final String sTopic = aWPEC.params().getAsString(FIELD_TOPIC);
        final String sText = StringHelper.trim(aWPEC.params().getAsString(FIELD_TEXT));
        final String sReCaptcha = StringHelper.trim(aWPEC.params().getAsString("g-recaptcha-response"));
        if (StringHelper.hasNoText(sName))
            aFormErrors.addFieldError(FIELD_NAME, "Your name must be provided.");
        if (StringHelper.hasNoText(sEmail))
            aFormErrors.addFieldError(FIELD_EMAIL, "Your email address must be provided.");
        else if (!EmailAddressHelper.isValid(sEmail))
            aFormErrors.addFieldError(FIELD_EMAIL, "The provided email address is invalid.");
        if (StringHelper.hasNoText(sText))
            aFormErrors.addFieldError(FIELD_TEXT, "A message text must be provided.");
        if (aFormErrors.isEmpty() || StringHelper.hasText(sReCaptcha)) {
            if (!CaptchaSessionSingleton.getInstance().isChecked()) {
                // Check only if no other errors occurred
                if (ReCaptchaServerSideValidator.check("6LfZFS0UAAAAAONDJHyDnuUUvMB_oNmJxz9Utxza", sReCaptcha).isFailure())
                    aFormErrors.addFieldError(FIELD_CAPTCHA, "Please confirm you are not a robot!");
                else
                    CaptchaSessionSingleton.getInstance().setChecked();
            }
        }
        if (aFormErrors.isEmpty()) {
            final EmailData aEmailData = new EmailData(EEmailType.TEXT);
            aEmailData.setFrom(CPDPublisher.EMAIL_SENDER);
            aEmailData.to().add(new EmailAddress("pd@helger.com"));
            aEmailData.replyTo().add(new EmailAddress(sEmail, sName));
            aEmailData.setSubject("[" + CPDPublisher.getApplication() + "] Contact Form - " + sName);
            final StringBuilder aSB = new StringBuilder();
            aSB.append("Contact form from " + CPDPublisher.getApplication() + " was filled out.\n\n");
            aSB.append("Name: ").append(sName).append("\n");
            aSB.append("Email: ").append(sEmail).append("\n");
            aSB.append("Topic: ").append(sTopic).append("\n");
            aSB.append("Text:\n").append(sText).append("\n");
            aEmailData.setBody(aSB.toString());
            ScopedMailAPI.getInstance().queueMail(InternalErrorSettings.getSMTPSettings(), aEmailData);
            aWPEC.postRedirectGetInternal(success("Thank you for your message. We will come back to you asap."));
        }
    }
    if (bShowForm) {
        aNodeList.addChild(info("Alternatively write an email to pd[at]helger.com - usually using the below form is more effective!"));
        aNodeList.addChild(warn("Please don't request any change of data via this contact form - contact your service provider instead. Thank you."));
        final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your name").setCtrl(new HCEdit(new RequestField(FIELD_NAME))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL)));
        final HCExtSelect aSelect = new HCExtSelect(new RequestField(FIELD_TOPIC));
        aSelect.addOption("SMP integration");
        aSelect.addOption("Website");
        aSelect.addOption("REST service");
        aSelect.addOption("SMP Statement of use");
        aSelect.addOption("General question");
        aSelect.addOptionPleaseSelect(aDisplayLocale);
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Topic").setCtrl(aSelect).setErrorList(aFormErrors.getListOfField(FIELD_TOPIC)));
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your message").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_TEXT)).setRows(5)).setErrorList(aFormErrors.getListOfField(FIELD_TEXT)));
        if (!CaptchaSessionSingleton.getInstance().isChecked()) {
            // Add visible Captcha
            aForm.addFormGroup(new BootstrapFormGroup().setCtrl(HCReCaptchaV2.create("6LfZFS0UAAAAAJaqpHJdFS_xxY7dqMQjXoBIQWOD", aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_CAPTCHA)));
        }
        aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
        aForm.addChild(new BootstrapSubmitButton().addChild("Send message").setIcon(EDefaultIcon.YES));
        aForm.addChild(new BootstrapButton().addChild("No thanks").setIcon(EDefaultIcon.CANCEL).setOnClick(aWPEC.getLinkToMenuItem(CMenuPublic.MENU_SEARCH_SIMPLE)));
    }
}
Also used : Locale(java.util.Locale) HCExtSelect(com.helger.photon.uicore.html.select.HCExtSelect) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) HCTextAreaAutosize(com.helger.photon.uictrls.autosize.HCTextAreaAutosize) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) EmailData(com.helger.smtp.data.EmailData) EmailAddress(com.helger.commons.email.EmailAddress) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) RequestField(com.helger.photon.core.form.RequestField)

Example 2 with BootstrapSubmitButton

use of com.helger.photon.bootstrap4.button.BootstrapSubmitButton in project phoss-smp by phax.

the class PageSecureServiceGroupImport method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPSettings aSettings = SMPMetaManager.getSettings();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final ICommonsSet<String> aAllServiceGroupIDs = aServiceGroupMgr.getAllSMPServiceGroupIDs();
    final ICommonsSet<String> aAllBusinessCardIDs = aBusinessCardMgr.getAllSMPBusinessCardIDs();
    final FormErrorList aFormErrors = new FormErrorList();
    final HCUL aImportResultUL = new HCUL();
    if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
        // Start import
        final IFileItem aImportFile = aWPEC.params().getAsFileItem(FIELD_IMPORT_FILE);
        final boolean bOverwriteExisting = aWPEC.params().isCheckBoxChecked(FIELD_OVERWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING);
        final String sDefaultOwnerID = aWPEC.params().getAsString(FIELD_DEFAULT_OWNER);
        final IUser aDefaultOwner = aUserMgr.getActiveUserOfID(sDefaultOwnerID);
        if (aImportFile == null || aImportFile.getSize() == 0)
            aFormErrors.addFieldError(FIELD_IMPORT_FILE, "A file to import must be selected!");
        if (StringHelper.hasNoText(sDefaultOwnerID))
            aFormErrors.addFieldError(FIELD_DEFAULT_OWNER, "A default owner must be selected!");
        else if (aDefaultOwner == null)
            aFormErrors.addFieldError(FIELD_DEFAULT_OWNER, "A valid default owner must be selected!");
        if (aFormErrors.isEmpty()) {
            final SAXReaderSettings aSRS = new SAXReaderSettings();
            final IMicroDocument aDoc = MicroReader.readMicroXML(aImportFile, aSRS);
            if (aDoc == null || aDoc.getDocumentElement() == null)
                aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file is not a valid XML file!");
            else {
                // Start interpreting
                final String sVersion = aDoc.getDocumentElement().getAttributeValue(CSMPExchange.ATTR_VERSION);
                if (CSMPExchange.VERSION_10.equals(sVersion)) {
                    // Version 1.0
                    final ICommonsList<ImportActionItem> aActionList = new CommonsArrayList<>();
                    final ImportSummary aImportSummary = new ImportSummary();
                    ServiceGroupImport.importXMLVer10(aDoc.getDocumentElement(), bOverwriteExisting, aDefaultOwner, aAllServiceGroupIDs, aAllBusinessCardIDs, aActionList, aImportSummary);
                    for (final ImportActionItem aAction : aActionList) {
                        final IErrorLevel aErrorLevel = aAction.getErrorLevel();
                        final EBootstrapBadgeType eBadgeType;
                        if (aErrorLevel.isGE(EErrorLevel.ERROR))
                            eBadgeType = EBootstrapBadgeType.DANGER;
                        else if (aErrorLevel.isGE(EErrorLevel.WARN))
                            eBadgeType = EBootstrapBadgeType.WARNING;
                        else if (aErrorLevel.isGE(EErrorLevel.INFO))
                            eBadgeType = EBootstrapBadgeType.INFO;
                        else
                            eBadgeType = EBootstrapBadgeType.SUCCESS;
                        // By default is is centered
                        aImportResultUL.addItem(new BootstrapBadge(eBadgeType).addChild((aAction.hasParticipantID() ? "[" + aAction.getParticipantID() + "] " : "") + aAction.getMessage()).addChild(SMPCommonUI.getTechnicalDetailsUI(aAction.getLinkedException())).addClass(CBootstrapCSS.TEXT_LEFT));
                    }
                } else {
                    // Unsupported or no version present
                    if (sVersion == null)
                        aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file cannot be imported because it has the wrong layout.");
                    else
                        aFormErrors.addFieldError(FIELD_IMPORT_FILE, "The provided file contains the unsupported version '" + sVersion + "'.");
                }
            }
        }
    }
    final boolean bHandleBusinessCards = aSettings.isDirectoryIntegrationEnabled();
    if (aImportResultUL.hasChildren()) {
        final BootstrapCard aPanel = new BootstrapCard();
        aPanel.createAndAddHeader().addChild("Import results");
        aPanel.createAndAddBody().addChild(aImportResultUL);
        aNodeList.addChild(aPanel);
    }
    aNodeList.addChild(info("Import service groups incl. all endpoints" + (bHandleBusinessCards ? " and business cards" : "") + " from a file."));
    final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormFileUploadSelf(aWPEC));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("File to import").setCtrl(new BootstrapFileUpload(FIELD_IMPORT_FILE, aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_IMPORT_FILE)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Overwrite existing elements").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_OVERWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING))).setHelpText("If this box is checked, all existing endpoints etc. of a service group are deleted and new endpoints are created! If the " + SMPWebAppConfiguration.getDirectoryName() + " integration is enabled, existing business cards contained in the import are also overwritten!").setErrorList(aFormErrors.getListOfField(FIELD_OVERWRITE_EXISTING)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Owner of the new service groups").setCtrl(new HCUserSelect(new RequestField(FIELD_DEFAULT_OWNER), aDisplayLocale)).setHelpText("This owner is only selected, if the owner contained in the import file is unknown.").setErrorList(aFormErrors.getListOfField(FIELD_DEFAULT_OWNER)));
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(getUIHandler().createToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM);
    aToolbar.addChild(new BootstrapSubmitButton().addChild("Import Service Groups").setIcon(EDefaultIcon.ADD));
}
Also used : Locale(java.util.Locale) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) IUserManager(com.helger.photon.security.user.IUserManager) ImportSummary(com.helger.phoss.smp.exchange.ImportSummary) RequestFieldBoolean(com.helger.photon.core.form.RequestFieldBoolean) FormErrorList(com.helger.photon.core.form.FormErrorList) ImportActionItem(com.helger.phoss.smp.exchange.ImportActionItem) SAXReaderSettings(com.helger.xml.serialize.read.SAXReaderSettings) BootstrapFileUpload(com.helger.photon.bootstrap4.uictrls.ext.BootstrapFileUpload) IFileItem(com.helger.web.fileupload.IFileItem) IUser(com.helger.photon.security.user.IUser) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) RequestField(com.helger.photon.core.form.RequestField) BootstrapCard(com.helger.photon.bootstrap4.card.BootstrapCard) BootstrapBadge(com.helger.photon.bootstrap4.badge.BootstrapBadge) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCUserSelect(com.helger.phoss.smp.ui.secure.hc.HCUserSelect) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) HCUL(com.helger.html.hc.html.grouping.HCUL) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) EBootstrapBadgeType(com.helger.photon.bootstrap4.badge.EBootstrapBadgeType) IErrorLevel(com.helger.commons.error.level.IErrorLevel) IMicroDocument(com.helger.xml.microdom.IMicroDocument) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 3 with BootstrapSubmitButton

use of com.helger.photon.bootstrap4.button.BootstrapSubmitButton in project phoss-directory by phax.

the class PagePublicSearchSimple method _createInitialSearchForm.

@Nonnull
private BootstrapRow _createInitialSearchForm(final WebPageExecutionContext aWPEC) {
    final HCForm aBigQueryBox = new HCForm().setAction(aWPEC.getSelfHref()).setMethod(EHCFormMethod.GET);
    final HCEdit aQueryEdit = _createQueryEdit();
    aBigQueryBox.addChild(div(aQueryEdit).addClass(CSS_CLASS_BIG_QUERY_BOX));
    {
        final String sHelpText = "Enter the name, address, ID or any other keyword of the entity you are looking for.";
        if (UI_MODE.isUseHelptext())
            aBigQueryBox.addChild(div(sHelpText).addClass(CSS_CLASS_BIG_QUERY_HELPTEXT));
        else
            aQueryEdit.setPlaceholder(sHelpText);
    }
    {
        final BootstrapButton aButton = new BootstrapSubmitButton().addChild("Search " + CPDPublisher.getApplication()).setIcon(EDefaultIcon.MAGNIFIER);
        if (UI_MODE.isUseGreenButton())
            aButton.setButtonType(EBootstrapButtonType.SUCCESS);
        aBigQueryBox.addChild(new HCDiv().addClass(CSS_CLASS_BIG_QUERY_BUTTONS).addChild(aButton));
    }
    final BootstrapRow aBodyRow = new BootstrapRow();
    aBodyRow.createColumn(-1, -1, 1, 2, 3).addClasses(CBootstrapCSS.D_NONE, CBootstrapCSS.D_MD_BLOCK);
    aBodyRow.createColumn(12, 12, 10, 8, 6).addChild(aBigQueryBox);
    aBodyRow.createColumn(-1, -1, 1, 2, 3).addClasses(CBootstrapCSS.D_NONE, CBootstrapCSS.D_MD_BLOCK);
    return aBodyRow;
}
Also used : HCDiv(com.helger.html.hc.html.grouping.HCDiv) HCForm(com.helger.html.hc.html.forms.HCForm) BootstrapRow(com.helger.photon.bootstrap4.grid.BootstrapRow) HCEdit(com.helger.html.hc.html.forms.HCEdit) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) BootstrapSubmitButton(com.helger.photon.bootstrap4.button.BootstrapSubmitButton) Nonnull(javax.annotation.Nonnull)

Aggregations

BootstrapSubmitButton (com.helger.photon.bootstrap4.button.BootstrapSubmitButton)3 HCEdit (com.helger.html.hc.html.forms.HCEdit)2 HCNodeList (com.helger.html.hc.impl.HCNodeList)2 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)2 BootstrapForm (com.helger.photon.bootstrap4.form.BootstrapForm)2 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)2 FormErrorList (com.helger.photon.core.form.FormErrorList)2 RequestField (com.helger.photon.core.form.RequestField)2 Locale (java.util.Locale)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 EmailAddress (com.helger.commons.email.EmailAddress)1 IErrorLevel (com.helger.commons.error.level.IErrorLevel)1 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)1 HCForm (com.helger.html.hc.html.forms.HCForm)1 HCHiddenField (com.helger.html.hc.html.forms.HCHiddenField)1 HCDiv (com.helger.html.hc.html.grouping.HCDiv)1 HCUL (com.helger.html.hc.html.grouping.HCUL)1 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)1 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)1 ImportActionItem (com.helger.phoss.smp.exchange.ImportActionItem)1