Ext.ns('Ext.clv2.utils')
/**
   * @author: Rodrigo Bartels
   * Date: October 3, 2008.
   * Object that manages the DWR calls for the SecurityService Bean.
*/

Ext.clv2.utils.SecurityUtils = function(){
  var currentUserName;
  var currentUniqueUserName;
  var currentUserId;
  var currentUserPermissionsAccess;

  this.getCurrentUserName = function(){
        return currentUserName;
  };

  this.setCurrentUserName = function(name){
        currentUserName = name;
  };

  this.getCurrentUniqueUsername = function(){
        return currentUniqueUserName;
  };

  this.setCurrentUniqueUsername = function(name){
        currentUniqueUserName = name;
  };

  this.getCurrentUserPermissionsAccess = function(){
        return currentUserPermissionsAccess;
  };

  this.setCurrentUserPermissionsAccess = function(access){
        currentUserPermissionsAccess = access;
  };

  this.getCurrentUserId = function(){
        return currentUserId;
  };

  this.setCurrentUserId  = function(id){
        currentUserId = id;
  };
};

Ext.clv2.utils.SecurityUtils.prototype = {
  loadUserContext : function(){
        var that = this;
        SecurityUtilsService.getCurrentUserName({async:false,callback : function(name){that.setCurrentUserName(name)}});
        SecurityUtilsService.getCurrentUserId({async:false,callback : function(id){that.setCurrentUserId(id)}});
        SecurityUtilsService.getCurrentUniqueUsername({async:false,callback : function(name){that.setCurrentUniqueUsername(name)}});
        return this.getCurrentUserName();
  },

  createUser: function(userData, language, country, date,gender){
        var that = this;
        url = "http://" + top.location.host + Ext.get('contextPathVar').dom.innerHTML;
        SecurityUtilsService.create(userData, language, country,date, gender, url, {async:false,callback : function(id){that.setCurrentUserId(id)}});
        return this.getCurrentUserId();
  },

  checkUserPermissions: function(userId, learningObjectId, type){
        var that = this;
        SecurityUtilsService.checkUserAccess(userId, learningObjectId, type,{async:false,callback : function(access){that.setCurrentUserPermissionsAccess(access)}});
        return this.getCurrentUserId();
  },

  changePassword: function(userName, password){
        var that = this;
        SecurityUtilsService.changeUserPassword(userName, password,{async:false,callback : Ext.emptyFn});
  }

};