module ErpApp module Desktop module UserManagement class BaseController < ErpApp::Desktop::BaseController before_filter :get_user, :only => [:get_details, :delete] def index username = params[:username] sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first) sort = sort_hash[:property] || 'username' dir = sort_hash[:direction] || 'ASC' limit = params[:limit] || 25 start = params[:start] || 0 if username.blank? users = User.order("#{sort} #{dir}").offset(start).limit(limit) total_count = User.count else users = User.where('username like ? or email like ?', "%#{username}%", "%#{username}%").order("#{sort} #{dir}").offset(start).limit(limit) total_count = users.count end render :inline => "{\"totalCount\":#{total_count},data:#{users.to_json(:only => [:id, :username, :email, :party_id])}}" end def new response = {} begin current_user.with_capability(:create, 'User') do user = User.new( :email => params[:email], :username => params[:username], :password => params[:password], :password_confirmation => params[:password_confirmation] ) #set this to tell activation where to redirect_to for login and temp password user.add_instance_attribute(:login_url, '/erp_app/login') user.add_instance_attribute(:temp_password, params[:password]) if user.save individual = Individual.create(:gender => params[:gender], :current_first_name => params[:first_name], :current_last_name => params[:last_name]) user.party = individual.party user.save response = {:success => true} else message = "