Copied to clipboard

Flag this post as spam?

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


  • David Armitage 505 posts 2073 karma points
    May 06, 2017 @ 13:39
    David Armitage
    0

    Umbraco - Backoffice Extension - angular (how to refreh current window)

    Hi Guys,

    I have build a backoffice extension using angular and some ajax.

    Basically there is a button that when clicked runs some ajax that calls my controller function. Some information is passed back if this was successful or not.

    The controller function updates the current selected node and does some other stuff in the background. The problem the current node I am on when using my new context menu item does not refresh after running my code.

    <div ng-controller="Umbraco.Editors.Content.approveMember">
        <div class="umb-dialog-body form-horizontal">
            <div class="umb-pane">
                <h2>Approve Member</h2>
                <div class="message-section"></div>
            </div>
        </div>
        <div class="umb-dialog-footer btn-toolbar umb-btn-toolbar">
            <a id="btnApprove" data-id="{{id}}" class="btn btn-primary">
                Approve
            </a>
            <a class="btn btn-link" ng-click="nav.hideDialog()">
                <localize key="general_cancel">Cancel</localize>
            </a>
        </div>
    </div>
    
    <script>
        $("#btnApprove").click(function () {
            var nodeId = $(this).attr("data-id");
            $.ajax({
                url: "/Umbraco/Backoffice/Api/Backend/ApproveMember?nodeId=" + nodeId,
                type: 'GET',
                success: function (data) {
                    $("#btnApprove").hide();
                    $(".message-section").html("<p><strong>The member was successfully approved.</strong></p>")
                },
                error: function (data) {
                    $("#btnApprove").hide();
                    $(".message-section").html("<p><strong>ERROR - The member could not be found. Please select the member and try again.</strong></p>")
                }
            });
        });
    </script>
    

    I want to know if there is any way I can get the selected node to refresh one my ajax data is returned.

    Or maybe even extending the close button to refresh the page when this is clicked or if the user clicks out of the context menu.

     <a class="btn btn-link" ng-click="nav.hideDialog()">
              <localize key="general_cancel">Cancel</localize>
     </a>
    

    Thanks in advanced.

    Kind Regards

    David

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    May 07, 2017 @ 17:33
    Marc Goodson
    0

    Hi David

    Are you looking for something like...

    $window.location.reload(true);
    

    passing true should force the browser to reload rather than display from cache.

    (injecting $window into your angular controller)

    regards

    Marc

  • David Armitage 505 posts 2073 karma points
    May 08, 2017 @ 07:54
    David Armitage
    0

    Hi Marc,

    Thanks for your reply. Yeah this sort of does the trick. What I was trying to figure out how to do was only refresh the node window.

    Since this action updating some properties on the node in view it would be great if I could just refresh the node screen. In much the same way the save and publish buttons does.

    Why screen shot should demonstrate the screen I am trying to update. Following my approve click.

    enter image description here

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    May 08, 2017 @ 10:56
    Marc Goodson
    100

    Ahh I see

    SaveAndPublish uses the method from the contenteditinghelperservice:

    https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Web.UI.Client/src/common/services/contenteditinghelper.service.js

    details here:

    https://our.umbraco.org/apidocs/ui/#/api/umbraco.services.contentEditingHelper

    think you could just rebind the changed 'approved' property when you click approve, or trigger save and use handleSuccessfulSave?

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft