Search in sources :

Example 1 with ICRMGroup

use of com.helger.peppol.crm.ICRMGroup in project peppol-practical by phax.

the class PageSecureCRMGroup method showListOfExistingObjects.

@Override
protected void showListOfExistingObjects(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    // Toolbar on top
    final BootstrapButtonToolbar aToolbar = aNodeList.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addButtonNew("Create new CRM group", createCreateURL(aWPEC));
    // List existing
    final HCTable aTable = new HCTable(new DTCol("Name").setInitialSorting(ESortOrder.ASCENDING), new DTCol("Sender email address"), new BootstrapDTColAction(aDisplayLocale)).setID(getID());
    for (final ICRMGroup aCurObject : aCRMGroupMgr.getAll()) {
        final ISimpleURL aViewLink = createViewURL(aWPEC, aCurObject);
        final HCRow aRow = aTable.addBodyRow();
        aRow.addCell(new HCA(aViewLink).addChild(aCurObject.getDisplayName()));
        aRow.addCell(aCurObject.getSenderEmailAddress());
        aRow.addCell(createEditLink(aWPEC, aCurObject), new HCTextNode(" "), createCopyLink(aWPEC, aCurObject));
    }
    aNodeList.addChild(aTable);
    final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
    aNodeList.addChild(aDataTables);
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCA(com.helger.html.hc.html.textlevel.HCA) HCRow(com.helger.html.hc.html.tabular.HCRow) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) HCTable(com.helger.html.hc.html.tabular.HCTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapDTColAction(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDTColAction) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) HCTextNode(com.helger.html.hc.impl.HCTextNode) ICRMGroup(com.helger.peppol.crm.ICRMGroup) DataTables(com.helger.photon.uictrls.datatables.DataTables) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)

Example 2 with ICRMGroup

use of com.helger.peppol.crm.ICRMGroup in project peppol-practical by phax.

the class PageSecureCRMSubscriber method showSelectedObject.

@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, final ICRMSubscriber aSelectedObject) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final BootstrapViewForm aForm = aNodeList.addAndReturnChild(new BootstrapViewForm());
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Status").setCtrl(aSelectedObject.isDeleted() ? "Deleted" : "Active"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Salutation").setCtrl(aSelectedObject.getSalutationDisplayName(aDisplayLocale)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Name").setCtrl(aSelectedObject.getName()));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Email address").setCtrl(aSelectedObject.getEmailAddress()));
    {
        final HCNodeList aGroups = new HCNodeList();
        for (final ICRMGroup aCRMGroup : CollectionHelper.getSorted(aSelectedObject.getAllAssignedGroups(), IHasDisplayName.getComparatorCollating(aDisplayLocale))) aGroups.addChild(div(new HCA(createViewURL(aWPEC, CMenuSecure.MENU_CRM_GROUPS, aCRMGroup)).addChild(aCRMGroup.getDisplayName())));
        aForm.addFormGroup(new BootstrapFormGroup().setLabel("Assigned groups").setCtrl(aGroups));
    }
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCA(com.helger.html.hc.html.textlevel.HCA) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) ICRMGroup(com.helger.peppol.crm.ICRMGroup)

Example 3 with ICRMGroup

use of com.helger.peppol.crm.ICRMGroup in project peppol-practical by phax.

the class PagePublicNewsletterSubscribe method fillContent.

@Override
protected void fillContent(final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final FormErrorList aFormErrors = new FormErrorList();
    ICommonsList<String> aSelectedCRMGroupIDs = null;
    if (aWPEC.hasAction(CPageParam.ACTION_SAVE)) {
        final String sSalutationID = aWPEC.params().getAsString(FIELD_SALUTATION);
        final ESalutation eSalutation = ESalutation.getFromIDOrNull(sSalutationID);
        final String sName = aWPEC.params().getAsString(FIELD_NAME);
        final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL_ADDRESS);
        aSelectedCRMGroupIDs = aWPEC.params().getAsStringList(FIELD_GROUP);
        final ICommonsSet<ICRMGroup> aSelectedCRMGroups = new CommonsHashSet<>();
        ICRMSubscriber aSameEmailAddressSubscriber = null;
        if (StringHelper.hasNoText(sName))
            aFormErrors.addFieldError(FIELD_NAME, "You must provide your name!");
        if (StringHelper.hasNoText(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "You must provide your email address!");
        else if (!EmailAddressHelper.isValid(sEmailAddress))
            aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
        else {
            // Check if the email address is already in use
            aSameEmailAddressSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
        }
        if (aSelectedCRMGroupIDs != null)
            for (final String sCRMGroupID : aSelectedCRMGroupIDs) {
                final ICRMGroup aGroup = aCRMGroupMgr.getCRMGroupOfID(sCRMGroupID);
                if (aGroup == null)
                    aFormErrors.addFieldError(FIELD_GROUP, "The selected mailing list is not existing!");
                else
                    aSelectedCRMGroups.add(aGroup);
            }
        if (aSelectedCRMGroups.isEmpty())
            aFormErrors.addFieldError(FIELD_GROUP, "At least one mailing list must be selected!");
        else {
            if (aSameEmailAddressSubscriber != null) {
                // Merge with existing subscriber
                aSelectedCRMGroups.addAll(aSameEmailAddressSubscriber.getAllAssignedGroups());
            }
        }
        if (aFormErrors.isEmpty()) {
            // Save
            if (aSameEmailAddressSubscriber == null) {
                // Create a new one
                aCRMSubscriberMgr.createCRMSubscriber(eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            } else {
                // Update an existing one
                aCRMSubscriberMgr.updateCRMSubscriber(aSameEmailAddressSubscriber.getID(), eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            }
            aNodeList.addChild(success("Successfully subscribed '" + sEmailAddress + "' to mailing lists"));
        } else {
            aNodeList.addChild(getUIHandler().createIncorrectInputBox(aWPEC));
        }
    }
    final BootstrapForm aForm = getUIHandler().createFormSelf(aWPEC);
    aForm.setLeft(3);
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Your salutation").setCtrl(new HCSalutationSelect(new RequestField(FIELD_SALUTATION), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_SALUTATION)));
    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_ADDRESS))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL_ADDRESS)));
    {
        final ICommonsList<? extends ICRMGroup> aAllCRMGroups = aCRMGroupMgr.getAll();
        if (aAllCRMGroups.size() == 1) {
            // No need for selection - use hidden field
            aForm.addChild(new HCHiddenField(FIELD_GROUP, aAllCRMGroups.getFirst().getID()));
        } else if (aAllCRMGroups.isNotEmpty()) {
            // Show selection
            final HCNodeList aGroups = new HCNodeList();
            for (final ICRMGroup aCRMGroup : aAllCRMGroups.getSorted(IHasDisplayName.getComparatorCollating(aDisplayLocale))) {
                final String sCRMGroupID = aCRMGroup.getID();
                final RequestFieldBooleanMultiValue aRFB = new RequestFieldBooleanMultiValue(FIELD_GROUP, sCRMGroupID, false);
                aGroups.addChild(new HCDiv().addChild(new HCCheckBox(aRFB)).addChild(" " + aCRMGroup.getDisplayName()));
            }
            aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Mailing lists to subscribe to").setCtrl(aGroups).setErrorList(aFormErrors.getListOfField(FIELD_GROUP)));
        }
    }
    // Toolbar
    final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aWPEC));
    aToolbar.addHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_SAVE);
    aToolbar.addSubmitButton("Subscribe", EDefaultIcon.YES);
    aNodeList.addChild(aForm);
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) RequestFieldBooleanMultiValue(com.helger.photon.core.form.RequestFieldBooleanMultiValue) ICommonsList(com.helger.commons.collection.impl.ICommonsList) HCNodeList(com.helger.html.hc.impl.HCNodeList) ESalutation(com.helger.masterdata.person.ESalutation) HCHiddenField(com.helger.html.hc.html.forms.HCHiddenField) FormErrorList(com.helger.photon.core.form.FormErrorList) HCEdit(com.helger.html.hc.html.forms.HCEdit) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) BootstrapForm(com.helger.photon.bootstrap4.form.BootstrapForm) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICRMGroup(com.helger.peppol.crm.ICRMGroup) HCSalutationSelect(com.helger.photon.uicore.html.select.HCSalutationSelect) RequestField(com.helger.photon.core.form.RequestField)

Example 4 with ICRMGroup

use of com.helger.peppol.crm.ICRMGroup in project peppol-practical by phax.

the class PageSecureCRMSubscriber method validateAndSaveInputParameters.

@Override
protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ICRMSubscriber aSelectedObject, @Nonnull final FormErrorList aFormErrors, @Nonnull final EWebPageFormAction eFormAction) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    final CRMSubscriberManager aCRMSubscriberMgr = PPMetaManager.getCRMSubscriberMgr();
    final String sSalutationID = aWPEC.params().getAsString(FIELD_SALUTATION);
    final ESalutation eSalutation = ESalutation.getFromIDOrNull(sSalutationID);
    final String sName = aWPEC.params().getAsString(FIELD_NAME);
    final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL_ADDRESS);
    final ICommonsList<String> aSelectedCRMGroupIDs = aWPEC.params().getAsStringList(FIELD_GROUP);
    final ICommonsSet<ICRMGroup> aSelectedCRMGroups = new CommonsHashSet<>();
    if (StringHelper.hasNoText(sName))
        aFormErrors.addFieldError(FIELD_NAME, "A name for the CRM subscriber must be provided!");
    if (StringHelper.hasNoText(sEmailAddress))
        aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "An email address must be provided!");
    else if (!EmailAddressHelper.isValid(sEmailAddress))
        aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "The provided email address is invalid!");
    else {
        final ICRMSubscriber aSameEmailAddresSubscriber = aCRMSubscriberMgr.getCRMSubscriberOfEmailAddress(sEmailAddress);
        if (aSameEmailAddresSubscriber != null) {
            if (!eFormAction.isEdit() || aSameEmailAddresSubscriber != aSelectedObject)
                aFormErrors.addFieldError(FIELD_EMAIL_ADDRESS, "A subscription for the provided email address is already present!");
        }
    }
    if (aSelectedCRMGroupIDs != null)
        for (final String sCRMGroupID : aSelectedCRMGroupIDs) {
            final ICRMGroup aGroup = aCRMGroupMgr.getCRMGroupOfID(sCRMGroupID);
            if (aGroup == null)
                aFormErrors.addFieldError(FIELD_GROUP, "The selected group is not existing!");
            else
                aSelectedCRMGroups.add(aGroup);
        }
    if (aSelectedCRMGroups.isEmpty())
        aFormErrors.addFieldError(FIELD_GROUP, "At least one group must be selected!");
    if (aFormErrors.isEmpty()) {
        // All fields are valid -> save
        if (eFormAction.isEdit()) {
            // We're editing an existing object
            aCRMSubscriberMgr.updateCRMSubscriber(aSelectedObject.getID(), eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            aNodeList.addChild(success("The CRM subscriber was successfully edited!"));
        } else {
            // We're creating a new object
            aCRMSubscriberMgr.createCRMSubscriber(eSalutation, sName, sEmailAddress, aSelectedCRMGroups);
            aNodeList.addChild(success("The new CRM subscriber was successfully created!"));
        }
    }
}
Also used : CRMSubscriberManager(com.helger.peppol.crm.CRMSubscriberManager) HCNodeList(com.helger.html.hc.impl.HCNodeList) ESalutation(com.helger.masterdata.person.ESalutation) ICRMSubscriber(com.helger.peppol.crm.ICRMSubscriber) PDTToString(com.helger.commons.datetime.PDTToString) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) CommonsHashSet(com.helger.commons.collection.impl.CommonsHashSet) ICRMGroup(com.helger.peppol.crm.ICRMGroup)

Example 5 with ICRMGroup

use of com.helger.peppol.crm.ICRMGroup in project peppol-practical by phax.

the class PageSecureCRMSubscriber method showInputForm.

@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ICRMSubscriber aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
    final CRMGroupManager aCRMGroupMgr = PPMetaManager.getCRMGroupMgr();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    aForm.addChild(getUIHandler().createActionHeader(eFormAction.isEdit() ? "Edit CRM subscriber" : "Create new CRM subscriber"));
    aForm.addFormGroup(new BootstrapFormGroup().setLabel("Salutation").setCtrl(new HCSalutationSelect(new RequestField(FIELD_SALUTATION, aSelectedObject == null ? null : aSelectedObject.getSalutationID()), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_SALUTATION)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(FIELD_NAME, aSelectedObject == null ? null : aSelectedObject.getName()))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
    aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL_ADDRESS, aSelectedObject == null ? null : aSelectedObject.getEmailAddress()))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL_ADDRESS)));
    {
        final HCNodeList aGroups = new HCNodeList();
        for (final ICRMGroup aCRMGroup : aCRMGroupMgr.getAll().getSortedInline(IHasDisplayName.getComparatorCollating(aDisplayLocale))) {
            final String sCRMGroupID = aCRMGroup.getID();
            final RequestFieldBooleanMultiValue aRFB = new RequestFieldBooleanMultiValue(FIELD_GROUP, sCRMGroupID, aSelectedObject != null && aSelectedObject.isAssignedToGroup(aCRMGroup));
            aGroups.addChild(div(new HCCheckBox(aRFB).setValue(sCRMGroupID)).addChild(" " + aCRMGroup.getDisplayName()));
        }
        aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Assigned groups").setCtrl(aGroups).setErrorList(aFormErrors.getListOfField(FIELD_GROUP)));
    }
}
Also used : Locale(java.util.Locale) RequestFieldBooleanMultiValue(com.helger.photon.core.form.RequestFieldBooleanMultiValue) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCEdit(com.helger.html.hc.html.forms.HCEdit) PDTToString(com.helger.commons.datetime.PDTToString) HCCheckBox(com.helger.html.hc.html.forms.HCCheckBox) CRMGroupManager(com.helger.peppol.crm.CRMGroupManager) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) HCSalutationSelect(com.helger.photon.uicore.html.select.HCSalutationSelect) ICRMGroup(com.helger.peppol.crm.ICRMGroup) RequestField(com.helger.photon.core.form.RequestField)

Aggregations

HCNodeList (com.helger.html.hc.impl.HCNodeList)5 ICRMGroup (com.helger.peppol.crm.ICRMGroup)5 CRMGroupManager (com.helger.peppol.crm.CRMGroupManager)4 Locale (java.util.Locale)4 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)3 CommonsHashSet (com.helger.commons.collection.impl.CommonsHashSet)2 PDTToString (com.helger.commons.datetime.PDTToString)2 HCCheckBox (com.helger.html.hc.html.forms.HCCheckBox)2 HCEdit (com.helger.html.hc.html.forms.HCEdit)2 HCA (com.helger.html.hc.html.textlevel.HCA)2 ESalutation (com.helger.masterdata.person.ESalutation)2 CRMSubscriberManager (com.helger.peppol.crm.CRMSubscriberManager)2 ICRMSubscriber (com.helger.peppol.crm.ICRMSubscriber)2 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)2 RequestField (com.helger.photon.core.form.RequestField)2 RequestFieldBooleanMultiValue (com.helger.photon.core.form.RequestFieldBooleanMultiValue)2 HCSalutationSelect (com.helger.photon.uicore.html.select.HCSalutationSelect)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1 ISimpleURL (com.helger.commons.url.ISimpleURL)1 HCHiddenField (com.helger.html.hc.html.forms.HCHiddenField)1