(function(NS){var $0='view.js';NS.ElementView=function($1)
{var $2=u.nel($1);try
{u.applyInterface($2,this);$2.id=u.generateId();u.info('[CREATE] ElementView '+$2.id,$0);return $2;}
catch(ex)
{u.cleanupClassInstance($2,NS.ElementView);throw ex;}};NS.ElementView.prototype={_Cleanup:function()
{u.cleanupDomElements(this);u.info('[DELETE] ElementView '+this.id,$0);},GetID:function()
{return this.id;}};NS.FragmentView=function()
{$2=NS.FragmentView.superclass.constructor.call(this,'DIV');u.initClassInstance($2,{doms:null,formDoms:null,fragmentId:null,$3:null});var d=$2.d;try
{u.importModule($2,u.Event);$2.m.Event.addMethods();$2.className='fragment_frame';$4=new u.DomBuilder();$4.build($2,{tag:'TABLE',cls:'fragment_layout',cellSpacing:0,cn:[{tag:'TBODY',cn:[{tag:'TR',cn:[{tag:'TD',index:'handle',id:u.generateId(),cls:'fragment_handle',cn:[{tag:'IMG',index:'close',src:u.build+'/template/action_stop.gif'}]},{tag:'TD',cn:[{index:'content',cls:'fragment_content'},{index:'edit',cls:'fragment_edit'}]}]}]}]});d.doms=$4.getElements();var $5=Ext.get(d.doms.handle);$5.on('click',$2.$6,$2);$5.on('mousedown',$2.$7,$2);var $8=Ext.get(d.doms.close);$8.on('click',$2.$9,$2);$8.on('mousedown',$2.$6,$2);var $a=Ext.get(d.doms.content);$a.on('mousedown',$2.$b,$2);$a.on('click',$2.$c,$2);u.toggle(d.doms.edit);u.info('[CREATE] FragmentView '+$2.id,$0);return $2;}
catch(ex)
{u.cleanupClassInstance($2,NS.FragmentView);throw ex;}};var $d=NS.FragmentView;u.extend(NS.FragmentView,NS.ElementView,{_Cleanup:function()
{var d=this.d,m=this.m;if(m&&m.Event)
u.unthrow(function(){m.Event.fire('cleanup')});if(d)
{d.$3=null;if(d.doms)
{if(d.doms.edit)
this.EndEdit();u.cleanupDomElements(d.doms);}}
u.info('[DELETE] FragmentView '+this.id,$0);},$e:function()
{if(this.m)
this.m.Event.fire('scrollintoview');},BeginEdit:function()
{var d=this.d;if(!d.doms.edit.hasChildNodes())
{var $f='';var $g='';var $h=[{tag:'INPUT',index:'ok',type:'button',value:NS.Msg.get('ED_OK')}];this.m.Event.fire('rawdataquery',function($i){$f=$i.title;$g=$i.content;});if(d.fragmentId>=0)
$h.push({tag:'INPUT',index:'cancel',type:'button',value:NS.Msg.get('ED_Cancel')});$4=new u.DomBuilder();d.doms.edit.appendChild($4.build({tag:'TABLE',cellSpacing:4,cn:[{tag:'TBODY',cn:[{tag:'TR',cn:[{tag:'TD',index:'label',cls:'label',html:NS.Msg.get('ED_Title')},{tag:'TD',cls:'edit_area',cn:{tag:'INPUT',index:'title',type:'text',value:$f}}]},{tag:'TR',cn:[{tag:'TD',cls:'edit_area',colSpan:2,cn:{tag:'TEXTAREA',index:'content',value:$g}}]},{tag:'TR',cn:[{tag:'TD'},{tag:'TD',cls:'buttons',cn:$h}]}]}]}));d.formDoms=$4.getElements();Ext.get(d.formDoms.ok).on('click',this.$j,this);if(d.formDoms.cancel)
Ext.get(d.formDoms.cancel).on('click',this.$k,this);u.toggle(d.doms.content);u.toggle(d.doms.edit);this.$e.defer(1,this);}},EndEdit:function()
{var d=this.d;if(d.doms.edit.hasChildNodes())
{u.toggle(d.doms.content);u.toggle(d.doms.edit);u.cleanupDomElements(d.formDoms);d.formDoms=null;u.removeAllChildren(d.doms.edit);}},FocusEdit:function()
{if(this.d.doms.edit.hasChildNodes())
this.d.formDoms['content'].focus();},GetFragmentID:function()
{return this.d.fragmentId;},SetFragmentID:function($l)
{var d=this.d;if(u.isNumber(d.fragmentId)&&($l<0||d.fragmentId>=0))
throw new Error('The fragment already has ID.');if($l>=0)
this.EndEdit();d.fragmentId=$l;},RollbackFragmentID:function($l)
{this.d.fragmentId=$l;this.BeginEdit();},SetContent:function($m)
{var $n=this.d.doms.content;$n.innerHTML=$m;},$6:function($o)
{$o.stopEvent();},$7:function($o)
{new NS.FragmentDD(this,$o.getXY());this.$6($o);},$9:function($p)
{Ext.Msg.confirm(NS.Msg.get('ED_UI_DeleteFragment'),NS.Msg.get('ED_UI_DeleteFragmentConfirm'),function($q){if($q=='yes'&&this.m)
this.m.Event.fire('close');},this);},$b:function($o)
{var $r=$o.getXY();this.d.$3={x:$r[0],y:$r[1],t:$o.getTime()};},$c:function($o)
{var $s=$o.getTarget('a');if($s&&Ext.fly($s).hasClass('wikilink'))
{this.m.Event.fire('openwiki',$s.href,$s.title,$o.ctrlKey||$o.shiftKey);$o.stopEvent();}
else if($s)
{if($s.href)
{var url=u.build+'/html/redirect.html?u='+u.esc($s.href);window.open(url,'_blank');$o.stopEvent();}
else
{$o.stopPropagation();}}
else
{$o.stopPropagation();var $t=this.d.$3,$r=$o.getXY();if($t&&Math.abs($r[0]-$t.x)<=2&&Math.abs($r[1]-$t.y)<=2&&($o.getTime()-$t.t)<1000)
{this.BeginEdit();this.FocusEdit();}}},$j:function($o)
{var d=this.d,$u=d.fragmentId;var $i={title:d.formDoms.title.value,content:d.formDoms.content.value}
try
{NS.DB.TransactionForSiteDB(function(){this.m.Event.fire('edited',$i);if(d.fragmentId!=$u)
this.m.Event.fire('statuschanged');this.EndEdit();},this);}
catch(ex)
{Ext.Msg.alert(NS.Msg.get('ERR_Title'),NS.Msg.get('ERR_Write'));if($u<0&&d.fragmentId>=0)
this.m.Event.fire('rollback',$u);}},$k:function($o)
{this.EndEdit();},OnDragEnter:function()
{Ext.get(this).addClass('drag_on');},OnDragOut:function()
{Ext.get(this).removeClass('drag_on');},OnDragDrop:function($o,$v,$w)
{this.m.Event.fire('dragdrop',$o,$v,$w,false);}});NS.AppendView=function()
{$2=NS.AppendView.superclass.constructor.call(this,'DIV');u.initClassInstance($2,{});var d=$2.d;try
{u.importModule($2,u.Event);$2.m.Event.addMethods();$2.className='page_append';$2.innerHTML=NS.Msg.get('ED_Append');Ext.get($2).on('click',$2.$x,$2);u.info('[CREATE] AppendView '+$2.id,$0);return $2;}
catch(ex)
{u.cleanupClassInstance($2,NS.AppendView);throw ex;}};u.extend(NS.AppendView,NS.ElementView,{_Cleanup:function()
{u.info('[DELETE] AppendView '+this.id,$0);},$x:function()
{this.m.Event.fire('append');},OnDragEnter:function()
{Ext.get(this).addClass('drag_on');},OnDragOut:function()
{Ext.get(this).removeClass('drag_on');},OnDragDrop:function($o,$v,$w)
{this.m.Event.fire('dragdrop',$o,$v,$w,false);}});NS.ResourceTab=function($2)
{u.applyInterface($2,this);u.initClassInstance($2,{});var d=$2.d;try
{u.importModule($2,u.Event);$2.m.Event.addMethods();NS.ResourceTab.$y.set($2.id,$2);u.info('[CREATE] ResourceTab '+$2.id,$0);return $2;}
catch(ex)
{u.cleanupClassInstance($2);throw ex;}};NS.ResourceTab.prototype={_Cleanup:function()
{NS.ResourceTab.$y.remove(this.id);u.info('[DELETE] ResourceTab '+this.id,$0);},OnDragEnter:function()
{this.style.border='solid 1px blue';},OnDragOut:function()
{this.style.border='none';},OnDragDrop:function($o,$v,$w)
{this.m.Event.fire('dragdrop',$o,$v,$w,true);}};NS.ResourceTab.$y=new u.ObjectCache();NS.ResourceTab.forEach=function($z,$A){NS.ResourceTab.$y.forEach($z,$A);};NS.ResourceHistory=function()
{this.$B=[];this.$C=0;};NS.ResourceHistory.prototype={Push:function($D)
{this.$C+=1;this.$C=u.clamp(this.$C,0,this.$B.length);if(this.$C<this.$B.length)
this.$B.splice(this.$C,this.$B.length-this.$C);this.$B.push({page:$D,scrollTop:0});},SetScrollTop:function($E)
{if(this.$B.length<=0)
return;this.$C=u.clamp(this.$C,0,this.$B.length-1);this.$B[this.$C].scrollTop=parseInt($E,10);},GetCurrentEntry:function()
{if(this.$B.length<=0)
throw new Error('This histori is empty.')
this.$C=u.clamp(this.$C,0,this.$B.length-1);return u.shallowCopy(this.$B[this.$C]);},Forward:function()
{if(this.$B.length>0&&this.$C<this.$B.length-1)
{this.$C+=1;return true;}
return false;},Back:function()
{if(this.$B.length>0&&this.$C>0)
{this.$C-=1;return true;}
return false;}};NS.ResourceView=function($l,$F)
{NS.ResourceView.superclass.constructor.call(this,{title:'_',autoCreate:true,closable:true,fitToFrame:true,autoScroll:false,toolbar:$F});u.initClassInstance(this,{region:null,frameDom:null,appendDom:null,history:new NS.ResourceHistory()});var d=this.d;try
{u.importModule(this,u.Event);this.m.Event.addMethods();d.history.Push($l);d.frameDom=u.nel('DIV');d.frameDom.className='page_frame';this.$G();this.getEl().dom.appendChild(d.frameDom);this.on('activate',this.$H,this);u.info('[CREATE] ResourceView '+$l,$0);}
catch(ex)
{u.cleanupClassInstance(this,NS.ResourceView);throw ex;}};u.extend(NS.ResourceView,Ext.ContentPanel,{_Cleanup:function()
{var d=this.d;var m=this.m;if(m&&m.Event)
m.Event.fire('cleanup');if(d)
{if(d.region)
d.region.removeListener('beforeremove',this.$I,this);this.$J(true);}
this.purgeListeners();u.info('[DELETE] ResourceView '+this.getTitle(),$0);},$G:function()
{var d=this.d;d.appendDom=new NS.AppendView();d.appendDom.On('append',this.$K,this);d.appendDom.On('dragdrop',this.$L,this);d.frameDom.appendChild(d.appendDom);},$J:function($M)
{var d=this.d;if(!$M)this.m.Event.fire('detach');if(d.frameDom&&d.frameDom.hasChildNodes())
{u.forEach(d.frameDom.childNodes,function($N){u.cleanupClassInstance($N);});}
if(!$M)u.removeAllChildren(d.frameDom);},$O:function($P,$Q)
{if(!u.isNumber($P))
throw new Error('Illegal fragment ID.');var $R=NS.FragmentController.Find($P),$S;$R.m.RefCount.holdWhile(function(){var d=this.d;$S=new NS.FragmentView();try
{$S.On('close',this.$T,this);$S.On('statuschanged',this.$U,this);$S.On('dragdrop',this.$L,this);$S.On('openwiki',this.$V,this);$S.On('scrollintoview',this.$W,this);$R.AttachView($S);if($Q)$S.BeginEdit();}
catch(ex)
{u.cleanupClassInstance($S);if($S.parentNode==d.frameDom)
d.frameDom.removeChild($S);throw ex;}},this);return $S;},PostAppend:function($X,$Y)
{if($Y)
{var d=this.d;d.region=$X;$X.addListener('beforeremove',this.$I,this);var $Z=$X.getTabs().getTab(this.getId()).el.dom;new NS.ResourceTab($Z);this.c.push($Z);$Z.On('dragdrop',this.$L,this);}},Close:function()
{var $X=this.d.region.remove(this);},GetID:function()
{return this.getEl().dom.id;},GetFragments:function()
{var d=this.d,$10=[];if(d.frameDom.hasChildNodes())
{u.forEach(d.frameDom.childNodes,function($N){if(u.isFunction($N.GetFragmentID))
{var $l=$N.GetFragmentID();if(u.isNumber($l))
$10.push($l);}});}
return $10;},SetFragments:function($11)
{var d=this.d,$12=null;u.toggle(d.frameDom);try
{var $13={},$14=true;if(d.frameDom.hasChildNodes())
{u.forEach(d.frameDom.childNodes,function($S){if(u.isFunction($S.GetFragmentID))
{var $P=$S.GetFragmentID();if(u.isNumber($P))
{if(!$13[$P])
$13[$P]=[];$13[$P].push($S);$14=false;}}});}
var $15=$14?($12=u.nfg()):d.frameDom;for(var i=$11.length-1;i>=0;--i)
{var $P=$11[i],$N;if($13[$P])
{$N=$13[$P].pop();if($13[$P].length<=0)
delete $13[$P];if($N!=$15.firstChild)
$15.insertBefore($N,$15.firstChild);}
else
{var $S=this.$O($P,$P<0);$15.insertBefore($S,$15.firstChild);}}
if($12)
d.frameDom.insertBefore($12,d.frameDom.firstChild);u.forEach($13,function($16){u.forEach($16,function($N){u.cleanupClassInstance($N);d.frameDom.removeChild($N);});});}
finally
{if($12)
{while($12.firstChild)
{u.cleanupClassInstance($12.firstChild);$12.removeChild($12.firstChild);}}
u.toggle(d.frameDom);}},SetResourceID:function($l)
{if(NS.Application.GetActivePanel()==this&&!NS.Environment.ie)
document.location.href=document.location.href.replace(/\#.+$/,'')+'#'+u.escWikiName($l);},SetTitle:function($f)
{this.setTitle(u.hesc($f));},Goto:function($l,$f,$E,$17)
{var d=this.d,$18=null
$18=NS.ResourceController.Find($l,$f);$18.m.RefCount.holdWhile(function(){try
{this.$J(false);this.$G();this.PostAppend(d.region,false);$18.AttachView(this);d.frameDom.scrollTop=$E;if(!$17)
this.d.history.Push($l);}
catch(ex)
{u.cleanupClassInstance(this);throw ex;}},this);},UIBack:function()
{var d=this.d,$B=d.history;$B.SetScrollTop(d.frameDom.scrollTop);if($B.Back())
{var $19=$B.GetCurrentEntry();var $l=$19.page;this.Goto($l,$l,$19.scrollTop,true);}},UIForward:function()
{var d=this.d,$B=d.history;$B.SetScrollTop(d.frameDom.scrollTop);if($B.Forward())
{var $19=$B.GetCurrentEntry();var $l=$19.page;this.Goto($l,$l,$19.scrollTop,true);}},UIGoHome:function()
{this.d.history.SetScrollTop(this.d.frameDom.scrollTop);this.Goto('home','home',0,false);},UIDelete:function()
{Ext.Msg.confirm(NS.Msg.get('ED_UI_DeletePage'),NS.Msg.get('ED_UI_DeletePageConfirm'),function($q){if($q=='yes'&&this.m)
this.m.Event.fire('delete');},this);},UIEditTitle:function()
{Ext.Msg.show({title:NS.Msg.get('ED_UI_EditTitle'),closable:false,prompt:true,value:u.hunesc(this.getTitle()),buttons:Ext.MessageBox.OKCANCEL,msg:NS.Msg.get('ED_UI_EditTitleMsg'),fn:function($1a,$f){if($1a=='ok'&&this.m)
this.m.Event.fire('titleedited',$f);},scope:this});},OnDragFragment:function($1b,$o)
{var d=this.d;var $1c=$o.getXY();var $1d=u.computeBounds(d.frameDom,true);$1b.SetScrollTarget(d.frameDom,{top:$1d.top-25,bottom:$1d.bottom});if($1d.left<=$1c[0]&&$1c[0]<$1d.right&&$1d.top<=$1c[1]&&$1c[1]<$1d.bottom)
{var y=$1d.top-d.frameDom.scrollTop;var $1e=d.frameDom.childNodes;for(var i=0;i<$1e.length;++i)
{var $N=$1e[i];var $1f=y+$N.offsetHeight;if(y<=$1c[1]&&$1c[1]<$1f)
return($o.ctrlKey||$N!=$1b.GetSource())?$N:null;y=$1f;}}
else
{var $1g=$1b.GetUserData('tabs');if(!$1g)
{$1g=[];NS.ResourceTab.forEach(function($1h){$1g.push([$1h,u.computeBounds($1h,true)]);},this);}
$1b.SetUserData('tabs',$1g);for(var i=0;i<$1g.length;++i)
{var $1i=$1g[i][1];if($1i.left<=$1c[0]&&$1c[0]<$1i.right&&$1i.top<=$1c[1]&&$1c[1]<$1i.bottom)
{return $1g[i][0];}}}
return null;},$I:function($X,$1j)
{if($1j==this)
u.cleanupClassInstance(this);},$H:function()
{this.m.Event.fire('rawdataquery',function($i){this.SetResourceID($i.id);});},$K:function()
{var $R=NS.FragmentController.Create(),d=this.d;$R.m.RefCount.holdWhile(function(){var $S=this.$O($R.GetFragmentID(),true);d.frameDom.insertBefore($S,d.appendDom);$S.FocusEdit();},this);this.m.Event.fire('updated');},$T:function($S)
{if($S.parentNode==this.d.frameDom)
{u.cleanupClassInstance($S);$S.parentNode.removeChild($S);this.m.Event.fire('updated');}},$U:function($S)
{this.m.Event.fire('updated');},$L:function($S,$o,$v,$w,$1k)
{if($o.ctrlKey||$1k)
{if(u.isFunction($w.GetFragmentID))
{var $P=$w.GetFragmentID(),$1l=$S;if($1l.parentNode!=this.d.frameDom)
$1l=this.d.appendDom;if(u.isNumber($P))
{var $1m=this.$O($P,$P<0);this.d.frameDom.insertBefore($1m,$1l);}
this.m.Event.fire('updated');}}
else if($w!=$S)
{Ext.get($w).insertBefore($S);this.m.Event.fire('updated');}},$V:function($S,$1n,$f,$1o)
{if(/[^\#]*\#(.+)$/.test($1n))
{var $l=u.toWikiName(u.unescWikiName(RegExp.$1));if(!$f)$f=$l;if($1o)
{NS.Application.OpenPage($l,$f);}
else if($l)
{this.d.history.SetScrollTop(this.d.frameDom.scrollTop);this.Goto($l,$f,0,false);}}},$W:function($S)
{var $1p=Ext.get(this.d.frameDom);var $1q=$S.offsetTop,$1r=$S.clientHeight;var $1s=$1p.getScroll().top,$1t=$1p.getViewSize().height;var $1u=null;if($1q<$1s||$1r>=$1t)
$1u=$1q;else if(($1q+$1r)>($1s+$1t))
$1u=$1q+$1r-$1t;if(!u.isNull($1u))
{if($1u<0)$1u=0;$1p.scrollTo('top',$1u,{duration:0.5,easing:'easeOut'});}}});})(Infosketch);