Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 409 posts 1063 karma points
    Jul 24, 2017 @ 13:56
    Jonathan Roberts
    0

    Umbraco RTE in an accordion Macro

    Im building a multi panel Accordion as a Macro in Umbraco 7.6.4 using AngularJS and Im using umb-editor as my Rich Text Editor. Im using code to create multiple (n) panels so when a user clicks on a New panel a new RTE is created so the user can save text to the $Scope. Here is my Macro html code

    {{slide.name}}

    And this is my controller:

    angular.module("umbraco").controller("AccordionEditor.controller", function ($scope, assetsService, $http, dialogService, mediaHelper) {

    $scope.getSummaryValue = function (index) {
        //var newIndex = 0;
        if (!index) {
            index = 0;
        }
        if ($scope.model.value && $scope.model.value.length > 0) {
            return $scope.model.value[index].summary;
        }
    }
    
    
    $scope.buildRTE = function (index) {
        if (!index) {
            index = 0;
        }
        $scope.rteText = {
            label: 'bodyText',
            description: '...',
            id: 'rte_' + index,
            view: 'rte',
            value: $scope.getSummaryValue(index),
            config: {
                editor: {
                    toolbar: ["code", "removeformat", "link", "unlink", "bold", "italic", "underline", "strikethrough"],
                    stylesheets: [],
                    dimensions: {
                        height: 200
                    }
                }
            }
        };
    
        return $scope.rteText;
    }
    
    $scope.$watch('rteText.value', function (newValue, oldValue, dd) {
        if ($scope.model.value && $scope.model.value.length > 0) {
            if (!$scope.SelectedIndex) {
                $scope.SelectedIndex = 0;
            }
            $scope.model.value[$scope.SelectedIndex].summary = newValue;
        }
    
    });
    
    
    
    var defaultItem = { name: "", summary: "", img: "", link: undefined };
    
    if (!$scope.model.value) {
        $scope.model.value = [];
    }
    
    if ($scope.model.value.length > 0) {
        $scope.selected = $scope.model.value[0];
        $scope.buildRTE($scope.SelectedIndex);
    }
    
    $scope.select = function (index) {
        $scope.selected = index;
        $scope.SelectedIndex = this.$index;
        //
        $scope.buildRTE($scope.SelectedIndex);
        $scope.rteText.value = $scope.model.value[$scope.SelectedIndex].summary;
    };
    
    $scope.remove = function ($index) {
        $scope.model.value.splice($index, 1);
    };
    
    $scope.add = function () {
    
            $scope.model.value.splice($scope.model.value.length + 1, 0, angular.copy(defaultItem));
            $scope.selected = $scope.model.value[$scope.model.value.length - 1];
            $scope.SelectedIndex = $scope.model.value.length - 1;
           // $scope.rteText.value = "";
          $scope.buildRTE($scope.SelectedIndex);
    };
    
    $scope.pick = function (slide) {
        dialogService.mediaPicker({
            multiPicker: false,
            callback: function (data) {
                slide.img = mediaHelper.resolveFile(data, false);
            }
        });
    };
    
    $scope.pickContent = function (slide) {
        dialogService.treePicker({
            multiPicker: false,
            section: "content",
            treeAlias: "content",
            callback: function (data) {
                slide.link = { name: data.name, id: data.id };
            }
        });
    };
    
    $scope.sortableOptions = {
        handle: ".icon-navigation",
        axis: "y",
        delay: 150,
        distance: 5
    };
    
    // Load css asset
    assetsService.loadCss("/App_Plugins/CarouselEditor/assets/CarouselEditor.css");
    

    }); The code saves into the scope ok but if I reload the Macro the first panel Summary [0] (rte text) appears in each panel rte. Stepping through the code the correct summary seems to load into the rte correctly but when it appears the initial summary appears regardless of which panel you select.

    Has anyone successfully added a RTE into an Accordion Macro?

    Thanks Jon

  • Jonathan Roberts 409 posts 1063 karma points
    Jul 26, 2017 @ 09:47
    Jonathan Roberts
    0

    Hi,

    When I drag a slide the RTE Iframe Html is empty. It is not until i save and reload the accordion macro that the IframeHTL is populated again.

Please Sign in or register to post replies

Write your reply to:

Draft