Copied to clipboard

Flag this post as spam?

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


  • Asembli 86 posts 260 karma points
    May 29, 2019 @ 07:42
    Asembli
    0

    Vorto, copy complex data from one lang to another

    Hi,

    For catalogue items we are using complex documenttype (dynamic created with embeddedblocks) wrapped inside nestedcontent (to simulate datatype - Jeroen B. tutorial: nestedcontent-vorto) and vorto (umb 7.14, vorto 1.71). So far so good - even with very complex structure, everything work well.

    The problem we have now is that editors who edit one language first, want to copy structure and content to another language. I only found this two links

    https://github.com/umco/umbraco-vorto/issues/52 https://github.com/anth12/umbraco-vorto/tree/copy-value

    Has somebody tried to make vorto enhancment to grab json of one lang (structure and content!) and copy it to another lang (there's no need to check for overwritting existing content on other langu, as this would be rather easy to achieve if core functionality will work)?

    Best regards, /Asembli

  • Asembli 86 posts 260 karma points
    May 30, 2019 @ 11:04
    Asembli
    1

    Ok,

    if someone is interested in this, here is the solution (be aware that this intervene in vorto's core)

    1) add notificationsService at vorto.js controller

    2) add this to vorto.js

    $scope.copyTo = function (language) {
        if (confirm("Copy language content [" + $scope.realActiveLanguage.name + "] to [" + language.name + "]?\nNote: Existing content at [" + language.name + "] will be overwritten!")) {
    
        // this actually save whatever is currently in fields
        $scope.$broadcast("vortoSyncLanguageValue", { language: $scope.realActiveLanguage.isoCode });
    
        setTimeout(function () {
            $scope.model.value.values[language.isoCode] = null;
            $scope.model.value.values[language.isoCode] = angular.copy($scope.model.value.values[$scope.realActiveLanguage.isoCode]);
            $scope.model.value.values[language.isoCode][0].key = generateUUID();
            notificationsService.success("Success", "Language [" + $scope.realActiveLanguage.name + "] copied to [" + language.name + "].");
        }, 100);
        };
    };
    
    $scope.filterLanguage = function (item) {
        if (item == $scope.activeLanguage) {
        return false;
        } else {
        return true;
        }
    };
    
    function generateUUID() {
        var d = new Date().getTime();
        if (Date.now) {
        d = Date.now();
        }
        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
        });
        return uuid;
    };
    

    3) add this to vorto.html, as last tab, behind icon-globe

    <li class="vorto-tabs__item vorto-tabs__item--menu">
    <i class="icon icon-documents"></i>
    <ul class="vorto-menu">
        <li class="vorto-menu__item vorto-menu__item--label">
        <label>Copy [{{activeLanguage.name}}] to...</label>
        </li>
        <li class="vorto-menu__item vorto-menu__item--icon"
        ng-repeat="language in languages | filter:filterLanguage"
        ng-click="copyTo(language);">
        <span>{{language.name}}</span>
        </li>
    </ul>
    </li>
    

    4) add this to vorto.css

    .vorto-menu__item:hover:not(.vorto-menu__item--label) {
    background: #2e8aea;
    color: #fff;
    }
    
    .vorto-menu__item--label * {
        font-weight: bold;
    }
    

    5) and the result

    enter image description here

    PS: maybe it is not obviously at first sight, but it copy also the whole structure eg. nested-content, embedded-block etc.

    Best regards,

    /Asembli

Please Sign in or register to post replies

Write your reply to:

Draft