﻿Wiki.IView.Object = Object.inherit(Wiki.Object, {
	getHandlerFun:function(){return Wiki.Config.name + ".action";},
	i18n:function(key){return Wiki.I18N.get("view."+key);},
	pf:function(key, params){return Wiki.TView.getPF(key, params);},
	i18n_op:function(key){return this.i18n("ops."+ key);},

	getPrefix:function(type){return Wiki.Config.name+"_" + Wiki.Config.getComponentPrefix(type);},
	_getViewClass:function(type){return Wiki.Config.getComponentViewClassName(type);},
	hasViewClass:function(type){return this._getViewClass(type).length>0;},
	newViewObject:function(type, model) {return new Wiki.View[this._getViewClass(type)](model, this._container);},
	getAppxList:function(){return Wiki.Config.appendix[this._model.getRoot().getType()];},
	isAppxVisible:function(type){return this._model.hasAppx(type) && Wiki.Config.enable[this._model.getPrefix(type)];}
});
Wiki.IView.View = Object.inherit(Wiki.IView.Object, IX.IView.View, {
	_init_View:function(model, container) {
		this._model =model;
		this._id = this.getPrefix(model.getType()) + model.getPureId();
		this._container = container;
	},

	__renderWOp:function(opf, px){return this.__renderAOp([opf+(isEmpty(px)?"":px), this.i18n_op(opf)]);},
	__renderWOpList:function(opfList, px){return IX.Utils.loop(opfList, "", function(acc, item){return acc + this.__renderWOp(item,px);}.bind(this));},
	__renderROp:function(op){return Wiki.Config.readonly?"":this.__renderWOp(op);},
	__getImgUrl:function(fname){return Wiki.Config.imgbase+fname;},

	__renderWIcon:function(imgN, altN,clzN, props) {return this.__renderAIcon(this.__getImgUrl(imgN), this.i18n("imgalt."+altN), clzN?clzN:"", props?props:"");},
	__renderWFIcon:function(funN, imgN, altN, clzN, props){
		return this.__renderAIcon(imgN.indexOf("http:")>=0?imgN:this.__getImgUrl(imgN), this.i18n("imgalt."+altN), clzN, 'onclick="'+this.__genFunStr(funN) + '"'+ (props?(' ' + props):'')); 
	},

	_getViewId:function(){return "wiki_" + this._id;},
	_getView:function(){return $X(this._getViewId());},
	isExist:function(){return this._getView();},
	_refreshView:function(){this._refresh(this._getView(), this._renderBody());}
});

Wiki.IView.MultiPage = {
	__MultiPage_VIRTUAL_FUN:["_pf", "__renderPageOpFun"], 
	__renderPagesBody:function(arr){
		return this._pf("mpindbody", IX.Utils.loop(["First", "Previous", "Next", "Last"], arr?arr:this._model.getPIArray(), this.__renderPageOpFun.bind(this))).replaceAll("#ID#", this._model.getId());
	},
	_refreshPages:function(n) {this._refresh($X('wiki_'+ this._id+"_"+ n+ '_mpind'), this.__renderPagesBody());}
};

Wiki.View.Editor= IX.Class.create();
Wiki.View.Editor.prototype = Object.inherit(Wiki.IEditable,Wiki.IView.View,{
	save:function(){
		this._model.saveSection(this.getEditContent(), this._dtype);
	},
	
	initialize:function(type, node, param){
		var dtype = type=="section"?param:100;	
		this._id = "ed_"+ (dtype*1 +5)+ "_"+ node.getId();
		this._initEditor(node,dtype);

		if (type=="section"){this._ifEditingSection = true;} 
		else {this._ifHtml = param;}
	}
});

Wiki.IView.STView= Object.inherit(IX.IView.STView, Wiki.IView.View,{
	__getPostfix:function(){return "";},
	_getSTClz:function(){return "wiki_stctl";},
	_getSTName:function(){return this.i18n_op((this._st_stat?"hide":"show")+this.__getPostfix());},
	_initWikiST:function(id) {
		this._initData(id);
		this._initST();
	}
});
Wiki.View.Vctl = IX.Class.create();
Wiki.View.Vctl.prototype = Object.inherit(Wiki.IView.STView, {
	initialize:function(id, getBodyFun) {
		this._initWikiST(id);
		this._actST=function(stat){this._display(getBodyFun(), stat);};
	}
});
Wiki.View.IdxCtl = IX.Class.create();
Wiki.View.IdxCtl.prototype = Object.inherit(Wiki.IView.STView,{
	__getPostfix:function(){return "Idx";},
	initialize:function(id) {this._initWikiST(id);}
});
Wiki.View.FolderCtl = IX.Class.create();
Wiki.View.FolderCtl.prototype = Object.inherit(IX.IView.ImageSTView, Wiki.IView.View,{
	STAT_NONE:0,
	STAT_CLOSED:1,
	STAT_OPENED:2,

	__getStatName:function(){
		var statName = ["none", "opened", "closed"];
		return statName[this._st_stat];
	},
	_getSTFun:function(){
		var statFun = ["void", "collapseST","expandST"];
		return statFun[this._st_stat];
	},
	_getSTClz:function(){ return "wiki_imgctl";},
	_getSTName:function(){return this.i18n("imgalt."+ this.__getStatName());},
	_getSTImage:function(){return this.__getImgUrl("folder_"+ this.__getStatName()+".png");},
	initialize:function(id, stat, actST){
		this._initData(id);
		this._st_stat = stat;
		this._actST=(isFunction(actST))?actST:function(stat){this._display($X('wiki_st_body_'+this._id), stat==1);}.bind(this);
	}
});