package nlib.cmm.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import nlib.cmm.NlibCommonController;
import nlib.cmm.service.CodeService;

@Controller
public class CodeController extends NlibCommonController {

	private static final Logger log = LoggerFactory.getLogger(CodeController.class);
	
	@Resource(name="codeService")
	private CodeService codeService;
	
	@RequestMapping( {"/code/listCodes.do"} )
	public String listCodes(HttpServletRequest req, @RequestParam Map<String, String> paramMap, ModelMap model) throws Exception {

		String lCodeId = paramMap.get("lCodeId");
		
		List<Map<String, String>> resultList = codeService.listCodes(lCodeId);
		model.addAttribute("resultList", resultList);
		model.addAttribute("lCodeId", lCodeId);
		
		return "nlib/code/listCodes";
	}
	
	@RequestMapping( {"/code/listCodesPopup.do"} )
	public String listCodesPopup(HttpServletRequest req, @RequestParam Map<String, String> paramMap, ModelMap model) throws Exception {

		String lCodeId = paramMap.get("lCodeId");
		
		List<Map<String, String>> resultList = codeService.listCodes(lCodeId);
		model.addAttribute("resultList", resultList);
		model.addAttribute("lCodeId", lCodeId);
		
		return "nlib/code/listCodesPopup";
	}
	
}
