Copied to clipboard

Flag this post as spam?

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


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 12, 2016 @ 13:46
    Jan Skovgaard
    0

    Limit allowed nodes using entityResource? Like in the MNTP

    Hi guys

    I'm currently working on a property editor where I would like to setup some filtering like we know it from the Multinode treepicker (MNTP).

    I'm using the entityResource and passing a query to it, which works just fine. However I would like to improve it so that I'm only allowed to select content nodes, which have a specific alias - Just like when we setup allowed types on the MNTP.

    I have tried looking in the Umbraco source code but can't seem to find any clues - I'm not sure that this is currently even possible?

    My current code looks like below

    $scope.pickContent = function(idx){
        var config = {
            multiPicker: false,
            entityType: "Document",
            type: "content",
            treeAlias: "content",
            query: $scope.model.config.nodetype,
            currentId: $routeParams.id
        };
    
        entityResource.getByQuery(config.query, config.currentId, config.entityType).then(function(entity){
    
            dialogService.contentPicker({
                section: config.type,
                treeAlias: config.type,
                multiPicker: config.multiPicker,
                startNodeId: entity.id,
                callback: function(data){
    
                      //Updating some scope variables
    
                }
            });
    
        });
    
    }
    

    As I mentioned it works but I would like to tweak it so I'm only allowed to pick certain document types (If possible).

    Looking forward to hear any tips/suggestions :)

    Cheers, Jan

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Apr 12, 2016 @ 23:24
    Marc Goodson
    100

    Hi Jan

    Looking at the source, the ContentPicker, calls the TreePicker, passing through it's options:

    and if you have a look at the TreePicker:

    https://github.com/umbraco/Umbraco-CMS/blob/75c2b07ad3a093b5b65b6ebd45697687c062f62a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js

    it has a 'filter' option that will take an angular function or object, or json, or I think a comma delimited whitelist of doctypes:

    so if you set

    filter: "doctype1,doctype2",
    

    as one of the options you pass to the contentPicker and cross your fingers.

    regards

    Marc

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 13, 2016 @ 05:46
    Jan Skovgaard
    0

    Thank you Marc - You're spot on! :) - Remind me that I owe you a beer at #CG16 - I assume you're going?

    I had a notion that it would be easy but just could not find that missing part - Would be nice if it was mentioned in the documentation at https://umbraco.github.io/Belle/#/api/umbraco.services.dialogService

    One weird thing though is that the unselectable items are not being greyed down like when using the MNTP - But they're just not selectable. Must file a bug report I think.

    Cheers, Jan

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Apr 15, 2016 @ 15:52
    Marc Goodson
    0

    I was tempted to start the reply with

    Hi Jan, welcome to the forum...

    but glad it worked; not sure about the greying out.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 15, 2016 @ 16:02
    Jan Skovgaard
    0

    Why would that be? You calling me a n00b? :-)

    Afterall I'm only human.

    Naaa, it's a bit odd that it's not acting the same way as when one is using the MNTP. But the important thing is that the editors can't make any mistake.

    Cheers, Jan

Please Sign in or register to post replies

Write your reply to:

Draft