var contextPath = ''; /* ################################### ### i18n.js ################################### */ /* ################################### ### Message Class ################################### */ var MGNL_I18N_DEFAULT_BASENAME = "info.magnolia.module.admininterface.messages"; /* ################################### ### Constructor ################################### */ function MgnlI18nMessages(){ this.messages = new Object(); } /* ################################### ### Add a message. Basename is optional ################################### */ MgnlI18nMessages.prototype.add = function (key, msg, basename){ if(basename==null){ basename = MGNL_I18N_DEFAULT_BASENAME; } if(this.messages[basename] == null){ this.messages[basename] = new Object(); } this.messages[basename][key]=msg; } /* ################################### ### Get a Message. Basename is optional ################################### */ MgnlI18nMessages.prototype.get = function (key, basename, args){ var msg; // basename is optional if(basename == null) basename = MGNL_I18N_DEFAULT_BASENAME; // return ??? key ??? if you can't find the mesage if(this.messages[basename] == null || this.messages[basename][key] == null){ return "???" + key + "???"; } msg = this.messages[basename][key]; // replace parameters if(args != null){ for(i=0; i

'); doc.write('

'); doc.write('
'); doc.close(); } else{ doc = console.document; } if(doc == null) return; // get the div to write in var div = doc.getElementById('consoleDiv'); if(o){ msg += ":" + mgnlDebugObject(o, level, ""); } if(context != null) msg = context + ": " + msg; div.innerHTML += msg + "
"; } function mgnlDebugObject(o, level, spaces){ var res = ""; switch(typeof o){ case "object": if(level<=0) return "object"; res = "
" + spaces + "{
"; for(var key in o){ if(!res.match(/\{
$/)) res += ",
"; res += spaces + "   " + key + ":"; res += mgnlDebugObject(o[key], level-1, spaces + "   "); } res += "
" + spaces + "}"; break; case "function": return "function" break; default: return o; } return res; } /* ################################### ### generic.js ### generic, magnolia independant methods ################################### */ /** * Simple shortcut for document.getElementById() */ if (typeof $ != 'function') { function $(element) { return document.getElementById(element); } } /** * get position of an object */ function mgnlGetPosX(obj) { if (!obj) return 0; if (navigator.appName.indexOf("Microsoft")==-1) { if (navigator.vendor!=("Netscape6") && navigator.product!=("Gecko")) return obj.x; //ns4 else //ns6; don't laugh... { for (var elem in obj) { var tmp=obj[elem]; } return obj.offsetLeft; } } var x=document.body.scrollLeft; while (obj.offsetParent) { x+=obj.offsetLeft; obj=obj.offsetParent; } return x; //ie } function mgnlGetPosY(obj) { if (!obj) return 0; return obj.offsetTop; if (navigator.appName.indexOf("Microsoft")==-1) { if (navigator.vendor!=("Netscape6") && navigator.product!=("Gecko")) return obj.y; //ns4 else //ns6; don't laugh... { for (var elem in obj) { var tmp=obj[elem]; } return obj.offsetTop; } } var y=document.body.scrollTop; while (obj.offsetParent) { y+=obj.offsetLeft; obj=obj.offsetParent; } return y; //ie } function mgnlGetMousePos(event) { var pos=new Object(); if (document.all) { pos.x=window.event.clientX+document.body.scrollLeft; pos.y=window.event.clientY+document.body.scrollTop; } else { pos.x=event.pageX; pos.y=event.pageY; } return pos; } /* ################################### ### miscellaneous ################################### */ function mgnlIsKeyEnter(event){ return mgnlIsKey(event,13); } function mgnlIsKeyEscape(event){ return mgnlIsKey(event,27); } function mgnlIsKey(event,keyCode){ if (window.event && window.event.keyCode == keyCode) return true; else if (navigator.appName=="Netscape" && event.which==keyCode) return true; else return false; } function mgnlGetWindowSize() { var obj=new Object(); if( typeof (window.innerWidth) == 'number' ) { //Non-IE obj.w=window.innerWidth; obj.h=window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' obj.w=document.documentElement.clientWidth; obj.h=document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible obj.w=document.body.clientWidth; obj.h=document.body.clientHeight; } //alert(h+'//'+w); return obj; } function mgnlGetIFrameDocument(iFrameName) { if (document.frames && document.frames[iFrameName]) return document.frames[iFrameName].document; else if (document.getElementById(iFrameName)) return document.getElementById(iFrameName).contentDocument; else return null; } function mgnlGetCacheKiller() { var now = new Date(); return now.getTime(); } /* ################################### ### add/remove parameter to query string ################################### */ function mgnlAddParameter(href, name, value) { var anchorSplit = href.split("#"); var anchor = (anchorSplit.length == 2) ? "#"+anchorSplit[1] : ""; href=anchorSplit[0]; var delimiter; if (href.indexOf("?") == -1) delimiter = "?"; else delimiter = "&"; return href + delimiter + name + "=" + value + anchor; } function mgnlRemoveParameter(href, name) { var anchorSplit = href.split("#"); var anchor = (anchorSplit.length == 2) ? "#"+anchorSplit[1] : ""; href=anchorSplit[0]; var tmp=href.split("?"); var newHref=tmp[0]; var query= new Array(); if (tmp[1]) { var paramObj=tmp[1].split("&"); for (var i=0;i=0){ url+="&"; } else{ url+="?"; } url+="mgnlCK="+mgnlGetCacheKiller(); var w=window.open(url,"mgnlDialog"+mgnlGetCacheKiller(),"width="+width+",height="+height+",scrollbars=no,status=yes,resizable=yes"); if (w) w.focus(); } /* ################################### ### open dialog window ################################### */ function mgnlOpenDialog(path,nodeCollection,node,paragraph,repository,dialogPage,width,height) { //dialog window is resized in dialog itself (window.resize) if (!width) width=800; if (!height) height=100; //magnolia edit window: add browser information (needed for rich editor) var agent=navigator.userAgent.toLowerCase(); var richE="false"; var richEPaste=""; var richESupported=false; if (document.designMode) { //safari has designMode... if (agent.indexOf("safari")==-1) richESupported=true; } if (richESupported) { //richedit richE="true"; if (agent.indexOf("mac")!=-1) richEPaste="false"; else if (agent.indexOf("msie")!=-1) richEPaste="button"; else richEPaste="textarea"; } if (!dialogPage){ dialogPage = ".magnolia/dialogs/" + paragraph + ".html"; } var url=contextPath; url+="/"+ dialogPage; url+="?mgnlPath="+path; if (nodeCollection) { url += "&mgnlNodeCollection=" + nodeCollection; } if (node) { url += "&mgnlNode=" + node; } if (paragraph) { url += "&mgnlParagraph=" + paragraph; } url+="&mgnlRichE="+richE; url+="&mgnlRichEPaste="+richEPaste; url+="&mgnlRepository="+repository; url+="&mgnlCK="+mgnlGetCacheKiller(); var w=window.open(url,"mgnlDialog"+mgnlGetCacheKiller(),"width="+width+",height="+height+"scrollbars=no,status=yes,resizable=yes"); if (w) w.focus(); } /* ################################### ### open tree browser ################################### */ function mgnlOpenTreeBrowser(pathSelected, pathOpen, repository, width, height, callBackCommand){ mgnlDebug("mgnlOpenTreeBrowser","dialog"); if (!width) width=450; if (!height) height=550; var src = contextPath + "/.magnolia/pages/linkBrowser.html?mgnlCK="+mgnlGetCacheKiller(); if (pathSelected) src+="&pathSelected="+pathSelected; if (pathOpen) src+="&pathOpen="+pathOpen; if (repository) src+="&repository="+repository; var w=window.open(src,"mgnlTreeBrowser","width="+width+",height="+height+",resizable=yes,status=yes,scrollbars=no"); mgnlDebug("register call back function", "dialog"); // we can't set this on the opened window since this is lost in safari window.mgnlCallBackCommand = callBackCommand; } function mgnlOpenTreeBrowserWithControl(control,repository,pathSelected,pathOpen,extension,width,height,addcontext){ pathSelected = pathSelected?pathSelected:control.value; pathOpen = pathOpen?pathOpen:control.value; mgnlDebug("mgnlOpenTreeBrowserWithControl","dialog"); var callBackCommand = new MgnlTreeBrowserWithControlCallBackCommand(control,extension,addcontext); mgnlOpenTreeBrowser(pathSelected, pathOpen, repository, width, height, callBackCommand) } /* ################################### ### tree browser default callback ################################### */ function MgnlTreeBrowserWithControlCallBackCommand(control, extension, addcontext){ this.control = control; this.extension = extension; this.addcontext = addcontext; this.callback = function(value){ if (this.addcontext){ value = contextPath + value; } if (this.extension){ value += "." + extension; } mgnlDebug("MgnlTreeBrowserCallBackCommand: write to the control", "dialog"); this.control.value = value; } } /* ################################### ### open adminCentral ################################### */ function mgnlOpenAdminCentral(path,repository) { var src=""; src+="${pageContext.request.contextPath}/.magnolia/adminCentral.html?mgnlCK="+mgnlGetCacheKiller(); src+="&pathSelected="+path; if (repository) src+="&repository="+repository; var w=window.open(src,"mgnlAdminCentral",""); if (w) w.focus(); } /* ################################### ### update mgnlCK in the extisting location string ################################### */ function mgnlUpdateCK(href) { if (!href) href=document.location.href; href = mgnlRemoveParameter(href, 'mgnlCK'); href = mgnlAddParameter(href, 'mgnlCK', new Date().getTime()); return href; } /* ################################### ### alert ################################### */ function mgnlAlert(text,title) { var line="--------------------------------------------\n"; var alertText=""; alertText+=line; if (title) alertText+=title+"\n"+line; alertText+="\n"+text+"\n"; alertText+=line; alert(alertText); } /* ################################### ### confirm ################################### */ function mgnlConfirm(text,title) { var line="--------------------------------------------\n"; var alertText=""; alertText+=line; if (title) alertText+=title+"\n"+line; alertText+="\n"+text+"\n"; alertText+=line; return confirm(alertText); } function eventHandlerOnResize(e) { //resize tabs before resize of trees (in case there are any trees on a tab) mgnlDialogResizeTabs(); mgnlDialogLinkBrowserResize(); mgnlTreeResize(); } /* ################################### ### controls.js ################################### */ var mgnlControlButtonBorderDark="#396101"; var mgnlControlButtonBorderLight="#ADC97B"; var mgnlControlButtonPUSHED="_PUSHED"; function mgnlShiftDividedButton(id) { var button=document.getElementById(id); if (button) { var state; if (button.type=="checkbox") state=!button.checked; else state=true; button.checked=state; } } function mgnlShiftPushButtonDown(button) { if (button.className.indexOf(mgnlControlButtonPUSHED)==-1) { button.style.borderTopColor=mgnlControlButtonBorderDark; button.style.borderLeftColor=mgnlControlButtonBorderDark; button.style.borderBottomColor=mgnlControlButtonBorderLight; button.style.borderRightColor=mgnlControlButtonBorderLight; } } function mgnlShiftPushButtonOut(button) { button.style.borderTopColor=""; button.style.borderLeftColor=""; button.style.borderBottomColor=""; button.style.borderRightColor=""; } function mgnlShiftPushButtonClick(button) { if (button.id.indexOf("_SETBUTTON_")!=-1) { //is part of a button set (radio, e.g. tab buttons) -> disable all other buttons var baseId=button.id.substring(0,button.id.lastIndexOf("_")); var i=0; var className=button.className; if (className.indexOf(mgnlControlButtonPUSHED)==-1) { while (document.getElementById(baseId+"_"+i)) { var currentButton=document.getElementById(baseId+"_"+i) currentButton.className=className; i++; } button.className=className+mgnlControlButtonPUSHED; } } mgnlShiftPushButtonOut(button); //get rid of hilighted borders } /* ################################### ### tree.js ################################### */ var globalCounter=0; //for debugging //################# //### Tree //### repository: the repository name //### name: the name of the javascript tree //### handlerName: the name of the tree handler //### browseMode: true if the tree is showed in the link browser. //### functionBarName: the name of the functionBar javascript object (needs call to refresh on selectNode) //################# function mgnlTree(repository, path, name, height, handlerName, browseMode, functionBarName) { if(handlerName == null){ handlerName = repository; } if(browseMode == null){ browseMode = false; } this.repository=repository; this.path=path; this.name=name; this.handlerName = handlerName; this.browseMode = browseMode; this.functionBarName = functionBarName; mgnlDebug("new mgnlTree", "tree", this); document.write(''); this.divMain=document.getElementById(name+"_"+path+"_DivMain"); // this is setted afterward because a cyclic dependency for the conditions this.menu = null; this.addressBar=document.getElementById(name+"AddressBar"); this.divMoveShadow=document.getElementById(name+"_MoveShadow"); this.divMoveDenied=document.getElementById(name+"_MoveDenied"); this.nodes=new Object(); this.selectedNode=this.getNode(path); this.clipboardNode=null; this.clipboardMethod=null; this.lastEditedHtmlObject; this.lastEditedOriginalValue=""; this.lastEditedNode; this.lastEditedName=""; this.lastEditedIsMeta=false; this.lastEditedIsLabel=false; this.lastEditedIsNodeDataValue=false; this.lastEditedIsNodeDataType=false; this.columns=new Array(); //this.columnResizerDiv=document.getElementById(name+"_ColumnResizerDiv"); this.columnResizerLine=document.getElementById(name+"_ColumnResizerLine"); this.columnHeaderDiv=document.getElementById(name+"_ColumnHeader"); this.height=height; this.paddingLeft=0; this.paddingRight=0; this.paddingTop=0; this.paddingBottom=0; this.columnResizerGifWidthHalf=4; this.columnResizerGifWidth=9; this.columnSpacing=8; this.columnMinimumWidth=20; this.colors=new Object(); this.colors.nodeHighlight="#EDF2FA"; this.colors.nodeSelected="#D1E1ED"; this.strings=new Object(); this.strings.saving=mgnlMessages.get('tree.saving.js'); this.strings.loading=mgnlMessages.get('tree.loading.js'); this.strings.empty="-"; this.moveDontReset=false; this.moveDenied=false; this.moveDeniedTimeout=200; this.moveLastMouseoverId=null; } mgnlTree.prototype.expandNode = function(path) { mgnlDebug('tree.expandNode','tree'); var chunks=path.split("/"); var id=""; for (var i=1;i [], [en], [bla] { id+="/"+chunks[i]; var node=this.nodes[id]; if (node) { node.expand(); } else { node=this.getNode(id); var divSub=document.getElementById(node.divSubId); if (divSub.innerHTML=="") { var params=new Object(); params.pathSelected=path; node.expand(params); break; } } } this.selectNode(path); } mgnlTree.prototype.shifterDown = function(id) { this.moveDontReset=true; this.shiftNode(id); } mgnlTree.prototype.shifterOut = function() { this.moveDontReset=false; } mgnlTree.prototype.shiftNode = function(id) { var node=this.getNode(id); node.shift(); } mgnlTree.prototype.selectNode = function(id) { mgnlDebug("selectNode:" + id, "tree"); var sNode=this.getNode(id); var divMain=document.getElementById(sNode.divMainId); mgnlDebug("selectNode: divMainId:" + sNode.divMainId, "tree"); var divMainSelected=document.getElementById(this.selectedNode.divMainId); if (divMain && this.selectedNode.divMainId!=sNode.divMainId) { if (divMainSelected) { divMainSelected.style.backgroundColor=""; divMainSelected.style.textDecoration=""; } divMain.style.backgroundColor=this.colors.nodeSelected; if(this.addressBar){ this.addressBar.value=id; } this.selectedNode=sNode; // refresh functionBar if (window[this.functionBarName]) { eval (this.functionBarName).refresh (); } } } mgnlTree.prototype.getNode = function(id) { var node=this.nodes[id]; if (!node) { node=new mgnlTreeNode(this,id); this.nodes[id]=node; } return node; } mgnlTree.prototype.dragColumnStart = function(resizerGif,resizerNumber) { if (!mgnlDragTreeColumn) { var line=this.columnResizerLine; line.style.left=mgnlGetPosX(resizerGif) + 5; line.style.visibility="visible"; line.style.top=mgnlGetPosY(this.divMain); line.style.height=parseInt(this.divMain.style.height)+1; this.columnResizerGif=resizerGif; this.columnResizerLine=line; this.columnResizerNumber=resizerNumber; mgnlDragTreeColumn_Tree=this; mgnlDragTreeColumn=true; } } mgnlTree.prototype.dragColumnStop = function(e){ //todo: resize edit control! mgnlDragTreeColumn=false; this.columnResizerLine.style.visibility="hidden"; var lastLeft=0; // true if more than one chanaged var resizeAll=true; // loop over all columns // the resizer gif is already at the new position for (var i=0;i=0; elem0--) { mgnlDebug("mgnlTree.resize: styleSheets[elem0].href = " + document.styleSheets[elem0].href, "tree"); var rules=document.styleSheets[elem0][rulesKey]; mgnlDebug("mgnlTree.resize: rules", "tree", rules); //for (var elem1 in rule) //does not work in firebird 0.8, safari 1.2 for (var elem1=0; elem1'; strDiv +=''; strDiv +=''; strDiv +=''; strDiv +=''; strDiv +=''; strDiv +='
'; strDiv +=''; strDiv +=''; strDiv +=''; var resDiv = document.createElement('div'); resDiv.id= "mgnlImportdiv"; document.body.appendChild(resDiv); resDiv.innerHTML = strDiv; $('mgnlImportdiv').style.left = (mgnlGetPosX(link) + 20) + "px"; $('mgnlImportdiv').style.top = mgnlGetPosY(link) + "px"; } mgnlTree.prototype.copyNode = function() { mgnlTreeMoveNode=true; mgnlTreeMoveNode_Tree=this; this.clipboardNode=this.selectedNode; this.clipboardMethod=1; //Tree.ACTION_COPY } mgnlTree.prototype.cutNode = function() { mgnlTreeMoveNode=true; mgnlTreeMoveNode_Tree=this; this.clipboardNode=this.selectedNode; this.clipboardMethod=0; //Tree.ACTION_MOVE var divMain=document.getElementById(this.selectedNode.divMainId); divMain.style.textDecoration="line-through"; } mgnlTree.prototype.pasteNode = function(id,pasteType,permissionWrite,lineDivId){ if (mgnlTreeMoveNode && permissionWrite){ if (this.clipboardMethod==0 && id.indexOf(this.clipboardNode.id)==0 && pasteType!=0){ //move into itself is not possible mgnlAlert(mgnlMessages.get('tree.pastenode.itself.js')); } else if (this.clipboardMethod==1 && id.indexOf(this.clipboardNode.id)==0 && pasteType!=0){ //move into itself is not possible mgnlAlert(mgnlMessages.get('tree.pastenode.itself.js')); } else{ // confirm deactivation var text=mgnlMessages.get('tree.movenode.confirm.text.js', null, [this.clipboardNode.id]); var title=mgnlMessages.get('tree.movenode.confirm.title.js'); if (!this.getNode(this.clipboardNode.id).isActivated || this.clipboardMethod==1 || mgnlConfirm(text,title)){ if (lineDivId){ //for last line on root level var lineDiv=document.getElementById(lineDivId); lineDiv.style.backgroundImage=""; } this.moveReset(); this.selectedNode=this.getNode(id); var parentPath=this.selectedNode.id.substring(0,this.selectedNode.id.lastIndexOf("/")); if (parentPath=="") parentPath="/"; var pathToReload; if (this.clipboardMethod==0){ //paste after cut if (this.clipboardNode.id.indexOf(parentPath)==0){ //e.g. sort inside a directory or paste into sister: reload selected pathToReload=parentPath; } else{ //no hokums, reload root pathToReload=this.path; } } else{ //paste after copy if (pasteType==2){ //Tree.PASTETYPE_SUB: reload selected pathToReload=this.selectedNode.id; var shifter=document.getElementById(this.selectedNode.shifterId); if (shifter){ var src=shifter.src; src=src.replace("EMPTY","COLLAPSE"); src=src.replace("EXPAND","COLLAPSE"); shifter.src=src; } } else { //reload parent of selected pathToReload=parentPath; } } var nodeToReload=this.getNode(pathToReload); var params=new Object(); params.forceReload=true; params.treeAction=this.clipboardMethod; params.pathClipboard=this.clipboardNode.id; params.pathSelected=this.selectedNode.id; params.pasteType=pasteType; nodeToReload.expand(params); } } this.clipboardNode=null; this.clipboardMethod=null; this.moveReset(); } } mgnlTree.prototype.moveNode = function(x,y) { if (this.divMoveShadow.style.visibility=="hidden") { //initalize var icon=document.getElementById(this.selectedNode.iconId); var shadowSrc=icon.src; var label=document.getElementById(this.selectedNode.labelId).innerHTML; this.divMoveShadow.innerHTML=''+label+''; this.divMoveShadow.style.visibility="visible"; this.divMoveDenied.style.visibility="visible"; } this.divMoveShadow.style.left=x+6; this.divMoveShadow.style.top=y+11; this.divMoveDenied.style.left=x+10; this.divMoveDenied.style.top=y+2; } mgnlTree.prototype.moveNodeHighlightLine = function(divId) { if (mgnlTreeMoveNode) { mgnlDebug("highlight line" + divId, "tree"); div=document.getElementById(divId); div.style.backgroundImage="url(" + contextPath + "/.resources/controls/tree/line_internode.gif)"; this.divMoveDenied.style.visibility="hidden"; this.moveLastMouseoverId=div.id; this.moveDenied=false; } } mgnlTree.prototype.moveNodeResetLine = function(divId) { if (mgnlTreeMoveNode) { div=document.getElementById(divId); div.style.backgroundImage=""; //to avoid flickering show the denied icon after a short timeout this.moveDenied=true; setTimeout("mgnlTreeMoveDeniedHide('"+this.name+"','"+div.id+"')",this.moveDeniedTimeout); } } mgnlTree.prototype.moveReset = function() { if (mgnlTreeMoveNode && !this.moveDontReset) { mgnlTreeMoveNode=false; mgnlTreeMoveNode_Tree=null; this.moveDenied=false; this.divMoveShadow.style.visibility="hidden"; this.divMoveDenied.style.visibility="hidden"; var divMain=document.getElementById(this.selectedNode.divMainId); divMain.style.textDecoration=""; divMain.style.backgroundColor=""; } } mgnlTree.prototype.activateNode = function(action,recursive) { var nodeToReload=this.selectedNode.getParent(); var params=new Object(); params.forceReload=true; params.treeAction=action; params.pathSelected=this.selectedNode.id; if (recursive) params.recursive=recursive; nodeToReload.expand(params); } mgnlTree.prototype.deactivateNode = function(action) { var nodeToReload=this.selectedNode.getParent(); var params=new Object(); params.forceReload=true; params.treeAction=action; params.pathSelected=this.selectedNode.id; nodeToReload.expand(params); } mgnlTree.prototype.editNodeData = function(span,id,columnNumber) { var column=this.columns[columnNumber]; var htmlEdit=column.htmlEdit; if (htmlEdit!="") { var value=span.innerHTML; value = value.replace(/</g,"<"); value = value.replace(/>/g,">"); value = value.replace(/&/g,"&"); if (value.toLowerCase().indexOf("/g,">"); document.getElementById(lastEditedHtmlObjectId).innerHTML=html; if (isLabel) { //reload parent //todo: highlight renamed (s. copy/move; hidden field mgnlSelectNode) var parentPath=id.substring(0,id.lastIndexOf("/")); var selectedPath=parentPath+"/"+html; if (!parentPath) parentPath="/"; var parent=tree.getNode(parentPath); var nodeParams=new Object(); nodeParams.forceReload=true; nodeParams.pathSelected=selectedPath; parent.expand(nodeParams); //reset tree nodes tree.nodes=new Object(); } } function mgnlTreeResize() { for (var elem in mgnlTreeControls) { var tree=mgnlTreeControls[elem]; mgnlTreeControls[elem].resize(); } } //################# //### TreeColumn //################# function mgnlTreeColumn(width,htmlEdit,name,isMeta,isLabel,isNodeDataValue,isNodeDataType) { this.width=width; this.htmlEdit=htmlEdit; this.name=name; this.isMeta=isMeta; this.isLabel=isLabel; this.isNodeDataValue=isNodeDataValue; this.isNodeDataType=isNodeDataType; } //################# //### TreeNode //################# function mgnlTreeNode(treeControl,id) { this.id = id; this.path = id; if (id.lastIndexOf("/")==0) this.parentId="/"; //parent is root else this.parentId=id.substring(0,id.lastIndexOf("/")); this.label=id.substring(id.lastIndexOf("/")+1); this.idPre=treeControl.name+"_"+id; this.repository=treeControl.repository; this.treeName=treeControl.name; this.tree=treeControl; if (document.getElementById(this.idPre+"_ItemType")) { this.itemType=document.getElementById(this.idPre+"_ItemType").value; } if (document.getElementById(this.idPre+"_IsActivated")) { if (document.getElementById(this.idPre+"_IsActivated").value=="true") this.isActivated=true; else this.isActivated=false; } if (document.getElementById(this.idPre+"_PermissionWrite")) { if (document.getElementById(this.idPre+"_PermissionWrite").value=="true") this.permissionWrite=true; else this.permissionWrite=false; } //html objects get lost, therefore use id and getElement on the float this.divMainId=this.idPre+"_DivMain"; this.shifterId=this.idPre+"_Shifter"; this.divSubId=this.idPre+"_DivSub"; this.iconId=this.idPre+"_Icon"; this.labelId=this.idPre+"_Column0Main"; if(document.location.href.indexOf("?")!=-1) this.url=document.location.href.substring(0,document.location.href.indexOf("?")); else this.url=document.location.href; } mgnlTreeNode.prototype.getParent = function(){ var parentPath=this.id.substring(0,this.id.lastIndexOf("/")); if (parentPath == ""){ parentPath = this.tree.path; //root } return this.tree.getNode(parentPath); } mgnlTreeNode.prototype.getHttpRequest = function() { var httpReq; if (window.XMLHttpRequest) httpReq = new XMLHttpRequest(); else if (window.ActiveXObject) httpReq = new ActiveXObject("Microsoft.XMLHTTP"); //IE/Windows ActiveX return httpReq; } mgnlTreeNode.prototype.httpRequest = function(params, callBackParams, callback) { /* //todo: clean up ... (e.g. isMeta, isLabel etc. to treeAction) * params is object of key/value pairs * possible keys: -------------------------------------------------------------------- pathOpen: path to open //check! and remove? pathSelected: path to select -> does not work (js is not executed at remote scripting); -------------------------------------------------------------------- * create and remove nodes createItemType: String; type of the item [NT_CONTENT | NT_CONTENTNODE | NT_NODEDATA] deleteNode: node to delete -------------------------------------------------------------------- * save node data values * save node data types * save names (label) of data or nodes (rename) saveName: name of the item which has to be saved saveValue: value to be saved isMeta: boolean - nodeData 'saveName' is meta data isLabel: boolean -> move 'this.path' to 'saveValue' (rename) isNodeDataValue: boolean - item to save is value of node data 'saveName' ('config admin') isNodeDataType: boolean - item to save is type of node data 'saveName' ('config admin') -------------------------------------------------------------------- * paste nodes treeAction: [ MOVE | COPY ] pathClipboard: path to move or copy //todo: mutliple selection pathSelected: path to move to pasteType: put pathOrigin [ ABOVE | BELOW | SUB ] of pathDestination -------------------------------------------------------------------- * activate recursive: activate selected and sub nodes */ var httpReq=this.getHttpRequest(); if (httpReq) { var paramString = "treeMode=snippet"; paramString+="&path="+this.path; paramString+="&browseMode="+this.tree.browseMode; paramString+="&mgnlCK="+mgnlGetCacheKiller(); for (var elem in params) { if (params[elem] || params[elem]=="0") { // ="0": createItemType; MAGNOLIA_NODE_DATA is 0 paramString+="&"+encodeURIComponent(elem)+"="+encodeURIComponent(unescape(params[elem])); //values seems to be passed escaped ... } } mgnlDebug("node.httpRequest: paramString: " + paramString, "tree"); // paramters need to be passed in body to allow utf8 encoding (query string is always ISO-88591) mgnlDebug("node.httpRequest: url: " + this.url, "tree"); httpReq.open("POST",encodeURI(this.url),true); httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); // register handler after the the request called after the request returned httpReq.onreadystatechange=function() { if (httpReq.readyState==4) { var returnText=httpReq.responseText; callback(callBackParams, returnText); } } httpReq.send(paramString); return; } else return; } mgnlTreeNode.prototype.shift = function() { var shifter=document.getElementById(this.shifterId); if (shifter && shifter.src.indexOf("EMPTY")==-1) { var divSub=document.getElementById(this.divSubId); if (divSub.style.display=="none") this.expand(); else this.collapse(); } } mgnlTreeNode.prototype.collapse = function() { mgnlDebug('node.collapse','tree'); var divSub=document.getElementById(this.divSubId); if (divSub.style.display!="none") { divSub.style.display="none"; var shifter=document.getElementById(this.shifterId); if (shifter) shifter.src=shifter.src.replace("COLLAPSE","EXPAND"); if (this.tree.selectedNode.id.indexOf(this.id+"/")==0) { this.tree.selectedNodeReset(); } } } mgnlTreeNode.prototype.expand = function(params) { mgnlDebug('node.expand','tree'); /* * params is object of key/value pairs * see mgnlTreeNode.prototype.httpRequest */ if (!params) params=new Object(); var shifter=document.getElementById(this.shifterId); var divSub=document.getElementById(this.divSubId); if (!params.forceReload && shifter && shifter.src.indexOf("EMPTY")!=-1) return; if (params.forceReload || (divSub && divSub.style.display=="none")) { //todo: find out, why divSub is not available always ... if (divSub) divSub.style.display="block"; if (shifter) shifter.src=shifter.src.replace("EXPAND","COLLAPSE"); if (params.forceReload || divSub.innerHTML=="") { var left=0; if (document.getElementById(this.idPre+"_Column0Main")) { left=parseInt(document.getElementById(this.idPre+"_Column0Outer").style.paddingLeft); if (left) left+=30; else left=30; } //todo: find out, why divSub is not available always ... if (divSub) divSub.innerHTML="
"+this.tree.strings.loading+"
"; this.params=params; setTimeout("mgnlTreeDrawNodes('"+this.id+"','"+this.treeName+"');",10); } } } mgnlTreeDrawNodes = function (id,treeName) { var div=document.getElementById(treeName+"_"+id+"_DivSub"); var tree=eval(treeName); var node=tree.getNode(id); var params=node.params; if (!params) params=new Object(); var callBackParams=new Object(); callBackParams.id = id; callBackParams.treeName = treeName; mgnlDebug('mglnTreeDrawNodes with treeName: ' + treeName, "tree"); mgnlDebug('mglnTreeDrawNodes used params', "tree", params); mgnlDebug('mglnTreeDrawNodes used callBackParams', "tree", callBackParams); node.httpRequest(params, callBackParams, mgnlTreeDrawNodesCallback); } /** callback **/ mgnlTreeDrawNodesCallback = function (params, html) { var id = params.id; var treeName = params.treeName; var div=document.getElementById(treeName+"_"+id+"_DivSub"); var tree=eval(treeName); if (div) div.innerHTML=html; if (id==tree.path){ //reset tree tree.nodes=new Object(); tree.selectedNode=tree.getNode(tree.path); tree.clipboardNode=null; tree.clipboardMethod=null; } html = mgnlAlertCallbackMessage(html); var selectPath=params.pathSelected; var selectNodePattern='")); tmp=tmp.replace(selectNodePattern,""); if (tmp!="") selectPath=tmp; } if (selectPath) { mgnlDebug('selectPath: ' + selectPath, "tree") //tree.selectNode(tree.path); tree.selectNode(selectPath); } if (html=="") { var shifter=document.getElementById(tree.nodes[id].shifterId); if (shifter) { shifter.src=shifter.src.replace("COLLAPSE","EMPTY") } } } function mgnlAlertCallbackMessage(html){ var messagePattern='", start); var msg = html.slice(start + messagePattern.length, end); alert(msg); html = html.slice(end); } return html; }/* ################################### ### contextmenu.js ################################### */ /* ################################### ### ContextMenu Class ################################### */ /* ################################### ### Constructor ################################### */ function mgnlContextMenu(name){ this.divMenu=document.getElementById(name+"_DivMenu"); this.menuItems=new Array(); this.colors=new Object(); this.colors.menuHighlight="#F0F2E6"; // true if this is keep showing this.showing = false; if(!this.divMenu){ alert('no div for the context [' + name + '] menu found'); } } mgnlContextMenu.prototype.show = function(event){ if (this.divMenu) { //todo: (hack) find out height/width of div var divMenuHeight=0; var divMenuWidth=150; for (var i=0;i'); //denied: denied sign document.write('
'); //allowed: text 'Move above here' document.write(''); var mgnlMoveDont=false; //move will not start as long as mgnlMoveDont is true //set true when clicking a button on a editBar ((and on timeout at mgnlMoveReset())) //var mgnlMove=false; //true as long as a container is selected // -> moved to general.js function mgnlMoveNodeStart(containerList,container,barId) { if (!mgnlMoveDont && !mgnlMove) { var bar=document.getElementById(barId); mgnlMoveNodeSetClassName(bar,"PUSHED"); //var tmp=bar.id.split('__'); mgnlMoveNodeCollection=containerList; mgnlMoveNode=container; var divShadow=document.getElementById('mgnlMoveDivShadow'); divShadow.style.visibility='visible'; var divDenied=document.getElementById('mgnlMoveDivDenied'); var divAllowed=document.getElementById('mgnlMoveDivAllowed'); if (divAllowed.style.visibility=='hidden') divDenied.style.visibility='visible'; // only if new selection mgnlMove=true; } } function mgnlMoveNodeSetClassName(bar,state) { if (!state) state="NORMAL"; var base=bar.className; if (base.indexOf("_")!=-1) base=base.substring(0,base.indexOf("_")); if (state=="NORMAL") bar.className=base; else if (state=="PUSHED") bar.className=base+"_PUSHED"; else if (state=="MOUSEOVER") bar.className=base+"_MOUSEOVER"; } function mgnlMoveNodeHigh(bar) { var tmp=bar.id.split('__'); if (mgnlMove) { if (tmp[0]==mgnlMoveNodeCollection && tmp[1]!=mgnlMoveNode) { //same container list and not the container to move: highlight this bar mgnlMoveNodeSetClassName(bar,"MOUSEOVER"); var divDenied=document.getElementById('mgnlMoveDivDenied'); divDenied.style.visibility='hidden'; var divAllowed=document.getElementById('mgnlMoveDivAllowed'); divAllowed.style.visibility='visible'; } } } function mgnlMoveNodeReset(bar) { tmp=bar.id.split('__'); if (mgnlMove) { if (tmp[0]==mgnlMoveNodeCollection) { //same containre list if (tmp[1]!=mgnlMoveNode) { //not the container to move: reset this bar mgnlMoveNodeSetClassName(bar,"NORMAL"); } var divDenied=document.getElementById('mgnlMoveDivDenied'); divDenied.style.visibility='visible'; var divAllowed=document.getElementById('mgnlMoveDivAllowed'); divAllowed.style.visibility='hidden'; } } } function mgnlMoveNodeEnd(bar,path) { if (mgnlMove) { var tmp=bar.id.split('__'); if (mgnlMoveNodeCollection==tmp[0] && mgnlMoveNode!=tmp[1]) { //same container list and not container to move mgnlMoveNodeSetClassName(bar,"PUSHED"); var href=document.location.href; var pathSelected=path+"/"+mgnlMoveNodeCollection+"/"+mgnlMoveNode; var pathSortAbove=path+"/"+mgnlMoveNodeCollection+"/"+tmp[1]; //'MoveNodeCollection='+mgnlMoveNodeCollection+'&MoveNode='+mgnlMoveNode+'&MoveNodeAbove='+tmp[1]+'&path='+path+'&actions=moveNode'; //var href='/.CMSadmin/tagRequestHandler.html?MoveNodeCollection='+mgnlMoveNodeCollection+'&MoveNode='+mgnlMoveNode+'&MoveNodeAbove='+tmp[1]+'&path='+path+'&actions=moveNode'; href=mgnlUpdateCK(href) href=mgnlRemoveParameter(href,"mgnlIntercept"); href=mgnlAddParameter(href,"mgnlIntercept","NODE_SORT"); href=mgnlRemoveParameter(href,"mgnlPathSelected"); href=mgnlAddParameter(href,"mgnlPathSelected",pathSelected); href=mgnlRemoveParameter(href,"mgnlPathSortAbove"); href=mgnlAddParameter(href,"mgnlPathSortAbove",pathSortAbove); document.location.href=href; } } } /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ // we can not use package command yet: make sure that the var mgnl exists var mgnl = mgnl ? mgnl : new Object(); // used to set the browser flags var agent = navigator.userAgent.toLowerCase() ; /** * This is the main class which must be loaded to use the importClass method. */ MgnlRuntime = mgnl.Runtime = { /** * This flag is false if all classes are loaded in one file in a final version. */ loadingOn: true, /** * If one script is loading synchronized. The others mast load synchronized too. */ loadSynchronized: false, /** * Remember allready loaded scripts (do not load twice) */ loaded: new Object(), /** * Check the browser */ isIE : ( agent.indexOf("msie") != -1 ), isGecko : !( agent.indexOf("msie") != -1 ), // Firefox and others isSafari : ( agent.indexOf("safari") != -1 ), isNetscape : ( agent.indexOf("netscape") != -1 ), /** * Creates the package object structure if not yet existing and register the class. * @param name the full name (including the class name) * @param superKlass (optional) the supper class or an object used as prototype * @param klass a constructor or an object defining the class * @param members (optional) an object containing the members (methods/properties) * @param statics (optional) an object containing the static members */ classDef: function(name, superKlass, klass, members, statics ){ var names = name.split("."); var current = window; // if super was not passed change the parameters if(arguments.length <= 2 || typeof klass != "function"){ statics = members; members = klass; klass = superKlass; superKlass = null; } if(superKlass){ // if this is a constructor if(typeof superKlass == "function"){ klass.superKlass = superKlass; // clone prototype of the supper for (var property in klass.superKlass.prototype) { klass.prototype[property] = klass.superKlass.prototype[property]; } // add nice shortcut to call the super method(s) klass.prototype.parentConstructor = function(){ // remember latest constructor to follow the chain var superKlass = klass.superKlass; if(this.nextSuperKlass){ superKlass = this.nextSuperKlass; } this.nextSuperKlass = superKlass.superKlass; superKlass.apply(this, arguments); } } // in case this is an object else{ klass.prototype = superKlass; } } // create package structure for(i=0; i * Pest practise *
    *
  • load scripts in the header *
  • start using them in the onload method *
* @see the load functions documentation */ importClass: function(name, sync){ var names = name.split("."); var className = names[names.length-1]; if(!this.existVariable(name)){ if(this.loadingOn){ var url = name.replace(/\./g,"/"); // load the script and set the shortcut after the script is loaded this.load(contextPath + "/admindocroot/js/classes/" + url + ".js", sync, function(){ window["Mgnl" + className] = eval(name); } ); } else{ alert('not imported class [' + name + ']'); } } // make sure that the shortcut exists else{ window["Mgnl" + className] = eval(name); } }, /** * Checks savely if this variable exists or not. */ existVariable: function(name){ try{ var test = eval(name); if(test != null){ return true; } } catch(e){ } return false; }, /** * This method loads a script dynamically. Set sync only to true if you load * a script after the page was loaded. If you load scripts in the header you * and use them after the onload event is fired (in the onload method for example) * you can savely load in the faster async mode. * * @param url the url to load (must be a javascript) * @param sync true if the method should wait until the script was loaded (optional) * @param callback the method called after async call (optional) */ load: function(url, sync, callback){ if(this.loaded[url] == null){ // do not load twice, but is not yet loaded this.loaded[url]=false; // if this is a synchronized call we must synchronize until this is finished var oldSynchronization; if(sync){ oldSynchronization = this.loadSynchronized; this.loadSynchronized = true; } else{ sync = this.loadSynchronized; } this.debug("load " + url + "(snc: " + sync + ")"); // save this for the follwing function var myRuntime = this; // create the function called after the script is loaded var onLoad = function(){ myRuntime.loaded[url] = true; // set to the original mode again if(oldSynchronization != null){ myRuntime.loadSynchronized = oldSynchronization; } // call callback function if(callback){ callback(); } } // in safari we must make a sync AJAX call // ie does not give a onload event if the page is already loaded // therfore we make a AJAX call if the page was loaded if(sync || this.isSafari || (this.isIE && document.readyState == "complete")){ var xmlRequest; if(this.isIE){ try{ xmlRequest = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e){ xmlRequest = new ActiveXObject('Microsoft.XMLHTTP'); } } else{ xmlRequest = new XMLHttpRequest() ; } // Load the script synchronously. xmlRequest.open( "GET", url, false ) ; xmlRequest.send( null ) ; // Evaluate the script. if ( xmlRequest.status == 200 ){ try{ eval( xmlRequest.responseText ) ; onLoad(); } catch ( e ){ alert( 'Error parsing ' + url + ': ' + e.message ) ; } } else{ alert( 'Error loading ' + url ) ; } } // async load else{ var e = document.createElement("script"); e.src = url; e.type="text/javascript"; e.onload = e.onreadystatechange = function (){ // Gecko doesn't have a "readyState" property if ( !this.readyState || this.readyState == 'loaded' ){ onLoad(); } } document.getElementsByTagName("head")[0].appendChild(e); } } }, /** * Cache for not yet printed messages */ notYetDebuged: new Array(), /** * Debug the message. Check if the debug class is already loaded. If not cache. */ debug: function(msg, o ,level){ if(window.MgnlDebug){ if(notYetDebugged.length>0){ for(i=0; i < notYetDebugged.length; i++){ MgnlDebug.debug(notYetDebuged[i].msg, this, notYetDebuged[i].o, notYetDebuged[i].level); } notYetDebugged = new Array(); } MgnlDebug.debug(msg, this, o, level); } else{ notYetDebuged.append({msg: msg, o:o, level:level}); } } }; // define shortcuts: the wrapping function is used to save the this variable classDef = function(name, superKlass, klass, members, statics){mgnl.Runtime.classDef(name, superKlass, klass, members, statics)}; importClass = function(name, sync){mgnl.Runtime.importClass(name,sync)}; // define this class properly classDef("mgnl.Runtime", MgnlRuntime); MgnlRuntime.loadingOn=false; /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.dms.DMS", { searchView: false, // this variable is used by the context menu selectedPath: "", selectedIsFolder: false, // this is the object used in the context menu to check the flag selectedIsNotFolderCondition:{test: function() {return !mgnl.dms.DMS.selectedIsFolder}}, show : function(path){ mgnlOpenWindow(".magnolia/dialogs/dmsEdit.html?mgnlPath=" + path + "&mgnlRepository=dms"); }, createNew: function(path){ mgnlOpenWindow(".magnolia/dialogs/dmsEdit.html?mgnlPath=" + path + "&mgnlNode=mgnlNew&mgnlRepository=dms"); }, // check if it is a folder showDialogInTree: function(tree){ if(tree.selectedNode.itemType=="mgnl:contentNode"){ mgnlTreeMenuOpenDialog(tree,'.magnolia/dialogs/dmsEdit.html'); } }, showVersions: function(path){ mgnl.admininterface.VersionsList.show('dms', path); }, restoreVersion: function(path, name){ window.location = contextPath +"/.magnolia/dms/versions.html?mgnlCommand=restore&mgnlPath=" + path + "&mgnlVersion=" + name; }, showVersion: function(path, name){ mgnlOpenWindow(".magnolia/dialogs/dmsEdit.html?mgnlPath=" + path + "&mgnlRepository=dms&mgnlVersion=" + name); }, downloadFile: function(path){ document.location = contextPath + "/dms" + path; }, reloadAfterEdit: function(path){ if(!mgnl.dms.DMS.searchView){ document.location = contextPath + "/.magnolia/trees/dms.html?mgnlCK=" + mgnlGetCacheKiller() + "&pathSelected=" + path; } else{ document.location.reload(); } }, showInTree: function(path){ MgnlAdminCentral.showTree('dms', path); }, showTree: function(){ top.mgnlAdminCentralSwitchExtractTree('dms'); }, simpleSearch: function(val){ if(document.mgnlForm && document.mgnlForm.searchStr){ if(document.mgnlForm.searchAdvanced){ document.mgnlForm.searchAdvanced.value = "false"; } document.mgnlForm.searchStr.value = val; document.mgnlForm.submit(); } else{ document.location = contextPath + '/.magnolia/pages/dmsSearchList.html?searchStr=' +val; } }, uploadZip: function(path){ mgnlOpenWindow(".magnolia/pages/dmsZipUpload.html?path=" + path); } }); /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ /** * */ classDef("mgnl.admininterface.VersionsList", function(onShowItem){ /** * The current selected items version label */ this.currentVersionLabel = null; /** * The function called to show the lists item */ this.onShowItem = onShowItem; this.restore = function(versionLabel){ versionLabel = versionLabel==null ? this.currentVersionLabel : versionLabel; document.mgnlForm.command.value="restore"; document.mgnlForm.versionLabel.value=versionLabel; document.mgnlForm.submit(); }; this.showItem = function(versionLabel){ versionLabel = versionLabel==null ? this.currentVersionLabel : versionLabel; // on show must be set by the user of this class onShowItem(versionLabel); }; }); /** * Show versions of a page */ mgnl.admininterface.VersionsList.show = function(repository, path){ url = "/.magnolia/pages/" + repository + "VersionsList.html"; url = MgnlURLUtil.addParameter(url, "repository", repository); url = MgnlURLUtil.addParameter(url, "path", path); mgnlOpenWindow(url, 1000, 600); }; /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ importClass("mgnl.admininterface.VersionsList"); classDef("mgnl.admininterface.WebsiteTree", { showVersions: function(tree){ mgnl.admininterface.VersionsList.show('website', tree.selectedNode.path); }, search: function(value){ document.location = contextPath +"/.magnolia/pages/websiteSearchList?searchStr=" + value; } }); /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.controls.FunctionBar", MgnlFunctionBar); MgnlFunctionBar.classActive = 'mgnlFunctionBarButton'; MgnlFunctionBar.classInactive = 'mgnlFunctionBarButtonInactive'; function MgnlFunctionBar (name, active, iconActive, iconInactive, onClick) { var parent = null; var nodes = new Array (); var img = null; var td = null; var div = null; var conditions = new Array (); this.addNode = function (name, active, iconActive, iconInactive, onClick) { var n = new MgnlFunctionBar (name, active, iconActive, iconInactive, onClick); n.setParent (this); nodes.push (n); } this.refresh = function () { if (parent != null) { // div must be present, img not necesseraly if (div == null) { td = document.getElementById (this.getFullName ()); div = document.getElementById (this.getFullName () + '_div'); img = document.getElementById (this.getFullName () + '_img'); } // determine the items state using javascript conditions active = true; for (var i = 0; i < conditions.length; i++) { //var condition = eval (conditions[i]); condition = conditions[i]; var testResult; if(typeof condition == "function"){ testResult = condition(); } else{ testResult = condition.test(); } active = (active && testResult); } // set icon and css-class corresponding to the nodes state if (active) { if (img) img.src = iconActive; td.className = MgnlFunctionBar.classActive; } else { if (img) img.src = iconInactive; td.className = MgnlFunctionBar.classInactive; } } for (var i = 0; i < nodes.length; i++) { nodes[i].refresh (); } } this.getName = function () { return name; } this.getParent = function () { return parent; } this.setParent = function (p) { parent = p; } this.getFullName = function () { if (parent != null) { return (parent.getFullName () + '_' + this.getName ()); } else return this.getName (); } this.getNode = function (nodeName) { var n = this.getNodes (); if (this.getName () == nodeName) return this; for (var i = 0; i < n.length; i++) { var ret = n[i].getNode (nodeName); if (ret) return ret; } return null; } this.getNodes = function () { return nodes; } this.setActive = function (nodeName, state) { if (this.getName () == nodeName) { active = state; } else { var n = this.getNode (nodeName); if (n) n.setActive (nodeName, state); } } this.isActive = function () { return active; } this.getOnClick = function () { return onClick; } this.addCondition = function (condition) { conditions.push (condition); } this.clicked = function (nodeName) { var n = this.getNode (nodeName); // only execute if node is found and node is active if (n && n.isActive ()) { var c = n.getOnClick (); if (c) { var f = new Function ('a ', c + ''); f(); } } } } /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.util.Debug", { /** * True if the debuggin is working */ on: false, /** * the context which can be switched on and of */ contextes : { "mgnl.Runtime": true, tree: true, dialog: true, acl: true, debug: true }, debug: function(msg, context, o, level){ if(!this.on) return; if(!level) level = 1; if(context && context._class) context=context._class; // is the context in debug mode? if(context != null && (this.contextes[context] == null || !this.contextes[context])) return; var console = this.getRootWindow().mgnlDebugConsole; var doc = null; // create new window if not allready done if(console == null){ console = window.open('','mgnlDebugConsole'); this.getRootWindow().mgnlDebugConsole = console; doc = console.document; doc.write('

'); doc.write('

'); doc.write('
'); doc.close(); // reset the focus window.focus(); } else{ doc = console.document; } if(doc == null) return; // get the div to write in var div = doc.getElementById('consoleDiv'); if(o){ msg += ":" + this.debugObject(o, level, ""); } if(context != null) msg = context + ": " + msg; div.appendChild(doc.createTextNode(msg)); div.appendChild(doc.createElement("br")); }, /** * Write out the objects values * @obj the object to debug * @param level level of recursion (default is 1) * @spaces used for the recursion to shift the content */ debugObject: function(o, level, spaces){ var res = ""; switch(typeof o){ case "object": if(level<=0) return "object"; res = "
" + spaces + "{
"; for(var key in o){ if(!res.match(/\{
$/)) res += ",
"; res += spaces + "   " + key + ":"; res += this.debugObject(o[key], level-1, spaces + "   "); } res += "
" + spaces + "}"; break; case "function": return "function" break; default: return o; } return res; }, /** * Copied from the dhtml util to avoid dependencies */ getRootWindow: function(current){ current = current?current:window; if(current.top != current) return this.getRootWindow(current.top); if(current.opener != null) return this.getRootWindow(current.opener); return current; } }); classDef("mgnl.dms.VersionCommentPopup", { checkEnter: false, show: function(){ var txt = document.getElementById("commentPopUpTextArea"); var div = document.getElementById("commentPopUpDiv"); var blockInputDiv = document.getElementById("blockInputDiv"); txt.value=""; div.style.left = mgnlGetWindowSize().w/2-div.clientWidth/2; div.style.top = mgnlGetWindowSize().h/2-div.clientHeight/2; div.style.visibility = "visible"; blockInputDiv.style.width = mgnlGetWindowSize().w; blockInputDiv.style.height = mgnlGetWindowSize().h; blockInputDiv.style.visibility = "visible"; this.checkEnter=true; }, save: function(){ var txt = document.getElementById("commentPopUpTextArea"); var hidden = document.getElementById("versionComment"); hidden.value=txt.value; mgnlDialogFormSubmit(); }, cancel: function(){ var div = document.getElementById("commentPopUpDiv"); var blockInputDiv = document.getElementById("blockInputDiv"); div.style.visibility = "hidden"; blockInputDiv.style.visibility = "hidden"; }, keyDown: function(e) { var evt=(e)?e:(window.event)?window.event:null; if(evt){ var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); if(this.checkEnter && key==13) { this.save(); } } } }); /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ /** * Functions to handle the js in the website search result */ classDef("mgnl.admininterface.WebsiteSearchList", { selected: null, search: function(value){ $('searchStr').value = value; document.mgnlForm.submit(); }, show: function(){ var url= contextPath + this.selected + ".html"; var w = window.open(url, "mgnlInline", ""); if (w) w.focus(); }, navigate: function(){ MgnlAdminCentral.showTree('website', this.selected); } }); /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.controls.ListColumn", function (list, width, index){ this.list = list; this.index = index; this.fixed; this.width; this.cssClass = mgnl.util.DHTMLUtil.getCSSClass(list.name + "CssClassColumn" + index); this.line = $(list.name + "ColumnLine" + index); this.resizer = $(list.name + "ColumnResizer" + index); this.list.columns[index] = this; if(width.indexOf("px")!=-1){ this.width = parseInt(width.substr(0, width.length-2)); this.fixed=true; } else{ this.width = parseInt(width); this.fixed=false; } this.resize = function(left, width){ this.cssClass.style.left = left + "px"; this.cssClass.style.width = width; this.cssClass.style.clip="rect(0 " + width + " 20 0)"; if(this.resizer){ this.resizer.style.left = left + "px"; } if(this.line){ this.line.style.left = (left + 5) + "px"; this.line.style.height = (this.list.height - 20) + "px"; } this.width = width; this.left = left; } }); /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.controls.List", // contstuctor function(name, form){ this.name = name; this.form = form; // the row of the list this.selected = -1; this.mainDiv = $(name + "Div"); this.sortGroupDiv = $(name + "SortGroupDiv"); this.contentDiv = $(name + "ContentDiv"); this.innerContentDiv = $(name + "InnerContentDiv"); this.resizerLine = $(name + "ColumnResizerLine"); this.columns = new Array(); this.items = new Object(); }, // members { // css classes used css: { row:{ selected: 'mgnlListRowSelected', hover: 'mgnlListRowHover', normal: 'mgnlListRow' } }, addColumn: function(column){ this.columns.push(column); }, select: function(index, id){ this.unselect(); this.selected = index; var row = $(this.name + 'Row' + this.selected); row.className = this.css.row.selected; // refresh function bar if any if(window["mgnlFunctionBar"]){ window["mgnlFunctionBar"].refresh(); } }, unselect: function(){ if(this.selected == -1) return; var row = $(this.name + 'Row' + this.selected); row.className= this.css.row.normal; this.selected = -1; }, show: function(){ alert(this.getSelectedItem().id); }, getSelectedItem: function(){ return this.items[this.selected]; }, startResizeColumn: function(index){ this.resizerLine.style.visibility="visible"; this.resizerLine.style.left = this.columns[index].left + 5; this.resizerLine.style.height = this.height; var list = this; this.contentDiv.onmousemove = function(event){ list.onResizeColumn(event, index); }; this.contentDiv.onmouseup = function(event){ list.stopResizeColumn(event, index); }; mgnl.util.Debug.debug("start column resizing"); }, onResizeColumn: function(event, index){ var pos = mgnl.util.DHTMLUtil.getMousePos(event); this.resizerLine.style.left = pos.x-1; }, stopResizeColumn: function(event, index){ var newLeft = mgnl.util.DHTMLUtil.getMousePos(event).x -6; var column = this.columns[index]; column.resize(newLeft, column.width + (column.left - newLeft)); // resize also column to the left if(index >= 1){ column = this.columns[index-1]; column.resize(column.left, newLeft -column.left); } this.resizerLine.style.visibility="hidden"; this.contentDiv.onmousemove = null; this.contentDiv.onmouseup = null; mgnl.util.Debug.debug("stop column resizing"); }, mouseover: function(id){ if(id != this.selected){ var row = $(this.name + 'Row' + id); row.className= this.css.row.hover; } }, mouseout: function(id){ if(id != this.selected){ var row = $(this.name + 'Row' + id); row.className= this.css.row.normal; } }, resize: function(){ this.height = MgnlDHTMLUtil.getHeight(this.mainDiv); this.width = MgnlDHTMLUtil.getWidth(this.mainDiv); if(this.sortGroupDiv){ var sortWidth = MgnlDHTMLUtil.getWidth(this.sortGroupDiv); this.sortGroupDiv.style.left = this.width - sortWidth + "px"; this.sortGroupDiv.style.height = this.height -1 + "px"; this.sortGroupDiv.style.visibility = "visible"; this.width -= sortWidth; } MgnlDebug.debug("new total widht:" + this.width, this); MgnlDHTMLUtil.setWidth(this.contentDiv, this.width); MgnlDHTMLUtil.setHeight(this.contentDiv, this.height); this.innerContentDiv.style.height = this.height - 20; // columns var factor = this.getWidthFactor(this.width); MgnlDebug.debug("factor is:" +factor, this); left=0; for(i=0; i< this.columns.length;i++){ var column = this.columns[i]; var newColumnWidth; if(column.fixed){ newColumnWidth = column.width; } else{ newColumnWidth = factor * column.width; } column.resize(left, newColumnWidth) left += newColumnWidth; // next start } }, /** * Calculate the factor to use for resizing the dynamic columns. */ getWidthFactor: function(){ var sum = 0; var fixSum = 0; for(i=0; i=0; elem0--) { var rules=document.styleSheets[elem0][rulesKey]; //for (var elem1 in rule) //does not work in firebird 0.8, safari 1.2 for (var elem1=0; elem10) { if (!usePathAsRoot) { url += "?pathSelected="+path +"&pathOpen="+path; } else { url += "?pathSelected="+path +"&pathOpen="+path+"&path="+path; } } this.showContent(url, false, false); } } /** * Set this method to execute after the admin central is opened in a new window */ MgnlAdminCentral.onOpenedInNewWindow = null; /** * Open the admin central in a new window (used for example for the admin central button in the templates) */ MgnlAdminCentral.openInNewWindow = function(onOpenedInNewWindow){ src = contextPath + "/.magnolia/adminCentral.html"; src = MgnlURLUtil.addCacheKiller(src); w = window.open(src,"mgnlAdminCentral",""); MgnlAdminCentral.onOpenedInNewWindow = onOpenedInNewWindow; if (w) { w.focus(); } return w; } /** * Some static methods useabe from everywhere. */ MgnlAdminCentral.showTree = function(name, path, usePathAsRoot){ mgnlAdminCentral = MgnlDHTMLUtil.findVariable("mgnlAdminCentral") if(mgnlAdminCentral){ mgnlAdminCentral.showTree(name, path, usePathAsRoot); mgnlAdminCentral.window.focus(); } else{ this.openInNewWindow(function(mgnlAdminCentral){ mgnlAdminCentral.showTree(name, path, usePathAsRoot); // remove the handler again MgnlAdminCentral.onOpenedInNewWindow = null; }); } } MgnlAdminCentral.showContent = function(url, border, scrolled){ MgnlDHTMLUtil.findVariable("mgnlAdminCentral").showContent(url, border, scrolled); } /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.controls.TextField", MgnlTextField); function MgnlTextField(name, value, width, imageLeft, imageLeftWidth, attributes){ this.attributes = attributes!=null?attributes:{}; this.name = name; this.value = value; if (width == undefined) { this.width = 150; } else { this.width = width; } if (imageLeft == undefined) { this.imageLeft = contextPath + '/.resources/controls/textfield/left.gif'; this.imageLeftWidth = 5; } else { this.imageLeft = imageLeft;this.imageLeftWidth = (imageLeftWidth == undefined ? '20' : imageLeftWidth); } this.widthSearchField = this.width - (5 + this.imageLeftWidth); // register control MgnlTextField.prototype.all[this.name] = this; } MgnlTextField.prototype.render = function() { // create other attributes var attributes=""; for(name in this.attributes){ attributes += " " + name + '="' + this.attributes[name] + '"'; } if (window.navigator.userAgent.indexOf("Safari") == -1) { var html = ''; html += '' html += ''; html += ''; html += '
' html += '
' } else { var html = ''; } return html } // collection of all instantiated controls MgnlTextField.prototype.all = new Object(); /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ /** * A util to manage the prototypes in javascripts. Used to extend allready existing prototype for example. */ classDef("mgnl.util.PrototypeUtil",{ /** * Add the properties from src to dest. * extend(obj.prototype, myOtherParent) * @parma dst the target * @parma src the object whichs properties will get copied to dst * @parma overwrite true if existing properties get overwritten (default is true) */ extend: function(dst, src, overwrite){ // default is false overwrite = overwrite?overwrite: false; for(name in src){ if(overwrite || dst[name] == null){ dst[name] = src[name]; } } return dst; } }); /** * MgnlNavigation * creates a hierarchical menu * Usage: * include this file in any html/xhtml file * link the corresponding css file * * create navigation: * mgnlNavigation = new MgnlNavigation (); * * add a node: * mgnlNavigation.addNode ('node1', 'Website', 'alert (\'blau\');', './.resources/icons/24/earth.gif'); * Parameters for addNode: * id: the nodes id (must be unique!) * title: the txt to display * action: javascript function as string * icon: path to the icon shown on the left * * add a subnode: * mgnlNavigation.getNode ('node1').addNode ('node11', 'Test', '', './.resources/icons/16/folder.gif'); * * to activate a node from wherever (without a user's click) without triggering its action: * mgnlNavigation.activate ('node2346'); * * to activate a node from wherever (without a user's click) and execute its action: * mgnlNavigation.activate ('node2346', true); * */ classDef("mgnl.admininterface.Navigation", MgnlNavigation); /** * static variables */ // path to the images MgnlNavigation.imagesPath = contextPath + "/.resources/controls/navigation/"; // path to the expandable-icon on the left MgnlNavigation.openIcon = MgnlNavigation.imagesPath + 'mgnlNavigationArrow.gif'; // specify animation step speed in milliseconds MgnlNavigation.navTimeoutOpen = 30; MgnlNavigation.navTimeoutClose = 20; /** * Parameters: * id: the nodes id (must be unique!) * title: the txt to display * action: javascript function as string * icon: path to the expandable-icon on the left * parent: either MgnlNavigation or MgnlNavigationNode * depth: int */ function MgnlNavigation (id, title, action, icon, parent, depth) { // holds all top-level navigation nodes var nodes = new Array (); // holds all open nodes, i.e. where the children are shown var openNodes = new Array (); // holds all nodes where mouse is moved over var hoverNodes = new Array (); // holds the currently selected/clicked node var activeNode = null; // background: the table-element in the dom-tree, this holds the background color/image that reacts on mouse-events var background = null; // whether the menu is opened or not, i.e. children visible or hidden. var isOpen = false; // obvious getters and setters this.getDepth = function () { if (depth) return depth; else return 0; } this.getId = function () { return id; } this.getTitle = function () { return title; } this.getIcon = function () { return icon; } this.hasIcon = function () { return (icon ? true : false); } this.getParent = function () { return parent; } /** * adds a navigation node * Parameters: * id: the nodes id (must be unique!) * title: the txt to display * action: javascript function as string * icon: path to the icon shown on the left */ this.addNode = function (id, title, action, icon) { // only add node if there is no such id yet if (!this.getNavigation ().getNode (id)) nodes[nodes.length] = new MgnlNavigation (id, title, action, icon, this, this.getDepth () + 1); } this.hasNodes = function () { return (nodes.length > 0); } this.getNodes = function () { return nodes; } this.getNode = function (id) { var n = this.getNodes (); if (this.getId () == id) return this; for (var i = 0; i < n.length; i++) { var ret = n[i].getNode (id); if (ret) return ret; } return null; } // open the menu tree this.showChildren = function () { // nothing to do on top-level if (this.getDepth () > 0) { this.closeOpenNodes (this); if (!isOpen) { if (this.hasNodes ()) { // hide all children // and set show timeout for animation if (MgnlNavigation.navTimeoutOpen && 1 * MgnlNavigation.navTimeoutOpen > 0) { if (c = this.background.parentNode.nextSibling.firstChild) { var n = this.getNodes (); var i = 0; do { c.style.display = 'none'; window.setTimeout ('document.mgnlNavigationSelf.showChild (\'' + n[i++].getId () + '\')', i * MgnlNavigation.navTimeoutOpen); } while (c = c.nextSibling); } } // display wrapper this.background.parentNode.nextSibling.style.display = 'block'; } this.addOpenNode (this); isOpen = true; } } } // close the menu tree this.hideChildren = function () { // nothing to do on top-level if (this.getDepth () > 0) { if (isOpen) { if (MgnlNavigation.navTimeoutClose && 1 * MgnlNavigation.navTimeoutClose > 0) { var n = this.getNodes (); for (var i = 0; i < n.length; i++) { // pretty animation... window.setTimeout ('document.mgnlNavigationSelf.hideChild (\'' + n[i].getId () + '\')', (i + 1) * MgnlNavigation.navTimeoutClose); } } // display wrapper else this.background.parentNode.nextSibling.style.display = 'none'; } isOpen = false; } } // open/close menus // these two functions are used in animation, they get called asynchronously this.showChild = function (idShow) { if (n = this.getNode (idShow)) n.background.parentNode.parentNode.style.display = 'block'; } this.hideChild = function (idHide) { if (n = this.getNode (idHide)) { n.background.parentNode.parentNode.style.display = 'none'; // if this is the last child hide the wrapper too if (!n.background.parentNode.parentNode.nextSibling) { n.background.parentNode.parentNode.parentNode.style.display = 'none'; } } } // changes the css-styles of the node this.setStyle = function (style) { // nothing to do on top-level if (style.length > 0) { style = style.charAt (0).toUpperCase () + style.substring (1, style.length); if (this.getDepth () > 0) { // apply styles if (this.background) this.background.className = 'mgnlNavigation' + this.getDepth () + style; if (this.hasNodes ()) { var n = this.getNodes (); if (n[0].background) n[0].background.parentNode.parentNode.parentNode.className = 'mgnlNavigationWrapper' + (this.getDepth () + 1) + style; } } } } // returns the navigationobject itself this.getNavigation = function () { // only do it on top-level-parent if (parent) return parent.getNavigation (); else return this; } // adds the node to the hoverNodes array this.addHoverNode = function (n) { // only do it on top-level-parent if (parent) parent.addHoverNode (n); else { var exists = false for (var i = 0; i < hoverNodes.length; i++) if (hoverNodes[i] == n) exists = true; if (!exists) hoverNodes.push (n); } } // used to reset the hover css style // loops through the hoverNodes array and calls mouseout if it's not the active node this.removeHoverNodes = function () { // only do it on top-level-parent if (parent) parent.removeHoverNodes (); else { for (var i = 0; i < hoverNodes.length; i++) { if (this.getActiveNode () == null || this.activeNode != hoverNodes[i]) { hoverNodes[i].mouseOut (); hoverNodes.splice (i, 1); } } } } // adds a node to the openNodes array this.addOpenNode = function (n) { // only do it on top-level-parent if (parent) parent.addOpenNode (n); else { var exists = false for (var i = 0; i < openNodes.length; i++) if (openNodes[i] == n) exists = true; if (!exists) openNodes.push (n); } } // loops through the openNodes array and closes all nodes with greater depth expect for the given one this.closeOpenNodes = function (n) { // only do it on top-level-parent if (parent) parent.closeOpenNodes (n); else { for (var i = 0; i < openNodes.length; i++) { // close them if they are less deep or a child if (openNodes[i].getDepth () >= n.getDepth () || n.getNode (openNodes[i].getId ())) { // only close it if it's NOT a parent of the active node if (openNodes[i].getNode (n.getId ()) == null) { openNodes[i].hideChildren (); openNodes.splice (i); } } } } } // the node that was clicked this.setActiveNode = function (n) { // only do it on top-level-parent if (parent) parent.setActiveNode (n); else this.activeNode = n; } this.getActiveNode = function () { // only do it on top-level-parent if (parent) return parent.activeNode; else return this.activeNode; } // set active style and show children // if it get's called with id set it's an external call // and we need to make sure the parents are open! this.activate = function (idActivate, execute) { if (idActivate) { var n = this.getNode (idActivate); if (n) { var p = n.getParent (); while (p && p.getDepth () > 0) { if (!p.isOpen) p.showChildren (); p = p.parent; } } this.addHoverNode (n); n.activate (); if (execute) n.execute (); } if (this.getDepth () > 0) { this.setActiveNode (this); this.removeHoverNodes (); if (!isOpen) this.showChildren (); this.setStyle ('active'); } } // call the action that was given to the constructor this.execute = function () { if (action.length > 0) { var f = new Function ('a ', action + ''); f (); } } this.mouseOver = function (idOver) { if (n = this.getNode (idOver)) { if (this.getActiveNode () == null || this.getActiveNode () != n) { this.addHoverNode (n); n.setStyle ('hover'); } } } this.mouseOut = function (idOut) { if (idOut && this.getDepth () == 0) this.removeHoverNodes (); else { if (this.getActiveNode () == null || this.getActiveNode () != this) { this.setStyle ('inactive'); } } } this.mouseClick = function (idClick) { var n = this.getNode (idClick); if (n) { n.activate (); n.execute (); } } } /** * static method to init the menus html -> dom * creates the node as dom-element and appends it to container * container: the surrounding element of the parent */ MgnlNavigation.prototype.create = function (container) { // create navigation root if (this.getDepth () == 0) { // craete variable to itself document.mgnlNavigationSelf = this; var c = document.getElementById (container); if (c) { var n = this.getNodes (); var d = document.createElement ('div'); d.className = 'mgnlNavigationBox'; if (n && d) { for (var i = 0; i < n.length; i++) n[i].create (d); } c.appendChild (d); } } // create menu-entry else { // wrapper div var wrapper = document.createElement ('div'); wrapper.className = 'mgnlNavigationWrapper' + this.getDepth (); var inner = document.createElement ('div'); // table table = document.createElement ('table'); // get the navigation object an put it into this closure to pass it in the functions var myNavigation = this.getNavigation(); table.className = 'mgnlNavigation' + this.getDepth () + 'Inactive'; table.appendChild (document.createElement ('tbody')); table.firstChild.appendChild (document.createElement ('tr')); var cell = document.createElement ('td'); cell.className = 'mgnlNavigation' + this.getDepth () + 'Cell mgnlNavigationText'; if (this.hasIcon ()) cell.style.backgroundImage = 'url(' + this.getIcon () + ')'; cell.id = this.getId (); cell.onmouseover = function () { myNavigation.mouseOver (this.id); }; cell.onmouseout = function () { myNavigation.mouseOut (this.id); }; cell.onclick = function () { myNavigation.mouseClick (this.id); }; cell.innerHTML = this.getTitle(); table.firstChild.firstChild.appendChild (cell); inner.appendChild (table); wrapper.appendChild (inner); container.appendChild (wrapper); this.background = table; // create children if (this.hasNodes ()) { // add icon if (MgnlNavigation.openIcon) { var td = document.createElement ('td'); td.width = '1%'; td.appendChild (document.createElement ('img')); td.firstChild.src = MgnlNavigation.openIcon; td.firstChild.className = 'mgnlNavigation' + this.getDepth () + 'Arrow'; table.firstChild.firstChild.appendChild (td); } // create children var n = this.getNodes (); var c = document.createElement ('div'); c.className = 'mgnlNavigationWrapper' + (this.getDepth () + 1) + 'Inactive'; for (var i = 0; i < n.length; i++) n[i].create (c); // initially hide all children c.style.display = 'none'; wrapper.appendChild (c); } } } /* ################################### ### DynamicTable.js ################################### */ /* ################################### This is an example Header: Body:
Use JSON to parse this returned value
################################### */ /* ################################### ### DynamicTable Class ################################### */ /* ################################### ### Constructor ################################### */ function MgnlDynamicTable(tableName, hiddenField, getNewObjectFunction, getObjectFunction, renderObjectFunction, validateFunction, objects){ this.tableName = tableName; if(objects == null){ objects = new Array(); } this.objects = objects; // object getNewObject() this.getNewObject = getNewObjectFunction; // object getObject(prefix) returns an object with the content of the fields this.getObject = getObjectFunction; // string renderObject(cell, prefix, rowNumber, object); this.renderObject = renderObjectFunction; // boolean validate(object) this.validate = validateFunction; // used for persistence this.hiddenField = hiddenField; // default persistence is some thing handmade this.json=false; } /* ################################### ### Add an Object ################################### */ MgnlDynamicTable.prototype.set = function (index, object){ this.objects = this.getObjects(); this.objects[index] = object; this.render(); } /* ################################### ### Delete an Object ################################### */ MgnlDynamicTable.prototype.del = function (index){ var tmp = this.getObjects(); tmp[index] = null; this.objects = new Array(); var newIndex = 0; for(oldIndex= 0; oldIndex < tmp.length; oldIndex++){ if(tmp[oldIndex] != null){ this.objects[newIndex] = tmp[oldIndex]; newIndex++; } } this.render(); } /* ################################### ### Append Object ################################### */ MgnlDynamicTable.prototype.add = function (object){ this.set(this.objects.length, object); } /* ################################### ### Add New ################################### */ MgnlDynamicTable.prototype.addNew = function (){ this.set(this.objects.length, this.getNewObject()); } /* ################################### ### Read the objects from the Table ################################### */ MgnlDynamicTable.prototype.getObjects = function(){ var objects = new Array(); // get table var table = document.getElementById(this.tableName); // for each row var objectCount = 0; for(i=0; i < table.rows.length; i++){ var row = table.rows[i]; // check if this is realy a row with content if (row && row.cells[0] && row.cells[0].innerHTML!=""){ objects[objectCount] = this.getObject(this.tableName + i, i); objectCount++; } } return objects; } /* ################################### ### Render the table ################################### */ MgnlDynamicTable.prototype.render = function (update){ if(update==null){ update = false; } if(update){ this.objects = this.getObjects(); } // delte all var table = document.getElementById(this.tableName); //table.innerHTML=""; does not work with safari for(i=table.rows.length-1; i>=0 ; i--){ table.deleteRow(i); } for(i=0; i < this.objects.length; i++){ var row = table.insertRow(table.rows.length); var cell = row.insertCell(0); cell.setAttribute("id", this.tableName + i + "Cell"); this.renderObject(cell, this.tableName + i, i, this.objects[i]); } } /* ################################### ### persist the table and save it in the hidden field ################################### */ MgnlDynamicTable.prototype.persist = function (){ var str = ""; this.objects = this.getObjects(); if(this.json){ // must include the json javascript str = JSON.stringify(this.objects); } // old model else{ // persist all for(i=0; i < this.objects.length; i++){ if(i >0) str += ";"; str += this.persistObject(this.objects[i]) ; } } this.hiddenField.value = str; } MgnlDynamicTable.prototype.persistObject = function (object){ var str = ""; var simple = this.objectSize(object) == 1; for(key in object){ if(str.length > 0) str += ","; if(simple){ str += object[key]; } else{ str += key + ":" + object[key]; } first = false; } return str; } MgnlDynamicTable.prototype.objectSize = function (object){ var size=0; for(key in object){ size++; } return size; } /** * * Magnolia and its source-code is licensed under the LGPL. * You may copy, adapt, and redistribute this file for commercial or non-commercial use. * When copying, adapting, or redistributing this document in keeping with the guidelines above, * you are required to provide proper attribution to obinary. * If you reproduce or distribute the document without making any substantive modifications to its content, * please use the following attribution line: * * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved. * */ classDef("mgnl.dms.DMSDialog", { init: function(){ // change the default function mgnlControlFileSetFileName = mgnl.dms.DMSDialog.setFileName; }, setFileName: function(id,clear){ var nameElem=document.getElementById(id+"_fileName"); var extElem=document.getElementById(id+"_extension"); var ext=""; var name=""; if (!clear){ var fileElem=document.getElementById(id); var value=fileElem.value; var slash="\\"; if (value.indexOf("/")!=-1){ slash="/"; } if (value.indexOf(".")!=-1){ name=value.substring(value.lastIndexOf(slash)+1,value.lastIndexOf(".")); ext=value.substring(value.lastIndexOf(".") + 1); } else{ name=value.substring(value.lastIndexOf(slash)+1); } } else{ ext=""; } if (nameElem){ nameElem.value=name; } if (extElem){ extElem.value=ext; } }, hideSaveButton: function(){ divs = window.document.getElementsByTagName("div"); for(i=0; i