package com.exam.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.exam.constant.URL;
import com.exam.constant.SideMenu;
import com.exam.constant.TopMenu;
import com.exam.service.AuthorityService;

/**
 * 权限控制
 * 
 * @author chenyi
 * 
 */
@Controller
public class AuthorityController extends BaseController {
	@Autowired
	private AuthorityService authorityService;

	@RequestMapping(value = URL.TOP_MENU, method = RequestMethod.GET)
	public void getTopMenu(final ModelMap model) {
		List<String> topMenu = authorityService.getTopMenu();
		model.put("topMenu", topMenu);

	}

	/**
	 * 权限列表
	 * 
	 * @author chenyi
	 * 
	 */
	@RequestMapping(value = URL.GET_AUTHORITY_LIST, method = RequestMethod.GET)
	public void authorityList(final ModelMap model) {
		List<String> authorityList = authorityService.getAuthorityList();
		model.put("authorityList", authorityList);
		
	}

	@RequestMapping(value = URL.SIDE_MENU, method = RequestMethod.GET)
	public void getSideMenu(final ModelMap model, String topId) {
		List<String> sideMenu = authorityService.getSideMenu(topId);
		model.put("sideMenu", sideMenu);
	}

	@RequestMapping(value = URL.TEST, method = RequestMethod.GET)
	public String test(final ModelMap model) {

		return view(model, "testView", "", "");
	}

	/**
	 * 新建用户
	 * 
	 * @author chenyi
	 * 
	 */
	@RequestMapping(value = URL.USER_NEW, method = RequestMethod.GET)
	public String userNew(final ModelMap model) {

		return view(model, "userNewView", TopMenu.SYSTEM,
				SideMenu.USER_MANAGEMENT);
	}

	/**
	 * 新建角色
	 * 
	 * @author chenyi
	 * 
	 */
	@RequestMapping(value = URL.ROLE_NEW, method = RequestMethod.GET)
	public String roleNew(final ModelMap model) {

		return view(model, "roleNewView", TopMenu.SYSTEM,
				SideMenu.ROLE_MANAGEMENT);
	}
}
