﻿Wiki.IView.Sector = Object.inherit(Wiki.IView.View, {
	__Sector_VIRTUAL_FUN: ["_getSectLevel", "_getSectCSS", "_getSectATitle","_getSectRTitle", "_getSectNTitle", "_getSectOps", "_getSectContent"],

	_isItem:function(){return this._model.isItem();},
	_isNew:function(){return this._model.isNew();},
	_getSectLevel:function(){
		var level = this._model.getLevel();		
		return (level>6?6:level);
	},
	_getSectCSS:function(){return "wiki_content";},
	_getSectOps:function(){return "";},
	_getSectATitle:function(){return ""},
	_getSectRTitle:function(){return ""},
	_getSectNTitle:function(){return ""},
	_getSectHTitle:function(){return ""},
	__renderAnchorToc:function(){return (this.isAppxVisible(this.__TOC) && !this._isNew() && !this._isItem())?this.pf("sector.atoc",[this.i18n("toc.atoc"), this.getPrefix(this.__TOC)]):"";},
	_renderContent:function(){
		return this.pf("sector.content", [this._id,this._getSectCSS(),this._getSectContent()]);
	},
	_renderBody:function(){
		//log(":::"+ this.pf("sector.title", [this._id, this._getSectATitle(), this._getSectNTitle(), this.__renderAnchorToc(), this._getSectHTitle()])+":::");
		return this.pf("sector.body",[this._getSectLevel()+"", this._getSectOps().replaceAll("#ID#", this._model.getId()),
			this.pf("sector.title", [this._id, this._getSectATitle(), this._getSectNTitle(), this.__renderAnchorToc(), this._getSectHTitle()]),
			this._getSectRTitle(), this._id, this._renderContent()]);
	},
	_render:function(){return this.pf("sector.tmpl", [this._id, this._renderBody()]);}
});

Wiki.IView.Section = Object.inherit(Wiki.IView.Sector, { //for render
	_isEdit:function(){return this._model.view_stat==0;},
	_getSectOps:function(){
		if(Wiki.Config.readonly){return "";}
		if (this._isNew()){return this.__renderWOp(this._isEdit()?"previewN":"back2editN");}
		
		return this._isItem()? this.__renderWOp("editAll"):"";
		// Abandon here!
		var opflist = ["save", "cancel"];
		if (!this._isEdit()){
			opflist = ["edit", "wnew"];
			if (this._isItem()){
				if (this._model.isFolder() && !this._model.isBookFolder()){
				//	opflist=["property"];
					opflist= [];
				}
				else if (this._model.isImage()){opflist=["edit"];}
				else {opflist.unshift("editAll");}
			} else {opflist.push("move", "wdelete");}
		}
		return this.__renderWOpList(opflist, this._isNew()?"N":"");
	},

	_getSectATitle:function(){return this._model.getTidx("&nbsp;&nbsp;") + (this._isEdit()?this.pf("section.label", [this.i18n("item.title")]):this._getTitle().trunc(this._isItem()?90:60));},
	_getSectRTitle:function(){
		var title = (this._isItem()?this._model.getPath():"")+this._model.getTitle(); 
		return title.length>60?title.replaceAll('"', "''"):"";
	},
	_getSectNTitle:function(){return this.pf("section.title", [this._id, this._model.getTitle(), this._isEdit()?"":"none"]);},
	initialize:function(node, container){
		this._init_View(node, container);
		var vs = this._model.view_stat;
		this._model.view_stat = vs?vs:(this._isNew()?0:1);
	}
},{// for refresh
	_loopF:function(ltype, acc0, fun){return this._model[ltype](acc0, function(acc, item, idx){
		return fun(acc, this.newViewObject(item.getType(), item), idx);
	}.bind(this));},
	loop:function(acc, fun){return this._loopF("loop", acc, fun);}, // only sons
	loopDsc:function(acc,fun) {return this._loopF("loopDsc", acc, fun);}, // not include self
	loopAll:function(acc, fun){return this._loopF("loopAll", acc, fun);},// include self

	_insToDOM:function(befNode){
		var divNode = this._getDiv(this._container._container, "wiki_sect", this._getViewId(), befNode);
		this._refreshView();
		return divNode;
	},
	_insChildsToDOM:function(befNode){return this.loopDsc(befNode, function(acc, item){return item._insAllToDOM(acc);});},
	_insAllToDOM:function(befNode){return this._insToDOM(this._insChildsToDOM(befNode));},
	_show:function(stype){
		var funs=["_insToDOM", "_insChildsToDOM", "_insAllToDOM"];
		var fun =function(xid){return $X("wiki_"+xid)?$X("wiki_"+xid):null;};
		var node = this._model;
		while(true && stype>0){
			var lnode=node.getLastNode();
			if (lnode.getId()==node.getId()){break;}
			node = lnode;
		}
		var nextNode = node.getNextSeqNode();		
		this[funs[stype]](fun(nextNode?this.newViewObject(this.__SECTION,nextNode)._id:this.getPrefix(this["__"+this.getAppxList()[1][0]])));
	},
	_refreshTidx:function(){
		var node = $X('wiki_title_'+this._id);
		if(node){
			node.parentNode.className= "wiki__title wiki_"+this._getSectLevel() + "_title";
			node.parentNode.title = this._getSectRTitle();
			this._refresh(node, this._getSectATitle());
		}
	},
	_clean:function(stype){
		if(stype==0){return this._container.remove(this._getView());}
		this.loop(0,function(acc, item){
			item._clean(1);
			item._clean(0);
		});
		return true;
	},
	_remove:function(stype){
		if (stype==0){
			if(this._isNew()){this.toSave();}
			return this._clean(0);
		}
		return this.loopAll(0, function(acc, item){item._remove(0);});
	}
},{// Real operation;
	render:function(){return this._render();},
	renderChilds:function(){return this.loop("", function(acc, item){return acc+item.renderAll();});},
	renderAll:function(){return this.render()+this.renderChilds();},

	show:function(){this._show(0);},
	showChilds:function(){this._show(1);},
	showAll:function(){this._show(2);},

	refresh:function(){this._refreshView();},
	refreshAllTidx:function(){this.loopAll(0, function(acc, item){item._refreshTidx();});},

	remove:function(){this._remove(0);},
	removeAll:function(){this._remove(1);},

	cleanAll:function(){this._clean(0);this.cleanChilds();},
	cleanChilds:function(){this._clean(1);}
},{ // for inline editing only
	save:function(){
		if (!this._isEdit()){return;}
		var previousNode = null;
		var title = $X('wiki_title_'+this._id+'_input').value;
		if (this._isItem()){
			//this._model.saveTags($X('wiki_tag_'+this._id +'_input').value);
			//this._model.saveTopic($X('wiki_topic_'+this._id +'_input').value);			
			this._model.save(title, "");
		}
	},
	saveAll:function(){this.loopAll("", function(acc, item){item.save();});},
	_toView:function(ifView) {this._model.view_stat =ifView?1:0;this.refresh();},
	toEdit:function(){this._toView(false);},
	toSave:function(){this.save();this.toView();},
	toView:function(){this._toView(true);}
});

Wiki.View.Item = IX.Class.create();
Wiki.View.Item.prototype= Object.inherit(Wiki.IView.Section, {
	_pf:function(key, param){return this.pf("item."+key, param);},
	_i18n:function(key){return this.i18n("item."+ key);},
	__isXFolder:function(){return this._model.isFolder() &&! this._model.isBookFolder();},	
	_getSectLevel:function(){return this.__isXFolder()?"folder":"0";},
	_getSectCSS:function(){return "wiki_summary";},
	_getSectNTitle:function(){return this.__isXFolder()?("&nbsp;"+ this.__renderROp("property").inTag("span", [["class", "wiki_stctl"]]).replace("#ID#", this._model.getId())):"";},
	_getSectHTitle:function(){
		//if (!this.__isXFolder()){
			return "";
		//}
		//var fun = function(act, which) {return this.__genEventFunStr(act+"Menu").replace("#PARAM#", which);}.bind(this);		
		//return ('onmousemove="'+fun("show", "hint") +'" onmouseout="' + fun("hide", "hint") + '"').replaceAll("#ID#", this._model.getId());
	},
	_getTitle:function(){
		var title = this._model.getTitle();
		if (this.__isXFolder()) {
			var path = this._model.getPath() + title;
			return path.length>85?("..."+path.substring(path.length-85)):path;
			//var pl = path.length;
			//var tl = title.length;
			//var len =  Math.max(85-tl,3);
			//title =  ((tl + pl)>85?("..."+path.substring(pl-len)):path)  + title;
		}
		return title;
	},
	_renderContent:function(){
		var content = this._getSectContent();
		if (this.__isXFolder()){
			var kiView = new Wiki.View.KItems(this._model.getRoot().getAppx(this._model.__KITEMS), this._container);
			content = kiView._renderContent();
		}
		return this.pf("sector.content", [this._id,this._getSectCSS(),content]);
	},
	_refreshView:function(){
		this._refreshTidx();
		if (this.__isXFolder()){
			var descView = new Wiki.View.KDesc(this._model.getRoot(), this._container);
			descView.refresh();
		} else {
			this._refresh(this._getView(), this._renderBody());
		}
	},

	__getTrArr:function(name, data){return [this._i18n(name), data];},
	//__getTagsTr:function(tags) {
	//	return this._pf("tr1",  [this._i18n("tags"),  
	//		this.__renderALink(tags, this._isNew()?"###":("#wiki_anchor_"+this.getPrefix(this.__TAGS)), 'class="external"'), 
	//		Wiki.Config.readonly?"":this.__renderFLink("editTags","...", 'class="wiki_editBtn"')]);
	//},
	__getTagsTd:function(tags) {
		return this._pf("tds",  [this._i18n("tags"),  
			this.__renderALink(tags, this._isNew()?"###":("#wiki_anchor_"+this.getPrefix(this.__TAGS)), 'class="external"'), 
			Wiki.Config.readonly?"":this.__renderFLink("editTags","...", 'class="wiki_editBtn"')]);
	},
	__getTopicTds:function(topic) {
		return this._pf("tds", [this._i18n(topic), 
			this._model[topic=="topic"?"getTopic":"getExtTopic"](), 
			(Wiki.Config.readonly || !Wiki.Config.enable.topicEditable)?"":this.__renderFLink("editTopic","...", 'class="wiki_editBtn"').replace("#ID#", topic)
		]);
	},
	getMenuNode:function(){return $X('wiki_title_'+ this._id);},
	
	_getSectContent:function(){
		var summary = this._model.getContent();
		return summary;
		if (this._model.isFolder()){
			return summary;
		}
		if (this._model.isImage()){return summary.inTag("pre");}
	
		var tags = this._model.getTags().join(",").unhtml();
		var hasTags = this.isAppxVisible(this.__TAGS);
		var arr = hasTags?[this._pf("tr", this.__getTrArr("topic", this._pf("topicInput",[this._id, this._model.getTopic()])))	 + this._pf("tr", this.__getTrArr("exttopic", this._pf("exttopicInput",[this._id, this._model.getExtTopic()]))),
			this._pf("tr", this.__getTrArr("tags", this._pf("tagInput",[this._id, tags]))), 
			""]:["", "", ""];
		if (!this._isEdit()){
			arr = [this._isNew()?"":this._pf("tr", this.__getTrArr("summary", summary)),
				 hasTags?this._pf("tr2", [this.__getTagsTd(tags),this.__getTopicTds("topic")]):"",
				""
			];
		}
		return this.pf("item.content",arr);
	}
});

Wiki.View.Section = IX.Class.create();
Wiki.View.Section.prototype= Object.inherit(Wiki.IView.Section, {
	_getTitle:function(){return this._model.getTitle();},
	_getSectContent:function(){
		var  editor = new Wiki.View.Editor("", this._model, true);
		editor.setReadOnly(!this._isEdit());
		return editor.renderBody(false);	
	}
});
Wiki.IView.Appendix=Object.inherit(Wiki.IView.Sector, {	
	_initAppendix:function(model, container){
		this._init_View(model, container);
		this._vctl = new Wiki.View.Vctl(this._id+"_v", this._getViewBody.bind(this));
	},
	_getViewBody:function(){return $X('wiki_content_'+this._id);},
	_getSectATitle:function(){return this._model.getTitle();},
	_getSectNTitle:function(){return "&nbsp;&nbsp;"+this._vctl.render();},
	vctl:function(isShow){this._vctl.stCtl(isShow);},
	refresh:function(){this._refresh(this._getViewBody(), this._getSectContent());},
	render:function(ifOnlyBody){return ifOnlyBody?this._renderContent():this._render();},
	initialize:function(model, container){this._initAppendix(model, container);}
});

Wiki.IView.SimpleAppendix = Object.inherit(Wiki.IView.Appendix, {
	__renderLK:function(ktype, kid, klink, opN){
		return this.pf("appendix.klink", [this.i18n("imgalt."+this.__getAltOfLink(ktype)), this.__getImgUrl(this.__getImgOfLink(ktype)),klink,(!Wiki.Config.readonly&& opN)?("&nbsp;"+this.__renderWOp(opN)):"", kid]);
	},
	__renderLinkItem:function(ktype, kid, klink, opN) {return this.pf("appendix.item", [this.__renderLK(ktype, kid, klink, opN)]);},
	__renderKLink:function(ktype, kid, ktitle, opN) {return this.__renderLinkItem(ktype, kid, this.__renderFLink("toLinked", ktitle, 'class="external"'), opN);},
	__getAltOfLink:function(type){
		var alts=["item", "attached", "linked", "unknown", "wiki", "requirement",  "specification"];
		var alts2={attach:"attachedFile"};
		return (type in alts2)?alts2[type]:alts[type];
	},
	__getImgOfLink:function(type){
		var imgs = {attach:"attachment.png"};
		return (type in imgs)?imgs[type]:("item_01_"+type+".gif");
	},
	_getSectCSS:function(){return "wiki_appendix";}
});

Wiki.View.KDesc = IX.Class.create();
Wiki.View.KDesc.prototype = Object.inherit(Wiki.IView.SimpleAppendix,{
	_getSectCSS:function(){return "wiki_sect";},
	_getSectATitle:function(){return this.i18n("desc");},
	_getSectNTitle:function(){return "";},
	_getSectLevel:function(){return 0;},
	_getSectOps:function(){return Wiki.Config.readonly? "":this.__renderWOpList(["editAll", "edit", "wnew"], "");},
	_getSectContent:function(){
		var content = this._model.getContent();
		return this._model.isImgFolder()?content.inTag("pre"):content;
	},
	initialize:function(model, container){
		this._init_View(model.find("root"), container);
		this._id = this.getPrefix(this.__DESCRIPTION);
	}
});

Wiki.View.KItems = IX.Class.create();
Wiki.View.KItems.prototype = Object.inherit(Wiki.IView.SimpleAppendix, Wiki.IView.MultiPage, {
	_pf:function(name, param) {return this.pf("kitems."+ name, param);},
	__renderPageOpFun:function(acc, item,idx){
		var ifEnable = !this._model[idx<2?"isFirstPage":"isLastPage"]();
		var imgUrl = this.__getImgUrl("wiki_arrow_"+item.toLowerCase()+ (ifEnable?"":"_disable")+ ".gif");
		acc.push(ifEnable?this.__renderFIcon(imgUrl, item, "", "jumpTo"+item):this.__renderIcon(imgUrl, item, ""));
		return acc;
	},
	__renderCheckBox:function(chkFunName, txt, props, ctype, kid) {
		return this._pf("chk", [this.__genFunStr(chkFunName), props?props:"", ctype?ctype:"", txt?this._pf("chklabel", [txt]):"", this._id, kid]);
	},

	_getSectCSS:function(){return "wiki_kilist";},
	_getSectContent:function(idList) {
		var eid = null;
		var arr =  this._model.getPIArray();
		if (idList && idList.length>0 && !this._model.isLastPage()){
			arr[2] +=1;
			eid =  idList[0];
		}
		var pages = this.__renderPagesBody(arr);
		var chkbox= this.__renderCheckBox("chkIncludeChildFolder", "", this._model.ifIncludeChild()?"checked":"", "child", "");
		var  fun = function(act, which){return this.__genEventFunStr(act+"Menu").replace("#PARAM#", which);}.bind(this);
		var ifThumbnail = false;
		var viewtype= IX.Utils.loop(this._model.getViewParams(), "", function(acc, item, idx){
			ifThumbnail = ifThumbnail || (item[0]=="img" && item[1]==1);
 			return acc + this._pf("viewtype", [(idx*3 + item[1]*1)*16, this.__genFunStr(item[0]+"TypeReset4Kilist"), 
				fun("show", "chose"+item[0]), fun("hide", "chose"+item[0]), 
				this._model.getId(), this._id, item[0], item[0]=="img"?"wiki_ifolder_sel":"wiki_rfolder_sel"] );
		}.bind(this));
		var hdr = "";
		switch(this._model.getActionType()) {
		case "book": hdr = this._pf("hdr3", [chkbox,this.i18n_op("includeChildFolder"), pages]); break;
		case "topic": hdr = this._pf("hdr2", [this.__genFunStr("link2Topic"), pages]); break;
		default:
			hdr =  this._pf("hdr", [chkbox,this.i18n_op("includeChildFolder"),viewtype, this.__renderWIcon("wiki_arrow_down.gif", "menu", "")+"Actions", fun("show", "kitems"), fun("hide", "kitems"), this.__renderPagesBody(arr)]).replaceAll("#ID#", this._model.getId());
			break;
		}
		hdr = hdr.replaceAll("#ID#", this._model.getId());
		return this._pf("tmpl", [hdr, this._id, this["__render"+(ifThumbnail?"Thumnnail":"KItems")](eid)]);
	}, 
	__renderThumnnail:function(idExtra){
		var view = this;
		var obj = view._model;
		var onloadStr = 'onload="' +"var ratio=Math.max(this.height, this.width, 96)/48; var y=Math.floor(this.height/ratio);var x=Math.floor(this.width/ratio);with(this.style){height=2*y+'px';width=2*x+'px'; marginRight=(48-x)+'px';marginLeft=(48-x)+'px';marginTop=(48-y)+'px';}; "+ '"';
		var rfun = function(node){
			return view._pf("ithumb", [view.__renderCheckBox("chkItemInFolder", '', '', '', node.getId()),
				view.__renderWFIcon("toLinked",node.getProps("img") ,"", "",onloadStr),
				view.__renderFLink("toLinked", node.getProps("title"))]).replaceAll("#ID#", "thumb_" +node.getProps("id")); 
		};
		return obj.loopPage(idExtra?rfun(obj.getLastChild()):"",  function(acc, item){return acc + rfun(item);});

	},
	__renderKItemTblHdr:function(cols, col) { //col:[id, width, type, name, nowrap, sortable],
		var oarr = [cols.orderBy==col[0], cols.order];
		var ktxt = col[3];		
		var actF = "sortKilist";
		if (oarr[0]) {
			ktxt += this.__renderWIcon("wiki_order_" +oarr[1]+".gif", "order_" + oarr[1], "");
			actF = (oarr[1]=="asc"?"dsc":"asc") + "OrderKilist";
		}
		 if (col[3] && col[5]!="false"){ktxt = this.__renderFLink(actF, ktxt, '').replace("#ID#", this._model.getId()+"_" + col[0]);}
		return [ktxt, col[1]>0?('style="width:' + col[1] + 'px;"'):''];
	},
	__renderKItemTblCol:function(col, node) { //col:[id, width, type, name, nowrap, sortable],
		var ktxt = "";
		var clz = "";
		var props = "";
		var prmid = col[0];
		var xn = node.getProps(prmid);
		var xid = node.getProps("id");
		if (prmid == "title" || prmid=="id"){
			ktxt = this.__renderFLink(this._model.isFolder()?"toLinked":"toLinkedAndCheck", xn, 'class="external" id="wiki_a_#ID#"').replaceAll("#ID#", "ki_" + xid);
			if (prmid=="title") {clz =  "wiki_left"; }
		} else if (prmid=="type") {
			//props +='style="background:url('+this.__getImgUrl(this.__getImgOfLink(xn)) +') no-repeat 4px 4px;cursor:hand;"';
			if (Wiki.Config.enable.ki_grapable && node){
				props +=  ' onmousedown="'+this.__genEventFunStr("grapList").replace("#ID#",  node.getProps("id")) + '"' ;
				//props +=  ' onmouseup="'+this.__genEventFunStr("releaseGrapList").replace("#ID#",  node.getProps("id")) + '"' ;
			}
			//alert(props);
			ktxt = '<span style="background:url('+this.__getImgUrl(this.__getImgOfLink(xn)) +') no-repeat;cursor:hand;width:30px;height:22px;display:block"></span>';
			//ktxt =  this.__renderWIcon(this.__getImgOfLink(xn), this.__getAltOfLink(xn), "wiki_type_img");
			clz =  "wiki_left";			
		} else if (prmid=="img") {
			ktxt =  this.__renderAIcon(xn, "", "");
		} else if (prmid=="mapped"){
			ktxt = this._pf("mapped", [this._id, xid, "", this.__renderFLink("mappingTopic","...", 'class="wiki_editBtn"').replace("#ID#", xid)]);
		} else {
			if(col[2]=="user"){clz = "wiki_left"; }
			ktxt = xn._cdata; 
		}
		if (col[4]!="false" && !isMSIE()) { clz += (clz.length>0?" ":"") + "wiki_nowrap";}
		return [ktxt, (clz.length>0?('class="' + clz + '" '):'')+(props.length>0?props:"")];
	},
	__renderKItems:function(idExtra){
		var view = this;
		var obj = view._model;
		var columns = obj.getColumns();
		if (obj.isBookFolder()){
			columns.list = IX.Utils.loop(columns.list, [], function(acc, item) {
				if (item[0]=="type" || item[0]=="title" || item[0]=="1112"){ // 1112 is id for "ID" column 
					acc.push(item);
				}
				return acc;
			});
			columns.list.push(["mapped","200", "", "Mapped Section", "", "false"]);
		}
				
		var idx = 0;
		var actionType = this._model.getActionType();
		var nfun = function(tname, props, txt) {return view._pf(tname, [props?(" "+props):"", txt?txt:"&nbsp;"]);};
		var rfun = function(node){
			var isHdr = node==null;
			var xid = (isHdr?(obj._id+"_hdr"):node.getId());
			var trProps=  'id="wiki_'+ xid  + '"';
			trProps += ' class="wiki_'+(isHdr?'first':(node && node.getProps("isSelf")>0?"toc_chose":(idx%2==0?"toc_odd":"toc_even")))+ '"';
			trProps += !(isHdr || node.isVisible())?' style="display:none;"':"";
			if (!(isHdr || actionType=="book")){
				var evtH ='"Wiki.RightClick(event, function(evt){';
				evtH += view.__genFStr("rightClick", "[evt, '"+ node.getId() + "', '" +actionType + "']");
				evtH +='});"'
				//if(isMSIE()) {
				//	trProps += ' oncontextmenu='+ evtH;
				//}else {
					trProps += ' onmousedown='+ evtH ;//+ ' onmouseup='+ evtH ;
				//}
			}
			
			var stctl = null;
			if (!isHdr){
				//stctl = new Wiki.View.FolderCtl(view._id+ "_"  + node.getId()+ "_f", node.hasChild()?2:0);
				if (node.isVisible()) {idx +=1;}
			}

			var tdFirst = nfun('col', 'class="wiki_left" ' + (isHdr?' style="width:24px;"':""), 
					view.__renderCheckBox("chkItemInFolder", '', (node && node.getProps("isSelf")>0?"checked ":""), '', (isHdr?obj:node).getId()) 
					+(!isHdr && node.getLevel()==1&& stctl?stctl.render():"")
			);
			return nfun("row",trProps,
				IX.Utils.loop(columns.list, tdFirst, function(acc, item) {
				var arr =isHdr?view.__renderKItemTblHdr(columns, item):view.__renderKItemTblCol(item, node);
				return acc + nfun('col', arr[1], arr[0]);
			}));
		};
		return this._pf ("body", [obj.loopPage(rfun(null)+ (idExtra?rfun(obj.getLastChild()):""),  function(acc, item){
			return item.loopAll(acc, function(xacc, xitem){return xacc+ rfun(xitem);});
		})]);
	},

	stCtl:function(sid, stat){
		var stctl = new Wiki.View.FolderCtl(sid, stat);
		stctl.stCtl(stat);
		var node = this._model.find(sid.split("_")[2]);
		node[stat==1?"expand":"collapse"]();
		var idx =0 ;
		var setOdd=function(node, idx){
			var clz = "wiki_toc_"+ (idx %2==1?"even":"odd");
			if (node.className!=clz){node.className=clz;}
		};
		var setVisible=function(node, ifVisible){
			var st= ifVisible?"":"none";
			if (node.style.display != st){node.style.display = st;}
		};
		this._model.loopDeep(0, function(acc, item){
			idx += item.isVisible()?1:0;
			var node =  $X('wiki_'+item.getId());
			setOdd(node, idx);
			setVisible(node, item.isVisible());
		});
	},

	updateSelfItemTitle:function() {
		var item = this._model.updateSelfItemTitle();
		if (!item){return;}
		var  node = $X('wiki_a_ki_'+ item.getProps("id"));
		if (node){
			var nnode = node.cloneNode(true);
			nnode.innerHTML = item.getTitle();
			node.parentNode.replaceChild(nnode, node);
		}
	},
	
	setIncludeChild:function() {this._model.setIncludeChild($X('wiki_chkchild_'+this._id + "_").checked);},
	_getCheckBox:function(item){return $X( 'wiki_chk_'+ this._id +"_" + (!item?this._model:item).getId());},
	_isChecked:function(item) {
		var chkItem = this._getCheckBox(item);
		return chkItem?chkItem.checked:false;
	},
	_getPageInfo:function(acc, fun){return this._model.loopPage(acc, function(acc, item){return item.loopAll(acc, fun);});},
	itemIsChecked:function(item){return this._isChecked(item);},
	setStat4Item:function(item, flag){this._getCheckBox(item).checked = flag;},		
	setStat4AllItems:function(flag){
		this._getPageInfo(flag, function(acc0, item0) {
			this.setStat4Item(item0, acc0);return acc0;
		}.bind(this));
	},
	selectAllItems:function(){this.setStat4AllItems(this._isChecked());},
	getCheckedItems:function(){
		return this._getPageInfo([], function(acc0, item0) {
			if (this._isChecked(item0)){acc0.push(item0.getId());}
			return acc0;
		}.bind(this));
	},
	resetCheckBox:function(checkIds){
		IX.Utils.loop(checkIds, 0, function(acc, item){
			$X( 'wiki_chk_'+ this._id +"_" + item).checked = true;
			return 0;
		}.bind(this));
	},
	getMenuNode:function(){return $X('wiki_actions_'+ this._id);},
	getChoseNode:function(type){return $X(this._id + "_isel_"+ type);},
	_getChecked:function(){
		return this._getPageInfo([], function(acc0, item0) {
			if (this._isChecked(item0)){acc0.push(item0.getProps("id"));}
			return acc0;
		}.bind(this));
	},
	getActionParam:function(act){return  this._getChecked();},
	addNodes:function(idList) {this._refresh(this._getViewBody(), this._getSectContent(idList));},
	setMapped:function(nodeId, value) {$X(this._id + "_" + nodeId +"_mapped").innerHTML = value;},
	link2Topic:function() {
		var chkList = this._getChecked();
		if (chkList.length==0){
			alert("Please select at least 1 item to link.");
		}else {
			this._model.link2Topic(IX.Utils.loop(chkList, [], function(acc, item){
				acc.push([item, $X(this._id + "_" + item +"_mapped").innerHTML]);
				return acc;
			}.bind(this)));
		}
	},
	getActionName:function(act){return this.i18n("menu.action"+act.substring(0,1).toUpperCase()+ act.substring(1));}
});

Wiki.View.Linked = IX.Class.create();
Wiki.View.Linked.prototype = Object.inherit(Wiki.IView.SimpleAppendix,{
	_getSectOps:function(){return this.__renderROp("addLinked");},
	_getSectContent:function(){return this.__renderUl(IX.Utils.loop(this._model.getAll(), "", function(acc, item, idx) {
		return acc + this.__renderKLink(item[1], item[0], item[2], "removeLinked");
	}.bind(this)));}
});

Wiki.View.Attachment = IX.Class.create();
Wiki.View.Attachment.prototype = Object.inherit(Wiki.IView.SimpleAppendix, {
	_getSectOps:function(){return this.__renderROp("addAttachment");},
	_getSectContent:function(){return this.__renderUl(IX.Utils.loop(this._model.getAll(), "", function(acc, item, idx) {
		var taLink = Wiki.Config.isLocalMode?this.__renderFLink("toAttached", item[2], 'class="attach"').replace("#ID#", item[1]):this.__renderALink(item[2],item[1],'class="attach" target="_blank"');
		return acc + this.__renderLinkItem("attach", item[0], taLink,"removeAttached");
	}.bind(this)));}
});

Wiki.View.Tag = IX.Class.create();
Wiki.View.Tag.prototype = Object.inherit(Wiki.IView.SimpleAppendix, {
	__getFolderCtl:function(sid, stat) {return new Wiki.View.FolderCtl(sid, stat);},
	_getSectContent:function(){return this.__renderUl(IX.Utils.loop(this._model.getAll(), "", function(acc, item, idx) {
		var stCtl = this.__getFolderCtl(this._id+"_"+idx+"_f", item[1].length==0?0:2);
		return acc + this.pf("appendix.tagitem", [stCtl.render(),item[0].unhtml(), stCtl.getId(), IX.Utils.loop(item[1], "", function(acc, itm){
			return acc + this.__renderKLink(itm[1], itm[0], itm[2], "");
		}.bind(this))]);
	}.bind(this)));},
	stCtl:function(sid, stat){this.__getFolderCtl(sid, stat).stCtl(stat);}
});

Wiki.IView.Comment = {
	__getComment:function(cmt){return this.newViewObject(this.__COMMENT, cmt);}
};

Wiki.View.Comment = IX.Class.create();
Wiki.View.Comment.prototype = Object.inherit(Wiki.IView.View,Wiki.IView.Comment, {
	_getBodyX:function(){
		var rcont = this._model.getContent();
		var content = rcont.stripTags().trunc(80);
		var ifHtml = this._model.ifHtml;
		var sttop = content==rcont?"":this.__renderAOp(["viewComment", this.i18n_op(ifHtml?"hide":"read") +"&nbsp;..."]).replaceAll("#ID#", this._model.getId());
		return [this.pf("cmt.content", [sttop, this._id, (ifHtml ||rcont==content)?rcont:(content+"<b>...</b>")]), sttop	];
	},
	render:function() {
		var w= 2* this._model.getLevel()-2;
		var bodyX = this._getBodyX();
		var str = this.i18n_op("edit");
		var cmtOp= Wiki.Config.readonly?"":((this._model.canEdit()?this.__renderAOp(["editComment", str]):this.pf("cmt.editdop", [str]))+ this.__renderWOp("reply","Comment"));
		var hdr = this.pf("cmt.hdr", [this._fCtl.render(),bodyX[1], cmtOp, this._id, this._model.getTidx("&nbsp;"), this._model.getTitle()]);
		return this.pf("cmt.tmpl",[100-(isMSIE()?0:w), w, (this._model.getLevel()==1 || this._model.isVisible())?"block":"none", this._id,
			hdr, bodyX[0], this._model.getPoster(), this._model.getDate(), this.i18n("cmt.poston")]).replaceAll("#ID#", this._model.getId());
	},
	
	renderAll:function(){return this._model.loopAll("", function(acc, item){return acc + this.__getComment(item).render();}.bind(this));},
	_expandView:function(visible){
		this._model.loop(0, function(acc, item){
			var view =  this.__getComment(item);
			var vs = visible && item.isVisible()
			view._display(view._getView(),vs);
			view._fCtl.updView();
			if (item.hasChild()){view._expandView(vs && item.ifExpanded());}
		}.bind(this));
	},
	stCtl:function(sid, stat){this._fCtl.stCtl(stat);},
	refresh:function(){
		var bodyX = this._getBodyX();
		this._refresh($X('wiki_title_'+this._id), (this._model.getTidx("&nbsp;")+this._model.getTitle()).inTag("b"));
		this._refresh($X('wiki_cmt_brief_'+this._id), bodyX[1].replaceAll("#ID#", this._id));
		this._refresh($X('wiki_cmt_detail_'+this._id), bodyX[0]);
	},
	view:function(){
		this._model.ifHtml = !this._model.ifHtml;
		this.refresh();
	},
	initialize:function(cmt, container){
		this._init_View(cmt, container);	
		this._fCtl = new Wiki.View.FolderCtl(this._id+"_f", this._model.hasChild()?(this._model.ifExpanded()?1:2):0, function(stat){
			this._model[stat==1?"expand":"collapse"]();
			this._expandView(stat==1);
		}.bind(this));
	}
});

Wiki.View.Comments = IX.Class.create();
Wiki.View.Comments.prototype = Object.inherit(Wiki.IView.Appendix, Wiki.IView.MultiPage, Wiki.IView.Comment, {
	_pf:function(tname, param){return this.pf("appendix."+tname, param);},
	__renderPageOpFun:function(acc, item){
		var otitle = this.i18n_op(item);
		acc.push(this._model.isMutilPage()?this.__renderFLink("jumpTo"+item, otitle):otitle);
		return acc;
	},
	_renderPages:function(n){return this._pf("mpind", [
		"wiki_comments_pages" + (this._model.isMutilPage()?"":" wiki_diasble"), 
		this.__renderPagesBody(), this._id + "_"+n]);
	},
	__renderCmts:function(){return this._model.loopPage("", function(acc, item){
		return acc + this.__getComment(item).renderAll();
	}.bind(this));},
	_getSectContent:function(){return this._pf("cmtbody", [this._renderPages(0), this._renderPages(1), this._id, this.__renderCmts() ]);},
	_getSectCSS:function(){return "wiki_comments_body";},
	_getSectOps:function(){
		var op = this._model.ifExpanded()?"collapse":"expand";
		return (this.__renderAOp([op+"Comment", this.i18n_op(op+"All")])+ this.__renderROp("postComment")).replaceAll("#ID#", this._model.getId());
	},
	refresh:function(rtype){ //rtype==0:expand/collpase; 1:post/jump, need to refresh Page
		if (rtype==1){
			this._refresh($X('wiki_title_'+this._id), this._model.getTitle());
			this._refreshPages(0);
			this._refreshPages(1);
			this._refresh($X('wiki_list_'+this._id),this.__renderCmts());
		} else {
			this._refresh($X('wiki_ops_'+this._id), this._getSectOps());
			this._model.loopPage("", function(acc, item){
				var view = this.__getComment(item);
				view._fCtl.updView();
				view._expandView(true);
			}.bind(this));
		}
	}
});

Wiki.View.KImage = IX.Class.create();
Wiki.View.KImage.prototype = Object.inherit(Wiki.IView.View,{
    refresh:function() {},
	render:function() {return this.pf("kimg.tmpl", [this.__renderIcon(this._model.getUrl(), "Image name:"+ this._model.getAlt(), ""), this._id]);},
	initialize:function(model, container){
		this._init_View(model, container);		
	}
});

Wiki.View.QuickLinks = IX.Class.create();
Wiki.View.QuickLinks.prototype = Object.inherit(Wiki.IView.SimpleAppendix,{	
	_getSectOps:function(){return this.__renderROp("addQuickLinks");},
	_getNumOfTocItem:function(){
		var view = this.newViewObject(this.__TOC, this._model.getRoot());
		return view.getNumOfTocItem();
	},
	resize:function(){
		var fun = function(){
			var  view = this._getView();
			if(!view){setTimeout(fun, 10); return;}
			var bodyView = this._getViewBody();
			var  stat = ("stCtl" in this._model &&  !this._model.stCtl); 
			var h = (stat?0:this._getNumOfTocItem())*20;
			view.style.height= (h+ (isMSIE()?22:26)) +"px";
			bodyView.style.height= h +"px";
		}.bind(this);
		fun();
	},
	vctl:function(isShow){
		this._vctl.stCtl(isShow);
		this._model.stCtl = isShow;
		this.resize();
	},
	_render:function() {return this.pf("qlinks.tmpl", [this._getSectContent(),  this._vctl.render(), this._model.getTitle(), this._getSectOps().replace("#ID#", this._model.getId()), this._id]);	},
	refresh:function() {
		this._refresh(this._getViewBody() , this._getSectContent());
		this.resize();
	},
	stCtl:function(sid, stat) {
		var gid = sid.substring(this._id.length+1, sid.length-2);
		this._model.setExpanded(gid, stat%2);
		if (isMSIE()){
			this._refresh(this._getViewBody() , this._getSectContent());
			return;
		}
		var setOdd=function(node, idx){
			var clz = "wiki_toc_"+ (idx %2==1?"even":"odd");
			if (node.className!=clz){node.className=clz;}
		};
		var setVisible=function(node, ifVisible){
			var st= ifVisible?"":"none";
			if (node.style.display != st){node.style.display = st;}
		};
		var nidx = 0;
		IX.Utils.loop(this._model.getAll(), "", function(html, grp){		
			 nidx += 1;
			var ifVisible = grp[4]>0;
			var vid = this._id+ "_" +  grp[0];
			if (grp[0] == gid){$X(vid).innerHTML = this.__renderGItem(grp[1], ifVisible, grp[2], grp[0]);}
			setOdd($X(vid), nidx);
			IX.Utils.loop(grp[3], "", function(acc, item) {
				nidx += (ifVisible?1:0);
				var node = $X(vid + "_" +  item[0]);
				setOdd(node, nidx);
				setVisible(node,ifVisible);
			}.bind(this));
		}.bind(this));
		for (var i=0; i<this._getNumOfTocItem();i+=1){setVisible($X(this._id+ "_empty" +  i),i>=nidx);}
	},
	__renderQItem:function(editable, xtitle, xid, ifLast, xtype, gid){
		var imgOp =  this.__renderWIcon("tree_leaf"+ (ifLast?"_last":"")+".gif", "none",'', 'style="margin-left:20px;"'); 
		var imgType = this.__renderLK(xtype, xid, "", "");
		var klink = this.__renderFLink("toLinked", xtitle, 'class="external"').replace("#ID#", xid);
		
		var qOp = "";//editable?this.__renderROp("removeQuickLink").replace("#ID#", gid+"_"+xid):"";
		return this.pf("qlinks.col", [imgOp, "wiki_grpitem", imgType, klink, "wiki_right",  qOp]);
	},
	__renderGItem:function(editable, ifCollapsed, gTitle, gid){
		var imgN = ifCollapsed?"opened":"closed";
		var imgOp =  this.__renderWFIcon((ifCollapsed?"collapseST":"expandST"), "tree_"+imgN+ ".gif", imgN,'', 'style="margin-left:4px;"').replace("#ID#", this._id+"_" +gid+"_f"); 
		var imgType = this.__renderIcon(this.__getImgUrl("tree_folder_"+ imgN +".gif"), "", "");
		var grpOp = editable?this.__renderROp("editQuickLinks").replace("#ID#", gid):"";
		return this.pf("qlinks.col", [imgOp,  "wiki_grpitem",imgType, editable?gTitle.inTag("b"):gTitle, "wiki_right",  grpOp]);
	},
	_getSectContent:function(){
		var itemF = function(idx, col, cid, ifV) {return this.pf("qlinks.list", [idx%2==0?"even":"odd", col, this._id+ "_"+ cid, ifV?"":"none"]);}.bind(this);
		var nidx = -1;
		var allHtml = IX.Utils.loop(this._model.getAll(), "", function(html, grp){		
			nidx += 1;
			var gid = grp[0];
			var editable = grp[1];
			var list = grp[3];
			var ifVisible = grp[4]>0;
			var gtitle = grp[2];
			return html+  itemF(nidx, this.__renderGItem(editable, ifVisible, gtitle, gid), gid, true) +(isMSIE()&&!ifVisible?"":IX.Utils.loop(list, "", function(acc, item, idx) {
				nidx+=ifVisible?1:0;
				return acc + itemF(nidx, this.__renderQItem(editable, item[2], item[0], (idx==list.length-1), item[1], gid),gid +"_"+item[0], ifVisible);
			}.bind(this)));
		}.bind(this));
		var num = this._getNumOfTocItem();
		if (isMSIE()){
			for (var i=nidx+1; i<num;i+=1){allHtml += itemF(i, "&nbsp;", "empty"+i, true);}
		} else {
			for (var i=0; i<num;i+=1){allHtml += itemF(i, "&nbsp;", "empty"+i, i>nidx);}
		}
		return allHtml;
	}
});

Wiki.IView.List = Object.inherit(Wiki.IView.View, {
	__List_VIRTUAL_FUN:["_getItemTemp", "_getNodeList"],
	_renderList:function(){return IX.Utils.loop(this._getNodeList(), "", function(acc, item, idx) {
		var n = item.getLevel()*4;
		var title = "&nbsp;".multi(n)+((n==0?"":item.getTidxForce("&nbsp;"))+item.getTitle());
		return acc + this._getItemTemp().loopReplace([["#ID#", item.getId()], ["#TITLE#", title], ["#TOE#", (idx%2==0)?"even":"odd"]]);
	}.bind(this));},
	_initList:function (model,viewId){
		this._model = model;
		this._id = viewId;
	}
});

Wiki.View.Toc = IX.Class.create();
Wiki.View.Toc.prototype = Object.inherit(Wiki.IView.List, {
	_getNodeList:function(){
		return IX.Utils.loop(this.getAppxList()[1], this._model.find("root").getAllNode(), function(acc, item){
			var atype  =  this["__"+item];
			if (this.isAppxVisible(atype)){acc.push(this._model.getAppx(atype));}
			return acc;
		}.bind(this));
	},
	getNumOfTocItem:function(){return this._getNodeList().length;},
	_getItemTemp:function(){
		var fun = function(act){return this.__genEventFunStr(act+"Menu").replace("#PARAM#", "toc");}.bind(this);
		var pophtm = Wiki.Config.readonly?"":this.pf("toc.popicon", [this.__getImgUrl("wiki_arrow_pop.png"), this.i18n("imgalt.menu"), fun("show"), fun("hide")]);
		return this.pf("toc.list", [pophtm, this._id,  this.getPrefix(this.__SECTION) +"#ID#"]);
	},
	render:function(){return this.pf("toc.tmpl",[this._idxCtl.render(),this._vctl.render(), this._id, this.i18n("toc.toc"), this._renderList()]);},

	getViewNode:function(nodeId){return $X(this._id+"_"+ nodeId);},
	idxCtl:function(isShow){this._idxCtl.stCtl(isShow);},
	vctl:function(isShow){this._vctl.stCtl(isShow);},
	_getViewBody:function(){ return $X("wiki_list_"+this._id);},
	refresh:function(){
		this._refresh(this._getViewBody() , this._renderList());
		this.vctl(true);
		if (this._model.hasAppx(this.__QUICKLINKS)) {
			this.newViewObject(this.__QUICKLINKS, this._model.getAppx(this.__QUICKLINKS)).refresh();
		}
	},
	initialize:function(model, container){
		this._initList(model, this.getPrefix(this.__TOC));
		this._container = container;
		this._idxCtl = new Wiki.View.IdxCtl(this._id+"_i");
		this._idxCtl.setStat(Wiki.Config.ifShowTidx);
		this._vctl = new Wiki.View.Vctl(this._id+"_v", this._getViewBody.bind(this));
	}
});

Wiki.View.List = IX.Class.create();
Wiki.View.List.prototype = Object.inherit(Wiki.IView.List, {
	_pf:function(key, param){return this.pf("list."+key, param);},
	_getTarget:function(){return $X("wiki_list_"+this._id+'_target');},
	_getListItem:function(nodeId){return $X(this._id +'_'+nodeId);},

	setHeight:function(h){this._height = h;},	
	_getItemTemp:function(){return (this._id=="delete")?this._pf("dellist"):this._pf("movelist", [this.__genFunStr("selectDialog"), this._id]);},
	_getNodeList:function(){return this._model.getAllNode();},
	render:function() {return this._pf("tmpl", [this._id, this._height, this._renderList()]);},
	getSelected:function() {return this._getTarget().value;},
	select:function(nodeId){
		var f = function(nd, n, v){nd.value = v; nd.name=n;};
		var node = this._getTarget();
		var oldId =node.value;
		if (!isEmpty(oldId)){
			var lnode = this._getListItem(oldId);
			if (lnode){lnode.className = node.name;}
		}
		if (oldId==nodeId){return f(node, "", "");}
		var lnode =this._getListItem(nodeId);
		f(node, lnode.className, nodeId);
		lnode.className += "wiki_select";
		return true;
	},
	initialize:function(model,op, container){
		this._initList(model, this.getPrefix(this.__SECTION)+"_"+op + "_"+ model.getId());
		this._container = container;
		this._height = 240;
	}
});

Wiki.View.SItems = IX.Class.create();
Wiki.View.SItems.prototype = Object.inherit(Wiki.IView.SimpleAppendix, Wiki.IView.MultiPage, {
	_pf:function(name, param) {return this.pf("kitems."+ name, param);},
	__renderPageOpFun:function(acc, item, idx){
		var ifEnable = ! this._model[idx<2?"isFirstPage":"isLastPage"]();
		var imgUrl = this.__getImgUrl("wiki_arrow_"+item.toLowerCase()+ (ifEnable?"":"_disable")+ ".gif");
		acc.push(ifEnable?this.__renderFIcon(imgUrl, item, "", "jumpTo"+item):__renderIcon(imgUrl, item, ""));
		return acc;
	},

	__renderSItemTblHdr:function(cols, col) { //col:[id, width, type, name, nowrap, sortable],
		var oarr = [cols.orderBy==col[0], cols.order];
		var ktxt = col[3];		
		var actF = "sortSilist";
		if (oarr[0]) {
			ktxt += this.__renderWIcon("wiki_order_" +oarr[1]+".gif", "order_" + oarr[1], "");
			actF = (oarr[1]=="asc"?"dsc":"asc") + "OrderSilist";
		}
		 if (col[3] && col[5]!="false"){ktxt = this.__renderFLink(actF, ktxt, '').replace("#ID#", this._model.getId()+"_" + col[0]);}
		return [ktxt, col[1]>0?('style="width:' + col[1] + 'px;"'):''];
	},
	__renderSItemTblCol:function(col, node) { //col:[id, width, type, name, nowrap, sortable],
		var ktxt = "";
		var clz = "";
		var prmid = col[0];
		var xn = node.getProps(prmid);
		var xid = node.getProps("id");
		if (prmid == "title" || prmid=="id"){
			ktxt = this.__renderFLink("toLinked", xn, 'class="external"').replace("#ID#", "si_" + xid);
			if (prmid=="title") {clz =  "wiki_left"; }
		} else if (prmid=="type") {			
			ktxt =  this.__renderWIcon(this.__getImgOfLink(xn), this.__getAltOfLink(xn), "wiki_type_img");
			clz =  "wiki_left";
		} else if (prmid=="img") {
			ktxt =  this.__renderAIcon(xn, "", "");
		} else {
			if(col[2]=="user"){clz = "wiki_left"; }
			ktxt = xn._cdata; 
		}
		if (col[4]!="false") { clz += (clz.length>0?" ":"") + "wiki_nowrap";}
		return [ktxt, (clz.length>0?('class="' + clz + '" '):'')];
	},
	__renderCheckBox:function(chkFunName, txt, props, ctype, kid) {
		return this._pf("chk", [this.__genFunStr(chkFunName), props?props:"", ctype?ctype:"", txt?this._pf("chklabel", [txt]):"", this._id, kid]);
	},
	__renderSItems:function(){
		var view = this;
		var obj = view._model;
		var columns = obj.getColumns();
		var idx = 0;
		var nfun = function(tname, props, txt) {return view._pf(tname, [props?(" "+props):"", txt?txt:"&nbsp;"]);};
		var rfun = function(node){
			var isHdr = node==null;
			var xid = (isHdr?(obj._id+"_hdr"):node.getId());
			var trProps=  'id="wiki_'+ xid  + '"';
			trProps += ' class="wiki_'+(isHdr?'first':(idx%2==0?"toc_odd":"toc_even"))+ '"';
			trProps += !(isHdr || node.isVisible())?' style="display:none;"':"";			
			if (!isHdr && node.isVisible()) {idx +=1;}

			var tdFirst = nfun('col', 'class="wiki_left" ' + (isHdr?' style="width:24px;"':""), 
					view.__renderCheckBox("chkItemInFolder", '', '', '', (isHdr?obj:node).getId()));
			return nfun("row",trProps,IX.Utils.loop(columns.list, tdFirst, function(acc, item) {
				var arr =isHdr?view.__renderSItemTblHdr(columns, item):view.__renderSItemTblCol(item, node);
				return acc + nfun('col', arr[1], arr[0]);
			}));
		};
		return this._pf ("body", [obj.loopPage(rfun(null),  function(acc, item){
			return item.loopAll(acc, function(xacc, xitem){return xacc+ rfun(xitem);});
		})]);
	},
	_render:function(){
		var hdr =  this._pf("hdr2", [this.__genFunStr("link2Topic"),this.__renderPagesBody(this._model.getPIArray())]);
		return this._pf("tmpl2", [hdr.replaceAll("#ID#", this._model.getId()), this._id, this.__renderSItems()]);
	},

	_getCheckBox:function(item){ return $X( 'wiki_chk_'+ this._id +"_" + (item==null?this._model:item).getId());},
	_isChecked:function(item) {return this._getCheckBox(item).checked;},
	selectAllItems:function(){this._model.loopPage(this._isChecked(), function(acc, item) {
		this._getCheckBox(item).checked = acc; 
		return acc;
	}.bind(this));},
	_getChecked:function(){return this._model.loopPage([], function(acc, item){
		if (this._isChecked(item)){acc.push(item.getProps("id"));}
		return acc;
	}.bind(this));},
		
	render:function() {return this._render();},
	_getViewBody:function(){return $X('wiki_list_'+this._id);},
	refresh:function(){
		this._refresh(this._getViewBody() , this.__renderSItems());
		this._refreshPages(0);
	},
	link2Topic:function() {
		var chkList = this._getChecked();
		if (chkList.length==0){alert("Please select at least 1 item to link.");}
		else {this._model.link2Topic(chkList);}
	},
	initialize:function(model, container){
		this._init_View(model, container);
	}
});