Copied to clipboard

Flag this post as spam?

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


  • Scott 3 posts 103 karma points
    Jul 14, 2015 @ 22:31
    Scott
    0

    Custom Plug-in Sync Tree on Delete of Node

    I'm trying to use the Navigation Service to refresh the tree when a node has been deleted. The issue that I'm running into is that it changes the active section to the "Content" section before I ever get to sync the tree. I'm basing the code on Tim Geyssen's "Umbraco Angular Backoffice Pages" repo (found @ https://github.com/TimGeyssens/UmbracoAngularBackofficePages).

    delete.html

    <div class="umb-pane"
     ng-controller="SecureDocument.SecureDocumentTree.DeleteController">
    <p>Are you sure you want to delete {{currentNode.name}}?</p>
    
    <div>
        <div class="umb-pane btn-toolbar umb-btn-toolbar">
            <div class="control-group umb-control-group">
                <a href="#" class="btn btn-link" ng-click="cancelDelete()"><localize key="general_cancel">Cancel</localize></a>
                <a href="#" class="btn btn-primary" ng-click="delete(currentNode.id)"><localize key="general_ok">OK</localize></a>
            </div>
        </div>
    </div>
    

    delete.controller.js

    'use strict';
    (function () {
        function controller($scope, secureDocumentResource, navigationService, notificationsService) {
            $scope.delete = function (id) {
                secureDocumentResource.deleteById(id).then(function () {
                    //navigationService.hideNavigation();
                    navigationService.syncTree({ tree: "SecureDocumentTree", path: ["-1"], forceReload: true, activate: true }).then(function (syncArgs) {
                        navigationService.reloadNode(syncArgs.node);
                    });
                    notificationsService.success("Success", "Secure Document deleted");
                });
            }
            $scope.cancelDelete = function () {
            };
        }
        angular.module("umbraco").controller("SecureDocument.SecureDocumentTree.DeleteController", controller);
    })();
    

    Any ideas? Stepping through you can clearly see it selecting the "Content" section immediately so when it goes through the syncTree method it throws an error that it can't find my particular tree.

    If I change the active section, do a timeout, and THEN sync the tree it will sync it fine. I saw this in a different thread on here, but that seems like a hack.

    Thanks!

  • Scott 3 posts 103 karma points
    Jul 14, 2015 @ 23:26
    Scott
    0

    Update on this. I tried switching to what Umbraco Forms does.

        $scope.delete = function(id) {
            secureDocumentResource.deleteById(id).then(function () {
                treeService.removeNode($scope.currentNode);
                navigationService.hideNavigation();
                notificationsService.success("Success", "Secure Document deleted");
            });
        }
    

    This still doesn't work because the content section is still loaded/active even though previously my custom section was loaded/active.

    I should also note that my edit's save works fine. The code I have for that is like the following.

        $scope.save = function(document) {
            secureDocumentResource.save(document).then(function(response) {
                $scope.document = response.data;
    
                navigationService.syncTree({ tree: 'SecureDocumentTree', path: [String($scope.document.id)], forceReload: true });
                notificationsService.success("Success", document.FileName + " has been saved");
                $scope.secureDocumentForm.$dirty = false;
            });
        };
    

    Thanks!

  • Scott 3 posts 103 karma points
    Jul 14, 2015 @ 23:47
    Scott
    100

    Well, I feel dumb now. I just realized my link had href="#". Obviously, making it href="" fixes everything!

Please Sign in or register to post replies

Write your reply to:

Draft