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.