class Panel::Member::FrontEnd::MemberListsController < OrbitWidgetController

  helper MemberHelper
  
  def initialize
    super
    @app_title = 'member'
  end
  
  # GET /member_lists
  # GET /member_lists.xml
  
  def index
    
    @item = Page.find(params[:page_id])
    @title = @item.title
    if !@item.frontend_data_count.blank?
      @page_num = @item.frontend_data_count
    else
      @page_num = 10
    end
  
    date_now = Time.now

    @role_id = RoleStatus.get_role_data("teacher")
      
    @member_role = Role.where(:_id => @role_id)

    @member_subroles = SubRole.where(:role_id => @role_id, :disabled => false)
    
    @member_list_categorys = RoleCategory.can_display.any_in(:_id => params[:tag_id]).asc("key")

    @member_status = RoleStatus.can_display.any_in(:_id => params[:category_id]).asc("key")

    @mlcs = @member_list_categorys.map{|category| category.id.to_s }

    @mcs = params[:mcid].blank? ? @mlcs.first : params[:mcid]

    if !@member_list_categorys.blank? or !@member_status.blank?
     
      if !@mcs.blank? and @mlcs.include?(@mcs)
        @member_lists = User.where(:role_ids => @role_id,:role_category_ids => @mcs).asc(:position)
      else
        @member_lists = User.where(:role_ids => @role_id).asc(:position)
      end
    else
      # @member_lists = User.where(:role_ids => @role_id)
      @member_lists = ''
    end

  end
  
  def show
    @member = User.find(params[:id])

    @plugins = OrbitApp::Plugin::Registration.all

    @ppname = Array.new
    @plugins.each do |aa|
      @ppname << [aa.sort_number.to_i, [aa.name, aa.app_name, aa.intro_app_name, aa.front_partial_path]]
    end
    @plugin_shows = @ppname.sort.collect {|v| {"name"=>v[1][0],"app_name"=>v[1][1],"intro_app_name"=>v[1][2],"front_partial_path"=>v[1][3]} }


    @profile_data = []

    attribute_values = @member.attribute_values.asc("_id")
    attribute_values.each{|att_val|
      @profile_data.push({:name => att_val.attribute_field.title,:value =>att_val.get_value_by_locale(I18n.locale.to_s)}) if att_val.attribute_field.attribute.key=="profile" rescue false
    }

  end
  
  
  protected
  
  # def get_categorys
  #   @member_list_categorys = MemberListCategory.excludes('disable' => true)
  # end
  
end
