if(typeof XWiki=="undefined"){alert("ERROR: xwikiexplorer.js depends on xwiki.js")
}XWiki.constants.rest={baseRestURI:XWiki.contextPath+"/rest/",restChildrenRel:"http://www.xwiki.org/rel/children",restParentRel:"http://www.xwiki.org/rel/parent",restAttachmentsRel:"http://www.xwiki.org/rel/attachments",restHomeRel:"http://www.xwiki.org/rel/home"};
isc.ClassFactory.defineClass("XWEResultTree",isc.ResultTree);
isc.XWEResultTree.addClassProperties({constants:{addNodeSuffix:"..new",attachmentsTitle:"$msg.get('xwikiexplorer.attachments.title')",addPageTitle:"$msg.get('xwikiexplorer.addpage.title')",addAttachmentTitle:"$msg.get('xwikiexplorer.addattachment.title')"}});
isc.XWEResultTree.addProperties({multiDSTree:true,callbacks:{dataArrived:new Array()},parentMap:{},displayLinks:true,displayAddPage:false,displayAddPageOnTop:true,displayAttachments:true,displayAttachmentsOnTop:false,displayAttachmentsWhenEmpty:false,displayAddAttachment:false,displayAddAttachmentOnTop:true,displayBlacklistedSpaces:false});
isc.XWEResultTree.addMethods({getChildDataSource:function(e,d){var c=e[this.childTypeProperty];
if(c!=null){return isc.DS.get(c)
}var d=d||this.getNodeDataSource(e);
if(d==null||!this.isMultiDSTree()){return this.getRootDataSource()
}var b=this.treeRelations,a=d.getChildDataSources();
var f=XWiki.resource.get(e.id);
e.resource=f;
if(d.Class=="XWEDataSource"){c=isc.XWEWikiDataSource.getOrCreate(f.wiki).getID()
}else{if(d.Class=="XWEWikiDataSource"){c=isc.XWESpaceDataSource.getOrCreate(f.wiki,f.space).getID()
}else{if(d.Class=="XWESpaceDataSource"){if(e.isXWikiAttachment==null){c=isc.XWESpaceDataSource.getOrCreate(f.wiki,f.space).getID()
}else{c=isc.XWEAttachmentsDataSource.getOrCreate(f.wiki,f.space,f.name).getID()
}}else{if(b){c=b[d.ID]
}}}}if(c!=null){return isc.DS.get(c)
}if(a!=null){return a[0]
}},dataArrived:function(e){var j=this.getNodeDataSource(e);
var c="";
if(j==null){j=this.getDataSource()
}if(j.Class=="XWEWikiDataSource"&&this.displayBlacklistedSpaces==false){this.filterNodesByName(this.getChildren(),XWiki.blacklistedSpaces)
}var b=this.getChildren(e);
for(var d=0;
d<b.length;
d++){var a=this.getNodeDataSource(b[d]);
var g=b[d].name;
var f=true;
if(this.displayLinks==true&&b[d].xwikiRelativeUrl!=null){g="<a href='"+b[d].xwikiRelativeUrl+"'>"+g+"</a>"
}isc.addProperties(b[d],{icon:a.icon,title:g,isNewPage:false,isNewAttachment:false});
if(d==0){c=a.Class
}}if(c=="XWESpaceDataSource"&&j.Class=="XWEWikiDataSource"&&this.displayAddPage==true){this.addAddPageNode(e)
}if(j.Class=="XWESpaceDataSource"&&this.displayAttachments==true&&!e.isXWikiAttachment){this.addAttachmentsNode(e)
}if(e.isXWikiAttachment&&this.displayAddAttachment==true){this.addAddAttachmentsNode(e)
}if(this.callbacks.dataArrived.length>0){var h=this.callbacks.dataArrived.shift();
h.callback()
}},isFolder:function(d){var c=this.getNodeDataSource(d);
if(c!=null){if(c.Class=="XWEDataSource"){return true
}else{if(c.Class=="XWEWikiDataSource"){return true
}else{if(c.Class=="XWESpaceDataSource"){if(d.isXWikiAttachment==true){return true
}var a=(d.link!=null)?d.link:new Array();
for(var b=0;
b<a.length;
b++){if(a[b].rel==XWiki.constants.rest.restChildrenRel||a[b].rel==XWiki.constants.rest.restAttachmentsRel||this.displayAttachmentsWhenEmpty||this.displayAddAttachment){return true
}}return false
}else{if(c.Class=="XWEAttachmentsDataSource"){return false
}}}}}return true
},getChildNodeByName:function(d,a){var c=this.getChildren(d);
if(c!=null){for(var b=0;
b<c.length;
b++){if(c[b].name==a){return c[b]
}}}return null
},filterNodesByName:function(a,c){for(var b=0;
b<a.length;
b++){if(XWiki.blacklistedSpaces.indexOf(a[b].name)!=-1){this.remove(a[b])
}}},addAddPageNode:function(c){var b={id:c.id+isc.XWEResultTree.constants.addNodeSuffix,wiki:c.wiki,space:c.space,title:isc.XWEResultTree.constants.addPageTitle,parentId:c.id,icon:"$xwiki.getSkinFile('icons/silk/bullet_add.gif')",resource:c.resource,isNewPage:true,isNewAttachment:false,clickCallback:function(f,d,e){d.resource=XWiki.resource.get(d.resource.prefixedSpace);
f.input.value=""
}};
var a;
if(this.displayAddPageOnTop==true){a=0
}else{a=null
}this.add(b,c,a)
},addAddAttachmentsNode:function(c){var b={id:c.id+isc.XWEResultTree.constants.addNodeSuffix,wiki:c.wiki,space:c.space,title:isc.XWEResultTree.constants.addAttachmentTitle,parentId:c.id,icon:"$xwiki.getSkinFile('icons/silk/bullet_add.gif')",resource:c.resource,isNewPage:false,isNewAttachment:true,clickCallback:function(f,d,e){f.input.value=""
}};
var a;
if(this.displayAddAttachmentsOnTop==true){a=0
}else{a=null
}this.add(b,c,a)
},addAttachmentsNode:function(g){var d=false;
var f=this.getNodeDataSource(g);
if(this.displayAttachmentsWhenEmpty==true||this.displayAddAttachment){d=true
}else{var b=(g.link!=null)?g.link:new Array();
var d=false;
for(var e=0;
e<b.length;
e++){if(b[e].rel==XWiki.constants.rest.restAttachmentsRel){d=true;
break
}}}if(d==true){var h=isc.XWEResultTree.constants.attachmentsTitle+" ("+g.name+")";
if(this.displayLinks==true){h="<a href='"+g.xwikiRelativeUrl+XWiki.constants.anchorSeparator+XWiki.constants.docextraAttachmentsAnchor+"'>"+h+"</a>"
}var a={id:g.id+XWiki.constants.anchorSeparator+XWiki.constants.docextraAttachmentsAnchor,fullName:g.fullName+XWiki.constants.anchorSeparator+XWiki.constants.docextraAttachmentsAnchor,wiki:g.wiki,space:g.space,title:h,name:g.name,parentId:g.id,xwikiRelativeURL:g.xwikiRelativeURL+XWiki.constants.anchorSeparator+XWiki.constants.docextraAttachmentsAnchor,icon:"$xwiki.getSkinFile('icons/silk/page_white_zip.gif')",resource:XWiki.resource.get(g.id+XWiki.constants.anchorSeparator+XWiki.constants.docextraAttachmentsAnchor),isXWikiAttachment:true,isNewPage:false,isNewAttachment:false};
var c;
if(this.displayAttachmentsOnTop==true){c=0
}else{c=null
}this.add(a,g,c)
}}});
isc.ClassFactory.defineClass("XWEDataSource",isc.DataSource);
isc.XWEDataSource.addClassProperties({sep:"_"});
isc.XWEDataSource.addProperties({dataFormat:"xml",xmlNamespaces:{xwiki:"http://www.xwiki.org"},resultTreeClass:"XWEResultTree",transformResponse:function(b,a,d){if(this.callbacks.transformResponse.length>0){var c=this.callbacks.transformResponse.shift();
c.callback(b,a,d)
}return b
},dataURL:XWiki.constants.rest.baseRestURI+"wikis/",recordXPath:"/xwiki:wikis/xwiki:wiki",fields:[{name:"id",required:true,type:"text",primaryKey:true},{name:"name",type:"text"},{name:"title",type:"text"},{name:"xwikiRelativeUrl",type:"text"}],icon:"$xwiki.getSkinFile('icons/silk/database.gif')",requestProperties:{promptStyle:"cursor"},callbacks:{transformResponse:new Array()}});
isc.XWEDataSource.addMethods({transformRequest:function(a){if(a.originalData){a.originalData.r=""+Math.floor(Math.random()*1000000)
}return a.data
}});
isc.ClassFactory.defineClass("XWEWikiDataSource",isc.XWEDataSource);
isc.XWEWikiDataSource.addClassMethods({getOrCreate:function(a){var c="XWEWikiDataSource_"+a;
var b=this.get(c);
if(b==null){b=this.create({ID:c,wiki:a})
}return b
}});
isc.XWEWikiDataSource.addProperties({wiki:XWiki.currentWiki,recordXPath:"/xwiki:spaces/xwiki:space",fields:[{name:"id",required:true,type:"text",primaryKey:true},{name:"name",required:true,type:"text"},{name:"title",type:"text"},{name:"xwikiRelativeUrl",type:"text"}],icon:"$xwiki.getSkinFile('icons/silk/folder.gif')"});
isc.XWEWikiDataSource.addMethods({init:function(){this.dataURL=XWiki.constants.rest.baseRestURI+"wikis/"+this.wiki+"/spaces";
this.Super("init",arguments)
}});
isc.ClassFactory.defineClass("XWESpaceDataSource",isc.XWEDataSource);
isc.XWESpaceDataSource.addClassMethods({getOrCreate:function(a,c){var d="XWESpaceDataSource_"+a+isc.XWEDataSource.sep+c;
var b=this.get(d);
if(b==null){b=this.create({ID:d,wiki:a,space:c})
}return b
}});
isc.XWESpaceDataSource.addProperties({wiki:"xwiki",space:"Main",recordXPath:"/xwiki:pages/xwiki:pageSummary",fields:[{name:"id",required:true,type:"text",primaryKey:true},{name:"fullName",required:true,type:"text"},{name:"wiki",required:true,type:"text"},{name:"space",required:true,type:"text"},{name:"name",required:true,type:"text"},{name:"title",required:true,type:"text"},{name:"parentId",required:true,type:"text",foreignKey:"id"},{name:"parent",required:true,type:"text"},{name:"xwikiRelativeUrl",type:"text"},{name:"link",propertiesOnly:true}],icon:"$xwiki.getSkinFile('icons/silk/page_white_text.gif')"});
isc.XWESpaceDataSource.addMethods({init:function(){this.dataURL=XWiki.constants.rest.baseRestURI+"wikis/"+this.wiki+"/spaces/"+this.space+"/pages";
this.transformRequest=function(a){var b=this.wiki+XWiki.constants.wikiSpaceSeparator+this.space;
if(a.originalData.parentId==b||a.originalData.parentId==null){a.originalData.parentId="^(?!"+b+".).*$"
}return this.Super("transformRequest",arguments)
};
this.Super("init",arguments)
}});
isc.ClassFactory.defineClass("XWEPageDataSource",isc.XWEDataSource);
isc.XWEPageDataSource.addClassMethods({getOrCreate:function(a,d,c){var e="XWEPageDataSource_"+a+isc.XWEDataSource.sep+d+isc.XWEDataSource.sep+c;
var b=this.get(e);
if(b==null){b=this.create({ID:e,wiki:a,space:d,page:c})
}return b
}});
isc.XWEPageDataSource.addProperties({wiki:"xwiki",space:"Main",page:"WebHome",recordXPath:"/xwiki:page",fields:[{name:"id",required:true,type:"text",primaryKey:true},{name:"wiki",required:true,type:"text"},{name:"space",required:true,type:"text"},{name:"name",required:true,type:"text"},{name:"parentId",required:true,type:"text"},{name:"parent",required:true,type:"text"},{name:"link",propertiesOnly:true}],icon:"$xwiki.getSkinFile('icons/silk/page_white_text.gif')"});
isc.XWEPageDataSource.addMethods({init:function(){this.dataURL=XWiki.constants.rest.baseRestURI+"wikis/"+this.wiki+"/spaces/"+this.space+"/pages/"+this.page;
this.Super("init",arguments)
}});
isc.ClassFactory.defineClass("XWEAttachmentsDataSource",isc.XWEDataSource);
isc.XWEAttachmentsDataSource.addClassMethods({getOrCreate:function(a,d,c){var e="XWEAttachmentsDataSource_"+a+isc.XWEDataSource.sep+d+isc.XWEDataSource.sep+c;
var b=this.get(e);
if(b==null){b=this.create({ID:e,wiki:a,space:d,page:c})
}return b
}});
isc.XWEAttachmentsDataSource.addProperties({wiki:"xwiki",space:"Main",page:"WebHome",recordXPath:"/xwiki:attachments/xwiki:attachment",fields:[{name:"id",required:true,type:"text",primaryKey:true},{name:"name",required:true,type:"text"},{name:"title",type:"text"},{name:"xwikiRelativeUrl",type:"text"}],icon:"$xwiki.getSkinFile('icons/silk/attach.gif')"});
isc.XWEAttachmentsDataSource.addMethods({init:function(){this.dataURL=XWiki.constants.rest.baseRestURI+"wikis/"+this.wiki+"/spaces/"+this.space+"/pages/"+this.page+"/attachments";
this.Super("init",arguments)
}});
isc.ClassFactory.defineClass("XWETreeGrid",isc.TreeGrid);
isc.XWETreeGrid.addProperties({autoDraw:false,autoFetchData:true,nodeClick:function(c,a,b){this.nodeClickCallback(c,a,b)
},showHeader:false,folderIcon:"$xwiki.getSkinFile('icons/silk/database.gif')",position:"relative",dropIconSuffix:"",openIconSuffix:"",closedIconSuffix:"",animateFolders:false,wiki:XWiki.currentWiki,space:null,displaySuggest:true,defaultValue:"Main.WebHome",inputValueCache:""});
isc.XWETreeGrid.addMethods({draw:function(){if(this.Super("draw",arguments)!=null){return this
}if(typeof this.input=="undefined"&&this.input==null){this.drawInput()
}for(member in this){if(typeof member!="function"&&member.startsWith("display")){this.data[member]=this[member]
}}var a="div.listGrid td, div.listGrid table {margin:0;padding:0;} div.listGrid td {border:0;color:#333;} #actionmenu {z-index: 999999;}";
var c=document.getElementsByTagName("head")[0];
var b=document.createElement("style");
b.type="text/css";
b.media="screen";
if(b.styleSheet){b.styleSheet.cssText=a
}else{b.appendChild(document.createTextNode(a))
}c.appendChild(b)
},invalidateCache:function(){this.Super("invalidateCache",arguments);
this.inputValueCache=""
},openNode:function(a,e,b){var d={treeId:this.getID(),callback:function(){window[this.treeId].openNodesFromInput()
}};
var c=a.findById(e);
if(c!=null){if(a.isFolder(c)&&!a.isOpen(c)){if(b==true){this.getData().callbacks.dataArrived.push(d)
}a.openFolder(c);
return null
}this.selectNodeAndScroll(c);
return c
}return null
},selectNodeAndScroll:function(a){this.deselectAllRecords();
this.selectRecord(a);
nodeYPos=this.getFocusRow()*this.getRowHeight();
this.body.scrollTo(this.body.getScrollLeft(),nodeYPos)
},openParent:function(a,d){if(d.name!=""){if(a.parentMap[d.prefixedFullName]==null){var e=isc.XWEPageDataSource.getOrCreate(d.wiki,d.space,d.name);
var c=function(i,h,k,g){if(i.httpResponseCode==200){var f=i.data[0].parent?XWiki.resource.get(i.data[0].parent):{prefixedFullName:"",name:""};
a.parentMap[d.prefixedFullName]=f;
if(a.findById(f.prefixedFullName)!=null){this.openNode(a,f.prefixedFullName,true)
}else{this.openParent(a,f)
}}else{if(this.displayAddPage==true){var j=this.getData().findById(d.prefixedSpace+isc.XWEResultTree.constants.addNodeSuffix);
j.resource=d;
this.selectNodeAndScroll(j)
}}}.bind(this);
e.fetchData(null,c,null)
}else{var b=a.parentMap[d.prefixedFullName];
if(a.findById(b.prefixedFullName)!=null){this.openNode(a,b.prefixedFullName,true)
}else{this.openParent(a,b)
}}}},openNodesFromInput:function(){var i=this.getDataSource().Class;
var d=XWiki.resource.get(this.input.value);
var b=XWiki.resource.get("");
var e=this.getData();
if(this.getSelectedRecord()!=null){b=this.getSelectedRecord().resource
}if(i=="XWEDataSource"){var j=this.openNode(e,d.wiki,true);
if(j==null){return
}}if(i=="XWEDataSource"||i=="XWEWikiDataSource"){if(d.space!=b.space){this.deselectRecord(this.getSelectedRecord())
}var f=this.openNode(e,d.prefixedSpace,true);
if(f==null){return
}}var k=this.openNode(e,d.prefixedFullName,true);
if(k==null){this.openParent(e,d)
}if(b.attachment!=d.attachment||(b.anchor!=d.anchor&&d.anchor==XWiki.constants.docextraAttachmentsAnchor)){var c=d.prefixedFullName+XWiki.constants.anchorSeparator+XWiki.constants.docextraAttachmentsAnchor;
var a=this.openNode(e,c,true);
if(a==null){return
}var g=d.prefixedFullName+XWiki.constants.pageAttachmentSeparator+d.attachment;
var h=this.openNode(e,g,false)
}return
},inputObserver:function(){var a=this.input.value;
if(a!=""&&a!=this.inputValueCache){this.openNodesFromInput();
this.inputValueCache=a
}setTimeout(this.inputObserver.bind(this),2000)
},drawInput:function(){var d=(this.displaySuggest==false)?"hidden":"text";
var a=this.width-6;
var b=document.createElement("input");
b.setAttribute("id",this.getID()+"_Input");
b.setAttribute("name",this.getID()+"_Input");
b.setAttribute("style","width:"+a+"px;clear:both");
b.setAttribute("type",d);
if(this.defaultValue){b.setAttribute("value",this.defaultValue)
}this.htmlElement.appendChild(b);
this.input=b;
if(this.displaySuggest){var c=function(){var f=new XWiki.widgets.Suggest(this,{script:"/xwiki/rest/wikis/"+XWiki.currentWiki+"/search?scope=name&",varname:"q"});
f.setSuggestions=function(l){this.aSuggestions=[];
var h=l.responseXML;
var k=h.getElementsByTagName("searchResult");
for(var j=0;
j<k.length;
j++){var n=k[j].getElementsByTagName("id")[0].firstChild.nodeValue;
var m=k[j].getElementsByTagName("space")[0].firstChild.nodeValue;
var g=k[j].getElementsByTagName("pageName")[0].firstChild.nodeValue;
if(k[j].hasChildNodes()){this.aSuggestions.push({id:n,value:m+XWiki.constants.spacePageSeparator+g,info:""})
}}this.idAs="as_"+this.fld.id;
this.createList(this.aSuggestions)
}
};
Event.observe(b,"focus",c);
var e={treeId:this.getID(),callback:function(){window[this.treeId].inputObserver()
}};
this.getData().callbacks.dataArrived.push(e)
}else{var e={treeId:this.getID(),callback:function(){window[this.treeId].openNodesFromInput()
}};
this.getData().callbacks.dataArrived.push(e)
}},nodeClickCallback:function(c,a,b){if(a.clickCallback==null){var d=a.id;
if(!d.include(XWiki.constants.wikiSpaceSeparator)&&this.getData().getNodeDataSource(a).Class=="XWEDataSource"){d=d+XWiki.constants.wikiSpaceSeparator+"Main"+XWiki.constants.spacePageSeparator+"WebHome"
}if(!d.include(XWiki.constants.spacePageSeparator)&&this.getData().getNodeDataSource(a).Class=="XWEWikiDataSource"){d=d+XWiki.constants.spacePageSeparator+"WebHome"
}if(this.getDataSource().Class!="XWEDataSource"){d=d.substring(d.indexOf(XWiki.constants.wikiSpaceSeparator)+1,d.length)
}if(a.resource.space==XWiki.currentSpace){d=d.substring(d.indexOf(XWiki.constants.spacePageSeparator)+1,d.length)
}this.input.value=d;
this.inputValueCache=d
}else{a.clickCallback(c,a,b)
}},setValue:function(a){this.input.value=a
},getValue:function(){return this.input.value
},selectResource:function(a){this.setValue(XWiki.resource.serialize(a))
},getSelectedResourceProperty:function(b){var c=this.getValue();
var a=this.getSelectedRecord();
if(c.length>0){return XWiki.resource.get(c)[b]
}else{if(a!=null){return a.isNewPage&&b=="name"?null:a.resource[b]
}}return null
},isNewPage:function(){var a=this.getSelectedRecord();
return a==null?this.getValue().length>0:a.isNewPage
},isNewAttachment:function(){return this.getSelectedRecord().isNewAttachment
}});