dojo.provide("ikewiki.IkeWikiReadStore");dojo.declare("ikewiki.IkeWikiReadStore",null,{constructor:function(actionHandlerFunction,progressFunction,errorHandler){if(progressFunction){this.updateProgressBar=progressFunction}else{this.updateProgressBar=function(percentage){}}this._fetchQueue=[];this._init(actionHandlerFunction,errorHandler)},reLoad:function(actionHandlerFunction){this.close();this._fetchQueue=[];this._init(actionHandlerFunction)},_init:function(actionHandlerFunction,errorHandler){var self,callback,myF;if(actionHandlerFunction){this._ready=false;this._items={};this._newitems={};this._moditems={};this._fetchQueue=[];self=this;callback=function(result,exception){var e;if(exception){e=new Error("error while initialising IkeWikiReadStore server connection"+exception);if(errorHandler){errorHandler(e)}else{throw e}}else{self._storename=result;self._ready=true;self.runQueue()}};myF=actionHandlerFunction.replace(/\(([a-zA-Z0-9-\'\,])/,"(callback,$1").replace(/\(\)/,"(callback)");console.log(myF);eval("ActionHandler."+myF)}},runQueue:function(){var fcall;var l=this._fetchQueue;this._fetchQueue=[];for(var i=0;i<l.length;i++){fcall=l[i];fcall.fun.call(this,fcall.args)}},getValue:function(item,attribute,defaultValue){var values=this.getValues(item,attribute);return(values.length>0)?values[0]:defaultValue},getValues:function(item,attribute){if(!this.isItem(item)){throw new Error("Item is not loaded rom this store")}var values=item.attributes.map[attribute].list;return values?values:[]},getAttributes:function(item){if(!this.isItem(item)){throw new Error("Item is not loaded rom this store")}var attributes=[];for(attr in item.attributes.map){attributes.push(attr)}return attributes},hasAttribute:function(item,attribute){return this.getValues(item,attribute).length>0},containsValue:function(item,attribute,value){return this.getValues(item,attribute).indexOf(value)>-1},isItem:function(item){return item&&item.id&&item.attributes.map&&this._items[item.id]},isItemLoaded:function(item){return item&&item.id&&this._items[item.id]},loadItem:function(keywordArgs){if(!this.isItem(keywordArgs.item)&&!this.isItemLoaded(keywordArgs.item)){if(keywordArgs.onError){keywordArgs.onError("the given argument is not an item of this store")}else{throw new Error("the given argument is not an item of this store")}}else{if(keywordArgs.onItem){keywordArgs.onItem(keywordArgs.item)}}},close:function(request){var callback;if(!this._ready){}else{callback=function(result,exception){if(exception){console.log(exception)}};ActionHandler.ReadStoreAction.close(callback,this._storename)}},getLabel:function(item){if(!this.isItem(item)){throw new Error("Item is not loaded rom this store")}return item.label},getLabelAttributes:function(item){return null},fetch:function(keywordArgs){var request,scope,self,requestId,qmap,count,callback;this.updateProgressBar("10%");if(this.ready){try{ActionHandler.ReadStoreAction.ping(this._storename)}catch(e){this.reLoad()}}this.updateProgressBar("20%");if(!this._ready){this._fetchQueue.push({fun:this.fetch,args:keywordArgs});return keywordArgs}else{request=keywordArgs;scope=keywordArgs.scope?keywordArgs.scope:dojo.global;self=this;qmap={javaClass:"java.util.HashMap",map:keywordArgs.query};callback=function(result,error){var items,item,i;if(result){console.info("result set size: "+result.list.length);self.updateProgressBar("50%");items=result.list;if(keywordArgs.onBegin){keywordArgs.onBegin.call(scope,items.length,request)}for(i=0;i<items.length;i++){item=items[i];self._items[item.id]=item;if(keywordArgs.onItem){keywordArgs.onItem.call(scope,item,request)}}if(keywordArgs.onComplete){keywordArgs.onComplete.call(scope,items,request)}self.updateProgressBar("100%")}else{if(keywordArgs.onError){keywordArgs.onError.call(scope,error,keywordArgs)}else{console.error(error)}}};requestId=ActionHandler.ReadStoreAction.fetch(callback,this._storename,qmap,keywordArgs.start?keywordArgs.start:0,-1);request.abort=function(){console.log("aborting ...");ActionHandler.cancelRequest(requestId)};return request}},getFeatures:function(){return{"dojo.data.api.Read":true,"dojo.data.api.Identity":true,"dojo.data.api.Write":true,"dojo.data.api.Notification":true}},getIdentity:function(item){if(!this.isItem(item)){throw new Error("Item is not loaded rom this store")}return item.id},getIdentityAttributes:function(item){return null},fetchItemByIdentity:function(keywordArgs){var scope,callback;if(this.ready){try{ActionHandler.ReadStoreAction.ping(this._storename)}catch(e){this.reLoad()}}if(!this._ready){this._fetchQueue.push({fun:this.fetchItemByIdentity,args:keywordArgs});return keywordArgs}else{if(this._items[keywordArgs.identity]){keywordArgs.onItem.call(scope,this._items[keywordArgs.identity],keywordArgs)}else{scope=keywordArgs.scope?keywordArgs.scope:dojo.global;callback=function(item,error){if(item){this._items[item.id]=item;keywordArgs.onItem.call(scope,item,keywordArgs)}else{if(keywordArgs.onError){keywordArgs.onError.call(scope,error,keywordArgs)}}};ActionHandler.ReadStoreAction.fetchItemByIdentity(callback,this._storename,keywordArgs.identity)}}},newItem:function(keywordArgs,parentInfo){var self;var newItem=ActionHandler.ReadStoreAction.newItem(this._storename);var args_set=false;for(attr in keywordArgs){if(!newItem.attributes.map[attr]){newItem.attributes.map[attr]={javaClass:"java.util.LinkedList",list:[]}}newItem.attributes.map[attr].list=[keywordArgs[attr]];args_set=true}this._newitems[newItem.id]=newItem;this._items[newItem.id]=newItem;if(args_set){self=this;this.save({onComplete:function(){self.onNew(newItem,parentInfo)}})}else{this.onNew(newItem,parentInfo)}return newItem},deleteItem:function(item){var self,callback;if(!this.isItem(item)){throw new Error("item does not belong to this store: "+item)}else{showStatus("Deleting ...");self=this;callback=function(result,exception){if(exception){showError("Error while deleting item",exception)}else{showStatus("Finished.");self.onDelete(item)}};ActionHandler.ReadStoreAction.deleteItem(callback,this._storename,item);return true}},setValue:function(item,attribute,value){return this.setValues(item,attribute,[value])},setValues:function(item,attribute,values){var oldValues,oldValue,newValue;if(!this.isItem(item)){throw new Error("item does not belong to this store: "+item)}else{if(!item.attributes.map[attribute]){item.attributes.map[attribute]={javaClass:"java.util.LinkedList",list:[]}}oldValues=item.attributes.map[attribute].list;item.attributes.map[attribute].list=values;if(!this._newitems[item.id]){this._moditems[item.id]=item}this.save({});oldValue=(oldValues&&oldValues.length==1)?oldValues[0]:oldValues;newValue=(values&&values.length==1)?values[0]:values;this.onSet(item,attribute,oldValue,newValue)}return true},unsetAttribute:function(item,attribute){return this.setValues(item,attribute,null)},save:function(keywordArgs){showStatus("Saving ...");var scope=keywordArgs.scope?keywordArgs.scope:dojo.global;var self=this;var callback=function(result,error){if(error){if(keywordArgs.onError){keywordArgs.onError.call(scope,error)}else{throw new Error(error)}showError("FAILED!",error)}else{if(keywordArgs.onComplete){keywordArgs.onComplete.call(scope)}showStatus("Finished.")}self._newitems={};self._moditems={}};var mlistv=[];for(id in this._moditems){mlistv.push(this._moditems[id])}var mlist={javaClass:"java.util.LinkedList",list:mlistv};var nlistv=[];for(id in this._newitems){nlistv.push(this._newitems[id])}var nlist={javaClass:"java.util.LinkedList",list:nlistv};ActionHandler.ReadStoreAction.save(callback,this._storename,nlist,mlist)},revert:function(){for(var i=0;i<this._newitems.length;i++){}this._newitems={};this._moditems={}},isDirty:function(item){if(item){return this._newitems[item.id]||this._moditems[item.id]}else{return(this._newitems!={})||(this._moditems!={})}},onSet:function(item,attribute,oldValue,newValue){},onNew:function(newItem,parentInfo){},onDelete:function(deletedItem){}});var escapeJSONChar=function(){var escapeChars=["\b","\t","\n","\f","\r"];return function(c){if(c=='"'||c=="\\"){return"\\"+c}if(c.charCodeAt(0)>=32){return c}for(var i=0;i<escapeChars.length;i++){if(c==escapeChars[i]){return"\\"+c}}return c}}();function escapeJSONString(s){var parts=s.split("");for(var i=0;i<parts.length;i++){parts[i]=escapeJSONChar(parts[i])}return'"'+parts.join("")+'"'}function toJSON(o){var marker="$_$jabsorbed$813492";var markerHead;var fixups=[];function removeMarkers(){var next;while(markerHead){next=markerHead[marker].prev;delete markerHead[marker];markerHead=next}}var omitCircRefOrDuplicate={};var json;function subObjToJSON(o,p,ref){var v=[],fixup,original,parent,circRef,i;if(o===null||o===undefined){return"null"}else{if(typeof o==="string"){return escapeJSONString(o)}else{if(typeof o==="number"){return o.toString()}else{if(typeof o==="boolean"){return o.toString()}else{if(o[marker]){fixup=[ref];parent=p;while(parent){if(original){original.unshift(parent[marker].ref)}if(parent===o){circRef=parent;original=[circRef[marker].ref]}fixup.unshift(parent[marker].ref);parent=parent[marker].parent}if(circRef){if(JSONRpcClient.fixupCircRefs){fixup.shift();original.shift();fixups.push([fixup,original]);return omitCircRefOrDuplicate}else{removeMarkers();throw new Error("circular reference detected!")}}else{if(JSONRpcClient.fixupDuplicates){original=[o[marker].ref];parent=o[marker].parent;while(parent){original.unshift(parent[marker].ref);parent=parent[marker].parent}fixup.shift();original.shift();fixups.push([fixup,original]);return omitCircRefOrDuplicate}}}else{o[marker]={parent:p,prev:markerHead,ref:ref};markerHead=o}if(o.constructor===Date){return'{javaClass: "java.util.Date", time: '+o.valueOf()+"}"}else{if(o.constructor===Array){for(i=0;i<o.length;i++){json=subObjToJSON(o[i],o,i);v.push(json===omitCircRefOrDuplicate?null:json)}return"["+v.join(", ")+"]"}else{for(var attr in o){if(attr===marker){}else{if(o[attr]===null||o[attr]===undefined){v.push('"'+attr+'": null')}else{if(typeof o[attr]=="function"){}else{json=subObjToJSON(o[attr],o,attr);if(json!==omitCircRefOrDuplicate){v.push(escapeJSONString(attr)+": "+json)}}}}}return"{"+v.join(", ")+"}"}}}}}}}json=subObjToJSON(o,null,"root");removeMarkers();if(fixups.length){return{json:json,fixups:fixups}}else{return{json:json}}}function JSONRpcClient(){var arg_shift=0,req,_function,methods,self,name,arg0type=(typeof arguments[0]),doListMethods=true;if(arg0type==="function"){this.readyCB=arguments[0];arg_shift++}else{if(arguments[0]&&arg0type==="object"&&arguments[0].length){this._addMethods(arguments[0]);arg_shift++;doListMethods=false}}this.serverURL=arguments[arg_shift];this.user=arguments[arg_shift+1];this.pass=arguments[arg_shift+2];this.objectID=0;if(doListMethods){this._addMethods(["system.listMethods"]);req=JSONRpcClient._makeRequest(this,"system.listMethods",[]);if(this.readyCB){self=this;req.cb=function(result,e){if(!e){self._addMethods(result)}self.readyCB(result,e)}}if(!this.readyCB){methods=JSONRpcClient._sendRequest(this,req);this._addMethods(methods)}else{JSONRpcClient.async_requests.push(req);JSONRpcClient.kick_async()}}}JSONRpcClient.prototype.createCallableProxy=function(objectID,javaClass){var cp,req,methodNames,name,i;cp=new JSONRPCCallableProxy(objectID,javaClass);for(name in JSONRpcClient.knownClasses[javaClass]){cp[name]=JSONRpcClient.bind(JSONRpcClient.knownClasses[javaClass][name],cp)}return cp};function JSONRPCCallableProxy(){this.objectID=arguments[0];this.javaClass=arguments[1];this.JSONRPCType="CallableReference"}JSONRpcClient.knownClasses={};JSONRpcClient.Exception=function(errorObject){var m;for(var prop in errorObject){if(errorObject.hasOwnProperty(prop)){this[prop]=errorObject[prop]}}if(this.trace){m=this.trace.match(/^([^:]*)/);if(m){this.name=m[0]}}if(!this.name){this.name="JSONRpcClientException"}};JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION=490;JSONRpcClient.Exception.CODE_ERR_CLIENT=550;JSONRpcClient.Exception.CODE_ERR_PARSE=590;JSONRpcClient.Exception.CODE_ERR_NOMETHOD=591;JSONRpcClient.Exception.CODE_ERR_UNMARSHALL=592;JSONRpcClient.Exception.CODE_ERR_MARSHALL=593;JSONRpcClient.Exception.prototype=new Error();JSONRpcClient.Exception.prototype.toString=function(code,msg){var str="";if(this.name){str+=this.name}if(this.message){str+=": "+this.message}if(str.length==0){str="no exception information given"}return str};JSONRpcClient.default_ex_handler=function(e){var str="";for(a in e){str+=a+"\t"+e[a]+"\n"}alert(str)};JSONRpcClient.toplevel_ex_handler=JSONRpcClient.default_ex_handler;JSONRpcClient.profile_async=false;JSONRpcClient.max_req_active=1;JSONRpcClient.requestId=1;JSONRpcClient.fixupCircRefs=true;JSONRpcClient.fixupDuplicates=true;JSONRpcClient.transformDates=false;JSONRpcClient.bind=function(functionName,context){return function(){return functionName.apply(context,arguments)}};JSONRpcClient._createMethod=function(client,methodName){var serverMethodCaller=function(){var args=[],callback;for(var i=0;i<arguments.length;i++){args.push(arguments[i])}if(typeof args[0]=="function"){callback=args.shift()}var req=JSONRpcClient._makeRequest(this,methodName,args,this.objectID,callback);if(!callback){return JSONRpcClient._sendRequest(client,req)}else{JSONRpcClient.async_requests.push(req);JSONRpcClient.kick_async();return req.requestId}};return serverMethodCaller};JSONRpcClient.prototype.createObject=function(){var args=[],callback=null,constructorName,_args,req;for(var i=0;i<arguments.length;i++){args.push(arguments[i])}if(typeof args[0]=="function"){callback=args.shift()}constructorName=args[0]+".$constructor";_args=args[1];req=JSONRpcClient._makeRequest(this,constructorName,_args,0,callback);if(callback===null){return JSONRpcClient._sendRequest(this,req)}else{JSONRpcClient.async_requests.push(req);JSONRpcClient.kick_async();return req.requestId}};JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX=".ref";JSONRpcClient.prototype._addMethods=function(methodNames,dontAdd){var name,obj,names,n,method,methods=[],javaClass,tmpNames,startIndex,endIndex;for(var i=0;i<methodNames.length;i++){obj=this;names=methodNames[i].split(".");startIndex=methodNames[i].indexOf("[");endIndex=methodNames[i].indexOf("]");if((methodNames[i].substring(0,JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX.length)==JSONRpcClient.CALLABLE_REFERENCE_METHOD_PREFIX)&&(startIndex!=-1)&&(endIndex!=-1)&&(startIndex<endIndex)){javaClass=methodNames[i].substring(startIndex+1,endIndex)}else{for(n=0;n<names.length-1;n++){name=names[n];if(obj[name]){obj=obj[name]}else{obj[name]={};obj=obj[name]}}}name=names[names.length-1];if(javaClass){method=JSONRpcClient._createMethod(this,name);if(!JSONRpcClient.knownClasses[javaClass]){JSONRpcClient.knownClasses[javaClass]={}}JSONRpcClient.knownClasses[javaClass][name]=method}else{method=JSONRpcClient._createMethod(this,methodNames[i]);if((!obj[name])&&(!dontAdd)){obj[name]=JSONRpcClient.bind(method,this)}methods.push(method)}javaClass=null}return methods};JSONRpcClient._getCharsetFromHeaders=function(http){var contentType,parts,i;try{contentType=http.getResponseHeader("Content-type");parts=contentType.split(/\s*;\s*/);for(i=0;i<parts.length;i++){if(parts[i].substring(0,8)=="charset="){return parts[i].substring(8,parts[i].length)}}}catch(e){}return"UTF-8"};JSONRpcClient.async_requests=[];JSONRpcClient.async_inflight={};JSONRpcClient.async_responses=[];JSONRpcClient.async_timeout=null;JSONRpcClient.num_req_active=0;JSONRpcClient._async_handler=function(){var res,req;JSONRpcClient.async_timeout=null;while(JSONRpcClient.async_responses.length>0){res=JSONRpcClient.async_responses.shift();if(res.canceled){continue}if(res.profile){res.profile.dispatch=new Date()}try{res.cb(res.result,res.ex,res.profile)}catch(e){JSONRpcClient.toplevel_ex_handler(e)}}while(JSONRpcClient.async_requests.length>0&&JSONRpcClient.num_req_active<JSONRpcClient.max_req_active){req=JSONRpcClient.async_requests.shift();if(req.canceled){continue}JSONRpcClient._sendRequest(req.client,req)}};JSONRpcClient.kick_async=function(){if(!JSONRpcClient.async_timeout){JSONRpcClient.async_timeout=setTimeout(JSONRpcClient._async_handler,0)}};JSONRpcClient.cancelRequest=function(requestId){if(JSONRpcClient.async_inflight[requestId]){JSONRpcClient.async_inflight[requestId].canceled=true;return true}var i;for(i in JSONRpcClient.async_requests){if(JSONRpcClient.async_requests[i].requestId==requestId){JSONRpcClient.async_requests[i].canceled=true;return true}}for(i in JSONRpcClient.async_responses){if(JSONRpcClient.async_responses[i].requestId==requestId){JSONRpcClient.async_responses[i].canceled=true;return true}}return false};JSONRpcClient._makeRequest=function(client,methodName,args,objectID,cb){var req={};req.client=client;req.requestId=JSONRpcClient.requestId++;var obj="{id:"+req.requestId+",method:";if((objectID)&&(objectID>0)){obj+='".obj['+objectID+"]."+methodName+'"'}else{obj+='"'+methodName+'"'}if(cb){req.cb=cb}if(JSONRpcClient.profile_async){req.profile={submit:new Date()}}var j=toJSON(args);obj+=",params:"+j.json;if(j.fixups){obj+=",fixups:"+toJSON(j.fixups).json}req.data=obj+"}";return req};JSONRpcClient._sendRequest=function(client,req){var http;if(req.profile){req.profile.start=new Date()}http=JSONRpcClient.poolGetHTTPRequest();JSONRpcClient.num_req_active++;http.open("POST",client.serverURL,!!req.cb,client.user,client.pass);try{http.setRequestHeader("Content-type","text/plain")}catch(e){}if(req.cb){http.onreadystatechange=function(){var res;if(http.readyState==4){http.onreadystatechange=function(){};res={cb:req.cb,result:null,ex:null};if(req.profile){res.profile=req.profile;res.profile.end=new Date()}else{res.profile=false}try{res.result=client._handleResponse(http)}catch(e){res.ex=e}if(!JSONRpcClient.async_inflight[req.requestId].canceled){JSONRpcClient.async_responses.push(res)}delete JSONRpcClient.async_inflight[req.requestId];JSONRpcClient.kick_async()}}}else{http.onreadystatechange=function(){}}JSONRpcClient.async_inflight[req.requestId]=req;try{http.send(req.data)}catch(e){JSONRpcClient.poolReturnHTTPRequest(http);JSONRpcClient.num_req_active--;throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"})}if(!req.cb){delete JSONRpcClient.async_inflight[req.requestId];return client._handleResponse(http)}return null};JSONRpcClient.prototype._handleResponse=function(http){if(!this.charset){this.charset=JSONRpcClient._getCharsetFromHeaders(http)}var status,statusText,data;try{status=http.status;statusText=http.statusText;data=http.responseText}catch(e){JSONRpcClient.poolReturnHTTPRequest(http);JSONRpcClient.num_req_active--;JSONRpcClient.kick_async();throw new JSONRpcClient.Exception({code:JSONRpcClient.Exception.CODE_ERR_CLIENT,message:"Connection failed"})}JSONRpcClient.poolReturnHTTPRequest(http);JSONRpcClient.num_req_active--;if(status!=200){throw new JSONRpcClient.Exception({code:status,message:statusText})}return this.unmarshallResponse(data)};JSONRpcClient.prototype.unmarshallResponse=function(data){function applyFixups(obj,fixups){function findOriginal(ob,original){for(var i=0,j=original.length;i<j;i++){ob=ob[original[i]]}return ob}function applyFixup(ob,fixups,value){var j=fixups.length-1;for(var i=0;i<j;i++){ob=ob[fixups[i]]}ob[fixups[j]]=value}for(var i=0,j=fixups.length;i<j;i++){applyFixup(obj,fixups[i][0],findOriginal(obj,fixups[i][1]))}}function transform_date(obj){var hint,foo,num,i,jsDate;if(obj&&typeof obj==="object"){hint=obj.hasOwnProperty("javaClass");foo=hint?obj.javaClass==="java.util.Date":obj.hasOwnProperty("time");num=0;if(!hint&&foo){for(i in obj){if(obj.hasOwnProperty(i)){num++}}}if(hint&&foo||foo&&num===1){jsDate=new Date(obj.time);return jsDate}else{for(i in obj){if(obj.hasOwnProperty(i)){obj[i]=transform_date(obj[i])}}return obj}}else{return obj}}var obj;try{eval("obj = "+data)}catch(e){throw new JSONRpcClient.Exception({code:550,message:"error parsing result"})}if(obj.error){throw new JSONRpcClient.Exception(obj.error)}var r=obj.result;var i,tmp;if(r){if(r.objectID&&r.JSONRPCType=="CallableReference"){return this.createCallableProxy(r.objectID,r.javaClass)}else{r=JSONRpcClient.extractCallableReferences(this,JSONRpcClient.transformDates?transform_date(r):r);if(obj.fixups){applyFixups(r,obj.fixups)}}}return r};JSONRpcClient.extractCallableReferences=function(client,root){var i,tmp,value;for(i in root){if(typeof (root[i])=="object"){tmp=JSONRpcClient.makeCallableReference(client,root[i]);if(tmp){root[i]=tmp}else{tmp=JSONRpcClient.extractCallableReferences(client,root[i]);root[i]=tmp}}if(typeof (i)=="object"){tmp=JSONRpcClient.makeCallableReference(client,i);if(tmp){value=root[i];delete root[i];root[tmp]=value}else{tmp=JSONRpcClient.extractCallableReferences(client,i);value=root[i];delete root[i];root[tmp]=value}}}return root};JSONRpcClient.makeCallableReference=function(client,value){if(value&&value.objectID&&value.javaClass&&value.JSONRPCType=="CallableReference"){return client.createCallableProxy(value.objectID,value.javaClass)}return null};JSONRpcClient.http_spare=[];JSONRpcClient.http_max_spare=8;JSONRpcClient.poolGetHTTPRequest=function(){var http=JSONRpcClient.http_spare.pop();if(http){return http}return JSONRpcClient.getHTTPRequest()};JSONRpcClient.poolReturnHTTPRequest=function(http){if(JSONRpcClient.http_spare.length>=JSONRpcClient.http_max_spare){delete http}else{JSONRpcClient.http_spare.push(http)}};JSONRpcClient.msxmlNames=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","Microsoft.XMLHTTP"];JSONRpcClient.getHTTPRequest=function(){try{JSONRpcClient.httpObjectName="XMLHttpRequest";return new XMLHttpRequest()}catch(e){}for(var i=0;i<JSONRpcClient.msxmlNames.length;i++){try{JSONRpcClient.httpObjectName=JSONRpcClient.msxmlNames[i];return new ActiveXObject(JSONRpcClient.msxmlNames[i])}catch(e){}}JSONRpcClient.httpObjectName=null;throw new JSONRpcClient.Exception({code:0,message:"Can't create XMLHttpRequest object"})};dojo.require("dojo.parser");dojo.require("dojo.string");dojo.require("dojo.fx");dojo.require("dojo.io.iframe");dojo.require("dojo.back");dojo.require("dojo.data.ItemFileReadStore");dojo.require("dijit.Tree");dojo.require("dijit.layout.LayoutContainer");dojo.require("dijit.layout.TabContainer");dojo.require("dijit.TitlePane");dojo.require("dijit.layout.LinkPane");dojo.require("dijit.layout.ContentPane");dojo.require("dojox.layout.ContentPane");dojo.require("dijit.form.Button");dojo.require("dijit.Dialog");dojo.require("dijit.form.CheckBox");dojo.require("dijit.Tooltip");dojo.require("dojox.layout.FloatingPane");dojo.require("dijit.InlineEditBox");dojo.require("dijit.form.ValidationTextBox");dojo.require("dijit.form.TextBox");dojo.require("dijit.form.ComboBox");dojo.require("dijit.form.FilteringSelect");dojo.require("dijit.form.Textarea");dojo.require("dijit.layout.AccordionContainer");dojo.require("dijit.ProgressBar");dojo.require("dojox.xml.DomParser");dojo.require("dojox.widget.Toaster");dojo.require("dojox.grid.Grid");dojo.require("dojox.grid._data.model");dojo.require("dojox.grid._data.dijitEditors");var _id=1;var conversation;var mouseX;var mouseY;var ActionHandler;var handleMouseMove=function(e){mouseX=(document.all)?window.event.x+document.body.scrollLeft:e.pageX;mouseY=(document.all)?window.event.y+document.body.scrollTop:e.pageY};dojo.connect(document,"onmousemove",handleMouseMove);dijit.layout.ContentPane.onDownloadEnd=function(url,data){this.setContent(data)};dojo.string.paramString=function(str,pairs,killExtra){var re,re2;for(var name in pairs){re=new RegExp("\\%\\{"+name+"\\}","g");str=str.replace(re,pairs[name]);re2=new RegExp("\\$\\{"+name+"\\}","g");str=str.replace(re2,pairs[name])}if(killExtra){str=str.replace(/%\{([^\}\s]+)\}/g,"")}return str};dojo.string.startsWith=function(str,start,ignoreCase){if(ignoreCase){str=str.toLowerCase();start=start.toLowerCase()}return str.indexOf(start)===0};var getAncestors=function(node,filterFunction,returnFirstHit){var ancestors=[];var isFunction=(filterFunction&&(filterFunction instanceof Function||typeof filterFunction=="function"));while(node){if(!isFunction||filterFunction(node)){ancestors.push(node)}if(returnFirstHit&&ancestors.length>0){return ancestors[0]}node=node.parentNode}if(returnFirstHit){return null}return ancestors};function findParentWindow(domNode){var node=getAncestors(domNode,function(n){var classv;if(n.nodeType==1){classv=n.getAttribute("class");if(classv&&classv.indexOf("dijitContentPane")>-1){return true}}return false},true);return dijit.byId(node.getAttribute("widgetid"))}function showStatus(message){dijit.byId("toast").setContent(message,"message",2000);dijit.byId("toast").show()}function clearStatus(){updateProgressBar("0%")}var timerId;function delayClearStatus(delay){timerId=setTimeout("clearStatus(); clearTimeout(timerId);",delay)}var updateProgressBar=function(progress){var pb_widget=dijit.byId("status-progress");if(progress=="0%"||progress=="0"){pb_widget.domNode.style.display="none"}else{pb_widget.domNode.style.display=""}pb_widget.update({progress:progress,maximum:100})};function showError(title,message){console.error(message);var et=dojo.byId("errbox-title");var em=dojo.byId("errbox-message");et.innerHTML=title;if(message&&message.message){em.innerHTML=message.message}else{em.innerHTML=message}dialog_error.show()}function showConfirmationDialog(title,message){var et=dojo.byId("confirm-title");var em=dojo.byId("confirm-message");et.innerHTML=title;em.innerHTML=message;dialog_confirm.show()}function showWaitMessage(title,message){dojo.byId("waitbox-message").innerHTML=message;dialog_wait.show()}function hideWaitMessage(){dialog_wait.hide()}function showTooltip(qtitle,target){return true}function showTextTooltip(text,target){target.onmouseover=null;if(!target.getAttribute("id")){_id++;target.setAttribute("id","id-"+_id)}var myid=target.getAttribute("id");var tooltip_area=dojo.byId("tooltip-area");var elem=document.createElement("div");if(tooltip_area){tooltip_area.appendChild(elem)}elem.innerHTML=text;var tooltip=new dijit.Tooltip({connectId:myid,label:text,showDelay:100},elem);tooltip.open()}function switchLanguage(language){var callback=function(result,exception){if(exception){showStatus("Error while switching to language "+language)}else{refresh()}};ActionHandler.RefreshAction.switchLanguage(callback,conversation,language)}var context_changed=false;function refresh(context_qtitle,nohistory){var callback;if(context_qtitle){callback=function(result,exception){var href,mystate;if(exception){if(exception.name=="at.srfg.ikewiki.permission.InsufficientPermissionsException"){showStatus("Insufficient privileges for accessing resource "+context_qtitle)}else{href=window.location.href;href.replace(/title=[^&]+/,"title="+context_qtitle);window.location.href=href}}else{context_changed=true;refreshPerspectives(true);refreshPortlets();refreshForms();refreshComponentLayout();fixupArticleLinks();fixupPageHeader();if(!nohistory){mystate={back:function(){refresh(context_qtitle,1)},forward:function(){refresh(context_qtitle,1)}};dojo.back.addToHistory(mystate)}if(!result){selectPerspective("perspective-edit_content")}}};ActionHandler.RefreshAction.refreshContext(callback,conversation,context_qtitle)}else{try{context_changed=true;refreshPerspectives(true);refreshPortlets();refreshForms();refreshComponentLayout();fixupArticleLinks()}catch(e){window.location.reload(true)}}}function refreshUri(context_uri,nohistory){var callback;if(context_uri){callback=function(result,exception){var href,mystate;if(exception){if(exception.name=="at.srfg.ikewiki.permission.InsufficientPermissionsException"){showStatus("Insufficient privileges for accessing resource "+context_uri)}else{href=window.location.href;href.replace(/title=[^&]+/,"uri="+context_uri);window.location.href=href}}else{context_changed=true;refreshPerspectives(true);refreshPortlets();refreshForms();refreshComponentLayout();fixupArticleLinks();fixupPageHeader();if(!nohistory){mystate={back:function(){refreshUri(context_uri,1)},forward:function(){refreshUri(context_uri,1)}};dojo.back.addToHistory(mystate)}if(!result){selectPerspective("perspective-edit_content")}}};ActionHandler.RefreshAction.refreshContextByUri(callback,conversation,context_uri)}else{try{refreshPerspectives(true);refreshPortlets();refreshForms();refreshComponentLayout();fixupArticleLinks()}catch(e){window.location.reload(true)}}}function refreshPerspectives(really){var i,ep,child;ep=dijit.byId("perspectives");try{hideContextGraph()}catch(e){}for(i=0;i<ep.getChildren().length;i++){child=ep.getChildren()[i];if(child&&(really||child!=ep.selectedChildWidget)){child.isLoaded=false;child.setHref(child.hasHref)}}}function refreshPortlets(){}var forms=[];function registerForm(form){forms.push(form)}function refreshForms(){for(var i=0;i<forms.length;i++){forms[i].isLoaded=false;forms[i].setHref(forms[i].hasHref);forms[i].cacheContent=false}}var permission_components={};var components_disabled={};function refreshComponentLayout(){var callback=function(permissions,exception){var perm_id,widget_id,widget,tabs,i;if(exception){showStatus("error while retrieving component list");showStatus("Exception",exception+"");console.error("error while retrieving component list: "+exception)}else{for(i in permission_components){perm_id=i;widget_id=permission_components[i];widget=dijit.byId(widget_id);if(widget){if(permissions.map[perm_id]){widget.enable();components_disabled[widget_id]=false}else{widget.disable();components_disabled[widget_id]=true}}else{alert("Widget "+widget_id+" not defined!")}}tabs=dijit.byId("perspectives");tabs.layout();context_changed=false}};ActionHandler.LayoutAction.listEnabledComponents(callback,conversation)}function fixupArticleLinks(){var page=dojo.byId("mainContent");var links,link,i;if(page){links=page.getElementsByTagName("a");for(i=0;i<links.length;i++){link=links[i];if(link.getAttribute("lTarget")){link.onclick=function(){refresh(this.getAttribute("lTarget"));return false}}}}}function getPageTitle(contextTitle){return"SWiM - "+contextTitle}function fixupPageHeader(){var metadata_callback=function(metadata,exception){var rdfexport,metas,context_title,context_uri,pagetitle,dcmap,i,key,head,meta;if(exception){log.error("error while retrieving context metadata"+exception)}else{context_title=metadata.map.context_qtitle;context_uri=metadata.map.context_uri;dcmap=metadata.map.context_dublincore;try{document.title=getPageTitle(context_title);pagetitle=dojo.byId("hd-title");pagetitle.innerHTML=getPageTitle(context_title)}catch(e){}rdfexport=dojo.byId("hd-rdf-export");rdfexport.setAttribute("href",rdfexport.getAttribute("base")+"components/actions/export.jsp?format=rdf/xml&scope=resource&uri="+escape(context_uri));metas=document.getElementsByTagName("meta");for(i=0;i<metas.length;i++){if(metas[i].getAttribute("name")&&metas[i].getAttribute("name").substr(0,3)=="DC."){metas[i].parentNode.removeChild(metas[i])}}for(key in dcmap.map){head=document.getElementsByTagName("head")[0];meta=document.createElement("meta");meta.setAttribute("name","DC."+key);meta.setAttribute("content",dcmap.map[key]);head.appendChild(meta)}}};ActionHandler.RefreshAction.getContextMetadata(metadata_callback,conversation)}function selectPerspective(id){dijit.byId("perspectives").selectChild(id);dijit.byId(id).startup()}function createCookie(name,value,days){var expires,date;if(days){date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires="; expires="+date.toGMTString()}else{expires=""}document.cookie=name+"="+value+expires+"; path=/"}function readCookie(name){var c;var nameEQ=name+"=";var ca=document.cookie.split(";");for(var i=0;i<ca.length;i++){c=ca[i];while(c.charAt(0)===" "){c=c.substring(1,c.length)}if(c.indexOf(nameEQ)===0){return c.substring(nameEQ.length,c.length)}}return null}function eraseCookie(name){createCookie(name,"",-1)}var fillTemplate=function(template,new_id,map,mode){var entry=template.cloneNode(true);if(new_id!==null){entry.setAttribute("id",new_id)}else{entry.removeAttribute("id")}entry.removeAttribute("parseWidgets");template.parentNode.insertBefore(entry,template);if(mode.indexOf("table")!=-1){console.info("to call fillTemplate with mode='"+mode+"' is deprecated, IE6+7 doesn't allow to set style.display to this value.")}entry.style.display=mode;entry.innerHTML=dojo.string.paramString(entry.innerHTML,map,false);entry.innerHTML=entry.innerHTML.replace(/ikewikitype/gi,"dojoType");dojo.parser.parse(entry);return entry};var init_form=function(id,permission_id,href){eval("form"+id+' = dijit.byId("form-'+id+'");');var widget=dijit.byId("form-"+id);var form_content=dijit.byId("form-"+id+"-content");widget.enable=function(){};widget.disable=function(){};widget.closeWindow=function(){widget.hide()};dojo.connect(widget,"hide",function(){form_content.hide();setTimeout("refreshForms()",1)});widget.ikewikiShow=function(){form_content.show();form_content._loadCheck(true);dojo.connect(form_content,"onLoad",function(){widget.show()})};widget.ikewikiLoad=function(){form_content._loadCheck(true)};widget.ikewikiContent=form_content;form_content.hasHref=href;form_content.cacheContent=false;registerForm(form_content);widget.hide();permission_components[permission_id]="form-"+id};var init_perspective=function(id,permission_id,href){var container=dijit.byId("perspectives");var widget=dijit.byId("perspective-"+id);widget.hasHref=href;permission_components[permission_id]="perspective-"+id;widget.disable=function(){var tabs=container.tablist;var button=tabs.pane2button[this];button.onClickSaved=button.onClick;button.onClick=function(){dojo.addClass(button.domNode,"button-disabled")};button.setDisabled(true);dojo.removeClass(button.domNode,"button-enabled");dojo.addClass(button.domNode,"button-disabled")};widget.enable=function(){var tabs=container.tablist;var button=tabs.pane2button[this];if(button.onClickSaved){button.onClick=button.onClickSaved}button.setDisabled(false);dojo.removeClass(button.domNode,"button-disabled");dojo.addClass(button.domNode,"button-enabled")};dojo.connect(widget,"onLoad",function(){var content=dojo.query(".perspective-body",widget.domNode)[0];var height=content.clientHeight+100;container.resize({h:height})})};var fixPerspectiveSize=function(){var content=dojo.query(".perspective-body",dojo.byId("column-center"))[0];var height=content.clientHeight+100;var container=dijit.byId("perspectives");container.resize({h:height})};var init_portlet=function(id,permission_id,href){var widget=dijit.byId("portlet-"+id);var pane=dijit.byId("portlet-pane-"+id);widget.hasHref=href;permission_components[permission_id]="portlet-"+id;widget.enable=function(){widget.show();pane.show();this.setHref(this.hasHref)};widget.disable=function(){pane.hide()};widget._handleDefaults=function(e,handler,messageType){}};var wrap_function_component_onload=function(component_id,f){var widget=dijit.byId(component_id);var fun=dojo.connect(widget,"onLoad",function(){f();dojo.disconnect(fun)})};var hideWidgetById=function(id){var widget=dijit.byId(id);widget.hide()};var showWidgetById=function(id){var widget=dijit.byId(id);widget.show()};var checkFormButton=function(form_id,button_id){var form=dijit.byId(form_id);var button=dijit.byId(button_id);button.setDisabled(!form.isValid())};dijit._Widget.prototype.show=function(){this.domNode.style.display=""};dijit._Widget.prototype.hide=function(){this.domNode.style.display="none"};var switchTheme=function(theme){var theme_callback=function(context_title,exception){if(!exception){try{window.location.reload()}catch(e){}}};ActionHandler.RefreshAction.switchTheme(theme_callback,theme)};dojo.addOnLoad(function(){try{ActionHandler=new JSONRpcClient("JSON-RPC")}catch(e){alert("JSON-RPC initialisation error: "+e)}dojo.connect(document,"onclick",function(){delayClearStatus(5000)})});function omcd_divfold(_Id){var thisLevel=document.getElementById(_Id);var thisLevela=document.getElementById(_Id.concat("a"));if(thisLevel.style.display!="none"){thisLevel.style.display="none";thisLevela.className=thisLevela.className.replace("omcd_active","omcd_inactive")}else{thisLevel.style.display="block";thisLevela.className=thisLevela.className.replace("omcd_inactive","omcd_active")}};