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 17, 2014 @ 17:09
    Stefano Beretta
    0

    Re-using content picker for multilingual website (Umbraco 7)

    Hi everyone!

    In these months my agency gave me very few hours to develop a custom data type for a multilingual website with 1 to 1 structure.

    I retrieve the installed languages from an ApiController and I try to render a content picker (with umb-property and umb-editor directives) for each installed language.
    No problem in this step, it renders the right language occurence, but I've a problem in creating the model (in angularjs) to pass to the editor. 

    My ApiController returns an array of structured objects:
    - the language
    - the node (if there's a record in the relation table)

    So i try to render a contentPicker for each object in the array but I cannot find the right information to pass to the contentpicker.

    Could someone help me with this problem?
    Or can someone tell me where I can find some information about re-using content picker?

    Thank you
    S

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 17, 2014 @ 17:38
    Jan Skovgaard
    0

    Hi Stefano

    You should use the dialogue service http://umbraco.github.io/Belle/#/api/umbraco.services.dialogService - You can see more API references here http://umbraco.github.io/Belle/#/api

    And then have a look at this screencast by Per Ploug on how to use it http://www.screenr.com/kpHH

    From what you're asking it sounds like what you need, let me know if I'm wrong :)

    hope this helps.

    /Jan

  • Stefano Beretta 102 posts 247 karma points
    Nov 18, 2014 @ 11:08
    Stefano Beretta
    0

    Hi Jan! Thank you for your suggestions! It's what I need but not exactly the same way I'm doing it...

    I try to explain it better (with some code), so maybe you can tell me if I'm totally wrong in developing mi custom data type.

    I found this article time ago http://www.wiliam.com.au/wiliam-blog/reusing-the-multi-node-tree-picker-in-a-custom-section so I reuse the code in the view to render my pickers

    <div ng-controller="NodePickerPerLanguage">
        <umb-property property="property" ng-repeat="property in properties">
            <umb-editor model="property.node"></umb-editor>
        </umb-property>   
    </div> 
    

    After that I wrote my language.resource.js that has a GetAll(Id) method which calls my custom umbraco Api. This Api looks for a record in the umbracoRelation table (using the RelationService) and get the related node if it exists (using the ContentService). The Api works fine, I manually put some records in the table to test the code and it correctly retieve the related nodes. My Api gives me back this structured object:

    public class NodeWithLanguage
        {
            public IContent RelatedNode { get; set; }
            public string LanguageNode { get; set; }
        }
    

    Then I wrote down my NodePickerPerLanguage.controller.js:

    angular.module('umbraco')
        .controller('NodePickerPerLanguage', function ($scope, $routeParams, languageResource, $http) {
            languageResource.getAll($routeParams.id)
                .then(function (response) {
    
                    $scope.properties = [];
                    var lightNode = [];
                    lightNode = response.data;
    
                    for (var i = 0; i < lightNode.length; i++) {
                        var p = {
                            label: lightNode[i].language,
                            description: lightNode[i].language,
                            view: 'contentpicker',
                            config: {
                                multiPicker: "0",
                                entityType: "Document",
                                startNode: {
                                    query: "",
                                    type: "content",
                                    id: 1064
                                },
                                filter: ""
                            },
                            value: lightNode[i].node
                        }
                        $scope.properties.push(p);
                    }
                    return false;
                })
        });
    

    But the console always gives the error

    TypeError: Cannot read property 'alias' of undefined at link (http://custompicker.it/umbraco/js/umbraco.directives.js:1328:32) at k (http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:44:444) at http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:49:393 at e (http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:40:139) at http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:39:205 at http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:40:89 at new aa.controller (http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:165:75) at d (http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:28:304) at Object.instantiate (http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:28:434) at http://custompicker.it/umbraco/lib/angular/1.1.5/angular.min.js:53:326

    and I think the problem is the json format of the node. I looked for the proper way to cast that IContent (dynamic code) to a json object for my picker, but I couldn't find anything about that (maybe I searched with the wrong keys). Or it's a problem in repeating the content picker?

    Forgive me but I'm not very skilled in angularjs for now (but i'm studying hard :-P ). I hope I've been clear enough...

    Thank you S

Please Sign in or register to post replies

Write your reply to:

Draft