Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 610 posts 2409 karma points
    Feb 04, 2020 @ 22:18
    Bo Jacobsen
    0

    Is there a way to get all available mailing lists?

    Hi Markus.

    Is there a way i can get all available mailing lists, from either code or angluar?

    I am trying to make an Umbraco Forms WorkFlowType, with a custom attribute setting type, where the user can select the mailing list from a dropdown, instead of manually typing a number.

  • Bo Jacobsen 610 posts 2409 karma points
    Feb 05, 2020 @ 08:53
    Bo Jacobsen
    0

    I found a temporary solution.

    I found the nsServiceHelper after looking through ~/App_Plugins/NewsLetterStudio/assets/compiled folder.

    But i would like to know if there is a better approch, that are more future safe?

    I added mailinglist.html to ~/App_Plugins/UmbracoForms/Backoffice/Common/SettingTypes/

    <div ng-controller="Custom.SettingTypes.MailingListController">
        <select class="-full-width"
                ng-options="field.value as field.name for field in fields"
                ng-model="mailinglist"
                ng-change="changeValue()">
            <option value="">Choose a mailing list</option>
        </select>
    </div>
    

    Added javascript controller file to a package.manifest in a custom pluigin inside ~/App_Plugins/CustomPlugin/

    angular.module("umbraco").controller("Custom.SettingTypes.MailingListController",
        function ($scope, $routeParams, notificationsService, nsServiceHelper) {
    
            function init() {
    
                if ($scope.setting.value) {
                    $scope.mailinglist = $scope.setting.value;
                }
    
                var formId = $routeParams.id;
    
                if (formId === -1 && $scope.model && $scope.model.fields) {
    
                } else {
                    nsServiceHelper.http({
                        method: "GET",
                        url: "/backofficeApi/GetAllMailingLists"
                    }).success(function (response) {
                        $scope.fields = response;
                        console.log(response);
                        }).error(function () {
                            notificationsService.error("Load failed", "Could not load mailinglists from newsletter studio");
                    });
                }
            }
    
            $scope.changeValue= function () {
                $scope.setting.value = $scope.mailinglist;
            };
    
            init();
    
        });
    

    Now i can get the attribute setting inside a WorkFlowType

    [Umbraco.Forms.Core.Attributes.Setting("Mailing list", description = "Choose mailinglist to use", view = "mailinglist")]'
    public string MailingListId { get; set; }
    
  • Markus Johansson 1945 posts 5898 karma points MVP 2x c-trib
    Feb 06, 2020 @ 10:09
    Markus Johansson
    0

    Hi!

    Hmm, nsServiceHelper is basically a "wrapper" around $http that adds some error-handling and stuff.

    Since you're only interested in the internal mailing lists (Newsletter Studios own and not any lists from a external Subscription Providers) I think that you're best of by creating your own API controller and return the mailing lists.

    You can get them using our "Service Locator", something like this:

    GlobalFactory.Current.MailingListRepository.GetAll()
    

    Hope this points you in the right direction?

    By the way, there is also some code that you can look at in our Contrib-project: https://github.com/enkelmedia/NewsletterStudioContrib/tree/master/Newsletter%20Studio%20V2/NewsletterStudioContrib/UmbracoForms this is stuff that I created for some Meetup-presentation some years ago but I think that there should be valuable pointers in there.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies