Copied to clipboard

Flag this post as spam?

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


  • lj 81 posts 425 karma points
    Sep 03, 2014 @ 13:23
    lj
    0

    angularjs property editor problem

    Hi All,

    ive created a property editor using angualrjs.

    What i am trying to now do is when the user clicks 'save and publish' make an ajax call (through a service) to a web api. depending on what is returned i will then set the $scope.model.value to a value for umbraco to automagically save it.

    to do this i have hooked into the method $scope.$on("formSubmitting", function (ev, args) {....} in my controller. This is the only way I know of doing this is there any other?

    The problem is that by the time the ajax call returns umbarco has already saved the $scope.model.value value. is there a way of forcing the $scope.$on method to wait on the ajax request returning before saving. If not how would you go about implementing this process.

    thanks

    lj

  • Jan Skovgaard 11257 posts 23497 karma points MVP 7x admin c-trib
    Sep 03, 2014 @ 13:27
    Jan Skovgaard
    0

    Hi lj

    Could you perhaps share your full code? I think it can perhaps speed up things if people can see the context.

    Cheers, Jan

  • lj 81 posts 425 karma points
    Sep 03, 2014 @ 13:38
    lj
    0

    hi there,

    here you go.

    controller ----

    angular.module("umbraco").controller("IsApprovedController", function ($scope, isapprovedResource, $routeParams) {

        var confirmationEmail = false; 

        if ($scope.model.value.confirmationEmail != '' && $scope.model.value.confirmationEmail == true) {

            confirmationEmail = true;    

        }

        if ($scope.model.value.approved != '' && $scope.model.value.approved == true) {

            $scope.model.approved = true;

        }

        else {

            $scope.model.approved = false;

        }

        //$scope.change = function () {        

        //}; 

        $scope.$on("formSubmitting", function (ev, args) {        

            $scope.model.value = { approved: $scope.model.approved, confirmationEmail: confirmationEmail };

            console.log(confirmationEmail); console.log(' 2');

            if ($scope.model.approved && !confirmationEmail) {

                //user has approved for the first time so send confirmation email and set flag

                isapprovedResource.SendIsApprovedEmail($routeParams.id).then(function (response) {                               

                    if(response.data == '\"OK\"')

                    {

                        confirmationEmail = true;

                        $scope.model.value = { approved: $scope.model.approved, confirmationEmail: confirmationEmail };

                        console.log(confirmationEmail); console.log(' 1');

                    }

                    else {

                        alert("Alert email was not sent please try again!!");

                    }                

                });            

            }                               

        })

     

    });

     

    heres the html-----

       

           

     

     

    isapprovedResource.SendIsApprovedEmail is a service that returns "OK" as a string. 

     

    basically this saves a json string like {  "approved": false,  "confirmationEmail": false } to the cmsPropertyData table. once the email has been sent confirmationEmail = true and it wont be sent again.

     

    thanks

    lj

     

  • Alain 73 posts 520 karma points c-trib
    Sep 27, 2014 @ 10:06
    Alain
    0

    Hi lj,

    I think Umbraco uses angular js validation for forms validation: http://docs.angularjs.org/guide/forms

    Alain

Please Sign in or register to post replies

Write your reply to:

Draft