Mys.boardList = function(config)
{
	Mys.boardList.superclass.constructor.call(this, config);
	
	this.on("move", function(start, maxRow){
		this.startLoading();
		Global.modelItem.getBoardList(this.boardID, this.boardType, start, maxRow, this.keyword, this.order, function(data){
			if(data && data.response.code == 100)
				this.update(data.response.item, data.response.total);
			else
				this.empty();
		}, this)
	}, this);
};

Ext.extend(Mys.boardList, Mys.TemplateList, {
	boardType : 4,
	itemClass : Mys.boardItem,
	emptyType : "게시글",
	
	elTemplate : (new Ext.Template([
		'<div class="{headerClassName}"></div>',
		'<div class="{bodyClassName}"></div>',
		'<div class="{emptyClassName}">등록된 {emptyType}이 없습니다.</div>',
		'<div class="{loadingClassName}"><img class="mys-loading-img" src="/images/common/loadings.gif"/></div>',
		'<div class="{pagerClassName}"></div>',
		'<div class="{footerClassName}"></div>'
	])).compile(),
	
	footerTemplate : (new Ext.Template([
		'<form class="mys-search-form" onsubmit="return false;">',
			'<input type="text" style="width:198px; height:15px" class="input" name="keyword"/>',
			'<button class="mys-search-btn" type="submit" src="/images/common/btn_search.gif"></button>',
		'</form>',
		'<button class="mys-no-search" style="display:none;">원래대로</button>'
	])).compile(),
	
	render : function(el)
	{
		if(Mys.boardList.superclass.render.call(this, el) === false)
			return false;
		
		if(this.footerEl && this.footerTemplate)
		{
			this.form = this.footerEl.child("form");
			this.form.on("submit", function(){
				location.hash = "#state=list&page=1&keyword=" + this.form.dom.keyword.value;
			}, this);
			this.footerEl.child(".mys-no-search").on("click", function(){
				this.keyword = "";
				location.hash = "#state=list&page=1";
			}, this);
			
		}
	},
	
	search : function(keyword)
	{
		if(!keyword)
		{
			alert("검색어를 입력하세요");
			return false;
		}
		
		this.keyword = keyword;
		
		this.pager.first();
	},
	
	loadList : function(page)
	{
		if(KMAView.rendered)
			KMAView.el.setStyle("display", "none");
		
		this.render("kma-list");
		
		this.pager.setPage(parseInt(page) || 1);
		
    this.el.show();
    
    if(window.RReplyList)
    {
	    if(window.relationList && relationList.rendered)
	    	relationList.el.setStyle("display", "none");
	    
			RReplyList.render("recent-reply-list");
			
			RReplyList.refresh();
			
			RReplyList.el.show();
		}
	},
	
	goView : function(data, loadStart)
	{
		if(!ViewManager.isViewURL(data))
		{
			ViewManager.goView(data, loadStart);
			return;
		}
		
		if(this.rendered)
			this.el.setStyle("display", "none");
		
		KMAView.render("kma-view");
		
		KMAView.start = (this.pager.page - 1) * this.maxRow;
		
		KMAView.loadView(data.item_id, loadStart);
		
		KMAView.el.show();
	}
});