cancel
Showing results for 
Search instead for 
Did you mean: 

callback not triggered

darkstar1
Confirmed Champ
Confirmed Champ
I modified the _createUser() method to call another method in the same users.js (loaded with the new user creation form) as follows:
<javascript>
        _createUser: function ConsoleUsers__createUser(handler)
        {
            // TODO: respect minimum field length for username/password
        
            var me = this;
            var fnGetter = function(id)
            {
                return YAHOO.lang.trim(Dom.get(me.id + id).value);
            };
        
            // verify password against second field
            var password = fnGetter("-create-password");
            var verifypw = fnGetter("-create-verifypassword");
            if (password !== verifypw)
            {
                Alfresco.util.PopupManager.displayMessage(
                {
                    text: this._msg("message.password-validate-failure")
                });
                return;
            }
        
            // gather up the data for our JSON PUT request
            var username = fnGetter("-create-username");
            var quota = this._calculateQuota(me.id + "-create");
        
            // gather the selected groups from the panel
            var groups = this._getCurrentPanel().getGroups();
        
            var personObj =
            {
                userName: username,
                password: password,
                firstName: fnGetter("-create-firstname"),
                lastName: fnGetter("-create-lastname"),
                location: fnGetter("-create-location"),
                email: fnGetter("-create-email"),
                disableAccount: Dom.get(me.id + "-create-disableaccount").checked,
                quota: quota,
                groups: groups
            };
            alert("This alert is triggered");
            Alfresco.util.Ajax.request(
            {
                url: Alfresco.constants.PROXY_URI + "api/people",
                method: Alfresco.util.Ajax.POST,
                dataObj: personObj,
                requestContentType: Alfresco.util.Ajax.JSON,
                successCallback:
                {
                    fn: function(res){   
                        alert("This alert is not triggered");
                        this._setCustomProperties();
                    },
                    scope: this
                },
                failureCallback:
                {
                    fn: function(res)
                    {
                        if (res.serverResponse.status === 409)
                        {
                            // username already exists
                            Alfresco.util.PopupManager.displayPrompt(
                            {
                                title: this._msg("message.failure"),
                                text: this._msg("message.create-user-exists")
                            });
                        }
                        else
                        {
                            // generic error
                            var json = Alfresco.util.parseJSON(res.serverResponse.responseText);
                            Alfresco.util.PopupManager.displayPrompt(
                            {
                                title: this._msg("message.failure"),
                                text: this._msg("message.create-failure", json ? json.message : res.serverResponse.statusText)
                            });
                        }
                    },
                    scope: this
                }
            });
     
        },
      
        _setCustomProperties: function ConsoleUsers__setCustomProperties() {
            var me = this;
            var fnGetter = function(id){
                return YAHOO.lang.trim(Dom.get(me.id + id).value);
            };
    
            alert("About to set custom properties");
            var username = fnGetter("-create-username");
            var customPersonObj =
            {
                username: username,
                department: fnGetter("-create-department"),
                otherLanguages: fnGetter("-create-otherLanguages"),
                spokenLanguages: fnGetter("-create-spokenLanguages")
            };
     
            alert("username is :"+username);
            Alfresco.util.Ajax.request(
            {
                url: Alfresco.constants.PROXY_URI + "com/test/setUserCustomProperties/"+username,
                method: Alfresco.util.Ajax.POST,
                dataObj: customPersonObj,
                requestContentType: Alfresco.util.Ajax.JSON,
                successCallback:
                {
                    fn: function(res){
                        window.scrollTo(0, 0);
                        Alfresco.util.PopupManager.displayMessage(
                        {
                           text: me._msg("message.create-success")
                        });

                        // clear fields
                        this._getCurrentPanel().clear();
                        Dom.get(me.id + "-create-firstname").focus();
                    },
                    scope: this
                },
                failureCallback:
                {
                    fn: function(res)
                    {
                        if (res.serverResponse.status === 409)
                        {
                            // username already exists
                            Alfresco.util.PopupManager.displayPrompt(
                            {
                                title: this._msg("message.failure"),
                                text: this._msg("PB 409")
                            });
                        }
                        else
                        {
                            // generic error
                            var json = Alfresco.util.parseJSON(res.serverResponse.responseText);
                            Alfresco.util.PopupManager.displayPrompt(
                            {
                                title: this._msg("message.failure"),
                                text: this._msg("PB")
                            });
                        }
                    },
                    scope: this
                }
            });
      
    
        },
</javascript>

The problem I have is that the successCallback in the _createUser() isn't executed and I'm not sure why.
9 REPLIES 9

zladuric
Champ on-the-rise
Champ on-the-rise
Does your Ajax call get executed at all? Perhaps a silly question.
If it does, what kind of response do you get? What is in it?

The Ajax calls GET and it does get executed as the user is created. The response seems to be the same script I according to what I glimpsed in the chromium debugger.

zladuric
Champ on-the-rise
Champ on-the-rise
Ajax calls GET? That's weird, you said
       url: Alfresco.constants.PROXY_URI + "api/people",

                method: Alfresco.util.Ajax.POST
                …

Do you see that POST call in the chromium network tab?

Also, a side advice, while in development, you can do a lot of console.log("message", object) or Alfresco.logger.debug("message") stuff, easier then to have to click on all those alerts Smiley Happy

At least to me it is.

Yes. There's a POST and you're correct I'll use those methodsto log instead from now on. Thanks

zladuric
Champ on-the-rise
Champ on-the-rise
And what does the POST response have? Is it a status 200 or something in the 4xx/5xx range?

No the post response doesn't have a status (is completely empty) I had capture the logs to see it because it only shows for less than a sec.

zladuric
Champ on-the-rise
Champ on-the-rise
Oh? Well, it sounds like the page reloads after your post event?

Can you click on the Chrome's "Preserve log on navigation' and see if it disappears then?

That's how I was able to view the response of the request. the post is listed but no response info, so it shows up in the logs

It took the consultant dev 6 hours to find out why but further up the users.js file in the CreatePanelHandler() function  at line 645 of the original file is the following code :

             // Buttons
            parent.widgets.createuserOkButton = Alfresco.util.createYUIButton(parent, "createuser-ok-button", parent.onCreateUserOKClick,
            {
               type: "submit"
            });


because the button was submitting the form it was instantly redirecting to another page and killing the post response. so the <strong>type: "submit"</strong> needed to be removed and everything worked.