/** ***** BEGIN LICENSE BLOCK *****
* |------------------------------------------------------------------------------|
* | O2OA 活力办公 创意无限 o2.js |
* |------------------------------------------------------------------------------|
* | Distributed under the AGPL license: |
* |------------------------------------------------------------------------------|
* | Copyright © 2018, o2oa.net, o2server.io O2 Team |
* | All rights reserved. |
* |------------------------------------------------------------------------------|
*
* This file is part of O2OA.
*
* O2OA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* O2OA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see .
*
* ***** END LICENSE BLOCK ******/
(function(){
var _href = window.location.href;
var _debug = (_href.indexOf("debugger")!==-1);
var _par = _href.substr(_href.lastIndexOf("?")+1, _href.length);
var _lp = "zh-cn";
if (_par){
var _parList = _par.split("&");
for (var i=0; i<_parList.length; i++){
var _v = _parList[i];
var _kv = _v.split("=");
if (_kv[0].toLowerCase()==="lg") _lp = _kv[1];
}
}
this.o2 = {
"version": {
"v": '2.1.0',
"build": "2018.11.22",
"info": "O2OA 活力办公 创意无限. Copyright © 2018, o2oa.net O2 Team All rights reserved."
},
"session": {
"isDebugger": _debug,
"path": "/o2_core/o2"
},
"language": _lp,
"splitStr": /\s*(?:,|;)\s*/
};
var _attempt = function(){
for (var i = 0, l = arguments.length; i < l; i++){
try {
arguments[i]();
return arguments[i];
} catch (e){}
}
return null;
};
var _typeOf = function(item){
if (item == null) return 'null';
if (item.$family != null) return item.$family();
if (item.constructor == window.Array) return "array";
if (item.nodeName){
if (item.nodeType == 1) return 'element';
if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
} else if (typeof item.length == 'number'){
if (item.callee) return 'arguments';
}
return typeof item;
};
this.o2.typeOf = _typeOf;
var _addListener = function(dom, type, fn){
if (type == 'unload'){
var old = fn, self = this;
fn = function(){
_removeListener(dom, 'unload', fn);
old();
};
}
if (dom.addEventListener) dom.addEventListener(type, fn, !!arguments[2]);
else dom.attachEvent('on' + type, fn);
};
var _removeListener = function(dom, type, fn){
if (dom.removeEventListener) dom.removeEventListener(type, fn, !!arguments[2]);
else dom.detachEvent('on' + type, fn);
};
//http request class
var _request = (function(){
var XMLHTTP = function(){ return new XMLHttpRequest(); };
var MSXML2 = function(){ return new ActiveXObject('MSXML2.XMLHTTP'); };
var MSXML = function(){ return new ActiveXObject('Microsoft.XMLHTTP'); };
return _attempt(XMLHTTP, MSXML2, MSXML);
})();
var _returnBase = function(number, base) {
return (number).toString(base).toUpperCase();
};
var _getIntegerBits = function(val, start, end){
var base16 = _returnBase(val, 16);
var quadArray = new Array();
var quadString = '';
var i = 0;
for (i = 0; i < base16.length; i++) {
quadArray.push(base16.substring(i, i + 1));
}
for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
if (!quadArray[i] || quadArray[i] == '')
quadString += '0';
else
quadString += quadArray[i];
}
return quadString;
};
var _rand = function(max) {
return Math.floor(Math.random() * (max + 1));
};
this.o2.addListener = _addListener;
this.o2.removeListener = _removeListener;
//uuid
var _uuid = function(){
var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
var dc = new Date();
var t = dc.getTime() - dg.getTime();
var tl = _getIntegerBits(t, 0, 31);
var tm = _getIntegerBits(t, 32, 47);
var thv = _getIntegerBits(t, 48, 59) + '1';
var csar = _getIntegerBits(_rand(4095), 0, 7);
var csl = _getIntegerBits(_rand(4095), 0, 7);
var n = _getIntegerBits(_rand(8191), 0, 7)
+ _getIntegerBits(_rand(8191), 8, 15)
+ _getIntegerBits(_rand(8191), 0, 7)
+ _getIntegerBits(_rand(8191), 8, 15)
+ _getIntegerBits(_rand(8191), 0, 15);
return tl + tm + thv + csar + csl + n;
};
this.o2.uuid = _uuid;
var _runCallback = function(callback, key, par){
if (typeOf(callback).toLowerCase() === 'function'){
if (key.toLowerCase()==="success") callback.apply(callback, par);
}else{
if (typeOf(callback).toLowerCase()==='object'){
var name = ("on-"+key).camelCase();
if (callback[name]) callback[name].apply(callback, par);
}
}
};
this.o2.runCallback = _runCallback;
//load js, css, html adn all.
var _getAllOptions = function(options){
var doc = (options && options.doc) || document;
if (!doc.unid) doc.unid = _uuid();
return {
"noCache": !!(options && options.nocache),
"reload": !!(options && options.reload),
"sequence": !!(options && options.sequence),
"doc": doc,
"dom": (options && options.dom) || document.body,
"bind": (options && options.bind) || null,
"position": (options && options.position) || "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
}
};
var _getCssOptions = function(options){
var doc = (options && options.doc) || document;
if (!doc.unid) doc.unid = _uuid();
return {
"noCache": !!(options && options.nocache),
"reload": !!(options && options.reload),
"sequence": !!(options && options.sequence),
"doc": doc,
"dom": (options && options.dom) || null
}
};
var _getJsOptions = function(options){
var doc = (options && options.doc) || document;
if (!doc.unid) doc.unid = _uuid();
return {
"noCache": !!(options && options.nocache),
"reload": !!(options && options.reload),
"sequence": (!(options && options.sequence == false)),
"doc": doc
}
};
var _getHtmlOptions = function(options){
var doc = (options && options.doc) || document;
if (!doc.unid) doc.unid = _uuid();
return {
"noCache": !!(options && options.nocache),
"reload": !!(options && options.reload),
"sequence": !!(options && options.sequence),
"doc": doc,
"dom": (options && options.dom) || null,
"bind": (options && options.bind) || null,
"position": (options && options.position) || "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
}
};
var _xhr_get = function(url, success, failure, completed){
var xhr = new _request();
xhr.open("GET", url, true);
var _checkCssLoaded= function(_, err){
if (!(xhr.readyState == 4)) return;
if (err){
if (completed) completed(xhr);
return;
}
_removeListener(xhr, 'readystatechange', _checkCssLoaded);
_removeListener(xhr, 'load', _checkCssLoaded);
_removeListener(xhr, 'error', _checkCssErrorLoaded);
if (err) {failure(xhr); return}
var status = xhr.status;
status = (status == 1223) ? 204 : status;
if ((status >= 200 && status < 300))
success(xhr);
else if ((status >= 300 && status < 400))
failure(xhr);
else
failure(xhr);
if (completed) completed(xhr);
};
var _checkCssErrorLoaded= function(err){ _checkCssLoaded(err) };
if ("load" in xhr) _addListener(xhr, "load", _checkCssLoaded);
if ("error" in xhr) _addListener(xhr, "load", _checkCssErrorLoaded);
_addListener(xhr, "readystatechange", _checkCssLoaded);
xhr.send();
};
var _loadSequence = function(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun){
loadSingle(ms[n], function(module){
if (module) thisLoaded.push(module);
n++;
if (fun) fun(module);
if (n===ms.length){
if (cb) cb(thisLoaded);
}else{
_loadSequence(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun);
}
}, op, uuid);
};
var _loadDisarray = function(ms, cb, op, thisLoaded, loadSingle, uuid, fun){
var count=0;
for (var i=0; i*/
// doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
// testElement.doScroll() throws when the DOM is not ready, only in the top window
doScrollWorks: function(){
try {
_dom.testElement.doScroll();
return true;
} catch (e){}
return false;
},
/**/
onReady: function(){
for (var i=0; i<_dom.readys.length; i++){
this.readys[i].apply(window);
}
},
addReady: function(fn){
if (_dom.loaded){
if (fn) fn.apply(window);
}else{
if (fn) _dom.readys.push(fn);
}
return _dom;
},
checkReady: function(){
_dom.checks.push(function(){return true});
_dom.check();
}
};
var _loadO2 = function(){
this.o2.load("o2.core", _dom.check);
this.o2.load("o2.more", _dom.check);
};
_addListener(document, 'DOMContentLoaded', _dom.checkReady);
/**/
// If doScroll works already, it can't be used to determine domready
// e.g. in an iframe
if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
_dom.checks.push(_dom.doScrollWorks);
_dom.shouldPoll = true;
}
/**/
if (document.readyState) _dom.checks.push(function(){
var state = document.readyState;
return (state == 'loaded' || state == 'complete');
});
if ('onreadystatechange' in document) _addListener(document, 'readystatechange', _dom.check);
else _dom.shouldPoll = true;
if (_dom.shouldPoll) _dom.poll();
if (!window.MooTools){
this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
}else{
_loadO2();
}
this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
})();
layout = window.layout || {};
layout.desktop = layout;
var locate = window.location;
layout.protocol = locate.protocol;
layout.session = layout.session || {};
layout.debugger = (locate.href.toString().indexOf("debugger")!==-1);
o2.xApplication = o2.xApplication || {};
o2.xDesktop = o2.xDesktop || {};
o2.xDesktop.requireApp = function(module, clazz, callback, async){
o2.requireApp(module, clazz, callback, async);
};
o2.addReady(function(){
//兼容方法
Element.implement({
"makeLnk": function(options){}
});
//异步载入必要模块
layout.config = null;
var lp = o2.session.path+"/lp/"+o2.language+".js";
var modules = [ "MWF.xDesktop.Common", "MWF.xAction.RestActions",lp];
MWF.require(modules, function(){
if (layout.config) _getDistribute(function(){ _load(); });
});
o2.getJSON("/x_desktop/res/config/config.json", function(config){
layout.config = config;
if (MWF.xDesktop.getServiceAddress) _getDistribute(function(){ _load(); });
});
var _getDistribute = function(callback){
if (layout.config.app_protocol==="auto"){
layout.config.app_protocol = window.location.protocol;
}
MWF.xDesktop.getServiceAddress(layout.config, function(service, center){
layout.serviceAddressList = service;
layout.centerServer = center;
if (callback) callback();
}.bind(this));
};
var _load = function(){
//先判断用户是否登录
MWF.Actions.get("x_organization_assemble_authentication").getAuthentication(function(json){
//用户已经登录
layout.user = json.data;
layout.session = {};
layout.session.user = json.data;
(function(layout){
var _loadResource = function(callback){
var isLoadedA = false;
var isLoadedB = false;
//var isLoadedC = false;
var modules = [
"o2.xDesktop.Dialog",
"MWF.xDesktop.UserData",
"MWF.xDesktop.Access",
"MWF.widget.UUID",
"MWF.xDesktop.Menu",
"MWF.xDesktop.shortcut",
"MWF.widget.PinYin",
"MWF.xDesktop.Access",
"MWF.xDesktop.MessageMobile",
"MWF.xScript.Macro"
];
//MWF.xDesktop.requireApp("Common", "", null, false);
var _check = function(){ if (isLoadedA && isLoadedB) if (callback) callback(); };
o2.load(["../o2_lib/mootools/plugin/mBox.min.js"], function(){isLoadedA = true; _check();});
o2.require("MWF.widget.Common", function(){
o2.require(modules, function(){
o2.requireApp("Common", "", function(){isLoadedB = true; _check();})
});
});
};
var _loadContent =function(){
_loadResource(function(){
//this.Macro = new MWF.Macro["PageContext"](this);
for (var i=0; i