Created
December 8, 2011 11:23
-
-
Save vietj/1446756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var eXo = { | |
animation: {}, | |
browser: {}, | |
desktop: {}, | |
core: {}, | |
env: { | |
portal: {}, | |
client: {}, | |
server: {} | |
}, | |
portal: {}, | |
util: {}, | |
webui: {}, | |
gadget: {}, | |
application: { | |
browser: {} | |
}, | |
ecm: {}, | |
calendar: {}, | |
contact: {}, | |
forum: {}, | |
mail: {}, | |
faq: {}, | |
session: {}, | |
i18n: {} | |
}; | |
eXo.require = function (module, jsLocation, callback, context, params) { | |
try { | |
if (eval(module + ' != null')) { | |
if (callback) { | |
var ctx = context ? context : {}; | |
if (params && typeof (params) != "string" && params.length) callback.apply(ctx, params); | |
else callback.call(ctx, params); | |
} | |
return; | |
} | |
} catch (err) {} | |
window.status = "Loading Javascript Module " + module; | |
if (jsLocation == null) jsLocation = '/eXoResources/javascript/'; | |
var path = jsLocation + module.replace(/\./g, '/') + '.js'; | |
eXo.loadJS(path, module, callback, context, params); | |
}; | |
eXo.loadJS = function (path, module, callback, context, params) { | |
if (!module) module = path; | |
eXo.core.Loader.register(module, path); | |
eXo.core.Loader.init(module, callback, context, params); | |
eXo.session.startItv(); | |
}; | |
eXo.env.server.createPortalURL = function (targetComponentId, actionName, useAjax, params) { | |
var url = decodeURIComponent(eXo.env.server.portalURLTemplate); | |
url = url.replace("{portal:componentId}", targetComponentId); | |
url = url.replace("{portal:action}", actionName); | |
if (params != null) { | |
var len = params.length; | |
for (var i = 0; i < len; i++) { | |
url += "&" + params[i].name + "=" + params[i].value; | |
} | |
} | |
if (useAjax) url += "&ajaxRequest=true"; | |
return url; | |
}; | |
eXo.portal.logout = function () { | |
window.location = eXo.env.server.createPortalURL("UIPortal", "Logout", false); | |
}; | |
eXo.session.openUrl = null; | |
eXo.session.itvTime = null; | |
eXo.session.itvObj = null; | |
eXo.session.initialized = false; | |
eXo.session.itvInit = function () { | |
if (!eXo.session.initialized && eXo.session.canKeepState && eXo.env.portal.accessMode == 'private') { | |
if (!eXo.session.openUrl) eXo.session.openUrl = eXo.env.server.createPortalURL("UIPortal", "Ping", false); | |
if (!eXo.session.itvTime) eXo.session.itvTime = 1800; | |
eXo.session.initialized = true; | |
eXo.session.openItv(); | |
} | |
}; | |
eXo.session.startItv = function () { | |
if (eXo.session.initialized) { | |
eXo.session.destroyItv(); | |
if (eXo.session.canKeepState && eXo.env.portal.accessMode == 'private') { | |
if (eXo.session.itvTime > 0) eXo.session.itvObj = window.setTimeout("eXo.session.openItv()", (eXo.session.itvTime - 10) * 1000); | |
} | |
} else if (eXo.session.isOpen) { | |
eXo.session.itvInit(); | |
} | |
}; | |
eXo.session.openItv = function () { | |
var result = ajaxAsyncGetRequest(eXo.session.openUrl, false); | |
if (!isNaN(result)) eXo.session.itvTime = parseInt(result); | |
}; | |
eXo.session.destroyItv = function () { | |
window.clearTimeout(eXo.session.itvObj); | |
eXo.session.itvObj = null; | |
}; | |
eXo.debug = function (message) { | |
if (!eXo.developing) return; | |
if (eXo.webui.UINotification) { | |
message = "DEBUG: " + message; | |
eXo.webui.UINotification.addMessage(message); | |
} | |
}; | |
Array.prototype.clear = function () { | |
this.length = 0; | |
}; | |
Array.prototype.remove = function (element) { | |
var result = false; | |
var array = []; | |
for (var i = 0; i < this.length; i++) { | |
if (this[i] == element) { | |
result = true; | |
} else { | |
array.push(this[i]); | |
} | |
} | |
this.clear(); | |
for (var i = 0; i < array.length; i++) { | |
this.push(array[i]); | |
} | |
array = null; | |
return result; | |
}; | |
Array.prototype.contains = function (element) { | |
for (var i = 0; i < this.length; i++) { | |
if (this[i] == element) { | |
return true; | |
} | |
} | |
return false; | |
}; | |
Array.prototype.insertAt = function (what, iIndex) { | |
if (iIndex < this.length) { | |
var aAfter = this.splice(iIndex, 100000, what); | |
for (var i = 0; i < aAfter.length; i++) { | |
this.push(aAfter[i]); | |
} | |
} else { | |
this.push(what); | |
} | |
}; | |
Array.prototype.pushAll = function (array) { | |
if (array != null) { | |
for (var i = 0; i < array.length; i++) { | |
this.push(array[i]); | |
} | |
} | |
}; | |
Array.prototype.each = function (iterator, context) { | |
iterator = iterator.bind(context); | |
for (var i = 0; i < this.length; i++) { | |
iterator(this[i]); | |
} | |
}; | |
function HashMap() { | |
this.properties = new Object(); | |
this.length = 0; | |
}; | |
HashMap.prototype.copyProperties = function (names, object) { | |
for (var i = 0; i < names.length; i++) { | |
var name = names[i]; | |
this.put(name, object[name]); | |
} | |
}; | |
HashMap.prototype.setProperties = function (object, clear) { | |
for (var name in this.properties) { | |
object[name] = this.properties[name]; | |
} | |
}; | |
HashMap.prototype.get = function (name) { | |
return this.properties[name]; | |
}; | |
HashMap.prototype.remove = function (name) { | |
var value = this.properties[name]; | |
if (value != null) { | |
this.properties[name] = null; | |
this.length--; | |
return value; | |
} else { | |
return null; | |
} | |
}; | |
HashMap.prototype.put = function (name, value) { | |
if (this.properties[name] == null) { | |
this.length++; | |
} | |
this.properties[name] = value; | |
}; | |
HashMap.prototype.size = function () { | |
return this.length; | |
}; | |
HashMap.prototype.clear = function () { | |
this.properties = new Object(); | |
this.length = 0; | |
}; | |
eXo.core.HashMap = HashMap.prototype.constructor; | |
function ExoDateTime() {}; | |
ExoDateTime.prototype.getTime = function () { | |
var dateTime = new Date(); | |
var hour = dateTime.getHours(); | |
var minute = dateTime.getMinutes(); | |
var second = dateTime.getSeconds(); | |
if (hour <= 9) hour = "0" + hour; | |
if (minute <= 9) minute = "0" + minute; | |
var AM_PM = ""; | |
if (hour < 12) { | |
AM_PM = "AM"; | |
} else if (hour == 12) { | |
AM_PM = "PM"; | |
} else { | |
AM_PM = "PM"; | |
hour = hour - 12; | |
} | |
var time = ""; | |
time += hour + ":" + minute + " " + AM_PM; | |
var digitalClock = document.getElementById("DigitalClock"); | |
digitalClock.innerHTML = time; | |
setTimeout("eXo.core.ExoDateTime.getTime()", 60000); | |
}; | |
ExoDateTime.prototype.getDate = function () { | |
var dateTime = new Date(); | |
var date = dateTime.getDate(); | |
var month = dateTime.getMonth(); | |
var year = dateTime.getFullYear(); | |
if (date <= 9) date = "0" + date; | |
switch (month) { | |
case 0: | |
month = "Jan"; | |
break; | |
case 1: | |
month = "Feb"; | |
break; | |
case 2: | |
month = "Mar"; | |
break; | |
case 3: | |
month = "Apl"; | |
break; | |
case 4: | |
month = "May"; | |
break; | |
case 5: | |
month = "Jun"; | |
break; | |
case 6: | |
month = "Jul"; | |
break; | |
case 7: | |
month = "Aug"; | |
break; | |
case 8: | |
month = "Sep"; | |
break; | |
case 9: | |
month = "Oct"; | |
break; | |
case 10: | |
month = "Nov"; | |
break; | |
case 11: | |
month = "Dec"; | |
break; | |
default: | |
month = month; | |
break; | |
} | |
var today = date + " " + month + " " + year; | |
var dateElement = eXo.core.DOMUtil.findFirstDescendantByClass(document.body, "div", "Date"); | |
dateElement.innerHTML = today; | |
}; | |
eXo.core.ExoDateTime = new ExoDateTime(); | |
String.prototype.trim = function () { | |
var tmp = this.replace(/^\s*/, ''); | |
return tmp.replace(/\s*$/, ''); | |
} | |
Function.prototype.bind = function (object) { | |
var method = this; | |
return function () { | |
method.apply(object, arguments); | |
} | |
} | |
Function.prototype.inherits = function (parentCtor) { | |
function tempCtor() {}; | |
tempCtor.prototype = parentCtor.prototype; | |
this.superClass_ = parentCtor.prototype; | |
this.prototype = new tempCtor(); | |
this.prototype.constructor = this; | |
}; | |
function DOMUtil() { | |
this.hideElementList = new Array(); | |
}; | |
DOMUtil.prototype.hasClass = function (elemt, className) { | |
var reg = new RegExp('(^|\\s+)' + className + '(\\s+|$)'); | |
return reg.test(elemt['className']); | |
}; | |
DOMUtil.prototype.addClass = function (elemt, className) { | |
if (this.hasClass(elemt, className)) return; | |
elemt['className'] = [elemt['className'], className].join(' '); | |
}; | |
DOMUtil.prototype.removeClass = function (elemt, className) { | |
var reg = new RegExp('(^|\\s+)' + className); | |
elemt['className'] = elemt['className'].replace(reg, ''); | |
}; | |
DOMUtil.prototype.replaceClass = function (elemt, oldClazz, newClazz) { | |
var reg = new RegExp('(^|\\s+)' + oldClazz); | |
elemt['className'] = elemt['className'].replace(reg, newClazz); | |
}; | |
DOMUtil.prototype.getChildrenByTagName = function (element, tagName) { | |
var ln = 0; | |
var list = []; | |
if (element && element.childNodes) ln = element.childNodes.length; | |
for (var k = 0; k < ln; k++) { | |
if (element.childNodes[k].nodeName == tagName.toUpperCase()) list.push(element.childNodes[k]); | |
} | |
return list; | |
}; | |
DOMUtil.prototype.findChildrenByClass = function (root, elementName, cssClass) { | |
if (elementName) elementName = elementName.toUpperCase(); | |
var elements = root.childNodes; | |
var ln = elements.length; | |
var list = []; | |
for (var k = 0; k < ln; k++) { | |
if (elementName == elements[k].nodeName && this.hasClass(elements[k], cssClass)) { | |
list.push(elements[k]); | |
} | |
} | |
return list; | |
}; | |
DOMUtil.prototype.findChildrenByAttribute = function (root, elementName, attrName, attrValue) { | |
if (elementName) elementName = elementName.toUpperCase(); | |
var elements = root.childNodes; | |
var ln = elements.length; | |
var list = []; | |
for (var k = 0; k < ln; k++) { | |
if (elementName == elements[k].nodeName) { | |
var retValue = elements[k].getAttribute(attrName); | |
if (retValue == attrValue) list.push(elements[k]); | |
} | |
} | |
return list; | |
}; | |
DOMUtil.prototype.findFirstChildByClass = function (root, elementName, cssClass) { | |
if (elementName != null) elementName = elementName.toUpperCase(); | |
var elements = root.childNodes; | |
for (var k = 0; k < elements.length; k++) { | |
if (elementName == elements[k].nodeName && this.hasClass(elements[k], cssClass)) { | |
return elements[k]; | |
} | |
} | |
return null; | |
}; | |
DOMUtil.prototype.findAncestorByClass = function (element, clazz) { | |
if (element == null) return null; | |
var parent = element.parentNode; | |
while (parent != null) { | |
if (this.hasClass(parent, clazz)) return parent; | |
parent = parent.parentNode; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.findAncestorsByClass = function (element, clazz) { | |
var list = []; | |
var parent = element.parentNode; | |
while (parent != null) { | |
if (this.hasClass(parent, clazz)) list.push(parent); | |
parent = parent.parentNode; | |
} | |
return list; | |
}; | |
DOMUtil.prototype.findAncestorById = function (element, id) { | |
var parent = element.parentNode; | |
while (parent != null) { | |
if (parent.getAttributeNode && parent.getAttributeNode("id") && parent.getAttributeNode("id").value == id) return parent; | |
parent = parent.parentNode; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.findAncestorByTagName = function (element, tagName) { | |
var parent = element.parentNode; | |
while (parent != null) { | |
if (parent.nodeName && parent.nodeName.toLowerCase() == tagName) return parent; | |
parent = parent.parentNode; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.findDescendantsByTag = function (root, tagName, list) { | |
var children = root.childNodes; | |
var ln = children.length; | |
var child = null; | |
for (var k = 0; k < ln; k++) { | |
child = children[k]; | |
if (tagName == null) { | |
list[list.length] = child; | |
} else if (child.nodeName == null) { | |
continue; | |
} else { | |
if (tagName == child.nodeName.toLowerCase()) list[list.length] = child; | |
} | |
this.findDescendantsByTag(child, tagName, list); | |
} | |
}; | |
DOMUtil.prototype.findDescendantsByTagName = function (root, tagName) { | |
var list = []; | |
this.findDescendantsByTag(root, tagName, list); | |
return list; | |
}; | |
DOMUtil.prototype.findDescendantsByClass = function (root, elementName, clazz) { | |
var elements = root.getElementsByTagName(elementName); | |
var ln = elements.length; | |
var list = []; | |
this.findDescendantsByTag(root, elementName, elements); | |
for (var k = 0; k < ln; k++) { | |
if (this.hasClass(elements[k], clazz)) list.push(elements[k]); | |
} | |
return list; | |
}; | |
DOMUtil.prototype.findFirstDescendantByClass = function (root, elementName, clazz) { | |
if (!root) return; | |
var elements = root.getElementsByTagName(elementName); | |
var ln = elements.length; | |
for (var k = 0; k < ln; k++) { | |
if (this.hasClass(elements[k], clazz)) return elements[k]; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.findDescendantById = function (root, id) { | |
var elements = root.getElementsByTagName('*'); | |
var ln = elements.length; | |
for (var i = 0; i < ln; i++) { | |
if (elements[i].getAttributeNode && elements[i].getAttributeNode("id") && elements[i].getAttributeNode("id").value == id) return elements[i]; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.hasAncestor = function (root, obj) { | |
var prtEle = root.parentNode; | |
while (prtEle) { | |
if (prtEle == obj) return true; | |
prtEle = prtEle.parentNode; | |
} | |
return false; | |
}; | |
DOMUtil.prototype.hasDescendant = function (root, obj) { | |
var elements = root.getElementsByTagName("*"); | |
var ln = elements.length; | |
for (var k = 0; k < ln; k++) { | |
if (elements[k] == obj) return true; | |
} | |
return false; | |
}; | |
DOMUtil.prototype.hasDescendantClass = function (root, clazz) { | |
var elements = root.getElementsByTagName("*"); | |
var ln = elements.length; | |
for (var k = 0; k < ln; k++) { | |
if (this.hasClass(elements[k], clazz)) return true; | |
} | |
return false; | |
}; | |
DOMUtil.prototype.findNextElementByTagName = function (element, tagName) { | |
var nextElement = element.nextSibling; | |
while (nextElement != null) { | |
var nodeName = nextElement.nodeName; | |
if (nodeName != null) nodeName = nodeName.toLowerCase(); | |
if (nodeName == tagName) return nextElement; | |
nextElement = nextElement.nextSibling; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.findPreviousElementByTagName = function (element, tagName) { | |
var previousElement = element.previousSibling; | |
while (previousElement != null) { | |
var nodeName = previousElement.nodeName; | |
if (nodeName != null) nodeName = nodeName.toLowerCase(); | |
if (nodeName == tagName) return previousElement; | |
previousElement = previousElement.previousSibling; | |
} | |
return null; | |
}; | |
DOMUtil.prototype.moveElemt = function (srcElemt, destElemt) { | |
if (typeof (srcElemt) == "string") srcElemt = document.getElementById(srcElemt); | |
if (typeof (destElemt) == "string") destElemt = document.getElementById(destElemt); | |
if (srcElemt && destElemt) destElemt.appendChild(srcElemt); | |
} | |
DOMUtil.prototype.createElementNode = function (innerHTML, tagName) { | |
var temporaryContainer = document.createElement(tagName); | |
temporaryContainer.innerHTML = innerHTML; | |
var applicationNode = this.getChildrenByTagName(temporaryContainer, "div")[0]; | |
return applicationNode; | |
}; | |
DOMUtil.prototype.generateId = function (objectId) { | |
return (objectId + "-" + new Date().getTime() + Math.random().toString().substring(2)); | |
}; | |
DOMUtil.prototype.getStyle = function (element, style, intValue) { | |
var result = null; | |
if (element.style[style]) { | |
result = element.style[style]; | |
} else if (element.currentStyle) { | |
result = element.currentStyle[style]; | |
} else if (document.defaultView && document.defaultView.getComputedStyle) { | |
style = style.replace(/([A-Z])/g, "-$1"); | |
style = style.toLowerCase(); | |
var s = document.defaultView.getComputedStyle(element, ""); | |
result = s && s.getPropertyValue(style); | |
} | |
if (intValue && result) { | |
var intRes = Number(result.match(/\d+/)); | |
if (!isNaN(intRes)) result = intRes; | |
} | |
return result; | |
}; | |
DOMUtil.prototype.hideElements = function () { | |
document.onclick = eXo.core.DOMUtil.cleanUpHiddenElements; | |
}; | |
DOMUtil.prototype.cleanUpHiddenElements = function () { | |
var ln = eXo.core.DOMUtil.hideElementList.length; | |
if (ln > 0) { | |
for (var i = 0; i < ln; i++) { | |
eXo.core.DOMUtil.hideElementList[i].style.display = "none"; | |
} | |
eXo.core.DOMUtil.hideElementList.clear(); | |
} | |
}; | |
DOMUtil.prototype.listHideElements = function (object) { | |
if (!eXo.core.DOMUtil.hideElementList.contains(object)) { | |
eXo.core.DOMUtil.hideElementList.push(object); | |
} | |
}; | |
DOMUtil.prototype.removeElement = function (elemt) { | |
if (typeof (elemt) == "string") elemt = document.getElementById(elemt); | |
if (!elemt) return; | |
var parentElement = elemt.parentNode; | |
parentElement.removeChild(elemt); | |
}; | |
DOMUtil.prototype.getElementsBy = function (method, tag, root, apply) { | |
tag = tag || '*'; | |
root = (root) ? this.get(root) : null || document; | |
if (!root) { | |
return []; | |
} | |
var nodes = [], | |
elements = root.getElementsByTagName(tag); | |
for (var i = 0, len = elements.length; i < len; ++i) { | |
if (method(elements[i])) { | |
nodes[nodes.length] = elements[i]; | |
if (apply) { | |
apply(elements[i]); | |
} | |
} | |
} | |
return nodes; | |
} | |
DOMUtil.prototype.get = function (el) { | |
if (el && (el.nodeType || el.item)) { | |
return el; | |
} | |
if ((typeof el === 'string') || !el) { | |
return document.getElementById(el); | |
} | |
if (el.length !== undefined) { | |
var c = []; | |
for (var i = 0, len = el.length; i < len; ++i) { | |
c[c.length] = eXo.core.DOMUtil.get(el[i]); | |
} | |
return c; | |
} | |
return el; | |
} | |
DOMUtil.prototype.disableOnClick = function (el) { | |
el.onclick = new Function("return false;"); | |
} | |
eXo.core.DOMUtil = new DOMUtil(); | |
if (!eXo.core.html) { | |
eXo.core.html = {}; | |
} | |
eXo.core.html.HTMLEntities = []; | |
eXo.core.html.HTMLEntities['nbsp'] = 32; | |
eXo.core.html.HTMLEntities['iexcl'] = 161; | |
eXo.core.html.HTMLEntities['cent'] = 162; | |
eXo.core.html.HTMLEntities['pound'] = 163; | |
eXo.core.html.HTMLEntities['curren'] = 164; | |
eXo.core.html.HTMLEntities['yen'] = 165; | |
eXo.core.html.HTMLEntities['brvbar'] = 166; | |
eXo.core.html.HTMLEntities['sect'] = 167; | |
eXo.core.html.HTMLEntities['uml'] = 168; | |
eXo.core.html.HTMLEntities['copy'] = 169; | |
eXo.core.html.HTMLEntities['ordf'] = 170; | |
eXo.core.html.HTMLEntities['laquo'] = 171; | |
eXo.core.html.HTMLEntities['not'] = 172; | |
eXo.core.html.HTMLEntities['shy'] = 173; | |
eXo.core.html.HTMLEntities['reg'] = 174; | |
eXo.core.html.HTMLEntities['macr'] = 175; | |
eXo.core.html.HTMLEntities['deg'] = 176; | |
eXo.core.html.HTMLEntities['plusmn'] = 177; | |
eXo.core.html.HTMLEntities['sup2'] = 178; | |
eXo.core.html.HTMLEntities['sup3'] = 179; | |
eXo.core.html.HTMLEntities['acute'] = 180; | |
eXo.core.html.HTMLEntities['micro'] = 181; | |
eXo.core.html.HTMLEntities['para'] = 182; | |
eXo.core.html.HTMLEntities['middot'] = 183; | |
eXo.core.html.HTMLEntities['cedil'] = 184; | |
eXo.core.html.HTMLEntities['sup1'] = 185; | |
eXo.core.html.HTMLEntities['ordm'] = 186; | |
eXo.core.html.HTMLEntities['raquo'] = 187; | |
eXo.core.html.HTMLEntities['frac14'] = 188; | |
eXo.core.html.HTMLEntities['frac12'] = 189; | |
eXo.core.html.HTMLEntities['frac34'] = 190; | |
eXo.core.html.HTMLEntities['iquest'] = 191; | |
eXo.core.html.HTMLEntities['Agrave'] = 192; | |
eXo.core.html.HTMLEntities['Aacute'] = 193; | |
eXo.core.html.HTMLEntities['Acirc'] = 194; | |
eXo.core.html.HTMLEntities['Atilde'] = 195; | |
eXo.core.html.HTMLEntities['Auml'] = 196; | |
eXo.core.html.HTMLEntities['Aring'] = 197; | |
eXo.core.html.HTMLEntities['AElig'] = 198; | |
eXo.core.html.HTMLEntities['Ccedil'] = 199; | |
eXo.core.html.HTMLEntities['Egrave'] = 200; | |
eXo.core.html.HTMLEntities['Eacute'] = 201; | |
eXo.core.html.HTMLEntities['Ecirc'] = 202; | |
eXo.core.html.HTMLEntities['Euml'] = 203; | |
eXo.core.html.HTMLEntities['Igrave'] = 204; | |
eXo.core.html.HTMLEntities['Iacute'] = 205; | |
eXo.core.html.HTMLEntities['Icirc'] = 206; | |
eXo.core.html.HTMLEntities['Iuml'] = 207; | |
eXo.core.html.HTMLEntities['ETH'] = 208; | |
eXo.core.html.HTMLEntities['Ntilde'] = 209; | |
eXo.core.html.HTMLEntities['Ograve'] = 210; | |
eXo.core.html.HTMLEntities['Oacute'] = 211; | |
eXo.core.html.HTMLEntities['Ocirc'] = 212; | |
eXo.core.html.HTMLEntities['Otilde'] = 213; | |
eXo.core.html.HTMLEntities['Ouml'] = 214; | |
eXo.core.html.HTMLEntities['times'] = 215; | |
eXo.core.html.HTMLEntities['Oslash'] = 216; | |
eXo.core.html.HTMLEntities['Ugrave'] = 217; | |
eXo.core.html.HTMLEntities['Uacute'] = 218; | |
eXo.core.html.HTMLEntities['Ucirc'] = 219; | |
eXo.core.html.HTMLEntities['Uuml'] = 220; | |
eXo.core.html.HTMLEntities['Yacute'] = 221; | |
eXo.core.html.HTMLEntities['THORN'] = 222; | |
eXo.core.html.HTMLEntities['szlig'] = 223; | |
eXo.core.html.HTMLEntities['agrave'] = 224; | |
eXo.core.html.HTMLEntities['aacute'] = 225; | |
eXo.core.html.HTMLEntities['acirc'] = 226; | |
eXo.core.html.HTMLEntities['atilde'] = 227; | |
eXo.core.html.HTMLEntities['auml'] = 228; | |
eXo.core.html.HTMLEntities['aring'] = 229; | |
eXo.core.html.HTMLEntities['aelig'] = 230; | |
eXo.core.html.HTMLEntities['ccedil'] = 231; | |
eXo.core.html.HTMLEntities['egrave'] = 232; | |
eXo.core.html.HTMLEntities['eacute'] = 233; | |
eXo.core.html.HTMLEntities['ecirc'] = 234; | |
eXo.core.html.HTMLEntities['euml'] = 235; | |
eXo.core.html.HTMLEntities['igrave'] = 236; | |
eXo.core.html.HTMLEntities['iacute'] = 237; | |
eXo.core.html.HTMLEntities['icirc'] = 238; | |
eXo.core.html.HTMLEntities['iuml'] = 239; | |
eXo.core.html.HTMLEntities['eth'] = 240; | |
eXo.core.html.HTMLEntities['ntilde'] = 241; | |
eXo.core.html.HTMLEntities['ograve'] = 242; | |
eXo.core.html.HTMLEntities['oacute'] = 243; | |
eXo.core.html.HTMLEntities['ocirc'] = 244; | |
eXo.core.html.HTMLEntities['otilde'] = 245; | |
eXo.core.html.HTMLEntities['ouml'] = 246; | |
eXo.core.html.HTMLEntities['divide'] = 247; | |
eXo.core.html.HTMLEntities['oslash'] = 248; | |
eXo.core.html.HTMLEntities['ugrave'] = 249; | |
eXo.core.html.HTMLEntities['uacute'] = 250; | |
eXo.core.html.HTMLEntities['ucirc'] = 251; | |
eXo.core.html.HTMLEntities['uuml'] = 252; | |
eXo.core.html.HTMLEntities['yacute'] = 253; | |
eXo.core.html.HTMLEntities['thorn'] = 254; | |
eXo.core.html.HTMLEntities['yuml'] = 255; | |
eXo.core.html.HTMLEntities['fnof'] = 402; | |
eXo.core.html.HTMLEntities['Alpha'] = 913; | |
eXo.core.html.HTMLEntities['Beta'] = 914; | |
eXo.core.html.HTMLEntities['Gamma'] = 915; | |
eXo.core.html.HTMLEntities['Delta'] = 916; | |
eXo.core.html.HTMLEntities['Epsilon'] = 917; | |
eXo.core.html.HTMLEntities['Zeta'] = 918; | |
eXo.core.html.HTMLEntities['Eta'] = 919; | |
eXo.core.html.HTMLEntities['Theta'] = 920; | |
eXo.core.html.HTMLEntities['Iota'] = 921; | |
eXo.core.html.HTMLEntities['Kappa'] = 922; | |
eXo.core.html.HTMLEntities['Lambda'] = 923; | |
eXo.core.html.HTMLEntities['Mu'] = 924; | |
eXo.core.html.HTMLEntities['Nu'] = 925; | |
eXo.core.html.HTMLEntities['Xi'] = 926; | |
eXo.core.html.HTMLEntities['Omicron'] = 927; | |
eXo.core.html.HTMLEntities['Pi'] = 928; | |
eXo.core.html.HTMLEntities['Rho'] = 929; | |
eXo.core.html.HTMLEntities['Sigma'] = 931; | |
eXo.core.html.HTMLEntities['Tau'] = 932; | |
eXo.core.html.HTMLEntities['Upsilon'] = 933; | |
eXo.core.html.HTMLEntities['Phi'] = 934; | |
eXo.core.html.HTMLEntities['Chi'] = 935; | |
eXo.core.html.HTMLEntities['Psi'] = 936; | |
eXo.core.html.HTMLEntities['Omega'] = 937; | |
eXo.core.html.HTMLEntities['alpha'] = 945; | |
eXo.core.html.HTMLEntities['beta'] = 946; | |
eXo.core.html.HTMLEntities['gamma'] = 947; | |
eXo.core.html.HTMLEntities['delta'] = 948; | |
eXo.core.html.HTMLEntities['epsilon'] = 949; | |
eXo.core.html.HTMLEntities['zeta'] = 950; | |
eXo.core.html.HTMLEntities['eta'] = 951; | |
eXo.core.html.HTMLEntities['theta'] = 952; | |
eXo.core.html.HTMLEntities['iota'] = 953; | |
eXo.core.html.HTMLEntities['kappa'] = 954; | |
eXo.core.html.HTMLEntities['lambda'] = 955; | |
eXo.core.html.HTMLEntities['mu'] = 956; | |
eXo.core.html.HTMLEntities['nu'] = 957; | |
eXo.core.html.HTMLEntities['xi'] = 958; | |
eXo.core.html.HTMLEntities['omicron'] = 959; | |
eXo.core.html.HTMLEntities['pi'] = 960; | |
eXo.core.html.HTMLEntities['rho'] = 961; | |
eXo.core.html.HTMLEntities['sigmaf'] = 962; | |
eXo.core.html.HTMLEntities['sigma'] = 963; | |
eXo.core.html.HTMLEntities['tau'] = 964; | |
eXo.core.html.HTMLEntities['upsilon'] = 965; | |
eXo.core.html.HTMLEntities['phi'] = 966; | |
eXo.core.html.HTMLEntities['chi'] = 967; | |
eXo.core.html.HTMLEntities['psi'] = 968; | |
eXo.core.html.HTMLEntities['omega'] = 969; | |
eXo.core.html.HTMLEntities['thetasym'] = 977; | |
eXo.core.html.HTMLEntities['upsih'] = 978; | |
eXo.core.html.HTMLEntities['piv'] = 982; | |
eXo.core.html.HTMLEntities['bull'] = 8226; | |
eXo.core.html.HTMLEntities['hellip'] = 8230; | |
eXo.core.html.HTMLEntities['prime'] = 8242; | |
eXo.core.html.HTMLEntities['Prime'] = 8243; | |
eXo.core.html.HTMLEntities['oline'] = 8254; | |
eXo.core.html.HTMLEntities['frasl'] = 8260; | |
eXo.core.html.HTMLEntities['weierp'] = 8472; | |
eXo.core.html.HTMLEntities['image'] = 8465; | |
eXo.core.html.HTMLEntities['real'] = 8476; | |
eXo.core.html.HTMLEntities['trade'] = 8482; | |
eXo.core.html.HTMLEntities['alefsym'] = 8501; | |
eXo.core.html.HTMLEntities['larr'] = 8592; | |
eXo.core.html.HTMLEntities['rarr'] = 8594; | |
eXo.core.html.HTMLEntities['darr'] = 8595; | |
eXo.core.html.HTMLEntities['harr'] = 8596; | |
eXo.core.html.HTMLEntities['crarr'] = 8629; | |
eXo.core.html.HTMLEntities['lArr'] = 8656; | |
eXo.core.html.HTMLEntities['uarr'] = 8593; | |
eXo.core.html.HTMLEntities['uArr'] = 8657; | |
eXo.core.html.HTMLEntities['rArr'] = 8658; | |
eXo.core.html.HTMLEntities['dArr'] = 8659; | |
eXo.core.html.HTMLEntities['hArr'] = 8660; | |
eXo.core.html.HTMLEntities['forall'] = 8704; | |
eXo.core.html.HTMLEntities['part'] = 8706; | |
eXo.core.html.HTMLEntities['exist'] = 8707; | |
eXo.core.html.HTMLEntities['empty'] = 8709; | |
eXo.core.html.HTMLEntities['nabla'] = 8711; | |
eXo.core.html.HTMLEntities['isin'] = 8712; | |
eXo.core.html.HTMLEntities['notin'] = 8713; | |
eXo.core.html.HTMLEntities['ni'] = 8715; | |
eXo.core.html.HTMLEntities['prod'] = 8719; | |
eXo.core.html.HTMLEntities['sum'] = 8721; | |
eXo.core.html.HTMLEntities['minus'] = 8722; | |
eXo.core.html.HTMLEntities['lowast'] = 8727; | |
eXo.core.html.HTMLEntities['radic'] = 8730; | |
eXo.core.html.HTMLEntities['prop'] = 8733; | |
eXo.core.html.HTMLEntities['infin'] = 8734; | |
eXo.core.html.HTMLEntities['ang'] = 8736; | |
eXo.core.html.HTMLEntities['and'] = 8743; | |
eXo.core.html.HTMLEntities['or'] = 8744; | |
eXo.core.html.HTMLEntities['cap'] = 8745; | |
eXo.core.html.HTMLEntities['cup'] = 8746; | |
eXo.core.html.HTMLEntities['int'] = 8747; | |
eXo.core.html.HTMLEntities['there4'] = 8756; | |
eXo.core.html.HTMLEntities['sim'] = 8764; | |
eXo.core.html.HTMLEntities['cong'] = 8773; | |
eXo.core.html.HTMLEntities['asymp'] = 8776; | |
eXo.core.html.HTMLEntities['ne'] = 8800; | |
eXo.core.html.HTMLEntities['equiv'] = 8801; | |
eXo.core.html.HTMLEntities['le'] = 8804; | |
eXo.core.html.HTMLEntities['ge'] = 8805; | |
eXo.core.html.HTMLEntities['sub'] = 8834; | |
eXo.core.html.HTMLEntities['sup'] = 8835; | |
eXo.core.html.HTMLEntities['nsub'] = 8836; | |
eXo.core.html.HTMLEntities['sube'] = 8838; | |
eXo.core.html.HTMLEntities['supe'] = 8839; | |
eXo.core.html.HTMLEntities['oplus'] = 8853; | |
eXo.core.html.HTMLEntities['otimes'] = 8855; | |
eXo.core.html.HTMLEntities['perp'] = 8869; | |
eXo.core.html.HTMLEntities['sdot'] = 8901; | |
eXo.core.html.HTMLEntities['lceil'] = 8968; | |
eXo.core.html.HTMLEntities['rceil'] = 8969; | |
eXo.core.html.HTMLEntities['lfloor'] = 8970; | |
eXo.core.html.HTMLEntities['rfloor'] = 8971; | |
eXo.core.html.HTMLEntities['lang'] = 9001; | |
eXo.core.html.HTMLEntities['rang'] = 9002; | |
eXo.core.html.HTMLEntities['loz'] = 9674; | |
eXo.core.html.HTMLEntities['spades'] = 9824; | |
eXo.core.html.HTMLEntities['clubs'] = 9827; | |
eXo.core.html.HTMLEntities['hearts'] = 9829; | |
eXo.core.html.HTMLEntities['diams'] = 9830; | |
eXo.core.html.HTMLEntities['quot'] = 34; | |
eXo.core.html.HTMLEntities['amp'] = 38; | |
eXo.core.html.HTMLEntities['lt'] = 60; | |
eXo.core.html.HTMLEntities['gt'] = 62; | |
eXo.core.html.HTMLEntities['OElig'] = 338; | |
eXo.core.html.HTMLEntities['oelig'] = 339; | |
eXo.core.html.HTMLEntities['Scaron'] = 352; | |
eXo.core.html.HTMLEntities['scaron'] = 353; | |
eXo.core.html.HTMLEntities['Yuml'] = 376; | |
eXo.core.html.HTMLEntities['circ'] = 710; | |
eXo.core.html.HTMLEntities['tilde'] = 732; | |
eXo.core.html.HTMLEntities['ensp'] = 8194; | |
eXo.core.html.HTMLEntities['emsp'] = 8195; | |
eXo.core.html.HTMLEntities['thinsp'] = 8201; | |
eXo.core.html.HTMLEntities['zwnj'] = 8204; | |
eXo.core.html.HTMLEntities['zwj'] = 8205; | |
eXo.core.html.HTMLEntities['lrm'] = 8206; | |
eXo.core.html.HTMLEntities['rlm'] = 8207; | |
eXo.core.html.HTMLEntities['ndash'] = 8211; | |
eXo.core.html.HTMLEntities['mdash'] = 8212; | |
eXo.core.html.HTMLEntities['lsquo'] = 8216; | |
eXo.core.html.HTMLEntities['rsquo'] = 8217; | |
eXo.core.html.HTMLEntities['sbquo'] = 8218; | |
eXo.core.html.HTMLEntities['ldquo'] = 8220; | |
eXo.core.html.HTMLEntities['rdquo'] = 8221; | |
eXo.core.html.HTMLEntities['bdquo'] = 8222; | |
eXo.core.html.HTMLEntities['dagger'] = 8224; | |
eXo.core.html.HTMLEntities['Dagger'] = 8225; | |
eXo.core.html.HTMLEntities['permil'] = 8240; | |
eXo.core.html.HTMLEntities['lsaquo'] = 8249; | |
eXo.core.html.HTMLEntities['rsaquo'] = 8250; | |
eXo.core.html.HTMLEntities['euro'] = 8364; | |
function HTMLUtil() { | |
this.entities = eXo.core.html.HTMLEntities; | |
} | |
HTMLUtil.prototype.entitiesEncode = function (str) { | |
if (!str || str == '') { | |
return str; | |
} | |
for (var n in this.entities) { | |
var entityChar = String.fromCharCode(this.entities[n]); | |
if (entityChar == '&') { | |
entityChar = '\\' + entityChar; | |
} | |
while (str.indexOf(entityChar) != -1) { | |
str = str.replace(entityChar, '&' + n + ';'); | |
} | |
} | |
return str; | |
} | |
HTMLUtil.prototype.entitiesDecode = function (str) { | |
if (!str || str == '') { | |
return str; | |
} | |
for (var n in this.entities) { | |
var entityChar = String.fromCharCode(this.entities[n]); | |
var htmlEntity = '&' + n + ';'; | |
while (str.indexOf(htmlEntity) != -1) { | |
str = str.replace(htmlEntity, entityChar); | |
} | |
} | |
return str; | |
} | |
eXo.core.HTMLUtil = new HTMLUtil(); | |
function MouseObject() { | |
this.init(null); | |
}; | |
MouseObject.prototype.init = function (mouseEvent) { | |
this.mousexInPage = null; | |
this.mouseyInPage = null; | |
this.lastMousexInPage = null; | |
this.lastMouseyInPage = null; | |
this.mousexInClient = null; | |
this.mouseyInClient = null; | |
this.lastMousexInClient = null; | |
this.lastMouseyInClient = null; | |
this.deltax = null; | |
this.deltay = null; | |
if (mouseEvent != null) this.update(mouseEvent); | |
}; | |
MouseObject.prototype.update = function (mouseEvent) { | |
var x = eXo.core.Browser.findMouseXInPage(mouseEvent); | |
var y = eXo.core.Browser.findMouseYInPage(mouseEvent); | |
this.lastMousexInPage = this.mousexInPage != null ? this.mousexInPage : x; | |
this.lastMouseyInPage = this.mouseyInPage != null ? this.mouseyInPage : y; | |
this.mousexInPage = x; | |
this.mouseyInPage = y; | |
x = eXo.core.Browser.findMouseXInClient(mouseEvent); | |
y = eXo.core.Browser.findMouseYInClient(mouseEvent); | |
this.lastMousexInClient = this.mousexInClient != null ? this.mousexInClient : x; | |
this.lastMouseyInClient = this.mouseyInClient != null ? this.mouseyInClient : y; | |
this.mousexInClient = x; | |
this.mouseyInClient = y; | |
this.deltax = this.mousexInClient - this.lastMousexInClient; | |
this.deltay = this.mouseyInClient - this.lastMouseyInClient; | |
}; | |
function Browser() { | |
this.onLoadCallback = new eXo.core.HashMap(); | |
this.onResizeCallback = new eXo.core.HashMap(); | |
this.onScrollCallback = new eXo.core.HashMap(); | |
this.breakStream; | |
window.onresize = this.managerResize; | |
window.onscroll = this.onScroll; | |
this.initCommon(); | |
this.detectBrowser(); | |
if (this.opera) this.initOpera(); | |
else if (this.ie) this.initIE(); | |
else if (this.webkit) this.initSafari(); | |
else this.initMozilla(); | |
}; | |
Browser.prototype.detectBrowser = function () { | |
this.ie = 0; | |
this.opera = 0; | |
this.gecko = 0; | |
this.webkit = 0; | |
this.mobile = null; | |
this.air = 0; | |
var ua = navigator.userAgent, | |
m; | |
if ((/KHTML/).test(ua)) { | |
this.webkit = 1; | |
} | |
m = ua.match(/AppleWebKit\/([^\s]*)/); | |
if (m && m[1]) { | |
this.webkit = parseFloat(m[1]); | |
if (/ Mobile\//.test(ua)) { | |
this.mobile = "Apple"; | |
} else { | |
m = ua.match(/NokiaN[^\/]*/); | |
if (m) { | |
this.mobile = m[0]; | |
} | |
} | |
m = ua.match(/AdobeAIR\/([^\s]*)/); | |
if (m) { | |
this.air = m[0]; | |
} | |
} | |
if (!this.webkit) { | |
m = ua.match(/Opera[\s\/]([^\s]*)/); | |
if (m && m[1]) { | |
this.opera = parseFloat(m[1]); | |
m = ua.match(/Opera Mini[^;]*/); | |
if (m) { | |
this.mobile = m[0]; | |
} | |
} else { | |
m = ua.match(/MSIE\s([^;]*)/); | |
if (m && m[1]) { | |
this.ie = parseFloat(m[1]); | |
} else { | |
m = ua.match(/Gecko\/([^\s]*)/); | |
if (m) { | |
this.gecko = 1; | |
m = ua.match(/rv:([^\s\)]*)/); | |
if (m && m[1]) { | |
this.gecko = parseFloat(m[1]); | |
} | |
} | |
} | |
} | |
} | |
} | |
Browser.prototype.managerResize = function () { | |
if (eXo.core.Browser.currheight != document.documentElement.clientHeight) { | |
clearTimeout(eXo.core.Browser.breakStream); | |
eXo.core.Browser.breakStream = setTimeout(eXo.core.Browser.onResize, 100); | |
} | |
eXo.core.Browser.currheight = document.documentElement.clientHeight; | |
} | |
Browser.prototype.initCommon = function () { | |
this.getBrowserHeight = function () { | |
return document.documentElement.clientHeight; | |
} | |
this.getBrowserWidth = function () { | |
return document.documentElement.clientWidth; | |
} | |
this.createHttpRequest = function () { | |
return new XMLHttpRequest(); | |
} | |
}; | |
Browser.prototype.initIE = function () { | |
this.browserType = "ie"; | |
this.createHttpRequest = function () { | |
return new ActiveXObject("Msxml2.XMLHTTP"); | |
} | |
this.eventListener = function (object, event, operation) { | |
event = "on" + event; | |
object.attachEvent(event, operation); | |
} | |
this.setOpacity = function (component, value) { | |
component.style.filter = "alpha(opacity=" + value + ")"; | |
} | |
this.getEventSource = function (e) { | |
return window.event.srcElement; | |
} | |
}; | |
Browser.prototype.initMozilla = function () { | |
this.browserType = "mozilla"; | |
this.eventListener = function (object, event, operation) { | |
object.addEventListener(event, operation, false); | |
} | |
this.setOpacity = function (component, value) { | |
component.style.opacity = value / 100; | |
} | |
this.getEventSource = function (e) { | |
return e.target; | |
} | |
}; | |
Browser.prototype.initSafari = function () { | |
this.browserType = "safari"; | |
this.getBrowserHeight = function () { | |
return self.innerHeight; | |
}; | |
this.getBrowserWidth = function () { | |
return self.innerWidth; | |
}; | |
this.eventListener = function (object, event, operation) { | |
object.addEventListener(event, operation, false); | |
} | |
this.setOpacity = function (component, value) { | |
component.style.opacity = value / 100; | |
} | |
this.getEventSource = function (e) { | |
var targ = e.target; | |
if (targ.nodeType == 3) targ = targ.parentNode; | |
return targ; | |
} | |
}; | |
Browser.prototype.initOpera = function () { | |
this.browserType = "opera"; | |
this.getBrowserHeight = function () { | |
return document.body.clientHeight; | |
} | |
this.getBrowserWidth = function () { | |
return document.body.clientWidth; | |
} | |
}; | |
Browser.prototype.isIE6 = function () { | |
var agent = navigator.userAgent; | |
return (agent.indexOf("MSIE 6") >= 0); | |
}; | |
Browser.prototype.isIE7 = function () { | |
var agent = navigator.userAgent; | |
return (agent.indexOf("MSIE 7") >= 0); | |
}; | |
Browser.prototype.isFF = function () { | |
return this.gecko; | |
}; | |
Browser.prototype.isFF2 = function () { | |
return (navigator.userAgent.indexOf("Firefox/2") >= 0); | |
}; | |
Browser.prototype.isFF3 = function () { | |
return (navigator.userAgent.indexOf("Firefox/3") >= 0); | |
}; | |
Browser.prototype.findMouseXInClient = function (e) { | |
if (!e) e = window.event; | |
return e.clientX; | |
}; | |
Browser.prototype.findMouseYInClient = function (e) { | |
if (!e) e = window.event; | |
return e.clientY; | |
}; | |
Browser.prototype.addOnLoadCallback = function (id, method) { | |
this.onLoadCallback.put(id, method); | |
}; | |
Browser.prototype.onLoad = function () { | |
var callback = eXo.core.Browser.onLoadCallback; | |
for (var name in callback.properties) { | |
var method = callback.get(name); | |
if (typeof (method) == "function") try { | |
method() | |
} catch (e) {}; | |
} | |
this.onLoadCallback = new eXo.core.HashMap(); | |
}; | |
Browser.prototype.addOnResizeCallback = function (id, method) { | |
this.onResizeCallback.put(id, method); | |
}; | |
Browser.prototype.onResize = function (event) { | |
var callback = eXo.core.Browser.onResizeCallback; | |
for (var name in callback.properties) { | |
var method = callback.get(name); | |
if (typeof (method) == "function") method(event); | |
} | |
}; | |
Browser.prototype.addOnScrollCallback = function (id, method) { | |
this.onScrollCallback.put(id, method); | |
}; | |
Browser.prototype.onScroll = function (event) { | |
var callback = eXo.core.Browser.onScrollCallback; | |
for (var name in callback.properties) { | |
var method = callback.get(name); | |
try { | |
if (typeof (method) == "function") method(event); | |
} catch (err) {} | |
} | |
}; | |
Browser.prototype.getBrowserType = function () { | |
return this.browserType; | |
}; | |
Browser.prototype.findPosX = function (obj, isRTL) { | |
var curleft = 0; | |
var tmpObj = obj; | |
while (tmpObj) { | |
curleft += tmpObj.offsetLeft; | |
tmpObj = tmpObj.offsetParent; | |
} | |
if (isRTL) return curleft + obj.offsetWidth; | |
return curleft; | |
}; | |
Browser.prototype.findPosY = function (obj) { | |
var curtop = 0; | |
while (obj) { | |
curtop += obj.offsetTop; | |
obj = obj.offsetParent; | |
} | |
return curtop; | |
}; | |
Browser.prototype.findPosXInContainer = function (obj, container, isRTL) { | |
var objX = eXo.core.Browser.findPosX(obj, isRTL); | |
var containerX = eXo.core.Browser.findPosX(container, isRTL); | |
if (isRTL) return -(objX - containerX); | |
return (objX - containerX); | |
}; | |
Browser.prototype.findPosYInContainer = function (obj, container) { | |
var objY = eXo.core.Browser.findPosY(obj); | |
var containerY = eXo.core.Browser.findPosY(container); | |
return (objY - containerY); | |
}; | |
Browser.prototype.findMouseXInPage = function (e) { | |
var posx = -1; | |
if (!e) e = window.event; | |
if (e.pageX || e.pageY) { | |
posx = e.pageX; | |
} else if (e.clientX || e.clientY) { | |
posx = e.clientX + document.body.scrollLeft; | |
} | |
return posx; | |
}; | |
Browser.prototype.findMouseYInPage = function (e) { | |
var posy = -1; | |
if (!e) e = window.event; | |
if (e.pageY) { | |
posy = e.pageY; | |
} else if (e.clientX || e.clientY) { | |
if (document.documentElement && document.documentElement.scrollTop) { | |
posy = e.clientY + document.documentElement.scrollTop; | |
} else { | |
posy = e.clientY + document.body.scrollTop; | |
} | |
} | |
return posy; | |
}; | |
Browser.prototype.findMouseRelativeX = function (object, e, isRTL) { | |
var posx = -1; | |
var posXObject = eXo.core.Browser.findPosX(object, isRTL); | |
if (!e) e = window.event; | |
if (e.pageX || e.pageY) { | |
posx = e.pageX - posXObject; | |
} else if (e.clientX || e.clientY) { | |
posx = e.clientX + document.body.scrollLeft - posXObject; | |
} | |
return posx; | |
}; | |
Browser.prototype.findMouseRelativeY = function (object, e) { | |
var posy = -1; | |
var posYObject = eXo.core.Browser.findPosY(object); | |
if (!e) e = window.event; | |
if (e.pageY) { | |
posy = e.pageY - posYObject; | |
} else if (e.clientX || e.clientY) { | |
if (document.documentElement && document.documentElement.scrollTop) { | |
posy = e.clientY + document.documentElement.scrollTop - posYObject; | |
} else { | |
posy = e.clientY + document.body.scrollTop - posYObject; | |
} | |
} | |
return posy; | |
}; | |
Browser.prototype.setPositionInContainer = function (container, component, posX, posY) { | |
var offsetX = component.offsetLeft; | |
var offsetY = component.offsetTop; | |
var posXInContainer = eXo.core.Browser.findPosXInContainer(component, container); | |
var posYInContainer = eXo.core.Browser.findPosYInContainer(component, container); | |
var deltaX = posX - (posXInContainer - offsetX); | |
var deltaY = posY - (posYInContainer - offsetY); | |
component.style.left = deltaX + "px"; | |
component.style.top = deltaY + "px"; | |
}; | |
Browser.prototype.setCookie = function (name, value, expiredays) { | |
var exdate = new Date(); | |
exdate.setDate(exdate.getDate() + expiredays); | |
document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); | |
}; | |
Browser.prototype.getCookie = function (name) { | |
if (document.cookie.length > 0) { | |
var start = document.cookie.indexOf(name + "=") | |
if (start != -1) { | |
start = start + name.length + 1; | |
var end = document.cookie.indexOf(";", start); | |
if (end == -1) end = document.cookie.length; | |
return unescape(document.cookie.substring(start, end)); | |
} | |
} | |
return ""; | |
}; | |
Browser.prototype.isDesktop = function () { | |
if (document.getElementById("UIPageDesktop")) return true; | |
return false; | |
} | |
Browser.prototype.getHeightOfFreeSpace = function () { | |
var elements = document.body.children; | |
var height = 0; | |
var ln = elements.length; | |
for (var k = 0; k < ln; k++) { | |
height += elements[k].offsetHeight; | |
} | |
return (this.getBrowserHeight() - height); | |
} | |
Browser.prototype.fillUpFreeSpace = function (elemt) { | |
if (typeof (elemt) == "string") elemt = document.getElementById(elemt); | |
var height = eXo.core.Browser.getHeightOfFreeSpace(); | |
if (height > 0 && elemt != undefined) { | |
height += elemt.offsetHeight; | |
elemt.style.height = height + "px"; | |
} | |
} | |
eXo.core.Browser = new Browser(); | |
eXo.core.Mouse = new MouseObject(); | |
function Loader() { | |
this.wait = 1; | |
this.defaultAsyncWait = 250; | |
}; | |
Loader.prototype.init = function (scriptName, callback, context, params) { | |
var a = -1; | |
var scriptNames = new Array(); | |
if (typeof (scriptName) != "string" && scriptName.length) { | |
var _scriptNames = scriptName; | |
for (var s = 0; s < _scriptNames.length; s++) { | |
if (this.registered[_scriptNames[s]] || durl(_scriptNames[s])) { | |
scriptNames.push(_scriptNames[s]); | |
} | |
} | |
scriptName = scriptNames[0]; | |
a = 1; | |
} else { | |
while (typeof (arguments[++a]) == "string") { | |
if (this.registered[scriptName] || durl(scriptName)) { | |
scriptNames.push(arguments[a]); | |
} | |
} | |
} | |
callback = arguments[a]; | |
context = arguments[++a]; | |
params = arguments[++a]; | |
if (scriptNames.length > 1) { | |
var cb = callback; | |
callback = function () { | |
eXo.core.Loader.init(scriptNames, cb, context, params); | |
} | |
} | |
var reg = this.registered[scriptName]; | |
if (!this.__durls) this.__durls = {}; | |
if (durl(scriptName) && scriptName.substring(0, 4) == "url(") { | |
scriptName = scriptName.substring(4, scriptName.length - 1); | |
if (!this.__durls[scriptName]) { | |
scriptNames[0] = scriptName; | |
this.register(scriptName, true, scriptName); | |
reg = this.registered[scriptName]; | |
var callbackQueue = this.getCallbackQueue(scriptName); | |
var cbitem = new this.CallbackItem(function () { | |
eXo.core.Loader.__durls[scriptName] = true; | |
}); | |
callbackQueue.push(cbitem); | |
callbackQueue.push(new this.CallbackItem(callback, context, params)); | |
callback = undefined; | |
context = undefined; | |
} | |
} | |
if (reg) { | |
for (var r = reg.requirements.length - 1; r >= 0; r--) { | |
if (this.registered[reg.requirements[r].name]) { | |
eXo.core.Loader.init(reg.requirements[r].name, function () { | |
eXo.core.Loader.init(scriptName, callback, context, params); | |
}, context); | |
return; | |
} | |
} | |
for (var u = 0; u < reg.urls.length; u++) { | |
if (u == reg.urls.length - 1) { | |
if (callback) { | |
this.load(reg.name, reg.urls[u], reg.remote, reg.asyncWait, new this.CallbackItem(callback, context, params)); | |
} else { | |
this.load(reg.name, reg.urls[u], reg.remote, reg.asyncWait); | |
} | |
} else { | |
this.load(reg.name, reg.urls[u], reg.remote, reg.asyncWait); | |
} | |
} | |
} else { | |
var cb = callback; | |
if (cb) { | |
if (params && typeof (params) != "string" && params.length) cb.apply(context, params); | |
else cb.call(context, params); | |
} | |
} | |
}; | |
Loader.prototype.CallbackItem = function (_callback, _context, _params) { | |
this.callback = _callback; | |
this.context = _context; | |
this.params = _params; | |
this.invoke = function () { | |
var ctx = this.context ? this.context : {}; | |
if (this.params && typeof (this.params) != "string" && this.params.length) this.callback.apply(ctx, this.params); | |
else this.callback.call(ctx, this.params); | |
}; | |
}; | |
Loader.prototype.Registration = function (_name, _version, _remote, _asyncWait, _urls) { | |
this.name = _name; | |
var a = 0; | |
var arg = arguments[++a]; | |
var v = true; | |
if (typeof (arg) == "string") { | |
for (var c = 0; c < arg.length; c++) { | |
if ("1234567890.".indexOf(c) == -1) { | |
v = false; | |
break; | |
} | |
} | |
if (v) { | |
this.version = arg; | |
arg = arguments[++a]; | |
} else { | |
this.version = "1.0.0"; | |
} | |
} | |
if (arg && typeof (arg) == "boolean") { | |
this.remote = arg; | |
arg = arguments[++a]; | |
} else { | |
this.remote = false; | |
} | |
if (arg && typeof (arg) == "number") { | |
this.asyncWait = _asyncWait; | |
} else { | |
this.asyncWait = 0; | |
} | |
this.urls = new Array(); | |
if (arg && arg.length && typeof (arg) != "string") { | |
this.urls = arg; | |
} else { | |
for (a = a; a < arguments.length; a++) { | |
if (arguments[a] && typeof (arguments[a]) == "string") { | |
this.urls.push(arguments[a]); | |
} | |
} | |
} | |
this.requirements = new Array(); | |
this.requires = function (resourceName, minimumVersion) { | |
if (!minimumVersion) minimumVersion = "1.0.0"; | |
eXo.core.Loader.requirements.push({ | |
name: resourceName, | |
minVersion: minimumVersion | |
}); | |
return this; | |
} | |
this.register = function (name, version, remote, asyncWait, urls) { | |
return eXo.core.Loader.register(name, version, remote, asyncWait, urls); | |
} | |
return this; | |
}; | |
Loader.prototype.register = function (name, version, remote, asyncWait, urls) { | |
var reg; | |
if (typeof (name) == "object") { | |
reg = name; | |
reg = new this.Registration(reg.name, reg.version, reg.remote, reg.asyncWait, urls); | |
} else { | |
reg = new this.Registration(name, version, remote, asyncWait, urls); | |
} | |
if (!this.registered) this.registered = {}; | |
if (this.registered[name] && window.console) { | |
window.console.log("Warning: Resource named \"" + name + "\" was already registered with this.register(); overwritten."); | |
} | |
this.registered[name] = reg; | |
return reg; | |
}; | |
Loader.prototype.getCallbackQueue = function (scriptUrl) { | |
if (!this.__callbackQueue) { | |
this.__callbackQueue = {}; | |
} | |
var callbackQueue = this.__callbackQueue[scriptUrl]; | |
if (!callbackQueue) { | |
callbackQueue = this.__callbackQueue[scriptUrl] = new Array(); | |
} | |
return callbackQueue; | |
}; | |
Loader.prototype.load = function (scriptName, scriptUrl, remote, asyncWait, cb) { | |
if (asyncWait == undefined) asyncWait = this.wait; | |
if (remote && asyncWait == 0) asyncWait = this.defaultAsyncWait; | |
if (!this.loadedScripts) this.loadedScripts = new Array(); | |
var callbackQueue = this.getCallbackQueue(scriptUrl); | |
callbackQueue.push(new this.CallbackItem(function () { | |
eXo.core.Loader.loadedScripts.push(eXo.core.Loader.registered[scriptName]); | |
eXo.core.Loader.registered[scriptName] = false; | |
}, null)); | |
if (cb) { | |
callbackQueue.push(cb); | |
if (callbackQueue.length > 2) return; | |
} | |
if (remote) { | |
this.srcScript(scriptUrl, asyncWait, callbackQueue); | |
} else { | |
var request = eXo.core.Browser.createHttpRequest(); | |
request.open('GET', scriptUrl, false); | |
request.send(null); | |
this.injectScript(request.responseText, scriptName); | |
if (callbackQueue) { | |
for (var q = 0; q < callbackQueue.length; q++) { | |
callbackQueue[q].invoke(); | |
} | |
} | |
this.__callbackQueue[scriptUrl] = undefined; | |
} | |
}; | |
Loader.prototype.genScriptNode = function () { | |
var scriptNode = document.createElement("script"); | |
scriptNode.setAttribute("type", "text/javascript"); | |
scriptNode.setAttribute("language", "JavaScript"); | |
return scriptNode; | |
}; | |
Loader.prototype.srcScript = function (scriptUrl, asyncWait, callbackQueue) { | |
var scriptNode = this.genScriptNode(); | |
scriptNode.setAttribute("src", scriptUrl); | |
if (callbackQueue) { | |
var execQueue = function () { | |
eXo.core.Loader.__callbackQueue[scriptUrl] = undefined; | |
for (var q = 0; q < callbackQueue.length; q++) { | |
callbackQueue[q].invoke(); | |
} | |
callbackQueue = new Array(); | |
} | |
scriptNode.onload = scriptNode.onreadystatechange = function () { | |
if ((!scriptNode.readyState) || scriptNode.readyState == "loaded" || scriptNode.readyState == "complete" || scriptNode.readyState == 4 && scriptNode.status == 200) { | |
if (asyncWait > 0) { | |
setTimeout(execQueue, asyncWait); | |
} else { | |
execQueue(); | |
} | |
} | |
}; | |
} | |
var headNode = document.getElementsByTagName("head")[0]; | |
headNode.appendChild(scriptNode); | |
}; | |
Loader.prototype.injectScript = function (scriptText, scriptName) { | |
var scriptNode = this.genScriptNode(); | |
try { | |
scriptNode.setAttribute("name", scriptName); | |
} catch (err) {} | |
scriptNode.text = scriptText; | |
var headNode = document.getElementsByTagName("head")[0]; | |
headNode.appendChild(scriptNode); | |
}; | |
function durl(sc) { | |
var su = sc; | |
if (sc && sc.substring(0, 4) == "url(") { | |
su = sc.substring(4, sc.length - 1); | |
} | |
var r = eXo.core.Loader.registered[su]; | |
return (!r && (!this.__durls || !this.__durls[su]) && sc && sc.length > 4 && sc.substring(0, 4) == "url("); | |
}; | |
eXo.core.Loader = new Loader(); | |
function MouseEventManager() {}; | |
MouseEventManager.prototype.addMouseDownHandler = function (method) { | |
document.onmousedown = this.docMouseDownEvt; | |
this.onMouseDownHandlers = method; | |
}; | |
MouseEventManager.prototype.docMouseDownEvt = function (evt) { | |
if (!evt) evt = window.event; | |
evt.cancelBubble = true; | |
if (eXo.core.MouseEventManager.onMouseDownHandlers == null) return; | |
if (typeof (eXo.core.MouseEventManager.onMouseDownHandlers) == "string") eval(eXo.core.MouseEventManager.onMouseDownHandlers); | |
else eXo.core.MouseEventManager.onMouseDownHandlers(evt); | |
document.onmousedown = null; | |
}; | |
MouseEventManager.prototype.addMouseUpHandler = function (method) { | |
document.onmouseup = this.docMouseUpEvt; | |
this.onMouseUpHandlers = method; | |
}; | |
MouseEventManager.prototype.docMouseUpEvt = function () { | |
var mouseUpHandlers = eXo.core.MouseEventManager.onMouseUpHandlers; | |
}; | |
MouseEventManager.prototype.docMouseClickEvt = function (evt) { | |
if (!evt) evt = window.event; | |
evt.cancelBubble = true; | |
if (typeof (eXo.core.MouseEventManager.onMouseClickHandlers) == "string") eval(eXo.core.MouseEventManager.onMouseClickHandlers); | |
else eXo.core.MouseEventManager.onMouseClickHandlers(evt); | |
document.onclick = null; | |
}; | |
MouseEventManager.prototype.addMouseClickHandler = function (method) { | |
document.onclick = this.docMouseClickEvt; | |
this.onMouseClickHandlers = method; | |
}; | |
eXo.core.MouseEventManager = new MouseEventManager(); | |
function UIMaskLayer() {}; | |
UIMaskLayer.prototype.createTransparentMask = function (position) { | |
var Browser = eXo.core.Browser; | |
var ajaxLoading = document.getElementById("AjaxLoadingMask"); | |
var maskLayer = eXo.core.UIMaskLayer.createMask("UIPortalApplication", ajaxLoading, 0, position); | |
Browser.addOnScrollCallback("5439383", eXo.core.UIMaskLayer.setPosition); | |
ajaxLoading.style.display = "none"; | |
Browser.setOpacity(maskLayer, 0); | |
maskLayer.style.backgroundColor = "white"; | |
maskLayer.style.cursor = "wait"; | |
return maskLayer; | |
}; | |
UIMaskLayer.prototype.showAjaxLoading = function (mask) { | |
var ajaxLoading = document.getElementById("AjaxLoadingMask"); | |
ajaxLoading.style.top = document.documentElement.scrollTop + "px"; | |
ajaxLoading.style.display = "block"; | |
} | |
UIMaskLayer.prototype.removeTransparentMask = function () { | |
var mask = document.getElementById("TransparentMaskLayer"); | |
if (mask) { | |
mask.style.height = "0px"; | |
mask.style.width = "0px"; | |
} | |
}; | |
UIMaskLayer.prototype.removeMasks = function (maskLayer) { | |
eXo.core.UIMaskLayer.removeTransparentMask(); | |
eXo.core.UIMaskLayer.removeMask(maskLayer); | |
}; | |
UIMaskLayer.prototype.createMask = function (blockContainerId, object, opacity, position) { | |
try { | |
var Browser = eXo.core.Browser; | |
if (typeof (blockContainerId) == "string") blockContainerId = document.getElementById(blockContainerId); | |
var blockContainer = blockContainerId; | |
var maskLayer = document.createElement("div"); | |
this.object = object; | |
this.blockContainer = blockContainer; | |
this.position = position; | |
if (document.getElementById("MaskLayer")) { | |
document.getElementById("MaskLayer").id = "subMaskLayer"; | |
} | |
blockContainer.appendChild(maskLayer); | |
maskLayer.className = "MaskLayer"; | |
maskLayer.id = "MaskLayer"; | |
maskLayer.maxZIndex = eXo.webui.UIPopup.zIndex + 1; | |
var offsetParent = maskLayer.offsetParent; | |
if (offsetParent && eXo.core.Browser.findPosX(offsetParent) != 0 && eXo.core.Browser.findPosY(offsetParent) != 0) { | |
maskLayer.style.width = offsetParent.offsetWidth + "px"; | |
maskLayer.style.height = offsetParent.offsetHeight + "px"; | |
} else { | |
maskLayer.style.width = Browser.getBrowserWidth() + "px"; | |
maskLayer.style.height = Browser.getBrowserHeight() + "px"; | |
} | |
maskLayer.style.top = "0px"; | |
maskLayer.style.left = "0px"; | |
maskLayer.style.zIndex = maskLayer.maxZIndex; | |
if (opacity) { | |
Browser.setOpacity(maskLayer, opacity); | |
} | |
if (object != null) { | |
var tempNextSibling = document.createElement("span"); | |
if (object.nextSibling) { | |
object.parentNode.insertBefore(tempNextSibling, object.nextSibling); | |
} else { | |
object.parentNode.appendChild(tempNextSibling); | |
} | |
maskLayer.nextSiblingOfObject = tempNextSibling; | |
object.style.zIndex = maskLayer.maxZIndex; | |
object.style.display = "block"; | |
blockContainer.appendChild(object); | |
eXo.core.UIMaskLayer.setPosition(); | |
if (eXo.core.I18n.isLT()) { | |
if ((blockContainer.offsetWidth > object.offsetLeft + object.offsetWidth) && (position == "TOP-RIGHT") || (position == "BOTTOM-RIGHT")) { | |
object.style.left = blockContainer.offsetWidth - object.offsetWidth + "px"; | |
} | |
} | |
eXo.core.UIMaskLayer.doScroll(); | |
} | |
if (maskLayer.parentNode.id == "UIPage") { | |
eXo.core.UIMaskLayer.enablePageDesktop(false); | |
} | |
} catch (err) { | |
alert(err); | |
} | |
Browser.addOnResizeCallback(maskLayer.id, eXo.core.UIMaskLayer.resizeMaskLayer); | |
return maskLayer; | |
}; | |
UIMaskLayer.prototype.createMaskForFrame = function (blockContainerId, object, opacity) { | |
try { | |
var Browser = eXo.core.Browser; | |
if (typeof (blockContainerId) == "string") blockContainerId = document.getElementById(blockContainerId); | |
var blockContainer = blockContainerId; | |
var maskLayer = document.createElement("div"); | |
blockContainer.appendChild(maskLayer); | |
maskLayer.className = "MaskLayer"; | |
maskLayer.id = object.id + "MaskLayer"; | |
maskLayer.maxZIndex = 3; | |
maskLayer.style.width = blockContainer.offsetWidth + "px"; | |
maskLayer.style.height = blockContainer.offsetHeight + "px"; | |
window.setTimeout(function () { | |
var temp = blockContainer.parentNode; | |
var parentOfBlockContainer; | |
do { | |
parentOfBlockContainer = temp; | |
temp = temp.parentNode; | |
} while (temp && eXo.core.DOMUtil.getStyle(parentOfBlockContainer, "position") === "static"); | |
maskLayer.style.top = eXo.core.Browser.findPosYInContainer(blockContainer, parentOfBlockContainer) + "px"; | |
maskLayer.style.left = eXo.core.Browser.findPosXInContainer(blockContainer, parentOfBlockContainer) + "px"; | |
}, 200); | |
maskLayer.style.zIndex = maskLayer.maxZIndex; | |
if (opacity) { | |
Browser.setOpacity(maskLayer, opacity); | |
} | |
if (object != null) { | |
var tempNextSibling = document.createElement("span"); | |
if (object.nextSibling) { | |
object.parentNode.insertBefore(tempNextSibling, object.nextSibling); | |
} else { | |
object.parentNode.appendChild(tempNextSibling); | |
} | |
maskLayer.nextSiblingOfObject = tempNextSibling; | |
object.style.zIndex = maskLayer.maxZIndex + 1; | |
object.style.display = "block"; | |
blockContainer.appendChild(object); | |
} | |
} catch (err) {} | |
return maskLayer; | |
}; | |
UIMaskLayer.prototype.doScroll = function () { | |
var maskLayer = document.getElementById("MaskLayer"); | |
if (maskLayer) { | |
var offsetParent = maskLayer.offsetParent; | |
if (offsetParent && eXo.core.Browser.findPosX(offsetParent) != 0 || eXo.core.Browser.findPosY(offsetParent) != 0) { | |
maskLayer = document.getElementById("subMaskLayer"); | |
if (!maskLayer) return; | |
} | |
if (document.documentElement && document.documentElement.scrollTop) { | |
maskLayer.style.top = document.documentElement.scrollTop + "px"; | |
} else { | |
maskLayer.style.top = document.body.scrollTop + "px"; | |
} | |
setTimeout("eXo.core.UIMaskLayer.doScroll()", 1); | |
} else if (document.getElementById("subMaskLayer")) { | |
var subMaskLayer = document.getElementById("subMaskLayer"); | |
subMaskLayer.id = "MaskLayer"; | |
eXo.core.UIMaskLayer.doScroll(); | |
} | |
}; | |
UIMaskLayer.prototype.setPosition = function () { | |
var UIMaskLayer = eXo.core.UIMaskLayer; | |
var Browser = eXo.core.Browser; | |
var object = UIMaskLayer.object; | |
if (object && object.previousSibling) { | |
var offsetParent = object.previousSibling.offsetParent; | |
if (offsetParent && (eXo.core.Browser.findPosX(offsetParent) != 0 || eXo.core.Browser.findPosY(offsetParent) != 0)) { | |
eXo.portal.UIMaskWorkspace.resetPosition(); | |
} | |
} | |
var blockContainer = UIMaskLayer.blockContainer; | |
var position = UIMaskLayer.position; | |
object.style.position = "absolute"; | |
var left; | |
var top; | |
var topPos; | |
if (document.documentElement && document.documentElement.scrollTop) { | |
topPos = document.documentElement.scrollTop; | |
} else { | |
topPos = document.body.scrollTop; | |
} | |
switch (position) { | |
case "TOP-LEFT": | |
top = topPos; | |
left = 0; | |
break; | |
case "TOP-RIGHT": | |
top = topPos; | |
left = blockContainer.offsetWidth - object.offsetWidth; | |
break; | |
case "TOP-CENTER": | |
top = topPos; | |
left = (blockContainer.offsetWidth - object.offsetWidth) / 2; | |
break; | |
case "BOTTOM-LEFT": | |
left = 0; | |
top = Browser.getBrowserHeight() - object.offsetHeight + topPos; | |
break; | |
case "BOTTOM-CENTER": | |
left = (blockContainer.offsetWidth - object.offsetWidth) / 2; | |
top = Browser.getBrowserHeight() - object.offsetHeight + topPos; | |
break; | |
case "BOTTOM-RIGHT": | |
left = blockContainer.offsetWidth - object.offsetWidth; | |
top = Browser.getBrowserHeight() - object.offsetHeight + topPos; | |
break; | |
default: | |
left = (blockContainer.offsetWidth - object.offsetWidth) / 2; | |
top = (Browser.getBrowserHeight() - object.offsetHeight) / 2 + topPos; | |
} | |
if ((top + object.offsetHeight) > topPos + Browser.getBrowserHeight()) { | |
top = topPos + Browser.getBrowserHeight() - object.offsetHeight; | |
} | |
object.style.left = left + "px"; | |
object.style.top = top + "px"; | |
}; | |
UIMaskLayer.prototype.removeMask = function (maskLayer) { | |
if (maskLayer) { | |
var parentNode = maskLayer.parentNode; | |
maskLayer.nextSibling.style.display = "none"; | |
maskLayer.nextSiblingOfObject.parentNode.insertBefore(maskLayer.nextSibling, maskLayer.nextSiblingOfObject); | |
maskLayer.nextSiblingOfObject.parentNode.removeChild(maskLayer.nextSiblingOfObject); | |
maskLayer.nextSiblingOfObject = null; | |
parentNode.removeChild(maskLayer); | |
} | |
}; | |
UIMaskLayer.prototype.enablePageDesktop = function (enabled) { | |
var pageDesktop = document.getElementById("UIPageDesktop"); | |
if (pageDesktop) { | |
if (enabled) { | |
pageDesktop.style.zIndex = ""; | |
} else { | |
pageDesktop.style.zIndex = "-1"; | |
} | |
} | |
}; | |
UIMaskLayer.prototype.resizeMaskLayer = function () { | |
var maskLayer = document.getElementById("MaskLayer"); | |
if (maskLayer) { | |
var offsetParent = maskLayer.offsetParent; | |
if (offsetParent && (eXo.core.Browser.findPosX(offsetParent) != 0 || eXo.core.Browser.findPosY(offsetParent) != 0)) { | |
maskLayer = document.getElementById("subMaskLayer"); | |
if (!maskLayer) return; | |
offsetParent = maskLayer.offsetParent; | |
} | |
} | |
if (maskLayer && offsetParent && eXo.core.Browser.findPosX(offsetParent) == 0 && eXo.core.Browser.findPosY(offsetParent) == 0) { | |
maskLayer.style.width = eXo.core.Browser.getBrowserWidth() + "px"; | |
maskLayer.style.height = eXo.core.Browser.getBrowserHeight() + "px"; | |
} | |
}; | |
eXo.core.UIMaskLayer = new UIMaskLayer(); | |
function Skin() {}; | |
Skin.prototype.addSkin = function (componentId, url) { | |
var skin = document.getElementById(componentId); | |
if (skin != null) return; | |
var link = document.createElement('link'); | |
link.setAttribute('id', componentId); | |
link.setAttribute('rel', 'stylesheet'); | |
link.setAttribute('type', 'text/css'); | |
link.setAttribute('href', url); | |
var head = document.getElementsByTagName("head")[0]; | |
head.appendChild(link); | |
}; | |
Skin.prototype.addCoreSkin = function (componentId, url) { | |
if (document.getElementById(componentId) == null) { | |
var coreSkin = document.getElementById("CoreSkin"); | |
var head = coreSkin.parentNode; | |
var link = document.createElement('link'); | |
link.setAttribute('id', componentId); | |
link.setAttribute('rel', 'stylesheet'); | |
link.setAttribute('type', 'text/css'); | |
link.setAttribute('href', url); | |
head.insertBefore(link, coreSkin); | |
} | |
}; | |
Skin.prototype.addApplicationSkin = function (componentId, url) { | |
if (document.getElementById(componentId) == null) { | |
var coreSkin = document.getElementById("PortalSkin"); | |
var head = coreSkin.parentNode; | |
var link = document.createElement('link'); | |
link.setAttribute('id', componentId); | |
link.setAttribute('rel', 'stylesheet'); | |
link.setAttribute('type', 'text/css'); | |
link.setAttribute('href', url); | |
head.insertBefore(link, coreSkin); | |
} | |
}; | |
if (!eXo.core.Skin) { | |
eXo.core.Skin = new Skin(); | |
}; | |
function DragDropEvent(clickObject, dragObject) { | |
this.clickObject = clickObject; | |
if (dragObject && dragObject != null) { | |
this.dragObject = dragObject; | |
} else { | |
this.dragObject = clickObject; | |
} | |
this.foundTargetObject = null; | |
this.lastFoundTargetObject = null; | |
this.junkMove = false; | |
if (eXo.core.I18n.isLT() && isNaN(parseInt(this.dragObject.style.left))) this.dragObject.style.left = "0px"; | |
if (eXo.core.I18n.isRT() && isNaN(parseInt(this.dragObject.style.right))) this.dragObject.style.right = "0px"; | |
if (isNaN(parseInt(this.dragObject.style.top))) this.dragObject.style.top = "0px"; | |
}; | |
DragDropEvent.prototype.update = function (foundTargetObject, junkMove) { | |
this.lastFoundTargetObject = this.foundTargetObject; | |
this.foundTargetObject = foundTargetObject; | |
this.junkMove = junkMove; | |
} | |
DragDropEvent.prototype.isJunkMove = function () { | |
return this.junkMove; | |
}; | |
function DragDrop() { | |
this.dropableTargets = null; | |
this.dndEvent = null; | |
this.initCallback = null; | |
this.dragCallback = null; | |
this.dropCallback = null; | |
this.destroyCallback = null; | |
this.isJunkMoveCallback = null; | |
}; | |
DragDrop.prototype.init = function (dropableTargets, clickObject, dragObject, evt) { | |
if (evt && evt.preventDefault) evt.preventDefault(); | |
eXo.core.Mouse.init(evt); | |
this.dropableTargets = dropableTargets; | |
var dndEvent = this.dndEvent = new DragDropEvent(clickObject, dragObject); | |
document.onmousemove = this.onMouseMove; | |
document.onmouseup = this.onDrop; | |
document.onmouseout = this.onCancel; | |
document.onkeypress = this.onKeyPressEvt; | |
if (this.initCallback != null) { | |
this.initCallback(dndEvent); | |
} | |
}; | |
DragDrop.prototype.onKeyPressEvt = function (evt) { | |
if (!evt) evt = window.event; | |
if (evt.keyCode == 27) eXo.core.DragDrop.onDrop(evt); | |
} | |
DragDrop.prototype.onMouseMove = function (evt) { | |
eXo.core.Mouse.update(evt); | |
var dndEvent = eXo.core.DragDrop.dndEvent; | |
dndEvent.backupMouseEvent = evt; | |
var dragObject = dndEvent.dragObject; | |
var y = parseInt(dragObject.style.top); | |
var x = eXo.core.I18n.isRT() ? parseInt(dragObject.style.right) : parseInt(dragObject.style.left); | |
if (eXo.core.I18n.isLT()) dragObject.style["left"] = x + eXo.core.Mouse.deltax + "px"; | |
else dragObject.style["right"] = x - eXo.core.Mouse.deltax + "px"; | |
dragObject.style["top"] = y + eXo.core.Mouse.deltay + "px"; | |
if (eXo.core.DragDrop.dragCallback != null) { | |
var foundTarget = eXo.core.DragDrop.findDropableTarget(dndEvent, eXo.core.DragDrop.dropableTargets, evt); | |
var junkMove = eXo.core.DragDrop.isJunkMove(dragObject, foundTarget); | |
dndEvent.update(foundTarget, junkMove); | |
eXo.core.DragDrop.dragCallback(dndEvent); | |
} | |
return false; | |
}; | |
DragDrop.prototype.onDrop = function (evt) { | |
if (!evt) evt = window.event; | |
if (eXo.core.DragDrop.dropCallback != null) { | |
var dndEvent = eXo.core.DragDrop.dndEvent; | |
dndEvent.backupMouseEvent = evt; | |
var dragObject = dndEvent.dragObject; | |
var foundTarget = eXo.core.DragDrop.findDropableTarget(dndEvent, eXo.core.DragDrop.dropableTargets, evt); | |
var junkMove = eXo.core.DragDrop.isJunkMove(dragObject, foundTarget); | |
dndEvent.update(foundTarget, junkMove); | |
eXo.core.DragDrop.dropCallback(dndEvent); | |
} | |
eXo.core.DragDrop.destroy(); | |
}; | |
DragDrop.prototype.onCancel = function (evt) { | |
if (eXo.core.DragDrop.cancelCallback) eXo.core.DragDrop.cancelCallback(eXo.core.DragDrop.dndEvent); | |
}; | |
DragDrop.prototype.destroy = function () { | |
if (this.destroyCallback != null) { | |
this.destroyCallback(this.dndEvent); | |
} | |
document.onmousemove = null; | |
document.onmouseup = null; | |
document.onmouseout = null; | |
document.onkeypress = null; | |
this.dndEvent = null; | |
this.dropableTargets = null; | |
this.initCallback = null; | |
this.dragCallback = null; | |
this.dropCallback = null; | |
this.destroyCallback = null; | |
this.isJunkMoveCallback = null; | |
}; | |
DragDrop.prototype.findDropableTarget = function (dndEvent, dropableTargets, mouseEvent) { | |
if (dropableTargets == null) return null; | |
var mousexInPage = eXo.core.Browser.findMouseXInPage(mouseEvent); | |
var mouseyInPage = eXo.core.Browser.findMouseYInPage(mouseEvent); | |
var clickObject = dndEvent.clickObject; | |
var dragObject = dndEvent.dragObject; | |
var foundTarget = null; | |
var len = dropableTargets.length; | |
for (var i = 0; i < len; i++) { | |
var ele = dropableTargets[i]; | |
if (dragObject != ele && this.isIn(mousexInPage, mouseyInPage, ele)) { | |
if (foundTarget == null) { | |
foundTarget = ele; | |
} else { | |
if (eXo.core.DOMUtil.hasAncestor(ele, foundTarget)) { | |
foundTarget = ele; | |
} | |
} | |
} | |
} | |
return foundTarget; | |
}; | |
DragDrop.prototype.isIn = function (x, y, component) { | |
var componentLeft = eXo.core.Browser.findPosX(component); | |
var componentRight = componentLeft + component.offsetWidth; | |
var componentTop = eXo.core.Browser.findPosY(component); | |
var componentBottom = componentTop + component.offsetHeight; | |
var isOver = false; | |
if ((componentLeft < x) && (x < componentRight)) { | |
if ((componentTop < y) && (y < componentBottom)) { | |
isOver = true; | |
} | |
} | |
return isOver; | |
}; | |
DragDrop.prototype.isJunkMove = function (src, target) { | |
if (this.isJunkMoveCallback != null) { | |
return this.isJunkMoveCallback(src, target); | |
} | |
if (target == null) return true; | |
return false; | |
}; | |
eXo.core.DragDrop = new DragDrop(); | |
var count = 1; | |
function DragDrop2() { | |
var obj = null; | |
DragDrop2.prototype.init = function (o, oRoot) { | |
o.onmousedown = eXo.core.DragDrop2.start; | |
o.root = oRoot && oRoot != null ? oRoot : o; | |
o.root.onmousedown = function () { | |
this.style.zIndex = ++count; | |
} | |
o.root.onDragStart = new Function(); | |
o.root.onDragEnd = new Function(); | |
o.root.onDrag = new Function(); | |
}; | |
DragDrop2.prototype.start = function (e) { | |
if (!e) e = window.event; | |
if (((e.which) && (e.which == 2 || e.which == 3)) || ((e.button) && (e.button == 2))) { | |
return; | |
} | |
var o = obj = this; | |
e = eXo.core.DragDrop2.fixE(e); | |
var y = parseInt(eXo.core.DOMUtil.getStyle(o.root, "top")); | |
var x = parseInt(eXo.core.DOMUtil.getStyle(o.root, "left")); | |
if (isNaN(x)) x = 0; | |
if (isNaN(y)) y = 0; | |
o.lastMouseX = eXo.core.Browser.findMouseXInPage(e); | |
o.lastMouseY = eXo.core.Browser.findMouseYInPage(e); | |
o.root.onDragStart(x, y, o.lastMouseX, o.lastMouseY, e); | |
document.onmousemove = eXo.core.DragDrop2.drag; | |
document.onmouseup = eXo.core.DragDrop2.end; | |
document.onmouseout = eXo.core.DragDrop2.cancel; | |
return false; | |
}; | |
DragDrop2.prototype.drag = function (e) { | |
e = eXo.core.DragDrop2.fixE(e); | |
var o = obj; | |
var ey = eXo.core.Browser.findMouseYInPage(e); | |
var ex = eXo.core.Browser.findMouseXInPage(e); | |
var y = parseInt(eXo.core.DOMUtil.getStyle(o.root, "top")); | |
var x = parseInt(eXo.core.DOMUtil.getStyle(o.root, "left")); | |
if (isNaN(x)) x = 0; | |
if (isNaN(y)) y = 0; | |
var nx, ny; | |
nx = x + (ex - o.lastMouseX); | |
ny = y + (ey - o.lastMouseY); | |
obj.root.style["left"] = nx + "px"; | |
obj.root.style["top"] = ny + "px"; | |
obj.lastMouseX = ex; | |
obj.lastMouseY = ey; | |
obj.root.onDrag(nx, ny, ex, ey, e); | |
return false; | |
}; | |
DragDrop2.prototype.end = function (e) { | |
e = eXo.core.DragDrop2.fixE(e); | |
document.onmousemove = null; | |
document.onmouseup = null; | |
document.onmouseout = null; | |
obj.root.onDragEnd(parseInt(obj.root.style["left"]), parseInt(obj.root.style["top"]), e.clientX, e.clientY); | |
obj = null; | |
}; | |
DragDrop2.prototype.cancel = function (e) { | |
if (obj.root.onCancel) obj.root.onCancel(e); | |
}; | |
DragDrop2.prototype.fixE = function (e) { | |
if (typeof e == 'undefined') e = window.event; | |
if (typeof e.layerX == 'undefined') e.layerX = e.offsetX; | |
if (typeof e.layerY == 'undefined') e.layerY = e.offsetY; | |
return e; | |
}; | |
}; | |
eXo.core.DragDrop2 = new DragDrop2(); | |
function Topic() { | |
this.topics = {}; | |
this.nextListenerInstanceId_ = 0; | |
} | |
Topic.prototype._normalizeTopicName = function (topic) { | |
if (topic.charAt(topic.length - 1) != '/') { | |
topic = topic + "/"; | |
} | |
return topic; | |
} | |
Topic.prototype._getNextListenerInstanceId = function () { | |
return this.nextListenerInstanceId_++; | |
}; | |
Topic.prototype.publish = function (senderId, topicName, message) { | |
topicName = this._normalizeTopicName(topicName); | |
var event = { | |
senderId: senderId, | |
message: message, | |
topic: topicName | |
}; | |
for (var topic in this.topics) { | |
if (topic && topicName.indexOf(topic) === 0) { | |
var callbacks = this.topics[topic]; | |
for (var j = 0; j < callbacks.length; j++) { | |
callback = callbacks[j]; | |
callback["func"](event); | |
} | |
} | |
} | |
} | |
Topic.prototype.isSubscribed = function (topic, func) { | |
topic = this._normalizeTopicName(topic); | |
callbacks = this.topics[topic]; | |
if (!callbacks) return false; | |
for (var i = 0; i < callbacks.length; i++) { | |
callback = callbacks[i]; | |
if (callback["func"] == func) { | |
return true; | |
} | |
} | |
return false; | |
} | |
Topic.prototype.subscribe = function (topic, func) { | |
topic = this._normalizeTopicName(topic); | |
if (this.isSubscribed(topic, func)) return -1; | |
if (!this.topics[topic]) { | |
this.topics[topic] = new Array(); | |
} | |
var id = this._getNextListenerInstanceId(); | |
this.topics[topic][this.topics[topic].length] = { | |
id: id, | |
func: func | |
}; | |
return id; | |
} | |
Topic.prototype.unsubscribe = function (topic, id) { | |
topic = this._normalizeTopicName(topic); | |
callbacks = this.topics[topic]; | |
if (!callbacks) return false; | |
var removed = false; | |
for (var i = 0; i < callbacks.length; i++) { | |
callback = callbacks[i]; | |
if (removed) { | |
callbacks[i - 1] = callbacks[i]; | |
} | |
if (callback["id"] == id) { | |
delete callbacks[i]; | |
removed = true; | |
} | |
} | |
if (removed) { | |
callbacks.length = callbacks.length - 1; | |
} | |
return removed; | |
} | |
Topic.prototype.initCometdBridge = function () { | |
eXo.core.Cometd.subscribe("/eXo/topics", function (event) { | |
if (event.data != null && event.data.topic != null && event.data.sender != null && event.data.message != null) { | |
eXo.core.Topic.publish(event.data.sender, event.data.topic, event.data.message); | |
} else { | |
eXo.core.Topic.publish("Topic Cometd bridge", "/eXo/portal/notification", "error in the message received from Cometd:" + event); | |
} | |
}); | |
} | |
eXo.core.Topic = new Topic(); | |
if (!eXo.core.JSON) { | |
JSON = function () { | |
function f(n) { | |
return n < 10 ? '0' + n : n; | |
} | |
Date.prototype.toJSON = function () { | |
return this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z'; | |
}; | |
var m = { | |
'\b': '\\b', | |
'\t': '\\t', | |
'\n': '\\n', | |
'\f': '\\f', | |
'\r': '\\r', | |
'"': '\\"', | |
'\\': '\\\\' | |
}; | |
function stringify(value, whitelist) { | |
var a, i, k, l, r = /["\\\x00-\x1f\x7f-\x9f]/g, | |
v; | |
switch (typeof value) { | |
case 'string': | |
return r.test(value) ? '"' + value.replace(r, function (a) { | |
var c = m[a]; | |
if (c) { | |
return c; | |
} | |
c = a.charCodeAt(); | |
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16); | |
}) + '"' : '"' + value + '"'; | |
case 'number': | |
return isFinite(value) ? String(value) : 'null'; | |
case 'boolean': | |
case 'null': | |
return String(value); | |
case 'object': | |
if (!value) { | |
return 'null'; | |
} | |
if (typeof value.toJSON === 'function') { | |
return stringify(value.toJSON()); | |
} | |
a = []; | |
if (typeof value.length === 'number' && !(value.propertyIsEnumerable('length'))) { | |
l = value.length; | |
for (i = 0; i < l; i += 1) { | |
a.push(stringify(value[i], whitelist) || 'null'); | |
} | |
return '[' + a.join(',') + ']'; | |
} | |
if (whitelist) { | |
l = whitelist.length; | |
for (i = 0; i < l; i += 1) { | |
k = whitelist[i]; | |
if (typeof k === 'string') { | |
v = stringify(value[k], whitelist); | |
if (v) { | |
a.push(stringify(k) + ':' + v); | |
} | |
} | |
} | |
} else { | |
for (k in value) { | |
if (typeof k === 'string') { | |
v = stringify(value[k], whitelist); | |
if (v) { | |
a.push(stringify(k) + ':' + v); | |
} | |
} | |
} | |
} | |
return '{' + a.join(',') + '}'; | |
} | |
} | |
return { | |
stringify: stringify, | |
parse: function (text, filter) { | |
var j; | |
function walk(k, v) { | |
var i, n; | |
if (v && typeof v === 'object') { | |
for (i in v) { | |
if (Object.prototype.hasOwnProperty.apply(v, [i])) { | |
n = walk(i, v[i]); | |
if (n !== undefined) { | |
v[i] = n; | |
} | |
} | |
} | |
} | |
return filter(k, v); | |
} | |
if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { | |
j = eval('(' + text + ')'); | |
return typeof filter === 'function' ? walk('', j) : j; | |
} | |
throw new SyntaxError('parseJSON'); | |
} | |
}; | |
}(); | |
eXo.core.JSON = JSON; | |
} | |
function Cometd() { | |
this._connected = false; | |
this._polling = false; | |
this._connecting = false; | |
this.currentTransport = null; | |
this.url = '/cometd/cometd'; | |
this.id = null; | |
this.exoId = null; | |
this.exoToken = null; | |
var Browser = eXo.core.Browser; | |
this.clientId = Browser.getCookie('cometdClientID') || false; | |
this.messageId = 0; | |
this.batch = 0; | |
this._subscriptions = []; | |
this._messageQ = []; | |
this._connectionReadyCallbacks = []; | |
this._maxInterval = 5 * 1000; | |
this._backoffInterval = 1000; | |
this._maxTry = 5; | |
this._tryToOpenTunnelCnt = 0; | |
this._retryInterval = 0; | |
this._multiClientsDetectCnt = 0; | |
} | |
Cometd.prototype.init = function (forceDisconnect) { | |
this._tryToOpenTunnelCnt = 0; | |
if ((!forceDisconnect && this._connected) || this._connecting) { | |
return; | |
} | |
if (!this.currentTransport) { | |
this.currentTransport = new eXo.portal.LongPollTransport(); | |
this.currentTransport.init(this); | |
} | |
if (this.clientId) this.currentTransport.initTunnel(); | |
else this.currentTransport.initHandshake(); | |
}; | |
Cometd.prototype.addOnConnectionReadyCallback = function (handle) { | |
if (handle) { | |
this._connectionReadyCallbacks.push(handle); | |
} | |
}; | |
Cometd.prototype.removeOnConnectionReadtCallback = function (handle) { | |
for (var i = 0; i < this._connectionReadyCallbacks.length; i++) { | |
if (this._connectionReadyCallbacks[i] == handle) { | |
this._connectionReadyCallbacks[i] = this._connectionReadyCallbacks[this._connectionReadyCallbacks.length - 1]; | |
this._connectionReadyCallbacks.pop(); | |
break; | |
} | |
} | |
}; | |
Cometd.prototype.deliver = function (messages) { | |
messages.each(this._deliver, this); | |
return messages; | |
} | |
Cometd.prototype.isConnected = function () { | |
return this._connected; | |
} | |
Cometd.prototype._deliver = function (message) { | |
if (!message['channel']) { | |
if (message['success'] !== true) { | |
return; | |
} | |
} | |
this.lastMessage = message; | |
if (message.advice) { | |
this.adviceBackup = this.advice; | |
this.advice = message.advice; | |
this.multiClients = message.advice['multiple-clients']; | |
if (this.multiClients) { | |
this._multiClientsDetectCnt++; | |
if (this._multiClientsDetectCnt == 1) {} | |
} else { | |
this._multiClientsDetectCnt = 0; | |
this.resetRetryInterval(); | |
} | |
} | |
if ((message['channel']) && (message.channel.length > 5) && (message.channel.substr(0, 5) == '/meta')) { | |
switch (message.channel) { | |
case '/meta/connect': | |
if (message.successful && !this._connected) { | |
this._connected = true; | |
this.endBatch(); | |
} | |
break; | |
case '/meta/subscribe': | |
if (!message.successful) { | |
alert('todo manage error subscription'); | |
return; | |
} | |
break; | |
case '/meta/unsubscribe': | |
if (!message.successful) { | |
alert('todo manage error unsubscription'); | |
return; | |
} | |
break; | |
} | |
} | |
if (message.data) { | |
var tname = message.channel; | |
var def = this._subscriptions[tname]; | |
if (def) def(message); | |
} | |
} | |
Cometd.prototype._sendMessage = function (message) { | |
if (this.currentTransport && this._connected && this.batch == 0) { | |
return this.currentTransport.sendMessages([message]); | |
} else { | |
this._messageQ.push(message); | |
} | |
} | |
Cometd.prototype.subscribe = function (channel, callback) { | |
if (callback) { | |
var tname = channel; | |
var subs = this._subscriptions[tname]; | |
if (!subs || subs.length == 0) { | |
subs = []; | |
var message = { | |
channel: '/meta/subscribe', | |
subscription: channel, | |
exoId: this.exoId, | |
exoToken: this.exoToken | |
} | |
this._sendMessage(message); | |
} | |
this._subscriptions[tname] = callback; | |
} | |
} | |
Cometd.prototype.unsubscribe = function (channel) { | |
var tname = channel; | |
if (this._subscriptions[tname]) { | |
this._subscriptions[tname] = null; | |
} | |
this._sendMessage({ | |
channel: '/meta/unsubscribe', | |
subscription: channel, | |
exoId: this.exoId, | |
exoToken: this.exoToken | |
}); | |
} | |
Cometd.prototype.startBatch = function () { | |
this.batch++; | |
} | |
Cometd.prototype.increaseRetryInterval = function () { | |
this.advice = this.advice || {}; | |
if (!this.advice.interval || (this.advice.interval && this.advice.interval > this._maxInterval)) { | |
this.resetRetryInterval(); | |
} else { | |
this._retryInterval += this._backoffInterval; | |
this.advice.interval = this._retryInterval; | |
} | |
} | |
Cometd.prototype.resetRetryInterval = function () { | |
if (this.advice) this.advice.interval = 0; | |
this._retryInterval = 0; | |
} | |
Cometd.prototype.endBatch = function () { | |
this._tryToOpenTunnelCnt = 0; | |
this._connecting = false; | |
for (var i = 0; i < this._connectionReadyCallbacks.length; i++) { | |
var handler = this._connectionReadyCallbacks[i]; | |
if (handler) { | |
handler(); | |
} | |
} | |
if (--this.batch <= 0 && this.currentTransport && this._connected) { | |
this.batch = 0; | |
var messages = this._messageQ; | |
this._messageQ = []; | |
if (messages.length > 0) { | |
this.currentTransport.sendMessages(messages); | |
} | |
} | |
} | |
Cometd.prototype.disconnect = function () { | |
this._tryToOpenTunnelCnt = 0; | |
this._subscriptions.each(this.unsubscribe, this); | |
this._messageQ = []; | |
if (this.currentTransport) { | |
this.currentTransport.disconnect(); | |
} | |
if (!this._polling) this._connected = false; | |
} | |
Cometd.prototype._backoff = function () { | |
if (!this.advice || !this.advice.interval) { | |
this.advice = { | |
reconnect: 'retry', | |
interval: 0 | |
}; | |
} | |
this.increaseRetryInterval(); | |
} | |
function LongPollTransport() { | |
var instance = new Object(); | |
instance.init = function (cometd) { | |
this._connectionType = 'long-polling'; | |
this._cometd = cometd; | |
} | |
instance.startup = function () { | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url); | |
request.onSuccess = this._cometd.deliver; | |
request.process(); | |
} | |
instance.initHandshake = function () { | |
var message = { | |
channel: '/meta/handshake', | |
id: this._cometd.messageId++, | |
exoId: this._cometd.exoId, | |
exoToken: this._cometd.exoToken | |
}; | |
var query = 'message=' + eXo.core.JSON.stringify(message); | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url, query); | |
request.onSuccess = function (request) { | |
this.finishInitHandshake(request.evalResponse()); | |
}.bind(this); | |
request.onError = function (err) { | |
throw (new Error('request Error, need to manage this error')); | |
}.bind(this); | |
request.process(); | |
} | |
instance.finishInitHandshake = function (data) { | |
data = data[0]; | |
this._cometd.handshakeReturn = data; | |
if (data['advice']) { | |
this._cometd.advice = data.advice; | |
} | |
if (!data.successful) { | |
if (this._cometd.advice && this._cometd.advice['reconnect'] == 'none') { | |
return; | |
} | |
if (this._cometd.advice && this._cometd.advice['interval'] && this._cometd.advice.interval > 0) { | |
setTimeout(function () { | |
eXo.core.Cometd.init(); | |
}, this._cometd._retryInterval); | |
} else { | |
this._cometd.init(this.url, this._props); | |
} | |
return; | |
} | |
if (data.version < this.minimumVersion) { | |
return; | |
} | |
this._cometd.clientId = data.clientId; | |
eXo.core.Browser.setCookie('cometdClientID', this._cometd.clientId, 1); | |
this.initTunnel(); | |
} | |
instance.initTunnel = function () { | |
var message = { | |
channel: '/meta/connect', | |
clientId: this._cometd.clientId, | |
connectionType: this._connectionType, | |
id: this._cometd.messageId++ | |
}; | |
this.openTunnelWith({ | |
message: eXo.core.JSON.stringify(message) | |
}); | |
} | |
instance.openTunnelWith = function (content, url) { | |
this._cometd._polling = true; | |
var query = 'message=' + content.message; | |
var request = new eXo.portal.AjaxRequest('POST', (url || this._cometd.url), query); | |
request.timeout = 180000; | |
request.onSuccess = function (request) { | |
this._cometd._polling = false; | |
if (request.status >= 200 && request.status < 300) { | |
this._cometd.deliver(request.evalResponse()); | |
} else this._cometd._backoff(); | |
this.tunnelReq = null; | |
this.tunnelCollapse(); | |
}.bind(this); | |
request.onError = function (err) { | |
this.tunnelReq = null; | |
this._cometd._polling = false; | |
this._cometd._tryToOpenTunnelCnt++; | |
this.tunnelCollapse(); | |
throw (new Error('tunnel opening failed')); | |
}.bind(this); | |
request.process(); | |
} | |
instance.tunnelCollapse = function () { | |
if (this._cometd._tryToOpenTunnelCnt > this._cometd._maxTry) { | |
return; | |
} | |
if (!this._cometd._polling) { | |
this._cometd._polling = false; | |
if (this._cometd['advice']) { | |
if (this._cometd.advice['reconnect'] == 'none') { | |
return; | |
} | |
if ((this._cometd.advice['interval']) && (this._cometd.advice.interval > 0)) { | |
var transport = this; | |
setTimeout(function () { | |
transport._connect(); | |
}, this._cometd._retryInterval); | |
this._cometd.increaseRetryInterval(); | |
} else { | |
this._connect(); | |
this._cometd.increaseRetryInterval(); | |
} | |
} else { | |
this._connect(); | |
this._cometd.increaseRetryInterval(); | |
} | |
} | |
} | |
instance._connect = function () { | |
if ((this._cometd['advice']) && (this._cometd.advice['reconnect'] == 'handshake')) { | |
this._cometd.clientId = null; | |
this._cometd.init(this._cometd.url, this._cometd._props); | |
} else if (this._cometd._connected) { | |
this.openTunnelWith({ | |
message: eXo.core.JSON.stringify([{ | |
channel: '/meta/connect', | |
connectionType: this._connectionType, | |
clientId: this._cometd.clientId, | |
timestamp: this.lastTimestamp, | |
id: '' + this._cometd.messageId++ | |
}]) | |
}); | |
} | |
} | |
instance.sendMessages = function (messages) { | |
for (var i = 0; i < messages.length; i++) { | |
messages[i].clientId = this._cometd.clientId; | |
messages[i].id = '' + this._cometd.messageId++; | |
} | |
var query = 'message=' + eXo.core.JSON.stringify(messages); | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url, query); | |
request.onSuccess = function (request) { | |
this._cometd.deliver(request.evalResponse()); | |
}.bind(this); | |
request.onError = function (err) { | |
throw (new Error('error sending the message')); | |
}.bind(this); | |
request.process(); | |
} | |
instance.disconnect = function () { | |
var query = 'message=' + eXo.core.JSON.stringify([{ | |
channel: '/meta/disconnect', | |
clientId: this._cometd.clientId, | |
id: '' + this._cometd.messageId++ | |
}]); | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url, query); | |
request.process(); | |
} | |
return instance; | |
} | |
eXo.core.Cometd = new Cometd(); | |
eXo.portal.LongPollTransport = LongPollTransport.prototype.constructor; | |
function Spliter() {}; | |
Spliter.prototype.exeRowSplit = function (e, markerobj) { | |
_e = (window.event) ? window.event : e; | |
this.posY = _e.clientY; | |
var marker = (typeof (markerobj) == "string") ? document.getElementById(markerobj) : markerobj; | |
this.beforeArea = eXo.core.DOMUtil.findPreviousElementByTagName(marker, "div"); | |
this.afterArea = eXo.core.DOMUtil.findNextElementByTagName(marker, "div"); | |
this.beforeArea.style.height = this.beforeArea.offsetHeight + "px"; | |
this.afterArea.style.height = this.afterArea.offsetHeight + "px"; | |
this.beforeY = this.beforeArea.offsetHeight; | |
this.afterY = this.afterArea.offsetHeight; | |
document.onmousemove = eXo.core.Spliter.adjustHeight; | |
document.onmouseup = eXo.core.Spliter.clear; | |
}; | |
Spliter.prototype.adjustHeight = function (evt) { | |
evt = (window.event) ? window.event : evt; | |
var Spliter = eXo.core.Spliter; | |
var delta = evt.clientY - Spliter.posY; | |
var afterHeight = (Spliter.afterY - delta); | |
var beforeHeight = (Spliter.beforeY + delta); | |
if (beforeHeight <= 0 || afterHeight <= 0) return; | |
Spliter.beforeArea.style.height = beforeHeight + "px"; | |
Spliter.afterArea.style.height = afterHeight + "px"; | |
}; | |
Spliter.prototype.clear = function () { | |
document.onmousemove = null; | |
}; | |
eXo.core.Spliter = new Spliter(); | |
function AnimationSlider() { | |
this.timerlen = 5; | |
this.slideAniLen = 1000; | |
this.timerID = new Array(); | |
this.startTime = new Array(); | |
this.obj = new Array(); | |
this.endHeight = new Array(); | |
this.moving = new Array(); | |
this.endSlideUpCallback = new Array(); | |
this.dir = new Array(); | |
} | |
AnimationSlider.prototype.slidedown = function (objname) { | |
if (this.moving[objname]) return; | |
if (document.getElementById(objname).style.display != "none") return; | |
this.moving[objname] = true; | |
this.dir[objname] = "down"; | |
this.startslide(objname); | |
} | |
AnimationSlider.prototype.slidedownup = function (objname, endSlideUpCallback) { | |
this.slidedown(objname); | |
this.endSlideUpCallback[objname] = endSlideUpCallback; | |
setTimeout("eXo.core.Notification.AnimationSlider.slideup('" + objname + "')", 3000); | |
} | |
AnimationSlider.prototype.slideup = function (objname) { | |
if (this.moving[objname]) return; | |
if (document.getElementById(objname).style.display == "none") return; | |
this.moving[objname] = true; | |
this.dir[objname] = "up"; | |
this.startslide(objname); | |
} | |
AnimationSlider.prototype.startslide = function (objname) { | |
this.obj[objname] = document.getElementById(objname); | |
this.endHeight[objname] = parseInt(this.obj[objname].style.height); | |
this.startTime[objname] = (new Date()).getTime(); | |
if (this.dir[objname] == "down") { | |
this.obj[objname].style.height = "1px"; | |
} | |
this.obj[objname].style.display = "block"; | |
this.timerID[objname] = setInterval('eXo.core.Notification.AnimationSlider.slidetick(\'' + objname + '\');', this.timerlen); | |
} | |
AnimationSlider.prototype.slidetick = function (objname) { | |
var elapsed = (new Date()).getTime() - this.startTime[objname]; | |
if (elapsed > this.slideAniLen) this.endSlide(objname); | |
else { | |
var before = "before:" + this.obj[objname].id + "-" + this.obj[objname].style.height + "-"; | |
var d = Math.round(elapsed / this.slideAniLen * this.endHeight[objname]); | |
if (this.dir[objname] == "up") d = this.endHeight[objname] - d; | |
this.obj[objname].style.height = d + "px"; | |
} | |
return; | |
} | |
AnimationSlider.prototype.endSlide = function (objname) { | |
clearInterval(this.timerID[objname]); | |
if (this.dir[objname] == "up") { | |
this.obj[objname].style.display = "none"; | |
if (this.endSlideUpCallback[objname]) { | |
this.endSlideUpCallback[objname](objname); | |
} | |
} | |
this.obj[objname].style.height = this.endHeight[objname] + "px"; | |
delete(this.moving[objname]); | |
delete(this.timerID[objname]); | |
delete(this.startTime[objname]); | |
delete(this.endHeight[objname]); | |
delete(this.obj[objname]); | |
delete(this.dir[objname]); | |
return; | |
} | |
function Notification() { | |
this.msgId = 0; | |
if (eXo.core.Topic != null) { | |
eXo.core.Topic.subscribe("/eXo/portal/notification", function (event) { | |
eXo.core.Notification.addMessage(event.message); | |
}) | |
} | |
} | |
Notification.prototype.deleteBox = function (objname) { | |
var el = document.getElementById(objname); | |
el.parentNode.removeChild(el); | |
} | |
Notification.prototype.addMessage = function (msg) { | |
var currBoxId = "messageBox_" + this.msgId++; | |
var msgEl = document.createElement('div'); | |
msgEl.id = currBoxId; | |
msgEl.style.width = "200px"; | |
msgEl.style.height = "75px"; | |
msgEl.style.display = "none"; | |
msgEl.className = "messageBox"; | |
msgEl.innerHTML = "<div id='messageContent'>" + msg + "</div>"; | |
var msgsEl = document.getElementById("msgs"); | |
if (msgsEl == null) { | |
document.body.appendChild(document.createElement('div')).id = "msgs"; | |
msgsEl = document.getElementById("msgs"); | |
} | |
msgsEl.appendChild(msgEl); | |
eXo.core.Notification.AnimationSlider.slidedownup(currBoxId, this.deleteBox); | |
} | |
eXo.core.Notification = new Notification(); | |
eXo.core.Notification.AnimationSlider = new AnimationSlider(); | |
function I18n() { | |
this.init(); | |
} | |
I18n.prototype.init = function () { | |
var html = document.getElementsByTagName('html')[0]; | |
var lang = html.getAttribute('xml:lang') || html.getAttribute('lang') || "en"; | |
var dir = html.getAttribute('dir') || "lt"; | |
this.lang = lang; | |
this.dir = dir; | |
this.orientation = "rtl" == dir ? "rt" : "lt"; | |
this.lt = this.orientation == "lt"; | |
} | |
I18n.prototype.getLanguage = function () { | |
return this.lang; | |
} | |
I18n.prototype.getOrientation = function () { | |
return this.orientation; | |
} | |
I18n.prototype.getDir = function () { | |
return !this.lt; | |
} | |
I18n.prototype.isLT = function () { | |
return this.lt; | |
} | |
I18n.prototype.isRT = function () { | |
return !this.lt; | |
} | |
eXo.core.I18n = new I18n(); | |
eXo.gadget.UIGadget = { | |
createGadget: function (url, id, metadata, userPref, view, hostName, isdev, debug, nocache) { | |
window.gadgets = window.gadgets || {}; | |
eXo.gadgets = window.gadgets; | |
if (!eXo.gadgets || !eXo.gadgets.rpc) { | |
eXo.core.Loader.register('rpc', '1.0.0', true, 0, hostName + '/js/pubsub.js?c=1'); | |
eXo.core.Loader.register('eXo.gadgets.Gadgets', '/eXoResources/javascript/eXo/gadget/Gadgets.js'); | |
eXo.core.Loader.register('eXo.gadgets.ExoBasedUserPrefStore', '/eXoResources/javascript/eXo/gadget/ExoBasedUserPrefStore.js'); | |
} | |
eXo.core.Loader.init("rpc", "eXo.gadgets.Gadgets", "eXo.gadgets.ExoBasedUserPrefStore", eXo.gadget.UIGadget.createCallback, null, arguments); | |
}, | |
createCallback: function (url, id, metadata, userPref, view, hostName, isdev, debug, nocache) { | |
var language = eXo.core.I18n.getLanguage(); | |
gadgets.container.setLanguage(language); | |
var gadget; | |
if (metadata != null) { | |
if (metadata.modulePrefs.height == 0 && view == 'canvas') { | |
metadata.modulePrefs.height = "800px"; | |
} | |
gadget = gadgets.container.createGadget({ | |
specUrl: url, | |
height: metadata.modulePrefs.height, | |
secureToken: metadata.secureToken, | |
view: view | |
}); | |
gadget.metadata = metadata; | |
} else { | |
gadget = gadgets.container.createGadget({ | |
specUrl: url | |
}); | |
} | |
gadget.parentId = id; | |
gadget.debug = debug; | |
gadget.nocache = nocache; | |
gadget.isdev = isdev; | |
gadget.serverBase_ = hostName; | |
gadgets.container.addGadget(gadget); | |
if (userPref != null) gadget.userPrefs_ = userPref; | |
var gadgetBlock = document.getElementById(id); | |
gadgetBlock.innerHTML = "<div id='gadget_" + gadget.id + "' class='UIGadgetContent'> </div>"; | |
gadgets.container.renderGadgets(); | |
var uiGadget = eXo.core.DOMUtil.findAncestorByClass(gadgetBlock, "UIGadget"); | |
if (uiGadget != null) { | |
var isDesktop = false; | |
if (uiGadget.parentNode.className == "UIPageDesktop") { | |
uiGadget.style.position = "absolute"; | |
isDesktop = true; | |
} else uiGadget.style.width = "auto"; | |
eXo.gadget.UIGadget.init(uiGadget, isDesktop, gadget.metadata); | |
} | |
gadgets.pubsubrouter.init(function (id) { | |
return url; | |
}, {}); | |
}, | |
init: function (uiGadget, inDesktop, metadata) { | |
var portletFragment = eXo.core.DOMUtil.findAncestorByClass(uiGadget, "PORTLET-FRAGMENT"); | |
if (portletFragment == null) { | |
uiGadget.onmouseover = eXo.gadget.UIGadget.showGadgetControl; | |
uiGadget.onmouseout = eXo.gadget.UIGadget.hideGadgetControl; | |
} else { | |
var gadgetControl = eXo.core.DOMUtil.findFirstDescendantByClass(uiGadget, "div", "GadgetControl"); | |
gadgetControl.style.display = "block"; | |
var gadgetTitle = eXo.core.DOMUtil.findFirstDescendantByClass(gadgetControl, "span", "GadgetTitle"); | |
gadgetTitle.style.display = "block"; | |
if (metadata && metadata.modulePrefs.title != null && metadata.modulePrefs.title.length > 0) gadgetTitle.innerHTML = metadata.modulePrefs.title; | |
} | |
if (inDesktop) { | |
var dragHandleArea = eXo.core.DOMUtil.findFirstDescendantByClass(uiGadget, "div", "GadgetDragHandleArea"); | |
if (uiGadget.style.zIndex < 0) uiGadget.style.zIndex = 0; | |
eXo.core.DragDrop2.init(dragHandleArea, uiGadget); | |
var uiPageDesktop = document.getElementById("UIPageDesktop"); | |
var offsetHeight = uiPageDesktop.offsetHeight - uiGadget.offsetHeight; | |
var offsetWidth = uiPageDesktop.offsetWidth - uiGadget.offsetWidth; | |
var dragPosX = uiGadget.offsetLeft; | |
var dragPosY = uiGadget.offsetTop; | |
if (dragPosX < 0) uiGadget.style.left = "0px"; | |
if (dragPosY < 0) uiGadget.style.top = "0px"; | |
if (dragPosY > offsetHeight) uiGadget.style.top = offsetHeight + "px"; | |
if (dragPosX > offsetWidth) uiGadget.style.left = offsetWidth + "px"; | |
uiGadget.onDragStart = function (x, y, lastMouseX, lastMouseY, e) { | |
var uiPageDesktop = document.getElementById("UIPageDesktop"); | |
if (uiPageDesktop == null) return; | |
var uiGadgets = eXo.core.DOMUtil.findChildrenByClass(uiPageDesktop, "div", "UIGadget"); | |
for (var i = 0; i < uiGadgets.length; i++) { | |
var uiMask = eXo.core.DOMUtil.findFirstDescendantByClass(uiGadgets[i], "div", "UIMask"); | |
if (uiMask != null) { | |
var gadgetContent = eXo.core.DOMUtil.findFirstDescendantByClass(uiGadgets[i], "div", "gadgets-gadget-content"); | |
uiMask.style.marginTop = -gadgetContent.offsetHeight + "px"; | |
uiMask.style.height = gadgetContent.offsetHeight + "px"; | |
uiMask.style.width = gadgetContent.offsetWidth + "px"; | |
uiMask.style.backgroundColor = "white"; | |
eXo.core.Browser.setOpacity(uiMask, 3); | |
uiMask.style.display = "block"; | |
} | |
} | |
} | |
uiGadget.onDrag = function (nx, ny, ex, ey, e) { | |
if (nx < 0) uiGadget.style.left = "0px"; | |
if (ny < 0) uiGadget.style.top = "0px"; | |
} | |
uiGadget.onDragEnd = function (x, y, clientX, clientY) { | |
var uiPageDesktop = document.getElementById("UIPageDesktop"); | |
var uiGadgets = eXo.core.DOMUtil.findChildrenByClass(uiPageDesktop, "div", "UIGadget"); | |
for (var i = 0; i < uiGadgets.length; i++) { | |
var uiMask = eXo.core.DOMUtil.findFirstDescendantByClass(uiGadgets[i], "div", "UIMask"); | |
if (uiMask) { | |
uiMask.style.display = "none"; | |
} | |
} | |
var offsetHeight = uiPageDesktop.offsetHeight - uiGadget.offsetHeight; | |
var offsetWidth = uiPageDesktop.offsetWidth - uiGadget.offsetWidth; | |
var dragPosX = uiGadget.offsetLeft; | |
var dragPosY = uiGadget.offsetTop; | |
if (dragPosX < 0) uiGadget.style.left = "0px"; | |
if (dragPosY < 0) uiGadget.style.top = "0px"; | |
if (dragPosY > offsetHeight) uiGadget.style.top = offsetHeight + "px"; | |
if (dragPosX > offsetWidth) uiGadget.style.left = offsetWidth + "px"; | |
eXo.gadget.UIGadget.saveWindowProperties(uiGadget); | |
} | |
} | |
}, | |
showGadgetControl: function (e) { | |
if (!e) e = window.event; | |
e.cancelBubble = true; | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiGadget = this; | |
var gadgetControl = DOMUtil.findFirstDescendantByClass(uiGadget, "div", "GadgetControl"); | |
gadgetControl.style.visibility = "visible"; | |
var uiPageDesktop = DOMUtil.findAncestorByClass(uiGadget, "UIPageDesktop"); | |
if (uiPageDesktop) { | |
var dragHandleArea = DOMUtil.findFirstDescendantByClass(gadgetControl, "div", "GadgetTitle"); | |
} | |
}, | |
hideGadgetControl: function (e) { | |
if (!e) e = window.event; | |
e.cancelBubble = true; | |
var uiGadget = this; | |
var gadgetControl = eXo.core.DOMUtil.findFirstDescendantByClass(uiGadget, "div", "GadgetControl"); | |
gadgetControl.style.visibility = "hidden"; | |
uiGadget.style.border = "none"; | |
}, | |
editGadget: function (id) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiapp = document.getElementById(id); | |
var id = eXo.core.DOMUtil.findFirstDescendantByClass(uiapp, "iframe", "gadgets-gadget"); | |
var tempId = id.id.split('_')[2]; | |
gadgets.container.getGadget(tempId).handleOpenUserPrefsDialog(); | |
}, | |
minimizeGadget: function (selectedElement) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiGadget = DOMUtil.findAncestorByClass(selectedElement, "UIGadget"); | |
var portletFrag = DOMUtil.findAncestorByClass(uiGadget, "PORTLET-FRAGMENT"); | |
if (!portletFrag) return; | |
var gadgetApp = DOMUtil.findFirstChildByClass(uiGadget, "div", "GadgetApplication"); | |
var minimized = false; | |
if (gadgetApp.style.display != "none") { | |
minimized = true; | |
gadgetApp.style.display = "none"; | |
DOMUtil.replaceClass(selectedElement, "MinimizeGadget", "RestoreGadget"); | |
selectedElement.title = selectedElement.getAttribute("unminiTitle"); | |
} else { | |
minimized = false; | |
gadgetApp.style.display = "block"; | |
DOMUtil.replaceClass(selectedElement, "RestoreGadget", "MinimizeGadget"); | |
selectedElement.title = selectedElement.getAttribute("miniTitle"); | |
} | |
var compId = portletFrag.parentNode.id; | |
var uicomp = DOMUtil.findAncestorByClass(uiGadget, "UIDashboard"); | |
var href = eXo.env.server.portalBaseURL + "?portal:componentId=" + compId; | |
href += "&portal:type=action&uicomponent=" + uicomp.id; | |
href += "&op=MinimizeGadget"; | |
href += "&minimized=" + minimized; | |
href += "&objectId=" + uiGadget.id + "&ajaxRequest=true"; | |
ajaxGet(href); | |
if (uiGadget.minimizeCallback) uiGadget.minimizeCallback(portletFrag.parentNode.id); | |
}, | |
maximizeGadget: function (selectedElement) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiGadget = DOMUtil.findAncestorByClass(selectedElement, "UIGadget"); | |
var portletFrag = DOMUtil.findAncestorByClass(uiGadget, "PORTLET-FRAGMENT"); | |
if (!portletFrag) return; | |
var compId = portletFrag.parentNode.id; | |
var uicomp = DOMUtil.findAncestorByClass(uiGadget, "UIDashboard"); | |
var compDisplay = DOMUtil.findAncestorByClass(uiGadget, "UIDashboardContainer"); | |
var maximize = compDisplay ? "maximize" : "unmaximize"; | |
var href = eXo.env.server.portalBaseURL + "?portal:componentId=" + compId; | |
href += "&portal:type=action&uicomponent=" + uicomp.id; | |
href += "&op=MaximizeGadget"; | |
href += "&maximize=" + maximize; | |
href += "&objectId=" + uiGadget.id + "&ajaxRequest=true"; | |
ajaxGet(href, true); | |
}, | |
deleteGadget: function (selectedElement) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiPage = DOMUtil.findAncestorByClass(selectedElement, "UIPage"); | |
var uiGadget = DOMUtil.findAncestorByClass(selectedElement, "UIGadget"); | |
var containerBlockId; | |
var portletFragment = DOMUtil.findAncestorByClass(uiGadget, "PORTLET-FRAGMENT"); | |
if (portletFragment != null) { | |
var compId = portletFragment.parentNode.id; | |
var uicomp = DOMUtil.findAncestorByClass(uiGadget, "UIDashboard").id; | |
if (confirm(this.confirmDeleteGadget)) { | |
var href = eXo.env.server.portalBaseURL + "?portal:componentId=" + compId; | |
href += "&portal:type=action&uicomponent=" + uicomp; | |
href += "&op=DeleteGadget"; | |
href += "&objectId=" + uiGadget.id + "&ajaxRequest=true"; | |
var uiDashboardCont = DOMUtil.findAncestorByClass(uiGadget, "UIDashboardContainer"); | |
if (uiDashboardCont) { | |
ajaxGet(href); | |
DOMUtil.removeElement(uiGadget); | |
if (!DOMUtil.findFirstDescendantByClass(uiDashboardCont, "div", "UIGadget")) { | |
DOMUtil.findFirstDescendantByClass(uiDashboardCont, "div", "NoGadget").style.display = "block"; | |
} | |
} else { | |
ajaxGet(href); | |
} | |
} | |
} else { | |
var uiPageIdNode = DOMUtil.findFirstDescendantByClass(uiPage, "div", "id"); | |
containerBlockId = uiPageIdNode.innerHTML; | |
if (confirm(this.confirmDeleteGadget)) { | |
var params = [{ | |
name: "objectId", | |
value: uiGadget.id | |
}]; | |
var result = ajaxAsyncGetRequest(eXo.env.server.createPortalURL(containerBlockId, "DeleteGadget", true, params), false); | |
if (result == "OK") { | |
DOMUtil.removeElement(uiGadget); | |
} | |
} | |
} | |
}, | |
saveWindowProperties: function (object) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiPage = DOMUtil.findAncestorByClass(object, "UIPage"); | |
var uiPageIdNode = DOMUtil.findFirstDescendantByClass(uiPage, "div", "id"); | |
containerBlockId = uiPageIdNode.innerHTML; | |
var gadgetApp = DOMUtil.findFirstDescendantByClass(object, "div", "GadgetApplication"); | |
var params = [{ | |
name: "objectId", | |
value: object.id | |
}, { | |
name: "posX", | |
value: object.offsetLeft | |
}, { | |
name: "posY", | |
value: object.offsetTop | |
}, { | |
name: "zIndex", | |
value: object.style.zIndex | |
}]; | |
ajaxAsyncGetRequest(eXo.env.server.createPortalURL(containerBlockId, "SaveGadgetProperties", true, params), false); | |
}, | |
resizeFullHeight: function (componentId) { | |
var gadget = document.getElementById(componentId); | |
var portlet = eXo.core.DOMUtil.findAncestorByClass(gadget, "PORTLET-FRAGMENT"); | |
eXo.core.Browser.fillUpFreeSpace(portlet); | |
} | |
} | |
function PortletResponse(responseDiv) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var div = eXo.core.DOMUtil.getChildrenByTagName(responseDiv, "div"); | |
this.portletId = div[0].innerHTML; | |
this.portletData = div[1].innerHTML; | |
this.blocksToUpdate = null; | |
var blocks = DOMUtil.findChildrenByClass(div[1], "div", "BlockToUpdate"); | |
if (blocks.length > 0) { | |
this.blocksToUpdate = new Array(); | |
for (var i = 0; i < blocks.length; i++) { | |
var obj = new Object(); | |
var div = eXo.core.DOMUtil.getChildrenByTagName(blocks[i], "div"); | |
obj.blockId = div[0].innerHTML; | |
obj.data = div[1]; | |
this.blocksToUpdate[i] = obj; | |
this.blocksToUpdate[i].scripts = eXo.core.DOMUtil.findDescendantsByTagName(div[1], "script"); | |
} | |
} else { | |
this.scripts = eXo.core.DOMUtil.findDescendantsByTagName(div[1], "script"); | |
} | |
}; | |
function PortalResponse(responseDiv) { | |
var DOMUtil = eXo.core.DOMUtil; | |
this.portletResponses = new Array(); | |
var div = DOMUtil.getChildrenByTagName(responseDiv, "div"); | |
for (var i = 0; i < div.length; i++) { | |
if (div[i].className == "PortletResponse") { | |
this.portletResponses[this.portletResponses.length] = new PortletResponse(div[i]); | |
} else if (div[i].className == "PortalResponseData") { | |
this.data = div[i]; | |
var blocks = DOMUtil.findChildrenByClass(div[i], "div", "BlockToUpdate"); | |
this.blocksToUpdate = new Array(); | |
for (var j = 0; j < blocks.length; j++) { | |
var obj = new Object(); | |
var dataBlocks = DOMUtil.getChildrenByTagName(blocks[j], "div"); | |
obj.blockId = dataBlocks[0].innerHTML; | |
obj.data = dataBlocks[1]; | |
this.blocksToUpdate[j] = obj; | |
this.blocksToUpdate[j].scripts = eXo.core.DOMUtil.findDescendantsByTagName(dataBlocks[1], "script"); | |
} | |
} else if (div[i].className == "MarkupHeadElements") { | |
this.markupHeadElements = new MarkupHeadElements(div[i]); | |
} else if (div[i].className == "PortalResponseScript") { | |
this.script = div[i].innerHTML; | |
div[i].style.display = "none"; | |
} | |
} | |
}; | |
function MarkupHeadElements(fragment) { | |
var DOMUtil = eXo.core.DOMUtil; | |
this.titles = DOMUtil.findDescendantsByTagName(fragment, "title"); | |
this.bases = DOMUtil.findDescendantsByTagName(fragment, "base"); | |
this.links = DOMUtil.findDescendantsByTagName(fragment, "link"); | |
this.metas = DOMUtil.findDescendantsByTagName(fragment, "meta"); | |
this.scripts = DOMUtil.findDescendantsByTagName(fragment, "script"); | |
this.styles = DOMUtil.findDescendantsByTagName(fragment, "style"); | |
} | |
function appendScriptToHead(scriptId, scriptElement) { | |
var head = document.getElementsByTagName("head")[0]; | |
var descendant = eXo.core.DOMUtil.findDescendantById(head, scriptId); | |
var script; | |
if (descendant) { | |
head.removeChild(descendant); | |
} | |
script = document.createElement('script'); | |
script.id = scriptId; | |
script.type = 'text/javascript'; | |
if (scriptElement.src) { | |
script.src = scriptElement.src; | |
} else { | |
script.text = scriptElement.innerHTML; | |
} | |
head.appendChild(script); | |
}; | |
function AjaxRequest(method, url, queryString) { | |
var instance = new Object(); | |
instance.timeout = 80000; | |
instance.aborted = false; | |
if (method != null) instance.method = method; | |
else instance.method = "GET"; | |
if (url != null) instance.url = url; | |
else instance.url = window.location.href; | |
if (queryString != null) instance.queryString = queryString; | |
else instance.queryString = null; | |
instance.request = null; | |
instance.responseReceived = false; | |
instance.status = null; | |
instance.statusText = null; | |
instance.responseText = null; | |
instance.responseXML = null; | |
instance.onTimeout = null; | |
instance.onLoading = null; | |
instance.onLoaded = null; | |
instance.onInteractive = null; | |
instance.onComplete = null; | |
instance.onSuccess = null; | |
instance.callBack = null; | |
instance.onError = null; | |
instance.isAsynchronize = function () { | |
var isASync = false; | |
var name = "ajax_async"; | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regexS = "[\\?&]" + name + "=([^&#]*)"; | |
var regex = new RegExp(regexS); | |
var results = regex.exec(instance.url); | |
if (results != null) { | |
isASync = (results[1] == "true") ? true : false; | |
} | |
return isASync; | |
}; | |
instance.onLoadingInternalHandled = false; | |
instance.onLoadedInternalHandled = false; | |
instance.onInteractiveInternalHandled = false; | |
instance.onCompleteInternalHandled = false; | |
instance.request = eXo.core.Browser.createHttpRequest(); | |
instance.request.onreadystatechange = function () { | |
if (instance == null || instance.request == null) { | |
return; | |
} | |
if (instance.request.readyState == 1) { | |
instance.onLoadingInternal(instance); | |
} | |
if (instance.request.readyState == 2) { | |
instance.onLoadedInternal(instance); | |
} | |
if (instance.request.readyState == 3) { | |
instance.onInteractiveInternal(instance); | |
} | |
if (instance.request.readyState == 4) { | |
instance.onCompleteInternal(instance); | |
} | |
}; | |
instance.onLoadingInternal = function () { | |
if (instance.onLoadingInternalHandled) return; | |
if (typeof (instance.onLoading) == "function") instance.onLoading(instance); | |
instance.onLoadingInternalHandled = true; | |
}; | |
instance.onLoadedInternal = function () { | |
if (instance.onLoadedInternalHandled) return; | |
if (typeof (instance.onLoaded) == "function") instance.onLoaded(instance); | |
instance.onLoadedInternalHandled = true; | |
}; | |
instance.onInteractiveInternal = function () { | |
if (instance.onInteractiveInternalHandled) return; | |
if (typeof (instance.onInteractive) == "function") instance.onInteractive(instance); | |
instance.onInteractiveInternalHandled = true; | |
}; | |
instance.evalResponse = function () { | |
try { | |
return eval((instance.responseText || '')); | |
} catch (e) { | |
throw (new Error('Cannot eval the response')); | |
} | |
}; | |
instance.onCompleteInternal = function () { | |
if (instance.onCompleteInternalHandled || instance.aborted) return; | |
try { | |
instance.responseReceived = true; | |
instance.status = instance.request.status; | |
instance.statusText = instance.request.statusText; | |
instance.responseText = instance.request.responseText; | |
instance.responseXML = instance.request.responseXML; | |
} catch (err) { | |
instance.status = 0; | |
} | |
if (typeof (instance.onComplete) == "function") instance.onComplete(instance); | |
if (instance.status == 200 && typeof (instance.onSuccess) == "function") { | |
instance.onSuccess(instance); | |
instance.onCompleteInternalHandled = true; | |
if (typeof (instance.callBack) == "function") { | |
instance.callBack(instance); | |
} else if (instance.callBack) { | |
try { | |
eval(instance.callBack); | |
} catch (e) { | |
throw (new Error('Can not execute callback...')); | |
} | |
} | |
} else if (typeof (instance.onError) == "function") { | |
instance.onError(instance); | |
instance.onCompleteInternalHandled = false; | |
} | |
delete instance.request['onreadystatechange']; | |
instance.request = null; | |
}; | |
instance.onTimeoutInternal = function () { | |
if (instance == null || instance.request == null || instance.onCompleteInternalHandled) return; | |
instance.aborted = true; | |
instance.request.abort(); | |
if (typeof (instance.onTimeout) == "function") instance.onTimeout(instance); | |
delete instance.request['onreadystatechange']; | |
instance.request = null; | |
}; | |
instance.process = function () { | |
if (instance.request == null) return; | |
instance.request.open(instance.method, instance.url, true); | |
if (instance.method == "POST") { | |
instance.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); | |
} else { | |
instance.request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); | |
} | |
if (instance.timeout > 0) setTimeout(instance.onTimeoutInternal, instance.timeout); | |
instance.request.send(instance.queryString); | |
}; | |
return instance; | |
}; | |
function HttpResponseHandler() { | |
var instance = new Object(); | |
instance.to = null; | |
instance.executeScript = function (script) { | |
if (script == null || script == "") return; | |
try { | |
var HTMLUtil = eXo.core.HTMLUtil; | |
script = HTMLUtil.entitiesDecode(script); | |
eval(script); | |
return; | |
} catch (err) {} | |
var elements = script.split(';'); | |
if (elements != null && elements.length > 0) { | |
for (var i = 0; i < elements.length; i++) { | |
try { | |
eval(elements[i]); | |
} catch (err) { | |
alert(err + " : " + elements[i] + " -- " + i); | |
} | |
} | |
} | |
}; | |
instance.updateHtmlHead = function (response) { | |
if (!response) return; | |
cleanHtmlHead(response); | |
var DOMUtil = eXo.core.DOMUtil; | |
var head = document.getElementsByTagName("head")[0]; | |
var markupHeadElements = response.markupHeadElements; | |
if (!markupHeadElements) return; | |
if (markupHeadElements.titles && markupHeadElements.titles.length != 0) { | |
var oldTitle = DOMUtil.getChildrenByTagName(head, "title")[0]; | |
var newTitle = markupHeadElements.titles[markupHeadElements.titles.length - 1]; | |
if (oldTitle) { | |
head.replaceChild(newTitle, oldTitle); | |
} else { | |
head.appendChild(newTitle); | |
} | |
} | |
appendElementsToHead(markupHeadElements.metas); | |
appendElementsToHead(markupHeadElements.bases); | |
appendElementsToHead(markupHeadElements.links); | |
appendElementsToHead(markupHeadElements.styles); | |
appendElementsToHead(markupHeadElements.scripts); | |
}; | |
function cleanHtmlHead(response) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var head = document.getElementsByTagName("head")[0]; | |
var portletResponses = response.portletResponses; | |
if (portletResponses) { | |
for (var i = 0; i < portletResponses.length; i++) { | |
removeExtraHead(portletResponses[i].portletId); | |
} | |
} | |
if (response.data) { | |
var portletFragments = DOMUtil.findDescendantsByClass(response.data, "div", "PORTLET-FRAGMENT"); | |
for (var i = 0; i < portletFragments.length; i++) { | |
removeExtraHead(portletFragments[i].parentNode.id); | |
} | |
} | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
var portletFragsInWS = DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "PORTLET-FRAGMENT"); | |
var exHeads = DOMUtil.getElementsBy(function (elem) { | |
return elem.tagName != "TITLE" && elem.className.indexOf("ExHead-") == 0; | |
}, "*", head); | |
for (var i = 0; i < exHeads.length; i++) { | |
var portletId = exHeads[i].className.substring(7); | |
var del = true; | |
for (var j = 0; j < portletFragsInWS.length; j++) { | |
if (portletId == portletFragsInWS[j].parentNode.id) { | |
del = false; | |
break; | |
} | |
} | |
if (del) { | |
head.removeChild(exHeads[i]); | |
} | |
} | |
} | |
function removeExtraHead(portletId) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var head = document.getElementsByTagName("head")[0]; | |
var elemsToRemove = DOMUtil.getElementsBy(function (elem) { | |
return elem.tagName != "TITLE" && elem.className == "ExHead-" + portletId; | |
}, "*", head); | |
for (var i = 0; i < elemsToRemove.length; i++) { | |
head.removeChild(elemsToRemove[i]); | |
} | |
} | |
function appendElementsToHead(elements) { | |
if (!elements) return; | |
var head = document.getElementsByTagName("head")[0]; | |
for (var i = 0; i < elements.length; i++) { | |
head.appendChild(elements[i]); | |
} | |
} | |
instance.updateBlocks = function (blocksToUpdate, parentId) { | |
if (blocksToUpdate == null) return; | |
var parentBlock = null; | |
if (parentId != null && parentId != "") parentBlock = document.getElementById(parentId); | |
for (var i = 0; i < blocksToUpdate.length; i++) { | |
var blockToUpdate = blocksToUpdate[i]; | |
var target = null; | |
if (parentBlock != null) { | |
target = eXo.core.DOMUtil.findDescendantById(parentBlock, blockToUpdate.blockId); | |
} else { | |
target = document.getElementById(blockToUpdate.blockId); | |
} | |
if (target == null) alert(eXo.i18n.I18NMessage.getMessage("TargetBlockNotFound", new Array(blockToUpdate.blockId))); | |
var newData = eXo.core.DOMUtil.findDescendantById(blockToUpdate.data, blockToUpdate.blockId); | |
if (newData == null) alert(eXo.i18n.I18NMessage.getMessage("BlockUpdateNotFound", new Array(blockToUpdate.blockId))); | |
target.innerHTML = newData.innerHTML; | |
if (blockToUpdate.scripts) { | |
if (blockToUpdate.scripts.length > 0) { | |
for (var k = 0; k < blockToUpdate.scripts.length; k++) { | |
var encodedName = 'script_' + k + '_' + blockToUpdate.blockId; | |
appendScriptToHead(encodedName, blockToUpdate.scripts[k]); | |
} | |
} | |
} | |
} | |
}; | |
instance.ajaxTimeout = function (request) { | |
eXo.core.UIMaskLayer.removeMasks(eXo.portal.AjaxRequest.maskLayer); | |
eXo.portal.AjaxRequest.maskLayer = null; | |
eXo.portal.CurrentRequest = null; | |
window.location.reload(); | |
}; | |
instance.ajaxResponse = function (request) { | |
var temp = document.createElement("div"); | |
temp.innerHTML = this.request.responseText; | |
var responseDiv = eXo.core.DOMUtil.findFirstDescendantByClass(temp, "div", "PortalResponse"); | |
var response = new PortalResponse(responseDiv); | |
var portletResponses = response.portletResponses; | |
if (portletResponses != null) { | |
for (var i = 0; i < portletResponses.length; i++) { | |
var portletResponse = portletResponses[i]; | |
if (portletResponse.blocksToUpdate == null) { | |
var parentBlock = document.getElementById(portletResponse.portletId); | |
var target = eXo.core.DOMUtil.findFirstDescendantByClass(parentBlock, "div", "PORTLET-FRAGMENT"); | |
target.innerHTML = portletResponse.portletData; | |
if (portletResponse.scripts) { | |
if (portletResponse.scripts.length > 0) { | |
for (var k = 0; k < portletResponse.scripts.length; k++) { | |
var encodedName = 'script_' + k + '_' + portletResponse.portletId; | |
appendScriptToHead(encodedName, portletResponse.scripts[k]); | |
} | |
} | |
} | |
} else { | |
instance.updateBlocks(portletResponse.blocksToUpdate, portletResponse.portletId); | |
} | |
} | |
} | |
if (response.blocksToUpdate == undefined && temp.innerHTML !== "") { | |
if (confirm(eXo.i18n.I18NMessage.getMessage("SessionTimeout"))) instance.ajaxTimeout(request); | |
} | |
instance.updateBlocks(response.blocksToUpdate); | |
instance.updateHtmlHead(response); | |
instance.executeScript(response.script); | |
clearTimeout(instance.to); | |
eXo.core.UIMaskLayer.removeMasks(eXo.portal.AjaxRequest.maskLayer); | |
eXo.portal.AjaxRequest.maskLayer = null; | |
eXo.portal.CurrentRequest = null; | |
}; | |
instance.ajaxLoading = function (request) { | |
if (request.isAsynchronize()) return; | |
Browser = eXo.core.Browser; | |
if (eXo.portal.AjaxRequest.maskLayer == null) { | |
eXo.portal.AjaxRequest.maskLayer = eXo.core.UIMaskLayer.createTransparentMask("TOP-CENTER"); | |
} | |
instance.to = setTimeout(function () { | |
if (eXo.portal.AjaxRequest.maskLayer != null) { | |
eXo.core.UIMaskLayer.showAjaxLoading(eXo.portal.AjaxRequest.maskLayer); | |
} | |
}, 2000); | |
}; | |
return instance; | |
}; | |
function ajaxGet(url, callback) { | |
if (!callback) callback = null; | |
doRequest("Get", url, null, callback); | |
}; | |
function ajaxPost(url, queryString, callback) { | |
if (!callback) callback = null; | |
doRequest("POST", url, queryString, callback); | |
}; | |
function doRequest(method, url, queryString, callback) { | |
request = new AjaxRequest(method, url, queryString); | |
handler = new HttpResponseHandler(); | |
request.onSuccess = handler.ajaxResponse; | |
request.onLoading = handler.ajaxLoading; | |
request.onTimeout = handler.ajaxTimeout; | |
request.callBack = callback; | |
eXo.portal.CurrentRequest = request; | |
request.process(); | |
eXo.session.startItv(); | |
}; | |
function ajaxAbort() { | |
eXo.core.UIMaskLayer.removeMasks(eXo.portal.AjaxRequest.maskLayer); | |
eXo.portal.AjaxRequest.maskLayer = null; | |
eXo.portal.CurrentRequest.request.abort(); | |
eXo.portal.CurrentRequest.aborted = true; | |
eXo.portal.CurrentRequest = null; | |
}; | |
function ajaxAsyncGetRequest(url, async) { | |
return ajaxRequest("GET", url, async); | |
} | |
function ajaxRequest(method, url, async, queryString) { | |
if (async == undefined) async = true; | |
var request = eXo.core.Browser.createHttpRequest(); | |
request.open(method, url, async); | |
request.setRequestHeader("Cache-Control", "max-age=86400"); | |
if (queryString != undefined) { | |
request.send(queryString); | |
} else { | |
request.send(null); | |
} | |
eXo.session.startItv(); | |
if (!async) return request.responseText; | |
} | |
function ajaxRedirect(url) { | |
url = url.replace(/&/g, "&"); | |
window.location.href = url; | |
} | |
eXo.portal.AjaxRequest = AjaxRequest.prototype.constructor; | |
function UIComponent(node) { | |
if (!node) return null; | |
this.node = node; | |
this.type = node.className; | |
var DOMUtil = eXo.core.DOMUtil; | |
var componentBlock = DOMUtil.findFirstDescendantByClass(node, "div", "UIComponentBlock"); | |
var children = DOMUtil.getChildrenByTagName(componentBlock, "div"); | |
for (var i = 0; i < children.length; i++) { | |
if (DOMUtil.hasClass(children[i], "LAYOUT-BLOCK")) this.layout = children[i]; | |
else if (DOMUtil.hasClass(children[i], "VIEW-BLOCK")) this.view = children[i]; | |
else if (DOMUtil.hasClass(children[i], "EDITION-BLOCK")) this.control = children[i]; | |
} | |
this.component = ""; | |
if (DOMUtil.hasClass(node, "UIPortal")) this.id = node.id.replace("UIPortal-", ""); | |
else if (DOMUtil.hasClass(node, "UIPortlet")) this.id = node.id.replace("UIPortlet-", ""); | |
else if (DOMUtil.hasClass(node, "UIContainer")) this.id = node.id.replace("UIContainer-", ""); | |
else this.id = node.id; | |
}; | |
UIComponent.prototype.getId = function () { | |
return this.id; | |
}; | |
UIComponent.prototype.getElement = function () { | |
return this.node; | |
}; | |
UIComponent.prototype.getUIComponentType = function () { | |
return this.type; | |
}; | |
UIComponent.prototype.getUIComponentBlock = function () { | |
return this.node; | |
}; | |
UIComponent.prototype.getControlBlock = function () { | |
return this.control; | |
}; | |
UIComponent.prototype.getLayoutBlock = function () { | |
return this.layout; | |
}; | |
UIComponent.prototype.getViewBlock = function () { | |
return this.view; | |
}; | |
function UIPortal() { | |
this.portalUIComponentDragDrop = false; | |
}; | |
UIPortal.prototype.blockOnMouseOver = function (event, portlet, isOver) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (!eXo.portal.portalMode || eXo.portal.isInDragging) return; | |
if (eXo.portal.portalMode <= 2 && DOMUtil.hasClass(portlet, "UIContainer")) return; | |
if (eXo.portal.portalMode > 2 && eXo.portal.portalMode != 4 && DOMUtil.hasClass(portlet, "UIPortlet")) return; | |
if (!event) event = window.event; | |
event.cancelBubble = true; | |
var component = DOMUtil.findFirstDescendantByClass(portlet, "div", "UIComponentBlock"); | |
var children = DOMUtil.getChildrenByTagName(component, "div"); | |
var layoutBlock; | |
var viewBlock; | |
var editBlock; | |
for (var i = 0; i < children.length; i++) { | |
if (DOMUtil.hasClass(children[i], "LAYOUT-BLOCK")) layoutBlock = children[i]; | |
else if (DOMUtil.hasClass(children[i], "VIEW-BLOCK")) viewBlock = children[i]; | |
else if (DOMUtil.hasClass(children[i], "EDITION-BLOCK")) editBlock = children[i]; | |
} | |
if (!editBlock) return; | |
if (isOver) { | |
var newLayer = DOMUtil.findFirstDescendantByClass(editBlock, "div", "NewLayer"); | |
var height = 0; | |
var width = 0; | |
if (layoutBlock && layoutBlock.style.display != "none") { | |
height = layoutBlock.offsetHeight; | |
width = layoutBlock.offsetWidth; | |
} else if (viewBlock && viewBlock.style.display != "none") { | |
height = viewBlock.offsetHeight; | |
width = viewBlock.offsetWidth; | |
} | |
if (DOMUtil.hasClass(portlet, "UIPortlet")) { | |
newLayer.style.width = width + "px"; | |
newLayer.style.height = height + "px"; | |
} else { | |
newLayer.parentNode.style.width = width + "px"; | |
var normalBlock = DOMUtil.findFirstChildByClass(portlet, "div", "NormalContainerBlock"); | |
if (normalBlock) DOMUtil.replaceClass(normalBlock, "NormalContainerBlock", "OverContainerBlock"); | |
} | |
newLayer.parentNode.style.top = -height + "px"; | |
editBlock.style.display = "block"; | |
var uiInfoBar = DOMUtil.findFirstDescendantByClass(editBlock, "div", "UIInfoBar"); | |
if (uiInfoBar && (eXo.core.Browser.isIE6() || (eXo.core.Browser.isIE7() && eXo.core.I18n.isRT()))) { | |
if (uiInfoBar.style.width == "") { | |
var dragControlArea = DOMUtil.findFirstDescendantByClass(uiInfoBar, "div", "DragControlArea"); | |
var portletIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "div", "PortletIcon"); | |
var editPortletPropertiesIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "EditPortletPropertiesIcon"); | |
var deletePortletIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "DeletePortletIcon"); | |
var contarnerIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "div", "ContainerIcon"); | |
var editContainerIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "EditContainerIcon"); | |
var deleteContainerIcon = DOMUtil.findFirstDescendantByClass(uiInfoBar, "a", "DeleteContainerIcon"); | |
var uiInfoBarWidth = dragControlArea.offsetWidth; | |
if (DOMUtil.hasClass(portlet, "UIPortlet")) { | |
uiInfoBarWidth += portletIcon.offsetWidth; | |
if (editPortletPropertiesIcon) { | |
uiInfoBarWidth += editPortletPropertiesIcon.offsetWidth; | |
} | |
if (deletePortletIcon) { | |
uiInfoBarWidth += deletePortletIcon.offsetWidth; | |
} | |
} | |
if (DOMUtil.hasClass(portlet, "UIContainer")) { | |
uiInfoBarWidth += contarnerIcon.offsetWidth | |
if (editContainerIcon) { | |
uiInfoBarWidth += editContainerIcon.offsetWidth; | |
} | |
if (deleteContainerIcon) { | |
uiInfoBarWidth += deleteContainerIcon.offsetWidth; | |
} | |
} | |
uiInfoBar.style.width = uiInfoBarWidth + 35 + "px"; | |
} | |
} | |
} else { | |
editBlock.style.display = "none"; | |
if (!DOMUtil.hasClass(portlet, "UIPortlet")) { | |
var normalBlock = DOMUtil.findFirstChildByClass(portlet, "div", "OverContainerBlock"); | |
if (normalBlock) DOMUtil.replaceClass(normalBlock, "OverContainerBlock", "NormalContainerBlock"); | |
} | |
} | |
var controlPortlet = DOMUtil.findFirstDescendantByClass(editBlock, "div", "CONTROL-PORTLET"); | |
if (controlPortlet) { | |
controlPortlet.style.display = eXo.portal.portalMode == 4 ? "none" : "block"; | |
} | |
}; | |
UIPortal.prototype.getUIPortlets = function () { | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
var founds = eXo.core.DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "UIPortlet"); | |
var components = new Array(); | |
for (j = 0; j < founds.length; j++) { | |
components[components.length] = new UIComponent(founds[j]); | |
} | |
return components; | |
}; | |
UIPortal.prototype.getUIPortletsInUIPortal = function () { | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
var founds = eXo.core.DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "UIPortlet"); | |
var components = new Array(); | |
for (var j = 0; j < founds.length; j++) { | |
if (eXo.core.DOMUtil.findAncestorByClass(founds[j], 'UIPage') == null) { | |
components[components.length] = new UIComponent(founds[j]); | |
} | |
} | |
return components; | |
}; | |
UIPortal.prototype.getUIPortletsInUIPage = function () { | |
var uiPage = document.getElementById("UIPage"); | |
var founds = eXo.core.DOMUtil.findDescendantsByClass(uiPage, "div", "UIPortlet"); | |
var components = new Array(); | |
for (var j = 0; j < founds.length; j++) { | |
components[components.length] = new UIComponent(founds[j]); | |
} | |
return components; | |
}; | |
UIPortal.prototype.getUIContainers = function () { | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
var founds = eXo.core.DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "UIContainer"); | |
var components = new Array(); | |
for (var j = 0; j < founds.length; j++) { | |
components[j] = new UIComponent(founds[j]); | |
} | |
return components; | |
}; | |
UIPortal.prototype.getUIPageBody = function () { | |
return new UIComponent(document.getElementById("UIPageBody")); | |
}; | |
UIPortal.prototype.getUIPortal = function () { | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
return new UIComponent(eXo.core.DOMUtil.findFirstDescendantByClass(uiWorkingWorkspace, "div", "UIPortal")); | |
}; | |
UIPortal.prototype.showLayoutModeForPage = function () { | |
var uiPage = eXo.core.DOMUtil.findFirstDescendantByClass(document.body, "div", "UIPage"); | |
if (uiPage == null) return; | |
var viewPage = eXo.core.DOMUtil.findFirstDescendantByClass(uiPage, "div", "VIEW-PAGE"); | |
var uiPortalApplication = document.getElementById("UIPortalApplication"); | |
if (uiPortalApplication.className != "Vista") { | |
viewPage.style.border = "solid 3px #dadada"; | |
} | |
viewPage.style.paddingTop = "50px"; | |
viewPage.style.paddingRight = "0px"; | |
viewPage.style.paddingBottom = "50px"; | |
viewPage.style.paddingLeft = "0px"; | |
var uiContainer = eXo.core.DOMUtil.findFirstDescendantByClass(viewPage, "div", "UIContainer"); | |
var uiPortlet = eXo.core.DOMUtil.findFirstDescendantByClass(viewPage, "div", "UIPortlet"); | |
if (uiContainer != null || uiPortlet != null) { | |
viewPage.style.border = "none"; | |
viewPage.style.paddingTop = "5px"; | |
viewPage.style.paddingRight = "5px"; | |
viewPage.style.paddingBottom = "5px"; | |
viewPage.style.paddingLeft = "5px"; | |
} | |
}; | |
UIPortal.prototype.showViewMode = function () { | |
var pageBody = this.getUIPageBody(); | |
var container = this.getUIContainers(); | |
var portlet = this.getUIPortlets(); | |
if (container.length == 0 && portlet.length == 0) { | |
var pageIdElemt = document.getElementById("UIPage"); | |
var viewPage = eXo.core.DOMUtil.findAncestorByClass(pageIdElemt, "VIEW-PAGE"); | |
viewPage.style.paddingTop = "50px"; | |
viewPage.style.paddingRight = "0px"; | |
viewPage.style.paddingBottom = "50px"; | |
viewPage.style.paddingLeft = "0px"; | |
} | |
var pageBodyBlock = pageBody.getUIComponentBlock(); | |
var mask = eXo.core.DOMUtil.findFirstDescendantByClass(pageBodyBlock, "div", "UIPageBodyMask"); | |
if (mask) { | |
mask.style.top = -pageBodyBlock.offsetHeight + "px"; | |
mask.style.height = pageBodyBlock.offsetHeight + "px"; | |
mask.style.width = pageBodyBlock.offsetWidth + "px"; | |
} | |
}; | |
UIPortal.prototype.findUIComponentOf = function (element) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parent; | |
if (parent = DOMUtil.findAncestorByClass(element, "UIPortlet")) { | |
return parent; | |
} else if (parent = DOMUtil.findAncestorByClass(element, "UIPageBody")) { | |
return parent; | |
} else if (parent = DOMUtil.findAncestorByClass(element, "UIContainer")) { | |
return parent; | |
} else if (parent = DOMUtil.findAncestorByClass(element, "UIPortal")) { | |
return parent; | |
} | |
return null; | |
}; | |
UIPortal.prototype.changeSkin = function (url) { | |
var skin = ''; | |
if (eXo.webui.UIItemSelector.SelectedItem != undefined) { | |
skin = eXo.webui.UIItemSelector.SelectedItem.option; | |
} | |
if (skin == undefined) skin = ''; | |
window.location = url + '&skin=' + skin; | |
}; | |
UIPortal.prototype.changeLanguage = function (url) { | |
var language = ''; | |
if (eXo.webui.UIItemSelector.SelectedItem != undefined) { | |
language = eXo.webui.UIItemSelector.SelectedItem.option; | |
} | |
if (language == undefined) language = ''; | |
window.location = url + '&language=' + language; | |
}; | |
UIPortal.prototype.changePortal = function (accessPath, portal) { | |
window.location = eXo.env.server.context + "/" + accessPath + "/" + portal + "/"; | |
}; | |
UIPortal.prototype.popupButton = function (url, action) { | |
if (action == undefined) action = ''; | |
window.location = url + '&action=' + action; | |
}; | |
UIPortal.prototype.removeComponent = function (componentId) { | |
var comp = document.getElementById(componentId); | |
var viewPage = eXo.core.DOMUtil.findAncestorByClass(comp, "VIEW-PAGE"); | |
if (comp.parentNode.nodeName.toUpperCase() == "TD") eXo.core.DOMUtil.removeElement(comp.parentNode); | |
else eXo.core.DOMUtil.removeElement(comp); | |
if (viewPage && eXo.portal.UIPortal.getUIContainers().length == 0 && eXo.portal.UIPortal.getUIPortlets().length == 0) { | |
viewPage.style.paddingTop = "50px"; | |
viewPage.style.paddingRight = "0px"; | |
viewPage.style.paddingBottom = "50px"; | |
viewPage.style.paddingLeft = "0px"; | |
} | |
}; | |
UIPortal.prototype.changeComposerSaveButton = function () { | |
if (eXo.portal.hasEditted == false) { | |
var uiWorkingWS = document.getElementById("UIWorkingWorkspace"); | |
var portalComposer = eXo.core.DOMUtil.findFirstDescendantByClass(uiWorkingWS, "div", "UIPortalComposer"); | |
if (!portalComposer) return; | |
var saveButton = eXo.core.DOMUtil.findFirstDescendantByClass(portalComposer, "a", "SaveButton"); | |
if (saveButton) { | |
eXo.core.DOMUtil.replaceClass(saveButton, "SaveButton", "EdittedSaveButton"); | |
} | |
ajaxAsyncGetRequest(eXo.env.server.createPortalURL(portalComposer.id, "ChangeEdittedState", true)); | |
} | |
}; | |
UIPortal.prototype.toggleComposer = function (clickedEle) { | |
var portalComposer = eXo.core.DOMUtil.findAncestorByClass(clickedEle, "UIPortalComposer"); | |
var content = eXo.core.DOMUtil.findFirstChildByClass(portalComposer, "div", "UIWindowContent"); | |
if (content && content.style.display != "none") { | |
content.style.display = "none"; | |
eXo.core.DOMUtil.replaceClass(clickedEle, "ExpandIcon", "CollapseIcon"); | |
} else { | |
content.style.display = "block"; | |
eXo.core.DOMUtil.replaceClass(clickedEle, "CollapseIcon", "ExpandIcon"); | |
} | |
var requestStr = eXo.env.server.createPortalURL(portalComposer.id, "Toggle", true); | |
ajaxAsyncGetRequest(requestStr); | |
}; | |
UIPortal.prototype.composerTabChanged = function (tabId) { | |
var toolPanel = document.getElementById("UIPortalToolPanel"); | |
if (!tabId || !toolPanel) return; | |
var removeCls, addCls; | |
if (tabId === "UIApplicationList") { | |
addCls = "ApplicationMode"; | |
removeCls = "ContainerMode"; | |
} else { | |
addCls = "ContainerMode"; | |
removeCls = "ApplicationMode"; | |
} | |
eXo.core.DOMUtil.removeClass(toolPanel, removeCls); | |
eXo.core.DOMUtil.addClass(toolPanel, addCls); | |
} | |
UIPortal.prototype.collapseExpand = function (element) { | |
var subGroup = eXo.core.DOMUtil.findFirstChildByClass(element.parentNode, "div", "ChildrenContainer"); | |
var className = element.className; | |
if (!subGroup) return; | |
if (subGroup.style.display == "none") { | |
if (className.indexOf("ExpandIcon") == 0) element.className = "CollapseIcon ClearFix"; | |
subGroup.style.display = "block"; | |
} else { | |
if (className.indexOf("CollapseIcon") == 0) element.className = "ExpandIcon ClearFix"; | |
subGroup.style.display = "none"; | |
} | |
}; | |
eXo.portal.UIPortalComponent = UIComponent.prototype.constructor; | |
eXo.portal.UIPortal = new UIPortal(); | |
eXo.portal.UIComponent = UIPortal.prototype.constructor; | |
function UIWorkspace(id) { | |
this.id = id; | |
this.isFirstTime = true; | |
}; | |
eXo.portal.UIWorkspace = new UIWorkspace("UIWorkspace"); | |
if (eXo.portal.UIWorkingWorkspace == undefined) { | |
eXo.portal.UIWorkingWorkspace = new UIWorkspace("UIWorkingWorkspace"); | |
}; | |
eXo.portal.UIWorkingWorkspace.onResize = function () { | |
var uiWorkspace = document.getElementById(eXo.portal.UIWorkingWorkspace.id); | |
if (eXo.core.Browser.isIE6()) { | |
var tabs = eXo.core.DOMUtil.findFirstDescendantByClass(uiWorkspace, "div", "UIHorizontalTabs"); | |
if (tabs) tabs.style.left = 0; | |
} | |
}; | |
function UIPortalControl() { | |
this.scrollManagers = new Array(); | |
}; | |
UIPortalControl.prototype.changeWindowState = function (id, state) { | |
var params = [{ | |
name: "portletId", | |
value: id | |
}, { | |
name: "objectId", | |
value: state | |
}]; | |
ajaxGet(eXo.env.server.createPortalURL("UIPortal", "ChangeWindowState", true, params)); | |
}; | |
UIPortalControl.prototype.collapseTree = function (selectedElement) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parentNode = DOMUtil.findAncestorByClass(selectedElement, "Node"); | |
var childrenContainer = DOMUtil.findFirstDescendantByClass(parentNode, "div", "ChildrenContainer"); | |
var newHTML = "<div onclick=\"" + childrenContainer.getAttribute("actionLink") + "\" class=\"ExpandIcon\">" + selectedElement.innerHTML + "</div>"; | |
parentNode.innerHTML = newHTML; | |
}; | |
UIPortalControl.prototype.onEnterPress = function (e, executeScript) { | |
var e = window.event || e; | |
var code; | |
if (!e) e = window.event; | |
if (e.keyCode) code = e.keyCode; | |
else if (e.which) code = e.which; | |
if (code == 13) { | |
if (window.event) { | |
e.returnValue = false; | |
} else { | |
e.preventDefault(); | |
} | |
var uiPortalLoginFormAction = document.getElementById("UIPortalLoginFormAction"); | |
if (uiPortalLoginFormAction) { | |
uiPortalLoginFormAction.onclick(); | |
} else { | |
if (executeScript) eval(executeScript); | |
} | |
} | |
}; | |
function ScrollManager() { | |
this.id = null; | |
this.elements = new Array(); | |
this.firstVisibleIndex = 0; | |
this.lastVisibleIndex = -1; | |
this.otherHiddenElements = new Array(); | |
this.axis = 0; | |
this.currDirection = null; | |
this.callback = null; | |
this.initFunction = null; | |
this.leftArrow = null; | |
this.rightArrow = null; | |
this.mainContainer = null; | |
this.arrowsContainer = null | |
this.margin = 6.9; | |
}; | |
ScrollManager.prototype.initArrowButton = function (arrow, dir, normalClass, overClass, disabledClass) { | |
if (arrow) { | |
arrow.direction = dir; | |
arrow.overClass = overClass; | |
arrow.disabledClass = disabledClass; | |
arrow.styleClass = normalClass; | |
arrow.scrollMgr = this; | |
arrow.onmouseover = this.mouseOverArrow; | |
arrow.onmouseout = this.mouseOutArrow; | |
arrow.onclick = this.scroll; | |
if (dir == "left") this.leftArrow = arrow; | |
else if (dir == "right") this.rightArrow = arrow; | |
} | |
}; | |
ScrollManager.prototype.enableArrow = function (arrow, enabled) { | |
if (arrow && !enabled) { | |
arrow.className = arrow.disabledClass; | |
arrow.onclick = null; | |
} else if (arrow && enabled) { | |
arrow.className = arrow.styleClass; | |
arrow.onclick = this.scroll; | |
} | |
}; | |
ScrollManager.prototype.mouseOverArrow = function (e) { | |
var arrow = this; | |
if (arrow.onclick && arrow.className == arrow.styleClass) { | |
if (!e) e = window.event; | |
if (arrow == eXo.core.Browser.getEventSource(e)) arrow.className = arrow.overClass; | |
} | |
}; | |
ScrollManager.prototype.mouseOutArrow = function (e) { | |
var arrow = this; | |
if (arrow.onclick && arrow.className == arrow.overClass) { | |
arrow.className = arrow.styleClass; | |
} | |
}; | |
ScrollManager.prototype.init = function () { | |
this.firstVisibleIndex = 0; | |
this.lastVisibleIndex = -1; | |
if (this.arrowsContainer) { | |
this.arrowsContainer.style.display = "none"; | |
this.arrowsContainer.space = null; | |
this.mainContainer.space = null; | |
} | |
var uiNavigationPortlet = eXo.core.DOMUtil.findAncestorByClass(this.mainContainer, "UINavigationPortlet"); | |
if (uiNavigationPortlet) { | |
var uiApplication = uiNavigationPortlet.parentNode; | |
uiApplication.style.display = "inline"; | |
} | |
}; | |
ScrollManager.prototype.loadElements = function (elementClass, clean) { | |
if (clean) this.cleanElements(); | |
this.elements.clear(); | |
this.elements.pushAll(eXo.core.DOMUtil.findDescendantsByClass(this.mainContainer, "li", elementClass)); | |
}; | |
ScrollManager.prototype.checkAvailableSpace = function (maxSpace) { | |
if (!maxSpace) maxSpace = this.getElementSpace(this.mainContainer) - this.getElementSpace(this.arrowsContainer); | |
var elementsSpace = 0; | |
var margin = 0; | |
var length = this.elements.length; | |
for (var i = 0; i < length; i++) { | |
elementsSpace += this.getElementSpace(this.elements[i]); | |
if (i + 1 < length) margin = this.getElementSpace(this.elements[i + 1]) / 3; | |
else margin = this.margin; | |
if (elementsSpace + margin < maxSpace) { | |
this.elements[i].isVisible = true; | |
this.lastVisibleIndex = i; | |
} else { | |
this.elements[i].isVisible = false; | |
} | |
} | |
}; | |
ScrollManager.prototype.getElementsSpace = function (indexStart, indexEnd) { | |
if (indexStart == null && indexEnd == null) { | |
indexStart = 0; | |
indexEnd = this.elements.length - 1; | |
} | |
var elementsSpace = 0; | |
if (indexStart >= 0 && indexEnd <= this.elements.length - 1) { | |
for (var i = indexStart; i <= indexEnd; i++) { | |
elementsSpace += this.getElementSpace(this.elements[i]); | |
} | |
} | |
return elementsSpace; | |
}; | |
ScrollManager.prototype.getElementSpace = function (element) { | |
if (element && element.space) { | |
return element.space; | |
} | |
var elementSpace = 0; | |
var wasHidden = false; | |
if (element) { | |
if (element.style.display == "none") { | |
element.style.display = "block"; | |
wasHidden = true; | |
} | |
if (this.axis == 0) { | |
elementSpace += element.offsetWidth; | |
elementSpace += eXo.core.DOMUtil.getStyle(element, "marginLeft", true); | |
elementSpace += eXo.core.DOMUtil.getStyle(element, "marginRight", true); | |
if (element.decorator) elementSpace += this.getElementSpace(element.decorator); | |
} else if (this.axis == 1) { | |
elementSpace += element.offsetHeight; | |
elementSpace += eXo.core.DOMUtil.getStyle(element, "marginTop", true); | |
elementSpace += eXo.core.DOMUtil.getStyle(element, "marginBottom", true); | |
if (element.decorator) elementSpace += this.getElementSpace(element.decorator); | |
} | |
if (wasHidden) element.style.display = "none"; | |
element.space = elementSpace; | |
} | |
return elementSpace; | |
}; | |
ScrollManager.prototype.cleanElements = function () { | |
for (var i = 0; i < this.elements.length; i++) { | |
this.elements[i].space = null; | |
if (this.elements[i].decorator) this.elements[i].decorator.space = null; | |
} | |
}; | |
ScrollManager.prototype.scroll = function (e) { | |
if (!e) e = window.event; | |
e.cancelBubble = true; | |
var src = eXo.core.Browser.getEventSource(e); | |
if (src.scrollMgr && src.onclick) { | |
if (src.scrollMgr.otherHiddenElements.length > 0) { | |
for (var i = 0; i < src.scrollMgr.otherHiddenElements.length; i++) { | |
src.scrollMgr.otherHiddenElements[i].isVisible = true; | |
src.scrollMgr.otherHiddenElements[i].style.display = "block"; | |
if (src.scrollMgr.currDirection == 1) src.scrollMgr.firstVisibleIndex--; | |
else if (src.scrollMgr.currDirection == 0) src.scrollMgr.lastVisibleIndex++; | |
} | |
src.scrollMgr.otherHiddenElements.clear(); | |
} | |
if (src.direction == "left") src.scrollMgr.scrollLeft(); | |
else if (src.direction == "right") src.scrollMgr.scrollRight(); | |
} | |
return false; | |
}; | |
ScrollManager.prototype.scrollLeft = function () { | |
if (this.firstVisibleIndex > 0) { | |
this.currDirection = 0; | |
this.elements[this.lastVisibleIndex--].isVisible = false; | |
this.getVisibleElements(); | |
this.renderElements(); | |
} | |
}; | |
ScrollManager.prototype.scrollUp = function () { | |
if (this.scrollMgr) this.scrollMgr.scrollLeft(); | |
}; | |
ScrollManager.prototype.scrollRight = function () { | |
if (this.lastVisibleIndex < this.elements.length - 1) { | |
this.currDirection = 1; | |
this.elements[this.firstVisibleIndex++].isVisible = false; | |
this.getVisibleElements(); | |
this.renderElements(); | |
} | |
}; | |
ScrollManager.prototype.scrollDown = function () { | |
if (this.scrollMgr) this.scrollMgr.scrollRight(); | |
}; | |
ScrollManager.prototype.getVisibleElements = function () { | |
var availableSpace = this.getElementSpace(this.mainContainer) - this.getElementSpace(this.arrowsContainer); | |
var refereceIndex = 0; | |
var margin = 0; | |
var elementsSpace = 0; | |
if (this.currDirection) { | |
var length = this.elements.length; | |
for (var i = this.firstVisibleIndex; i < length; i++) { | |
elementsSpace += this.getElementSpace(this.elements[i]); | |
if (i + 1 < length) margin = this.getElementSpace(this.elements[i + 1]) / 3; | |
else margin = this.margin; | |
if (elementsSpace + margin < availableSpace) { | |
this.elements[i].isVisible = true; | |
refereceIndex = i; | |
} else this.elements[i].isVisible = false; | |
} | |
if (this.lastVisibleIndex == refereceIndex) this.scrollRight(); | |
else this.lastVisibleIndex = refereceIndex; | |
} else { | |
for (var i = this.lastVisibleIndex; i >= 0; i--) { | |
elementsSpace += this.getElementSpace(this.elements[i]); | |
margin = this.getElementSpace(this.elements[this.lastVisibleIndex]) / 3; | |
if (elementsSpace + margin < availableSpace) { | |
this.elements[i].isVisible = true; | |
refereceIndex = i; | |
} else this.elements[i].isVisible = false; | |
} | |
if (this.firstVisibleIndex == refereceIndex) this.scrollLeft(); | |
else this.firstVisibleIndex = refereceIndex; | |
} | |
}; | |
ScrollManager.prototype.renderElements = function () { | |
for (var i = 0; i < this.elements.length; i++) { | |
if (this.elements[i].isVisible) { | |
this.elements[i].style.display = "block"; | |
} else { | |
this.elements[i].style.display = "none"; | |
this.arrowsContainer.style.display = "block"; | |
} | |
} | |
if (this.arrowsContainer.style.display == "block") { | |
this.renderArrows(); | |
} | |
if (typeof (this.callback) == "function") this.callback(); | |
}; | |
ScrollManager.prototype.renderArrows = function () { | |
if (this.firstVisibleIndex == 0) this.enableArrow(this.leftArrow, false); | |
else this.enableArrow(this.leftArrow, true); | |
if (this.lastVisibleIndex == this.elements.length - 1) this.enableArrow(this.rightArrow, false); | |
else this.enableArrow(this.rightArrow, true); | |
}; | |
UIPortalControl.prototype.initAllManagers = function () { | |
var managers = eXo.portal.UIPortalControl.scrollManagers; | |
for (var i = 0; i < managers.length; i++) { | |
var mgrContainer = document.getElementById(managers[i].id); | |
var mgrParent = eXo.core.DOMUtil.findAncestorByClass(mgrContainer, "UIWindow"); | |
var toInit = (mgrContainer !== null) && (mgrParent === null || (mgrParent !== null && mgrParent.style.display == "block")) && (typeof (managers[i].initFunction) == "function"); | |
if (toInit) { | |
managers[i].initFunction(); | |
} | |
} | |
}; | |
UIPortalControl.prototype.newScrollManager = function (id_) { | |
if (eXo.portal.UIPortalControl.scrollManagers.length == 0) { | |
eXo.core.Browser.addOnResizeCallback("initAllManagers", eXo.portal.UIPortalControl.initAllManagers); | |
} | |
if (id_) { | |
var tmpMgr = new ScrollManager(); | |
tmpMgr.id = id_; | |
eXo.portal.UIPortalControl.scrollManagers.push(tmpMgr); | |
return tmpMgr; | |
} else { | |
alert('You must set an id to the new scroll manager !!'); | |
return null; | |
} | |
}; | |
function VerticalScrollManager() { | |
repeat = null; | |
} | |
VerticalScrollManager.prototype.initScroll = function (clickedEle, isUp, step) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var verticalScroll = eXo.portal.VerticalScrollManager; | |
var container = DOMUtil.findAncestorByClass(clickedEle, "ItemContainer"); | |
var middleCont = DOMUtil.findFirstDescendantByClass(container, "div", "MiddleItemContainer"); | |
if (!middleCont.id) middleCont.id = "IC" + new Date().getTime() + Math.random().toString().substring(2); | |
verticalScroll.scrollComponent(middleCont.id, isUp, step); | |
document.onmouseup = verticalScroll.cancelScroll; | |
}; | |
VerticalScrollManager.prototype.scrollComponent = function (id, isUp, step) { | |
var verticalScroll = eXo.portal.VerticalScrollManager; | |
var scrollComp = document.getElementById(id); | |
if (isUp) { | |
scrollComp.scrollTop -= step; | |
} else { | |
scrollComp.scrollTop += step; | |
} | |
if (verticalScroll.repeat) { | |
verticalScroll.cancelScroll(); | |
} | |
verticalScroll.repeat = setTimeout("eXo.portal.VerticalScrollManager.scrollComponent('" + id + "'," + isUp + "," + step + ")", 100); | |
}; | |
VerticalScrollManager.prototype.cancelScroll = function () { | |
clearTimeout(eXo.portal.VerticalScrollManager.repeat); | |
eXo.portal.VerticalScrollManager.repeat = null; | |
}; | |
eXo.portal.VerticalScrollManager = new VerticalScrollManager(); | |
eXo.portal.UIPortalControl = new UIPortalControl(); | |
function PortalDragDrop() { | |
this.count = 0; | |
}; | |
PortalDragDrop.prototype.init = function (e) { | |
if (eXo.core.DragDrop.dndEvent) { | |
return; | |
} | |
if (!e) e = window.event; | |
if (((e.which) && (e.which == 2 || e.which == 3)) || ((e.button) && (e.button == 2))) return; | |
var DOMUtil = eXo.core.DOMUtil; | |
var Browser = eXo.core.Browser; | |
var DragDrop = eXo.core.DragDrop; | |
var Mouse = eXo.core.Mouse; | |
var previewBlock = null; | |
var previewTD = null; | |
DragDrop.initCallback = function (dndEvent) { | |
var PortalDragDrop = eXo.portal.PortalDragDrop; | |
this.origDragObjectStyle = new eXo.core.HashMap(); | |
var dragObject = dndEvent.dragObject; | |
var properties = ["top", eXo.core.I18n.isLT() ? "left" : "right", "zIndex", "opacity", "filter", "position", "width"]; | |
this.origDragObjectStyle.copyProperties(properties, dragObject.style); | |
var isAddingNewly = !DOMUtil.findFirstDescendantByClass(dragObject, "div", "UIComponentBlock"); | |
var uiWorkingWS = document.getElementById("UIWorkingWorkspace"); | |
PortalDragDrop.positionRootObj = !isAddingNewly ? uiWorkingWS : DOMUtil.findFirstDescendantByClass(uiWorkingWS, "div", "UIPortalComposer"); | |
var originalDragObjectTop = Browser.findPosYInContainer(dragObject, PortalDragDrop.positionRootObj); | |
var originalDragObjectLeft = Browser.findPosXInContainer(dragObject, PortalDragDrop.positionRootObj); | |
PortalDragDrop.deltaYDragObjectAndMouse = Browser.findMouseRelativeY(dragObject, e); | |
PortalDragDrop.deltaXDragObjectAndMouse = Browser.findMouseRelativeX(dragObject, e); | |
if (isAddingNewly) { | |
var contentContainer = DOMUtil.findAncestorByClass(dragObject, "PopupContent"); | |
originalDragObjectTop -= contentContainer.scrollTop; | |
PortalDragDrop.deltaYDragObjectAndMouse += contentContainer.scrollTop; | |
} | |
PortalDragDrop.parentDragObject = dragObject.parentNode; | |
PortalDragDrop.backupParentSibling = DOMUtil.findNextElementByTagName(dragObject.parentNode, "td"); | |
PortalDragDrop.backupDragObjectWidth = dragObject.offsetWidth; | |
var componentBlockWidth = 300; | |
if (isAddingNewly) { | |
var cloneObject = dragObject.cloneNode(true); | |
dragObject.parentNode.insertBefore(cloneObject, dragObject); | |
cloneObject.style.opacity = 0.5; | |
cloneObject.style.filter = "alpha(opacity=50)"; | |
cloneObject.style.width = PortalDragDrop.backupDragObjectWidth + "px"; | |
dndEvent.dragObject = cloneObject; | |
dndEvent.dragObject.isAddingNewly = isAddingNewly; | |
} else { | |
previewBlock = PortalDragDrop.createPreview(); | |
dragObject.parentNode.insertBefore(previewBlock, dragObject); | |
dragObject.style.width = componentBlockWidth + "px"; | |
var componentBlock = eXo.core.DOMUtil.findFirstDescendantByClass(dragObject, "div", "UIComponentBlock"); | |
var editBlock = eXo.core.DOMUtil.findFirstChildByClass(componentBlock, "div", "EDITION-BLOCK"); | |
if (editBlock) { | |
var newLayer = eXo.core.DOMUtil.findFirstDescendantByClass(editBlock, "div", "NewLayer"); | |
if (newLayer) newLayer.style.width = "300px"; | |
} | |
} | |
dragObject.isAddingNewly = isAddingNewly; | |
dragObject = dndEvent.dragObject; | |
dragObject.style.position = "absolute"; | |
dragObject.style.top = originalDragObjectTop + "px"; | |
var dragObjectLeft = originalDragObjectLeft; | |
if (PortalDragDrop.deltaXDragObjectAndMouse > componentBlockWidth / 2) { | |
if ((PortalDragDrop.backupDragObjectWidth - PortalDragDrop.deltaXDragObjectAndMouse) > componentBlockWidth / 2) { | |
dragObjectLeft = originalDragObjectLeft + PortalDragDrop.deltaXDragObjectAndMouse - componentBlockWidth / 2; | |
} else { | |
dragObjectLeft = originalDragObjectLeft + PortalDragDrop.backupDragObjectWidth - componentBlockWidth; | |
} | |
} | |
if (eXo.core.I18n.isLT()) dragObject.style.left = dragObjectLeft + "px"; | |
else dragObject.style.right = PortalDragDrop.positionRootObj.offsetWidth - dragObject.offsetWidth - dragObjectLeft + "px"; | |
eXo.portal.isInDragging = true; | |
} | |
DragDrop.dragCallback = function (dndEvent) { | |
var dragObject = dndEvent.dragObject; | |
eXo.portal.PortalDragDrop.scrollOnDrag(dndEvent); | |
if (!dndEvent.foundTargetObject) { | |
if (!dndEvent.lastFoundTargetObject) { | |
return; | |
} else { | |
dndEvent.foundTargetObject = dndEvent.lastFoundTargetObject; | |
} | |
} | |
var uiComponentLayout; | |
if (dndEvent.foundTargetObject.className == "UIPage") { | |
uiComponentLayout = DOMUtil.findFirstDescendantByClass(dndEvent.foundTargetObject, "div", "VIEW-PAGE"); | |
} else if (dndEvent.foundTargetObject.className == "UIPortal") { | |
if (eXo.portal.portalMode % 2) uiComponentLayout = DOMUtil.findFirstDescendantByClass(dndEvent.foundTargetObject, "div", "LAYOUT-PORTAL"); | |
else uiComponentLayout = DOMUtil.findFirstDescendantByClass(dndEvent.foundTargetObject, "div", "VIEW-PORTAL"); | |
} else { | |
var foundUIComponent = new eXo.portal.UIPortalComponent(dndEvent.foundTargetObject); | |
if (eXo.portal.portalMode % 2) uiComponentLayout = foundUIComponent.getLayoutBlock(); | |
else uiComponentLayout = foundUIComponent.getViewBlock(); | |
uiComponentLayout.style.height = "auto"; | |
} | |
dndEvent.foundTargetObject.uiComponentLayoutType = uiComponentLayout; | |
var componentIdElement = DOMUtil.getChildrenByTagName(uiComponentLayout, "div")[0]; | |
var layoutTypeElement = DOMUtil.getChildrenByTagName(componentIdElement, "div")[0]; | |
eXo.portal.PortalDragDrop.layoutTypeElementNode = layoutTypeElement; | |
if (previewBlock == null) previewBlock = eXo.portal.PortalDragDrop.createPreview(); | |
if (layoutTypeElement != null && !DOMUtil.hasClass(layoutTypeElement, "UITableColumnContainer")) { | |
var rowContainer = DOMUtil.findFirstDescendantByClass(uiComponentLayout, "div", "UIRowContainer"); | |
var childRowContainer = DOMUtil.getChildrenByTagName(rowContainer, "div"); | |
var listComponent = new Array(); | |
for (var i = 0; i < childRowContainer.length; i++) { | |
if ((childRowContainer[i].className != "DragAndDropPreview") && (childRowContainer[i] != dragObject)) { | |
listComponent.push(childRowContainer[i]); | |
} | |
} | |
dndEvent.foundTargetObject.listComponentInTarget = listComponent; | |
var insertPosition = eXo.portal.PortalDragDrop.findInsertPosition(listComponent, "row", dndEvent.backupMouseEvent); | |
dndEvent.foundTargetObject.foundIndex = insertPosition; | |
if (insertPosition >= 0) { | |
rowContainer.insertBefore(previewBlock, listComponent[insertPosition]); | |
} else { | |
rowContainer.appendChild(previewBlock); | |
} | |
} else { | |
var columnContainer = DOMUtil.findFirstDescendantByClass(uiComponentLayout, "table", "UITableColumnContainer"); | |
var trContainer = DOMUtil.findFirstDescendantByClass(uiComponentLayout, "tr", "TRContainer"); | |
var tdElementList = DOMUtil.getChildrenByTagName(trContainer, "td"); | |
var listComponent = new Array(); | |
for (var i = 0; i < tdElementList.length; i++) { | |
if (DOMUtil.hasAncestor(previewBlock, uiComponentLayout)) { | |
var td = tdElementList[i]; | |
if ((td != previewBlock.parentNode) && (td != dragObject.parentNode)) { | |
listComponent.push(td); | |
} | |
} else { | |
listComponent.push(tdElementList[i]); | |
} | |
} | |
dndEvent.foundTargetObject.listComponentInTarget = listComponent; | |
var insertPosition = eXo.portal.PortalDragDrop.findInsertPosition(listComponent, "column", dndEvent.backupMouseEvent); | |
dndEvent.foundTargetObject.foundIndex = insertPosition; | |
if (insertPosition >= 0) { | |
trContainer.insertBefore(dragObject.parentNode, listComponent[insertPosition]); | |
} else { | |
trContainer.appendChild(dragObject.parentNode); | |
} | |
} | |
var dragParent = dragObject.parentNode; | |
if (eXo.core.DOMUtil.getChildrenByTagName(dragParent, "div").length === 1 && !eXo.core.DOMUtil.hasClass(dragParent, "EmptyContainer")) { | |
eXo.core.DOMUtil.addClass(dragParent, "EmptyContainer"); | |
} | |
}; | |
DragDrop.dropCallback = function (dndEvent) { | |
var hasChanged = true; | |
if (dndEvent.backupMouseEvent && dndEvent.backupMouseEvent.keyCode == 27) { | |
hasChanged = false; | |
} | |
if (!dndEvent.foundTargetObject) { | |
dndEvent.foundTargetObject = dndEvent.lastFoundTargetObject; | |
} | |
var targetElement = dndEvent.foundTargetObject; | |
if (!targetElement || targetElement.foundIndex == null) { | |
hasChanged = false; | |
} | |
var DOMUtil = eXo.core.DOMUtil; | |
if (!dndEvent.dragObject.isAddingNewly) { | |
if (dndEvent.dragObject.parentNode.tagName.toLowerCase() == "td") { | |
var backupParentSibling = eXo.portal.PortalDragDrop.backupParentSibling; | |
if (DOMUtil.findNextElementByTagName(dndEvent.dragObject.parentNode, "td") == backupParentSibling) { | |
hasChanged = false; | |
} | |
} else { | |
var tempObj = DOMUtil.findNextElementByTagName(dndEvent.dragObject, "div"); | |
if (tempObj != null && tempObj.className == "DragAndDropPreview") { | |
hasChanged = false; | |
} else { | |
tempObj = DOMUtil.findPreviousElementByTagName(dndEvent.dragObject, "div"); | |
if (tempObj != null && tempObj.className == "DragAndDropPreview") { | |
hasChanged = false; | |
} | |
} | |
} | |
} | |
if (dndEvent.backupMouseEvent && dndEvent.backupMouseEvent.keyCode != 27) { | |
eXo.portal.PortalDragDrop.doDropCallback(dndEvent); | |
} else { | |
if (dndEvent.dragObject.parentNode && dndEvent.dragObject.parentNode.tagName.toLowerCase() == "td") { | |
var tdNode = dndEvent.dragObject.parentNode; | |
var lastSibling = eXo.portal.PortalDragDrop.backupParentSibling; | |
if (lastSibling == null) { | |
tdNode.parentNode.appendChild(tdNode); | |
} else { | |
tdNode.parentNode.insertBefore(tdNode, lastSibling); | |
} | |
} | |
if (dndEvent.dragObject.isAddingNewly) { | |
dndEvent.dragObject.parentNode.removeChild(dndEvent.dragObject); | |
} | |
} | |
if (!dndEvent.dragObject.isAddingNewly) { | |
var componentBlock = eXo.core.DOMUtil.findFirstDescendantByClass(dndEvent.dragObject, "div", "UIComponentBlock"); | |
var editBlock = eXo.core.DOMUtil.findFirstChildByClass(componentBlock, "div", "EDITION-BLOCK"); | |
if (editBlock) editBlock.style.display = "none"; | |
} | |
if (previewBlock) previewBlock.parentNode.removeChild(previewBlock); | |
previewBlock = null; | |
eXo.portal.isInDragging = false; | |
if (hasChanged) { | |
eXo.portal.UIPortal.changeComposerSaveButton(); | |
} | |
this.origDragObjectStyle.setProperties(dndEvent.dragObject.style, false); | |
}; | |
var clickObject = this; | |
var componentBlock = DOMUtil.findAncestorByClass(clickObject, "UIComponentBlock"); | |
if (componentBlock != null) { | |
var dragBlock = eXo.portal.UIPortal.findUIComponentOf(componentBlock); | |
DragDrop.init(eXo.portal.PortalDragDrop.findDropableTargets(dragBlock), clickObject, dragBlock, e); | |
} else { | |
var dragBlock = DOMUtil.findAncestorByClass(clickObject, "DragObjectPortlet"); | |
if (dragBlock) { | |
eXo.debug("The dragBlock is not null"); | |
DragDrop.init(eXo.portal.PortalDragDrop.findDropableTargets(dragBlock), clickObject, dragBlock, e); | |
} else { | |
DragDrop.init(eXo.portal.PortalDragDrop.findDropableTargets(dragBlock), clickObject, clickObject, e); | |
} | |
} | |
}; | |
PortalDragDrop.prototype.doDropCallback = function (dndEvent) { | |
var srcElement = dndEvent.dragObject; | |
var targetElement = dndEvent.foundTargetObject; | |
if (!targetElement || targetElement.foundIndex == null) { | |
if (dndEvent.dragObject.isAddingNewly) { | |
dndEvent.dragObject.parentNode.removeChild(dndEvent.dragObject); | |
} | |
dndEvent.dragObject.style.width = "auto"; | |
return; | |
} | |
if (!srcElement.isAddingNewly && (targetElement.foundIndex != null)) { | |
if (eXo.portal.PortalDragDrop.layoutTypeElementNode != null) { | |
eXo.portal.PortalDragDrop.divRowContainerAddChild(srcElement, targetElement, targetElement.foundIndex); | |
} | |
} | |
if (srcElement.isAddingNewly) { | |
eXo.core.DOMUtil.removeElement(srcElement); | |
} | |
var params = [{ | |
name: "srcID", | |
value: (srcElement.id.replace(/^UIPortlet-/, "")) | |
}, { | |
name: "targetID", | |
value: targetElement.id.replace(/^.*-/, "") | |
}, { | |
name: "insertPosition", | |
value: targetElement.foundIndex | |
}, { | |
name: "isAddingNewly", | |
value: srcElement.isAddingNewly | |
}]; | |
try { | |
dndEvent.lastFoundTargetObject.foundIndex = null; | |
} catch (err) {} | |
ajaxGet(eXo.env.server.createPortalURL("UIPortal", "MoveChild", true, params)); | |
}; | |
PortalDragDrop.prototype.findDropableTargets = function (dragBlock) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var dropableTargets = new Array(); | |
if (dragBlock && DOMUtil.hasClass(dragBlock, "UIColumnContainer")) { | |
var uiTableContainer = eXo.core.DOMUtil.findAncestorByClass(dragBlock, "UITableColumnContainer"); | |
dropableTargets.push(uiTableContainer); | |
return dropableTargets; | |
} | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
var pagebody = document.getElementById("UIPageBody"); | |
if (eXo.portal.portalMode && pagebody) { | |
var uiPortal = DOMUtil.findFirstDescendantByClass(uiWorkingWorkspace, "div", "UIPortal"); | |
dropableTargets.push(uiPortal); | |
} else { | |
var uiPage = DOMUtil.findFirstDescendantByClass(uiWorkingWorkspace, "div", "UIPage"); | |
if (uiPage) dropableTargets.push(uiPage); | |
} | |
var uiContainers = DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "UIContainer"); | |
for (var i = 0; i < uiContainers.length; i++) { | |
if (DOMUtil.hasAncestor(uiContainers[i], dragBlock)) continue; | |
if (DOMUtil.hasClass(uiContainers[i], "ProtectedContainer")) continue; | |
if (DOMUtil.hasClass(uiContainers[i], "UITableColumnContainer")) continue; | |
dropableTargets.push(uiContainers[i]); | |
} | |
return dropableTargets; | |
}; | |
PortalDragDrop.prototype.scrollOnDrag = function (dndEvent) { | |
var workspaceHeight = document.getElementById("UIWorkingWorkspace").offsetHeight; | |
var browserHeight = eXo.core.Browser.getBrowserHeight(); | |
if (workspaceHeight <= browserHeight) return; | |
var mouseY = eXo.core.Browser.findMouseYInClient(dndEvent.backupMouseEvent); | |
var deltaTop = mouseY - (Math.round(browserHeight * 5 / 6)); | |
var deltaBottom = mouseY - (Math.round(browserHeight / 6)); | |
var currentDragObjPos = parseInt(dndEvent.dragObject.style.top); | |
if (deltaTop > 0) { | |
document.documentElement.scrollTop += deltaTop - 5; | |
currentDragObjPos += deltaTop - 5; | |
} | |
if (deltaBottom < 0 && document.documentElement.scrollTop > 0) { | |
document.documentElement.scrollTop += deltaBottom; | |
currentDragObjPos += deltaBottom; | |
} | |
dndEvent.dragObject.style.top = currentDragObjPos + "px"; | |
}; | |
PortalDragDrop.prototype.findInsertPosition = function (components, layout, mouseEvent) { | |
var Browser = eXo.core.Browser; | |
if (layout == "row") { | |
for (var i = 0; i < components.length; i++) { | |
var componentTop = Browser.findPosY(components[i]); | |
var mouseYInPage = Browser.findMouseYInPage(mouseEvent); | |
var componentMIddle = componentTop + Math.round(components[i].offsetHeight / 2); | |
if (mouseYInPage > componentMIddle) continue; | |
else return i; | |
} | |
return -1; | |
} else { | |
for (var i = 0; i < components.length; i++) { | |
var mouseXInPage = Browser.findMouseXInPage(mouseEvent); | |
var componentX = Browser.findPosX(components[i], eXo.core.I18n.isRT()); | |
if (eXo.core.I18n.isRT()) { | |
if (mouseXInPage < componentX) continue; | |
} else if (mouseXInPage > componentX) continue; | |
return i; | |
} | |
return -1; | |
} | |
}; | |
PortalDragDrop.prototype.createPreview = function (layoutType) { | |
var previewBlock = document.createElement("div"); | |
previewBlock.className = "DragAndDropPreview"; | |
previewBlock.id = "DragAndDropPreview"; | |
return previewBlock; | |
}; | |
PortalDragDrop.prototype.divRowContainerAddChild = function (srcElement, targetElement, insertPosition) { | |
var listComponent = eXo.core.DragDrop.dndEvent.foundTargetObject.listComponentInTarget; | |
var uiRowContainer = eXo.core.DOMUtil.findFirstDescendantByClass(targetElement, "div", "UIRowContainer"); | |
srcElement.style.width = "auto"; | |
var parentNode = srcElement.parentNode; | |
if (insertPosition >= 0) { | |
uiRowContainer.insertBefore(srcElement, listComponent[insertPosition]); | |
} else { | |
uiRowContainer.appendChild(srcElement); | |
} | |
eXo.core.DOMUtil.removeClass(uiRowContainer, "EmptyContainer"); | |
if (parentNode.nodeName.toLowerCase() == "td") { | |
eXo.core.DOMUtil.removeElement(parentNode); | |
} | |
}; | |
eXo.portal.PortalDragDrop = new PortalDragDrop(); | |
function UIPortalNavigation() { | |
this.currentOpenedMenu = null; | |
this.scrollMgr = null; | |
this.scrollManagerLoaded = false; | |
}; | |
UIPortalNavigation.prototype.init = function (popupMenu, container, x, y) { | |
this.superClass = eXo.webui.UIPopupMenu; | |
this.superClass.init(popupMenu, container, x, y); | |
this.tabStyleClass = "MenuItem"; | |
this.itemStyleClass = "NormalItem"; | |
this.selectedItemStyleClass = "SelectedItem"; | |
this.itemOverStyleClass = "OverItem"; | |
this.containerStyleClass = "MenuItemContainer"; | |
this.buildMenu(popupMenu); | |
}; | |
UIPortalNavigation.prototype.onLoad = function () { | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
var uiNavPortlets = eXo.core.DOMUtil.findDescendantsByClass(uiWorkingWorkspace, "div", "UINavigationPortlet"); | |
if (uiNavPortlets.length) { | |
var mainContainer = eXo.core.DOMUtil.findFirstDescendantByClass(uiNavPortlets[0], "ul", "UIHorizontalTabs"); | |
eXo.portal.UIPortalNavigation.init(uiNavPortlets[0], mainContainer, 0, 0); | |
for (var i = 1; i < uiNavPortlets.length; ++i) { | |
uiNavPortlets[i].style.display = "none"; | |
} | |
} | |
}; | |
UIPortalNavigation.prototype.buildMenu = function (popupMenu) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var topContainer = DOMUtil.findFirstDescendantByClass(popupMenu, "ul", "UIHorizontalTabs"); | |
topContainer.id = "PortalNavigationTopContainer"; | |
var topItems = DOMUtil.findDescendantsByClass(topContainer, "li", "UITab"); | |
for (var i = 0; i < topItems.length; i++) { | |
var item = topItems[i]; | |
item.onmouseover = eXo.portal.UIPortalNavigation.setTabStyleOnMouseOver; | |
item.onmouseout = eXo.portal.UIPortalNavigation.setTabStyleOnMouseOut; | |
if (!item.getAttribute('hidesubmenu')) { | |
item.onmousemove = eXo.portal.UIPortalNavigation.tabOnMouseMove; | |
} | |
item.style.width = item.offsetWidth + "px"; | |
} | |
var container = DOMUtil.findFirstDescendantByClass(item, "ul", this.containerStyleClass); | |
if (container) { | |
if (eXo.core.Browser.isIE6()) { | |
container.style.width = item.offsetWidth + "px"; | |
} else { | |
container.style.minWidth = item.offsetWidth + "px"; | |
} | |
} | |
var itemConts = DOMUtil.findDescendantsByClass(topContainer, "ul", this.containerStyleClass); | |
for (var i = 0; i < itemConts.length; i++) { | |
var cont = itemConts[i]; | |
if (!cont.id) cont.id = DOMUtil.generateId("PortalNavigationContainer"); | |
cont.resized = false; | |
var items = DOMUtil.findDescendantsByClass(cont, "li", this.tabStyleClass); | |
if (items.length == 0) cont.parentNode.removeChild(cont); | |
for (var j = 0; j < items.length; j++) { | |
items[j].onmouseover = eXo.portal.UIPortalNavigation.onMenuItemOver; | |
items[j].onmouseout = eXo.portal.UIPortalNavigation.onMenuItemOut; | |
} | |
} | |
}; | |
UIPortalNavigation.prototype.generateContainer = function (data) { | |
var htmlFrags = "<ul class='" + this.containerStyleClass + "' style='display: none;' id='"; | |
htmlFrags += eXo.core.DOMUtil.generateId("PortalNavigationContainer") + "' resized='false'>"; | |
for (var i = 0; i < data.length; i++) { | |
var node = data[i]; | |
var actionLink = node.actionLink ? node.actionLink : "javascript:void(0);"; | |
htmlFrags += ("<li class='MenuItem " + (node.hasChild ? "ArrowIcon " : "") + (node.isSelected ? "SelectedItem'" : "NormalItem'")); | |
htmlFrags += (node.hasChild ? (" exo:getNodeURL='" + node.getNodeURL + "' ") : ""); | |
htmlFrags += ("onmouseover='eXo.portal.UIPortalNavigation.onMenuItemOver(this)' onmouseout='eXo.portal.UIPortalNavigation.onMenuItemOut(this)'"); | |
htmlFrags += ("' title='" + node.label + "'>"); | |
htmlFrags += ("<a class='ItemIcon " + (node.icon ? node.icon : "DefaultPageIcon") + "'" + "href='" + actionLink + "'>" + (node.label.length > 40 ? node.label.substring(0, 37) + "..." : node.label) + "</a>"); | |
if (node.childs.length) { | |
htmlFrags += eXo.portal.UIPortalNavigation.generateContainer(node.childs); | |
} | |
htmlFrags += "</li>"; | |
} | |
htmlFrags += "</ul>"; | |
return htmlFrags; | |
}; | |
UIPortalNavigation.prototype.setTabStyleOnMouseOver = function (e) { | |
var tab = this; | |
if (eXo.portal.UIPortalNavigation.previousMenuItem != tab) { | |
eXo.portal.UIPortalNavigation.hideMenu(); | |
} | |
eXo.portal.UIPortalNavigation.setTabStyleOnMouseOut(e, tab); | |
eXo.portal.UIPortalNavigation.previousMenuItem = tab; | |
var getNodeURL = tab.getAttribute("exo:getNodeURL"); | |
var menuItemContainer = eXo.core.DOMUtil.findFirstDescendantByClass(tab, "ul", eXo.portal.UIPortalNavigation.containerStyleClass); | |
if (getNodeURL && !menuItemContainer) { | |
var jsChilds = ajaxAsyncGetRequest(getNodeURL, false) | |
try { | |
var data = eXo.core.JSON.parse(jsChilds); | |
} catch (e) {} | |
if (!data || !data.length) { | |
return; | |
} | |
var temp = document.createElement("div"); | |
temp.innerHTML = eXo.portal.UIPortalNavigation.generateContainer(data); | |
tab.appendChild(eXo.core.DOMUtil.findFirstChildByClass(temp, "ul", eXo.portal.UIPortalNavigation.containerStyleClass)); | |
} | |
if (!eXo.portal.UIPortalNavigation.menuVisible) { | |
var hideSubmenu = tab.getAttribute('hideSubmenu'); | |
menuItemContainer = eXo.core.DOMUtil.findFirstDescendantByClass(tab, "ul", eXo.portal.UIPortalNavigation.containerStyleClass); | |
if (menuItemContainer && !hideSubmenu) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (eXo.core.Browser.browserType == "ie") { | |
var navAncestor = DOMUtil.findAncestorByClass(tab, "UINavigationPortlet"); | |
var pageBody = document.getElementById("UIPageBody"); | |
if (pageBody) { | |
var uicomponents = DOMUtil.getChildrenByTagName(pageBody.parentNode, "div"); | |
for (var i = 0; i < uicomponents.length; i++) { | |
var navPortlet = DOMUtil.findFirstDescendantByClass(uicomponents[i], "div", "UINavigationPortlet"); | |
if (navPortlet && (navAncestor != navPortlet)) { | |
var tabsContainer = DOMUtil.findFirstDescendantByClass(navPortlet, "ul", "UIHorizontalTabs"); | |
tabsContainer.style.position = "static"; | |
} | |
} | |
} | |
} | |
eXo.portal.UIPortalNavigation.toggleSubMenu(e, tab, menuItemContainer); | |
} | |
} | |
eXo.portal.UIPortalNavigation.cancelHideMenuContainer(); | |
eXo.portal.UIPortalNavigation.menuVisible = true; | |
}; | |
UIPortalNavigation.prototype.setTabStyleOnMouseOut = function (e, src) { | |
var tab = src || this; | |
if (!eXo.core.DOMUtil.hasClass(tab, "HighlightNavigationTab")) { | |
eXo.webui.UIHorizontalTabs.changeTabNavigationStyle(tab, true); | |
} else { | |
if (tab.id != eXo.portal.UIPortalNavigation.currentOpenedMenu) { | |
eXo.webui.UIHorizontalTabs.changeTabNavigationStyle(tab, false); | |
} | |
} | |
eXo.portal.UIPortalNavigation.hideMenuTimeout(300); | |
} | |
UIPortalNavigation.prototype.tabOnMouseMove = function () { | |
eXo.portal.UIPortalNavigation.cancelHideMenuContainer(); | |
}; | |
UIPortalNavigation.prototype.toggleSubMenu = function (e, tab, menuItemContainer) { | |
if (!e) e = window.event; | |
e.cancelBubble = true; | |
var src = eXo.core.Browser.getEventSource(e); | |
if (src.tagName.toLowerCase() == "a" && !menuItemContainer) { | |
if (src.href.substr(0, 7) == "http://") { | |
if (!src.target) { | |
window.location.href = src.href | |
} else { | |
return true; | |
} | |
} else eval(src.href); | |
return false; | |
} | |
var item = tab; | |
var DOMUtil = eXo.core.DOMUtil; | |
if (menuItemContainer) { | |
if (menuItemContainer.style.display == "none") { | |
if (eXo.portal.UIPortalNavigation.currentOpenedMenu) eXo.portal.UIPortalNavigation.hideMenu(); | |
eXo.portal.UIPortalNavigation.superClass.pushVisibleContainer(menuItemContainer.id); | |
menuItemContainer.style.display = "block"; | |
menuItemContainer.style.position = "absolute"; | |
var offParent = menuItemContainer.offsetParent; | |
var y = item.offsetHeight + eXo.core.Browser.findPosYInContainer(item, offParent); | |
var x = eXo.core.Browser.findPosXInContainer(item, offParent) + 2; | |
if (eXo.core.I18n.isRT()) { | |
x = eXo.core.Browser.findPosX(offParent) + offParent.offsetWidth - eXo.core.Browser.findPosX(item) - item.offsetWidth; | |
} | |
eXo.portal.UIPortalNavigation.superClass.setPosition(menuItemContainer, x, y, eXo.core.I18n.isRT()); | |
eXo.portal.UIPortalNavigation.superClass.show(menuItemContainer); | |
menuItemContainer.style.width = menuItemContainer.offsetWidth - parseInt(DOMUtil.getStyle(menuItemContainer, "borderLeftWidth", true)) - parseInt(DOMUtil.getStyle(menuItemContainer, "borderRightWidth", true)) + "px"; | |
var posXinBrowser = eXo.core.Browser.findPosX(menuItemContainer); | |
if (eXo.core.I18n.isLT()) { | |
if (posXinBrowser + menuItemContainer.offsetWidth >= eXo.core.Browser.getBrowserWidth()) { | |
x += (item.offsetWidth - menuItemContainer.offsetWidth); | |
menuItemContainer.style.left = x + "px"; | |
} | |
} else { | |
if (posXinBrowser + item.offsetWidth < menuItemContainer.offsetWidth) { | |
x += (item.offsetWidth - menuItemContainer.offsetWidth); | |
menuItemContainer.style.right = x + "px"; | |
} | |
} | |
eXo.portal.UIPortalNavigation.currentOpenedMenu = menuItemContainer.id; | |
var uiPortalApplication = document.getElementById("UIPortalApplication"); | |
uiPortalApplication.onclick = eXo.portal.UIPortalNavigation.hideMenu; | |
} else { | |
eXo.portal.UIPortalNavigation.hideMenuContainer(); | |
} | |
} | |
}; | |
UIPortalNavigation.prototype.cancelHideMenuContainer = function () { | |
if (this.hideMenuTimeoutId) { | |
window.clearTimeout(this.hideMenuTimeoutId); | |
} | |
}; | |
UIPortalNavigation.prototype.closeMenuTimeout = function () { | |
eXo.portal.UIPortalNavigation.hideMenuTimeout(200); | |
}; | |
UIPortalNavigation.prototype.hideMenuTimeout = function (time) { | |
this.cancelHideMenuContainer(); | |
if (!time || time <= 0) { | |
time = 200; | |
} | |
this.hideMenuTimeoutId = window.setTimeout('eXo.portal.UIPortalNavigation.hideMenu() ;', time); | |
}; | |
UIPortalNavigation.prototype.hideMenuContainer = function () { | |
var menuItemContainer = document.getElementById(eXo.portal.UIPortalNavigation.currentOpenedMenu); | |
if (menuItemContainer) { | |
eXo.portal.UIPortalNavigation.superClass.pushHiddenContainer(menuItemContainer.id); | |
eXo.portal.UIPortalNavigation.superClass.popVisibleContainer(); | |
eXo.portal.UIPortalNavigation.superClass.setCloseTimeout(); | |
eXo.portal.UIPortalNavigation.superClass.hide(menuItemContainer); | |
eXo.portal.UIPortalNavigation.currentOpenedMenu = null; | |
} | |
this.previousMenuItem = false; | |
eXo.portal.UIPortalNavigation.menuVisible = false; | |
}; | |
UIPortalNavigation.prototype.hideMenu = function () { | |
if (eXo.portal.UIPortalNavigation.currentOpenedMenu) { | |
var currentItemContainer = document.getElementById(eXo.portal.UIPortalNavigation.currentOpenedMenu); | |
var tab = eXo.core.DOMUtil.findAncestorByClass(currentItemContainer, "UITab"); | |
eXo.webui.UIHorizontalTabs.changeTabNavigationStyle(tab, false); | |
} | |
eXo.portal.UIPortalNavigation.hideMenuContainer(); | |
var DOMUtil = eXo.core.DOMUtil; | |
if (eXo.core.Browser.browserType == "ie") { | |
var pageBody = document.getElementById("UIPageBody"); | |
if (!pageBody) return; | |
var uicomponents = DOMUtil.getChildrenByTagName(pageBody.parentNode, "div"); | |
for (var i = 0; i < uicomponents.length; i++) { | |
var navPortlet = DOMUtil.findFirstDescendantByClass(uicomponents[i], "div", "UINavigationPortlet"); | |
if (navPortlet) { | |
var tabsContainer = DOMUtil.findFirstDescendantByClass(navPortlet, "ul", "UIHorizontalTabs"); | |
tabsContainer.style.position = "relative"; | |
} | |
} | |
} | |
}; | |
UIPortalNavigation.prototype.onMenuItemOver = function (menuItem) { | |
if (!menuItem || !menuItem.nodeName) menuItem = this; | |
var DOMUtil = eXo.core.DOMUtil; | |
var getNodeURL = menuItem.getAttribute("exo:getNodeURL"); | |
var subContainer = DOMUtil.findFirstDescendantByClass(menuItem, "ul", eXo.portal.UIPortalNavigation.containerStyleClass); | |
if (getNodeURL && !subContainer) { | |
var jsChilds = ajaxAsyncGetRequest(getNodeURL, false) | |
try { | |
var data = eXo.core.JSON.parse(jsChilds); | |
} catch (e) {} | |
if (!data || !data.length) { | |
DOMUtil.removeClass(menuItem, "ArrowIcon"); | |
menuItem.removeAttribute("exo:getNodeURL"); | |
return; | |
} | |
var temp = document.createElement("div"); | |
temp.innerHTML = eXo.portal.UIPortalNavigation.generateContainer(data); | |
menuItem.appendChild(eXo.core.DOMUtil.findFirstChildByClass(temp, "ul", eXo.portal.UIPortalNavigation.containerStyleClass)); | |
} | |
subContainer = DOMUtil.findFirstDescendantByClass(menuItem, "ul", eXo.portal.UIPortalNavigation.containerStyleClass); | |
if (subContainer) { | |
eXo.portal.UIPortalNavigation.superClass.pushVisibleContainer(subContainer.id); | |
eXo.portal.UIPortalNavigation.showMenuItemContainer(menuItem, subContainer); | |
if (!subContainer.firstTime) { | |
subContainer.style.width = subContainer.offsetWidth + 2 + "px"; | |
subContainer.firstTime = true; | |
} | |
} | |
}; | |
UIPortalNavigation.prototype.showMenuItemContainer = function (menuItem, menuItemContainer) { | |
var x = menuItem.offsetWidth; | |
var y = menuItem.offsetTop; | |
this.superClass.show(menuItemContainer); | |
var posRight = eXo.core.Browser.getBrowserWidth() - eXo.core.Browser.findPosX(menuItem) - menuItem.offsetWidth; | |
var rootX = (eXo.core.I18n.isLT() ? eXo.core.Browser.findPosX(menuItem) : posRight); | |
if (x + menuItemContainer.offsetWidth + rootX > eXo.core.Browser.getBrowserWidth()) { | |
x -= (menuItemContainer.offsetWidth + menuItem.offsetWidth); | |
} | |
this.superClass.setPosition(menuItemContainer, x, y, eXo.core.I18n.isRT()); | |
}; | |
UIPortalNavigation.prototype.onMenuItemOut = function (menuItem) { | |
if (!menuItem || !menuItem.nodeName) menuItem = this; | |
var subContainer = eXo.core.DOMUtil.findFirstDescendantByClass(menuItem, "ul", eXo.portal.UIPortalNavigation.containerStyleClass); | |
if (subContainer) { | |
eXo.portal.UIPortalNavigation.superClass.pushHiddenContainer(subContainer.id); | |
eXo.portal.UIPortalNavigation.superClass.popVisibleContainer(); | |
eXo.portal.UIPortalNavigation.superClass.setCloseTimeout(300); | |
} | |
}; | |
UIPortalNavigation.prototype.loadScroll = function (e) { | |
var uiNav = eXo.portal.UIPortalNavigation; | |
var portalNav = document.getElementById("PortalNavigationTopContainer"); | |
if (portalNav) { | |
uiNav.scrollMgr = eXo.portal.UIPortalControl.newScrollManager("PortalNavigationTopContainer"); | |
uiNav.scrollMgr.initFunction = uiNav.initScroll; | |
uiNav.scrollMgr.mainContainer = portalNav; | |
uiNav.scrollMgr.arrowsContainer = eXo.core.DOMUtil.findFirstDescendantByClass(portalNav, "li", "ScrollButtons"); | |
uiNav.scrollMgr.loadElements("UITab"); | |
var arrowButtons = eXo.core.DOMUtil.findDescendantsByTagName(uiNav.scrollMgr.arrowsContainer, "a"); | |
if (arrowButtons.length == 2) { | |
uiNav.scrollMgr.initArrowButton(arrowButtons[0], "left", "ScrollLeftButton", "HighlightScrollLeftButton", "DisableScrollLeftButton"); | |
uiNav.scrollMgr.initArrowButton(arrowButtons[1], "right", "ScrollRightButton", "HighlightScrollRightButton", "DisableScrollRightButton"); | |
} | |
uiNav.scrollMgr.callback = uiNav.scrollCallback; | |
uiNav.scrollManagerLoaded = true; | |
uiNav.initScroll(); | |
} | |
}; | |
UIPortalNavigation.prototype.initScroll = function (e) { | |
if (!eXo.portal.UIPortalNavigation.scrollManagerLoaded) eXo.portal.UIPortalNavigation.loadScroll(); | |
var scrollMgr = eXo.portal.UIPortalNavigation.scrollMgr; | |
scrollMgr.init(); | |
scrollMgr.checkAvailableSpace(); | |
scrollMgr.renderElements(); | |
}; | |
UIPortalNavigation.prototype.scrollCallback = function () {}; | |
eXo.portal.UIPortalNavigation = new UIPortalNavigation(); | |
function UIMaskWorkspace() {}; | |
UIMaskWorkspace.prototype.init = function (maskId, show, width, height) { | |
var maskWorkpace = document.getElementById(maskId); | |
this.maskWorkpace = maskWorkpace; | |
if (this.maskWorkpace) { | |
if (width > -1) this.maskWorkpace.style.width = width + "px"; | |
if (show) { | |
if (eXo.portal.UIMaskWorkspace.maskLayer == null) { | |
var maskLayer = eXo.core.UIMaskLayer.createMask("UIPortalApplication", this.maskWorkpace, 30); | |
eXo.portal.UIMaskWorkspace.maskLayer = maskLayer; | |
} | |
this.maskWorkpace.style.margin = "auto"; | |
this.maskWorkpace.style.display = "block"; | |
} else { | |
if (eXo.portal.UIMaskWorkspace.maskLayer == undefined) return; | |
eXo.core.UIMaskLayer.removeMask(eXo.portal.UIMaskWorkspace.maskLayer); | |
eXo.portal.UIMaskWorkspace.maskLayer = null; | |
this.maskWorkpace.style.display = "none"; | |
} | |
if (height < 0) return; | |
} | |
}; | |
UIMaskWorkspace.prototype.resetPosition = function () { | |
var maskWorkpace = eXo.portal.UIMaskWorkspace.maskWorkpace; | |
if (maskWorkpace && (maskWorkpace.style.display == "block")) { | |
try { | |
eXo.core.UIMaskLayer.blockContainer = document.getElementById("UIPortalApplication"); | |
eXo.core.UIMaskLayer.object = maskWorkpace; | |
eXo.core.UIMaskLayer.setPosition(); | |
} catch (e) {} | |
} | |
}; | |
eXo.portal.UIMaskWorkspace = new UIMaskWorkspace(); | |
function UIBrowseContent() { | |
this.bcManagers = new Array(); | |
}; | |
UIBrowseContent.prototype.waitForLoadComplete = function () { | |
var homeButton = null; | |
var bcPortlet = document.getElementById("UIBrowseContainer"); | |
if (bcPortlet) homeButton = eXo.core.DOMUtil.findFirstDescendantByClass(bcPortlet, "div", "HomeTab"); | |
var tabs = eXo.core.DOMUtil.findFirstDescendantByClass(bcPortlet, "div", "UIHorizontalTabs"); | |
if (homeButton && tabs && homeButton.offsetWidth == tabs.offsetWidth) window.setTimeout(eXo.portal.UIBrowseContent.waitForLoadComplete, 100); | |
else eXo.portal.UIBrowseContent.loadScroll(); | |
}; | |
UIBrowseContent.prototype.loadScroll = function () { | |
var uiBC = eXo.portal.UIBrowseContent; | |
uiBC.bcManagers.clear(); | |
var bcPortlet = document.getElementById("UIBrowseContainer"); | |
if (bcPortlet) { | |
var mainNav = eXo.core.DOMUtil.findFirstDescendantByClass(bcPortlet, "div", "UICBMainNavigation"); | |
var mainBarMgr = eXo.portal.UIPortalControl.newScrollManager("UIBrowseContainer"); | |
mainBarMgr.mainContainer = mainNav; | |
mainBarMgr.arrowsContainer = eXo.core.DOMUtil.findFirstDescendantByClass(mainNav, "div", "NavigationButtonContainer"); | |
mainBarMgr.loadElements("UITab", true); | |
var mainArrows = eXo.core.DOMUtil.findDescendantsByClass(mainBarMgr.arrowsContainer, "div", "NavigationIcon"); | |
if (mainArrows.length == 2) { | |
mainBarMgr.initArrowButton(mainArrows[0], "left", "NavigationIcon ScrollBackArrow16x16Icon", "NavigationIcon DisableBackArrow16x16Icon", "NavigationIcon DisableBackArrow16x16Icon"); | |
mainBarMgr.initArrowButton(mainArrows[1], "right", "NavigationIcon ScrollNextArrow16x16Icon", "NavigationIcon DisableNextArrow16x16Icon", "NavigationIcon DisableNextArrow16x16Icon"); | |
} | |
mainBarMgr.initFunction = uiBC.initScroll; | |
mainBarMgr.callback = uiBC.mainMenuScrollCallback; | |
uiBC.bcManagers.push(mainBarMgr); | |
var subNav = eXo.core.DOMUtil.findFirstDescendantByClass(bcPortlet, "div", "UICBSubNavigation"); | |
var subBarMgr = eXo.portal.UIPortalControl.newScrollManager("UIBrowseContainer"); | |
subBarMgr.mainContainer = subNav; | |
subBarMgr.arrowsContainer = eXo.core.DOMUtil.findFirstDescendantByClass(subNav, "div", "NavigationButtonContainer"); | |
subBarMgr.loadElements("ChildNodeItem", true); | |
for (var i = 0; i < subBarMgr.elements.length; i++) { | |
subBarMgr.elements[i].decorator = eXo.core.DOMUtil.findNextElementByTagName(subBarMgr.elements[i], "div"); | |
} | |
var subArrows = eXo.core.DOMUtil.findDescendantsByClass(subBarMgr.arrowsContainer, "div", "NavigationIcon"); | |
if (subArrows.length == 2) { | |
subBarMgr.initArrowButton(subArrows[0], "left", "NavigationIcon ScrollBackArrow16x16Icon", "NavigationIcon DisableBackArrow16x16Icon", "NavigationIcon DisableBackArrow16x16Icon"); | |
subBarMgr.initArrowButton(subArrows[1], "right", "NavigationIcon ScrollNextArrow16x16Icon", "NavigationIcon DisableNextArrow16x16Icon", "NavigationIcon DisableNextArrow16x16Icon"); | |
} | |
subBarMgr.initFunction = uiBC.initScroll; | |
subBarMgr.callback = uiBC.subMenuScrollCallback; | |
uiBC.bcManagers.push(subBarMgr); | |
var pageNav = eXo.core.DOMUtil.findFirstDescendantByClass(bcPortlet, "div", "UIEventViewer"); | |
var pageMenus = eXo.core.DOMUtil.findDescendantsByClass(pageNav, "div", "SubContentTitle"); | |
for (var i = 0; i < pageMenus.length; i++) { | |
var currMgr = eXo.portal.UIPortalControl.newScrollManager("UIBrowseContainer"); | |
currMgr.mainContainer = eXo.core.DOMUtil.findFirstDescendantByClass(pageMenus[i], "div", "MiddleBar"); | |
currMgr.arrowsContainer = eXo.core.DOMUtil.findFirstDescendantByClass(pageMenus[i], "div", "NavigationButtonContainer"); | |
currMgr.loadElements("ChildNode", true); | |
for (var j = 0; j < currMgr.elements.length; j++) { | |
currMgr.elements[j].decorator = eXo.core.DOMUtil.findNextElementByTagName(currMgr.elements[j], "div"); | |
} | |
var currArrows = eXo.core.DOMUtil.findDescendantsByClass(currMgr.arrowsContainer, "div", "NavigationIcon"); | |
if (currArrows.length == 2) { | |
currMgr.initArrowButton(currArrows[0], "left", "NavigationIcon ScrollBackArrow16x16Icon", "NavigationIcon DisableBackArrow16x16Icon", "NavigationIcon DisableBackArrow16x16Icon"); | |
currMgr.initArrowButton(currArrows[1], "right", "NavigationIcon ScrollNextArrow16x16Icon", "NavigationIcon DisableNextArrow16x16Icon", "NavigationIcon DisableNextArrow16x16Icon"); | |
} | |
currMgr.initFunction = uiBC.initScroll; | |
currMgr.callback = uiBC.subMenuScrollCallback; | |
uiBC.bcManagers.push(currMgr); | |
} | |
uiBC.initScroll(); | |
} | |
}; | |
UIBrowseContent.prototype.initScroll = function () { | |
var uiBC = eXo.portal.UIBrowseContent; | |
var bcPortlet = document.getElementById("UIBrowseContainer"); | |
var mainNav = eXo.core.DOMUtil.findFirstDescendantByClass(bcPortlet, "div", "UICBMainNavigation"); | |
if (mainNav) { | |
if (uiBC.bcManagers.length >= 1) { | |
var mainBarMgr = uiBC.bcManagers[0]; | |
mainBarMgr.init(); | |
mainBarMgr.loadElements("UITab", true); | |
var homeButton = eXo.core.DOMUtil.findFirstDescendantByClass(mainBarMgr.mainContainer, "div", "HomeTab"); | |
var maxSpace = mainBarMgr.getElementSpace(mainBarMgr.mainContainer) - mainBarMgr.getElementSpace(mainBarMgr.arrowsContainer) - mainBarMgr.margin - 100; | |
if (homeButton) { | |
maxSpace = maxSpace + 100 - mainBarMgr.getElementSpace(homeButton); | |
} | |
mainBarMgr.checkAvailableSpace(maxSpace); | |
mainBarMgr.renderElements(); | |
var subBarMgr = uiBC.bcManagers[1]; | |
subBarMgr.init(); | |
subBarMgr.loadElements("ChildNodeItem", true); | |
subBarMgr.checkAvailableSpace(); | |
subBarMgr.renderElements(); | |
} | |
if (uiBC.bcManagers.length >= 2) { | |
for (var i = 2; i < uiBC.bcManagers.length; i++) { | |
var currMgr = uiBC.bcManagers[i]; | |
currMgr.init(); | |
currMgr.loadElements("ChildNode", true); | |
currMgr.checkAvailableSpace(); | |
currMgr.renderElements(); | |
} | |
} | |
} | |
}; | |
UIBrowseContent.prototype.mainMenuScrollCallback = function () { | |
var homeButton = eXo.core.DOMUtil.findFirstDescendantByClass(this.mainContainer, "div", "HomeTab"); | |
if (eXo.core.Browser.isIE7()) this.cleanElements(); | |
var maxSpace = this.getElementSpace(this.mainContainer) - this.getElementSpace(this.arrowsContainer) - this.margin - 100; | |
if (homeButton) { | |
maxSpace = maxSpace + 100 - this.getElementSpace(homeButton); | |
} | |
var elementsSpace = this.getElementsSpace(this.firstVisibleIndex, this.lastVisibleIndex); | |
var delta = maxSpace - elementsSpace; | |
if (delta < 0) { | |
this.hideElements(delta); | |
} | |
}; | |
UIBrowseContent.prototype.subMenuScrollCallback = function () { | |
for (var i = 0; i < this.elements.length; i++) { | |
if (!this.elements[i].isVisible) { | |
this.elements[i].decorator.style.display = "none"; | |
} else { | |
this.elements[i].decorator.style.display = "block"; | |
} | |
} | |
}; | |
eXo.portal.UIBrowseContent = new UIBrowseContent(); | |
function UIItemSelector() { | |
this.backupClass; | |
this.backupItem; | |
}; | |
UIItemSelector.prototype.onOver = function (selectedElement, mouseOver) { | |
if (selectedElement.className == "Item") { | |
eXo.webui.UIItemSelector.beforeActionHappen(selectedElement); | |
} | |
if (mouseOver) { | |
this.backupClass = selectedElement.className; | |
selectedElement.className = "OverItem Item"; | |
} else { | |
selectedElement.className = this.backupClass; | |
} | |
}; | |
UIItemSelector.prototype.onClick = function (clickedElement) { | |
var itemListContainer = clickedElement.parentNode; | |
var allItems = eXo.core.DOMUtil.findDescendantsByClass(itemListContainer, "div", "Item"); | |
eXo.webui.UIItemSelector.beforeActionHappen(clickedElement); | |
if (this.allItems.length <= 0) return; | |
for (var i = 0; i < allItems.length; i++) { | |
if (allItems[i] != clickedElement) { | |
allItems[i].className = "Item"; | |
this.onChangeItemDetail(clickedElement, true); | |
} else { | |
allItems[i].className = "SelectedItem Item"; | |
this.backupClass = "SelectedItem Item"; | |
this.onChangeItemDetail(clickedElement, false); | |
} | |
} | |
}; | |
UIItemSelector.prototype.onChangeItemDetail = function (itemSelected, mouseOver) { | |
if (!this.allItems || this.allItems.length <= 0) return; | |
if (mouseOver) { | |
for (var i = 0; i < this.allItems.length; i++) { | |
if (this.allItems[i] == itemSelected) { | |
this.itemDetails[i].style.display = "block"; | |
} else { | |
this.itemDetails[i].style.display = "none"; | |
} | |
} | |
} else { | |
for (var i = 0; i < this.allItems.length; i++) { | |
if (this.allItems[i].className == "SelectedItem Item") { | |
this.itemDetails[i].style.display = "block"; | |
} else { | |
this.itemDetails[i].style.display = "none"; | |
} | |
} | |
} | |
}; | |
UIItemSelector.prototype.onClickCategory = function (clickedElement, form, component, option) { | |
eXo.webui.UIItemSelector.onClick(clickedElement); | |
if (eXo.webui.UIItemSelector.SelectedItem == null) { | |
eXo.webui.UIItemSelector.SelectedItem = new Object(); | |
} | |
eXo.webui.UIItemSelector.SelectedItem.component = component; | |
eXo.webui.UIItemSelector.SelectedItem.option = option; | |
}; | |
UIItemSelector.prototype.onClickOption = function (clickedElement, form, component, option) { | |
var itemDetailList = eXo.core.DOMUtil.findAncestorByClass(clickedElement, "ItemDetailList"); | |
var selectedItems = eXo.core.DOMUtil.findDescendantsByClass(itemDetailList, "div", "SelectedItem"); | |
for (var i = 0; i < selectedItems.length; i++) { | |
selectedItems[i].className = "NormalItem"; | |
} | |
clickedElement.className = "SelectedItem"; | |
if (eXo.webui.UIItemSelector.SelectedItem == null) { | |
eXo.webui.UIItemSelector.SelectedItem = new Object(); | |
} | |
eXo.webui.UIItemSelector.SelectedItem.component = component; | |
eXo.webui.UIItemSelector.SelectedItem.option = option; | |
}; | |
UIItemSelector.prototype.beforeActionHappen = function (selectedItem) { | |
DOMUtil = eXo.core.DOMUtil; | |
this.uiItemSelector = DOMUtil.findAncestorByClass(selectedItem, "UIItemSelector"); | |
this.itemList = DOMUtil.findAncestorByClass(selectedItem, "ItemList"); | |
this.itemListContainer = DOMUtil.findAncestorByClass(selectedItem, "ItemListContainer"); | |
this.itemListAray = DOMUtil.findDescendantsByClass(this.itemListContainer.parentNode, "div", "ItemList"); | |
if (this.itemListAray.length > 1) { | |
this.itemDetailLists = DOMUtil.findDescendantsByClass(this.itemListContainer.parentNode, "div", "ItemDetailList"); | |
this.itemDetailList = null; | |
for (var i = 0; i < this.itemListAray.length; i++) { | |
if (this.itemListAray[i].style.display == "none") { | |
this.itemDetailLists[i].style.display = "none"; | |
} else { | |
this.itemDetailList = this.itemDetailLists[i]; | |
this.itemDetailList.style.display = "block"; | |
} | |
} | |
} else { | |
this.itemDetailList = DOMUtil.findFirstDescendantByClass(this.itemListContainer.parentNode, "div", "ItemDetailList"); | |
} | |
this.itemDetails = DOMUtil.findDescendantsByClass(this.itemDetailList, "div", "ItemDetail"); | |
var firstItemDescendant = DOMUtil.findFirstDescendantByClass(this.itemList, "div", "Item"); | |
var firstItemParent = firstItemDescendant.parentNode; | |
this.allItems = DOMUtil.findChildrenByClass(firstItemParent, "div", "Item"); | |
}; | |
UIItemSelector.prototype.showPopupCategory = function (selectedNode) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var itemListContainer = DOMUtil.findAncestorByClass(selectedNode, "ItemListContainer"); | |
var uiPopupCategory = DOMUtil.findFirstDescendantByClass(itemListContainer, "div", "UIPopupCategory"); | |
itemListContainer.style.position = "relative"; | |
if (uiPopupCategory.style.display == "none") { | |
uiPopupCategory.style.position = "absolute"; | |
uiPopupCategory.style.top = "23px"; | |
uiPopupCategory.style.left = "0px"; | |
uiPopupCategory.style.display = "block"; | |
uiPopupCategory.style.width = "100%"; | |
} else { | |
uiPopupCategory.style.display = "none"; | |
} | |
}; | |
UIItemSelector.prototype.selectCategory = function (selectedNode) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiPopupCategory = DOMUtil.findAncestorByClass(selectedNode, "UIPopupCategory"); | |
var itemListContainer = DOMUtil.findAncestorByClass(selectedNode, "OverflowContainer"); | |
var selectedNodeIndex = eXo.webui.UIItemSelector.findIndex(selectedNode); | |
var itemLists = DOMUtil.findDescendantsByClass(itemListContainer, "div", "ItemList"); | |
var itemDetailLists = DOMUtil.findDescendantsByClass(itemListContainer, "div", "ItemDetailList"); | |
for (var i = 0; i < itemLists.length; i++) { | |
if (i != selectedNodeIndex) { | |
itemLists[i].style.display = "none"; | |
itemDetailLists[i].style.display = "none"; | |
} else { | |
itemDetailLists[i].style.display = "block"; | |
itemLists[i].style.display = "block"; | |
} | |
} | |
uiPopupCategory.style.display = "none"; | |
}; | |
UIItemSelector.prototype.findIndex = function (object) { | |
var parentNode = object.parentNode; | |
var objectElements = eXo.core.DOMUtil.findChildrenByClass(parentNode, "div", object.className); | |
for (var i = 0; i < objectElements.length; i++) { | |
if (objectElements[i] == object) return i; | |
} | |
}; | |
UIItemSelector.prototype.selectPageLayout = function (id, selectedIndex) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiDropDownControl = document.getElementById(id); | |
var itemSelectorAncestor = DOMUtil.findAncestorByClass(uiDropDownControl, "ItemSelectorAncestor"); | |
var itemList = DOMUtil.findDescendantsByClass(itemSelectorAncestor, "div", "ItemList"); | |
var itemSelectorLabel = DOMUtil.findDescendantsByClass(itemSelectorAncestor, "a", "OptionItem"); | |
var uiItemSelector = DOMUtil.findAncestorByClass(uiDropDownControl, "UIItemSelector"); | |
var itemDetailList = DOMUtil.findDescendantsByClass(uiItemSelector, "div", "ItemDetailList"); | |
if (itemList == null) return; | |
for (i = 0; i < itemSelectorLabel.length; ++i) { | |
if (i >= itemList.length) continue; | |
if (i == selectedIndex) { | |
itemList[i].style.display = "block"; | |
if (itemDetailList.length < 1) continue; | |
itemDetailList[i].style.display = "block"; | |
var selectedItem = DOMUtil.findFirstDescendantByClass(itemList[i], "div", "SelectedItem"); | |
if (selectedItem == null) continue; | |
var setValue = DOMUtil.findDescendantById(selectedItem, "SetValue"); | |
if (setValue == null) continue; | |
eval(setValue.innerHTML); | |
} else { | |
itemList[i].style.display = "none"; | |
if (itemDetailList.length > 0) itemDetailList[i].style.display = "none"; | |
} | |
} | |
}; | |
eXo.webui.UIItemSelector = new UIItemSelector(); | |
function UIForm() {}; | |
UIForm.prototype.ajaxPost = function (formElement, callback) { | |
if (!callback) callback = null; | |
var queryString = eXo.webui.UIForm.serializeForm(formElement); | |
var url = formElement.action + "&ajaxRequest=true"; | |
doRequest("POST", url, queryString, callback); | |
}; | |
UIForm.prototype.getFormElemt = function (pattern) { | |
if (pattern.indexOf("#") == -1) return document.getElementById(pattern); | |
var strArr = pattern.split("#"); | |
var portlet = document.getElementById(strArr[0]); | |
return eXo.core.DOMUtil.findDescendantById(portlet, strArr[1]); | |
} | |
UIForm.prototype.submitForm = function (formId, action, useAjax, callback) { | |
if (!callback) callback = null; | |
var form = this.getFormElemt(formId); | |
try { | |
if (FCKeditorAPI && typeof FCKeditorAPI == "object") { | |
for (var name in FCKeditorAPI.__Instances) { | |
var oEditor; | |
try { | |
oEditor = FCKeditorAPI.__Instances[name]; | |
if (oEditor && oEditor.GetParentForm && oEditor.GetParentForm() == form) { | |
oEditor.UpdateLinkedField(); | |
} | |
} catch (e) { | |
continue; | |
} | |
} | |
} | |
} catch (e) {} | |
form.elements['formOp'].value = action; | |
if (useAjax) this.ajaxPost(form, callback); | |
else form.submit(); | |
}; | |
UIForm.prototype.submitEvent = function (formId, action, params) { | |
var form = this.getFormElemt(formId); | |
try { | |
if (FCKeditorAPI && typeof FCKeditorAPI == "object") { | |
for (var name in FCKeditorAPI.__Instances) { | |
var oEditor = FCKeditorAPI.__Instances[name]; | |
if (oEditor.GetParentForm && oEditor.GetParentForm() == form) { | |
oEditor.UpdateLinkedField(); | |
} | |
} | |
} | |
} catch (e) {} | |
form.elements['formOp'].value = action; | |
if (!form.originalAction) form.originalAction = form.action; | |
form.action = form.originalAction + encodeURI(params); | |
this.ajaxPost(form); | |
}; | |
UIForm.prototype.selectBoxOnChange = function (formId, elemt) { | |
var selectBox = eXo.core.DOMUtil.findAncestorByClass(elemt, "UISelectBoxOnChange"); | |
var contentContainer = eXo.core.DOMUtil.findFirstDescendantByClass(selectBox, "div", "SelectBoxContentContainer"); | |
var tabs = eXo.core.DOMUtil.findChildrenByClass(contentContainer, "div", "SelectBoxContent"); | |
for (var i = 0; i < tabs.length; i++) { | |
tabs[i].style.display = "none"; | |
} | |
tabs[elemt.selectedIndex].style.display = "block"; | |
}; | |
UIForm.prototype.setHiddenValue = function (formId, typeId, hiddenValue) { | |
var form = document.getElementById(formId); | |
if (form == null) { | |
maskWorkspace = document.getElementById("UIMaskWorkspace"); | |
form = eXo.core.DOMUtil.findDescendantById(maskWorkspace, formId); | |
} | |
form.elements[typeId].value = hiddenValue; | |
}; | |
UIForm.prototype.serializeForm = function (formElement) { | |
var queryString = ""; | |
var element; | |
var elements = formElement.elements; | |
this.addField = function (name, value) { | |
if (queryString.length > 0) queryString += "&"; | |
queryString += name + "=" + encodeURIComponent(value); | |
}; | |
for (var i = 0; i < elements.length; i++) { | |
element = elements[i]; | |
switch (element.type) { | |
case "text": | |
case "hidden": | |
case "password": | |
case "textarea": | |
this.addField(element.name, element.value.replace(/\r/gi, "")); | |
break; | |
case "checkbox": | |
if (element.checked) this.addField(element.name, "true"); | |
else this.addField(element.name, "false"); | |
break; | |
case "radio": | |
if (element.checked) this.addField(element.name, element.value); | |
break; | |
case "select-one": | |
if (element.selectedIndex > -1) { | |
this.addField(element.name, element.options[element.selectedIndex].value); | |
} | |
break; | |
case "select-multiple": | |
for (var j = 0; j < element.options.length; j++) { | |
if (element.options[j].selected) this.addField(element.name, element.options[j].value); | |
} | |
break; | |
} | |
} | |
return queryString; | |
}; | |
eXo.webui.UIForm = new UIForm(); | |
function UIPopup() { | |
this.zIndex = 3; | |
}; | |
UIPopup.prototype.init = function (popup, containerId) { | |
if (typeof (popup) == "string") popup = document.getElementById(popup); | |
if (containerId) popup.containerId = containerId; | |
popup.onmousedown = this.changezIndex; | |
}; | |
UIPopup.prototype.changezIndex = function () { | |
this.style.zIndex = ++eXo.webui.UIPopup.zIndex; | |
}; | |
UIPopup.prototype.create = function () { | |
var popup = document.createElement("div"); | |
with(popup.style) { | |
position = "relative"; | |
display = "none"; | |
} | |
return popup; | |
}; | |
UIPopup.prototype.setSize = function (popup, w, h) { | |
popup.style.width = w + "px"; | |
popup.style.height = h + "px"; | |
}; | |
UIPopup.prototype.show = function (popup) { | |
if (typeof (popup) == "string") { | |
popup = document.getElementById(popup); | |
} | |
var uiMaskWS = document.getElementById("UIMaskWorkspace"); | |
if (uiMaskWS) { | |
uiMaskWSzIndex = eXo.core.DOMUtil.getStyle(uiMaskWS, "zIndex"); | |
if (uiMaskWSzIndex && (uiMaskWSzIndex > eXo.webui.UIPopup.zIndex)) { | |
eXo.webui.UIPopup.zIndex = uiMaskWSzIndex; | |
} | |
} | |
popup.style.zIndex = ++eXo.webui.UIPopup.zIndex; | |
popup.style.display = "block"; | |
}; | |
UIPopup.prototype.hide = function (popup) { | |
if (typeof (popup) == "string") { | |
popup = document.getElementById(popup); | |
} | |
popup.style.display = "none"; | |
}; | |
UIPopup.prototype.setPosition = function (popup, x, y, isRTL) { | |
if (popup.containerId) { | |
var container = document.getElementById(popup.containerId); | |
container.style.position = "relative"; | |
} | |
popup.style.position = "absolute"; | |
popup.style.top = y + "px"; | |
if (isRTL) { | |
popup.style.right = x + "px"; | |
popup.style.left = ""; | |
} else { | |
popup.style.left = x + "px"; | |
popup.style.right = ""; | |
} | |
}; | |
UIPopup.prototype.setAlign = function (popup, pos, hozMargin, verMargin) { | |
if (typeof (popup) == 'string') popup = document.getElementById(popup); | |
var stdLeft = eXo.core.Browser.getBrowserWidth() - eXo.core.Browser.findPosX(document.getElementById("UIWorkingWorkspace")); | |
var intTop = 0; | |
var intLeft = 0; | |
if (!hozMargin) hozMargin = 0; | |
if (!verMargin) verMargin = 0; | |
switch (pos) { | |
case 1: | |
intTop = verMargin; | |
intLeft = hozMargin; | |
break; | |
case 2: | |
intTop = verMargin; | |
intLeft = (stdLeft - popup.offsetWidth) - hozMargin; | |
break; | |
case 3: | |
intTop = (eXo.core.Browser.getBrowserHeight() - popup.offsetHeight) - verMargin; | |
intLeft = hozMargin; | |
break; | |
case 4: | |
intTop = (eXo.core.Browser.getBrowserHeight() - popup.offsetHeight) - verMargin; | |
intLeft = (stdLeft - popup.offsetWidth) - hozMargin; | |
break; | |
default: | |
intTop = (eXo.core.Browser.getBrowserHeight() - popup.offsetHeight) / 2; | |
intLeft = (uiWorkingWS.offsetWidth - popup.offsetWidth) / 2; | |
break; | |
} | |
this.setPosition(popup, intLeft, intTop, eXo.core.I18n.isRT()); | |
}; | |
UIPopup.prototype.initDND = function (evt) { | |
var DragDrop = eXo.core.DragDrop; | |
DragDrop.initCallback = null; | |
DragDrop.dragCallback = null; | |
DragDrop.dropCallback = null; | |
var clickBlock = this; | |
var dragBlock = eXo.core.DOMUtil.findAncestorByClass(this, "UIDragObject"); | |
DragDrop.init(null, clickBlock, dragBlock, evt); | |
}; | |
eXo.webui.UIPopup = new UIPopup(); | |
function UIPopupSelectCategory() {}; | |
UIPopupSelectCategory.prototype.hide = function () { | |
var ln = eXo.core.DOMUtil.hideElementList.length; | |
if (ln > 0) { | |
for (var i = 0; i < ln; i++) { | |
eXo.core.DOMUtil.hideElementList[i].style.display = "none"; | |
} | |
} | |
}; | |
UIPopupSelectCategory.prototype.show = function (obj, evt) { | |
if (!evt) evt = window.event; | |
evt.cancelBubble = true; | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiPopupCategory = DOMUtil.findFirstDescendantByClass(obj, 'div', 'UIPopupCategory'); | |
if (!uiPopupCategory) return; | |
if (uiPopupCategory.style.display == "none") { | |
eXo.webui.UIPopupSelectCategory.hide(); | |
uiPopupCategory.style.display = "block"; | |
eXo.core.DOMUtil.listHideElements(uiPopupCategory); | |
} else uiPopupCategory.style.display = "none"; | |
} | |
eXo.webui.UIPopupSelectCategory = new UIPopupSelectCategory(); | |
function UIPopupWindow() {}; | |
UIPopupWindow.prototype.init = function (popupId, isShow, isResizable, showCloseButton, isShowMask) { | |
var DOMUtil = eXo.core.DOMUtil; | |
this.superClass = eXo.webui.UIPopup; | |
var popup = document.getElementById(popupId); | |
if (popup == null) return; | |
popup.style.visibility = "hidden"; | |
if (isShow) { | |
popup.style.display = "block"; | |
} | |
var contentBlock = DOMUtil.findFirstDescendantByClass(popup, 'div', 'PopupContent'); | |
if (contentBlock && (eXo.core.Browser.getBrowserHeight() - 100 < contentBlock.offsetHeight)) { | |
contentBlock.style.height = (eXo.core.Browser.getBrowserHeight() - 100) + "px"; | |
} | |
var popupBar = DOMUtil.findFirstDescendantByClass(popup, 'span', 'PopupTitle'); | |
popupBar.onmousedown = this.initDND; | |
if (isShow == false) { | |
this.superClass.hide(popup); | |
if (isShowMask) eXo.webui.UIPopupWindow.showMask(popup, false); | |
} | |
if (isResizable) { | |
var resizeBtn = DOMUtil.findFirstDescendantByClass(popup, "span", "ResizeButton"); | |
resizeBtn.style.display = 'block'; | |
resizeBtn.onmousedown = this.startResizeEvt; | |
} | |
popup.style.visibility = "hidden"; | |
if (isShow == true) { | |
var iframes = DOMUtil.findDescendantsByTagName(popup, "iframe"); | |
if (iframes.length > 0) { | |
setTimeout("eXo.webui.UIPopupWindow.show('" + popupId + "'," + isShowMask + ")", 500); | |
} else { | |
this.show(popup, isShowMask); | |
} | |
} | |
}; | |
UIPopupWindow.prototype.showMask = function (popup, isShowPopup) { | |
var mask = popup.previousSibling; | |
if (mask && mask.className != "MaskLayer") { | |
mask = null; | |
} | |
if (isShowPopup) { | |
if (eXo.core.DOMUtil.findAncestorByClass(popup, "PORTLET-FRAGMENT") == null) { | |
if (!mask) eXo.core.UIMaskLayer.createMask(popup.parentNode, popup, 1); | |
} else { | |
if (!mask) eXo.core.UIMaskLayer.createMaskForFrame(popup.parentNode, popup, 1); | |
} | |
} else { | |
if (mask) eXo.core.UIMaskLayer.removeMask(mask); | |
} | |
}; | |
UIPopupWindow.prototype.show = function (popup, isShowMask, middleBrowser) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (typeof (popup) == "string") popup = document.getElementById(popup); | |
var portalApp = document.getElementById("UIPortalApplication"); | |
var maskLayer = DOMUtil.findFirstDescendantByClass(portalApp, "div", "UIMaskWorkspace"); | |
var zIndex = 0; | |
var currZIndex = 0; | |
if (maskLayer != null) { | |
currZIndex = DOMUtil.getStyle(maskLayer, "zIndex"); | |
if (!isNaN(currZIndex) && currZIndex > zIndex) zIndex = currZIndex; | |
} | |
var popupWindows = DOMUtil.findDescendantsByClass(portalApp, "div", "UIPopupWindow"); | |
var len = popupWindows.length; | |
for (var i = 0; i < len; i++) { | |
currZIndex = DOMUtil.getStyle(popupWindows[i], "zIndex"); | |
if (!isNaN(currZIndex) && currZIndex > zIndex) zIndex = currZIndex; | |
} | |
if (zIndex == 0) zIndex = 2000; | |
if (isShowMask) eXo.webui.UIPopupWindow.showMask(popup, true); | |
popup.style.visibility = "hidden"; | |
this.superClass.show(popup); | |
var offsetParent = popup.offsetParent; | |
var scrollY = 0; | |
if (window.pageYOffset != undefined) scrollY = window.pageYOffset; | |
else if (document.documentElement && document.documentElement.scrollTop) scrollY = document.documentElement.scrollTop; | |
else scrollY = document.body.scrollTop; | |
if (offsetParent) { | |
var middleWindow = (eXo.core.DOMUtil.hasClass(offsetParent, "UIPopupWindow") || eXo.core.DOMUtil.hasClass(offsetParent, "UIWindow")); | |
if (middleWindow) { | |
popup.style.top = Math.ceil((offsetParent.offsetHeight - popup.offsetHeight) / 2) + "px"; | |
} | |
if (middleBrowser || !middleWindow) { | |
popup.style.top = Math.ceil((eXo.core.Browser.getBrowserHeight() - popup.offsetHeight) / 2) + scrollY + "px"; | |
} | |
if (eXo.core.DOMUtil.hasClass(offsetParent, "UIMaskWorkspace")) { | |
popup.style.top = Math.ceil((offsetParent.offsetHeight - popup.offsetHeight) / 2) + "px"; | |
} | |
var checkHeight = popup.offsetHeight > 300; | |
if (document.getElementById("UIDockBar") && checkHeight) { | |
popup.style.top = "6px"; | |
} | |
if (eXo.core.I18n.lt) popup.style.left = Math.ceil((offsetParent.offsetWidth - popup.offsetWidth) / 2) + "px"; | |
else popup.style.right = Math.ceil((offsetParent.offsetWidth - popup.offsetWidth) / 2) + "px"; | |
} | |
if (eXo.core.Browser.findPosY(popup) < 0) popup.style.top = scrollY + "px"; | |
popup.style.visibility = "visible"; | |
}; | |
UIPopupWindow.prototype.increasezIndex = function (popup) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (typeof (popup) == "string") popup = document.getElementById(popup); | |
var portalApp = document.getElementById("UIPortalApplication"); | |
var uiLogin = DOMUtil.findFirstDescendantByClass(portalApp, "div", "UILoginForm"); | |
if (uiLogin) { | |
var curMaskzIndex = parseInt(DOMUtil.getStyle(document.getElementById('UIMaskWorkspace'), "zIndex")); | |
popup.style.zIndex = ++curMaskzIndex + ""; | |
} | |
} | |
UIPopupWindow.prototype.closePopupEvt = function (evt) { | |
eXo.core.DOMUtil.findAncestorByClass(this, "UIDragObject").style.display = "none"; | |
} | |
UIPopupWindow.prototype.startResizeEvt = function (evt) { | |
eXo.webui.UIPopupWindow.popupId = eXo.core.DOMUtil.findAncestorByClass(this, "UIPopupWindow").id; | |
document.onmousemove = eXo.webui.UIPopupWindow.resize; | |
document.onmouseup = eXo.webui.UIPopupWindow.endResizeEvt; | |
} | |
var POPUP_WINDOW_BOTTOM_HEIGHT = 50; | |
UIPopupWindow.prototype.resize = function (evt) { | |
var targetPopup = document.getElementById(eXo.webui.UIPopupWindow.popupId); | |
var content = eXo.core.DOMUtil.findFirstDescendantByClass(targetPopup, "div", "PopupContent"); | |
var isRTL = eXo.core.I18n.isRT(); | |
var pointerX = eXo.core.Browser.findMouseRelativeX(targetPopup, evt, isRTL); | |
var pointerY = eXo.core.Browser.findMouseRelativeY(targetPopup, evt); | |
var delta = eXo.core.Browser.findPosYInContainer(content, targetPopup) + content.style.borderWidth + content.style.padding + content.style.margin; | |
if ((pointerY - delta) > 0) content.style.height = (pointerY - delta - POPUP_WINDOW_BOTTOM_HEIGHT) + "px"; | |
targetPopup.style.height = "auto"; | |
if (isRTL) { | |
pointerX = (-1) * pointerX | |
} | |
if (pointerX > 200) targetPopup.style.width = (pointerX + 5) + "px"; | |
}; | |
UIPopupWindow.prototype.endResizeEvt = function (evt) { | |
delete eXo.webui.UIPopupWindow.popupId; | |
this.onmousemove = null; | |
this.onmouseup = null; | |
eXo.portal.UIPortalControl.initAllManagers(); | |
} | |
UIPopupWindow.prototype.initDND = function (evt) { | |
var DragDrop = eXo.core.DragDrop; | |
var DOMUtil = eXo.core.DOMUtil; | |
DragDrop.initCallback = function (dndEvent) { | |
var dragObject = dndEvent.dragObject; | |
dragObject.uiWindowContent = DOMUtil.findFirstDescendantByClass(dragObject, "div", "PopupContent"); | |
if (!dragObject.uiWindowContent) return; | |
if (eXo.core.Browser.browserType == "mozilla") { | |
dragObject.uiWindowContent.style.overflow = "hidden"; | |
var elements = eXo.core.DOMUtil.findDescendantsByClass(dragObject.uiWindowContent, "ul", "PopupMessageBox"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.overflow = "hidden"; | |
} | |
} | |
} | |
DragDrop.dragCallback = function (dndEvent) {} | |
DragDrop.dropCallback = function (dndEvent) { | |
var dragObject = dndEvent.dragObject; | |
if (eXo.core.Browser.browserType == "mozilla" && dragObject.uiWindowContent) { | |
dragObject.uiWindowContent.style.overflow = "auto"; | |
var elements = eXo.core.DOMUtil.findDescendantsByClass(dragObject.uiWindowContent, "ul", "PopupMessageBox"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.overflow = "auto"; | |
} | |
} | |
var offsetParent = dragObject.offsetParent; | |
if (offsetParent) { | |
if (eXo.core.Browser.findPosY(dragObject) < 0) dragObject.style.top = (0 - offsetParent.offsetTop) + "px"; | |
} else { | |
dragObject.style.top = "0px"; | |
} | |
} | |
var clickBlock = this; | |
var dragBlock = eXo.core.DOMUtil.findAncestorByClass(this, "UIDragObject"); | |
DragDrop.init(null, clickBlock, dragBlock, evt); | |
}; | |
eXo.webui.UIPopupWindow = new UIPopupWindow(); | |
function UIHorizontalTabs() { | |
this.backupNavigationTabStyle; | |
this.backupItemStyle; | |
}; | |
UIHorizontalTabs.prototype.init = function () {}; | |
UIHorizontalTabs.prototype.changeTabNavigationStyle = function (clickedEle, over) { | |
if (clickedEle == null) return; | |
if (!eXo.core.DOMUtil.hasClass(clickedEle, "UITab")) clickedEle = eXo.core.DOMUtil.findAncestorByClass(clickedEle, "UITab"); | |
if (over) { | |
this.backupNavigationTabStyle = clickedEle.className; | |
clickedEle.className = "UITab HighlightNavigationTab"; | |
} else if (this.backupNavigationTabStyle) { | |
clickedEle.className = this.backupNavigationTabStyle; | |
} | |
} | |
UIHorizontalTabs.prototype.itemOver = function (selectedElement, over) { | |
if (over) { | |
this.backupItemStyle = selectedElement.className; | |
if (selectedElement.className == "MenuItem") { | |
selectedElement.className = "MenuItemSelected"; | |
} else { | |
selectedElement.className = "MenuItemSelected MenuItemExpand"; | |
} | |
} else { | |
selectedElement.className = this.backupItemStyle; | |
} | |
}; | |
UIHorizontalTabs.prototype.displayTabContent = function (clickedEle) { | |
this.changeTabForUITabPane(clickedEle, null, null); | |
}; | |
UIHorizontalTabs.prototype.changeTabForUITabPane = function (clickedEle, tabId, url) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiSelectTab = DOMUtil.findAncestorByClass(clickedEle, "UITab"); | |
var uiHorizontalTabs = DOMUtil.findAncestorByClass(clickedEle, "UIHorizontalTabs"); | |
var uiTabs = eXo.core.DOMUtil.findDescendantsByClass(uiHorizontalTabs, "div", "UITab"); | |
var parentdHorizontalTab = uiHorizontalTabs.parentNode; | |
var contentTabContainer = DOMUtil.findFirstDescendantByClass(parentdHorizontalTab, "div", "UITabContentContainer"); | |
var uiTabContents = DOMUtil.findChildrenByClass(contentTabContainer, "div", "UITabContent"); | |
var form = DOMUtil.getChildrenByTagName(contentTabContainer, "form"); | |
if (form.length > 0) { | |
var tmp = DOMUtil.findChildrenByClass(form[0], "div", "UITabContent"); | |
for (var i = 0; i < tmp.length; i++) { | |
uiTabContents.push(tmp[i]); | |
} | |
} | |
var index = 0; | |
for (var i = 0; i < uiTabs.length; i++) { | |
var styleTabDiv = DOMUtil.getChildrenByTagName(uiTabs[i], "div")[0]; | |
if (styleTabDiv.className == "DisabledTab") continue; | |
if (uiSelectTab == uiTabs[i]) { | |
styleTabDiv.className = "SelectedTab"; | |
index = i; | |
continue; | |
} | |
styleTabDiv.className = "NormalTab"; | |
uiTabContents[i].style.display = "none"; | |
} | |
uiTabContents[index].style.display = "block"; | |
if (eXo.ecm.UIJCRExplorer) { | |
try { | |
eXo.ecm.UIJCRExplorer.initViewNodeScroll(); | |
} catch (e) { | |
void(0); | |
} | |
} | |
}; | |
UIHorizontalTabs.prototype.checkContentAvailable = function (id) { | |
var tabContent = document.getElementById(id).parentNode; | |
if (!tabContent.isLoaded) { | |
tabContent.isLoaded = true; | |
return false; | |
} | |
tabContent.style.display = 'block'; | |
return true; | |
}; | |
UIHorizontalTabs.prototype.changeTabForUIFormTabpane = function (clickedElemt, formId, hiddenValue) { | |
this.displayTabContent(clickedElemt, formId, hiddenValue); | |
eXo.webui.UIForm.setHiddenValue(formId, 'currentSelectedTab', hiddenValue); | |
}; | |
eXo.webui.UIHorizontalTabs = new UIHorizontalTabs(); | |
function UIPopupMenu() { | |
this.elementsToHide = new Array(); | |
this.currentVisibleContainers = new Array(); | |
this.currentElement = null; | |
}; | |
UIPopupMenu.prototype.init = function (popupMenu, container, x, y) { | |
this.superClass = eXo.webui.UIPopup; | |
this.superClass.init(popupMenu, container.id); | |
}; | |
UIPopupMenu.prototype.setPosition = function (popupMenu, x, y, isRTL) { | |
this.superClass.setPosition(popupMenu, x, y, isRTL); | |
}; | |
UIPopupMenu.prototype.setSize = function (popup, w, h) { | |
this.superClass.setSize(popupMenu, w, h); | |
}; | |
UIPopupMenu.prototype.pushVisibleContainer = function (containerId) { | |
eXo.webui.UIPopupMenu.currentVisibleContainers.push(containerId); | |
}; | |
UIPopupMenu.prototype.popVisibleContainer = function () { | |
eXo.webui.UIPopupMenu.currentVisibleContainers.pop(); | |
}; | |
UIPopupMenu.prototype.pushHiddenContainer = function (containerId) { | |
eXo.webui.UIPopupMenu.elementsToHide.push(containerId); | |
}; | |
UIPopupMenu.prototype.setCloseTimeout = function (time) { | |
if (!time) time = 100; | |
setTimeout("eXo.webui.UIPopupMenu.doOnMenuItemOut()", time); | |
}; | |
UIPopupMenu.prototype.createLink = function (menuItem, link) { | |
if (link && link.href) { | |
menuItem.onclick = function (e) { | |
if (link.href.substr(0, 7) == "http://") window.location.href = link.href; | |
else eval(link.href); | |
if (!e) e = window.event; | |
if (e.stopPropagation) e.stopPropagation(); | |
e.cancelBubble = true; | |
return false; | |
} | |
} | |
}; | |
UIPopupMenu.prototype.doOnMenuItemOut = function () { | |
while (eXo.webui.UIPopupMenu.elementsToHide.length > 0) { | |
var container = document.getElementById(eXo.webui.UIPopupMenu.elementsToHide.shift()); | |
if (container) { | |
if (!eXo.webui.UIPopupMenu.currentVisibleContainers.contains(container.id)) { | |
eXo.webui.UIPopupMenu.hide(container); | |
} | |
} | |
} | |
}; | |
UIPopupMenu.prototype.showMenuItemContainer = function (menuItemContainer, x, y) { | |
this.superClass.setPosition(menuItemContainer, x, y); | |
}; | |
UIPopupMenu.prototype.hide = function (object) { | |
if (typeof (object) == "string") object = document.getElementById(object); | |
object.style.display = "none"; | |
object.style.visibility = "hidden"; | |
}; | |
UIPopupMenu.prototype.show = function (object) { | |
if (typeof (object) == "string") object = document.getElementById(object); | |
object.style.display = "block"; | |
object.style.visibility = ""; | |
}; | |
eXo.webui.UIPopupMenu = new UIPopupMenu(); | |
function UIDropDownControl() {}; | |
UIDropDownControl.prototype.init = function (id) {}; | |
UIDropDownControl.prototype.selectItem = function (method, id, selectedIndex) { | |
if (method) method(id, selectedIndex); | |
}; | |
UIDropDownControl.prototype.show = function (obj, evt) { | |
if (!evt) evt = window.event; | |
evt.cancelBubble = true; | |
var DOMUtil = eXo.core.DOMUtil; | |
var Browser = eXo.core.Browser; | |
var dropDownAnchor = DOMUtil.findNextElementByTagName(obj, 'div'); | |
if (dropDownAnchor) { | |
if (dropDownAnchor.style.display == "none") { | |
dropDownAnchor.style.display = "block"; | |
dropDownAnchor.style.visibility = "visible"; | |
var middleCont = DOMUtil.findFirstDescendantByClass(dropDownAnchor, "div", "MiddleItemContainer"); | |
var topCont = DOMUtil.findPreviousElementByTagName(middleCont, "div"); | |
var bottomCont = DOMUtil.findNextElementByTagName(middleCont, "div"); | |
topCont.style.display = "block"; | |
bottomCont.style.display = "block"; | |
var visibleHeight = Browser.getBrowserHeight() - Browser.findPosY(middleCont) - 40; | |
var scrollHeight = middleCont.scrollHeight; | |
if (scrollHeight > visibleHeight) { | |
topCont.style.display = "block"; | |
bottomCont.style.display = "block"; | |
middleCont.style.height = visibleHeight - topCont.offsetHeight - bottomCont.offsetHeight + "px"; | |
topCont.onclick = function (event) { | |
event = event || window.event; | |
event.cancelBubble = true; | |
}; | |
bottomCont.onclick = function (event) { | |
event = event || window.event; | |
event.cancelBubble = true; | |
} | |
} else { | |
topCont.style.display = "none"; | |
bottomCont.style.display = "none"; | |
middleCont.scrollTop = 0; | |
middleCont.style.height = "auto"; | |
} | |
DOMUtil.listHideElements(dropDownAnchor); | |
} else { | |
dropDownAnchor.style.display = "none"; | |
dropDownAnchor.style.visibility = "hidden"; | |
} | |
} | |
}; | |
UIDropDownControl.prototype.hide = function (obj) { | |
if (typeof (obj) == "string") obj = document.getElementById(obj); | |
obj.style.display = "none"; | |
}; | |
UIDropDownControl.prototype.onclickEvt = function (obj, evt) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiDropDownAnchor = DOMUtil.findAncestorByClass(obj, 'UIDropDownAnchor'); | |
var uiDropDownTitle = DOMUtil.findPreviousElementByTagName(uiDropDownAnchor, 'div'); | |
var uiDropDownMiddleTitle = DOMUtil.findFirstDescendantByClass(uiDropDownTitle, 'div', 'DropDownSelectLabel'); | |
uiDropDownMiddleTitle.innerHTML = obj.innerHTML; | |
uiDropDownAnchor.style.display = 'none'; | |
}; | |
eXo.webui.UIDropDownControl = new UIDropDownControl(); | |
function UIRightClickPopupMenu() {}; | |
UIRightClickPopupMenu.prototype.init = function (contextMenuId) { | |
var contextMenu = document.getElementById(contextMenuId); | |
if (!contextMenu) return; | |
contextMenu.onmousedown = function (e) { | |
if (!e) e = window.event; | |
e.cancelBubble = true; | |
} | |
var parentNode = contextMenu.parentNode; | |
this.disableContextMenu(parentNode); | |
} | |
UIRightClickPopupMenu.prototype.hideContextMenu = function (contextId) { | |
if (document.getElementById(contextId)) { | |
document.getElementById(contextId).style.display = 'none'; | |
eXo.core.MouseEventManager.onMouseDownHandlers = null; | |
} | |
} | |
UIRightClickPopupMenu.prototype.disableContextMenu = function (comp) { | |
if (typeof (comp) == "string") comp = document.getElementById(comp); | |
comp.onmouseover = function () { | |
document.oncontextmenu = function () { | |
return false | |
}; | |
} | |
comp.onmouseout = function () { | |
document.oncontextmenu = function () { | |
return true | |
}; | |
} | |
}; | |
UIRightClickPopupMenu.prototype.prepareObjectId = function (evt, elemt) { | |
eXo.core.MouseEventManager.docMouseDownEvt(evt); | |
var contextMenu = eXo.core.DOMUtil.findAncestorByClass(elemt, "UIRightClickPopupMenu"); | |
contextMenu.style.display = "none"; | |
var href = elemt.getAttribute('href'); | |
if (!href) { | |
return; | |
} | |
if (href.indexOf("ajaxGet") != -1) { | |
href = href.replace("ajaxGet", "ajaxPost"); | |
elemt.setAttribute('href', href); | |
} | |
if (href.indexOf("objectId") != -1 || !contextMenu.objId) { | |
return; | |
} | |
var objId = encodeURIComponent(contextMenu.objId.replace(/'/g, "\\'")); | |
if (href.indexOf("javascript") == -1) { | |
elemt.setAttribute('href', href + "&objectId=" + objId); | |
return; | |
} else if (href.indexOf("window.location") != -1) { | |
href = href.substr(0, href.length - 1) + "&objectId=" + objId + "'"; | |
} else if (href.indexOf("ajaxPost") != -1) { | |
href = href.substr(0, href.length - 2) + "', 'objectId=" + objId + "')"; | |
} else { | |
href = href.substr(0, href.length - 2) + "&objectId=" + objId + "')"; | |
} | |
eval(href); | |
if (evt && evt.preventDefault) evt.preventDefault(); | |
else window.event.returnValue = false; | |
return false; | |
}; | |
UIRightClickPopupMenu.prototype.clickRightMouse = function (event, elemt, menuId, objId, params, opt) { | |
if (!event) event = window.event; | |
eXo.core.MouseEventManager.docMouseDownEvt(event); | |
var contextMenu = document.getElementById(menuId); | |
contextMenu.objId = objId; | |
if (!(((event.which) && (event.which == 2 || event.which == 3)) || ((event.button) && (event.button == 2)))) { | |
contextMenu.style.display = 'none'; | |
return; | |
} | |
eXo.core.MouseEventManager.addMouseDownHandler("eXo.webui.UIRightClickPopupMenu.hideContextMenu('" + menuId + "');") | |
if (params) { | |
params = "," + params + ","; | |
var items = contextMenu.getElementsByTagName("a"); | |
for (var i = 0; i < items.length; i++) { | |
if (params.indexOf(items[i].getAttribute("exo:attr")) > -1) { | |
items[i].style.display = 'block'; | |
} else { | |
items[i].style.display = 'none'; | |
} | |
} | |
} | |
var customItem = eXo.core.DOMUtil.findFirstDescendantByClass(elemt, "div", "RightClickCustomItem"); | |
var tmpCustomItem = eXo.core.DOMUtil.findFirstDescendantByClass(contextMenu, "div", "RightClickCustomItem"); | |
if (tmpCustomItem) { | |
if (customItem) { | |
tmpCustomItem.innerHTML = customItem.innerHTML; | |
tmpCustomItem.style.display = "inline"; | |
} else { | |
tmpCustomItem.style.display = "none"; | |
} | |
} | |
var fixWidthForIE7 = 0; | |
var UIWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
if (eXo.core.Browser.isIE7() && document.getElementById("UIDockBar")) { | |
if (event.clientX > UIWorkingWorkspace.offsetLeft) fixWidthForIE7 = UIWorkingWorkspace.offsetLeft; | |
} | |
eXo.core.Mouse.update(event); | |
eXo.webui.UIPopup.show(contextMenu); | |
var ctxMenuContainer = eXo.core.DOMUtil.findFirstChildByClass(contextMenu, "div", "UIContextMenuContainer"); | |
var intTop = eXo.core.Mouse.mouseyInPage - (eXo.core.Browser.findPosY(contextMenu) - contextMenu.offsetTop); | |
var intLeft = eXo.core.Mouse.mousexInPage - (eXo.core.Browser.findPosX(contextMenu) - contextMenu.offsetLeft) + fixWidthForIE7; | |
if (eXo.core.I18n.isRT()) { | |
var scrollWidth = 16; | |
if (eXo.core.Browser.getBrowserType() == "mozilla") scrollWidth = 0; | |
intLeft = contextMenu.offsetParent.offsetWidth - intLeft + fixWidthForIE7 + scrollWidth; | |
var clickCenter = eXo.core.DOMUtil.findFirstDescendantByClass(contextMenu, "div", "ClickCenterBottom"); | |
if (clickCenter) { | |
var clickCenterWidth = clickCenter ? parseInt(eXo.core.DOMUtil.getStyle(clickCenter, "marginRight")) : 0; | |
intLeft += (ctxMenuContainer.offsetWidth - 2 * clickCenterWidth); | |
} | |
} | |
switch (opt) { | |
case 1: | |
intTop -= ctxMenuContainer.offsetHeight; | |
break; | |
case 2: | |
break; | |
case 3: | |
break; | |
case 4: | |
break; | |
default: | |
if ((eXo.core.Mouse.mouseyInClient + ctxMenuContainer.offsetHeight) > eXo.core.Browser.getBrowserHeight() && (intTop > ctxMenuContainer.offsetHeight)) { | |
intTop -= ctxMenuContainer.offsetHeight; | |
} | |
break; | |
} | |
if (eXo.core.I18n.isLT()) { | |
contextMenu.style.left = eXo.core.Browser.getBrowserWidth() * 0.5 + "px"; | |
ctxMenuContainer.style.width = "auto"; | |
ctxMenuContainer.style.width = ctxMenuContainer.offsetWidth + 2 + "px"; | |
contextMenu.style.left = (intLeft + 1) + "px"; | |
} else { | |
contextMenu.style.right = eXo.core.Browser.getBrowserWidth() * 0.5 + "px"; | |
ctxMenuContainer.style.width = "auto"; | |
ctxMenuContainer.style.width = ctxMenuContainer.offsetWidth + 2 + "px"; | |
contextMenu.style.right = intLeft + "px"; | |
} | |
ctxMenuContainer.style.width = ctxMenuContainer.offsetWidth + "px"; | |
if ((eXo.core.Mouse.mouseyInClient + ctxMenuContainer.offsetHeight) <= eXo.core.Browser.getBrowserHeight()) { | |
intTop += 1 | |
} | |
contextMenu.style.top = intTop + "px"; | |
}; | |
eXo.webui.UIRightClickPopupMenu = new UIRightClickPopupMenu(); | |
function UIVerticalSlideTabs() {}; | |
UIVerticalSlideTabs.prototype.slideInEffect = function () { | |
if ((parseInt(this.selectedTab.style.height) - 30) > 0) { | |
this.selectedTab.style.height = (parseInt(this.selectedTab.style.height) - 30) + "px"; | |
setTimeout("eXo.webui.UIVerticalSlideTabs.slideInEffect()", 3); | |
} else { | |
this.selectedTab.style.height = "0px"; | |
this.selectedTab.style.display = "none"; | |
delete this.selectedTab; | |
this.clickedTab.style.display = "block"; | |
setTimeout("eXo.webui.UIVerticalSlideTabs.slideOutEffect()", 3); | |
} | |
} | |
UIVerticalSlideTabs.prototype.slideOutEffect = function () { | |
if ((parseInt(this.clickedTab.style.height) + 30) < this.clickedTab.scrollHeight) { | |
this.clickedTab.style.height = (parseInt(this.clickedTab.style.height) + 30) + "px"; | |
setTimeout("eXo.webui.UIVerticalSlideTabs.slideOutEffect()", 3); | |
} else { | |
this.clickedTab.style.height = this.clickedTab.scrollHeight + "px"; | |
delete this.clickedTab; | |
} | |
} | |
UIVerticalSlideTabs.prototype.switchVTab = function (clickedElement) { | |
var uiClickedVTab = eXo.core.DOMUtil.findAncestorByClass(clickedElement, "UIVTab"); | |
var uiClickedVTabContent = eXo.core.DOMUtil.findFirstChildByClass(uiClickedVTab, "div", "UIVTabContent"); | |
var uiVerticalSlideTabs = eXo.core.DOMUtil.findAncestorByClass(clickedElement, "UIVerticalSlideTabs"); | |
var uiVTabs = eXo.core.DOMUtil.findChildrenByClass(uiVerticalSlideTabs, "div", "UIVTab"); | |
for (var i = 0; i < uiVTabs.length; i++) { | |
if (eXo.core.DOMUtil.getChildrenByTagName(uiVTabs[i], "div")[0].className == "SelectedTab") { | |
this.selectedTab = eXo.core.DOMUtil.findFirstChildByClass(uiVTabs[i], "div", "UIVTabContent"); | |
eXo.core.DOMUtil.getChildrenByTagName(uiVTabs[i], "div")[0].className = "NormalTab"; | |
break; | |
} | |
} | |
eXo.core.DOMUtil.getChildrenByTagName(uiClickedVTab, "div")[0].className = "SelectedTab"; | |
this.clickedTab = uiClickedVTabContent; | |
if (this.clickedTab != this.selectedTab) { | |
if (this.selectedTab) this.slideInEffect(); | |
else { | |
this.clickedTab.style.display = "block"; | |
this.slideOutEffect(); | |
} | |
} | |
}; | |
UIVerticalSlideTabs.prototype.onTabClick = function (clickedElement, normalStyle, selectedStyle) { | |
var uiClickedVTab = eXo.core.DOMUtil.findAncestorByClass(clickedElement, "UIVTab"); | |
var uiClickedVTabContent = eXo.core.DOMUtil.findFirstChildByClass(uiClickedVTab, "div", "UIVTabContent"); | |
var uiVerticalSlideTabs = eXo.core.DOMUtil.findAncestorByClass(clickedElement, "UIVerticalSlideTabs"); | |
var uiVTab = eXo.core.DOMUtil.findChildrenByClass(uiVerticalSlideTabs, "div", "UIVTab"); | |
if (eXo.core.DOMUtil.getChildrenByTagName(uiClickedVTab, "div")[0].className == normalStyle) { | |
for (var i = 0; i < uiVTab.length; i++) { | |
eXo.core.DOMUtil.getChildrenByTagName(uiVTab[i], "div")[0].className = normalStyle; | |
eXo.core.DOMUtil.findFirstChildByClass(uiVTab[i], "div", "UIVTabContent").style.display = "none"; | |
} | |
eXo.core.DOMUtil.getChildrenByTagName(uiClickedVTab, "div")[0].className = selectedStyle; | |
uiClickedVTabContent.style.display = "block"; | |
} else { | |
eXo.core.DOMUtil.getChildrenByTagName(uiClickedVTab, "div")[0].className = normalStyle; | |
uiClickedVTabContent.style.display = "none"; | |
} | |
}; | |
UIVerticalSlideTabs.prototype.onResize = function (uiVerticalSlideTabs, width, height) { | |
var vTabHeight = 35; | |
var uiVTabs = eXo.core.DOMUtil.findChildrenByClass(uiVerticalSlideTabs, "div", "UIVTab"); | |
var uiVTab = this.getSelectedUIVTab(uiVerticalSlideTabs, "div", "UIVTab"); | |
if (uiVTab == null) return; | |
if (height != null) { | |
var totalTabHeight = (vTabHeight * uiVTabs.length); | |
var controlArea = eXo.core.DOMUtil.findFirstDescendantByClass(uiVTab, "div", "ControlArea"); | |
var controlAreaHeight = 0; | |
if (controlArea != null) controlAreaHeight = controlArea.offsetHeight; | |
scrollArea = eXo.core.DOMUtil.findFirstDescendantByClass(uiVTab, "div", "ScrollArea"); | |
if (scrollArea != null) { | |
scrollArea.style.height = (height - controlAreaHeight - totalTabHeight - 35) + "px"; | |
} | |
} | |
if (width != null) { | |
scrollArea.style.width = width + "px"; | |
} | |
}; | |
UIVerticalSlideTabs.prototype.isSelectedUIVTab = function (uiVtab) { | |
var tabRight = eXo.core.DOMUtil.findFirstDescendantByClass(uiVtab, "div", "TabRight"); | |
var changeIcon = eXo.core.DOMUtil.getChildrenByTagName(tabRight, "div")[0]; | |
if (changeIcon.className == "ExpandButton") return true; | |
return false; | |
}; | |
UIVerticalSlideTabs.prototype.getSelectedUIVTab = function (uiVerticalSlideTabs) { | |
var uiVTab = eXo.core.DOMUtil.findChildrenByClass(uiVerticalSlideTabs, "div", "UIVTab"); | |
for (var i = 0; i < uiVTab.length; i++) { | |
if (this.isSelectedUIVTab(uiVTab[i])) return uiVTab[i]; | |
} | |
return null; | |
}; | |
UIVerticalSlideTabs.prototype.fitParentHeight = function (obj) { | |
this.onResize(obj, null, obj.parentNode.offsetHeight); | |
} | |
eXo.webui.UIVerticalSlideTabs = new UIVerticalSlideTabs(); | |
function UIPermissionSelectorTab() {}; | |
UIPermissionSelectorTab.prototype.init = function () {}; | |
UIPermissionSelectorTab.prototype.displayBlockContent = function (clickedEle) { | |
var permissionTypeBar = eXo.core.DOMUtil.findAncestorByClass(clickedEle, "PermissionTypeBar"); | |
var permissionButton = eXo.core.DOMUtil.findChildrenByClass(permissionTypeBar, "div", "PermissionButton"); | |
var selectedPermissionInfo = eXo.core.DOMUtil.findChildrenByClass(permissionTypeBar.parentNode, "div", "SelectedPermissionInfo"); | |
for (var i = 0; i < permissionButton.length; i++) { | |
if (permissionButton[i] == clickedEle) { | |
permissionButton[i].style.fontWeight = "bold"; | |
selectedPermissionInfo[i].style.display = "block"; | |
} else { | |
permissionButton[i].style.fontWeight = "100"; | |
selectedPermissionInfo[i].style.display = "none"; | |
} | |
} | |
}; | |
eXo.webui.UIPermissionSelectorTab = new UIPermissionSelectorTab(); | |
function UIDashboard() { | |
var currCol = null; | |
var targetObj = null; | |
UIDashboard.prototype.init = function (dragItem, dragObj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
eXo.core.DragDrop2.init(dragItem, dragObj); | |
dragObj.onDragStart = function (x, y, lastMouseX, lastMouseY, e) { | |
var uiDashboard = eXo.webui.UIDashboard; | |
var portletFragment = DOMUtil.findAncestorByClass(dragObj, "PORTLET-FRAGMENT"); | |
if (!portletFragment) return; | |
var uiWorkingWS = document.getElementById("UIWorkingWorkspace"); | |
var gadgetContainer = DOMUtil.findFirstDescendantByClass(portletFragment, "div", "GadgetContainer"); | |
var ggwidth = dragObj.offsetWidth; | |
var ggheight = dragObj.offsetHeight; | |
var mx = eXo.webui.UIDashboardUtil.findMouseRelativeX(uiWorkingWS, e); | |
var ox = eXo.webui.UIDashboardUtil.findMouseRelativeX(dragObj, e); | |
var x = mx - ox; | |
var my = eXo.webui.UIDashboardUtil.findMouseRelativeY(uiWorkingWS, e); | |
var oy = eXo.webui.UIDashboardUtil.findMouseRelativeY(dragObj, e); | |
var y = my - oy; | |
var temp = dragObj; | |
while (temp.parentNode && DOMUtil.hasDescendant(portletFragment, temp)) { | |
if (temp.scrollLeft > 0) x -= temp.scrollLeft; | |
if (temp.scrollTop > 0) y -= temp.scrollTop; | |
temp = temp.parentNode; | |
} | |
var uiTarget = null; | |
if (!DOMUtil.hasClass(dragObj, "SelectItem")) { | |
uiTarget = uiDashboard.createTarget(ggwidth, 0); | |
dragObj.parentNode.insertBefore(uiTarget, dragObj.nextSibling); | |
currCol = eXo.webui.UIDashboardUtil.findColIndexInDashboard(dragObj); | |
} else { | |
var dragCopyObj = dragObj.cloneNode(true); | |
DOMUtil.addClass(dragCopyObj, "CopyObj"); | |
dragObj.parentNode.insertBefore(dragCopyObj, dragObj); | |
targetObj = null; | |
} | |
dragObj.style.width = ggwidth + "px"; | |
var uiGadgets = DOMUtil.findDescendantsByClass(gadgetContainer, "div", "UIGadget"); | |
for (var i = 0; i < uiGadgets.length; i++) { | |
var uiMask = DOMUtil.findFirstDescendantByClass(uiGadgets[i], "div", "UIMask"); | |
if (uiMask != null) { | |
var gadgetApp = DOMUtil.findFirstDescendantByClass(uiGadgets[i], "div", "GadgetApplication"); | |
uiMask.style.marginTop = -gadgetApp.offsetHeight + "px"; | |
uiMask.style.height = gadgetApp.offsetHeight + "px"; | |
uiMask.style.width = gadgetApp.offsetWidth + "px"; | |
uiMask.style.display = "block"; | |
uiMask.style.backgroundColor = "white"; | |
eXo.core.Browser.setOpacity(uiMask, 3); | |
} | |
} | |
if (!DOMUtil.hasClass(dragObj, "Dragging")) DOMUtil.addClass(dragObj, "Dragging"); | |
dragObj.style.position = "absolute"; | |
eXo.webui.UIDashboardUtil.setPositionInContainer(uiWorkingWS, dragObj, x, y); | |
if (uiTarget != null) { | |
uiTarget.style.height = ggheight + "px"; | |
targetObj = uiTarget; | |
} | |
} | |
dragObj.onDrag = function (nx, ny, ex, ey, e) { | |
var uiTarget = targetObj; | |
var portletFragment = DOMUtil.findAncestorByClass(dragObj, "PORTLET-FRAGMENT"); | |
if (!portletFragment) return; | |
var dashboardCont = DOMUtil.findFirstDescendantByClass(portletFragment, "div", "GadgetContainer"); | |
var cols = null; | |
eXo.webui.UIDashboard.scrollOnDrag(dragObj); | |
if (eXo.webui.UIDashboardUtil.isIn(ex, ey, dashboardCont)) { | |
if (!uiTarget) { | |
uiTarget = eXo.webui.UIDashboard.createTargetOfAnObject(dragObj); | |
targetObj = uiTarget; | |
} | |
var uiCol = currCol; | |
if (!uiCol) { | |
if (!cols) cols = DOMUtil.findDescendantsByClass(dashboardCont, "div", "UIColumn"); | |
for (var i = 0; i < cols.length; i++) { | |
var uiColLeft = eXo.webui.UIDashboardUtil.findPosX(cols[i]) - dashboardCont.scrollLeft; | |
if (uiColLeft < ex && ex < uiColLeft + cols[i].offsetWidth) { | |
currCol = uiCol = cols[i]; | |
break; | |
} | |
} | |
} | |
if (!uiCol) return; | |
var uiColLeft = eXo.webui.UIDashboardUtil.findPosX(uiCol) - dashboardCont.scrollLeft; | |
if (uiColLeft < ex && ex < uiColLeft + uiCol.offsetWidth) { | |
var gadgets = DOMUtil.findDescendantsByClass(uiCol, "div", "UIGadget"); | |
for (var i = 0; i < gadgets.length; i++) { | |
if (dragObj.id == gadgets[i].id) { | |
gadgets.splice(i, 1); | |
break; | |
} | |
} | |
if (gadgets.length == 0) { | |
uiCol.appendChild(uiTarget); | |
return; | |
} | |
for (var i = 0; i < gadgets.length; i++) { | |
var oy = eXo.webui.UIDashboardUtil.findPosY(gadgets[i]) + (gadgets[i].offsetHeight / 3) - dashboardCont.scrollTop; | |
if (ey <= oy) { | |
uiCol.insertBefore(uiTarget, gadgets[i]); | |
break; | |
} | |
if (i == gadgets.length - 1 && ey > oy) uiCol.appendChild(uiTarget); | |
} | |
} else { | |
if (cols == null) cols = DOMUtil.findDescendantsByClass(dashboardCont, "div", "UIColumn"); | |
for (var i = 0; i < cols.length; i++) { | |
var uiColLeft = eXo.webui.UIDashboardUtil.findPosX(cols[i]) - dashboardCont.scrollLeft; | |
if (uiColLeft < ex && ex < uiColLeft + cols[i].offsetWidth) { | |
currCol = cols[i]; | |
break; | |
} | |
} | |
} | |
} else { | |
if (uiTarget != null && DOMUtil.hasClass(dragObj, "SelectItem")) { | |
uiTarget.parentNode.removeChild(uiTarget); | |
targetObj = uiTarget = null; | |
} | |
} | |
} | |
dragObj.onDragEnd = function (x, y, clientX, clientY) { | |
var uiDashboardUtil = eXo.webui.UIDashboardUtil; | |
var portletFragment = DOMUtil.findAncestorByClass(dragObj, "PORTLET-FRAGMENT"); | |
if (!portletFragment) return; | |
var masks = DOMUtil.findDescendantsByClass(portletFragment, "div", "UIMask"); | |
for (var i = 0; i < masks.length; i++) { | |
eXo.core.Browser.setOpacity(masks[i], 100); | |
masks[i].style.display = "none"; | |
} | |
var uiTarget = targetObj; | |
if (uiTarget && !uiTarget.parentNode) { | |
uiTarget = null; | |
} | |
dragObj.style.position = "static"; | |
DOMUtil.removeClass(dragObj, "Dragging"); | |
var dragCopyObj = DOMUtil.findFirstDescendantByClass(portletFragment, "div", "CopyObj"); | |
if (dragCopyObj) { | |
dragCopyObj.parentNode.replaceChild(dragObj, dragCopyObj); | |
dragObj.style.width = "auto"; | |
} | |
if (uiTarget) { | |
var col = uiDashboardUtil.findColIndexInDashboard(uiTarget); | |
var row = uiDashboardUtil.findRowIndexInDashboard(uiTarget); | |
var compId = portletFragment.parentNode.id; | |
if (DOMUtil.hasClass(dragObj, "SelectItem")) { | |
var params = [{ | |
name: "colIndex", | |
value: col | |
}, { | |
name: "rowIndex", | |
value: row | |
}, { | |
name: "objectId", | |
value: dragObj.id | |
}]; | |
var url = uiDashboardUtil.createRequest(compId, 'AddNewGadget', params); | |
ajaxGet(url); | |
} else { | |
if (uiDashboardUtil.findColIndexInDashboard(dragObj) == col && uiDashboardUtil.findRowIndexInDashboard(dragObj) == (row - 1)) { | |
uiTarget.parentNode.removeChild(uiTarget); | |
} else { | |
uiTarget.parentNode.replaceChild(dragObj, uiTarget); | |
row = uiDashboardUtil.findRowIndexInDashboard(dragObj); | |
var params = [{ | |
name: "colIndex", | |
value: col | |
}, { | |
name: "rowIndex", | |
value: row | |
}, { | |
name: "objectId", | |
value: dragObj.id | |
}]; | |
var url = uiDashboardUtil.createRequest(compId, 'MoveGadget', params); | |
ajaxGet(url); | |
} | |
} | |
} | |
uiTarget = DOMUtil.findFirstDescendantByClass(portletFragment, "div", "UITarget"); | |
while (uiTarget) { | |
DOMUtil.removeElement(uiTarget); | |
uiTarget = eXo.core.DOMUtil.findFirstDescendantByClass(portletFragment, "div", "UITarget"); | |
} | |
targetObj = currCol = null; | |
} | |
dragObj.onCancel = function (e) { | |
if (eXo.core.Browser.browserType == "ie" && eXo.core.Browser.findMouseYInClient() < 0) { | |
eXo.core.DragDrop2.end(e); | |
} | |
} | |
}; | |
UIDashboard.prototype.onLoad = function (windowId, canEdit) { | |
var portletWindow = document.getElementById(windowId); | |
if (!portletWindow) return; | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiDashboard = DOMUtil.findFirstDescendantByClass(portletWindow, "div", "UIDashboard"); | |
var portletFragment = DOMUtil.findAncestorByClass(uiDashboard, "PORTLET-FRAGMENT"); | |
var uiContainer = DOMUtil.findFirstDescendantByClass(uiDashboard, "div", "UIDashboardContainer"); | |
if (!uiContainer) return; | |
var gadgetContainer = DOMUtil.findFirstChildByClass(uiContainer, "div", "GadgetContainer"); | |
uiDashboard.style.overflow = "hidden"; | |
portletFragment.style.overflow = "hidden"; | |
if (eXo.core.Browser.isIE6()) gadgetContainer.style.width = "99.5%"; | |
var selectPopup = DOMUtil.findPreviousElementByTagName(uiContainer, "div"); | |
var closeButton = DOMUtil.findFirstDescendantByClass(selectPopup, "a", "CloseButton"); | |
closeButton.onclick = eXo.webui.UIDashboard.showHideSelectContainer; | |
var colsContainer = DOMUtil.findFirstChildByClass(gadgetContainer, "div", "UIColumns"); | |
var columns = DOMUtil.findChildrenByClass(colsContainer, "div", "UIColumn"); | |
var colsSize = 0; | |
for (var i = 0; i < columns.length; i++) { | |
if (columns[i].style.display != "none") colsSize++; | |
} | |
colsContainer.style.width = "100%"; | |
setTimeout("eXo.webui.UIDashboard.initDragDrop('" + windowId + "'," + canEdit + ");", 400); | |
}; | |
UIDashboard.prototype.initDragDrop = function (windowId, canEdit) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var portletWindow = document.getElementById(windowId); | |
var gadgetControls = DOMUtil.findDescendantsByClass(portletWindow, "div", "GadgetControl"); | |
for (var j = 0; j < gadgetControls.length; j++) { | |
var uiGadget = DOMUtil.findAncestorByClass(gadgetControls[j], "UIGadget"); | |
var minimizeButton = DOMUtil.findFirstDescendantByClass(gadgetControls[j], "span", "MinimizeAction"); | |
if (canEdit) { | |
eXo.webui.UIDashboard.init(gadgetControls[j], uiGadget); | |
if (minimizeButton) minimizeButton.style.display = "block"; | |
} else { | |
if (minimizeButton) { | |
minimizeButton.style.display = "none"; | |
var controlBar = minimizeButton.parentNode; | |
var closeButton = DOMUtil.findFirstChildByClass(controlBar, "div", "CloseGadget"); | |
var editButton = DOMUtil.findFirstChildByClass(controlBar, "div", "EditGadget"); | |
closeButton.style.display = "none"; | |
editButton.style.display = "none"; | |
} | |
} | |
} | |
}; | |
UIDashboard.prototype.initPopup = function (popup) { | |
if (typeof (popup) == "string") popup = document.getElementById(popup); | |
if (!popup || popup.style.display == "none") return; | |
var uiDashboard = eXo.core.DOMUtil.findAncestorByClass(popup, "UIDashboard"); | |
var deltaY = Math.ceil((uiDashboard.offsetHeight - popup.offsetHeight) / 2); | |
if (deltaY < 0) { | |
deltaY = 0; | |
} | |
popup.style.top = eXo.core.Browser.findPosY(uiDashboard) + deltaY + "px"; | |
}; | |
UIDashboard.prototype.createTarget = function (width, height) { | |
var uiTarget = document.createElement("div"); | |
uiTarget.id = "UITarget"; | |
uiTarget.className = "UITarget"; | |
uiTarget.style.width = width + "px"; | |
uiTarget.style.height = height + "px"; | |
return uiTarget; | |
}; | |
UIDashboard.prototype.createTargetOfAnObject = function (obj) { | |
var uiTarget = document.createElement("div"); | |
uiTarget.id = "UITarget"; | |
uiTarget.className = "UITarget"; | |
uiTarget.style.height = obj.offsetHeight + "px"; | |
return uiTarget; | |
}; | |
UIDashboard.prototype.showHideSelectContainer = function (event) { | |
if (!event) event = window.event; | |
var DOMUtil = eXo.core.DOMUtil; | |
var comp = eXo.core.Browser.getEventSource(event); | |
var uiDashboardPortlet = DOMUtil.findAncestorByClass(comp, "UIDashboard"); | |
var portletFragment = DOMUtil.findAncestorByClass(uiDashboardPortlet, "PORTLET-FRAGMENT"); | |
var uiContainer = DOMUtil.findFirstDescendantByClass(uiDashboardPortlet, "div", "UIDashboardContainer"); | |
var uiSelectPopup = DOMUtil.findPreviousElementByTagName(uiContainer, "div"); | |
var addButton = DOMUtil.findFirstDescendantByClass(uiContainer, "a", "AddIcon"); | |
var params; | |
if (uiSelectPopup.style.display != "none") { | |
uiSelectPopup.style.visibility = "hidden"; | |
uiSelectPopup.style.display = "none"; | |
addButton.style.visibility = "visible"; | |
params = [{ | |
name: "isShow", | |
value: false | |
}]; | |
var url = eXo.webui.UIDashboardUtil.createRequest(portletFragment.parentNode.id, "SetShowSelectContainer", params); | |
ajaxAsyncGetRequest(url, false); | |
} else { | |
addButton.style.visibility = "hidden"; | |
params = [{ | |
name: "isShow", | |
value: true | |
}]; | |
var url = eXo.webui.UIDashboardUtil.createRequest(portletFragment.parentNode.id, "SetShowSelectContainer", params); | |
ajaxGet(url); | |
} | |
}; | |
UIDashboard.prototype.onTabClick = function (clickElement, normalStyle, selectedType) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var category = DOMUtil.findAncestorByClass(clickElement, "GadgetCategory"); | |
var categoryContent = DOMUtil.findFirstChildByClass(category, "div", "ItemsContainer"); | |
var categoriesContainer = DOMUtil.findAncestorByClass(category, "GadgetItemsContainer"); | |
var categories = DOMUtil.findChildrenByClass(categoriesContainer, "div", "GadgetCategory"); | |
var gadgetTab = DOMUtil.findFirstChildByClass(category, "div", "GadgetTab"); | |
if (DOMUtil.hasClass(gadgetTab, normalStyle)) { | |
for (var i = 0; i < categories.length; i++) { | |
DOMUtil.findFirstChildByClass(categories[i], "div", "GadgetTab").className = "GadgetTab " + normalStyle; | |
DOMUtil.findFirstChildByClass(categories[i], "div", "ItemsContainer").style.display = "none"; | |
} | |
DOMUtil.findFirstChildByClass(category, "div", "GadgetTab").className = "GadgetTab " + selectedType; | |
categoryContent.style.display = "block"; | |
} else { | |
DOMUtil.findFirstChildByClass(category, "div", "GadgetTab").className = "GadgetTab " + normalStyle; | |
categoryContent.style.display = "none"; | |
} | |
var popupContent = DOMUtil.findAncestorByClass(clickElement, "PopupContent"); | |
if (eXo.core.Browser.getBrowserHeight() - 100 < categoriesContainer.offsetHeight) { | |
popupContent.style.height = (eXo.core.Browser.getBrowserHeight() - 100) + "px"; | |
} else { | |
popupContent.style.height = "auto"; | |
} | |
}; | |
UIDashboard.prototype.enableContainer = function (elemt) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (DOMUtil.hasClass(elemt, "DisableContainer")) { | |
DOMUtil.replaceClass(elemt, " DisableContainer", ""); | |
} | |
var arrow = DOMUtil.findFirstChildByClass(elemt, "div", "Arrow"); | |
if (DOMUtil.hasClass(arrow, "DisableArrowIcon")) DOMUtil.replaceClass(arrow, " DisableArrowIcon", ""); | |
}; | |
UIDashboard.prototype.disableContainer = function (elemt) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (!DOMUtil.hasClass(elemt, "DisableContainer")) { | |
DOMUtil.addClass(elemt, "DisableContainer"); | |
} | |
var arrow = DOMUtil.findFirstChildByClass(elemt, "div", "Arrow"); | |
if (!DOMUtil.hasClass(arrow, "DisableArrowIcon")) DOMUtil.addClass(arrow, " DisableArrowIcon"); | |
}; | |
UIDashboard.prototype.scrollOnDrag = function (dragObj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var dashboardUtil = eXo.webui.UIDashboardUtil; | |
var uiDashboard = DOMUtil.findAncestorByClass(dragObj, "UIDashboard"); | |
var gadgetContainer = DOMUtil.findFirstDescendantByClass(uiDashboard, "div", "GadgetContainer"); | |
var colCont = DOMUtil.findFirstChildByClass(gadgetContainer, "div", "UIColumns"); | |
if (!DOMUtil.findFirstDescendantByClass(colCont, "div", "UITarget")) return; | |
var visibleWidth = gadgetContainer.offsetWidth; | |
var visibleHeight = gadgetContainer.offsetHeight; | |
var trueWidth = colCont.offsetWidth; | |
var trueHeight = colCont.offsetHeight; | |
var objLeft = dashboardUtil.findPosXInContainer(dragObj, gadgetContainer); | |
var objRight = objLeft + dragObj.offsetWidth; | |
var objTop = dashboardUtil.findPosYInContainer(dragObj, gadgetContainer); | |
var objBottom = objTop + dragObj.offsetHeight; | |
var deltaX = gadgetContainer.scrollLeft; | |
if ((trueWidth - (visibleWidth + deltaX) > 0) && objRight > visibleWidth) { | |
gadgetContainer.scrollLeft += 5; | |
} else { | |
if (objLeft < 0 && deltaX > 0) gadgetContainer.scrollLeft -= 5; | |
} | |
var controlBar = DOMUtil.findFirstChildByClass(gadgetContainer, "div", "ContainerControlBarL"); | |
var buttonHeight = 0; | |
if (controlBar) buttonHeight = controlBar.offsetHeight; | |
var deltaY = gadgetContainer.scrollTop; | |
if ((trueHeight - (visibleHeight - 10 - buttonHeight + deltaY) > 0) && objBottom > visibleHeight) { | |
gadgetContainer.scrollTop += 5; | |
} else { | |
if (objTop < 0 && deltaY > 0) gadgetContainer.scrollTop -= 5; | |
} | |
}; | |
}; | |
eXo.webui.UIDashboard = new UIDashboard(); | |
function UIDashboardUtil() { | |
UIDashboardUtil.prototype.findPosX = function (obj) { | |
var curleft = 0; | |
var uiWorkspaceContainer = document.getElementById("UIWorkspaceContainer"); | |
var uiWorkingWorkspace = document.getElementById("UIWorkingWorkspace"); | |
while (obj) { | |
if (uiWorkspaceContainer != null && uiWorkspaceContainer.style.display != "none" && eXo.core.Browser.getBrowserType() == "ie") { | |
var uiPageDesktop = document.getElementById("UIPageDesktop"); | |
if ((uiPageDesktop != null && eXo.core.DOMUtil.hasClass(obj, "UIPageDesktop") && eXo.core.Browser.isIE7()) || (uiPageDesktop == null && eXo.core.DOMUtil.hasClass(obj, "PORTLET-FRAGMENT"))) { | |
curleft += (obj.offsetLeft - uiWorkingWorkspace.offsetLeft); | |
obj = obj.offsetParent; | |
continue; | |
} | |
} | |
curleft += obj.offsetLeft; | |
obj = obj.offsetParent; | |
} | |
return curleft; | |
}; | |
UIDashboardUtil.prototype.findPosY = function (obj) { | |
var curtop = 0; | |
while (obj) { | |
curtop += obj.offsetTop; | |
obj = obj.offsetParent; | |
} | |
return curtop; | |
}; | |
UIDashboardUtil.prototype.findMouseRelativeX = function (object, e) { | |
var posx = -1; | |
var posXObject = eXo.webui.UIDashboardUtil.findPosX(object); | |
if (!e) e = window.event; | |
if (e.pageX || e.pageY) { | |
posx = e.pageX - posXObject; | |
} else if (e.clientX || e.clientY) { | |
posx = e.clientX + document.body.scrollLeft - posXObject; | |
} | |
return posx; | |
}; | |
UIDashboardUtil.prototype.findMouseRelativeY = function (object, e) { | |
var posy = -1; | |
var posYObject = eXo.webui.UIDashboardUtil.findPosY(object); | |
if (!e) e = window.event; | |
if (e.pageY) { | |
posy = e.pageY - posYObject; | |
} else if (e.clientX || e.clientY) { | |
if (document.documentElement && document.documentElement.scrollTop) { | |
posy = e.clientY + document.documentElement.scrollTop - posYObject; | |
} else { | |
posy = e.clientY + document.body.scrollTop - posYObject; | |
} | |
} | |
return posy; | |
}; | |
UIDashboardUtil.prototype.findPosXInContainer = function (obj, container) { | |
var objX = eXo.webui.UIDashboardUtil.findPosX(obj); | |
var containerX = eXo.webui.UIDashboardUtil.findPosX(container); | |
return (objX - containerX); | |
}; | |
UIDashboardUtil.prototype.findPosYInContainer = function (obj, container) { | |
var objY = eXo.webui.UIDashboardUtil.findPosY(obj); | |
var containerY = eXo.webui.UIDashboardUtil.findPosY(container); | |
return (objY - containerY); | |
}; | |
UIDashboardUtil.prototype.setPositionInContainer = function (container, component, posX, posY) { | |
var offsetX = component.offsetLeft; | |
var offsetY = component.offsetTop; | |
var posXInContainer = eXo.webui.UIDashboardUtil.findPosXInContainer(component, container); | |
var posYInContainer = eXo.webui.UIDashboardUtil.findPosYInContainer(component, container); | |
var deltaX = posX - (posXInContainer - offsetX); | |
var deltaY = posY - (posYInContainer - offsetY); | |
component.style.left = deltaX + "px"; | |
component.style.top = deltaY + "px"; | |
}; | |
UIDashboardUtil.prototype.isIn = function (x, y, component) { | |
var componentLeft = eXo.webui.UIDashboardUtil.findPosX(component); | |
var componentRight = componentLeft + component.offsetWidth; | |
var componentTop = eXo.webui.UIDashboardUtil.findPosY(component); | |
var componentBottom = componentTop + component.offsetHeight; | |
var isOver = false; | |
if ((componentLeft < x) && (x < componentRight)) { | |
if ((componentTop < y) && (y < componentBottom)) { | |
isOver = true; | |
} | |
} | |
return isOver; | |
}; | |
UIDashboardUtil.prototype.findColIndexInDashboard = function (dragObj) { | |
var col = dragObj.parentNode; | |
if (col == null) return null; | |
var dashboardContainer = eXo.core.DOMUtil.findAncestorByClass(col, "DashboardContainer"); | |
var columns = eXo.core.DOMUtil.findDescendantsByClass(dashboardContainer, "div", "UIColumn"); | |
for (var i = 0; i < columns.length; i++) { | |
if (col.id == columns[i].id) { | |
return i; | |
} | |
} | |
}; | |
UIDashboardUtil.prototype.findRowIndexInDashboard = function (dragObj) { | |
var modules = eXo.core.DOMUtil.getChildrenByTagName(dragObj.parentNode, "div"); | |
for (var i = 0; i < modules.length; i++) { | |
if (modules[i].id == dragObj.id) return i; | |
} | |
}; | |
UIDashboardUtil.prototype.createRequest = function (componentId, action, params) { | |
var url = eXo.env.server.portalBaseURL; | |
url += '?portal:componentId=' + componentId + '&portal:type=action&uicomponent=UIDashboard&op=' + action; | |
url += '&ajaxRequest=true'; | |
if (params != null) { | |
var len = params.length; | |
for (var i = 0; i < len; i++) { | |
url += "&" + params[i].name + "=" + params[i].value; | |
} | |
} | |
return url; | |
}; | |
}; | |
eXo.webui.UIDashboardUtil = new UIDashboardUtil(); | |
function UINotification() { | |
this.timerlen = 5; | |
this.slideAniLen = 1000; | |
this.timerID = new Array(); | |
this.startTime = new Array(); | |
this.object = new Array(); | |
this.endHeight = new Array(); | |
this.moving = new Array(); | |
this.endSlideUpCallback = new Array(); | |
this.dir = new Array(); | |
this.importantNoti = new Array(); | |
this.flagNoti = new Array(); | |
this.totalCurrentMessage = 0; | |
this.numberMessageRecepted = 0; | |
this.numImptNoti = 0; | |
if (eXo.core.Topic != null) { | |
eXo.core.Topic.subscribe("/eXo/portal/notification", function (event) { | |
eXo.webui.UINotification.addMessage(event.message); | |
}) | |
} | |
} | |
UINotification.prototype.slideDown = function (objectName) { | |
if (this.moving[objectName]) return; | |
if (document.getElementById(objectName).style.display != "none") return; | |
this.moving[objectName] = true; | |
this.dir[objectName] = "down"; | |
this.startSlide(objectName); | |
} | |
UINotification.prototype.slideDownUp = function (objectName, endSlideUpCallback) { | |
this.slideDown(objectName); | |
this.endSlideUpCallback[objectName] = endSlideUpCallback; | |
if (this.flagNoti[objectName]) setTimeout("eXo.webui.UINotification.slideUp('" + objectName + "')", 3000); | |
} | |
UINotification.prototype.closeNotification = function () { | |
for (var i = 0; i < this.importantNoti.length; i++) { | |
this.flagNoti[this.importantNoti[i]] = true; | |
setTimeout("eXo.webui.UINotification.slideUp('" + this.importantNoti[i] + "')", 100); | |
} | |
} | |
UINotification.prototype.slideUp = function (objectName) { | |
if (this.moving[objectName]) return; | |
if (document.getElementById(objectName).style.display == "none") return; | |
this.moving[objectName] = true; | |
this.dir[objectName] = "up"; | |
this.startSlide(objectName); | |
} | |
UINotification.prototype.startSlide = function (objectName) { | |
this.object[objectName] = document.getElementById(objectName); | |
this.endHeight[objectName] = parseInt(this.object[objectName].style.height); | |
this.startTime[objectName] = (new Date()).getTime(); | |
if (this.dir[objectName] == "down") { | |
this.object[objectName].style.height = "1px"; | |
} | |
this.object[objectName].style.display = "block"; | |
this.timerID[objectName] = setInterval('eXo.webui.UINotification.slideTick(\'' + objectName + '\');', this.timerlen); | |
} | |
UINotification.prototype.slideTick = function (objectName) { | |
var elapsed = (new Date()).getTime() - this.startTime[objectName]; | |
if (elapsed > this.slideAniLen) this.endSlide(objectName); | |
else { | |
var d = Math.round(elapsed / this.slideAniLen * this.endHeight[objectName]); | |
if (this.dir[objectName] == "up") d = this.endHeight[objectName] - d; | |
this.object[objectName].style.height = d + "px"; | |
} | |
return; | |
} | |
UINotification.prototype.destroyUINotification = function () { | |
var UINotification = document.getElementById("UINotification"); | |
document.getElementsByTagName("body")[0].removeChild(UINotification); | |
} | |
UINotification.prototype.endSlide = function (objectName) { | |
clearInterval(this.timerID[objectName]); | |
if (this.dir[objectName] == "up") { | |
this.object[objectName].style.display = "none"; | |
if (this.endSlideUpCallback[objectName]) { | |
this.endSlideUpCallback[objectName](objectName); | |
this.totalCurrentMessage--; | |
if (this.totalCurrentMessage == 0) { | |
this.destroyUINotification(); | |
return; | |
} | |
} | |
} | |
this.object[objectName].style.height = this.endHeight[objectName] + "px"; | |
delete(this.moving[objectName]); | |
delete(this.timerID[objectName]); | |
delete(this.startTime[objectName]); | |
delete(this.endHeight[objectName]); | |
delete(this.object[objectName]); | |
delete(this.dir[objectName]); | |
delete(this.flagNoti[objectName]); | |
return; | |
} | |
UINotification.prototype.deleteBox = function (objectName) { | |
var el = document.getElementById(objectName); | |
el.parentNode.removeChild(el); | |
} | |
UINotification.prototype.createFrameForMessages = function () { | |
var htmlString = ""; | |
htmlString += "<div class=\"UIPopupNotification\">"; | |
htmlString += "<div class=\"TLPopupNotification\">"; | |
htmlString += "<div class=\"TRPopupNotification\">"; | |
htmlString += "<div class=\"TCPopupNotification\" ><span></span></div>"; | |
htmlString += "</div>"; | |
htmlString += "</div>"; | |
htmlString += "<div class=\"MLPopupNotification\">"; | |
htmlString += "<div class=\"MRPopupNotification\">"; | |
htmlString += "<div class=\"MCPopupNotification\">"; | |
htmlString += "<div class=\"TitleNotification\">"; | |
htmlString += "<a class=\"ItemTitle\" href=\"#\">Notification</a>"; | |
htmlString += "<a class=\"Close\" href=\"#\" onclick=\"eXo.webui.UINotification.closeNotification();\"><span></span></a>"; | |
htmlString += "</div>"; | |
htmlString += "<div id=\"UINotificationContent\">"; | |
htmlString += "</div>"; | |
htmlString += "</div>"; | |
htmlString += "</div>"; | |
htmlString += "</div>"; | |
htmlString += "<div class=\"BLPopupNotification\">"; | |
htmlString += "<div class=\"BRPopupNotification\">"; | |
htmlString += "<div class=\"BCPopupNotification\"><span></span></div>"; | |
htmlString += "</div>"; | |
htmlString += "</div>"; | |
htmlString += "</div>"; | |
return htmlString; | |
} | |
UINotification.prototype.addMessage = function (messageContent, flag) { | |
var currMessageBoxId = "UIMessageBox_" + this.numberMessageRecepted++; | |
var UIMessageContent = document.createElement('div'); | |
this.totalCurrentMessage++; | |
this.flagNoti[currMessageBoxId] = !flag; | |
if (flag) { | |
this.importantNoti[this.numImptNoti] = currMessageBoxId; | |
this.numImptNoti++; | |
} | |
UIMessageContent.id = currMessageBoxId; | |
UIMessageContent.style.height = "35px"; | |
UIMessageContent.style.display = "none"; | |
UIMessageContent.className = "Item"; | |
UIMessageContent.innerHTML = "<div>" + messageContent + "</div>"; | |
var UINotification = document.getElementById("UINotification"); | |
if (UINotification == null) { | |
document.body.appendChild(document.createElement('div')).id = "UINotification"; | |
UINotification = document.getElementById("UINotification"); | |
UINotification.className = 'UINotification'; | |
UINotification.innerHTML = this.createFrameForMessages(); | |
} | |
var msPanel = document.getElementById("UINotificationContent"); | |
msPanel.appendChild(UIMessageContent); | |
eXo.webui.UINotification.slideDownUp(currMessageBoxId, this.deleteBox); | |
} | |
eXo.webui.UINotification = new UINotification(); | |
function UIUserSelector() {}; | |
UIUserSelector.prototype.init = function (cont) { | |
if (typeof (cont) == "string") cont = document.getElementById(cont); | |
var checkboxes = eXo.core.DOMUtil.findDescendantsByClass(cont, "input", "checkbox"); | |
if (checkboxes.length <= 0) return; | |
checkboxes[0].onclick = this.checkAll; | |
var len = checkboxes.length; | |
for (var i = 1; i < len; i++) { | |
checkboxes[i].onclick = this.check; | |
} | |
}; | |
UIUserSelector.prototype.checkAll = function () { | |
eXo.webui.UIUserSelector.checkAllItem(this); | |
}; | |
UIUserSelector.prototype.getItems = function (obj) { | |
var table = eXo.core.DOMUtil.findAncestorByTagName(obj, "table"); | |
var checkboxes = eXo.core.DOMUtil.findDescendantsByClass(table, "input", "checkbox"); | |
return checkboxes; | |
}; | |
UIUserSelector.prototype.check = function () { | |
eXo.webui.UIUserSelector.checkItem(this); | |
}; | |
UIUserSelector.prototype.checkAllItem = function (obj) { | |
var checked = obj.checked; | |
var items = eXo.webui.UIUserSelector.getItems(obj); | |
var len = items.length; | |
for (var i = 1; i < len; i++) { | |
items[i].checked = checked; | |
} | |
}; | |
UIUserSelector.prototype.checkItem = function (obj) { | |
var checkboxes = eXo.webui.UIUserSelector.getItems(obj); | |
var len = checkboxes.length; | |
var state = true; | |
if (!obj.checked) { | |
checkboxes[0].checked = false; | |
} else { | |
for (var i = 1; i < len; i++) { | |
state = state && checkboxes[i].checked; | |
} | |
checkboxes[0].checked = state; | |
} | |
}; | |
UIUserSelector.prototype.getKeynum = function (event) { | |
var keynum = false; | |
if (window.event) { | |
keynum = window.event.keyCode; | |
event = window.event; | |
} else if (event.which) { | |
keynum = event.which; | |
} | |
if (keynum == 0) { | |
keynum = event.keyCode; | |
} | |
return keynum; | |
}; | |
UIUserSelector.prototype.isEnterPress = function (evt) { | |
var _e = evt || window.event; | |
var keynum = eXo.webui.UIUserSelector.getKeynum(_e); | |
if (keynum == 13) { | |
return true; | |
} | |
return false; | |
}; | |
UIUserSelector.prototype.cancelSubmit = function () { | |
return false; | |
}; | |
eXo.webui.UIUserSelector = new UIUserSelector(); | |
function UICombobox() {} | |
UICombobox.prototype.init = function (textbox) { | |
if (typeof (textbox) == "string") textbox = document.getElementById(textbox); | |
textbox = eXo.core.DOMUtil.findNextElementByTagName(textbox, "input"); | |
var UICombobox = eXo.webui.UICombobox; | |
var onfocus = textbox.getAttribute("onfocus"); | |
var onclick = textbox.getAttribute("onclick"); | |
if (!onfocus) textbox.onfocus = UICombobox.show; | |
if (!onclick) textbox.onclick = UICombobox.show; | |
}; | |
UICombobox.prototype.show = function (evt) { | |
var uiCombo = eXo.webui.UICombobox; | |
uiCombo.items = eXo.core.DOMUtil.findDescendantsByTagName(this.parentNode, "a"); | |
if (uiCombo.list) uiCombo.list.style.display = "none"; | |
uiCombo.list = eXo.core.DOMUtil.findFirstDescendantByClass(this.parentNode, "div", "UIComboboxContainer"); | |
uiCombo.list.parentNode.style.position = "absolute"; | |
uiCombo.fixForIE6(this); | |
uiCombo.list.style.display = "block"; | |
uiCombo.list.style.top = this.offsetHeight + "px"; | |
uiCombo.list.style.width = this.offsetWidth + "px"; | |
uiCombo.setSelectedItem(this); | |
uiCombo.list.onmousedown = eXo.core.EventManager.cancelEvent; | |
document.onmousedown = uiCombo.hide; | |
}; | |
UICombobox.prototype.getSelectedItem = function (textbox) { | |
var val = textbox.value; | |
var data = eval(textbox.getAttribute("options")); | |
var len = data.length; | |
for (var i = 0; i < len; i++) { | |
if (val == data[i]) return i; | |
} | |
return false; | |
}; | |
UICombobox.prototype.setSelectedItem = function (textbox) { | |
if (this.lastSelectedItem) eXo.core.DOMUtil.replaceClass(this.lastSelectedItem, "UIComboboxSelectedItem", ""); | |
var selectedIndex = parseInt(this.getSelectedItem(textbox)); | |
if (selectedIndex >= 0) { | |
eXo.core.DOMUtil.addClass(this.items[selectedIndex], "UIComboboxSelectedItem"); | |
this.lastSelectedItem = this.items[selectedIndex]; | |
var y = eXo.core.Browser.findPosYInContainer(this.lastSelectedItem, this.list); | |
this.list.firstChild.scrollTop = y; | |
var hidden = eXo.core.DOMUtil.findPreviousElementByTagName(textbox, "input"); | |
hidden.value = this.items[selectedIndex].getAttribute("value"); | |
} | |
}; | |
UICombobox.prototype.fixForIE6 = function (obj) { | |
if (!eXo.core.Browser.isIE6()) return; | |
if (eXo.core.DOMUtil.getChildrenByTagName(this.list, "iframe").length > 0) return; | |
var iframe = document.createElement("iframe"); | |
iframe.frameBorder = 0; | |
iframe.style.width = obj.offsetWidth + "px"; | |
this.list.appendChild(iframe); | |
}; | |
UICombobox.prototype.cancelBubbe = function (evt) { | |
var _e = window.event || evt; | |
_e.cancelBubble = true; | |
}; | |
UICombobox.prototype.complete = function (obj, evt) { | |
if (evt.keyCode == 16) { | |
this.setSelectedItem(obj); | |
return; | |
} | |
if (evt.keyCode == 13) { | |
this.setSelectedItem(obj); | |
this.hide(); | |
return; | |
} | |
var sVal = obj.value.toLowerCase(); | |
if (evt.keyCode == 8) sVal = sVal.substring(0, sVal.length - 1) | |
if (sVal.length < 1) return; | |
var data = eval(obj.getAttribute("options").trim()); | |
var len = data.length; | |
var tmp = null; | |
for (var i = 0; i < data.length; i++) { | |
tmp = data[i].trim(); | |
var idx = tmp.toLowerCase().indexOf(sVal, 0); | |
if (idx == 0 && tmp.length > sVal.length) { | |
obj.value = data[i]; | |
if (obj.createTextRange) { | |
hRange = obj.createTextRange(); | |
hRange.findText(data[i].substr(sVal.length)); | |
hRange.select(); | |
} else { | |
obj.setSelectionRange(sVal.length, tmp.length); | |
} | |
break; | |
} | |
} | |
this.setSelectedItem(obj); | |
}; | |
UICombobox.prototype.hide = function () { | |
eXo.webui.UICombobox.list.style.display = "none"; | |
document.onmousedown = null; | |
}; | |
UICombobox.prototype.getValue = function (obj) { | |
var UICombobox = eXo.webui.UICombobox; | |
var val = obj.getAttribute("value"); | |
var hiddenField = eXo.core.DOMUtil.findNextElementByTagName(UICombobox.list.parentNode, "input"); | |
hiddenField.value = val; | |
var text = eXo.core.DOMUtil.findNextElementByTagName(hiddenField, "input"); | |
text.value = eXo.core.DOMUtil.findFirstDescendantByClass(obj, "div", "UIComboboxLabel").innerHTML; | |
UICombobox.list.style.display = "none"; | |
}; | |
eXo.webui.UICombobox = new UICombobox(); | |
function EventManager() {} | |
EventManager.prototype.cancelBubble = function (evt) { | |
if (eXo.core.Browser.browserType == 'ie') window.event.cancelBubble = true; | |
else evt.stopPropagation(); | |
}; | |
EventManager.prototype.cancelEvent = function (evt) { | |
eXo.core.EventManager.cancelBubble(evt); | |
if (eXo.core.Browser.browserType == 'ie') window.event.returnValue = true; | |
else evt.preventDefault(); | |
}; | |
eXo.core.EventManager = new EventManager(); | |
function UIVirtualList() {} | |
UIVirtualList.prototype.init = function (componentId, hasNext, autoAdjustHeight) { | |
var uiVirtualList = document.getElementById(componentId); | |
if (uiVirtualList == null) return; | |
if (!hasNext) { | |
uiVirtualList.isFinished = true; | |
} | |
var virtualHeight = eXo.core.DOMUtil.getStyle(uiVirtualList, 'height', true); | |
if (virtualHeight == 0) { | |
virtualHeight = 300; | |
} | |
uiVirtualList.style.height = virtualHeight + "px"; | |
if (autoAdjustHeight) { | |
uiVirtualList.autoAdjustHeight = autoAdjustHeight; | |
eXo.core.Browser.fillUpFreeSpace(uiVirtualList); | |
} | |
uiVirtualList.scrollTop = 0; | |
this.loadIfNeeded(uiVirtualList); | |
} | |
UIVirtualList.prototype.loadIfNeeded = function (uiVirtualList) { | |
if (uiVirtualList.clientHeight == uiVirtualList.scrollHeight) { | |
if (uiVirtualList.isFinished) { | |
if (uiVirtualList.autoAdjustHeight) { | |
uiVirtualList.style.height = "auto"; | |
} | |
} else { | |
uiVirtualList.onscroll(); | |
} | |
} | |
} | |
UIVirtualList.prototype.getFeedBox = function (componentId) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiVirtualList = document.getElementById(componentId); | |
var feedBox = DOMUtil.findFirstDescendantByClass(uiVirtualList, "div", "FeedBox"); | |
if (feedBox == null) { | |
feedBox = DOMUtil.findFirstDescendantByClass(uiVirtualList, "tbody", "FeedBox"); | |
} | |
return feedBox; | |
} | |
UIVirtualList.prototype.onScroll = function (uiVirtualList, url) { | |
if (uiVirtualList.isFinished || uiVirtualList.inProgress) return; | |
var DOMUtil = eXo.core.DOMUtil; | |
var componentHeight = uiVirtualList.offsetHeight; | |
var scrollPosition = uiVirtualList.scrollTop; | |
var scrollerHeight = uiVirtualList.scrollHeight; | |
var scrollable_gap = scrollerHeight - (scrollPosition + componentHeight); | |
if (scrollable_gap <= 1) { | |
var feedBox = this.getFeedBox(uiVirtualList.id); | |
var html = feedBox.innerHTML; | |
uiVirtualList.backupHTML = html; | |
uiVirtualList.inProgress = true; | |
ajaxGet(url); | |
} | |
} | |
UIVirtualList.prototype.updateList = function (componentId, hasNext) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiVirtualList = document.getElementById(componentId); | |
if (uiVirtualList == null) return; | |
if (!hasNext) { | |
uiVirtualList.isFinished = true; | |
} | |
var feedBox = this.getFeedBox(uiVirtualList.id); | |
var loadedContent = uiVirtualList.backupHTML; | |
if (eXo.core.Browser.browserType != "ie") { | |
feedBox.innerHTML = loadedContent + feedBox.innerHTML; | |
} else { | |
var index = uiVirtualList.innerHTML.indexOf(feedBox.className); | |
index = uiVirtualList.innerHTML.indexOf(">", index) + 1; | |
var firstSec = uiVirtualList.innerHTML.substring(0, index); | |
var secondSec = uiVirtualList.innerHTML.substring(index); | |
uiVirtualList.innerHTML = firstSec + loadedContent + secondSec; | |
} | |
uiVirtualList.inProgress = false; | |
this.loadIfNeeded(uiVirtualList); | |
} | |
eXo.webui.UIVirtualList = new UIVirtualList(); | |
function UIColorPicker() {} | |
UIColorPicker.prototype.show = function (obj) { | |
document.onmousedown = new Function("eXo.webui.UIColorPicker.hide()"); | |
this.tableColor = eXo.core.DOMUtil.findNextElementByTagName(obj, "div"); | |
this.title = eXo.core.DOMUtil.findFirstDescendantByClass(obj, "span", "DisplayValue"); | |
this.input = eXo.core.DOMUtil.findFirstDescendantByClass(obj.parentNode, "input", "UIColorPickerValue"); | |
this.showHide(); | |
this.getSelectedValue(); | |
} | |
UIColorPicker.prototype.setColor = function (color) { | |
if (eXo.core.DOMUtil.hasClass(this.title, color)) { | |
this.hide(); | |
return; | |
} | |
var className = "DisplayValue " + color; | |
this.title.className = className; | |
this.input.value = color; | |
this.hide(); | |
}; | |
UIColorPicker.prototype.clearSelectedValue = function () { | |
var selectedValue = this.input.value; | |
var colorCell = eXo.core.DOMUtil.findDescendantsByTagName(this.tableColor, "a"); | |
var len = colorCell.length; | |
for (var i = 0; i < len; i++) { | |
if (eXo.core.DOMUtil.hasClass(colorCell[i], "SelectedColorCell")) { | |
colorCell[i].className = colorCell[i].className.replace("SelectedColorCell", ""); | |
break; | |
} | |
} | |
}; | |
UIColorPicker.prototype.getSelectedValue = function () { | |
var selectedValue = this.input.value; | |
var colorCell = eXo.core.DOMUtil.findDescendantsByTagName(this.tableColor, "a"); | |
var len = colorCell.length; | |
this.clearSelectedValue(); | |
for (var i = 0; i < len; i++) { | |
if (eXo.core.DOMUtil.hasClass(colorCell[i], selectedValue)) { | |
eXo.core.DOMUtil.addClass(colorCell[i], "SelectedColorCell"); | |
break; | |
} | |
} | |
}; | |
UIColorPicker.prototype.hide = function () { | |
if (eXo.webui.UIColorPicker.tableColor) { | |
eXo.webui.UIColorPicker.tableColor.style.display = "none"; | |
eXo.webui.UIColorPicker.tableColor = null; | |
eXo.webui.UIColorPicker.title = null; | |
eXo.webui.UIColorPicker.input = null; | |
document.onmousedown = null; | |
} | |
}; | |
UIColorPicker.prototype.showHide = function () { | |
var obj = this.tableColor; | |
if (obj.style.display != "block") { | |
obj.style.display = "block"; | |
} else { | |
obj.style.display = "none"; | |
} | |
}; | |
eXo.webui.UIColorPicker = new UIColorPicker(); | |
function UIPortlet() { | |
this.maxIndex = 0; | |
}; | |
UIPortlet.prototype.onControlOver = function (element, isOver) { | |
var originalElementName = element.className; | |
if (isOver) { | |
var overElementName = "ControlIcon Over" + originalElementName.substr(originalElementName.indexOf(" ") + 1, 30); | |
element.className = overElementName; | |
if (element.className == "ControlIcon OverRestoreIcon") { | |
var hiddenAttribute = eval('(' + eXo.core.DOMUtil.findFirstChildByClass(element, "div", "").innerHTML + ')'); | |
element.title = hiddenAttribute.modeTitle; | |
} | |
if (element.className == "ControlIcon OverMaximizedIcon") { | |
var hiddenAttribute = eval('(' + eXo.core.DOMUtil.findFirstChildByClass(element, "div", "").innerHTML + ')'); | |
element.title = hiddenAttribute.normalTitle; | |
} | |
} else { | |
var over = originalElementName.indexOf("Over"); | |
if (over >= 0) { | |
var overElementName = "ControlIcon " + originalElementName.substr(originalElementName.indexOf(" ") + 5, 30); | |
element.className = overElementName; | |
} | |
} | |
}; | |
eXo.webui.UIPortlet = new UIPortlet(); | |
var FCKeditor = function (instanceName, width, height, toolbarSet, value) { | |
this.InstanceName = instanceName; | |
this.Width = width || '100%'; | |
this.Height = height || '200'; | |
this.ToolbarSet = toolbarSet || 'Default'; | |
this.Value = value || ''; | |
this.BasePath = FCKeditor.BasePath; | |
this.CheckBrowser = true; | |
this.DisplayErrors = true; | |
this.Config = new Object(); | |
this.OnError = null; | |
} | |
FCKeditor.BasePath = '/fckeditor/'; | |
FCKeditor.MinHeight = 200; | |
FCKeditor.MinWidth = 750; | |
FCKeditor.prototype.Version = '2.6.6'; | |
FCKeditor.prototype.VersionBuild = '25427'; | |
FCKeditor.prototype.Create = function () { | |
document.write(this.CreateHtml()); | |
} | |
FCKeditor.prototype.CreateHtml = function () { | |
if (!this.InstanceName || this.InstanceName.length == 0) { | |
this._ThrowError(701, 'You must specify an instance name.'); | |
return ''; | |
} | |
var sHtml = ''; | |
if (!this.CheckBrowser || this._IsCompatibleBrowser()) { | |
sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode(this.Value) + '" style="display:none" />'; | |
sHtml += this._GetConfigHtml(); | |
sHtml += this._GetIFrameHtml(); | |
} else { | |
var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px'; | |
var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px'; | |
sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight; | |
if (this.TabIndex) sHtml += '" tabindex="' + this.TabIndex; | |
sHtml += '">' + this._HTMLEncode(this.Value) + '<\/textarea>'; | |
} | |
return sHtml; | |
} | |
FCKeditor.prototype.ReplaceTextarea = function () { | |
if (document.getElementById(this.InstanceName + '___Frame')) return; | |
if (!this.CheckBrowser || this._IsCompatibleBrowser()) { | |
var oTextarea = document.getElementById(this.InstanceName); | |
var colElementsByName = document.getElementsByName(this.InstanceName); | |
var i = 0; | |
while (oTextarea || i == 0) { | |
if (oTextarea && oTextarea.tagName.toLowerCase() == 'textarea') break; | |
oTextarea = colElementsByName[i++]; | |
} | |
if (!oTextarea) { | |
alert('Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found'); | |
return; | |
} | |
oTextarea.style.display = 'none'; | |
if (oTextarea.tabIndex) this.TabIndex = oTextarea.tabIndex; | |
this._InsertHtmlBefore(this._GetConfigHtml(), oTextarea); | |
this._InsertHtmlBefore(this._GetIFrameHtml(), oTextarea); | |
} | |
} | |
FCKeditor.prototype._InsertHtmlBefore = function (html, element) { | |
if (element.insertAdjacentHTML) element.insertAdjacentHTML('beforeBegin', html); | |
else { | |
var oRange = document.createRange(); | |
oRange.setStartBefore(element); | |
var oFragment = oRange.createContextualFragment(html); | |
element.parentNode.insertBefore(oFragment, element); | |
} | |
} | |
FCKeditor.prototype._GetConfigHtml = function () { | |
var sConfig = ''; | |
for (var o in this.Config) { | |
if (sConfig.length > 0) sConfig += '&'; | |
sConfig += encodeURIComponent(o) + '=' + encodeURIComponent(this.Config[o]); | |
} | |
return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />'; | |
} | |
FCKeditor.prototype._GetIFrameHtml = function () { | |
var sFile = 'fckeditor.html'; | |
try { | |
if ((/fcksource=true/i).test(window.top.location.search)) sFile = 'fckeditor.original.html'; | |
} catch (e) {} | |
var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent(this.InstanceName); | |
if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet; | |
var html = '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height; | |
if (this.TabIndex) html += '" tabindex="' + this.TabIndex; | |
html += '" frameborder="0" scrolling="no"></iframe>'; | |
return html; | |
} | |
FCKeditor.prototype._IsCompatibleBrowser = function () { | |
return FCKeditor_IsCompatibleBrowser(); | |
} | |
FCKeditor.prototype._ThrowError = function (errorNumber, errorDescription) { | |
this.ErrorNumber = errorNumber; | |
this.ErrorDescription = errorDescription; | |
if (this.DisplayErrors) { | |
document.write('<div style="COLOR: #ff0000">'); | |
document.write('[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]'); | |
document.write('</div>'); | |
} | |
if (typeof (this.OnError) == 'function') this.OnError(this, errorNumber, errorDescription); | |
} | |
FCKeditor.prototype._HTMLEncode = function (text) { | |
if (typeof (text) != "string") text = text.toString(); | |
text = text.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"); | |
return text; | |
}; | |
(function () { | |
var textareaToEditor = function (textarea) { | |
var editor = new FCKeditor(textarea.name); | |
editor.Width = Math.max(textarea.offsetWidth, FCKeditor.MinWidth); | |
editor.Height = Math.max(textarea.offsetHeight, FCKeditor.MinHeight); | |
return editor; | |
} | |
FCKeditor.ReplaceAllTextareas = function () { | |
var textareas = document.getElementsByTagName('textarea'); | |
for (var i = 0; i < textareas.length; i++) { | |
var editor = null; | |
var textarea = textareas[i]; | |
var name = textarea.name; | |
if (!name || name.length == 0) continue; | |
if (typeof arguments[0] == 'string') { | |
var classRegex = new RegExp('(?:^| )' + arguments[0] + '(?:$| )'); | |
if (!classRegex.test(textarea.className)) continue; | |
} else if (typeof arguments[0] == 'function') { | |
editor = textareaToEditor(textarea); | |
if (arguments[0](textarea, editor) === false) continue; | |
} | |
if (!editor) editor = textareaToEditor(textarea); | |
editor.ReplaceTextarea(); | |
} | |
} | |
})(); | |
function FCKeditor_IsCompatibleBrowser() { | |
var sAgent = navigator.userAgent.toLowerCase(); | |
if (false && sAgent.indexOf("mac") == -1) { | |
var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1]; | |
return (sBrowserVersion >= 5.5); | |
} | |
if (navigator.product == "Gecko" && navigator.productSub >= 20030210 && !(typeof (opera) == 'object' && opera.postError)) return true; | |
if (window.opera && window.opera.version && parseFloat(window.opera.version()) >= 9.5) return true; | |
if (sAgent.indexOf(' adobeair/') != -1) return (sAgent.match(/ adobeair\/(\d+)/)[1] >= 1); | |
if (sAgent.indexOf(' applewebkit/') != -1) return (sAgent.match(/ applewebkit\/(\d+)/)[1] >= 522); | |
return false; | |
} | |
function WCMUIPopupWindow() {}; | |
WCMUIPopupWindow.prototype.init = function (popupId, isShow, isResizable, showCloseButton, isShowMask, top, left) { | |
var DOMUtil = eXo.core.DOMUtil; | |
this.superClass = eXo.webui.UIPopup; | |
var popup = document.getElementById(popupId); | |
if (popup == null) return; | |
popup.style.visibility = "hidden"; | |
if (isShow) { | |
popup.style.display = "block"; | |
} | |
var contentBlock = DOMUtil.findFirstDescendantByClass(popup, 'div', 'PopupContent'); | |
if (contentBlock && (eXo.core.Browser.getBrowserHeight() - 100 < contentBlock.offsetHeight)) { | |
contentBlock.style.height = (eXo.core.Browser.getBrowserHeight() - 100) + "px"; | |
} | |
var popupBar = DOMUtil.findFirstDescendantByClass(popup, 'span', 'PopupTitle'); | |
popupBar.onmousedown = this.initDND; | |
if (isShow == false) { | |
this.superClass.hide(popup); | |
if (isShowMask) eXo.webui.WCMUIPopupWindow.showMask(popup, false); | |
} | |
if (isResizable) { | |
var resizeBtn = DOMUtil.findFirstDescendantByClass(popup, "span", "ResizeButton"); | |
resizeBtn.style.display = 'block'; | |
resizeBtn.onmousedown = this.startResizeEvt; | |
} | |
popup.style.visibility = "hidden"; | |
if (isShow == true) { | |
var iframes = DOMUtil.findDescendantsByTagName(popup, "iframe"); | |
if (iframes.length > 0) { | |
setTimeout("eXo.webui.WCMUIPopupWindow.show('" + popupId + "'," + isShowMask + ")", 500, top, left); | |
} else { | |
this.show(popup, isShowMask, 500, top, left); | |
} | |
} | |
}; | |
WCMUIPopupWindow.prototype.showMask = function (popup, isShowPopup) { | |
var mask = popup.previousSibling; | |
if (mask && mask.className != "MaskLayer") { | |
mask = null; | |
} | |
if (isShowPopup) { | |
if (eXo.core.DOMUtil.findAncestorByClass(popup, "PORTLET-FRAGMENT") == null) { | |
if (!mask) eXo.core.UIMaskLayer.createMask(popup.parentNode, popup, 1); | |
} else { | |
if (!mask) eXo.core.UIMaskLayer.createMaskForFrame(popup.parentNode, popup, 1); | |
} | |
} else { | |
if (mask) eXo.core.UIMaskLayer.removeMask(mask); | |
} | |
}; | |
WCMUIPopupWindow.prototype.show = function (popup, isShowMask, middleBrowser, top, left) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (typeof (popup) == "string") popup = document.getElementById(popup); | |
var portalApp = document.getElementById("UIPortalApplication"); | |
var maskLayer = DOMUtil.findFirstDescendantByClass(portalApp, "div", "UIMaskWorkspace"); | |
var zIndex = 0; | |
var currZIndex = 0; | |
if (maskLayer != null) { | |
currZIndex = DOMUtil.getStyle(maskLayer, "zIndex"); | |
if (!isNaN(currZIndex) && currZIndex > zIndex) zIndex = currZIndex; | |
} | |
var popupWindows = DOMUtil.findDescendantsByClass(portalApp, "div", "WCMUIPopupWindow"); | |
var len = popupWindows.length; | |
for (var i = 0; i < len; i++) { | |
currZIndex = DOMUtil.getStyle(popupWindows[i], "zIndex"); | |
if (!isNaN(currZIndex) && currZIndex > zIndex) zIndex = currZIndex; | |
} | |
if (zIndex == 0) zIndex = 2000; | |
if (isShowMask) eXo.webui.WCMUIPopupWindow.showMask(popup, true); | |
popup.style.visibility = "hidden"; | |
this.superClass.show(popup); | |
if (top > -1 && left > -1) { | |
var pageWidth = 0; | |
var wsElement = document.getElementById('UIWorkingWorkspace'); | |
if (wsElement) pageWidth = wsElement.clientWidth; | |
if (screen.width - pageWidth <= 325) left = left - (screen.width - pageWidth); | |
else left = left - (screen.width - pageWidth) / 2; | |
popup.style.top = top + 10 + "px"; | |
var deltaX = screen.width - left; | |
if (deltaX < 325) { | |
left = left - (325 - deltaX) - 70; | |
} | |
popup.style.left = left + "px"; | |
popup.style.position = "fixed"; | |
} else { | |
var offsetParent = popup.offsetParent; | |
var scrollY = 0; | |
if (window.pageYOffset != undefined) scrollY = window.pageYOffset; | |
else if (document.documentElement && document.documentElement.scrollTop) scrollY = document.documentElement.scrollTop; | |
else scrollY = document.body.scrollTop; | |
if (offsetParent) { | |
var middleWindow = (eXo.core.DOMUtil.hasClass(offsetParent, "WCMUIPopupWindow") || eXo.core.DOMUtil.hasClass(offsetParent, "UIWindow")); | |
if (middleWindow) { | |
popup.style.top = Math.ceil((offsetParent.offsetHeight - popup.offsetHeight) / 2) + "px"; | |
} | |
if (middleBrowser || !middleWindow) { | |
popup.style.top = Math.ceil((eXo.core.Browser.getBrowserHeight() - popup.offsetHeight) / 2) + scrollY + "px"; | |
} | |
if (eXo.core.DOMUtil.hasClass(offsetParent, "UIMaskWorkspace")) { | |
popup.style.top = Math.ceil((offsetParent.offsetHeight - popup.offsetHeight) / 2) + "px"; | |
} | |
var checkHeight = popup.offsetHeight > 300; | |
if (document.getElementById("UIDockBar") && checkHeight) { | |
popup.style.top = "6px"; | |
} | |
if (eXo.core.I18n.lt) popup.style.left = Math.ceil((offsetParent.offsetWidth - popup.offsetWidth) / 2) + "px"; | |
else popup.style.right = Math.ceil((offsetParent.offsetWidth - popup.offsetWidth) / 2) + "px"; | |
} | |
if (eXo.core.Browser.findPosY(popup) < 0) popup.style.top = scrollY + "px"; | |
} | |
popup.style.visibility = "visible"; | |
}; | |
WCMUIPopupWindow.prototype.increasezIndex = function (popup) { | |
var DOMUtil = eXo.core.DOMUtil; | |
if (typeof (popup) == "string") popup = document.getElementById(popup); | |
var portalApp = document.getElementById("UIPortalApplication"); | |
var uiLogin = DOMUtil.findFirstDescendantByClass(portalApp, "div", "UILoginForm"); | |
if (uiLogin) { | |
var curMaskzIndex = parseInt(DOMUtil.getStyle(document.getElementById('UIMaskWorkspace'), "zIndex")); | |
popup.style.zIndex = ++curMaskzIndex + ""; | |
} | |
} | |
WCMUIPopupWindow.prototype.closePopupEvt = function (evt) { | |
eXo.core.DOMUtil.findAncestorByClass(this, "UIDragObject").style.display = "none"; | |
} | |
WCMUIPopupWindow.prototype.startResizeEvt = function (evt) { | |
eXo.webui.WCMUIPopupWindow.popupId = eXo.core.DOMUtil.findAncestorByClass(this, "WCMUIPopupWindow").id; | |
document.onmousemove = eXo.webui.WCMUIPopupWindow.resize; | |
document.onmouseup = eXo.webui.WCMUIPopupWindow.endResizeEvt; | |
} | |
var POPUP_WINDOW_BOTTOM_HEIGHT = 50; | |
WCMUIPopupWindow.prototype.resize = function (evt) { | |
var targetPopup = document.getElementById(eXo.webui.WCMUIPopupWindow.popupId); | |
var content = eXo.core.DOMUtil.findFirstDescendantByClass(targetPopup, "div", "PopupContent"); | |
var isRTL = eXo.core.I18n.isRT(); | |
var pointerX = eXo.core.Browser.findMouseRelativeX(targetPopup, evt, isRTL); | |
var pointerY = eXo.core.Browser.findMouseRelativeY(targetPopup, evt); | |
var delta = eXo.core.Browser.findPosYInContainer(content, targetPopup) + content.style.borderWidth + content.style.padding + content.style.margin; | |
if ((pointerY - delta) > 0) content.style.height = (pointerY - delta - POPUP_WINDOW_BOTTOM_HEIGHT) + "px"; | |
targetPopup.style.height = "auto"; | |
if (isRTL) { | |
pointerX = (-1) * pointerX | |
} | |
if (pointerX > 200) targetPopup.style.width = (pointerX + 5) + "px"; | |
}; | |
WCMUIPopupWindow.prototype.endResizeEvt = function (evt) { | |
delete eXo.webui.WCMUIPopupWindow.popupId; | |
this.onmousemove = null; | |
this.onmouseup = null; | |
eXo.portal.UIPortalControl.initAllManagers(); | |
} | |
WCMUIPopupWindow.prototype.initDND = function (evt) { | |
var DragDrop = eXo.core.DragDrop; | |
var DOMUtil = eXo.core.DOMUtil; | |
DragDrop.initCallback = function (dndEvent) { | |
var dragObject = dndEvent.dragObject; | |
dragObject.uiWindowContent = DOMUtil.findFirstDescendantByClass(dragObject, "div", "PopupContent"); | |
if (!dragObject.uiWindowContent) return; | |
if (eXo.core.Browser.browserType == "mozilla") { | |
dragObject.uiWindowContent.style.overflow = "hidden"; | |
var elements = eXo.core.DOMUtil.findDescendantsByClass(dragObject.uiWindowContent, "div", "PopupMessageBox"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.overflow = "hidden"; | |
} | |
} | |
} | |
DragDrop.dragCallback = function (dndEvent) {} | |
DragDrop.dropCallback = function (dndEvent) { | |
var dragObject = dndEvent.dragObject; | |
if (eXo.core.Browser.browserType == "mozilla" && dragObject.uiWindowContent) { | |
dragObject.uiWindowContent.style.overflow = "auto"; | |
var elements = eXo.core.DOMUtil.findDescendantsByClass(dragObject.uiWindowContent, "div", "PopupMessageBox"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.overflow = "auto"; | |
} | |
} | |
var offsetParent = dragObject.offsetParent; | |
if (offsetParent) { | |
if (eXo.core.Browser.findPosY(dragObject) < 0) dragObject.style.top = (0 - offsetParent.offsetTop) + "px"; | |
} else { | |
dragObject.style.top = "0px"; | |
} | |
} | |
var clickBlock = this; | |
var dragBlock = eXo.core.DOMUtil.findAncestorByClass(this, "UIDragObject"); | |
DragDrop.init(null, clickBlock, dragBlock, evt); | |
}; | |
eXo.webui.WCMUIPopupWindow = new WCMUIPopupWindow(); | |
function WCMUtils() { | |
var DOM = eXo.core.DOMUtil; | |
} | |
WCMUtils.prototype.getHostName = function () { | |
var parentLocation = window.parent.location; | |
return parentLocation.href.substring(0, parentLocation.href.indexOf(parentLocation.pathname)); | |
}; | |
WCMUtils.prototype.request = function (url) { | |
var xmlHttpRequest = false; | |
if (window.XMLHttpRequest) { | |
xmlHttpRequest = new window.XMLHttpRequest(); | |
xmlHttpRequest.open("GET", url, false); | |
xmlHttpRequest.send(""); | |
return xmlHttpRequest.responseXML; | |
} else if (ActiveXObject("Microsoft.XMLDOM")) { | |
xmlHttpRequest = new ActiveXObject("Microsoft.XMLDOM"); | |
xmlHttpRequest.async = false; | |
xmlHttpRequest.load(urlRequestXML); | |
return xmlHttpRequest; | |
} | |
return null; | |
}; | |
WCMUtils.prototype.getCurrentNodes = function (navigations, selectedNodeUri) { | |
var currentNodes = new Array(); | |
var currentNodeUris = new Array(); | |
currentNodeUris = selectedNodeUri.split("/"); | |
for (var i in navigations) { | |
for (var j in navigations[i].nodes) { | |
if (navigations[i].nodes[j].name == currentNodeUris[0]) { | |
currentNodes[0] = navigations[i].nodes[j]; | |
break; | |
} | |
} | |
} | |
var parent = currentNodes[0]; | |
for (var k = 1; k < currentNodeUris.length; k++) { | |
if (parent.children == 'null') { | |
break; | |
} | |
for (var n in parent.children) { | |
var node = parent.children[n]; | |
if (currentNodeUris[k] == node.name) { | |
currentNodes[k] = node; | |
parent = node; | |
break; | |
} | |
} | |
} | |
return currentNodes; | |
}; | |
WCMUtils.prototype.getRestContext = function () { | |
return eXo.env.portal.context + "/" + eXo.env.portal.rest; | |
}; | |
WCMUtils.prototype.openPrintPreview = function (urlToOpen) { | |
if (urlToOpen.indexOf("?") == -1) { | |
return urlToOpen + '?isPrint=true'; | |
} else { | |
return urlToOpen + '&isPrint=true'; | |
} | |
}; | |
WCMUtils.prototype.showInContextHelp = function (id, isIn) { | |
var parentElm = document.getElementById(id); | |
var popupHelp = document.getElementById(id + "ID"); | |
var inContextContentHelp = eXo.core.DOMUtil.findFirstDescendantByClass(parentElm, "div", "InContextHelpContent"); | |
var wTmp = 1; | |
if (inContextContentHelp) { | |
if (isIn == "true") { | |
inContextContentHelp.style.display = "block"; | |
var inContextHelpPopup = eXo.core.DOMUtil.findFirstDescendantByClass(inContextContentHelp, "div", "InContextHelpPopup"); | |
var contentHelp = eXo.core.DOMUtil.findFirstDescendantByClass(popupHelp, "div", "InContextHelpContentData"); | |
var contentPosition = eXo.core.DOMUtil.findFirstDescendantByClass(inContextContentHelp, "div", "ContentPosition"); | |
var l = String(contentHelp.innerHTML).length; | |
if (l < 100) { | |
contentHelp.style.width = (20 + l * 4) + "px" | |
inContextContentHelp.style.width = (20 + l * 4 + 54) + "px" | |
wTmp = (20 + l * 4 + 54); | |
contentPosition.style.height = "auto"; | |
} else { | |
contentHelp.style.width = "400px" | |
inContextContentHelp.style.width = "454px" | |
wTmp = 454; | |
contentPosition.style.height = (contentHelp.offsetHeight - 26) + "px"; | |
} | |
inContextContentHelp.style.left = "-" + (wTmp) + "px"; | |
popupHelp.className = "LeftInContextHelpPopup"; | |
var accumulateLeft = 0; | |
var parentObj = inContextContentHelp; | |
do { | |
accumulateLeft = accumulateLeft + parentObj.offsetLeft; | |
parentObj = parentObj.offsetParent; | |
} while (parentObj); | |
if (accumulateLeft < 0) { | |
inContextContentHelp.style.left = "12px"; | |
popupHelp.className = "RightInContextHelpPopup"; | |
} | |
} else { | |
inContextContentHelp.style.display = "none"; | |
} | |
} | |
}; | |
WCMUtils.prototype.showHideComponent = function (elemtClicked) { | |
var nodeReference = eXo.core.DOMUtil.findAncestorByClass(elemtClicked, "ShowHideContainer"); | |
var elemt = eXo.core.DOMUtil.findFirstDescendantByClass(nodeReference, "div", "ShowHideComponent"); | |
if (elemt.style.display == 'none') { | |
elemtClicked.childNodes[0].style.display = 'none'; | |
elemtClicked.childNodes[1].style.display = 'block'; | |
elemt.style.display = 'block'; | |
eXo.ecm.WCMUtils.setScrollBar(); | |
} else { | |
elemtClicked.childNodes[0].style.display = 'block'; | |
elemtClicked.childNodes[1].style.display = 'none'; | |
elemt.style.display = 'none'; | |
} | |
}; | |
WCMUtils.prototype.setScrollBar = function () { | |
try { | |
var elementWorkingArea = document.getElementById('UIWorkingArea'); | |
var parent = document.getElementById('TabContainerParent'); | |
if (parent != null) { | |
var elements = eXo.core.DOMUtil.findDescendantsByClass(parent, "div", "UITabContent"); | |
if (elements != null) { | |
for (i = 0; i < elements.length; i++) { | |
var obj = elements[i]; | |
if (obj.style.display != "none") { | |
var height = obj.offsetHeight; | |
if (height > 430) { | |
obj.style.height = elementWorkingArea.offsetHeight - 50 + "px"; | |
obj.style.overflow = "auto"; | |
} | |
} | |
} | |
} | |
} | |
} catch (err) {} | |
}; | |
WCMUtils.prototype.hideContextMenu = function (menuItemElem) { | |
var contextMenu = eXo.core.DOMUtil.findAncestorByClass(menuItemElem, "UIRightClickPopupMenu"); | |
contextMenu.style.display = "none"; | |
} | |
WCMUtils.prototype.changePriorityCss = function () { | |
priorityField = document.getElementById("priority"); | |
if (priorityField != null) { | |
if (isNaN(priorityField.value)) { | |
priorityField.className = "Tip"; | |
} | |
priorityField.onclick = function () { | |
priorityField.className = "SeoPriority"; | |
if (isNaN(priorityField.value)) priorityField.value = ""; | |
}; | |
} | |
} | |
WCMUtils.prototype.addParamIntoAjaxEventRequest = function (eventReq, extParam) { | |
return eventReq.substring(0, eventReq.length - 2) + extParam + "\')"; | |
} | |
WCMUtils.prototype.searchNodeTypeOnKeyPress = function () { | |
var element = document.getElementById("NodeTypeText"); | |
if (element == null) return false; | |
element.onkeypress = function (event) { | |
var keynum = false; | |
if (window.event) { | |
keynum = window.event.keyCode; | |
event = window.event; | |
} else if (event.which) { | |
keynum = event.which; | |
} | |
if (keynum == 0) { | |
keynum = event.keyCode; | |
} | |
if (keynum == 13) { | |
var divUINodeTypeSearch = eXo.core.DOMUtil.findAncestorByClass(this, "UINodeTypeSearh"); | |
var tdButtonCell = eXo.core.DOMUtil.findFirstDescendantByClass(divUINodeTypeSearch, "td", "ButtonCell"); | |
var btnSearch = eXo.core.DOMUtil.findDescendantsByTagName(tdButtonCell, "a")[0]; | |
eval(btnSearch.getAttribute("href")); | |
return false; | |
} | |
} | |
} | |
eXo.ecm.WCMUtils = new WCMUtils(); | |
function NewsletterManager() {} | |
NewsletterManager.prototype.checkAllSelected = function (checkBox) { | |
var elements = checkBox.form.elements; | |
var checked = checkBox.checked; | |
for (i = 0; i < elements.length; i++) { | |
if (elements[i].type == "checkbox") elements[i].checked = checked; | |
} | |
}; | |
NewsletterManager.prototype.checkBeforeDelete = function (uiSubscriptionsForm, checkMess, confirmMess) { | |
var isChecked = false; | |
var elements = document.getElementById(uiSubscriptionsForm).elements; | |
for (var i = 0; i < elements.length; i++) { | |
if (elements[i].type == "checkbox" && elements[i].checked == true) isChecked = true; | |
} | |
if (isChecked == false) { | |
alert(checkMess); | |
return false; | |
} | |
return confirm(confirmMess); | |
} | |
NewsletterManager.prototype.hide = function () { | |
var ln = eXo.core.DOMUtil.hideElementList.length; | |
if (ln > 0) { | |
for (var i = 0; i < ln; i++) { | |
eXo.core.DOMUtil.hideElementList[i].style.display = "none"; | |
} | |
} | |
}; | |
NewsletterManager.prototype.show = function (obj, evt) { | |
if (!evt) evt = window.event; | |
evt.cancelBubble = true; | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiPopupCategory = DOMUtil.findFirstDescendantByClass(obj, 'div', 'UIPopupCategory'); | |
if (!uiPopupCategory) return; | |
if (uiPopupCategory.style.display == "none") { | |
eXo.ecm.NewsletterManager.hide(); | |
if (eXo.core.Browser.isIE7()) { | |
uiPopupCategory.style.left = "-176px"; | |
uiPopupCategory.style.top = "16px"; | |
uiPopupCategory.style.display = "block"; | |
} else { | |
uiPopupCategory.style.display = "block"; | |
} | |
eXo.core.DOMUtil.listHideElements(uiPopupCategory); | |
} else uiPopupCategory.style.display = "none"; | |
} | |
eXo.ecm.NewsletterManager = new NewsletterManager(); | |
function UIFormGeneratorPortlet() {} | |
UIFormGeneratorPortlet.prototype.init = function () { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uiTabContentContainer = document.getElementById('UITabContentContainer'); | |
var uiTabContent = DOMUtil.findFirstDescendantByClass(uiTabContentContainer, 'div', 'UITabContent'); | |
var menuitems = DOMUtil.findDescendantsByClass(uiTabContent, 'div', 'LeftMenu'); | |
for (var i = 0; i < menuitems.length; i++) { | |
menuitems[i].onclick = function () { | |
eXo.ecm.UIFormGeneratorPortlet.renderComponent(this.getAttribute('elementType')); | |
} | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.renderComponent = function (typeComp) { | |
var formGenerator = ""; | |
var fieldComponent = ""; | |
var advancedOption = ""; | |
var multivalue = false; | |
switch (typeComp) { | |
case "label": | |
fieldComponent += "<td class='FieldLabel' value='Label'>Label</td>"; | |
fieldComponent += "<td class='FieldComponent'></td>"; | |
break; | |
case "input": | |
fieldComponent += "<td class='FieldLabel' value='Input Text'>Input field</td>"; | |
fieldComponent += "<td class='FieldComponent'><input type='text' class='InputText' value=''/></td>"; | |
break; | |
case "textarea": | |
fieldComponent += "<td class='FieldLabel' value='Textarea'>Textarea field</td>"; | |
fieldComponent += "<td class='FieldComponent'><textarea class='Textarea'>Textarea value</textarea></td>"; | |
break; | |
case "wysiwyg": | |
if (!eXo.ecm.UIFormGeneratorPortlet.countFCK) eXo.ecm.UIFormGeneratorPortlet.countFCK = 1; | |
fieldComponent += "<td class='FieldLabel' value='WYSIWYG'>WYSIWYG field</td>"; | |
fieldComponent += "<td class='FieldComponent'><textarea class='Textarea' id='RichTextEditorContent_" + eXo.ecm.UIFormGeneratorPortlet.countFCK + "'>WYSIWYG value</textarea></td>"; | |
advancedOption += "<tr>"; | |
advancedOption += "<td class='FieldLabel'>Advance Options</td>"; | |
advancedOption += "<td class='FileComponent'>"; | |
advancedOption += "Toolbar: <select class='SelectBox'><option value='toolbar:SuperBasicWCM'>SuperBasicWCM</option><option value='toolbar:BasicWCM'>BasicWCM</option><option value='toolbar:CompleteWCM'>CompleteWCM</option><option value='toolbar:Basic'>Basic</option></select>"; | |
advancedOption += "</td>"; | |
advancedOption += "</tr>"; | |
break; | |
case "select": | |
fieldComponent += "<td class='FieldLabel' value='Select'>Select field</td>"; | |
fieldComponent += "<td class='FieldComponent'><select class='SelectBox'><option idx='1' value='option1'>Option 1</option></select></td>"; | |
multivalue = true; | |
break; | |
case "checkbox": | |
fieldComponent += "<td class='FieldLabel' value='Checkbox'>Checkbox field</td>"; | |
fieldComponent += "<td class='FieldComponent'><div class='CheckboxButton'><input type='checkbox' class='CheckBox' value='checkbox1'/><span style='padding : 0 5px 0 19px; display:block; line-height:12px'>Checkbox 1</span><div style='clear:left'></div></div></td>"; | |
break; | |
case "radio": | |
fieldComponent += "<td class='FieldLabel' value='Radio'>Radio field</td>"; | |
fieldComponent += "<td class='FieldComponent'><div class='RadioButton' idx='1'><input type='radio' name='group1' class='Radio' value='radio1'/><span style='padding : 0 5px 0 19px; display:block; line-height:12px'>Radio 1</span><div style='clear:left'></div></div></td>"; | |
multivalue = true; | |
break; | |
case "datetime": | |
fieldComponent += "<td class='FieldLabel' value='DateTime'>Datetime field</td>"; | |
fieldComponent += "<td class='FieldComponent'><input type='text' class='InputText' value='Datetime value'/></td>"; | |
advancedOption += "<tr>"; | |
advancedOption += "<td class='FieldLabel'>Advance Options</td>"; | |
advancedOption += "<td class='FileComponent'>"; | |
advancedOption += "Format: <select><option>dd/mm/yyyy</option><option>dd-mm-yyyy</option></select>"; | |
advancedOption += "</td>"; | |
advancedOption += "</tr>"; | |
break; | |
case "upload": | |
fieldComponent += "<td class='FieldLabel' value='Upload'>Upload field</td>"; | |
fieldComponent += "<td class='FieldComponent'><input type='file' class='Upload' disabled='disabled'/><img src='/eXoResources/skin/sharedImages/Blank.gif' alt='' class='UploadButton'/></td>"; | |
break; | |
} | |
formGenerator += "<div class='TopContentBoxStyle'>"; | |
formGenerator += "<div class='UIForm UIFormEditBox'>"; | |
formGenerator += "<div class='HorizontalLayout'>"; | |
formGenerator += "<div class='FormContainer'>"; | |
formGenerator += "<table class='UIFormGrid'>"; | |
formGenerator += "<tr>"; | |
formGenerator += fieldComponent; | |
formGenerator += "<td class='FieldIcon'>"; | |
formGenerator += "<div class='EditBox'>"; | |
formGenerator += "<a class='ControlIcon DeleteIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.removeComponent(this);' title='Click here to remove this component'><span></span></a>"; | |
formGenerator += "<a class='ControlIcon EditIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.showEditBox(this);' title='Click here to edit property'><span></span></a>"; | |
formGenerator += "</div>"; | |
formGenerator += "<a class='ControlIcon DownIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.moveDownElement(this);' title='Move down component'><span></span></a>"; | |
formGenerator += "<a class='ControlIcon UpIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.moveUpElement(this);' title='Move up component'><span></span></a>"; | |
formGenerator += "<div class='ClearRight'><span></span></div>"; | |
formGenerator += "</td>"; | |
formGenerator += "</tr>"; | |
formGenerator += "</table>"; | |
formGenerator += "</div>"; | |
formGenerator += "</div>"; | |
formGenerator += "</div>"; | |
formGenerator += "</div>"; | |
formGenerator += "<div class='MiddleContentBoxStyle' style='display:none'>"; | |
formGenerator += "<div class='UIForm UIFormEditBox'>"; | |
formGenerator += "<div class='HorizontalLayout'>"; | |
formGenerator += "<div class='FormContainer'>"; | |
formGenerator += "<table class='UIFormGrid'>"; | |
formGenerator += "<tr>"; | |
formGenerator += "<td class='FieldLabel'>Field Label</td>"; | |
formGenerator += "<td class='FieldComponent'>"; | |
formGenerator += "<input type='text' class='InputText' onkeyup='eXo.ecm.UIFormGeneratorPortlet.updateLabel(this);'/>"; | |
formGenerator += "</td>"; | |
formGenerator += "</tr>"; | |
formGenerator += "<tr>"; | |
formGenerator += "<td class='FieldLabel'>Width</td>"; | |
formGenerator += "<td class='FieldComponent'>"; | |
formGenerator += "<input type='number' value='' class='InputText' style='width: 50%; float:left;' onkeyup='eXo.ecm.UIFormGeneratorPortlet.updateWidth(this);' />"; | |
formGenerator += "<div class='BoxRules'>"; | |
formGenerator += "Rules: <input class='Requied' type='checkbox' onchange='eXo.ecm.UIFormGeneratorPortlet.updateRequired(this);'>Required</input>"; | |
formGenerator += "</div>"; | |
formGenerator += "</td>"; | |
formGenerator += "<td class='FieldIcon'><span></span></td>"; | |
formGenerator += "</tr>"; | |
formGenerator += "<tr>"; | |
formGenerator += "<td class='FieldLabel'>Height</td>"; | |
formGenerator += "<td class='FieldComponent' style='padding:0px;'>"; | |
formGenerator += "<input type='number' value='' class='InputText' style='width: 50%; float:left;' onkeyup='eXo.ecm.UIFormGeneratorPortlet.updateHeight(this);' />"; | |
formGenerator += "</td>"; | |
formGenerator += "<td class='FieldIcon'><span></span></td>"; | |
formGenerator += "</tr>"; | |
formGenerator += "<tr>"; | |
formGenerator += "<td class='FieldLabel'>Default Value</td>"; | |
formGenerator += "<td class='FieldComponent' >"; | |
formGenerator += "<div class='DivIcon' idx='1'>"; | |
formGenerator += "<input type='text' class='InputText' onkeyup='eXo.ecm.UIFormGeneratorPortlet.updateValue(event);' idx='1'/ style=\"float:left;width:90%\">"; | |
if (multivalue) { | |
formGenerator += "<a class='AddIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.addOption(this);'><span></span></a>"; | |
formGenerator += "<a class='RemoveIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.removeOption(this);'><span></span></a>"; | |
} else { | |
formGenerator += "<span></span>"; | |
} | |
formGenerator += "<div style='clear:left;'><span></span></div>"; | |
formGenerator += "</div>"; | |
formGenerator += "</td>"; | |
formGenerator += "</tr>"; | |
formGenerator += advancedOption | |
formGenerator += "<tr>"; | |
formGenerator += "<td class='FieldLabel'>Guidelines for User</td>"; | |
formGenerator += "<td class='FieldComponent'><textarea class='Textarea' onkeyup='eXo.ecm.UIFormGeneratorPortlet.updateGuide(this);'></textarea></td>"; | |
formGenerator += "<td class='FieldIcon'><span></span></td>"; | |
formGenerator += "</tr>"; | |
formGenerator += "</table>"; | |
formGenerator += "</div>"; | |
formGenerator += "</div>"; | |
formGenerator += "</div>"; | |
formGenerator += "</div>"; | |
var node = document.createElement('div'); | |
node.innerHTML = formGenerator; | |
node.className = 'BoxContentBoxStyle'; | |
node.setAttribute('typeComponent', typeComp); | |
document.getElementById('MiddleCenterViewBoxStyle').appendChild(node); | |
if (typeComp == 'wysiwyg' && !CKEDITOR.instances['RichTextEditorContent']) { | |
var idEditor = 'RichTextEditorContent_' + eXo.ecm.UIFormGeneratorPortlet.countFCK; | |
CKEDITOR.replace(idEditor, { | |
toolbar: 'BasicWCM' | |
}); | |
} | |
eXo.ecm.UIFormGeneratorPortlet.countFCK++; | |
}; | |
UIFormGeneratorPortlet.prototype.showEditBox = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parentNode = DOMUtil.findAncestorByClass(obj, "TopContentBoxStyle"); | |
var boxContent = DOMUtil.findNextElementByTagName(parentNode, "div"); | |
if (boxContent && boxContent.style.display != 'block') { | |
boxContent.style.display = 'block'; | |
} else { | |
boxContent.style.display = 'none'; | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.removeComponent = function (obj) { | |
var parentNode = eXo.core.DOMUtil.findAncestorByClass(obj, "BoxContentBoxStyle"); | |
if (parentNode) { | |
var confirmDelete = confirm("Are you sure to remove?"); | |
if (confirmDelete == true) { | |
document.getElementById('MiddleCenterViewBoxStyle').removeChild(parentNode); | |
} else { | |
return; | |
} | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.moveDownElement = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parentNode = DOMUtil.findAncestorByClass(obj, "BoxContentBoxStyle"); | |
var middContainer = document.getElementById('MiddleCenterViewBoxStyle'); | |
if (!middContainer || !parentNode) return; | |
var tmpNode = ''; | |
nextElt = DOMUtil.findNextElementByTagName(parentNode, 'div'); | |
if (nextElt) { | |
tmpNode = nextElt.cloneNode(true); | |
middContainer.removeChild(nextElt); | |
middContainer.insertBefore(tmpNode, parentNode); | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.moveUpElement = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parentNode = DOMUtil.findAncestorByClass(obj, "BoxContentBoxStyle"); | |
var middContainer = document.getElementById('MiddleCenterViewBoxStyle'); | |
if (!middContainer || !parentNode) return; | |
previousElt = DOMUtil.findPreviousElementByTagName(parentNode, 'div'); | |
if (!previousElt) return; | |
var tmpNode = parentNode.cloneNode(true); | |
middContainer.removeChild(parentNode); | |
middContainer.insertBefore(parentNode, previousElt); | |
}; | |
UIFormGeneratorPortlet.prototype.updateLabel = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parentNode = DOMUtil.findAncestorByClass(obj, 'BoxContentBoxStyle'); | |
var labelNode = DOMUtil.findFirstDescendantByClass(parentNode, 'td', 'FieldLabel'); | |
labelNode.innerHTML = obj.value; | |
}; | |
UIFormGeneratorPortlet.prototype.updateWidth = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var width = ''; | |
if (obj.value == '') { | |
width = null; | |
} else if (isNaN(parseFloat(obj.value))) { | |
alert('Number only'); | |
obj.value = ''; | |
return false; | |
} else { | |
width = obj.value + 'px'; | |
} | |
var parentNode = DOMUtil.findAncestorByClass(obj, 'BoxContentBoxStyle'); | |
var containerNode = DOMUtil.findFirstDescendantByClass(parentNode, 'div', 'TopContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(containerNode, 'td', 'FieldComponent'); | |
if (componentNode) { | |
var inputNode = componentNode.childNodes[0]; | |
if (inputNode) inputNode.style.width = width; | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.updateHeight = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var height = ''; | |
if (obj.value == '') { | |
height = null; | |
} else if (isNaN(parseFloat(obj.value))) { | |
alert('Number only'); | |
obj.value = ''; | |
return false; | |
} else { | |
height = obj.value + 'px'; | |
} | |
var parentNode = DOMUtil.findAncestorByClass(obj, 'BoxContentBoxStyle'); | |
var containerNode = DOMUtil.findFirstDescendantByClass(parentNode, 'div', 'TopContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(containerNode, 'td', 'FieldComponent'); | |
if (componentNode) { | |
var inputNode = componentNode.childNodes[0]; | |
if (inputNode) inputNode.style.height = height; | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.updateRequired = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var parentNode = DOMUtil.findAncestorByClass(obj, 'BoxContentBoxStyle'); | |
var containerNode = DOMUtil.findFirstDescendantByClass(parentNode, 'div', 'TopContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(containerNode, 'td', 'FieldComponent'); | |
var labelNode = DOMUtil.findFirstDescendantByClass(containerNode, 'td', 'FieldLabel'); | |
if (!componentNode) return false; | |
if (obj.checked) { | |
labelNode.setAttribute('mandatory', 'true'); | |
} else { | |
labelNode.setAttribute('mandatory', 'false'); | |
} | |
var requiredNode = DOMUtil.getChildrenByTagName(componentNode, 'span')[0]; | |
if (!requiredNode) { | |
requiredNode = document.createElement('span'); | |
requiredNode.style.color = 'red'; | |
requiredNode.innerHTML = ' *'; | |
componentNode.appendChild(requiredNode); | |
} else { | |
componentNode.removeChild(requiredNode); | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.updateValue = function (evt) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var srcEle = eXo.core.Browser.getEventSource(evt); | |
if (!srcEle) return; | |
var root = DOMUtil.findAncestorByClass(srcEle, 'BoxContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(root, 'div', 'TopContentBoxStyle'); | |
var eltName = DOMUtil.findFirstDescendantByClass(componentNode, 'td', 'FieldLabel').getAttribute('value'); | |
var srcIndex = parseInt(srcEle.getAttribute("idx")) - 1; | |
if (!eltName) return; | |
switch (eltName) { | |
case "Label": | |
var labelNode = DOMUtil.findFirstDescendantByClass(componentNode, 'td', 'FieldComponent'); | |
labelNode.innerHTML = srcEle.value; | |
break; | |
case "Input Text": | |
var inputNode = DOMUtil.findFirstDescendantByClass(componentNode, 'input', 'InputText'); | |
inputNode.value = srcEle.value; | |
break; | |
case "Select": | |
var selectNode = DOMUtil.findFirstDescendantByClass(componentNode, 'select', 'SelectBox'); | |
var fieldNode = DOMUtil.findAncestorByClass(srcEle, 'FieldComponent'); | |
var inputNodes = DOMUtil.getChildrenByTagName(fieldNode, 'input'); | |
if (selectNode.options.length > srcIndex) { | |
selectNode.options[srcIndex].value = srcEle.value; | |
selectNode.options[srcIndex].innerHTML = srcEle.value; | |
} | |
break; | |
case "Textarea": | |
var textarea = DOMUtil.findFirstDescendantByClass(componentNode, 'textarea', 'Textarea'); | |
textarea.value = srcEle.value; | |
break | |
case "WYSIWYG": | |
var eltComp = DOMUtil.findFirstDescendantByClass(componentNode, 'td', 'FieldComponent'); | |
var txtArea = DOMUtil.findFirstChildByClass(eltComp, "textarea", "Textarea"); | |
var iEditor = txtArea.id; | |
var editor = eval('CKEDITOR.instances.' + iEditor); | |
editor.setText(srcEle.value); | |
break; | |
case "upload": | |
break; | |
case "Radio": | |
var fieldComponent = DOMUtil.findFirstDescendantByClass(componentNode, "td", "FieldComponent"); | |
var radioNodes = DOMUtil.findDescendantsByClass(fieldComponent, 'div', 'RadioButton'); | |
var fieldNode = DOMUtil.findAncestorByClass(srcEle, 'FieldComponent'); | |
var inputList = DOMUtil.findDescendantsByClass(fieldNode, 'input', 'InputText'); | |
for (var i = 0; i < inputList.length; i++) { | |
if (inputList[i] == srcEle) { | |
var radioInputNode = DOMUtil.findFirstDescendantByClass(radioNodes[i], 'input', 'Radio'); | |
if (srcEle.value.length > 0) radioInputNode.value = srcEle.value; | |
var radioTextNode = DOMUtil.findDescendantsByTagName(radioNodes[i], 'span')[0]; | |
if (srcEle.value.length > 0) radioTextNode.innerHTML = srcEle.value; | |
} | |
} | |
break; | |
case "Checkbox": | |
var fieldComponent = DOMUtil.findFirstDescendantByClass(componentNode, "td", "FieldComponent"); | |
var checkboxNodes = DOMUtil.findDescendantsByClass(fieldComponent, 'div', 'CheckboxButton'); | |
var fieldNode = DOMUtil.findAncestorByClass(srcEle, 'FieldComponent'); | |
var inputList = DOMUtil.findDescendantsByClass(fieldNode, 'input', 'InputText'); | |
for (var i = 0; i < inputList.length; i++) { | |
if (inputList[i] == srcEle) { | |
var chkInputNode = DOMUtil.findFirstDescendantByClass(checkboxNodes[i], 'input', 'CheckBox'); | |
chkInputNode.value = srcEle.value; | |
var chkTextNode = DOMUtil.findDescendantsByTagName(checkboxNodes[i], 'span')[0]; | |
chkTextNode.innerHTML = srcEle.value; | |
} | |
} | |
break; | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.updateGuide = function (objGuide) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var root = DOMUtil.findAncestorByClass(objGuide, 'BoxContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(root, 'div', 'TopContentBoxStyle'); | |
var fieldLabel = DOMUtil.findFirstDescendantByClass(componentNode, 'td', 'FieldLabel'); | |
fieldLabel.setAttribute("desc", objGuide.value); | |
}; | |
UIFormGeneratorPortlet.prototype.insertAfter = function (referenceNode, newNode) { | |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); | |
} | |
UIFormGeneratorPortlet.prototype.updateNodeIndex = function (elementNode, index) { | |
for (var i = parseInt(index); i < elementNode.length; i++) { | |
elementNode[i].setAttribute("idx", parseInt(i) + 1); | |
} | |
} | |
UIFormGeneratorPortlet.prototype.addOption = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var ancestorNode = DOMUtil.findAncestorByClass(obj, 'BoxContentBoxStyle'); | |
var containerNode = DOMUtil.findFirstDescendantByClass(ancestorNode, 'div', 'TopContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(containerNode, 'td', 'FieldComponent'); | |
var selectNode = DOMUtil.findFirstDescendantByClass(componentNode, 'select', 'SelectBox'); | |
var rowNode = DOMUtil.findAncestorByTagName(obj, 'tr'); | |
var brotherNode = DOMUtil.findFirstDescendantByClass(rowNode, 'td', 'FieldComponent'); | |
var brotherChildNodes = DOMUtil.findDescendantsByClass(brotherNode, 'input', 'InputText'); | |
var radioContainer = DOMUtil.findDescendantsByClass(containerNode, 'div', 'RadioButton'); | |
var upperIconNode = DOMUtil.findAncestorByClass(obj, 'DivIcon'); | |
var currentIndex = upperIconNode.getAttribute("idx"); | |
var index = parseInt(currentIndex) + 1; | |
var strRNode = "<input onkeyup=\"eXo.ecm.UIFormGeneratorPortlet.updateValue(event);\" type='text' class='InputText' idx='" + index + "'/ style=\"float:left;width:90%\">"; | |
strRNode += "<a class='AddIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.addOption(this);'><span></span></a>"; | |
strRNode += "<a class='RemoveIcon' onclick='eXo.ecm.UIFormGeneratorPortlet.removeOption(this);'><span></span></a>"; | |
strRNode += "<div style='clear:left;'><span></span></div>"; | |
var rNode = document.createElement('div'); | |
rNode.className = "DivIcon"; | |
rNode.setAttribute("idx", index); | |
rNode.innerHTML = strRNode; | |
eXo.ecm.UIFormGeneratorPortlet.insertAfter(upperIconNode, rNode); | |
var arrayInputTexts = DOMUtil.findDescendantsByClass(brotherNode, 'input', 'InputText'); | |
var arrayDivIcons = DOMUtil.findDescendantsByClass(brotherNode, 'div', 'DivIcon'); | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(arrayInputTexts, index); | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(arrayDivIcons, index); | |
switch (ancestorNode.getAttribute("typeComponent")) { | |
case "select": | |
var optionNode = document.createElement('option'); | |
optionNode.setAttribute("idx", index); | |
optionNode.value = "Option" + index; | |
optionNode.innerHTML = "Option" + index; | |
if (currentIndex <= selectNode.length) { | |
eXo.ecm.UIFormGeneratorPortlet.insertAfter(selectNode[currentIndex - 1], optionNode); | |
} | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(selectNode, index); | |
for (var i = 0; i < arrayInputTexts.length; i++) { | |
if (arrayInputTexts[i].value == "" || arrayInputTexts[i].value.length < 1) { | |
selectNode[i].value = "Option" + selectNode[i].getAttribute("idx"); | |
selectNode[i].text = "Option" + selectNode[i].getAttribute("idx"); | |
} | |
} | |
break; | |
case "radio": | |
var radioNode = document.createElement("div"); | |
radioNode.setAttribute("idx", index); | |
radioNode.innerHTML = '<input type="radio" name="group1" class="Radio" value="radio' + index + '" /><span style="padding : 0 5px 0 19px; display:block; line-height:12px">Radio ' + index + '</span><div style="clear:left"></div>'; | |
radioNode.className = "RadioButton"; | |
if (currentIndex <= radioContainer.length) { | |
eXo.ecm.UIFormGeneratorPortlet.insertAfter(radioContainer[currentIndex - 1], radioNode); | |
} | |
var rContainer = DOMUtil.findDescendantsByClass(containerNode, 'div', 'RadioButton'); | |
var arrInputTexts = DOMUtil.findDescendantsByClass(brotherNode, 'input', 'InputText'); | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(rContainer, index); | |
for (var i = 0; i < rContainer.length; i++) { | |
if (arrInputTexts[i].value == "" || arrInputTexts[i].value.length < 1) { | |
rContainer[i].firstChild.value = "radio" + rContainer[i].getAttribute("idx"); | |
rContainer[i].firstChild.nextSibling.innerHTML = "Radio " + rContainer[i].getAttribute("idx"); | |
} | |
} | |
break; | |
case "checkbox": | |
var checkboxNode = document.createElement("div"); | |
checkboxNode.innerHTML = '<input type="checkbox" class="CheckBox" value="checkbox' + index + '" /><span style="padding : 0 5px 0 19px; display:block; line-height:12px">Checkbox ' + index + '</span><div style="clear:left"></div>'; | |
checkboxNode.className = "CheckboxButton"; | |
componentNode.appendChild(checkboxNode); | |
break; | |
} | |
}; | |
UIFormGeneratorPortlet.prototype.removeOption = function (obj) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var ancestorNode = DOMUtil.findAncestorByClass(obj, 'BoxContentBoxStyle'); | |
var containerNode = DOMUtil.findFirstDescendantByClass(ancestorNode, 'div', 'TopContentBoxStyle'); | |
var componentNode = DOMUtil.findFirstDescendantByClass(containerNode, 'td', 'FieldComponent'); | |
var selectNode = DOMUtil.findFirstDescendantByClass(componentNode, 'select', 'SelectBox'); | |
var rowNode = DOMUtil.findAncestorByTagName(obj, 'tr'); | |
var brotherNode = DOMUtil.findFirstDescendantByClass(rowNode, 'td', 'FieldComponent'); | |
var radioContainer = DOMUtil.findDescendantsByClass(containerNode, 'div', 'RadioButton'); | |
var upperIconNode = DOMUtil.findAncestorByClass(obj, 'DivIcon'); | |
var brotherChildNodes = DOMUtil.findDescendantsByClass(brotherNode, 'div', 'DivIcon'); | |
var currentIndex = upperIconNode.getAttribute("idx"); | |
var index = parseInt(currentIndex) + 1; | |
for (var j = 0; j < brotherChildNodes.length; j++) { | |
if (brotherChildNodes[j].getAttribute("idx") == currentIndex) { | |
brotherChildNodes[j].parentNode.removeChild(brotherChildNodes[j]); | |
break; | |
} | |
} | |
switch (ancestorNode.getAttribute("typeComponent")) { | |
case "select": | |
if (selectNode.length > currentIndex - 1) { | |
selectNode[0].parentNode.removeChild(selectNode[currentIndex - 1]); | |
} | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(selectNode, 0); | |
var arrInputTexts = DOMUtil.findDescendantsByClass(brotherNode, 'input', 'InputText'); | |
for (var i = 0; i < arrInputTexts.length; i++) { | |
if (arrInputTexts[i].value == "" || arrInputTexts[i].value.length < 1) { | |
selectNode[i].value = "Option" + selectNode[i].getAttribute("idx"); | |
selectNode[i].text = "Option" + selectNode[i].getAttribute("idx"); | |
} | |
} | |
break; | |
case "radio": | |
if (radioContainer.length > currentIndex - 1) { | |
radioContainer[0].parentNode.removeChild(radioContainer[currentIndex - 1]); | |
} | |
var rContainer = DOMUtil.findDescendantsByClass(containerNode, 'div', 'RadioButton'); | |
var arrInputTexts = DOMUtil.findDescendantsByClass(brotherNode, 'input', 'InputText'); | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(rContainer, 0); | |
for (var i = 0; i < rContainer.length; i++) { | |
if (arrInputTexts[i].value == "" || arrInputTexts[i].value.length < 1) { | |
rContainer[i].firstChild.value = "Radio " + rContainer[i].getAttribute("idx"); | |
rContainer[i].firstChild.nextSibling.innerHTML = "Radio " + rContainer[i].getAttribute("idx"); | |
} | |
} | |
break; | |
} | |
var arrayInputTexts = DOMUtil.findDescendantsByClass(brotherNode, 'input', 'InputText'); | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(arrayInputTexts, 0); | |
var arrayDivIcons = DOMUtil.findDescendantsByClass(brotherNode, 'div', 'DivIcon'); | |
eXo.ecm.UIFormGeneratorPortlet.updateNodeIndex(arrayDivIcons, 0); | |
}; | |
UIFormGeneratorPortlet.prototype.getStringJsonObject = function () { | |
var DOMUtil = eXo.core.DOMUtil; | |
var root = document.getElementById('MiddleCenterViewBoxStyle'); | |
var boxsContent = DOMUtil.findDescendantsByClass(root, 'div', 'BoxContentBoxStyle'); | |
var strJsonObject = '{ "inputs" : ['; | |
for (var i = 0; i < boxsContent.length; i++) { | |
strJsonObject += eXo.ecm.UIFormGeneratorPortlet.getProperties(boxsContent[i]); | |
if (i != (boxsContent.length - 1)) { | |
strJsonObject += ','; | |
} | |
} | |
strJsonObject += "]}"; | |
return strJsonObject; | |
}; | |
UIFormGeneratorPortlet.prototype.getProperties = function (comp) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var strObject = '{'; | |
strObject += '"type":"' + comp.getAttribute("typeComponent") + '",'; | |
var topContent = DOMUtil.findFirstDescendantByClass(comp, 'div', 'TopContentBoxStyle'); | |
var fieldLabel = DOMUtil.findFirstDescendantByClass(topContent, 'td', 'FieldLabel'); | |
var defaultValue = fieldLabel.getAttribute('value'); | |
var nameComp = ''; | |
if (fieldLabel && fieldLabel.innerHTML != '') { | |
nameComp = fieldLabel.innerHTML; | |
} else { | |
nameComp = defaultValue; | |
} | |
strObject += '"name":"' + encodeURIComponent(nameComp) + '",'; | |
switch (comp.getAttribute("typeComponent")) { | |
case "input": | |
inputNode = DOMUtil.findFirstDescendantByClass(topContent, 'input', "InputText"); | |
var width = inputNode.offsetWidth; | |
var mandatory = fieldLabel.getAttribute('mandatory'); | |
var height = inputNode.offsetHeight; | |
strObject += '"value":"' + inputNode.value + '","width":' + width + ',"mandatory":' + mandatory + ',"height":' + height + ','; | |
break; | |
case "label": | |
var labelNode = DOMUtil.findFirstDescendantByClass(topContent, 'td', 'FieldComponent'); | |
strObject += '"value":"' + labelNode.innerHTML + '","width":0,"mandatory":' + mandatory + ',"height":0,'; | |
break; | |
case "textarea": | |
var textareaNode = DOMUtil.findFirstDescendantByClass(topContent, 'textarea', "Textarea"); | |
var width = textareaNode.offsetWidth; | |
var mandatory = fieldLabel.getAttribute('mandatory'); | |
var height = textareaNode.offsetHeight; | |
strObject += '"value":"' + textareaNode.value + '","width":' + width + ',"mandatory":' + mandatory + ',"height":' + height + ','; | |
break; | |
case "wysiwyg": | |
var midContent = DOMUtil.findNextElementByTagName(topContent, "div"); | |
var selectNode = DOMUtil.findFirstDescendantByClass(midContent, 'select', "SelectBox"); | |
strObject += '"value":"Type content here...","width":0,"mandatory":' + mandatory + ',"height":0,"advanced":"' + selectNode.value + '",'; | |
break; | |
case "select": | |
var selectNode = DOMUtil.findFirstDescendantByClass(topContent, 'select', "SelectBox"); | |
var width = selectNode.offsetWidth; | |
var mandatory = fieldLabel.getAttribute('mandatory'); | |
var height = selectNode.offsetHeight; | |
strObject += '"value":"' + selectNode.value + '","width":' + width + ',"mandatory":' + mandatory + ',"height":' + height + ','; | |
var options = DOMUtil.getChildrenByTagName(selectNode, 'option'); | |
var advOptions = ''; | |
strObject += '"advanced":"'; | |
for (var i = 0; i < options.length; i++) { | |
strObject += options[i].value; | |
if (i != (options.length - 1)) { | |
strObject += ","; | |
} | |
} | |
strObject += '",'; | |
break; | |
case "upload": | |
strObject += '"value":"null","width":0,"mandatory":' + mandatory + ',"height":0,'; | |
break; | |
case "radio": | |
var radioButtonList = DOMUtil.findDescendantsByClass(topContent, 'div', 'RadioButton'); | |
var strAdvanced = ""; | |
for (var i = 0; i < radioButtonList.length; i++) { | |
var radioButton = radioButtonList[i]; | |
var inputList = DOMUtil.getChildrenByTagName(radioButton, 'input'); | |
for (var j = 0; j < inputList.length; j++) { | |
var radioLabel = DOMUtil.findNextElementByTagName(inputList[j], 'span'); | |
if ((radioLabel != null) && (radioLabel.innerHTML.length > 0)) { | |
strAdvanced += radioLabel.innerHTML + ","; | |
} else { | |
strAdvanced += inputList[j].value + ","; | |
} | |
} | |
} | |
var mandatory = fieldLabel.getAttribute('mandatory'); | |
strObject += '"mandatory":' + mandatory + ','; | |
strObject += '"advanced":"' + strAdvanced + '",'; | |
break; | |
case "checkbox": | |
var checkboxButtonList = DOMUtil.findDescendantsByClass(topContent, 'div', 'CheckboxButton'); | |
var strAdvanced = ""; | |
for (var i = 0; i < checkboxButtonList.length; i++) { | |
var checkboxButton = checkboxButtonList[i]; | |
var inputList = DOMUtil.getChildrenByTagName(checkboxButton, 'input'); | |
for (var j = 0; j < inputList.length; j++) { | |
var checkboxLabel = DOMUtil.findNextElementByTagName(inputList[j], 'span'); | |
if ((checkboxLabel != null) && (checkboxLabel.innerHTML.length > 0)) { | |
strAdvanced += checkboxLabel.innerHTML + ","; | |
} else { | |
strAdvanced += inputList[j].value + ","; | |
} | |
} | |
} | |
var mandatory = fieldLabel.getAttribute('mandatory'); | |
strObject += '"mandatory":' + mandatory + ','; | |
strObject += '"advanced":"' + strAdvanced + '",'; | |
break; | |
} | |
strObject += '"guideline":"' + fieldLabel.getAttribute('desc') + '"'; | |
strObject += "}"; | |
return strObject; | |
}; | |
UIFormGeneratorPortlet.prototype.submitForm = function () { | |
var strJsonObject = eXo.ecm.UIFormGeneratorPortlet.getStringJsonObject(); | |
var inputHidden = document.getElementById("UIFormGeneratorJsonObjectStringInput"); | |
if (inputHidden) inputHidden.value = "" + strJsonObject; | |
}; | |
eXo.ecm.UIFormGeneratorPortlet = new UIFormGeneratorPortlet(); | |
function ContentListViewer() {} | |
ContentListViewer.prototype.initCheckedRadio = function (id) { | |
eXo.core.Browser.chkRadioId = id; | |
}; | |
ContentListViewer.prototype.initCondition = function (formid) { | |
var formElement = document.getElementById(formid); | |
var radioboxes = []; | |
for (var i = 0; i < formElement.elements.length; i++) { | |
if (formElement.elements[i].type == "radio") radioboxes.push(formElement.elements[i]); | |
} | |
var i = radioboxes.length; | |
while (i--) { | |
radioboxes[i].onclick = eXo.ecm.CLV.chooseCondition; | |
} | |
if (eXo.core.Browser.chkRadioId && eXo.core.Browser.chkRadioId != "null") { | |
var selectedRadio = document.getElementById(eXo.core.Browser.chkRadioId); | |
} else { | |
var selectedRadio = radioboxes[0]; | |
} | |
var itemSelectedContainer = eXo.core.DOMUtil.findAncestorByClass(selectedRadio, "ContentSearchForm"); | |
var itemContainers = eXo.core.DOMUtil.findDescendantsByClass(selectedRadio.form, "div", "ContentSearchForm"); | |
for (var i = 0; i < itemContainers.length; i++) { | |
eXo.ecm.CLV.setCondition(itemContainers[i], true); | |
} | |
eXo.ecm.CLV.enableCondition(itemSelectedContainer); | |
}; | |
ContentListViewer.prototype.chooseCondition = function () { | |
var me = this; | |
var hiddenField = eXo.core.DOMUtil.findFirstDescendantByClass(me.form, "input", "hidden"); | |
hiddenField.value = me.id; | |
var itemSelectedContainer = eXo.core.DOMUtil.findAncestorByClass(me, "ContentSearchForm"); | |
var itemContainers = eXo.core.DOMUtil.findDescendantsByClass(me.form, "div", "ContentSearchForm"); | |
for (var i = 0; i < itemContainers.length; i++) { | |
eXo.ecm.CLV.setCondition(itemContainers[i], true); | |
} | |
eXo.ecm.CLV.enableCondition(itemSelectedContainer); | |
eXo.ecm.lastCondition = itemSelectedContainer; | |
}; | |
ContentListViewer.prototype.enableCondition = function (itemContainer) { | |
if (eXo.ecm.lastCondition) eXo.ecm.CLV.setCondition(eXo.ecm.lastCondition, true); | |
eXo.ecm.CLV.setCondition(itemContainer, false); | |
}; | |
ContentListViewer.prototype.setCondition = function (itemContainer, state) { | |
var domUtil = eXo.core.DOMUtil; | |
var action = domUtil.findDescendantsByTagName(itemContainer, "img"); | |
if (action && action.length > 0) { | |
for (var i = 0; i < action.length; i++) { | |
if (state) { | |
action[i].style.visibility = "hidden"; | |
} else { | |
action[i].style.visibility = ""; | |
} | |
} | |
} | |
var action = domUtil.findDescendantsByTagName(itemContainer, "input"); | |
if (action && (action.length > 0)) { | |
for (i = 0; i < action.length; i++) { | |
if (action[i].type != "radio") action[i].disabled = state; | |
} | |
} | |
var action = domUtil.findDescendantsByTagName(itemContainer, "select"); | |
if (action && (action.length > 0)) { | |
for (i = 0; i < action.length; i++) { | |
action[i].disabled = state; | |
} | |
} | |
}; | |
ContentListViewer.prototype.setHiddenValue = function () { | |
var inputHidden = document.getElementById("checkedRadioId"); | |
if (eXo.core.Browser.chkRadioId == "null") { | |
inputHidden.value = "name"; | |
document.getElementById("name").checked = true; | |
} else { | |
inputHidden.value = eXo.core.Browser.chkRadioId; | |
document.getElementById(eXo.core.Browser.chkRadioId).checked = true; | |
} | |
}; | |
ContentListViewer.prototype.checkModeViewer = function () { | |
var formObj = document.getElementById("UICLVConfig"); | |
var OrderOptions = eXo.core.DOMUtil.findDescendantsByClass(formObj, "tr", "OrderBlock"); | |
var viewerModes = eXo.core.DOMUtil.findDescendantsByTagName(formObj, "input"); | |
for (var i = 0; i < viewerModes.length; i++) { | |
if (viewerModes[i].getAttribute("name") == "ViewerMode") { | |
if (viewerModes[i].value == "AutoViewerMode") { | |
viewerModes[i].onclick = function () { | |
for (var j = 0; j < OrderOptions.length; j++) { | |
OrderOptions[j].style.display = ""; | |
} | |
}; | |
} else if (viewerModes[i].value == "ManualViewerMode") { | |
viewerModes[i].onclick = function () { | |
for (var k = 0; k < OrderOptions.length; k++) { | |
OrderOptions[k].style.display = "none"; | |
} | |
}; | |
} | |
} | |
} | |
}; | |
ContentListViewer.prototype.checkContextualFolderInput = function () { | |
var formObj = document.getElementById("UICLVConfig"); | |
var tdContextualFolder = eXo.core.DOMUtil.findDescendantsByClass(formObj, "td", "ContextualRadio")[0]; | |
var inputs = eXo.core.DOMUtil.getChildrenByTagName(tdContextualFolder, "input"); | |
var enableInput = inputs[0]; | |
var disableInput = inputs[1]; | |
var trContextual = eXo.core.DOMUtil.findAncestorByTagName(tdContextualFolder, "tr"); | |
var trClv = eXo.core.DOMUtil.findNextElementByTagName(trContextual, "tr"); | |
var clvInput = eXo.core.DOMUtil.findDescendantsByTagName(trClv, "input")[0]; | |
enableInput.setAttribute("onmouseup", "eXo.ecm.CLV.enableClvInput(this)"); | |
disableInput.setAttribute("onmouseup", "eXo.ecm.CLV.disableClvInput(this)"); | |
if (enableInput.checked) { | |
clvInput.removeAttribute('readonly'); | |
} else { | |
clvInput.setAttribute('readonly', ''); | |
} | |
}; | |
ContentListViewer.prototype.enableClvInput = function (obj) { | |
var trContextual = eXo.core.DOMUtil.findAncestorByTagName(obj, "tr"); | |
var trClv = eXo.core.DOMUtil.findNextElementByTagName(trContextual, "tr"); | |
var clvInput = eXo.core.DOMUtil.findDescendantsByTagName(trClv, "input")[0]; | |
clvInput.removeAttribute('readonly'); | |
}; | |
ContentListViewer.prototype.disableClvInput = function (obj) { | |
var trContextual = eXo.core.DOMUtil.findAncestorByTagName(obj, "tr"); | |
var trClv = eXo.core.DOMUtil.findNextElementByTagName(trContextual, "tr"); | |
var clvInput = eXo.core.DOMUtil.findDescendantsByTagName(trClv, "input")[0]; | |
clvInput.setAttribute('readonly', ''); | |
}; | |
ContentListViewer.prototype.addURL = function (aDiv) { | |
var strHref = aDiv.getAttribute("href"); | |
var fIdx = strHref.indexOf("&backto"); | |
if (fIdx < 0) fIdx = strHref.indexOf("?backto"); | |
if (fIdx < 0) return; | |
var lIdx = strHref.indexOf("&", fIdx + 1); | |
var lString = ""; | |
var fString = strHref; | |
if (lIdx > 0) { | |
lString = strHref.substr(lIdx); | |
fString = strHref.substr(0, lIdx); | |
} | |
strHref = fString + escape(location.search) + lString; | |
aDiv.setAttribute("href", strHref); | |
} | |
eXo.ecm.CLV = new ContentListViewer(); | |
function WCMFCKEditor() {} | |
WCMFCKEditor.prototype.insertCSSFromTextArea2FCK = function (Instance, ContentCSS) { | |
if (!Instance) return; | |
var eContentCSS = document.getElementById(ContentCSS); | |
var sContentCSSId = ContentCSS + "_Inline"; | |
var count = 1; | |
eContentCSS.onblur = updateStyle; | |
function updateStyle() { | |
var sValue = eContentCSS.value; | |
if (!sValue) return; | |
var iDoc = FCKeditorAPI.Instances[Instance].EditorWindow.document; | |
var eHead = iDoc.getElementsByTagName("head")[0]; | |
var eStyle = iDoc.getElementById(sContentCSSId); | |
if (eStyle) { | |
eHead.removeChild(eStyle); | |
} | |
eStyle = iDoc.createElement("style"); | |
eStyle.setAttribute("type", "text/css"); | |
eStyle.setAttribute("id", sContentCSSId); | |
if (eXo.core.Browser.isFF()) { | |
eStyle.innerHTML = sValue; | |
} else { | |
eStyle.styleSheet.cssText = sValue; | |
} | |
eHead.appendChild(eStyle); | |
}; | |
(function checkFCKEditorAPI() { | |
if (count <= 5) { | |
try { | |
updateStyle(); | |
if (updateStyle.time) { | |
clearTimeout(updateStyle.time); | |
updateStyle.time = null; | |
} | |
} catch (e) { | |
count++; | |
updateStyle.time = setTimeout(checkFCKEditorAPI, 500); | |
} | |
} | |
})(); | |
}; | |
eXo.ecm.WCMFCKEditor = new WCMFCKEditor(); | |
function CKEditor() {} | |
CKEditor.prototype.insertCSS = function (Instance, ContentCSS) { | |
if (!Instance) return; | |
var eContentCSS = document.getElementById(ContentCSS); | |
var sContentCSSId = ContentCSS + "_Inline"; | |
var count = 1; | |
eContentCSS.onblur = updateStyle; | |
updateStyle; | |
function updateStyle() { | |
var sValue = eContentCSS.value; | |
if (!sValue) return; | |
var iDoc = CKEDITOR.instances[Instance].document.$; | |
var eHead = iDoc.getElementsByTagName("head")[0]; | |
var eStyle = iDoc.getElementById(sContentCSSId); | |
if (eStyle) { | |
eHead.removeChild(eStyle); | |
} | |
eStyle = iDoc.createElement("style"); | |
eStyle.setAttribute("type", "text/css"); | |
eStyle.setAttribute("id", sContentCSSId); | |
if (eXo.core.Browser.isIE6() || eXo.core.Browser.isIE7()) { | |
eStyle.styleSheet.cssText = sValue; | |
} else { | |
eStyle.innerHTML = sValue; | |
} | |
eHead.appendChild(eStyle); | |
}; | |
(function checkCKEditorAPI() { | |
if (count <= 5) { | |
try { | |
updateStyle(); | |
if (updateStyle.time) { | |
clearTimeout(updateStyle.time); | |
updateStyle.time = null; | |
} | |
} catch (e) { | |
count++; | |
updateStyle.time = setTimeout(checkCKEditorAPI, 500); | |
} | |
} | |
})(); | |
}; | |
eXo.ecm.CKEditor = new CKEditor(); | |
var FCKeditor = function (instanceName, width, height, toolbarSet, value) { | |
this.InstanceName = instanceName; | |
this.Width = width || '100%'; | |
this.Height = height || '200'; | |
this.ToolbarSet = toolbarSet || 'Default'; | |
this.Value = value || ''; | |
this.BasePath = FCKeditor.BasePath; | |
this.CheckBrowser = true; | |
this.DisplayErrors = true; | |
this.Config = new Object(); | |
this.OnError = null; | |
} | |
FCKeditor.BasePath = '/fckeditor/'; | |
FCKeditor.MinHeight = 200; | |
FCKeditor.MinWidth = 750; | |
FCKeditor.prototype.Version = '2.6.3'; | |
FCKeditor.prototype.VersionBuild = '19836'; | |
FCKeditor.prototype.Create = function () { | |
document.write(this.CreateHtml()); | |
} | |
FCKeditor.prototype.CreateHtml = function () { | |
if (!this.InstanceName || this.InstanceName.length == 0) { | |
this._ThrowError(701, 'You must specify an instance name.'); | |
return ''; | |
} | |
var sHtml = ''; | |
if (!this.CheckBrowser || this._IsCompatibleBrowser()) { | |
sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode(this.Value) + '" style="display:none" />'; | |
sHtml += this._GetConfigHtml(); | |
sHtml += this._GetIFrameHtml(); | |
} else { | |
var sWidth = this.Width.toString().indexOf('%') > 0 ? this.Width : this.Width + 'px'; | |
var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px'; | |
sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight; | |
if (this.TabIndex) sHtml += '" tabindex="' + this.TabIndex; | |
sHtml += '">' + this._HTMLEncode(this.Value) + '<\/textarea>'; | |
} | |
return sHtml; | |
} | |
FCKeditor.prototype.ReplaceTextarea = function () { | |
if (!this.CheckBrowser || this._IsCompatibleBrowser()) { | |
var oTextarea = document.getElementById(this.InstanceName); | |
var value = oTextarea.value; | |
value = value.replace(/ /g, "  "); | |
oTextarea.value = value; | |
var colElementsByName = document.getElementsByName(this.InstanceName); | |
var i = 0; | |
while (oTextarea || i == 0) { | |
if (oTextarea && oTextarea.tagName.toLowerCase() == 'textarea') break; | |
oTextarea = colElementsByName[i++]; | |
} | |
if (!oTextarea) { | |
alert('Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found'); | |
return; | |
} | |
oTextarea.style.display = 'none'; | |
if (oTextarea.tabIndex) this.TabIndex = oTextarea.tabIndex; | |
this._InsertHtmlBefore(this._GetConfigHtml(), oTextarea); | |
this._InsertHtmlBefore(this._GetIFrameHtml(), oTextarea); | |
} | |
} | |
FCKeditor.prototype._InsertHtmlBefore = function (html, element) { | |
if (element.insertAdjacentHTML) element.insertAdjacentHTML('beforeBegin', html); | |
else { | |
var oRange = document.createRange(); | |
oRange.setStartBefore(element); | |
var oFragment = oRange.createContextualFragment(html); | |
element.parentNode.insertBefore(oFragment, element); | |
} | |
} | |
FCKeditor.prototype._GetConfigHtml = function () { | |
var sConfig = ''; | |
for (var o in this.Config) { | |
if (sConfig.length > 0) sConfig += '&'; | |
sConfig += encodeURIComponent(o) + '=' + encodeURIComponent(this.Config[o]); | |
} | |
return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />'; | |
} | |
FCKeditor.prototype._GetIFrameHtml = function () { | |
var sFile = 'fckeditor.html'; | |
try { | |
if ((/fcksource=true/i).test(window.top.location.search)) sFile = 'fckeditor.original.html'; | |
} catch (e) {} | |
var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent(this.InstanceName); | |
if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet; | |
html = '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height; | |
if (this.TabIndex) html += '" tabindex="' + this.TabIndex; | |
html += '" frameborder="0" scrolling="no"></iframe>'; | |
return html; | |
} | |
FCKeditor.prototype._IsCompatibleBrowser = function () { | |
return FCKeditor_IsCompatibleBrowser(); | |
} | |
FCKeditor.prototype._ThrowError = function (errorNumber, errorDescription) { | |
this.ErrorNumber = errorNumber; | |
this.ErrorDescription = errorDescription; | |
if (this.DisplayErrors) { | |
document.write('<div style="COLOR: #ff0000">'); | |
document.write('[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]'); | |
document.write('</div>'); | |
} | |
if (typeof (this.OnError) == 'function') this.OnError(this, errorNumber, errorDescription); | |
} | |
FCKeditor.prototype._HTMLEncode = function (text) { | |
if (typeof (text) != "string") text = text.toString(); | |
text = text.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"); | |
return text; | |
}; | |
(function () { | |
var textareaToEditor = function (textarea) { | |
var editor = new FCKeditor(textarea.name); | |
editor.Width = Math.max(textarea.offsetWidth, FCKeditor.MinWidth); | |
editor.Height = Math.max(textarea.offsetHeight, FCKeditor.MinHeight); | |
return editor; | |
} | |
FCKeditor.ReplaceAllTextareas = function () { | |
var textareas = document.getElementsByTagName('textarea'); | |
for (var i = 0; i < textareas.length; i++) { | |
var editor = null; | |
var textarea = textareas[i]; | |
var name = textarea.name; | |
if (!name || name.length == 0) continue; | |
if (typeof arguments[0] == 'string') { | |
var classRegex = new RegExp('(?:^| )' + arguments[0] + '(?:$| )'); | |
if (!classRegex.test(textarea.className)) continue; | |
} else if (typeof arguments[0] == 'function') { | |
editor = textareaToEditor(textarea); | |
if (arguments[0](textarea, editor) === false) continue; | |
} | |
if (!editor) editor = textareaToEditor(textarea); | |
editor.ReplaceTextarea(); | |
} | |
} | |
})(); | |
function FCKeditor_IsCompatibleBrowser() { | |
return true; | |
var sAgent = navigator.userAgent.toLowerCase(); | |
if (false && sAgent.indexOf("mac") == -1) { | |
var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1]; | |
return (sBrowserVersion >= 5.5); | |
} | |
if (navigator.product == "Gecko" && navigator.productSub >= 20030210 && !(typeof (opera) == 'object' && opera.postError)) return true; | |
if (window.opera && window.opera.version && parseFloat(window.opera.version()) >= 9.5) return true; | |
if (sAgent.indexOf(' adobeair/') != -1) return (sAgent.match(/ adobeair\/(\d+)/)[1] >= 1); | |
if (sAgent.indexOf(' applewebkit/') != -1) return (sAgent.match(/ applewebkit\/(\d+)/)[1] >= 522); | |
return false; | |
} | |
function UISiteMap() {}; | |
UISiteMap.prototype.updateTreeNode = function (nodeToUpdate, getNodeURL) { | |
if (!nodeToUpdate || !getNodeURL) return; | |
var subGroup = eXo.core.DOMUtil.findFirstChildByClass(nodeToUpdate.parentNode, "div", "ChildrenContainer"); | |
if (!subGroup || subGroup.innerHTML.trim() !== "") return; | |
var jsChilds = ajaxAsyncGetRequest(getNodeURL, false); | |
try { | |
var data = eXo.core.JSON.parse(jsChilds); | |
} catch (e) {} | |
if (data && data.length) { | |
eXo.webui.UISiteMap.generateHtml(data, nodeToUpdate, subGroup); | |
return; | |
} | |
eXo.core.DOMUtil.removeClass(nodeToUpdate, "CollapseIcon"); | |
eXo.core.DOMUtil.addClass(nodeToUpdate, "NullItem"); | |
}; | |
UISiteMap.prototype.generateHtml = function (data, nodeToUpdate, subGroup) { | |
function toHtml(node, isLast) { | |
if (!node) return; | |
var lastNode = isLast ? "LastNode" : ""; | |
var actionLink = node.actionLink ? node.actionLink : "javascript:void(0);"; | |
var actionExpand = 'eXo.webui.UISiteMap.updateTreeNode(this, "' + node.getNodeURL + '")'; | |
var actionCollapse = 'ajaxAsyncGetRequest("' + node.collapseURL + '", true)'; | |
var str = ""; | |
if (node.hasChild) { | |
str += "<div class='" + lastNode + " Node'>"; | |
if (node.isExpanded) { | |
str += "<div class='CollapseIcon ClearFix' onclick='eXo.portal.UIPortal.collapseExpand(this); " + actionCollapse + "'>"; | |
str += "<a class='NodeIcon DefaultPageIcon' href='" + actionLink + "'>" + node.label + "</a>"; | |
str += "</div><div class='ChildrenContainer' style='display: block'>"; | |
for (var idx = 0; idx < node.childs.length; idx++) { | |
str += toHtml(node.childs[idx], idx == node.childs.length - 1); | |
} | |
} else { | |
str += "<div class='ExpandIcon ClearFix' onclick='eXo.portal.UIPortal.collapseExpand(this); " + actionExpand + "'>"; | |
str += "<a class='NodeIcon DefaultPageIcon' href='" + actionLink + "'>" + node.label + "</a>"; | |
str += "</div><div class='ChildrenContainer' style='display: none'>"; | |
for (var idx = 0; idx < node.childs.length; idx++) { | |
str += toHtml(node.childs[idx], idx == node.childs.length - 1); | |
} | |
} | |
str += "</div></div>"; | |
} else { | |
str += "<div class='" + lastNode + " Node ClearFix'><div class='NullItem'><div class='ClearFix'>"; | |
str += "<a class='NodeIcon DefaultPageIcon' href='" + actionLink + "'>" + node.label + "</a></div></div></div>"; | |
} | |
return str; | |
} | |
var htmlFrags = ""; | |
for (var i = 0; i < data.length; i++) { | |
htmlFrags += toHtml(data[i], i == data.length - 1); | |
} | |
subGroup.innerHTML = htmlFrags; | |
subGroup.style.display = "block"; | |
}; | |
eXo.webui.UISiteMap = new UISiteMap(); | |
eXo.require("eXo.core.EventManager"); | |
if (!eXo.wiki) eXo.wiki = {}; | |
function UIWikiPortlet() {}; | |
UIWikiPortlet.prototype.init = function (portletId, linkId) { | |
var me = eXo.wiki.UIWikiPortlet; | |
me.wikiportlet = document.getElementById(portletId); | |
me.changeModeLink = document.getElementById(linkId); | |
if (document.attachEvent) me.wikiportlet.attachEvent("onmouseup", me.onMouseUp); | |
else me.wikiportlet.onmouseup = function (event) { | |
me.onMouseUp(event); | |
}; | |
me.wikiportlet.onkeyup = function (event) { | |
me.onKeyUp(event); | |
}; | |
} | |
UIWikiPortlet.prototype.onMouseUp = function (evt) { | |
var me = eXo.wiki.UIWikiPortlet; | |
var evt = evt || window.event; | |
var target = evt.target || evt.srcElement; | |
if (evt.button == 2) return; | |
var searchPopup = eXo.core.DOMUtil.findFirstDescendantByClass(me.wikiportlet, "div", "SearchPopup"); | |
if (searchPopup) searchPopup.style.display = 'none'; | |
var breadCrumbPopup = eXo.wiki.UIWikiPortlet.getBreadcrumbPopup(); | |
if (breadCrumbPopup) { | |
breadCrumbPopup.style.display = 'none'; | |
} | |
if (target.tagName == "A" || (target.tagName == "INPUT" && target.type == "button") || target.tagName == "SELECT" || target.tagName == "DIV" && target.className.indexOf("RefreshModeTarget") > 0) { | |
eXo.wiki.UIWikiPortlet.changeMode(evt); | |
} | |
} | |
UIWikiPortlet.prototype.onKeyUp = function (evt) { | |
var evt = evt || window.event; | |
var target = evt.target || evt.srcElement; | |
if (target.tagName == "INPUT" && target.type == "text") if (evt.keyCode == 13) eXo.wiki.UIWikiPortlet.changeMode(evt); | |
} | |
UIWikiPortlet.prototype.changeMode = function (event) { | |
setTimeout("eXo.wiki.UIWikiPortlet.timeChangeMode()", 200); | |
}; | |
UIWikiPortlet.prototype.timeChangeMode = function () { | |
var me = eXo.wiki.UIWikiPortlet; | |
var currentURL = document.location.href; | |
var mode = ""; | |
if (currentURL.indexOf("action=AddPage") > 0) { | |
mode = "AddPage"; | |
} else if (currentURL.indexOf("#") > 0) { | |
mode = currentURL.substring(currentURL.indexOf("#") + 1, currentURL.length); | |
if (mode && mode.length > 0 && mode.charAt(0) == 'H') { | |
mode = ""; | |
} | |
if (mode.indexOf("/") > 0) mode = mode.substring(0, mode.indexOf("/")); | |
} | |
var link = me.changeModeLink; | |
var endParamIndex = link.href.lastIndexOf("')"); | |
var modeIndex = link.href.indexOf("&mode"); | |
if (modeIndex < 0) link.href = link.href.substring(0, endParamIndex) + "&mode=" + mode + "')"; | |
else link.href = link.href.substring(0, modeIndex) + "&mode=" + mode + "')"; | |
window.location = link.href; | |
}; | |
UIWikiPortlet.prototype.showPopup = function (elevent, e) { | |
var strs = ["AddTagId", "goPageTop", "goPageBottom", "SearchForm"]; | |
for (var t = 0; t < strs.length; t++) { | |
var elm = document.getElementById(strs[t]); | |
if (elm) elm.onclick = eXo.wiki.UIWikiPortlet.cancel; | |
} | |
if (!e) e = window.event; | |
e.cancelBubble = true; | |
var parend = eXo.core.DOMUtil.findAncestorByTagName(elevent, "div"); | |
var popup = eXo.core.DOMUtil.findFirstDescendantByClass(parend, "div", "UIPopupCategory"); | |
if (popup.style.display === "none") { | |
popup.style.display = "block"; | |
eXo.core.DOMUtil.listHideElements(popup); | |
} else { | |
popup.style.display = "none"; | |
} | |
}; | |
UIWikiPortlet.prototype.cancel = function (evt) { | |
var _e = window.event || evt; | |
_e.cancelBubble = true; | |
}; | |
UIWikiPortlet.prototype.renderBreadcrumbs = function (uicomponentid, isLink) { | |
var me = eXo.wiki.UIWikiPortlet; | |
var component = document.getElementById(uicomponentid); | |
var DOMUtil = eXo.core.DOMUtil; | |
var breadcrumb = DOMUtil.findFirstDescendantByClass(component, 'div', 'BreadcumbsInfoBar'); | |
var breadcrumbPopup = DOMUtil.findFirstDescendantByClass(component, 'div', 'SubBlock'); | |
var itemArray = DOMUtil.findDescendantsByTagName(breadcrumb, "a"); | |
var shortenFractor = 3 / 4; | |
itemArray.shift(); | |
var ancestorItem = itemArray.shift(); | |
var lastItem = itemArray.pop(); | |
if (lastItem == undefined) { | |
return; | |
} | |
var parentLastItem = itemArray.pop(); | |
if (parentLastItem == undefined) { | |
return; | |
} | |
var popupItems = new Array(); | |
var firstTime = true; | |
var content = String(lastItem.innerHTML); | |
while (breadcrumb.offsetWidth > shortenFractor * breadcrumb.parentNode.offsetWidth) { | |
if (itemArray.length > 0) { | |
var arrayLength = itemArray.length; | |
var item = itemArray.pop(); | |
popupItems.push(item); | |
if (firstTime) { | |
firstTime = false; | |
var newItem = item.cloneNode(true); | |
newItem.innerHTML = ' ... '; | |
if (isLink) { | |
newItem.href = '#'; | |
eXo.core.Browser.eventListener(newItem, 'mouseover', me.showBreadcrumbPopup); | |
} | |
breadcrumb.replaceChild(newItem, item); | |
} else { | |
var leftBlock = DOMUtil.findPreviousElementByTagName(item, 'div'); | |
breadcrumb.removeChild(leftBlock); | |
breadcrumb.removeChild(item); | |
} | |
} else { | |
break; | |
} | |
} | |
if (content.length != lastItem.innerHTML.length) { | |
lastItem.innerHTML = '<span title="' + content + '">' + lastItem.innerHTML + '...' + '</span>'; | |
} | |
me.createPopup(popupItems, isLink, breadcrumbPopup); | |
}; | |
UIWikiPortlet.prototype.createPopup = function (popupItems, isLink, breadcrumbPopup) { | |
if (isLink) { | |
var popupItemDepth = -1; | |
for (var index = popupItems.length - 1; index >= 0; index--) { | |
popupItems[index].className = 'ItemIcon MenuIcon'; | |
popupItemDepth++; | |
var menuItem = document.createElement('div'); | |
menuItem.className = 'MenuItem'; | |
var previousDiv = menuItem; | |
for (var i = 0; i < popupItemDepth; i++) { | |
var marginLeftDiv = document.createElement('div'); | |
marginLeftDiv.className = 'MarginLeftDiv'; | |
previousDiv.appendChild(marginLeftDiv); | |
previousDiv = marginLeftDiv; | |
if (i == popupItemDepth - 1) { | |
previousDiv.appendChild(popupItems[index]); | |
} | |
} | |
if (popupItemDepth == 0) { | |
menuItem.appendChild(popupItems[index]); | |
} | |
breadcrumbPopup.appendChild(menuItem); | |
} | |
} | |
}; | |
UIWikiPortlet.prototype.shortenUntil = function (item, condition) { | |
var isShortent = false; | |
while (!condition() && item.innerHTML.length > 3) { | |
item.innerHTML = item.innerHTML.substring(0, item.innerHTML.length - 1); | |
isShortent = true; | |
} | |
if (isShortent) { | |
if (item.innerHTML.length > 6) { | |
item.innerHTML = item.innerHTML.substring(0, item.innerHTML.length - 3); | |
} | |
item.innerHTML = item.innerHTML + ' ... '; | |
} | |
}; | |
UIWikiPortlet.prototype.getBreadcrumbPopup = function () { | |
var breadcrumb = document.getElementById("UIWikiBreadCrumb"); | |
var breadcrumbPopup = eXo.core.DOMUtil.findFirstDescendantByClass(breadcrumb, 'div', 'BreadcumPopup'); | |
return breadcrumbPopup; | |
}; | |
UIWikiPortlet.prototype.showBreadcrumbPopup = function (evt) { | |
var breadcrumbPopup = eXo.wiki.UIWikiPortlet.getBreadcrumbPopup(); | |
var ellipsis = evt.target || evt.srcElement; | |
var isRTL = eXo.core.I18n.isRT(); | |
var offsetLeft = eXo.core.Browser.findPosX(ellipsis, isRTL) - 20; | |
var offsetTop = eXo.core.Browser.findPosY(ellipsis) + 20; | |
breadcrumbPopup.style.zIndex = '100'; | |
breadcrumbPopup.style.display = 'block'; | |
breadcrumbPopup.style.left = offsetLeft + 'px'; | |
breadcrumbPopup.style.top = offsetTop + 'px'; | |
}; | |
UIWikiPortlet.prototype.highlightEditSection = function (header, highlight) { | |
var sectionContainer = eXo.core.DOMUtil.findAncestorByClass(header, 'section-container'); | |
var section = eXo.core.DOMUtil.findFirstDescendantByClass(header, 'span', 'EditSection'); | |
if (highlight == true) { | |
section.style.display = 'block'; | |
sectionContainer.style.backgroundColor = '#F7F7F7'; | |
} else { | |
section.style.display = 'none'; | |
sectionContainer.style.backgroundColor = ''; | |
} | |
}; | |
UIWikiPortlet.prototype.createURLHistory = function (uicomponentId, isShow) { | |
if (isShow || isShow === 'true') { | |
setTimeout("eXo.wiki.UIWikiPortlet.urlHistory('" + uicomponentId + "')", 500); | |
} | |
}; | |
UIWikiPortlet.prototype.urlHistory = function (uicomponentId) { | |
var component = document.getElementById(uicomponentId); | |
if (component) { | |
var local = String(window.location); | |
if (local.indexOf('#') < 0 || local.indexOf('#') === (local.length - 1)) { | |
window.location = local.replace('#', '') + '#ShowHistory'; | |
} | |
} | |
}; | |
UIWikiPortlet.prototype.makeRenderingErrorsExpandable = function (uicomponentId) { | |
var uicomponent = document.getElementById(uicomponentId); | |
var DOMUtil = eXo.core.DOMUtil; | |
if (uicomponent) { | |
var renderingErrors = DOMUtil.findDescendantsByClass(uicomponent, "div", "xwikirenderingerror"); | |
for (i = 0; i < renderingErrors.length; i++) { | |
var renderingError = renderingErrors[i]; | |
var descriptionError = renderingError.nextSibling; | |
if (descriptionError.innerHTML !== "" && DOMUtil.hasClass(descriptionError, "xwikirenderingerrordescription")) { | |
renderingError.style.cursor = "pointer"; | |
eXo.core.EventManager.addEvent(renderingError, "click", function (event) { | |
if (!DOMUtil.hasClass(descriptionError, "hidden")) { | |
descriptionError.className += ' ' + "hidden"; | |
} else { | |
DOMUtil.removeClass(descriptionError, "hidden"); | |
} | |
}); | |
} | |
} | |
} | |
}; | |
UIWikiPortlet.prototype.decorateSpecialLink = function (uicomponentId) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var uicomponent = document.getElementById(uicomponentId); | |
var invalidChars = DOMUtil.findFirstDescendantByClass(uicomponent, "div", "InvalidChars"); | |
var invalidCharsMsg = invalidChars.innerText; | |
if (!invalidCharsMsg || invalidCharsMsg == "undefined") { | |
invalidCharsMsg = invalidChars.textContent; | |
} | |
if (uicomponent) { | |
var linkSpans = DOMUtil.findDescendantsByClass(uicomponent, "span", "wikicreatelink"); | |
for (i = 0; i < linkSpans.length; i++) { | |
var linkSpan = linkSpans[i]; | |
var pageLink = linkSpan.childNodes[0]; | |
if (pageLink.href == "javascript:void(0);") { | |
eXo.core.EventManager.addEvent(pageLink, "click", function (event) { | |
alert(invalidCharsMsg); | |
return; | |
}); | |
} | |
} | |
} | |
}; | |
UIWikiPortlet.prototype.keepSessionAlive = function (isKeepSessionAlive) { | |
if (isKeepSessionAlive == true) { | |
eXo.session.itvInit(); | |
} else { | |
eXo.session.destroyItv(); | |
eXo.session.initialized = false; | |
eXo.session.openUrl = null; | |
} | |
} | |
eXo.wiki.UIWikiPortlet = new UIWikiPortlet(); | |
String.prototype.trim = function () { | |
return this.replace(/^\s+|\s+$/g, ''); | |
}; | |
String.prototype.replaceAll = function (oldText, newText) { | |
return this.replace(new RegExp(oldText, "g"), newText); | |
} | |
function UIWikiEditParagraph() {}; | |
UIWikiEditParagraph.prototype.init = function (pageContentAreaId, editActionId) { | |
var pageContentArea = document.getElementById(pageContentAreaId); | |
var editAction = document.getElementById(editActionId); | |
var sections = eXo.core.DOMUtil.findDescendantsByClass(pageContentArea, 'span', 'EditSection'); | |
for (var index = 0; index < sections.length; index++) { | |
var editLink = eXo.core.DOMUtil.findDescendantsByTagName(sections[index], 'a')[0]; | |
var linkLabel = eXo.core.DOMUtil.findDescendantsByTagName(editLink, 'span')[0]; | |
editLink.onclick = (function (sectionIndex) { | |
return function () { | |
eXo.wiki.UIWikiAjaxRequest.makeNewHash('#EditPage§ion=' + sectionIndex); | |
}; | |
})(index + 1); | |
editLink.href = 'javascript:void(0);'; | |
linkLabel.innerHTML = ''; | |
var headerContainer = sections[index].parentNode; | |
headerContainer.onmouseover = function () { | |
eXo.wiki.UIWikiPortlet.highlightEditSection(this, true); | |
} | |
headerContainer.onmouseout = function () { | |
eXo.wiki.UIWikiPortlet.highlightEditSection(this, false); | |
} | |
} | |
}; | |
eXo.wiki.UIWikiEditParagraph = new UIWikiEditParagraph(); | |
eXo.require("eXo.core.Keyboard"); | |
function UIWikiSearchBox() { | |
this.restURL = null; | |
this.input = null; | |
this.searchPopup = null; | |
this.searchType = ""; | |
this.menu = null; | |
this.wikiNodeURI = null; | |
}; | |
UIWikiSearchBox.prototype.init = function (componentId, searchInputName, searchLabel, wikiNodeURI) { | |
this.wikiNodeURI = wikiNodeURI; | |
var uiComponent = document.getElementById(componentId); | |
var restInput = uiComponent["restURL"]; | |
this.input = uiComponent[searchInputName]; | |
this.input.setAttribute('autocomplete', 'off'); | |
this.restURL = restInput.value; | |
this.input.onkeyup = function (evt) { | |
evt = window.event || evt; | |
eXo.wiki.UIWikiSearchBox.pressHandler(evt, this); | |
} | |
this.input.form.onsubmit = function () { | |
return false; | |
} | |
this.input.value = searchLabel; | |
this.input.style.color = "Gray"; | |
this.input.onfocus = function (evt) { | |
this.value = ""; | |
this.style.color = "Black"; | |
} | |
this.input.onblur = function (evt) { | |
if (this.value == '') { | |
this.value = searchLabel; | |
this.style.color = "Gray"; | |
} | |
} | |
}; | |
UIWikiSearchBox.prototype.pressHandler = function (evt, textbox) { | |
var me = eXo.wiki.UIWikiSearchBox; | |
evt = window.event || evt; | |
var keyNum = eXo.core.Keyboard.getKeynum(evt); | |
if (evt.altKey || evt.ctrlKey || evt.shiftKey) return; | |
switch (keyNum) { | |
case 13: | |
if (textbox.value.trim() != "") me.enterHandler(evt); | |
break; | |
case 27: | |
me.escapeHandler(); | |
break; | |
case 38: | |
me.arrowUpHandler(); | |
break; | |
case 40: | |
me.arrowDownHandler(); | |
break; | |
default: | |
if (me.typeTimeout) clearTimeout(me.typeTimeout); | |
if (me.currentItem) me.currentItem = null; | |
me.typeTimeout = setTimeout(function () { | |
if (me.xhr) { | |
me.xhr.abort(); | |
me.xhr = null; | |
delete me.xhr; | |
} | |
me.typeHandler(textbox); | |
clearTimeout(me.typeTimeout); | |
}, 100) | |
} | |
return; | |
}; | |
UIWikiSearchBox.prototype.enterHandler = function (evt) { | |
var me = eXo.wiki.UIWikiSearchBox; | |
if (me.currentItem) { | |
var link = me.currentItem.firstChild.firstChild; | |
if (link.href) { | |
evt.cancelBubble = true; | |
if (evt.stopPropagation) evt.stopPropagation(); | |
this.searchPopup.style.display = "none"; | |
window.location = link.href; | |
} | |
} else { | |
me.doAdvanceSearch(); | |
} | |
}; | |
UIWikiSearchBox.prototype.escapeHandler = function () { | |
var me = eXo.wiki.UIWikiSearchBox; | |
if (me.currentItem) me.currentItem = null; | |
eXo.wiki.UIWikiSearchBox.hideMenu(); | |
}; | |
UIWikiSearchBox.prototype.arrowUpHandler = function () { | |
var me = eXo.wiki.UIWikiSearchBox; | |
if (!me.currentItem) { | |
me.currentItem = this.menu.lastChild; | |
eXo.core.DOMUtil.addClass(me.currentItem, "ItemOver"); | |
return; | |
} | |
eXo.core.DOMUtil.replaceClass(me.currentItem, "ItemOver", ""); | |
if (me.currentItem.previousSibling) me.currentItem = me.currentItem.previousSibling; | |
else me.currentItem = this.menu.lastChild; | |
eXo.core.DOMUtil.addClass(me.currentItem, "ItemOver"); | |
}; | |
UIWikiSearchBox.prototype.arrowDownHandler = function () { | |
var me = eXo.wiki.UIWikiSearchBox; | |
if (!me.currentItem) { | |
me.currentItem = this.menu.firstChild; | |
eXo.core.DOMUtil.addClass(me.currentItem, "ItemOver"); | |
return; | |
} | |
eXo.core.DOMUtil.replaceClass(me.currentItem, "ItemOver", ""); | |
if (me.currentItem.nextSibling) me.currentItem = me.currentItem.nextSibling; | |
else me.currentItem = this.menu.firstChild; | |
eXo.core.DOMUtil.addClass(me.currentItem, "ItemOver"); | |
}; | |
UIWikiSearchBox.prototype.typeHandler = function (textbox) { | |
var keyword = this.createKeyword(textbox.value); | |
if (keyword == '') { | |
eXo.wiki.UIWikiSearchBox.hideMenu(); | |
return; | |
} | |
var url = this.restURL + keyword; | |
this.makeRequest(url, this.typeCallback); | |
}; | |
UIWikiSearchBox.prototype.makeRequest = function (url, callback) { | |
var me = eXo.wiki.UIWikiSearchBox; | |
this.xhr = eXo.core.Browser.createHttpRequest(); | |
this.xhr.open('GET', url, true); | |
this.xhr.setRequestHeader("Cache-Control", "max-age=86400"); | |
this.xhr.onreadystatechange = function () { | |
if (me.xhr.readyState == 4 && me.xhr.status == 200) { | |
if (callback) callback(me.xhr.responseText); | |
} | |
} | |
me.xhr.send(null); | |
}; | |
UIWikiSearchBox.prototype.typeCallback = function (data) { | |
if (!data) return; | |
eval("var data = " + data.trim()); | |
if (typeof (data) != "object") return; | |
eXo.wiki.UIWikiSearchBox.renderMenu(data); | |
}; | |
UIWikiSearchBox.prototype.doAdvanceSearch = function () { | |
var action = eXo.core.DOMUtil.findAncestorByClass(this.input, "SearchForm"); | |
action = eXo.core.DOMUtil.findFirstChildByClass(action, "a", "AdvancedSearch"); | |
eXo.wiki.UIWikiAjaxRequest.makeNewHash('#AdvancedSearch'); | |
action.onclick(); | |
} | |
UIWikiSearchBox.prototype.renderMenu = function (data) { | |
var me = eXo.wiki.UIWikiSearchBox; | |
var searchBox = eXo.core.DOMUtil.findAncestorByClass(this.input, "UIWikiSearchBox"); | |
this.searchPopup = eXo.core.DOMUtil.findFirstDescendantByClass(searchBox, "div", "SearchPopup"); | |
this.searchPopup.style.display = "block"; | |
this.searchPopup.onmouseup = function (evt) { | |
this.style.display = "none"; | |
evt.cancelBubble = true; | |
if (evt.stopPropagation()) evt.stopPropagation(); | |
} | |
this.menu = eXo.core.DOMUtil.findFirstDescendantByClass(this.searchPopup, "div", "SubBlock"); | |
var resultLength = data.jsonList.length; | |
this.menu.innerHTML = ""; | |
var textNode = document.createTextNode(''); | |
this.menu.appendChild(textNode); | |
var searchItemNode = document.createElement('div'); | |
searchItemNode.className = 'MenuItem TextItem Horizon'; | |
var searchText = document.createElement('div'); | |
searchText.className = 'MenuText'; | |
var linkNode = document.createElement("a"); | |
linkNode.className = 'ItemIcon MenuIcon'; | |
linkNode.setAttribute('href', 'javascript:eXo.wiki.UIWikiSearchBox.doAdvanceSearch();'); | |
linkNode.setAttribute('title', "Seach for \'" + this.input.value + "\'"); | |
linkNode.innerHTML = "Seach for \'" + this.input.value + "\'"; | |
linkNode.setAttribute('title', "Seach for \'" + this.input.value + "\'"); | |
searchText.appendChild(linkNode); | |
searchItemNode.appendChild(searchText); | |
this.menu.insertBefore(searchItemNode, textNode); | |
me.shortenWord(linkNode, searchText); | |
for (var i = 0; i < resultLength; i++) { | |
var itemNode = this.buildChild(data.jsonList[i]); | |
this.menu.insertBefore(itemNode, searchItemNode); | |
var linkContainer = itemNode.firstChild; | |
var link = linkContainer.firstChild; | |
var keyword = this.input.value.trim(); | |
var origin = link.innerHTML; | |
var shorten = me.shortenWord(link, linkContainer); | |
if (origin != shorten && keyword.length >= shorten.length - 3) link.innerHTML = me.doHighLight(shorten, shorten.substring(0, shorten.length - 3)); | |
else link.innerHTML = me.doHighLight(shorten, keyword); | |
} | |
this.menu.removeChild(this.menu.lastChild); | |
}; | |
UIWikiSearchBox.prototype.buildChild = function (dataObject) { | |
var menuItemNode = document.createElement('div'); | |
menuItemNode.className = 'MenuItem TextItem'; | |
if (this.searchType != dataObject.type) { | |
menuItemNode.className = 'MenuItem TextItem Horizon'; | |
} | |
this.searchType = dataObject.type; | |
var searchText = document.createElement('div'); | |
searchText.className = 'MenuText '; | |
var linkNode = document.createElement("a"); | |
linkNode.className = 'ItemIcon MenuIcon'; | |
if (dataObject.type == "wiki:attachment") { | |
linkNode.setAttribute('href', dataObject.uri); | |
} else { | |
linkNode.setAttribute('href', this.wikiNodeURI + dataObject.uri); | |
} | |
var keyword = this.input.value.trim(); | |
var labelResult = dataObject.fullTitle; | |
linkNode.setAttribute('title', labelResult); | |
linkNode.innerHTML = labelResult; | |
searchText.appendChild(linkNode); | |
menuItemNode.appendChild(searchText); | |
return menuItemNode; | |
}; | |
UIWikiSearchBox.prototype.createKeyword = function (str) { | |
if (str.indexOf(",") != -1) { | |
str = str.substr(str.lastIndexOf(",") + 1, str.length); | |
} | |
str = str.replace(/^\s*/, ""); | |
return str; | |
}; | |
UIWikiSearchBox.prototype.hideMenu = function () { | |
if (this.searchPopup) this.searchPopup.style.display = "none"; | |
}; | |
UIWikiSearchBox.prototype.doHighLight = function (text, keyword) { | |
var hiRE = new RegExp("(" + keyword + ")", "gi"); | |
text = text.replace(hiRE, "<b>$1</b>"); | |
return text; | |
} | |
UIWikiSearchBox.prototype.shortenWord = function (source, container) { | |
var isCut = false; | |
while (source.offsetWidth > container.offsetWidth) { | |
isCut = true; | |
var size = source.innerHTML.length; | |
source.innerHTML = source.innerHTML.substring(0, size - 1); | |
} | |
if (isCut) { | |
source.innerHTML = source.innerHTML.substring(0, source.innerHTML.length - 8) + "..."; | |
} | |
return source.innerHTML; | |
}; | |
eXo.wiki.webservice = eXo.wiki.webservice || {}; | |
eXo.wiki.UIWikiSearchBox = new UIWikiSearchBox(); | |
function UIWikiAdvanceSearchForm() {}; | |
UIWikiAdvanceSearchForm.prototype.init = function (inputId) { | |
var input = document.getElementById(inputId); | |
input.onkeyup = function (evt) { | |
evt = window.event || evt; | |
eXo.wiki.UIWikiAdvanceSearchForm.pressHandler(evt, this); | |
} | |
input.form.onsubmit = function () { | |
return false; | |
} | |
}; | |
UIWikiAdvanceSearchForm.prototype.pressHandler = function (evt, textbox) { | |
var me = eXo.wiki.UIWikiAdvanceSearchForm; | |
var keyNum = me.captureKey(evt); | |
evt = window.event || evt; | |
if (evt.altKey || evt.ctrlKey || evt.shiftKey) return; | |
switch (keyNum) { | |
case 13: | |
if (textbox.value.trim() != "") me.enterHandler(evt, textbox); | |
break; | |
case 27: | |
me.escapeHandler(evt, textbox); | |
break; | |
case 38: | |
me.arrowUpHandler(evt, textbox); | |
break; | |
case 40: | |
me.arrowDownHandler(evt, textbox); | |
break; | |
default: | |
me.typeHandler(evt, textbox); | |
} | |
return; | |
}; | |
UIWikiAdvanceSearchForm.prototype.captureKey = function (e) { | |
var code; | |
if (!e) { | |
var e = window.event; | |
} | |
if (e.keyCode) { | |
code = e.keyCode; | |
} else if (e.which) { | |
code = e.which; | |
} | |
return code; | |
}; | |
UIWikiAdvanceSearchForm.prototype.enterHandler = function (evt, textbox) { | |
var uiform = eXo.core.DOMUtil.findAncestorByClass(textbox, "UIWikiAdvanceSearchForm"); | |
var list = eXo.core.DOMUtil.findDescendantsByClass(uiform, "div", "SearchAction"); | |
list[0].onclick(); | |
}; | |
UIWikiAdvanceSearchForm.prototype.escapeHandler = function () {}; | |
UIWikiAdvanceSearchForm.prototype.arrowUpHandler = function () {}; | |
UIWikiAdvanceSearchForm.prototype.arrowDownHandler = function () {}; | |
UIWikiAdvanceSearchForm.prototype.typeHandler = function (evt, textbox) {}; | |
eXo.wiki.UIWikiAdvanceSearchForm = new UIWikiAdvanceSearchForm(); | |
if (!eXo.wiki) eXo.wiki = {}; | |
function UIForm() {}; | |
UIForm.prototype.submitPageEvent = function (formId, action, params) { | |
var form = eXo.webui.UIForm.getFormElemt(formId); | |
try { | |
if (FCKeditorAPI && typeof FCKeditorAPI == "object") { | |
for (var name in FCKeditorAPI.__Instances) { | |
var oEditor = FCKeditorAPI.__Instances[name]; | |
if (oEditor.GetParentForm && oEditor.GetParentForm() == form) { | |
oEditor.UpdateLinkedField(); | |
} | |
} | |
} | |
} catch (e) {} | |
form.elements['formOp'].value = action; | |
if (!form.originalAction) form.originalAction = form.action; | |
form.action = form.originalAction + encodeURI(params); | |
this.ajaxPagePost(form, null); | |
}; | |
UIForm.prototype.ajaxPagePost = function (formElement, callback) { | |
if (!callback) callback = null; | |
var queryString = eXo.webui.UIForm.serializeForm(formElement); | |
var url = formElement.action; | |
this.doPageRequest("POST", url, queryString, callback); | |
}; | |
UIForm.prototype.doPageRequest = function (method, url, queryString, callback) { | |
request = new AjaxRequest(method, url, queryString); | |
handler = new HttpResponseHandler(); | |
request.onSuccess = function (request) { | |
try { | |
var url = request.responseText; | |
url = url.substring(url.indexOf("eXo.env.server.portalBaseURL")); | |
url = url.substring(0, url.indexOf("eXo.env.server.portalURLTemplate")); | |
eval(url); | |
} catch (e) {} | |
ajaxRedirect(eXo.env.server.portalBaseURL); | |
}; | |
request.onLoading = handler.ajaxLoading; | |
request.onTimeout = handler.ajaxTimeout; | |
request.callBack = callback; | |
eXo.portal.CurrentRequest = request; | |
request.process(); | |
eXo.session.itvDestroy(); | |
if (eXo.session.canKeepState && eXo.session.isOpen && eXo.env.portal.accessMode == 'private') { | |
eXo.session.itvInit(); | |
} | |
}; | |
eXo.wiki.UIForm = new UIForm(); | |
if (!eXo.wiki) eXo.wiki = {}; | |
function UIUpload() { | |
this.listUpload = new Array(); | |
this.isAutoUpload = false; | |
}; | |
UIUpload.prototype.initUploadEntry = function (uploadId, isAutoUpload) { | |
var url = eXo.env.server.context + "/upload?"; | |
url += "action=progress&uploadId=" + uploadId; | |
var responseText = ajaxAsyncGetRequest(url, false); | |
var response; | |
try { | |
eval("response = " + responseText); | |
} catch (err) { | |
return; | |
} | |
UIUpload.isAutoUpload = isAutoUpload; | |
if (response.upload[uploadId] == undefined || response.upload[uploadId].percent == undefined) { | |
this.createUploadEntry(uploadId, isAutoUpload); | |
} else if (response.upload[uploadId].percent == 100) { | |
this.showUploaded(uploadId, decodeURIComponent(response.upload[uploadId].fileName)); | |
} | |
}; | |
UIUpload.prototype.createUploadEntry = function (uploadId, isAutoUpload) { | |
var me = eXo.wiki.UIUpload; | |
var iframe = document.getElementById(uploadId + 'uploadFrame'); | |
var idoc = iframe.contentWindow.document; | |
if (eXo.core.Browser.gecko) { | |
me.createUploadEntryForFF(idoc, uploadId, isAutoUpload); | |
return; | |
} | |
var uploadAction = eXo.env.server.context + "/upload?"; | |
uploadAction += "uploadId=" + uploadId + "&action=upload"; | |
var uploadHTML = ""; | |
uploadHTML += "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>"; | |
uploadHTML += "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='" + eXo.core.I18n.lang + "' dir='" + eXo.core.I18n.dir + "'>"; | |
uploadHTML += "<head>"; | |
uploadHTML += "<style type='text/css'>"; | |
uploadHTML += this.getStyleSheetContent(); | |
uploadHTML += "</style>"; | |
uploadHTML += "<script type='text/javascript'>var eXo = parent.eXo</script>"; | |
uploadHTML += "</head>"; | |
uploadHTML += "<body style='margin: 0px; border: 0px;'>"; | |
uploadHTML += this.getUploadContent(uploadId, uploadAction, isAutoUpload); | |
uploadHTML += "</body>"; | |
uploadHTML += "</html>"; | |
idoc.open(); | |
idoc.write(uploadHTML); | |
idoc.close(); | |
}; | |
UIUpload.prototype.createUploadEntryForFF = function (idoc, uploadId, isAutoUpload) { | |
var uploadAction = eXo.env.server.context + "/upload?"; | |
uploadAction += "uploadId=" + uploadId + "&action=upload"; | |
var newDoctype = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); | |
if (idoc.doctype) { | |
idoc.replaceChild(newDoctype, idoc.doctype); | |
} | |
idoc.lang = eXo.core.I18n.lang; | |
idoc.xmlns = 'http://www.w3.org/1999/xhtml'; | |
idoc.dir = eXo.core.I18n.dir; | |
idoc.head = idoc.head || idoc.getElementsByTagName('head')[0]; | |
var script = document.createElement('script'); | |
script.type = "text/javascript"; | |
script.text = "var eXo = parent.eXo"; | |
idoc.head = idoc.head || idoc.getElementsByTagName('head')[0]; | |
idoc.head.appendChild(script); | |
var style = document.createElement('style'); | |
style.type = "text/css"; | |
var styleText = this.getStyleSheetContent(); | |
var cssText = document.createTextNode(styleText); | |
style.appendChild(cssText); | |
idoc.head.appendChild(style); | |
idoc.body.innerHTML = this.getUploadContent(uploadId, uploadAction, isAutoUpload); | |
} | |
UIUpload.prototype.getUploadContent = function (uploadId, uploadAction, isAutoUpload) { | |
var container = parent.document.getElementById(uploadId); | |
var uploadIframe = eXo.core.DOMUtil.findDescendantById(container, uploadId + "UploadIframe"); | |
var uploadText = uploadIframe.title; | |
var uploadHTML = ""; | |
uploadHTML += " <form id='" + uploadId + "' class='UIUploadForm' style='margin: 0px; padding: 0px' action='" + uploadAction + "' enctype='multipart/form-data' method='post'>"; | |
uploadHTML += " <div class='BrowseDiv'>"; | |
uploadHTML += " <a class='BrowseLink'>"; | |
uploadHTML += " <input type='file' name='file' size='1' id='file' class='FileHidden' value='' onchange='eXo.wiki.UIUpload.upload(this, " + uploadId + ")'/>"; | |
uploadHTML += " " + uploadText + "</a>"; | |
uploadHTML += " </div>"; | |
uploadHTML += " </form>"; | |
return uploadHTML; | |
} | |
UIUpload.prototype.getStyleSheetContent = function () { | |
var styleText = ""; | |
styleText += ".UIUploadForm {position: relative; } "; | |
styleText += ".FileHidden { cursor: pointer; opacity: 0; overflow: hidden; position: absolute; height: 15px; top: 0px; left: 0px; width: 100%; -moz-opacity:0 ; filter:alpha(opacity: 0); z-index: 1;} "; | |
styleText += ".BrowseDiv {padding: 10px 0px 10px 0px;} "; | |
styleText += ".BrowseLink { cursor: pointer; position: relative; font-family: Arial, Helvetica, sans-serif; text-align: left; font-size: 12px; color: #165FB3; "; | |
styleText += " text-decoration: none; padding: 0px 0px 0px 20px;"; | |
styleText += " background: url('/wiki/skin/DefaultSkin/webui/UIWikiSearchBox/icons/16x16/AttachFileIcon.gif') no-repeat left top;)}"; | |
styleText += ".UIUploadForm a:hover {cursor: pointer; text-decoration: underline;}"; | |
return styleText; | |
} | |
UIUpload.prototype.refeshProgress = function (elementId) { | |
var list = eXo.wiki.UIUpload.listUpload; | |
if (list.length < 1) return; | |
var url = eXo.env.server.context + "/upload?"; | |
url += "action=progress"; | |
for (var i = 0; i < list.length; i++) { | |
url = url + "&uploadId=" + list[i]; | |
} | |
var responseText = ajaxAsyncGetRequest(url, false); | |
if (list.length > 0) { | |
setTimeout("eXo.wiki.UIUpload.refeshProgress('" + elementId + "');", 1000); | |
} | |
var response; | |
try { | |
eval("response = " + responseText); | |
} catch (err) { | |
return; | |
} | |
for (id in response.upload) { | |
var container = parent.document.getElementById(elementId); | |
if (response.upload[id].status == "failed") { | |
this.abortUpload(id); | |
var message = eXo.core.DOMUtil.findFirstChildByClass(container, "div", "LimitMessage").innerHTML; | |
alert(message.replace("{0}", response.upload[id].size)); | |
continue; | |
} | |
var element = document.getElementById(id + "ProgressIframe"); | |
var percent = response.upload[id].percent; | |
var progressBarMiddle = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarMiddle"); | |
var blueProgressBar = eXo.core.DOMUtil.findFirstChildByClass(progressBarMiddle, "div", "BlueProgressBar"); | |
var progressBarLabel = eXo.core.DOMUtil.findFirstChildByClass(blueProgressBar, "div", "ProgressBarLabel"); | |
blueProgressBar.style.width = percent + "%"; | |
progressBarLabel.innerHTML = percent + "%"; | |
if (percent == 100) { | |
var postUploadActionNode = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "PostUploadAction"); | |
if (postUploadActionNode) { | |
eXo.wiki.UIUpload.listUpload.remove(elementId); | |
postUploadActionNode.onclick(); | |
} else { | |
this.showUploaded(id, ""); | |
} | |
} | |
} | |
if (eXo.wiki.UIUpload.listUpload.length < 1) return; | |
if (element) { | |
element.innerHTML = "Uploaded " + percent + "% " + "<span onclick='parent.eXo.wiki.UIUpload.abortUpload(" + id + ")'>Abort</span>"; | |
} | |
}; | |
UIUpload.prototype.showUploaded = function (id, fileName) { | |
eXo.wiki.UIUpload.listUpload.remove(id); | |
var container = parent.document.getElementById(id); | |
var element = document.getElementById(id + "ProgressIframe"); | |
element.innerHTML = "<span></span>"; | |
var uploadIframe = eXo.core.DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "none"; | |
var progressIframe = eXo.core.DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var selectFileFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "SelectFileFrame"); | |
var fileNameLabel = eXo.core.DOMUtil.findFirstDescendantByClass(selectFileFrame, "div", "FileNameLabel"); | |
if (fileName != null) fileNameLabel.innerHTML += " " + fileName; | |
var progressBarFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "none"; | |
var tmp = element.parentNode; | |
var temp = tmp.parentNode; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "true"; | |
}; | |
UIUpload.prototype.abortUpload = function (id) { | |
eXo.wiki.UIUpload.listUpload.remove(id); | |
var url = eXo.env.server.context + "/upload?"; | |
url += "uploadId=" + id + "&action=abort"; | |
var request = eXo.core.Browser.createHttpRequest(); | |
request.open('GET', url, false); | |
request.setRequestHeader("Cache-Control", "max-age=86400"); | |
request.send(null); | |
var container = parent.document.getElementById(id); | |
var uploadIframe = eXo.core.DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "block"; | |
eXo.wiki.UIUpload.createUploadEntry(id, UIUpload.isAutoUpload); | |
var progressIframe = eXo.core.DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var tmp = progressIframe.parentNode; | |
var temp = tmp.parentNode; | |
var progressBarFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "none"; | |
var selectFileFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "SelectFileFrame"); | |
selectFileFrame.style.display = "none"; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "false"; | |
}; | |
UIUpload.prototype.deleteUpload = function (id) { | |
var url = eXo.env.server.context + "/upload?"; | |
url += "uploadId=" + id + "&action=delete"; | |
var request = eXo.core.Browser.createHttpRequest(); | |
request.open('GET', url, false); | |
request.setRequestHeader("Cache-Control", "max-age=86400"); | |
request.send(null); | |
var DOMUtil = eXo.core.DOMUtil; | |
var container = parent.document.getElementById(id); | |
var uploadIframe = DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "block"; | |
eXo.wiki.UIUpload.createUploadEntry(id, UIUpload.isAutoUpload); | |
var progressIframe = DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var tmp = progressIframe.parentNode; | |
var temp = tmp.parentNode; | |
var progressBarFrame = DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "none"; | |
var selectFileFrame = DOMUtil.findFirstDescendantByClass(container, "div", "SelectFileFrame"); | |
selectFileFrame.style.display = "none"; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "false"; | |
}; | |
UIUpload.prototype.upload = function (clickEle, id) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var container = parent.document.getElementById(id); | |
var uploadFrame = parent.document.getElementById(id + "uploadFrame"); | |
var form = uploadFrame.contentWindow.document.getElementById(id); | |
var file = DOMUtil.findDescendantById(form, "file"); | |
if (file.value == null || file.value == '') return; | |
var infoUploaded = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "FileNameLabel"); | |
var temp = file.value; | |
if (temp.indexOf('/') != -1) { | |
temp = temp.substr((temp.lastIndexOf('/') + 1), temp.length - 1); | |
} | |
if (temp.indexOf('\\') != -1) { | |
temp = temp.substr((temp.lastIndexOf('\\') + 1), temp.length - 1); | |
} | |
infoUploaded.innerHTML = temp; | |
var progressBarFrame = DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "block"; | |
var progressBarMiddle = DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarMiddle"); | |
var blueProgressBar = DOMUtil.findFirstChildByClass(progressBarMiddle, "div", "BlueProgressBar"); | |
var progressBarLabel = DOMUtil.findFirstChildByClass(blueProgressBar, "div", "ProgressBarLabel"); | |
blueProgressBar.style.width = "0%"; | |
progressBarLabel.innerHTML = "0%"; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "true"; | |
var uploadIframe = DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "none"; | |
var progressIframe = DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var tmp = progressIframe.parentNode; | |
var temp = tmp.parentNode; | |
form.submit(); | |
var list = eXo.wiki.UIUpload.listUpload; | |
if (list.length == 0) { | |
eXo.wiki.UIUpload.listUpload.push(form.id); | |
setTimeout("eXo.wiki.UIUpload.refeshProgress('" + id + "');", 1000); | |
} else { | |
eXo.wiki.UIUpload.listUpload.push(form.id); | |
} | |
}; | |
UIUpload.prototype.validate = function (name) { | |
if (name.indexOf(':') >= 0 || name.indexOf('/') >= 0 || name.indexOf('\\') >= 0 || name.indexOf('|') >= 0 || name.indexOf('^') >= 0 || name.indexOf('#') >= 0 || name.indexOf(';') >= 0 || name.indexOf('[') >= 0 || name.indexOf(']') >= 0 || name.indexOf('{') >= 0 || name.indexOf('}') >= 0 || name.indexOf('<') >= 0 || name.indexOf('>') >= 0 || name.indexOf('*') >= 0 || name.indexOf('\'') >= 0 || name.indexOf('\"') >= 0 || name.indexOf('+') >= 0) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
eXo.wiki.UIUpload = new UIUpload(); | |
function UIWikiPagePreview() {}; | |
UIWikiPagePreview.prototype.init = function (maskId) { | |
var maskWorkpace = document.getElementById(maskId); | |
if (maskWorkpace) { | |
var pagePreview = eXo.core.DOMUtil.findFirstDescendantByClass(maskWorkpace, "div", "UIWikiPagePreview"); | |
if (pagePreview) { | |
pagePreview.style.height = eXo.core.Browser.getBrowserHeight() - 33 + "px"; | |
eXo.portal.UIMaskWorkspace.resetPosition(); | |
} | |
} | |
}; | |
eXo.wiki.UIWikiPagePreview = new UIWikiPagePreview(); | |
function UIWikiSavePage() {}; | |
UIWikiSavePage.prototype.confirm = function (uicomponentId, isNewMode, pageTitleInputId, untitled, titleMessage, addMessage, submitClass, submitLabel, cancelLabel) { | |
var pageTitleInput = document.getElementById(pageTitleInputId); | |
if (isNewMode == true && (pageTitleInput.value == untitled)) { | |
eXo.wiki.UIConfirmBox.render(uicomponentId, titleMessage, addMessage, submitClass, submitLabel, cancelLabel); | |
return false; | |
} | |
return true; | |
}; | |
eXo.wiki.UIWikiSavePage = new UIWikiSavePage(); | |
function UIWikiAjaxRequest() { | |
this.DEFAULT_TIMEOUT_CHECK = 100; | |
this.autoCheckAnchorId = false; | |
this.actionPrefix = false; | |
this.defaultAction = false; | |
this.currentAnchor = null; | |
this.isEnableCheck = true; | |
}; | |
UIWikiAjaxRequest.prototype.init = function (actionPrefix, defaultAction) { | |
this.actionPrefix = actionPrefix; | |
this.defaultAction = defaultAction; | |
this.isEnableCheck = true; | |
if (this.actionPrefix && this.defaultAction) { | |
this.autoCheckAnchorId = window.setInterval(this.autoCheckAnchor, this.DEFAULT_TIMEOUT_CHECK); | |
this.addEventListener(window, 'unload', this.destroyAll, false); | |
if (eXo.core.Browser.ie) { | |
this.createIEHistoryFrame(); | |
} | |
} | |
}; | |
UIWikiAjaxRequest.prototype.autoCheckAnchor = function () { | |
eXo.wiki.UIWikiAjaxRequest.checkAnchor(); | |
}; | |
UIWikiAjaxRequest.prototype.getCurrentHash = function () { | |
var r = window.location.href; | |
var i = r.indexOf("#"); | |
return (i >= 0 ? r.substr(i + 1) : false); | |
}; | |
UIWikiAjaxRequest.prototype.urlHasActionParameters = function () { | |
var r = window.location.href; | |
var i = r.indexOf("?"); | |
if (i >= 0) { | |
r = r.substr(i + 1); | |
if (r && r.length > 0) { | |
i = r.indexOf("action="); | |
if (i >= 0) { | |
return true; | |
} | |
i = r.indexOf("op="); | |
return (i >= 0 ? true : false); | |
} | |
} | |
return false; | |
}; | |
UIWikiAjaxRequest.prototype.checkAnchor = function () { | |
if (this.currentAnchor != this.getCurrentHash()) { | |
this.currentAnchor = this.getCurrentHash(); | |
if (this.isEnableCheck == false) { | |
this.isEnableCheck = true; | |
return; | |
} | |
var action = null; | |
if (this.currentAnchor && this.currentAnchor.length > 0) { | |
var splits = this.currentAnchor.split('&'); | |
action = splits[0]; | |
if (action && action.length > 0 && action.charAt(0) == 'H') { | |
return; | |
} | |
action = document.getElementById(this.actionPrefix + action); | |
var queryParams = ''; | |
for (var index = 1; index < splits.length; index++) { | |
queryParams += '&'; | |
queryParams += splits[index]; | |
} | |
if (action) { | |
var ajaxGetLink = action.getAttributeNode('onclick').value.replace('&ajaxRequest=true', queryParams + '&ajaxRequest=true'); | |
action.onclick = function () { | |
eval(ajaxGetLink); | |
}; | |
} | |
} else if (!this.urlHasActionParameters()) { | |
action = document.getElementById(this.actionPrefix + this.defaultAction); | |
} | |
if (action) { | |
action.onclick(); | |
} | |
} | |
}; | |
UIWikiAjaxRequest.prototype.createIEHistoryFrame = function () { | |
var iframeID = 'rshHistoryFrame'; | |
this.iframe = document.getElementById(iframeID); | |
if (!this.iframe) { | |
var tmpIframe = document.createElement('iframe'); | |
tmpIframe.id = iframeID; | |
tmpIframe.style.display = 'none'; | |
document.body.appendChild(tmpIframe); | |
this.iframe = tmpIframe; | |
eXo.wiki.UIWikiAjaxRequest.makeNewHash(location.hash); | |
} | |
}; | |
UIWikiAjaxRequest.prototype.onFrameLoaded = function (hash) { | |
location.hash = hash; | |
}; | |
UIWikiAjaxRequest.prototype.makeNewHash = function (hash) { | |
if (eXo.core.Browser.ie) { | |
var doc = document.getElementById("rshHistoryFrame").contentWindow.document; | |
doc.open("javascript:'<html></html>'"); | |
doc.write("<html><head></head><body onload=\"parent.eXo.wiki.UIWikiAjaxRequest.onFrameLoaded('" + hash + "');\"></body></html>"); | |
doc.close(); | |
} else { | |
this.onFrameLoaded(hash); | |
} | |
}; | |
UIWikiAjaxRequest.prototype.makeHash = function (hash) { | |
this.isEnableCheck = false; | |
eXo.wiki.UIWikiAjaxRequest.makeNewHash(hash); | |
}; | |
UIWikiAjaxRequest.prototype.stopAutoCheckAnchor = function () { | |
if (this.autoCheckAnchorId) { | |
window.clearInterval(this.autoCheckAnchorId); | |
this.autoCheckAnchorId = false; | |
} | |
}; | |
UIWikiAjaxRequest.prototype.addEventListener = function (node, eventType, handler, allowBubble) { | |
if ((!node || !node.nodeName) && node != window) { | |
throw (new Error('Can not add event listener for null or not DOM Element object')); | |
} | |
if (node.addEventListener) { | |
node.addEventListener(eventType, handler, allowBubble); | |
} else { | |
node.attachEvent('on' + eventType, handler, allowBubble); | |
} | |
}; | |
UIWikiAjaxRequest.prototype.destroyAll = function () { | |
eXo.wiki.UIWikiAjaxRequest.stopAutoCheckAnchor(); | |
}; | |
eXo.wiki.UIWikiAjaxRequest = new UIWikiAjaxRequest(); | |
function UIDropdownMenu() {}; | |
UIDropdownMenu.prototype.init = function (componentid) { | |
var component = document.getElementById(componentid); | |
var me = eXo.wiki.UIDropdownMenu; | |
var menu = eXo.core.DOMUtil.findDescendantsByClass(component, "div", "HoverMenu")[0]; | |
component.onmouseover = function (e) { | |
return me.hover(menu, true); | |
} | |
component.onmouseout = function (e) { | |
return me.hover(menu, false); | |
} | |
menu.onmouseover = function (e) { | |
return me.hover(this, true); | |
} | |
menu.onmouseout = function (e) { | |
return me.hover(this, false); | |
} | |
}; | |
UIDropdownMenu.prototype.hover = function (menu, state) { | |
if (state == true) { | |
menu.style.display = "block"; | |
} else { | |
menu.style.display = "none"; | |
} | |
}; | |
eXo.wiki.UIDropdownMenu = new UIDropdownMenu(); | |
eXo.require("eXo.core.EventManager"); | |
if (eXo.wiki.UITreeExplorer == null) { | |
eXo.wiki.UITreeExplorer = {}; | |
}; | |
function UITreeExplorer() {}; | |
UITreeExplorer.prototype.init = function (componentid, initParam, isFullRender) { | |
var me = eXo.wiki.UITreeExplorer; | |
var component = document.getElementById(componentid); | |
if (component == null) { | |
var editForm = document.getElementById('UIWikiPageEditForm'); | |
var ifm = eXo.core.DOMUtil.findFirstDescendantByClass(editForm, 'iframe', 'gwt-RichTextArea'); | |
me.innerDoc = ifm.contentDocument || ifm.contentWindow.document; | |
component = me.innerDoc.getElementById(componentid); | |
} | |
var initURL = eXo.core.DOMUtil.findFirstDescendantByClass(component, "input", "InitURL"); | |
var initNode = eXo.core.DOMUtil.findFirstDescendantByClass(component, "div", "NodeGroup"); | |
initParam = me.cleanParam(initParam); | |
me.render(initParam, initNode, isFullRender); | |
}; | |
UITreeExplorer.prototype.collapseExpand = function (element) { | |
var node = element.parentNode; | |
var subGroup = eXo.core.DOMUtil.findFirstChildByClass(node, "div", "NodeGroup"); | |
if (element.className == "EmptyIcon") return true; | |
if (!subGroup) return false; | |
if (subGroup.style.display == "none") { | |
if (element.className == "ExpandIcon") element.className = "CollapseIcon"; | |
subGroup.style.display = "block"; | |
} else { | |
if (element.className == "CollapseIcon") element.className = "ExpandIcon"; | |
subGroup.style.display = "none"; | |
} | |
return true; | |
}; | |
UITreeExplorer.prototype.onNodeClick = function (node, absPath) { | |
var me = eXo.wiki.UITreeExplorer; | |
var selectableObj = eXo.core.DOMUtil.findDescendantsByTagName(node, "a"); | |
if (selectableObj.length > 0) { | |
var component = eXo.core.DOMUtil.findAncestorByClass(node, "UITreeExplorer"); | |
var selectedNode = eXo.core.DOMUtil.findFirstDescendantByClass(component, "div", "Hover"); | |
if (selectedNode) eXo.core.DOMUtil.removeClass(selectedNode, "Hover"); | |
if (!eXo.core.DOMUtil.hasClass(node, "Hover")) eXo.core.DOMUtil.addClass(node, "Hover"); | |
me.selectNode(node, absPath); | |
} | |
}; | |
UITreeExplorer.prototype.selectNode = function (node, nodePath) { | |
var me = eXo.wiki.UITreeExplorer; | |
var component = eXo.core.DOMUtil.findAncestorByClass(node, "UITreeExplorer"); | |
var root = eXo.core.DOMUtil.findAncestorByClass(node, "UITreeExplorer"); | |
var link = eXo.core.DOMUtil.findFirstDescendantByClass(component, "a", "SelectNode"); | |
var endParamIndex = link.href.lastIndexOf("')"); | |
var param = "&objectId"; | |
var modeIndex = link.href.indexOf(param); | |
if (endParamIndex > 0) { | |
if (modeIndex < 0) link.href = link.href.substring(0, endParamIndex) + param + "=" + nodePath + "')"; | |
else link.href = link.href.substring(0, modeIndex) + param + "=" + nodePath + "')"; | |
} else { | |
if (modeIndex < 0) link.href = link.href.substring(0, link.href.length) + param + "=" + nodePath; | |
else link.href = link.href.substring(0, modeIndex) + param + "=" + nodePath; | |
} | |
window.location = link.href; | |
}; | |
UITreeExplorer.prototype.render = function (param, element, isFullRender) { | |
var me = eXo.wiki.UITreeExplorer; | |
var node = element.parentNode; | |
var component = eXo.core.DOMUtil.findAncestorByClass(node, "UITreeExplorer"); | |
var url = eXo.core.DOMUtil.findFirstDescendantByClass(component, "input", "ChildrenURL").value; | |
if (isFullRender) { | |
url = eXo.core.DOMUtil.findFirstDescendantByClass(component, "input", "InitURL").value; | |
} | |
var http = eXo.wiki.UITreeExplorer.getHTTPObject(); | |
var restURL = url + param; | |
http.open("GET", restURL, true); | |
http.onreadystatechange = function () { | |
if (http.readyState == 4) { | |
me.renderTreeNodes(node, http.responseText); | |
} | |
} | |
http.send(""); | |
element.className = "CollapseIcon"; | |
}; | |
UITreeExplorer.prototype.getHTTPObject = function () { | |
if (typeof XMLHttpRequest != 'undefined') { | |
return new XMLHttpRequest(); | |
} | |
try { | |
return new ActiveXObject("Msxml2.XMLHTTP"); | |
} catch (e) { | |
try { | |
return new ActiveXObject("Microsoft.XMLHTTP"); | |
} catch (e) {} | |
} | |
return false; | |
}; | |
UITreeExplorer.prototype.renderTreeNodes = function (parentNode, responseText) { | |
var me = eXo.wiki.UITreeExplorer; | |
var dataList = JSON.parse(responseText); | |
var resultLength = dataList.jsonList.length; | |
var childBlock = document.createElement("div"); | |
if (me.innerDoc) { | |
childBlock = me.innerDoc.createElement("div"); | |
me.innerDoc = null; | |
} | |
childBlock.className = "NodeGroup"; | |
var str = ""; | |
for (var i = 0; i < resultLength; i++) { | |
str += me.buildNode(dataList.jsonList[i]); | |
} | |
childBlock.innerHTML = str; | |
parentNode.appendChild(childBlock); | |
} | |
UITreeExplorer.prototype.buildHierachyNode = function (data) { | |
var me = eXo.wiki.UITreeExplorer; | |
var children = data.children; | |
var childBlock = "<div class=\"NodeGroup\">"; | |
for (var i = 0; i < children.length; i++) { | |
childBlock += me.buildNode(children[i]); | |
} | |
childBlock += "</div>"; | |
return childBlock | |
} | |
UITreeExplorer.prototype.buildNode = function (data) { | |
var me = eXo.wiki.UITreeExplorer; | |
var nodeName = data.name; | |
var nodeType = data.nodeType; | |
var nodeTypeCSS = nodeType.substring(0, 1).toUpperCase() + nodeType.substring(1).toLowerCase(); | |
var iconType = (data.expanded == true) ? "Collapse" : "Expand"; | |
var lastNodeClass = ""; | |
var hoverClass = ""; | |
var excerptData = data.excerpt; | |
var path = data.path.replaceAll("/", "."); | |
var param = "?path=" + path; | |
if (excerptData != null) { | |
param += "&excerpt=true"; | |
} | |
if (data.extendParam) param += "¤t=" + data.extendParam.replaceAll("/", "."); | |
if (data.lastNode == true) { | |
lastNodeClass = "LastNode"; | |
} | |
if (data.hasChild == false) { | |
iconType = "Empty"; | |
} | |
if (data.selected == true) { | |
hoverClass = "Hover"; | |
} | |
var childNode = ""; | |
childNode += " <div class=\"" + lastNodeClass + " Node\" >"; | |
childNode += " <div class=\"" + iconType + "Icon\" id=\"" + path + "\" onclick=\"event.cancelBubble=true; if(eXo.wiki.UITreeExplorer.collapseExpand(this)) return; eXo.wiki.UITreeExplorer.render('" + param + "', this)\">"; | |
childNode += " <div id=\"iconTreeExplorer\" onclick=\"event.cancelBubble=true; eXo.wiki.UITreeExplorer.onNodeClick(this,'" + path + "', false " + ")\"" + "class=\"" + nodeTypeCSS + " TreeNodeType Node " + hoverClass + " \">"; | |
childNode += " <div class='NodeLabel'>"; | |
if (data.selectable == true) { | |
childNode += " <a title=\"" + nodeName + "\">" + nodeName + "</a>"; | |
} else { | |
childNode += " <span style=\"cursor:auto\" title=\"" + nodeName + "\">" + nodeName + "</span>"; | |
} | |
if (excerptData != null) { | |
childNode += excerptData; | |
} | |
childNode += " </div>"; | |
childNode += " </div>"; | |
childNode += " </div>"; | |
if (data.children.length > 0) { | |
childNode += me.buildHierachyNode(data); | |
} | |
childNode += " </div>"; | |
return childNode; | |
} | |
UITreeExplorer.prototype.cleanParam = function (data) { | |
return data.replace(/&/g, "&"); | |
} | |
eXo.wiki.UITreeExplorer = new UITreeExplorer(); | |
function UIWikiMaskLayer() {}; | |
UIWikiMaskLayer.prototype.createTransparentMask = function () { | |
var Browser = eXo.core.Browser; | |
var ajaxLoading = document.getElementById("AjaxLoadingMask"); | |
var maskLayer = eXo.wiki.UIWikiMaskLayer.createMask("UIPortalApplication", ajaxLoading, 0); | |
Browser.addOnScrollCallback("5439383", eXo.wiki.UIWikiMaskLayer.setPosition); | |
ajaxLoading.style.display = "none"; | |
Browser.setOpacity(maskLayer, 0); | |
maskLayer.style.backgroundColor = "white"; | |
maskLayer.style.cursor = "wait"; | |
return maskLayer; | |
}; | |
UIWikiMaskLayer.prototype.showAjaxLoading = function (mask) { | |
var ajaxLoading = document.getElementById("AjaxLoadingMask"); | |
ajaxLoading.style.display = "block"; | |
eXo.core.Browser.setOpacity(mask, 30); | |
mask.style.backgroundColor = "black"; | |
} | |
UIWikiMaskLayer.prototype.removeTransparentMask = function () { | |
var mask = document.getElementById("TransparentMaskLayer"); | |
if (mask) { | |
mask.style.height = "0px"; | |
mask.style.width = "0px"; | |
} | |
}; | |
UIWikiMaskLayer.prototype.removeMasks = function (maskLayer) { | |
eXo.wiki.UIWikiMaskLayer.removeTransparentMask(); | |
eXo.wiki.UIWikiMaskLayer.removeMask(maskLayer); | |
}; | |
UIWikiMaskLayer.prototype.createMask = function (blockContainerId, object, opacity, position) { | |
try { | |
var Browser = eXo.core.Browser; | |
var blockContainer = document.getElementById(blockContainerId); | |
var maskLayer = document.createElement("div"); | |
this.object = object; | |
maskLayer.object = object; | |
this.blockContainer = blockContainer; | |
this.position = position; | |
if (document.getElementById("MaskLayer")) { | |
document.getElementById("MaskLayer").id = "subMaskLayer"; | |
} | |
blockContainer.appendChild(maskLayer); | |
maskLayer.className = "MaskLayer"; | |
maskLayer.id = "MaskLayer"; | |
maskLayer.maxZIndex = 4; | |
maskLayer.style.width = Browser.getBrowserWidth() + "px"; | |
maskLayer.style.height = Browser.getBrowserHeight() + "px"; | |
maskLayer.style.top = "0px"; | |
maskLayer.style.left = "0px"; | |
maskLayer.style.zIndex = maskLayer.maxZIndex; | |
if (opacity) { | |
Browser.setOpacity(maskLayer, opacity); | |
} | |
if (object != null) { | |
if (object.nextSibling) { | |
maskLayer.nextSiblingOfObject = object.nextSibling; | |
maskLayer.parentOfObject = null; | |
} else { | |
maskLayer.nextSiblingOfObject = null; | |
maskLayer.parentOfObject = object.parentNode; | |
} | |
object.style.zIndex = maskLayer.maxZIndex; | |
object.style.display = "block"; | |
blockContainer.appendChild(object); | |
eXo.wiki.UIWikiMaskLayer.setPosition(); | |
if (eXo.core.I18n.isLT()) { | |
if ((blockContainer.offsetWidth > object.offsetLeft + object.offsetWidth) && (position == "TOP-RIGHT") || (position == "BOTTOM-RIGHT")) { | |
object.style.left = blockContainer.offsetWidth - object.offsetWidth + "px"; | |
} | |
} | |
eXo.wiki.UIWikiMaskLayer.doScroll(); | |
} | |
if (maskLayer.parentNode.id == "UIPage") { | |
eXo.wiki.UIWikiMaskLayer.enablePageDesktop(false); | |
} | |
} catch (err) { | |
alert(err); | |
} | |
Browser.addOnResizeCallback(maskLayer.id, eXo.wiki.UIWikiMaskLayer.resizeMaskLayer); | |
return maskLayer; | |
}; | |
UIWikiMaskLayer.prototype.createMaskForFrame = function (blockContainerId, object, opacity) { | |
try { | |
var Browser = eXo.core.Browser; | |
if (typeof (blockContainerId) == "string") blockContainerId = document.getElementById(blockContainerId); | |
var blockContainer = blockContainerId; | |
var maskLayer = document.createElement("div"); | |
blockContainer.appendChild(maskLayer); | |
maskLayer.className = "MaskLayer"; | |
maskLayer.id = object.id + "MaskLayer"; | |
maskLayer.maxZIndex = 3; | |
maskLayer.style.width = blockContainer.offsetWidth + "px"; | |
maskLayer.style.height = blockContainer.offsetHeight + eXo.core.Browser.findPosY(blockContainer) + "px"; | |
maskLayer.style.top = "0px"; | |
maskLayer.style.left = "0px"; | |
maskLayer.style.zIndex = maskLayer.maxZIndex; | |
if (opacity) { | |
Browser.setOpacity(maskLayer, opacity); | |
} | |
if (object != null) { | |
if (object.nextSibling) { | |
maskLayer.nextSiblingOfObject = object.nextSibling; | |
maskLayer.parentOfObject = null; | |
} else { | |
maskLayer.nextSiblingOfObject = null; | |
maskLayer.parentOfObject = object.parentNode; | |
} | |
object.style.zIndex = maskLayer.maxZIndex + 1; | |
object.style.display = "block"; | |
blockContainer.appendChild(object); | |
} | |
} catch (err) {} | |
return maskLayer; | |
}; | |
UIWikiMaskLayer.prototype.doScroll = function () { | |
if (document.getElementById("MaskLayer")) { | |
var maskLayer = document.getElementById("MaskLayer"); | |
if (maskLayer.object) { | |
if (document.documentElement && document.documentElement.scrollTop) { | |
maskLayer.style.top = document.documentElement.scrollTop + "px"; | |
maskLayer.object.style.top = document.documentElement.scrollTop + "px"; | |
} else { | |
maskLayer.style.top = document.body.scrollTop + "px"; | |
maskLayer.object.style.top = document.body.scrollTop + "px"; | |
} | |
} | |
setTimeout("eXo.wiki.UIWikiMaskLayer.doScroll()", 1); | |
} else if (document.getElementById("subMaskLayer")) { | |
var subMaskLayer = document.getElementById("subMaskLayer"); | |
subMaskLayer.id = "MaskLayer"; | |
eXo.wiki.UIWikiMaskLayer.doScroll(); | |
} | |
}; | |
UIWikiMaskLayer.prototype.setPosition = function () { | |
var UIWikiMaskLayer = eXo.wiki.UIWikiMaskLayer; | |
var Browser = eXo.core.Browser; | |
var object = UIWikiMaskLayer.object; | |
var blockContainer = UIWikiMaskLayer.blockContainer; | |
var position = UIWikiMaskLayer.position; | |
object.style.position = "absolute"; | |
var left; | |
var top; | |
var topPos; | |
if (document.documentElement && document.documentElement.scrollTop) { | |
topPos = document.documentElement.scrollTop; | |
} else { | |
topPos = document.body.scrollTop; | |
} | |
if (position == "TOP-LEFT") { | |
left = 0; | |
top = 0; | |
} else if (position == "TOP-RIGHT") { | |
return; | |
} else if (position == "BOTTOM-LEFT") { | |
left = 0; | |
top = Browser.getBrowserHeight() - object.offsetHeight + topPos; | |
} else if (position == "BOTTOM-RIGHT") { | |
left = blockContainer.offsetWidth - object.offsetWidth; | |
top = Browser.getBrowserHeight() - object.offsetHeight + topPos; | |
} else { | |
left = (blockContainer.offsetWidth - object.offsetWidth) / 2; | |
top = (Browser.getBrowserHeight() - object.offsetHeight) / 2 + topPos; | |
} | |
object.style.left = left + "px"; | |
object.style.top = top + "px"; | |
}; | |
UIWikiMaskLayer.prototype.removeMask = function (maskLayer) { | |
if (maskLayer) { | |
var parentNode = maskLayer.parentNode; | |
maskLayer.nextSibling.style.display = "none"; | |
if (maskLayer.nextSiblingOfObject) { | |
if (maskLayer.nextSiblingOfObject.parentNode) { | |
maskLayer.nextSiblingOfObject.parentNode.insertBefore(maskLayer.nextSibling, maskLayer.nextSiblingOfObject); | |
maskLayer.nextSiblingOfObject = null; | |
} else parentNode.removeChild(maskLayer.object); | |
} else { | |
maskLayer.parentOfObject.appendChild(maskLayer.nextSibling); | |
maskLayer.parentOfObject = null; | |
} | |
parentNode.removeChild(maskLayer); | |
} | |
}; | |
UIWikiMaskLayer.prototype.enablePageDesktop = function (enabled) { | |
var pageDesktop = document.getElementById("UIPageDesktop"); | |
if (pageDesktop) { | |
if (enabled) { | |
pageDesktop.style.zIndex = ""; | |
} else { | |
pageDesktop.style.zIndex = "-1"; | |
} | |
} | |
}; | |
UIWikiMaskLayer.prototype.resizeMaskLayer = function () { | |
var maskLayer = document.getElementById("MaskLayer"); | |
if (maskLayer) { | |
maskLayer.style.width = eXo.core.Browser.getBrowserWidth() + "px"; | |
maskLayer.style.height = eXo.core.Browser.getBrowserHeight() + "px"; | |
} | |
}; | |
eXo.wiki.UIWikiMaskLayer = new UIWikiMaskLayer(); | |
function UIWikiMaskWorkspace() {}; | |
UIWikiMaskWorkspace.prototype.init = function (maskId, show, width, height) { | |
var maskWorkpace = document.getElementById(maskId); | |
this.maskWorkpace = maskWorkpace; | |
if (this.maskWorkpace) { | |
if (width > -1) this.maskWorkpace.style.width = width + "px"; | |
if (show) { | |
if (eXo.wiki.UIWikiMaskWorkspace.maskLayer == null) { | |
var maskLayer = eXo.wiki.UIWikiMaskLayer.createMask("UIPortalApplication", this.maskWorkpace, 30); | |
eXo.wiki.UIWikiMaskWorkspace.maskLayer = maskLayer; | |
} | |
this.maskWorkpace.style.margin = "auto"; | |
this.maskWorkpace.style.display = "block"; | |
} else { | |
if (eXo.wiki.UIWikiMaskWorkspace.maskLayer == undefined) return; | |
eXo.wiki.UIWikiMaskLayer.removeMask(eXo.wiki.UIWikiMaskWorkspace.maskLayer); | |
eXo.wiki.UIWikiMaskWorkspace.maskLayer = null; | |
this.maskWorkpace.style.display = "none"; | |
} | |
if (height < 0) return; | |
} | |
}; | |
UIWikiMaskWorkspace.prototype.resetPosition = function () { | |
var maskWorkpace = eXo.wiki.UIWikiMaskWorkspace.maskWorkpace; | |
if (maskWorkpace && (maskWorkpace.style.display == "block")) { | |
try { | |
eXo.wiki.UIWikiMaskLayer.blockContainer = document.getElementById("UIPortalApplication"); | |
eXo.wiki.UIWikiMaskLayer.object = maskWorkpace; | |
eXo.wiki.UIWikiMaskLayer.setPosition(); | |
} catch (e) {} | |
} | |
}; | |
eXo.wiki.UIWikiMaskWorkspace = new UIWikiMaskWorkspace(); | |
function UIWikiPageVersionsList() {}; | |
UIWikiPageVersionsList.prototype.init = function (formId) { | |
var me = eXo.wiki.UIWikiPageVersionsList; | |
var DOMUtil = eXo.core.DOMUtil; | |
me.selectedCheckbox = new Array(); | |
var versionListForm = document.getElementById(formId); | |
var inputs = DOMUtil.findDescendantsByTagName(versionListForm, "input"); | |
this.compareButton = DOMUtil.findFirstDescendantByClass(versionListForm, "a", "RefreshModeTarget"); | |
this.compareButton.onclick = function (evt) { | |
if (me.selectedCheckbox.length == 2) { | |
eXo.wiki.UIWikiAjaxRequest.makeNewHash("#CompareRevision"); | |
} | |
}; | |
var ln = inputs.length; | |
var countCheckBox = 0; | |
for (var i = 0; i < ln; i++) { | |
var input = inputs[i]; | |
if (input.type == "checkbox") { | |
input.checked = false; | |
eXo.core.Browser.eventListener(input, 'click', me.onCheck); | |
countCheckBox++; | |
} | |
} | |
this.compareButton.className = "ActionButton LightBlueStyle DisableButton RefreshModeTarget"; | |
}; | |
UIWikiPageVersionsList.prototype.onCheck = function (evt) { | |
var me = eXo.wiki.UIWikiPageVersionsList; | |
var evt = evt || window.event; | |
var target = evt.target || evt.srcElement; | |
if (target.checked == true) { | |
me.selectedCheckbox.push(target); | |
if (me.selectedCheckbox.length > 2) { | |
var popCheckbox = me.selectedCheckbox.shift(); | |
popCheckbox.checked = false; | |
} | |
} else { | |
me.selectedCheckbox.remove(target); | |
} | |
if (me.selectedCheckbox.length == 2) { | |
eXo.wiki.UIWikiPageVersionsList.compareButton.className = "ActionButton LightBlueStyle RefreshModeTarget"; | |
} else { | |
eXo.wiki.UIWikiPageVersionsList.compareButton.className = "ActionButton LightBlueStyle DisableButton RefreshModeTarget"; | |
} | |
}; | |
eXo.wiki.UIWikiPageVersionsList = new UIWikiPageVersionsList(); | |
if (!eXo.wiki) eXo.wiki = {}; | |
function UIFieldEditableForm() {}; | |
UIFieldEditableForm.prototype.init = function (componentId, parentId, titleId, inputId) { | |
var me = eXo.wiki.UIFieldEditableForm; | |
me.parentComponent = document.getElementById(parentId); | |
me.component = eXo.core.DOMUtil.findDescendantById(me.parentComponent, componentId); | |
var titleControl = eXo.core.DOMUtil.findDescendantById(me.parentComponent, titleId); | |
if (titleControl) { | |
me.fieldValue = titleControl.firstChild.data; | |
} | |
me.inputControl = eXo.core.DOMUtil.findDescendantById(me.component, inputId); | |
me.showInputLink = eXo.core.DOMUtil.findFirstChildByClass(me.component, "a", "ShowInput"); | |
me.submitLink = eXo.core.DOMUtil.findFirstChildByClass(me.component, "a", "SubmitLink"); | |
eXo.core.Browser.eventListener(document, 'click', me.onClick); | |
if (titleControl) { | |
eXo.core.Browser.eventListener(titleControl, 'click', me.onClickToChangeTitle); | |
} | |
if (me.inputControl) { | |
me.inputControl.form.onsubmit = function () { | |
return false; | |
}; | |
me.inputControl.focus(); | |
eXo.core.Browser.eventListener(me.inputControl, 'keyup', me.pressHandler); | |
} | |
}; | |
UIFieldEditableForm.prototype.onClickToChangeTitle = function (evt) { | |
var me = eXo.wiki.UIFieldEditableForm; | |
if (me.showInputLink || me.showInputLink.onclick) me.showInputLink.onclick(); | |
}; | |
UIFieldEditableForm.prototype.onClick = function (evt) { | |
var me = eXo.wiki.UIFieldEditableForm; | |
var evt = evt || window.event; | |
var target = evt.target || evt.srcElement; | |
if (me.inputControl && target != me.inputControl && target != me.component) { | |
var hideInputLink = eXo.core.DOMUtil.findFirstDescendantByClass(me.component, "a", "HideInput"); | |
hideInputLink.onclick(); | |
} | |
}; | |
UIFieldEditableForm.prototype.pressHandler = function (evt) { | |
var me = eXo.wiki.UIFieldEditableForm; | |
evt = window.event || evt; | |
var keyNum = eXo.core.Keyboard.getKeynum(evt); | |
if (evt.altKey || evt.ctrlKey || evt.shiftKey) return; | |
switch (keyNum) { | |
case 13: | |
me.enterHandler(evt); | |
break; | |
case 27: | |
break; | |
case 38: | |
break; | |
case 40: | |
break; | |
default: | |
break; | |
} | |
return; | |
}; | |
UIFieldEditableForm.prototype.enterHandler = function (evt) { | |
var me = eXo.wiki.UIFieldEditableForm; | |
var isChange = me.fieldValue != me.inputControl.value.trim(); | |
if (isChange == true) { | |
if (me.submitLink || me.submitLink.onclick) me.submitLink.onclick(); | |
} else { | |
var hideInputLink = eXo.core.DOMUtil.findFirstDescendantByClass(me.component, "a", "HideInput"); | |
hideInputLink.onclick(); | |
} | |
}; | |
eXo.wiki.UIFieldEditableForm = new UIFieldEditableForm(); | |
function UIWikiPageTitleControlArea() {}; | |
UIWikiPageTitleControlArea.prototype.init = function (componentId, inputId, untitledLabel, isAddMode) { | |
var component = document.getElementById(componentId); | |
var input = eXo.core.DOMUtil.findDescendantById(component, inputId); | |
if (input) { | |
input.form.onsubmit = function () { | |
return false; | |
}; | |
input.onfocus = function (evt) { | |
if (this.value == untitledLabel && isAddMode) this.value = ""; | |
}; | |
} | |
}; | |
eXo.wiki.UIWikiPageTitleControlArea = new UIWikiPageTitleControlArea(); | |
if (!eXo.wiki) eXo.wiki = {}; | |
function UIConfirmBox() {}; | |
UIConfirmBox.prototype.init = function () { | |
eXo.wiki.UIConfirmBox.closeConfirm(); | |
}; | |
UIConfirmBox.prototype.render = function (uicomponentId, titleMessage, message, submitClass, submitLabel, cancelLabel) { | |
var me = eXo.wiki.UIConfirmBox; | |
var submitAction = document.getElementById(uicomponentId); | |
me.confirmBox = document.createElement('div'); | |
eXo.core.DOMUtil.addClass(me.confirmBox, 'ConfirmBox'); | |
me.confirmBox.setAttribute('align', 'center'); | |
var confirmBar = document.createElement('div'); | |
eXo.core.DOMUtil.addClass(confirmBar, 'ConfirmBar'); | |
var confirmTitle = document.createElement('div'); | |
eXo.core.DOMUtil.addClass(confirmTitle, 'ConfirmTitle'); | |
confirmTitle.appendChild(document.createTextNode(titleMessage)); | |
confirmBar.appendChild(confirmTitle); | |
var closeButton = document.createElement('a'); | |
eXo.core.DOMUtil.addClass(closeButton, 'CloseButton'); | |
closeButton.setAttribute('href', 'javascript:eXo.wiki.UIConfirmBox.closeConfirm()'); | |
confirmBar.appendChild(closeButton); | |
me.confirmBox.appendChild(confirmBar); | |
var container = document.createElement('div'); | |
var divMessage = document.createElement('div'); | |
eXo.core.DOMUtil.addClass(divMessage, 'ConfirmMessage'); | |
divMessage.appendChild(document.createTextNode(message)); | |
container.appendChild(divMessage); | |
if (submitAction && submitLabel) { | |
me.createInput(container, submitAction, submitLabel); | |
} | |
if (cancelLabel) { | |
me.createInput(container, null, cancelLabel); | |
} | |
me.confirmBox.appendChild(container); | |
submitAction.appendChild(me.confirmBox); | |
this.maskLayer = eXo.core.UIMaskLayer.createMask("UIPortalApplication", me.confirmBox, 30); | |
return false; | |
}; | |
UIConfirmBox.prototype.createInput = function (container, action, message) { | |
var input = document.createElement('input'); | |
input.setAttribute('value', message); | |
input.setAttribute('type', 'button'); | |
eXo.core.Browser.eventListener(input, 'click', function (event) { | |
if (action && action.href) { | |
window.location = action.href; | |
} | |
eXo.wiki.UIConfirmBox.closeConfirm(); | |
}); | |
container.appendChild(input); | |
}; | |
UIConfirmBox.prototype.closeConfirm = function () { | |
var me = eXo.wiki.UIConfirmBox; | |
if (this.maskLayer) { | |
eXo.core.UIMaskLayer.removeMask(this.maskLayer); | |
this.maskLayer = null; | |
} | |
if (me.confirmBox) { | |
eXo.core.DOMUtil.removeElement(me.confirmBox); | |
me.confirmBox = null; | |
} | |
}; | |
UIConfirmBox.prototype.resetPosition = function () { | |
var me = eXo.wiki.UIConfirmBox; | |
var confirmbox = me.confirmBox; | |
if (confirmbox && (confirmbox.style.display == "block")) { | |
try { | |
eXo.core.UIMaskLayer.blockContainer = document.getElementById("UIPortalApplication"); | |
eXo.core.UIMaskLayer.object = confirmbox; | |
eXo.core.UIMaskLayer.setPosition(); | |
} catch (e) {} | |
} | |
}; | |
eXo.wiki.UIConfirmBox = new UIConfirmBox(); | |
if (!eXo.wiki) { | |
eXo.wiki = {}; | |
}; | |
eXo.require("eXo.core.Browser"); | |
function WikiLayout() { | |
this.posX = 0; | |
this.posY = 0; | |
this.portletId = 'UIWikiPortlet'; | |
this.wikiBodyClass = 'wiki-body'; | |
}; | |
window.onresize = function () { | |
eXo.wiki.WikiLayout.processeWithHeight(); | |
}; | |
WikiLayout.prototype.init = function (prtId) { | |
try { | |
try { | |
var myBody = document.getElementsByTagName("body")[0]; | |
var className = String(myBody.className + ''); | |
className = (className.length > 0 && className.indexOf(this.wikiBodyClass) < 0) ? (className + ' ' + this.wikiBodyClass) : this.wikiBodyClass; | |
myBody.className = className; | |
var myHtml = document.getElementsByTagName("html")[0]; | |
myHtml.className = this.wikiBodyClass; | |
} catch (e) {}; | |
if (prtId.length > 0) this.portletId = prtId; | |
var isIE = (eXo.core.Browser.getBrowserType() == "ie") ? true : false; | |
var idPortal = (isIE) ? 'UIWorkingWorkspace' : 'UIPortalApplication'; | |
this.portal = document.getElementById(idPortal); | |
var portlet = document.getElementById(this.portletId); | |
var DOMUtil = eXo.core.DOMUtil; | |
var wikiLayout = DOMUtil.findFirstDescendantByClass(portlet, "div", "UIWikiMiddleArea"); | |
this.layoutContainer = DOMUtil.findFirstDescendantByClass(wikiLayout, "div", "WikiLayout"); | |
this.spliter = DOMUtil.findFirstDescendantByClass(this.layoutContainer, "div", "Spliter"); | |
this.verticalLine = DOMUtil.findFirstDescendantByClass(this.layoutContainer, "div", "VerticalLine"); | |
if (this.spliter) { | |
this.leftArea = DOMUtil.findPreviousElementByTagName(this.spliter, "div"); | |
this.rightArea = DOMUtil.findNextElementByTagName(this.spliter, "div"); | |
var leftWidth = eXo.core.Browser.getCookie("leftWidth"); | |
if ((leftWidth != null) && (leftWidth != "") && (leftWidth * 1 > 0)) { | |
this.spliter.style.left = leftWidth + 'px'; | |
this.leftArea.style.width = leftWidth + 'px'; | |
this.rightArea.style.left = (leftWidth + this.spliter.offsetWidth) + 'px'; | |
} | |
this.spliter.onmousedown = eXo.wiki.WikiLayout.exeRowSplit; | |
} | |
this.setWithLayOut(); | |
this.setHeightLayOut(); | |
} catch (e) {}; | |
}; | |
WikiLayout.prototype.processeWithHeight = function () { | |
var WikiLayout = eXo.wiki.WikiLayout; | |
if (WikiLayout.layoutContainer) { | |
WikiLayout.setWithLayOut(); | |
WikiLayout.setHeightLayOut(); | |
} else { | |
WikiLayout.init(''); | |
} | |
}; | |
WikiLayout.prototype.setWithLayOut = function () { | |
var WikiLayout = eXo.wiki.WikiLayout; | |
var maxWith = WikiLayout.layoutContainer.offsetWidth; | |
var lWith = 0; | |
if (WikiLayout.leftArea && WikiLayout.spliter) { | |
lWith = WikiLayout.leftArea.offsetWidth + WikiLayout.spliter.offsetWidth; | |
} | |
if (WikiLayout.rightArea) { | |
WikiLayout.rightArea.style.width = (maxWith - lWith) + 'px'; | |
WikiLayout.rightArea.style.left = lWith + 'px'; | |
} | |
}; | |
WikiLayout.prototype.setHeightLayOut = function () { | |
var WikiLayout = eXo.wiki.WikiLayout; | |
var layout = eXo.wiki.WikiLayout.layoutContainer; | |
var hdef = document.documentElement.clientHeight - layout.offsetTop; | |
hdef = (hdef > 200) ? hdef : 200; | |
var hct = hdef * 1; | |
layout.style.height = hdef + "px"; | |
var delta = 0; | |
while ((delta = WikiLayout.heightDelta()) > 0 && hdef >= 200) { | |
hct = hdef - delta; | |
hdef = hdef - 2; | |
layout.style.height = (hct + "px"); | |
} | |
if (WikiLayout.leftArea && WikiLayout.spliter) { | |
WikiLayout.leftArea.style.height = hct + "px"; | |
WikiLayout.spliter.style.height = hct + "px"; | |
} else if (WikiLayout.verticalLine) { | |
WikiLayout.verticalLine.style.height = hct + "px"; | |
} | |
if (WikiLayout.rightArea) { | |
WikiLayout.rightArea.style.height = hct + "px"; | |
} | |
WikiLayout.setHeightRightContent(); | |
}; | |
WikiLayout.prototype.setHeightRightContent = function () { | |
var WikiLayout = eXo.wiki.WikiLayout; | |
if (!WikiLayout.layoutContainer) WikiLayout.init(''); | |
var pageArea = eXo.core.DOMUtil.findFirstDescendantByClass(WikiLayout.layoutContainer, "div", "UIWikiPageArea"); | |
var bottomArea = eXo.core.DOMUtil.findFirstDescendantByClass(WikiLayout.layoutContainer, "div", "UIWikiBottomArea"); | |
if (pageArea && bottomArea) { | |
pageArea.style.height = "auto"; | |
var h = eXo.wiki.WikiLayout.layoutContainer.offsetHeight - (bottomArea.offsetHeight + 18); | |
var x = pageArea.offsetHeight; | |
pageArea.style.height = ((h < x) ? x : h) + "px"; | |
} | |
}; | |
WikiLayout.prototype.exeRowSplit = function (e) { | |
_e = (window.event) ? window.event : e; | |
var WikiLayout = eXo.wiki.WikiLayout; | |
WikiLayout.posX = _e.clientX; | |
WikiLayout.posY = _e.clientY; | |
if (WikiLayout.leftArea && WikiLayout.rightArea && WikiLayout.leftArea.style.display != "none" && WikiLayout.rightArea.style.display != "none") { | |
WikiLayout.adjustHorizon(); | |
} | |
}; | |
WikiLayout.prototype.adjustHorizon = function () { | |
this.leftX = this.leftArea.offsetWidth; | |
this.rightX = this.rightArea.offsetWidth; | |
document.onmousemove = eXo.wiki.WikiLayout.adjustWidth; | |
document.onmouseup = eXo.wiki.WikiLayout.clear; | |
}; | |
WikiLayout.prototype.adjustWidth = function (evt) { | |
evt = (window.event) ? window.event : evt; | |
var WikiLayout = eXo.wiki.WikiLayout; | |
var delta = evt.clientX - WikiLayout.posX; | |
var leftWidth = (WikiLayout.leftX + delta); | |
var rightWidth = (WikiLayout.rightX - delta); | |
if (rightWidth <= 0 || leftWidth <= 0) { | |
return; | |
} | |
WikiLayout.leftArea.style.width = leftWidth + "px"; | |
WikiLayout.rightArea.style.width = rightWidth + "px"; | |
WikiLayout.rightArea.style.left = (leftWidth + WikiLayout.spliter.offsetWidth) + "px"; | |
WikiLayout.spliter.style.left = leftWidth + "px"; | |
}; | |
WikiLayout.prototype.clear = function () { | |
eXo.core.Browser.setCookie("leftWidth", eXo.wiki.WikiLayout.leftArea.offsetWidth, 1); | |
document.onmousemove = null; | |
}; | |
WikiLayout.prototype.heightDelta = function () { | |
return this.portal.offsetHeight - document.documentElement.clientHeight; | |
}; | |
eXo.wiki.WikiLayout = new WikiLayout(); | |
eXo.require("eXo.core.Keyboard"); | |
function UIWikiTemplateForm() {}; | |
UIWikiTemplateForm.prototype.init = function (componentid, inputId) { | |
var me = eXo.wiki.UIWikiTemplateForm; | |
me.component = document.getElementById(componentid); | |
var input = eXo.core.DOMUtil.findDescendantById(me.component, inputId); | |
input.setAttribute('autocomplete', 'off'); | |
input.onkeyup = function (evt) { | |
evt = window.event || evt; | |
eXo.wiki.UIWikiTemplateForm.pressHandler(evt, this); | |
} | |
input.form.onsubmit = function () { | |
return false; | |
} | |
}; | |
UIWikiTemplateForm.prototype.pressHandler = function (evt, textbox) { | |
var me = eXo.wiki.UIWikiTemplateForm; | |
evt = window.event || evt; | |
var keyNum = eXo.core.Keyboard.getKeynum(evt); | |
if (evt.altKey || evt.ctrlKey || evt.shiftKey) return; | |
switch (keyNum) { | |
case 13: | |
me.enterHandler(evt); | |
break; | |
case 27: | |
me.escapeHandler(); | |
break; | |
case 38: | |
me.arrowUpHandler(); | |
break; | |
case 40: | |
me.arrowDownHandler(); | |
break; | |
default: | |
break; | |
} | |
return; | |
}; | |
UIWikiTemplateForm.prototype.enterHandler = function (evt) { | |
var me = eXo.wiki.UIWikiTemplateForm; | |
me.doAdvanceSearch(); | |
}; | |
UIWikiTemplateForm.prototype.escapeHandler = function () {}; | |
UIWikiTemplateForm.prototype.arrowUpHandler = function () {}; | |
UIWikiTemplateForm.prototype.arrowDownHandler = function () {}; | |
UIWikiTemplateForm.prototype.typeHandler = function (textbox) {}; | |
UIWikiTemplateForm.prototype.doAdvanceSearch = function () { | |
var me = eXo.wiki.UIWikiTemplateForm; | |
if (me.component) { | |
var action = eXo.core.DOMUtil.findFirstDescendantByClass(me.component, "a", "SearchButton"); | |
action.onclick(); | |
} | |
} | |
eXo.wiki.UIWikiTemplateForm = new UIWikiTemplateForm(); | |
function UIRelated() {}; | |
UIRelated.prototype.init = function (componentid) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var me = eXo.wiki.UIRelated; | |
var relatedBlock = document.getElementById(componentid); | |
var infoElement = DOMUtil.findFirstDescendantByClass(relatedBlock, "input", "info"); | |
var restUrl = infoElement.getAttribute("restUrl"); | |
var redirectTempl = infoElement.getAttribute("redirectUrl"); | |
var request = eXo.core.Browser.createHttpRequest(); | |
request.open('GET', restUrl, false); | |
request.setRequestHeader("Cache-Control", "max-age=86400"); | |
request.send(null); | |
var dataList = eXo.core.JSON.parse(request.responseText); | |
relatedList = dataList.jsonList; | |
var docFrag = me.initRelatedDOM(relatedList, redirectTempl); | |
relatedBlock.appendChild(docFrag); | |
}; | |
UIRelated.prototype.initRelatedDOM = function (dataList, redirectUrl) { | |
var docFrag = document.createDocumentFragment(); | |
for (var i = 0; i < relatedList.length; i++) { | |
var relatedItem = relatedList[i]; | |
var nodeGroupDiv = document.createElement("div"); | |
nodeGroupDiv.setAttribute("class", "NodeGroup"); | |
var nodeDiv = document.createElement("div"); | |
nodeDiv.setAttribute("class", "Page TreeNodeType Node"); | |
var labelDiv = document.createElement("div"); | |
labelDiv.setAttribute("class", "NodeLabel"); | |
var a = document.createElement("a"); | |
if (redirectUrl && relatedItem.identity != null) { | |
var relatedLink = redirectUrl + "&objectId=" + encodeURIComponent(relatedItem.identity); | |
a.href = relatedLink; | |
} | |
if (relatedItem.title) { | |
a.setAttribute("title", relatedItem.title); | |
a.appendChild(document.createTextNode(relatedItem.title)); | |
} | |
labelDiv.appendChild(a); | |
nodeDiv.appendChild(labelDiv); | |
nodeGroupDiv.appendChild(nodeDiv); | |
docFrag.appendChild(nodeGroupDiv); | |
} | |
return docFrag; | |
}; | |
eXo.wiki.UIRelated = new UIRelated(); | |
function UIWikiPageEditForm() {}; | |
UIWikiPageEditForm.prototype.editPageContent = function (pageEditFormId) { | |
var pageEditForm = document.getElementById(pageEditFormId); | |
var titleContainer = eXo.core.DOMUtil.findFirstDescendantByClass(pageEditForm, 'div', 'UIWikiPageTitleControlForm_PageEditForm'); | |
var titleInput = eXo.core.DOMUtil.findDescendantsByTagName(titleContainer, 'input')[0]; | |
eXo.wiki.UIWikiPageEditForm.changed = false; | |
titleInput.onchange = function () { | |
eXo.wiki.UIWikiPageEditForm.changed = true; | |
titleInput.onchange = null; | |
} | |
var textAreaContainer = eXo.core.DOMUtil.findFirstDescendantByClass(pageEditForm, 'div', 'UIWikiPageContentInputContainer'); | |
if (textAreaContainer != null) { | |
var textArea = eXo.core.DOMUtil.findDescendantsByTagName(textAreaContainer, 'textarea')[0]; | |
textArea.onchange = function () { | |
eXo.wiki.UIWikiPageEditForm.changed = true; | |
textArea.onchange = null; | |
} | |
} else { | |
eXo.wiki.UIWikiPageEditForm.changed = true; | |
} | |
}; | |
UIWikiPageEditForm.prototype.cancel = function (uicomponentId, titleMessage, message, submitClass, submitLabel, cancelLabel) { | |
if (eXo.wiki.UIWikiPageEditForm.changed == true) { | |
eXo.wiki.UIConfirmBox.render(uicomponentId, titleMessage, message, submitClass, submitLabel, cancelLabel); | |
return false; | |
} | |
return true; | |
}; | |
eXo.wiki.UIWikiPageEditForm = new UIWikiPageEditForm(); | |
function Cometd() { | |
this._connected = false; | |
this._polling = false; | |
this._connecting = false; | |
this.currentTransport = null; | |
this.url = '/cometd/cometd'; | |
this.id = null; | |
this.exoId = null; | |
this.exoToken = null; | |
var Browser = eXo.core.Browser; | |
this.clientId = Browser.getCookie('cometdClientID') || false; | |
this.messageId = 0; | |
this.batch = 0; | |
this._subscriptions = []; | |
this._messageQ = []; | |
this._connectionReadyCallbacks = []; | |
this._maxInterval = 5 * 1000; | |
this._backoffInterval = 1000; | |
this._maxTry = 5; | |
this._tryToOpenTunnelCnt = 0; | |
this._retryInterval = 0; | |
this._multiClientsDetectCnt = 0; | |
} | |
Cometd.prototype.init = function (forceDisconnect) { | |
this._tryToOpenTunnelCnt = 0; | |
if ((!forceDisconnect && this._connected) || this._connecting) { | |
return; | |
} | |
if (!this.currentTransport) { | |
this.currentTransport = new eXo.portal.LongPollTransport(); | |
this.currentTransport.init(this); | |
} | |
if (this.clientId) this.currentTransport.initTunnel(); | |
else this.currentTransport.initHandshake(); | |
}; | |
Cometd.prototype.addOnConnectionReadyCallback = function (handle) { | |
if (handle) { | |
this._connectionReadyCallbacks.push(handle); | |
} | |
}; | |
Cometd.prototype.removeOnConnectionReadtCallback = function (handle) { | |
for (var i = 0; i < this._connectionReadyCallbacks.length; i++) { | |
if (this._connectionReadyCallbacks[i] == handle) { | |
this._connectionReadyCallbacks[i] = this._connectionReadyCallbacks[this._connectionReadyCallbacks.length - 1]; | |
this._connectionReadyCallbacks.pop(); | |
break; | |
} | |
} | |
}; | |
Cometd.prototype.deliver = function (messages) { | |
messages.each(this._deliver, this); | |
return messages; | |
} | |
Cometd.prototype.isConnected = function () { | |
return this._connected; | |
} | |
Cometd.prototype._deliver = function (message) { | |
if (!message['channel']) { | |
if (message['success'] !== true) { | |
return; | |
} | |
} | |
this.lastMessage = message; | |
if (message.advice) { | |
this.adviceBackup = this.advice; | |
this.advice = message.advice; | |
this.multiClients = message.advice['multiple-clients']; | |
if (this.multiClients) { | |
this._multiClientsDetectCnt++; | |
if (this._multiClientsDetectCnt == 1) { | |
if (window.console && window.console.error) window.console.error('You has multiple tab/window using Cometd!\nPlease keep only once.'); | |
} | |
} else { | |
this._multiClientsDetectCnt = 0; | |
this.resetRetryInterval(); | |
} | |
} | |
if ((message['channel']) && (message.channel.length > 5) && (message.channel.substr(0, 5) == '/meta')) { | |
switch (message.channel) { | |
case '/meta/connect': | |
if (message.successful && !this._connected) { | |
this._connected = true; | |
this.endBatch(); | |
} | |
break; | |
case '/meta/subscribe': | |
if (!message.successful) { | |
throw (new Error('todo manage error subscription')); | |
return; | |
} | |
break; | |
case '/meta/unsubscribe': | |
if (!message.successful) { | |
throw (new Error('todo manage error unsubscription')); | |
return; | |
} | |
break; | |
} | |
} | |
if (message.data) { | |
var tname = message.channel; | |
var def = this._subscriptions[tname]; | |
if (def) def(message); | |
} | |
} | |
Cometd.prototype._sendMessage = function (message) { | |
if (this.currentTransport && this._connected && this.batch == 0) { | |
return this.currentTransport.sendMessages([message]); | |
} else { | |
this._messageQ.push(message); | |
} | |
} | |
Cometd.prototype.subscribe = function (channel, callback) { | |
if (callback) { | |
var tname = channel; | |
var subs = this._subscriptions[tname]; | |
if (!subs || subs.length == 0) { | |
subs = []; | |
var message = { | |
channel: '/meta/subscribe', | |
subscription: channel, | |
exoId: this.exoId, | |
exoToken: this.exoToken | |
} | |
this._sendMessage(message); | |
} | |
this._subscriptions[tname] = callback; | |
} | |
} | |
Cometd.prototype.unsubscribe = function (channel) { | |
var tname = channel; | |
if (this._subscriptions[tname]) { | |
this._subscriptions[tname] = null; | |
} | |
this._sendMessage({ | |
channel: '/meta/unsubscribe', | |
subscription: channel, | |
exoId: this.exoId, | |
exoToken: this.exoToken | |
}); | |
} | |
Cometd.prototype.startBatch = function () { | |
this.batch++; | |
} | |
Cometd.prototype.increaseRetryInterval = function () { | |
this.advice = this.advice || {}; | |
if (!this.advice.interval || (this.advice.interval && this.advice.interval > this._maxInterval)) { | |
this.resetRetryInterval(); | |
} else { | |
this._retryInterval += this._backoffInterval; | |
this.advice.interval = this._retryInterval; | |
} | |
} | |
Cometd.prototype.resetRetryInterval = function () { | |
if (this.advice) this.advice.interval = 1000; | |
this._retryInterval = 1000; | |
} | |
Cometd.prototype.endBatch = function () { | |
this._tryToOpenTunnelCnt = 0; | |
this._connecting = false; | |
for (var i = 0; i < this._connectionReadyCallbacks.length; i++) { | |
var handler = this._connectionReadyCallbacks[i]; | |
if (handler) { | |
handler(); | |
} | |
} | |
if (--this.batch <= 0 && this.currentTransport && this._connected) { | |
this.batch = 0; | |
var messages = this._messageQ; | |
this._messageQ = []; | |
if (messages.length > 0) { | |
this.currentTransport.sendMessages(messages); | |
} | |
} | |
} | |
Cometd.prototype.disconnect = function () { | |
this._tryToOpenTunnelCnt = 0; | |
this._subscriptions.each(this.unsubscribe, this); | |
this._messageQ = []; | |
if (this.currentTransport) { | |
this.currentTransport.disconnect(); | |
} | |
if (!this._polling) this._connected = false; | |
} | |
Cometd.prototype._backoff = function () { | |
if (!this.advice || !this.advice.interval) { | |
this.advice = { | |
reconnect: 'retry', | |
interval: 0 | |
}; | |
} | |
this.increaseRetryInterval(); | |
} | |
function LongPollTransport() { | |
var instance = new Object(); | |
instance.init = function (cometd) { | |
this._connectionType = 'long-polling'; | |
this._cometd = cometd; | |
} | |
instance.startup = function () { | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url); | |
request.onSuccess = this._cometd.deliver; | |
request.process(); | |
} | |
instance.initHandshake = function () { | |
var message = { | |
channel: '/meta/handshake', | |
id: this._cometd.messageId++, | |
exoId: this._cometd.exoId, | |
exoToken: this._cometd.exoToken | |
}; | |
var query = 'message=' + eXo.core.JSON.stringify(message); | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url, query); | |
request.onSuccess = function (request) { | |
this.finishInitHandshake(request.evalResponse()); | |
}.bind(this); | |
request.onError = function (err) { | |
throw (new Error('request Error, need to manage this error')); | |
}.bind(this); | |
request.process(); | |
} | |
instance.finishInitHandshake = function (data) { | |
data = data[0]; | |
this._cometd.handshakeReturn = data; | |
if (data['advice']) { | |
this._cometd.advice = data.advice; | |
} | |
if (!data.successful) { | |
if (this._cometd.advice && this._cometd.advice['reconnect'] == 'none') { | |
return; | |
} | |
if (this._cometd.advice && this._cometd.advice['interval'] && this._cometd.advice.interval > 0) { | |
setTimeout(function () { | |
eXo.core.Cometd.init(); | |
}, this._cometd._retryInterval); | |
} else { | |
this._cometd.init(this.url, this._props); | |
} | |
return; | |
} | |
if (data.version < this.minimumVersion) { | |
return; | |
} | |
this._cometd.clientId = data.clientId; | |
eXo.core.Browser.setCookie('cometdClientID', this._cometd.clientId, 1); | |
this.initTunnel(); | |
} | |
instance.initTunnel = function () { | |
var message = { | |
channel: '/meta/connect', | |
clientId: this._cometd.clientId, | |
connectionType: this._connectionType, | |
id: this._cometd.messageId++ | |
}; | |
this.openTunnelWith({ | |
message: eXo.core.JSON.stringify(message) | |
}); | |
} | |
instance.openTunnelWith = function (content, url) { | |
this._cometd._polling = true; | |
var query = 'message=' + content.message; | |
var request = new eXo.portal.AjaxRequest('POST', (url || this._cometd.url), query); | |
request.timeout = 180000; | |
request.onSuccess = function (request) { | |
this._cometd._polling = false; | |
if (request.status >= 200 && request.status < 300) { | |
this._cometd.deliver(request.evalResponse()); | |
} else this._cometd._backoff(); | |
this.tunnelReq = null; | |
this.tunnelCollapse(); | |
}.bind(this); | |
request.onError = function (err) { | |
this.tunnelReq = null; | |
this._cometd._polling = false; | |
this._cometd._tryToOpenTunnelCnt++; | |
this.tunnelCollapse(); | |
throw (new Error('tunnel opening failed')); | |
}.bind(this); | |
request.process(); | |
} | |
instance.tunnelCollapse = function () { | |
if (this._cometd._tryToOpenTunnelCnt > this._cometd._maxTry) { | |
return; | |
} | |
if (!this._cometd._polling) { | |
this._cometd._polling = false; | |
if (this._cometd['advice']) { | |
if (this._cometd.advice['reconnect'] == 'none') { | |
return; | |
} | |
if ((this._cometd.advice['interval']) && (this._cometd.advice.interval > 0)) { | |
var transport = this; | |
setTimeout(function () { | |
transport._connect(); | |
}, this._cometd._retryInterval); | |
this._cometd.increaseRetryInterval(); | |
} else { | |
this._connect(); | |
this._cometd.increaseRetryInterval(); | |
} | |
} else { | |
this._connect(); | |
this._cometd.increaseRetryInterval(); | |
} | |
} | |
} | |
instance._connect = function () { | |
if ((this._cometd['advice']) && (this._cometd.advice['reconnect'] == 'handshake')) { | |
this._cometd.clientId = null; | |
this._cometd.init(this._cometd.url, this._cometd._props); | |
} else if (this._cometd._connected) { | |
this.openTunnelWith({ | |
message: eXo.core.JSON.stringify([{ | |
channel: '/meta/connect', | |
connectionType: this._connectionType, | |
clientId: this._cometd.clientId, | |
timestamp: this.lastTimestamp, | |
id: '' + this._cometd.messageId++ | |
}]) | |
}); | |
} | |
} | |
instance.sendMessages = function (messages) { | |
for (var i = 0; i < messages.length; i++) { | |
messages[i].clientId = this._cometd.clientId; | |
messages[i].id = '' + this._cometd.messageId++; | |
} | |
var query = 'message=' + eXo.core.JSON.stringify(messages); | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url, query); | |
request.onSuccess = function (request) { | |
this._cometd.deliver(request.evalResponse()); | |
}.bind(this); | |
request.onError = function (err) { | |
throw (new Error('error sending the message')); | |
}.bind(this); | |
request.process(); | |
} | |
instance.disconnect = function () { | |
var query = 'message=' + eXo.core.JSON.stringify([{ | |
channel: '/meta/disconnect', | |
clientId: this._cometd.clientId, | |
id: '' + this._cometd.messageId++ | |
}]); | |
var request = new eXo.portal.AjaxRequest('POST', this._cometd.url, query); | |
request.process(); | |
} | |
return instance; | |
} | |
eXo.core.Cometd = new Cometd(); | |
eXo.portal.LongPollTransport = LongPollTransport.prototype.constructor; | |
if (!eXo) eXo = {}; | |
if (!eXo.commons) eXo.commons = {}; | |
function DocumentSelector() { | |
this.defaultDriveType = "personal"; | |
this.getDrives = ""; | |
this.getFoldersAndFiles = ""; | |
this.deleteFolderOrFile = ""; | |
this.createFolder = ""; | |
this.isFolderOnlyParam = ""; | |
this.folderNameParam = ""; | |
this.driveTypeParam = ""; | |
this.driveNameParam = ""; | |
this.workspaceNameParam = ""; | |
this.currentFolderParam = ""; | |
this.itemPathParam = ""; | |
this.xmlHttpRequest = false; | |
this.selectFile = null; | |
this.selectFileLink = null; | |
this.selectFolderLink = null; | |
this.allowDeleteItem = true; | |
this.dataId = null; | |
this.selectedItem = null; | |
}; | |
function DocumentItem() { | |
driveType = null; | |
driveName = null; | |
workspaceName = null; | |
currentFolder = null; | |
jcrPath = null; | |
}; | |
DocumentSelector.prototype.init = function (uicomponentId, restContext) { | |
var me = eXo.commons.DocumentSelector; | |
this.uiComponent = document.getElementById(uicomponentId); | |
this.selectFileLink = eXo.core.DOMUtil.findFirstDescendantByClass(this.uiComponent, "a", "SelectFile"); | |
this.selectFolderLink = eXo.core.DOMUtil.findFirstDescendantByClass(this.uiComponent, "a", "SelectFolder"); | |
this.getDrivesURL = restContext + this.getDrives; | |
this.getFoldersAndFilesURL = restContext + this.getFoldersAndFiles; | |
this.deleteFolderOrFileURL = restContext + this.deleteFolderOrFile; | |
this.createFolderURL = restContext + this.createFolder; | |
var documentItem = new DocumentItem(); | |
documentItem.driveType = this.defaultDriveType; | |
me.renderDetails(documentItem); | |
}; | |
DocumentSelector.prototype.changeDrive = function (selectBox) { | |
var documentItem = new DocumentItem(); | |
documentItem.driveType = selectBox.value; | |
eXo.commons.DocumentSelector.renderDetails(documentItem); | |
}; | |
DocumentSelector.prototype.renderDetails = function (documentItem) { | |
var me = eXo.commons.DocumentSelector; | |
var domUtil = eXo.core.DOMUtil; | |
var rightWS = domUtil.findFirstDescendantByClass(this.uiComponent, "div", "RightWorkspace"); | |
var actionBar = domUtil.findFirstDescendantByClass(this.uiComponent, "div", "ActionBar"); | |
var tblRWS = domUtil.findDescendantsByTagName(rightWS, "table")[0]; | |
var rowsRWS = domUtil.findDescendantsByTagName(tblRWS, "tr"); | |
if (rowsRWS && rowsRWS.length > 0) { | |
for (var i = 0; i < rowsRWS.length; i++) { | |
if (i > 0) tblRWS.deleteRow(rowsRWS[i].rowIndex); | |
} | |
} | |
me.selectedItem = documentItem; | |
if (!me.selectedItem || !me.selectedItem.driveName) { | |
actionBar.style.display = "none"; | |
} else { | |
actionBar.style.display = "block"; | |
} | |
if (!me.selectedItem.currentFolder) me.selectedItem.currentFolder = ''; | |
me.renderBreadcrumbs(documentItem, null); | |
if (!documentItem.driveName) { | |
me.renderDrives(tblRWS, documentItem); | |
} else { | |
me.renderDetailsFolder(tblRWS, documentItem); | |
} | |
}; | |
DocumentSelector.prototype.renderDrives = function (tableContainer, documentItem) { | |
var me = eXo.commons.DocumentSelector; | |
var driveType = documentItem.driveType; | |
var url = this.getDrivesURL; | |
url += "?" + this.driveTypeParam + "=" + driveType; | |
var data = me.request(url); | |
var folderContainer = data.getElementsByTagName("Folders")[0]; | |
var folderList = folderContainer.getElementsByTagName("Folder"); | |
if (!folderList || folderList.length <= 0) { | |
var tdNoContent = tableContainer.insertRow(1).insertCell(0); | |
tdNoContent.innerHTML = "There is no drive"; | |
tdNoContent.className = "Item TRNoContent"; | |
return; | |
} | |
var clazz = 'EventItem'; | |
var k = 0; | |
for (var i = 0; i < folderList.length; i++) { | |
k = i + 1; | |
var name = folderList[i].getAttribute("name"); | |
var driveName = folderList[i].getAttribute("name"); | |
var nodeType = folderList[i].getAttribute("nodeType"); | |
var workspaceName = folderList[i].getAttribute("workspaceName"); | |
var canAddChild = folderList[i].getAttribute("canAddChild"); | |
var newRow = tableContainer.insertRow(i + 1); | |
newRow.className = clazz + " Cell"; | |
var cellZero = newRow.insertCell(0); | |
cellZero.onclick = function () { | |
eXo.commons.DocumentSelector.browseFolder(this); | |
} | |
cellZero.innerHTML = '<a class="Item Drive_' + nodeType + '" name="' + name + '" driveType="' + driveType + '" driveName="' + driveName + '" workspaceName="' + workspaceName + '" canAddChild="' + canAddChild + '" onclick="javascript:void(0);">' + name + '</a>'; | |
} | |
}; | |
DocumentSelector.prototype.renderDetailsFolder = function (tableContainer, documentItem) { | |
var me = eXo.commons.DocumentSelector; | |
var driveType = documentItem.driveType; | |
var driveName = documentItem.driveName; | |
var workSpaceName = documentItem.workspaceName; | |
var currentFolder = documentItem.currentFolder; | |
if (!currentFolder) currentFolder = ""; | |
var url = this.getFoldersAndFilesURL; | |
url += "?" + this.driveNameParam + "=" + driveName; | |
url += "&" + this.workspaceNameParam + "=" + workSpaceName; | |
url += "&" + this.currentFolderParam + "=" + currentFolder; | |
url += "&" + this.isFolderOnlyParam + "=false"; | |
var data = me.request(url); | |
var folderContainer = data.getElementsByTagName("Folders")[0]; | |
var folderList = folderContainer.getElementsByTagName("Folder"); | |
var fileContainer = data.getElementsByTagName("Files")[0]; | |
var fileList = fileContainer.getElementsByTagName("File"); | |
if ((!fileList || fileList.length <= 0) && (!folderList || folderList.length <= 0)) { | |
var tdNoContent = tableContainer.insertRow(1).insertCell(0); | |
tdNoContent.innerHTML = "There is no folder or file"; | |
tdNoContent.className = "Item TRNoContent"; | |
return; | |
} else { | |
var listItem = ''; | |
var clazz = 'EventItem'; | |
var k = 0; | |
for (var i = 0; i < folderList.length; i++) { | |
k = i + 1; | |
var clazzItem = me.getClazzIcon(folderList[i].getAttribute("nodeType")); | |
var jcrPath = folderList[i].getAttribute("path"); | |
var nodeType = folderList[i].getAttribute("folderType"); | |
var name = folderList[i].getAttribute("name"); | |
var childFolder = folderList[i].getAttribute("currentFolder"); | |
var canRemove = folderList[i].getAttribute("canRemove"); | |
var canAddChild = folderList[i].getAttribute("canAddChild"); | |
var newRow = tableContainer.insertRow(i + 1); | |
newRow.className = clazz + " Cell"; | |
var cellZero = newRow.insertCell(0); | |
cellZero.onclick = function () { | |
eXo.commons.DocumentSelector.browseFolder(this); | |
} | |
cellZero.innerHTML = '<a class="Item IconDefault ' + clazzItem + '" name="' + name + '" driveType="' + driveType + '" driveName="' + driveName + '"workSpaceName="' + workSpaceName + '" canAddChild="' + canAddChild + '" currentFolder="' + childFolder + '" jcrPath="' + jcrPath + '" onclick="javascript:void(0);">' + name + '</a>'; | |
} | |
for (var j = 0; j < fileList.length; j++) { | |
var jcrPath = fileList[j].getAttribute("path"); | |
var nodeType = fileList[j].getAttribute("nodeType"); | |
var nodeTypeIcon = nodeType.replace(":", "_") + "48x48Icon Folder"; | |
var node = fileList[j].getAttribute("name"); | |
var size = fileList[j].getAttribute("size"); | |
if (size < 1024) size += ' Byte(s)'; | |
else if (size > 1024 && size < (1024 * 1024)) { | |
size = (Math.round(size / 1024 * 100)) / 100; | |
size += ' KB'; | |
} else { | |
size = (Math.round(size / (1024 * 1024) * 100)) / 100; | |
size += ' MB'; | |
} | |
var clazzItem = me.getClazzIcon(fileList[j].getAttribute("nodeType")); | |
var newRow = tableContainer.insertRow(k + j + 1); | |
newRow.className = clazz + " Cell"; | |
var cellZero = newRow.insertCell(0); | |
cellZero.tabIndex = "1"; | |
cellZero.onclick = function () { | |
eXo.commons.DocumentSelector.submitSelectedFile(this); | |
} | |
cellZero.innerHTML = '<a class="Item ' + clazzItem + '" jcrPath="' + jcrPath + '" name="' + node + '" onclick="javascript:void(0);">' + node + '</a>'; | |
} | |
} | |
}; | |
DocumentSelector.prototype.selectUploadedFile = function (fileName) { | |
var domUtil = eXo.core.DOMUtil; | |
var rightWS = domUtil.findFirstDescendantByClass(this.uiComponent, "div", "RightWorkspace"); | |
var tblRWS = domUtil.findDescendantsByTagName(rightWS, "table")[0]; | |
var items = domUtil.findDescendantsByClass(tblRWS, "a", "Item"); | |
for (var j = 0; j < items.length; j++) { | |
var item = items[j]; | |
var itemName = item.getAttribute("name"); | |
if (itemName && itemName == fileName) { | |
item.parentNode.onclick(); | |
item.parentNode.focus(); | |
} | |
} | |
}; | |
DocumentSelector.prototype.submitSelectedFile = function (tableCell) { | |
var me = eXo.commons.DocumentSelector; | |
var domUtil = eXo.core.DOMUtil; | |
var detailNode = domUtil.getChildrenByTagName(tableCell, "a")[0]; | |
var nodePath = detailNode.getAttribute("jcrPath"); | |
var fileName = detailNode.getAttribute("name"); | |
if (me.selectFileLink) { | |
var link = me.selectFileLink.href; | |
var endParamIndex = link.lastIndexOf("')"); | |
if (endParamIndex > 0) link = link.substring(0, endParamIndex) + "&" + me.dataId + "=" + nodePath + "')"; | |
window.location = link; | |
} | |
if (me.selectFile) { | |
if (eXo.core.DOMUtil.hasClass(me.selectFile, "Selected")) { | |
eXo.core.DOMUtil.removeClass(me.selectFile, "Selected"); | |
} | |
} | |
me.selectFile = tableCell.parentNode; | |
domUtil.addClass(me.selectFile, "Selected"); | |
if (me.selectedItem) { | |
me.renderBreadcrumbs(me.selectedItem, fileName); | |
} | |
}; | |
DocumentSelector.prototype.submitSelectedFolder = function (documentItem) { | |
var me = eXo.commons.DocumentSelector; | |
var workspaceName = documentItem.workspaceName; | |
var jcrPath = documentItem.jcrPath; | |
if (me.selectFolderLink) { | |
var link = me.selectFolderLink.href; | |
var endParamIndex = link.lastIndexOf("')"); | |
if (endParamIndex > 0) link = link.substring(0, endParamIndex) + "&" + me.dataId + "=" + workspaceName + jcrPath + "')"; | |
window.location = link; | |
} | |
}; | |
DocumentSelector.prototype.browseFolder = function (tableCell) { | |
var me = eXo.commons.DocumentSelector; | |
var domUtil = eXo.core.DOMUtil; | |
var detailNode = domUtil.getChildrenByTagName(tableCell, "a")[0]; | |
var documentItem = new DocumentItem(); | |
documentItem.driveType = detailNode.getAttribute("driveType"); | |
documentItem.driveName = detailNode.getAttribute("driveName"); | |
documentItem.workspaceName = detailNode.getAttribute("workspaceName"); | |
documentItem.currentFolder = detailNode.getAttribute("currentFolder"); | |
documentItem.jcrPath = detailNode.getAttribute("jcrPath"); | |
documentItem.canAddChild = detailNode.getAttribute("canAddChild"); | |
me.renderDetails(documentItem); | |
me.submitSelectedFolder(documentItem); | |
}; | |
DocumentSelector.prototype.remove = function (tableCell) { | |
var me = eXo.commons.DocumentSelector; | |
var domUtil = eXo.core.DOMUtil; | |
var detailNode = domUtil.getChildrenByTagName(tableCell, "a")[0]; | |
var name = detailNode.getAttribute("name"); | |
var r = confirm("Are you sure you want remove " + name + " ?"); | |
if (r == false) return; | |
var driveName = detailNode.getAttribute("driveName"); | |
var workspaceName = detailNode.getAttribute("workspaceName"); | |
var itemPath = detailNode.getAttribute("itemPath"); | |
var url = me.deleteFolderOrFileURL; | |
url += "?" + me.driveNameParam + "=" + driveName; | |
url += "&" + me.workspaceNameParam + "=" + workspaceName; | |
url += "&" + me.itemPathParam + "=" + itemPath; | |
me.request(url); | |
if (me.selectedItem) { | |
me.renderDetails(me.selectedItem); | |
} | |
}; | |
DocumentSelector.prototype.newFolder = function (inputFolderName) { | |
var me = eXo.commons.DocumentSelector; | |
var domUtil = eXo.core.DOMUtil; | |
var msg_new_folder_not_allow = inputFolderName.getAttribute("msg_new_folder_not_allow"); | |
var msg_select_folder = inputFolderName.getAttribute("msg_select_drive"); | |
var msg_enter_folder_name = inputFolderName.getAttribute("msg_enter_folder_name"); | |
var msg_empty_folder_name = inputFolderName.getAttribute("msg_empty_folder_name"); | |
if (!me.selectedItem || !me.selectedItem.driveName) { | |
alert(msg_select_folder); | |
return; | |
} | |
var folderName = prompt(msg_enter_folder_name, ""); | |
if (folderName == null || folderName == "") { | |
alert(msg_empty_folder_name); | |
return; | |
} | |
var canAddChild = me.selectedItem.canAddChild; | |
if (canAddChild == "false") { | |
alert(msg_new_folder_not_allow); | |
return; | |
} | |
var driveName = me.selectedItem.driveName; | |
var workspaceName = me.selectedItem.workspaceName; | |
var url = me.createFolderURL; | |
url += "?" + me.driveNameParam + "=" + driveName; | |
url += "&" + me.workspaceNameParam + "=" + workspaceName; | |
url += "&" + me.currentFolderParam + "=" + me.selectedItem.currentFolder; | |
url += "&" + me.folderNameParam + "=" + folderName; | |
me.request(url); | |
me.renderDetails(me.selectedItem); | |
}; | |
DocumentSelector.prototype.actionBreadcrumbs = function (driveType, driveName, workspaceName, currentFolder) { | |
var documentItem = new DocumentItem(); | |
documentItem.driveType = driveType; | |
documentItem.driveName = driveName; | |
documentItem.workspaceName = workspaceName; | |
documentItem.currentFolder = currentFolder; | |
eXo.commons.DocumentSelector.renderDetails(documentItem); | |
} | |
DocumentSelector.prototype.renderBreadcrumbs = function (documentItem, fileName) { | |
var domUtil = eXo.core.DOMUtil; | |
var breadcrumbContainer = domUtil.findFirstDescendantByClass(this.uiComponent, "div", "BreadcumbsContainer"); | |
breadcrumbContainer.innerHTML = ''; | |
var breadCrumbObject = new BreadCrumbs(); | |
breadCrumbObject.breadCrumb = breadcrumbContainer; | |
if (fileName) { | |
breadCrumbObject.renderFileName(documentItem, fileName); | |
} else if (documentItem.currentFolder) { | |
breadCrumbObject.renderFolder(documentItem, fileName); | |
} else if (documentItem.driveName) { | |
breadCrumbObject.renderDrive(documentItem, fileName); | |
} else { | |
breadCrumbObject.renderDriveType(documentItem, fileName); | |
} | |
var linkNode = eXo.core.DOMUtil.findDescendantsByTagName(breadcrumbContainer, "a"); | |
eXo.core.DOMUtil.replaceClass(linkNode[linkNode.length - 1], 'Normal', 'Selected'); | |
}; | |
function BreadCrumbs() { | |
breadCrumb = null; | |
BreadCrumbs.prototype.renderDriveType = function (documentItem) { | |
if (this.breadCrumb) { | |
this.appendBreadCrumbNode(documentItem, null); | |
} | |
}; | |
BreadCrumbs.prototype.renderDrive = function (documentItem) { | |
if (this.breadCrumb) { | |
var tmpDocumentItem = new DocumentItem(); | |
tmpDocumentItem.driveType = documentItem.driveType; | |
this.renderDriveType(tmpDocumentItem); | |
this.appendBreadCrumbNode(documentItem, documentItem.driveName); | |
} | |
}; | |
BreadCrumbs.prototype.renderFolder = function (documentItem) { | |
if (this.breadCrumb) { | |
var tmpDocumentItem = new DocumentItem(); | |
tmpDocumentItem.driveType = documentItem.driveType; | |
tmpDocumentItem.driveName = documentItem.driveName; | |
tmpDocumentItem.workspaceName = documentItem.workspaceName; | |
this.renderDrive(tmpDocumentItem); | |
var breadCrumbItem = documentItem.currentFolder.split("/"); | |
if (breadCrumbItem != "") { | |
tmpDocumentItem.currentFolder = ''; | |
for (var i = 0; i < breadCrumbItem.length; i++) { | |
tmpDocumentItem.currentFolder += breadCrumbItem[i]; | |
this.appendBreadCrumbNode(tmpDocumentItem, breadCrumbItem[i]); | |
tmpDocumentItem.currentFolder += "/"; | |
} | |
} | |
} | |
}; | |
BreadCrumbs.prototype.renderFileName = function (documentItem, fileName) { | |
if (this.breadCrumb) { | |
this.renderFolder(documentItem) | |
var fileNode = document.createElement("div"); | |
fileNode.className = 'BreadcumbTab'; | |
fileNode.innerHTML = '<a class="Normal">' + "/" + fileName + '</a>'; | |
this.breadCrumb.appendChild(fileNode); | |
} | |
}; | |
BreadCrumbs.prototype.appendBreadCrumbNode = function (documentItem, name) { | |
var node = document.createElement("div"); | |
var className = 'Normal'; | |
if (name == null) { | |
name = ''; | |
className = 'HomeIcon'; | |
} else { | |
name = "/" + name; | |
} | |
var driveType = documentItem.driveType; | |
if (driveType) driveType = "'" + driveType + "'"; | |
var driveName = documentItem.driveName; | |
if (driveName) driveName = "'" + driveName + "'"; | |
var workspaceName = documentItem.workspaceName; | |
if (workspaceName) workspaceName = "'" + workspaceName + "'"; | |
var currentFolder = documentItem.currentFolder; | |
if (currentFolder) currentFolder = "'" + currentFolder + "'"; | |
node.className = 'BreadcumbTab'; | |
strOnclick = "eXo.commons.DocumentSelector.actionBreadcrumbs(" + driveType + "," + driveName + "," + workspaceName + "," + currentFolder + ");"; | |
node.innerHTML = '<a class="' + className + ' href="javascript:void(0);" onclick="' + strOnclick + '">' + name + '</a> '; | |
this.breadCrumb.appendChild(node); | |
}; | |
}; | |
DocumentSelector.prototype.getClazzIcon = function (nodeType) { | |
var strClassIcon = ''; | |
if (!nodeType) { | |
strClassIcon = ".nt_file"; | |
return strClassIcon; | |
} | |
strClassIcon = nodeType.replace("/", "_").replace(":", "_").toLowerCase() + "16x16Icon"; | |
return strClassIcon; | |
}; | |
DocumentSelector.prototype.request = function (url) { | |
var xmlHttpRequest = false; | |
if (window.XMLHttpRequest) { | |
xmlHttpRequest = new window.XMLHttpRequest(); | |
xmlHttpRequest.open("GET", url, false); | |
xmlHttpRequest.send(""); | |
if (xmlHttpRequest.responseXML) return xmlHttpRequest.responseXML; | |
} else if (ActiveXObject("Microsoft.XMLDOM")) { | |
xmlHttpRequest = new ActiveXObject("Microsoft.XMLDOM"); | |
xmlHttpRequest.async = false; | |
xmlHttpRequest.load(urlRequestXML); | |
return xmlHttpRequest; | |
} | |
return null; | |
}; | |
String.prototype.trunc = function (n, useWordBoundary) { | |
var toLong = this.length > n, | |
s_ = toLong ? this.substr(0, n - 1) : this; | |
s_ = useWordBoundary && toLong ? s_.substr(0, s_.lastIndexOf(' ')) : s_; | |
return toLong ? s_ + '...' : s_; | |
}; | |
eXo.commons.DocumentSelector = new DocumentSelector(); | |
if (!eXo.commons) eXo.commons = {}; | |
function UIDSUpload() { | |
this.listUpload = new Array(); | |
this.isAutoUpload = true; | |
}; | |
UIDSUpload.prototype.initUploadEntry = function (uploadId, isAutoUpload) { | |
UIDSUpload.isAutoUpload = isAutoUpload; | |
this.restContext = eXo.env.portal.context + "/" + eXo.env.portal.rest + "/managedocument/uploadFile"; | |
this.createUploadEntry(uploadId, isAutoUpload); | |
}; | |
UIDSUpload.prototype.createUploadEntry = function (uploadId, isAutoUpload) { | |
var me = eXo.commons.UIDSUpload; | |
var iframe = document.getElementById(uploadId + 'uploadFrame'); | |
var idoc = iframe.contentWindow.document; | |
if (eXo.core.Browser.gecko) { | |
idoc.open(); | |
idoc.close(); | |
me.createUploadEntryForFF(idoc, uploadId, isAutoUpload); | |
return; | |
} | |
var uploadAction = me.restContext + "/upload?"; | |
uploadAction += "uploadId=" + uploadId; | |
var uploadHTML = ""; | |
uploadHTML += "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>"; | |
uploadHTML += "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='" + eXo.core.I18n.lang + "' dir='" + eXo.core.I18n.dir + "'>"; | |
uploadHTML += "<head>"; | |
uploadHTML += "<style type='text/css'>"; | |
uploadHTML += this.getStyleSheetContent(); | |
uploadHTML += "</style>"; | |
uploadHTML += "<script type='text/javascript'>var eXo = parent.eXo</script>"; | |
uploadHTML += "</head>"; | |
uploadHTML += "<body style='margin: 0px; border: 0px;'>"; | |
uploadHTML += this.getUploadContent(uploadId, uploadAction, isAutoUpload); | |
uploadHTML += "</body>"; | |
uploadHTML += "</html>"; | |
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) { | |
idoc.open(); | |
idoc.close(); | |
idoc.documentElement.innerHTML = uploadHTML; | |
} else { | |
idoc.open(); | |
idoc.write(uploadHTML); | |
idoc.close(); | |
} | |
}; | |
UIDSUpload.prototype.createUploadEntryForFF = function (idoc, uploadId, isAutoUpload) { | |
var uploadAction = eXo.env.server.context + "/upload?"; | |
uploadAction += "uploadId=" + uploadId + "&action=upload"; | |
var newDoctype = document.implementation.createDocumentType('html', '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); | |
if (idoc.doctype) { | |
idoc.replaceChild(newDoctype, idoc.doctype); | |
} | |
idoc.lang = eXo.core.I18n.lang; | |
idoc.xmlns = 'http://www.w3.org/1999/xhtml'; | |
idoc.dir = eXo.core.I18n.dir; | |
idoc.head = idoc.head || idoc.getElementsByTagName('head')[0]; | |
var script = document.createElement('script'); | |
script.type = "text/javascript"; | |
script.text = "var eXo = parent.eXo"; | |
idoc.head = idoc.head || idoc.getElementsByTagName('head')[0]; | |
idoc.head.appendChild(script); | |
var style = document.createElement('style'); | |
style.type = "text/css"; | |
var styleText = this.getStyleSheetContent(); | |
var cssText = document.createTextNode(styleText); | |
style.appendChild(cssText); | |
idoc.head.appendChild(style); | |
idoc.body.innerHTML = this.getUploadContent(uploadId, uploadAction, isAutoUpload); | |
} | |
UIDSUpload.prototype.getUploadContent = function (uploadId, uploadAction, isAutoUpload) { | |
var container = parent.document.getElementById(uploadId); | |
var uploadIframe = eXo.core.DOMUtil.findDescendantById(container, uploadId + "UploadIframe"); | |
var uploadText = uploadIframe.title; | |
var uploadHTML = ""; | |
uploadHTML += " <form id='" + uploadId + "' class='UIDSUploadForm' style='margin: 0px; padding: 0px' action='" + uploadAction + "' enctype='multipart/form-data' method='post'>"; | |
uploadHTML += " <div class='BrowseDiv'>"; | |
uploadHTML += " <a class='BrowseLink'>"; | |
uploadHTML += " <input type='file' name='file' size='1' id='file' class='FileHidden' value='' onchange='parent.eXo.commons.UIDSUpload.upload(this, " + uploadId + ")'/>"; | |
uploadHTML += " </a>"; | |
uploadHTML += " </div>"; | |
uploadHTML += " </form>"; | |
return uploadHTML; | |
} | |
UIDSUpload.prototype.getStyleSheetContent = function () { | |
var styleText = ""; | |
styleText += "body { margin:0; padding:0}"; | |
styleText += ".UIDSUploadForm {position: relative; }"; | |
styleText += ".FileHidden { opacity: 0; overflow: hidden; position: absolute; height: 32px; top: 0px; left: 0px; width: 100%; -moz-opacity:0 ; filter:alpha(opacity: 0); z-index: 1;} "; | |
styleText += ".BrowseLink { position: relative; font-family: Arial, Helvetica, sans-serif; text-align: left; top:5px;padding: 3px 10px 3px 11px;"; | |
styleText += " text-decoration: none;"; | |
styleText += " background: url('/ecmexplorer/skin/icons/24x24/DefaultSkin/UploadFile.png') no-repeat 2px center;}"; | |
styleText += ".UIDSUploadForm a:hover {text-decoration: underline;}"; | |
return styleText; | |
} | |
UIDSUpload.prototype.refeshProgress = function (elementId) { | |
var me = eXo.commons.UIDSUpload; | |
var documentSelector = eXo.commons.DocumentSelector; | |
var list = me.listUpload; | |
var selectedItem = documentSelector.selectedItem; | |
if (!selectedItem) return; | |
if (list.length < 1) return; | |
var currentFolder = selectedItem.currentFolder; | |
if (!currentFolder) currentFolder = ''; | |
var url = me.restContext + "/control?"; | |
url += "action=progress" + "&workspaceName=" + selectedItem.workspaceName + "&driveName=" + selectedItem.driveName + "¤tFolder=" + currentFolder + "¤tPortal=" + eXo.env.portal.portalName + "&language=" + eXo.env.portal.language + "&uploadId=" + elementId; | |
var data = null; | |
if (list.length > 0) { | |
var data = documentSelector.request(url); | |
setTimeout("eXo.commons.UIDSUpload.refeshProgress('" + elementId + "');", 1000); | |
} else { | |
return; | |
} | |
var container = parent.document.getElementById(elementId); | |
if (!data) { | |
this.abortUpload(elementId); | |
var message = eXo.core.DOMUtil.findFirstChildByClass(container, "div", "LimitMessage").innerHTML; | |
alert(message.replace("{0}", response.upload[id].size)); | |
return; | |
} else { | |
var element = document.getElementById(elementId + "ProgressIframe"); | |
var nodeList = data.getElementsByTagName("UploadProgress"); | |
if (!nodeList) return; | |
var oProgress; | |
if (nodeList.length > 0) oProgress = nodeList[0]; | |
var percent = oProgress.getAttribute("percent"); | |
var fileName = oProgress.getAttribute("fileName"); | |
var progressBarLabel = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarLabel"); | |
progressBarLabel.innerHTML = percent + "%"; | |
if (percent == 100) { | |
me.listUpload.remove(elementId); | |
if (!fileName || fileName == "") { | |
alert(container.getAttribute("upload_failed")); | |
} | |
me.saveUploaded(elementId, fileName); | |
documentSelector.renderDetails(selectedItem); | |
documentSelector.selectUploadedFile(fileName); | |
var refreshUpload = eXo.core.DOMUtil.findFirstDescendantByClass(container, "a", "RefreshUpload"); | |
if (refreshUpload) { | |
eval(refreshUpload.href); | |
} | |
} | |
} | |
}; | |
UIDSUpload.prototype.saveUploaded = function (uploadId, fileName) { | |
var me = eXo.commons.UIDSUpload; | |
var selectedItem = eXo.commons.DocumentSelector.selectedItem; | |
var url = me.restContext + "/control?"; | |
url += "action=save" + "&workspaceName=" + selectedItem.workspaceName + "&driveName=" + selectedItem.driveName + "¤tFolder=" + selectedItem.currentFolder + "¤tPortal=" + eXo.env.portal.portalName + "&language=" + eXo.env.portal.language + "&uploadId=" + uploadId + "&fileName=" + fileName; | |
var responseText = ajaxAsyncGetRequest(url, false); | |
}; | |
UIDSUpload.prototype.showUploaded = function (id) { | |
eXo.commons.UIDSUpload.listUpload.remove(id); | |
var container = parent.document.getElementById(id); | |
var element = document.getElementById(id + "ProgressIframe"); | |
element.innerHTML = "<span></span>"; | |
var uploadIframe = eXo.core.DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "block"; | |
var progressIframe = eXo.core.DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var progressBarFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "none"; | |
var tmp = element.parentNode; | |
var temp = tmp.parentNode; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "true"; | |
}; | |
UIDSUpload.prototype.abortUpload = function (id) { | |
var me = eXo.commons.UIDSUpload; | |
me.listUpload.remove(id); | |
var url = me.restContext + "/control?"; | |
url += "uploadId=" + id + "&action=abort"; | |
var request = eXo.core.Browser.createHttpRequest(); | |
request.open('GET', url, false); | |
request.setRequestHeader("Cache-Control", "max-age=86400"); | |
request.send(null); | |
var container = parent.document.getElementById(id); | |
var uploadIframe = eXo.core.DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "block"; | |
me.createUploadEntry(id, UIDSUpload.isAutoUpload); | |
var progressIframe = eXo.core.DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var tmp = progressIframe.parentNode; | |
var temp = tmp.parentNode; | |
var progressBarFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "none"; | |
var selectFileFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "SelectFileFrame"); | |
selectFileFrame.style.display = "none"; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "false"; | |
}; | |
UIDSUpload.prototype.upload = function (clickEle, id) { | |
var DOMUtil = eXo.core.DOMUtil; | |
var me = eXo.commons.UIDSUpload; | |
var selectedItem = eXo.commons.DocumentSelector.selectedItem; | |
var container = parent.document.getElementById(id); | |
var uploadIFrame = parent.document.getElementById(id + "UploadIframe"); | |
var uploadFrame = parent.document.getElementById(id + "uploadFrame"); | |
if (!selectedItem || !selectedItem.driveName) { | |
alert(uploadIFrame.getAttribute("select_drive")); | |
file.value == ''; | |
return; | |
} | |
var canAddChild = selectedItem.canAddChild; | |
if (canAddChild == "false") { | |
alert(uploadIFrame.getAttribute("permission_required")); | |
file.value == ''; | |
return; | |
} | |
var form = uploadFrame.contentWindow.document.getElementById(id); | |
var file = DOMUtil.findDescendantById(form, "file"); | |
if (file.value == null || file.value == '') return; | |
var progressBarFrame = DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame"); | |
progressBarFrame.style.display = "block"; | |
var progressBarLabel = DOMUtil.findFirstChildByClass(progressBarFrame, "div", "ProgressBarLabel"); | |
progressBarLabel.innerHTML = "0%"; | |
var input = parent.document.getElementById('input' + id); | |
input.value = "true"; | |
var uploadIframe = DOMUtil.findDescendantById(container, id + "UploadIframe"); | |
uploadIframe.style.display = "none"; | |
var progressIframe = DOMUtil.findDescendantById(container, id + "ProgressIframe"); | |
progressIframe.style.display = "none"; | |
var tmp = progressIframe.parentNode; | |
var temp = tmp.parentNode; | |
form.submit(); | |
var list = me.listUpload; | |
if (list.length == 0) { | |
me.listUpload.push(form.id); | |
setTimeout("eXo.commons.UIDSUpload.refeshProgress('" + id + "');", 1000); | |
} else { | |
me.listUpload.push(form.id); | |
} | |
}; | |
UIDSUpload.prototype.validate = function (name) { | |
if (name.indexOf(':') >= 0 || name.indexOf('/') >= 0 || name.indexOf('\\') >= 0 || name.indexOf('|') >= 0 || name.indexOf('^') >= 0 || name.indexOf('#') >= 0 || name.indexOf(';') >= 0 || name.indexOf('[') >= 0 || name.indexOf(']') >= 0 || name.indexOf('{') >= 0 || name.indexOf('}') >= 0 || name.indexOf('<') >= 0 || name.indexOf('>') >= 0 || name.indexOf('*') >= 0 || name.indexOf('\'') >= 0 || name.indexOf('\"') >= 0 || name.indexOf('+') >= 0) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
eXo.commons.UIDSUpload = new UIDSUpload(); | |
UIForm.prototype.submitForm = function (formId, action, useAjax, callback) { | |
if (!callback) callback = null; | |
var form = this.getFormElemt(formId); | |
try { | |
if (FCKeditorAPI && typeof FCKeditorAPI == "object") { | |
for (var name in FCKeditorAPI.__Instances) { | |
var oEditor; | |
try { | |
oEditor = FCKeditorAPI.__Instances[name]; | |
if (oEditor && oEditor.GetParentForm && oEditor.GetParentForm() == form) { | |
oEditor.UpdateLinkedField(); | |
} | |
} catch (e) { | |
continue; | |
} | |
} | |
} | |
} catch (e) {} | |
try { | |
if (CKEDITOR && typeof CKEDITOR == "object") { | |
for (var i in CKEDITOR.instances) { | |
if (document.getElementById(i)) CKEDITOR.instances[i].updateElement(); | |
} | |
} | |
} catch (e) {} | |
form.elements['formOp'].value = action; | |
if (useAjax) this.ajaxPost(form, callback); | |
else form.submit(); | |
}; | |
function getUrlParam(paramName) { | |
var oRegex = new RegExp("[\?&]" + paramName + "=([^&]+)", "i"); | |
var oMatch = oRegex.exec(window.location.search); | |
if (oMatch && oMatch.length > 1) return oMatch[1]; | |
else return ""; | |
} | |
function ajaxGet(url, callback) { | |
if (!callback) callback = null; | |
var path = getUrlParam("path"); | |
if (path) url += "&path=" + path; | |
doRequest("Get", url, null, callback); | |
}; | |
UIForm.prototype.ajaxPost = function (formElement, callback) { | |
if (!callback) callback = null; | |
var queryString = eXo.webui.UIForm.serializeForm(formElement); | |
var url = formElement.action + "&ajaxRequest=true"; | |
var path = getUrlParam("path"); | |
if (path) url += "&path=" + path; | |
doRequest("POST", url, queryString, callback); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment