Copied to clipboard

Flag this post as spam?

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


  • Stefano Beretta 102 posts 247 karma points
    Nov 19, 2018 @ 14:25
    Stefano Beretta
    0

    Reuse Nested Content and nuPicker in Custom dashboard

    Hi everyone!

    I'm trying to reuse 2 data types I've created: one nested content (composed by 2 fluidity entity picker) and one nupicker typeahead list picker inside a custom dashboard.

    I followed the examples I've found in some threads (e.g. using the DatatypeController of UmbUkFestival2014.sln to get view and configuration of the editors) but for these two properties the 'value' is always undefined.

    I did the same for a third property, a switcher (Our.Umbraco.Switcher) and the configuration works fine.

    My view:

    <div class="CustomWelcomeDashboard-dashboard" ng-controller="CustomWelcomeDashboardController">
        <umb-editor model="gender"></umb-editor>
        <umb-editor model="countryPicker"></umb-editor>
        <umb-editor model="roles"></umb-editor>
    </div>
    

    And my controller:

    angular.module("umbraco").controller("CustomWelcomeDashboardController",
        function ($scope, datatypeResource) {
    
        //init
        $scope.value = {
            gender: 0,
            roles: [],
            name: '',
            email: '',
            year: 0,
            ldap: '',
            userid: '',
            country: ''
        };
        $scope.countryPicker = {};
        $scope.gender = {};
        $scope.roles = {};
        $scope.loaded = 3;
    
        //watch gender: OK
        $scope.$watch('gender', function () {
    
            if ($scope.gender !== undefined) {
                $scope.value.gender = $scope.gender.value;
            }
        }, true);
    
        //watch country: KO, never triggers
        $scope.$watch('countryPicker', function () {
    
            if ($scope.countryPicker !== undefined) {
                $scope.value.country = $scope.countryPicker.value;
            }
        }, true);
    
        //watch roles: KO, never triggers
        $scope.$watch('roles', function () {
            if ($scope.roles !== undefined) {
                $scope.value.roles = $scope.roles.value;
            }
        }, true);
    
        //get switcher datatype configuration data
        datatypeResource.getByName('Gender Switcher').then(function (result) {
            $scope.gender = {
                alias: 'gender',
                view: result.data.view,
                config: result.data.config,
                value: $scope.value.gender
            };
            $scope.loaded--;
        });
    
        //get nuPicker datatype configuration data
        datatypeResource.getByName('Country Picker').then(function (result) {
    
            $scope.countryPicker = {
                alias: 'countryPickerAlias',
                view: result.data.view,
                config: result.data.config,
                value: $scope.value.country
            };
    
            $scope.loaded--;
        });
    
        //get Nested Content datatype configuration data
        datatypeResource.getByName('Jobs and Units NC').then(function (result) {
            console.log(result)
    
            $scope.roles = {
                alias: 'roles',
                view: result.data.view,
                config: result.data.config,
                value: $scope.value.roles
            };
            $scope.loaded--;
        });
    
    
        $scope.save = function () {
            console.log($scope.value)
            //the result is
            //{
            //  "gender": 1,
            //  "roles": [],
            //  "name": "stefano beretta",
            //  "email": "[email protected]",
            //  "year": 1988,
            //  "ldap": "qweqwe",
            //  "userid": "asdasd",
            //  "country": ""
            //}
        }
    });
    

    How my dashboard is composed

    Thank you!

    S

Please Sign in or register to post replies

Write your reply to:

Draft