Copied to clipboard

Flag this post as spam?

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


  • John B 5 posts 75 karma points
    Jul 01, 2016 @ 08:55
    John B
    0

    Custom property editor - get current alias

    Hi all! So my problem: I'm making my own property editor for ucommerce. So i've made view,controller and resource for that. And i need to send to my api controller current editor alias (on node) to get it's value. For now i hardcoded that ("CountryPickerAlias") - and it's not good idea :) so do anybody know - how i could get that in angular.controller?

    My code:

    resourse.js :

    angular.module('umbraco.resources').factory('countryResource',
    function ($q, $http) {
        //the factory object returned
        return {
            //this cals the Api Controller we setup earlier
            getAll: function (nodeId) {
                return $http.get("backoffice/My/CountriesPlugin/GetAll?nodeId="+nodeId);
            }
        };
    }
    

    );

    CountriesPluginController:

    public IEnumerable<PluginCountry> GetAll(int nodeId)
        {
            var systems = TransactionLibrary.GetCountries().Select(p => new PluginCountry {Id = p.CountryId, Title = p.Name}).ToList();
            var current = new List<PluginCountry>();
            if (nodeId != 0)
            {
                UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                IPublishedContent thisPage = umbracoHelper.TypedContent(nodeId);
    
                var checkboxListString = string.Empty;
                if (thisPage != null)
                {
                    checkboxListString = thisPage.GetPropertyValue<string>("CountryPickerAlias");
                    if (checkboxListString != null && checkboxListString != string.Empty)
                    {
                        checkboxListString = checkboxListString.Replace("\"", string.Empty);
                    }
                }
    
                if (!string.IsNullOrEmpty(checkboxListString))
                {
                    try
                    {
                        current = JsonConvert.DeserializeObject<List<PluginCountry>>(checkboxListString);
                    }
                    catch (Exception ex)
                    { }  
                }
            }
            return CompareLists(current, systems);
        }
    

    and angular.controller

    angular.module("umbraco")
    .controller("My.uCommerceCountryPickerController", function ($scope, countryResource, $routeParams) {
        var nodeId = $routeParams.id;
        countryResource.getAll(nodeId).then(function (response) {
            $scope.countries = response.data;
        });
    
        $scope.$on("formSubmitting", function (ev, args) {
            $scope.model.value = [];
    
            var selectedExamples = "";
            angular.forEach($scope.countries, function (value, key) {
                var itemId = "{ Id : " + value.Id;
                var itemSelected = "Selected : " + value.Selected;
                var itemTitle = "Title : '" + value.Title + "'}, ";
                selectedExamples = selectedExamples + itemId.concat(", ", itemSelected).concat(", ", itemTitle);
            });
            console.log(selectedExamples);
            $scope.model.value.push(selectedExamples);
        });
    });
    
  • John B 5 posts 75 karma points
    Jul 01, 2016 @ 09:35
    John B
    0

    So while it was on approving - i've found solution :D And it is:

    in angular controller:

    $scope.model.alias
    

    heh :) but for now i have another question. Is it possible to create package for property editor to easy install it in other projects ?

Please Sign in or register to post replies

Write your reply to:

Draft