dojo part:
userInfo.registerOrUpdateUser = function(formID, isNewOrUpdate) {
var isSendNotification = dojo.byId('userReg.sendNotification').checked;
var action = "";
if (isNewOrUpdate == 'new') {
action = "mngrUserActionBean.registerUser";
} else if (isNewOrUpdate == 'update') {
action = "mngrUserActionBean.updateUser";
}
var callback = function(response, xhr){
if(isAjaxSuccess(xhr)){
mtpGrid.refresh('userReg','refresh');
dojo.byId("userReg.cancelBtn").click();
}
};
var params = {};
params.name = dijit.byId('user.name').attr('value');
params.location = dijit.byId('user.location').attr('value');
if (isNewOrUpdate == 'update') {
params.userId = dojo.byId('userReg.userId').value;
}
params.contact = dijit.byId('user.contact').attr('value');
params.email = dijit.byId('user.email').attr('value');
params.notesId = dijit.byId('user.notesId').attr('value');
params.roleList = dojo.toJson(userInfo.getRoleJson());
var url = CENTRAL_CONTROLLER + '?' + PARAM_ACTION + '=' + action;
url += '&isSendNotification='+isSendNotification;
dojoAjaxPost(params, url, null, callback);
}
userInfo.getRoleJson = function() {
var rolesInfoTbl = dojo.byId('mgrRegInfoTbl.rolesInfoTbl');
var rolesInfoTblLen = rolesInfoTbl.rows.length;
var roleList = new Array();
for (var i = 1; i < rolesInfoTblLen; i++) {
var roleObj = {};
var role = rolesInfoTbl.rows[i].cells[3].innerHTML;
roleObj.role = role;
//var divsions = rolesInfoTbl.rows[i].cells[1].innerHTML;
//roleObj.divsions = divsions;
var languages = rolesInfoTbl.rows[i].cells[4].innerHTML;
roleObj.languages = languages;
roleList.push(roleObj);
}
return roleList;
}
java part:
private void setUserRoleInfo(String roleJsonObj) {
if (roleJsonObj == null || roleJsonObj.trim().length() == 0) {
return;
}
JSONArray jsonArray = JSONArray.fromObject( roleJsonObj);
Iterator<JSONObject> iterator = jsonArray.iterator();
List<Role> roleList = new ArrayList<Role>();
while(iterator.hasNext()) {
JSONObject jsonObj = iterator.next();
Role role = new Role();
role.setRoleId((String)jsonObj.get("role"));
// Add current division
List<BusinessUnit> buList = new ArrayList<BusinessUnit>();
buList.add(userSession.getCurrentDiv());
role.setDivisions(buList);
/*String divisions = (String)jsonObj.get("divsions");
String[] buArr = divisions.split(",");
List<BusinessUnit> buList = new ArrayList<BusinessUnit>();
for (String buCode : buArr) {
BusinessUnit bu = new BusinessUnit();
bu.setBU_Code(buCode.replace(GenConst.HTML_AND, GenConst.DB_AND));
buList.add(bu);
}
role.setDivisions(buList);*/
String languages = (String)jsonObj.get("languages");
String[] langArr = languages.split(",");
List<Language> langList = new ArrayList<Language>();
for (String langId : langArr) {
Language lang = new Language();
lang.setLanguageId(langId);
langList.add(lang);
}
role.setLanguages(langList);
roleList.add(role);
}
regUser.setRoles(roleList);
}
userInfo.registerOrUpdateUser = function(formID, isNewOrUpdate) {
var isSendNotification = dojo.byId('userReg.sendNotification').checked;
var action = "";
if (isNewOrUpdate == 'new') {
action = "mngrUserActionBean.registerUser";
} else if (isNewOrUpdate == 'update') {
action = "mngrUserActionBean.updateUser";
}
var callback = function(response, xhr){
if(isAjaxSuccess(xhr)){
mtpGrid.refresh('userReg','refresh');
dojo.byId("userReg.cancelBtn").click();
}
};
var params = {};
params.name = dijit.byId('user.name').attr('value');
params.location = dijit.byId('user.location').attr('value');
if (isNewOrUpdate == 'update') {
params.userId = dojo.byId('userReg.userId').value;
}
params.contact = dijit.byId('user.contact').attr('value');
params.email = dijit.byId('user.email').attr('value');
params.notesId = dijit.byId('user.notesId').attr('value');
params.roleList = dojo.toJson(userInfo.getRoleJson());
var url = CENTRAL_CONTROLLER + '?' + PARAM_ACTION + '=' + action;
url += '&isSendNotification='+isSendNotification;
dojoAjaxPost(params, url, null, callback);
}
userInfo.getRoleJson = function() {
var rolesInfoTbl = dojo.byId('mgrRegInfoTbl.rolesInfoTbl');
var rolesInfoTblLen = rolesInfoTbl.rows.length;
var roleList = new Array();
for (var i = 1; i < rolesInfoTblLen; i++) {
var roleObj = {};
var role = rolesInfoTbl.rows[i].cells[3].innerHTML;
roleObj.role = role;
//var divsions = rolesInfoTbl.rows[i].cells[1].innerHTML;
//roleObj.divsions = divsions;
var languages = rolesInfoTbl.rows[i].cells[4].innerHTML;
roleObj.languages = languages;
roleList.push(roleObj);
}
return roleList;
}
java part:
private void setUserRoleInfo(String roleJsonObj) {
if (roleJsonObj == null || roleJsonObj.trim().length() == 0) {
return;
}
JSONArray jsonArray = JSONArray.fromObject( roleJsonObj);
Iterator<JSONObject> iterator = jsonArray.iterator();
List<Role> roleList = new ArrayList<Role>();
while(iterator.hasNext()) {
JSONObject jsonObj = iterator.next();
Role role = new Role();
role.setRoleId((String)jsonObj.get("role"));
// Add current division
List<BusinessUnit> buList = new ArrayList<BusinessUnit>();
buList.add(userSession.getCurrentDiv());
role.setDivisions(buList);
/*String divisions = (String)jsonObj.get("divsions");
String[] buArr = divisions.split(",");
List<BusinessUnit> buList = new ArrayList<BusinessUnit>();
for (String buCode : buArr) {
BusinessUnit bu = new BusinessUnit();
bu.setBU_Code(buCode.replace(GenConst.HTML_AND, GenConst.DB_AND));
buList.add(bu);
}
role.setDivisions(buList);*/
String languages = (String)jsonObj.get("languages");
String[] langArr = languages.split(",");
List<Language> langList = new ArrayList<Language>();
for (String langId : langArr) {
Language lang = new Language();
lang.setLanguageId(langId);
langList.add(lang);
}
role.setLanguages(langList);
roleList.add(role);
}
regUser.setRoles(roleList);
}