uioMATIC ISSUE 5.14
Tags: uiomatic
Published: 2023-08-30 15:16:38

Tim you have left some code out of this version - multicontentpicker . Here is some I get to work on Umbraco V11. 
angular.module("umbraco").controller("UIOMatic.FieldEditors.Pickers.MultiContentController",
    function ($scope, $routeParams, $http, editorService, entityResource, iconHelper, contentResource)  {
        
try{
    $scope.startId = $scope.model.config.startId;
    $scope.typeAlias = $scope.model.config.typeAlias;
        $scope.allItems = [];
        $scope.items = [];
        $scope.selectedIds = [];
}
catch(e)
{
alert(e);
}
        $scope.openContentPicker = function () {
            var d = editorService.treePicker({
                section: "content",
                filter: $scope.typeAlias,
                treeAlias: "content",
                multiPicker: true,
                startNodeId: $scope.startId,
                submit: function (model) {

                    angular.forEach(model.selection, function (item, idx) {
                        $scope.model.value = $scope.model.value + "," + item.id;

                        $scope.items.push({
                            id: item.id,
                            text: item.name
                        });
                        $scope.allItems.push(item.id);
                        $scope.model.value = $scope.allItems.join();
                    });
                    
                  

                    editorService.close();
                    //getFullDetails();
                },
                close: function () {
                    editorService.close();
                }
            }); 
        };

        $scope.remove = function (index) {
            $scope.items.splice(index, 1);
            //$scope.selectedIds.splice(index, 1);
            $scope.allItems.splice(index, 1);
            $scope.model.value = $scope.allItems.join();
        }

        function isInt(value) {
            var x = parseFloat(value);
            return !isNaN(value) && (x | 0) === x;
        }

        function getFullDetails() {
            console.log("getFullDetails.$scope.selectedIds.length " + $scope.selectedIds.length);
         

            if ($scope.selectedIds.length > 0) {
                angular.forEach($scope.selectedIds, function (item, idx) {
                    console.log("getFullDetails.splicing " + idx + " id " + item.id + " ,text= item.name " + item.name);
                    $scope.items.splice(idx, 0, {
                        id: item.id,
                        text: item.name
                    });
                });

            }
        }

        function init() {
            if (!$scope.setting) {
                $scope.setting = {};
            }
            try {
                $scope.allItems = $scope.model.value ? $scope.model.value.toString().split(',') : [];
                console.log("init. " + $scope.allItems.length);
            }
            catch(ex){
                alert(ex);
            }
           

            var index = 0;
            angular.forEach($scope.allItems, function (item, idx) {
                try {
                    console.log("getting content for id " + item);
                    contentResource.getById(item).then(function (data) {
                        var dataitem = new ContentItem(item,data.urls[0].text.substring(0, data.urls[0].text.length - 1).substring(data.urls[0].text.substring(0, data.urls[0].text.length-2).lastIndexOf("/")+1));                       
                        $scope.items.push( {
                            id: dataitem.id,
                            text: dataitem.name
                        });
                        //$scope.selectedIds.push(dataitem); 

                        index++;
                    },
                        function (error) {
                            alert(error);
                        });
                }
                catch (exc) {
                    alert(exc);
                }
            });         

             
        }

 	var appScope = $scope;
        while (appScope && typeof appScope === 'object' && typeof appScope.currentSection === 'undefined')
            appScope = appScope.$parent;

        if (appScope.valuesLoaded) {
            init();
        }
        else {
            var unsubscribe = appScope.$on('valuesLoaded', function () {
                init();
                unsubscribe();
            });
        }

        class ContentItem {
            constructor(id, name) {
                this.id = parseInt(id);
                this.name = name;
            }
        }
});