base.js 23.4 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2
layout = window.layout || {};
layout.desktop = layout;
NoSubject's avatar
NoSubject 已提交
3
layout.desktop.type = "app";
NoSubject's avatar
NoSubject 已提交
4 5
var locate = window.location;
layout.protocol = locate.protocol;
R
roo00 已提交
6
layout.inBrowser = true;
NoSubject's avatar
NoSubject 已提交
7
layout.session = layout.session || {};
R
roo00 已提交
8 9
layout.debugger = (locate.href.toString().indexOf("debugger") !== -1);
layout.anonymous = (locate.href.toString().indexOf("anonymous") !== -1);
NoSubject's avatar
NoSubject 已提交
10 11 12
o2.xApplication = o2.xApplication || {};

o2.xDesktop = o2.xDesktop || {};
R
roo00 已提交
13
o2.xDesktop.requireApp = function (module, clazz, callback, async) {
NoSubject's avatar
NoSubject 已提交
14 15 16
    o2.requireApp(module, clazz, callback, async);
};

R
roo00 已提交
17
(function (layout) {
NoSubject's avatar
NoSubject 已提交
18
    layout.readys = [];
R
roo00 已提交
19 20 21
    layout.addReady = function () {
        for (var i = 0; i < arguments.length; i++) {
            if (o2.typeOf(arguments[i]) === "function") layout.readys.push(arguments[i]);
NoSubject's avatar
NoSubject 已提交
22 23
        }
    };
R
roo00 已提交
24
    var _requireApp = function (appNames, callback, clazzName) {
NoSubject's avatar
NoSubject 已提交
25 26
        var appPath = appNames.split(".");
        var baseObject = o2.xApplication;
R
roo00 已提交
27 28
        appPath.each(function (path, i) {
            if (i < (appPath.length - 1)) {
NoSubject's avatar
NoSubject 已提交
29
                baseObject[path] = baseObject[path] || {};
R
roo00 已提交
30
            } else {
NoSubject's avatar
NoSubject 已提交
31
                baseObject[path] = baseObject[path] || { "options": Object.clone(o2.xApplication.Common.options) };
NoSubject's avatar
NoSubject 已提交
32 33 34
            }
            baseObject = baseObject[path];
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
35
        if (!baseObject.options) baseObject.options = Object.clone(o2.xApplication.Common.options);
NoSubject's avatar
NoSubject 已提交
36 37

        var _lpLoaded = false;
NoSubject's avatar
NoSubject 已提交
38
        o2.xDesktop.requireApp(appNames, "lp." + o2.language, {
R
roo00 已提交
39
            "failure": function () {
NoSubject's avatar
NoSubject 已提交
40
                o2.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
NoSubject's avatar
NoSubject 已提交
41 42
            }.bind(this)
        }, false);
R
roo00 已提交
43

NoSubject's avatar
NoSubject 已提交
44
        o2.xDesktop.requireApp(appNames, clazzName, function () {
NoSubject's avatar
NoSubject 已提交
45 46 47
            if (callback) callback(baseObject);
        });
    };
NoSubject's avatar
NoSubject 已提交
48 49 50 51
    var _createNewApplication = function (e, appNamespace, appName, options, statusObj, inBrowser, taskitem, notCurrent) {
        if (options){ options.event = e; }else{ options = {"event": e}; }
        var app = new appNamespace["Main"](layout.desktop, options);
        app.desktop = layout.desktop;
NoSubject's avatar
NoSubject 已提交
52
        app.status = statusObj;
NoSubject's avatar
NoSubject 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        app.inBrowser = !!(inBrowser || layout.inBrowser);

        if (layout.desktop.type === "layout"){
            app.appId = (options.appId) ? options.appId : ((appNamespace.options.multitask) ? appName + "-" + (new o2.widget.UUID()) : appName);
            app.options.appId = app.appId;

            if (!taskitem) taskitem = layout.desktop.createTaskItem(app);
            app.taskitem = taskitem;
            app.taskitem.app = app;

            // if (layout.viewMode=="Default"){
            //     if (!notCurrent){
            //         app.load(!notCurrent);
            //     }else{
            //         app.isLoadApplication = false;
            //     }
            // }else{
            //     app.load(!notCurrent);
            // }
            app.isLoadApplication = true;
            app.load(!notCurrent);

            if (!layout.desktop.apps) layout.desktop.apps = {};
            if (layout.desktop.apps[app.appId]){
                var tmpApp = layout.desktop.apps[app.appId];

            }else{
                layout.desktop.apps[app.appId] = app;
            }
R
roo00 已提交
82

NoSubject's avatar
NoSubject 已提交
83

NoSubject's avatar
NoSubject 已提交
84 85 86 87 88 89 90 91 92

            layout.desktop.appArr.push(app);
            layout.desktop.appCurrentList.push(app);
            if (!notCurrent) layout.desktop.currentApp = app;

            //app.taskitem = new MWF.xDesktop.Layout.Taskitem(app, this);
        }else{
            app.load(true);
            layout.app = app;
NoSubject's avatar
NoSubject 已提交
93
        }
NoSubject's avatar
NoSubject 已提交
94 95


NoSubject's avatar
NoSubject 已提交
96 97 98 99 100

        var mask = document.getElementById("appContentMask");
        if (mask) mask.destroy();
    };

R
roo00 已提交
101
    var _openWorkAndroid = function (options) {
NoSubject's avatar
NoSubject 已提交
102 103
        if (window.o2android && window.o2android.openO2Work) {
            if (options.workId) {
NoSubject's avatar
NoSubject 已提交
104
                window.o2android.openO2Work(options.workId, "", options.title || "");
NoSubject's avatar
NoSubject 已提交
105
            } else if (options.workCompletedId) {
NoSubject's avatar
NoSubject 已提交
106
                window.o2android.openO2Work("", options.workCompletedId, options.title || "");
NoSubject's avatar
NoSubject 已提交
107 108 109 110 111
            }
            return true;
        }
        return false;
    };
R
roo00 已提交
112
    var _openWorkIOS = function (options) {
NoSubject's avatar
NoSubject 已提交
113 114 115 116 117
        if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
            if (options.workId) {
                window.webkit.messageHandlers.openO2Work.postMessage({
                    "work": options.workId,
                    "workCompleted": "",
NoSubject's avatar
NoSubject 已提交
118
                    "title": options.title || ""
NoSubject's avatar
NoSubject 已提交
119 120 121 122 123
                });
            } else if (options.workCompletedId) {
                window.webkit.messageHandlers.openO2Work.postMessage({
                    "work": "",
                    "workCompleted": options.workCompletedId,
NoSubject's avatar
NoSubject 已提交
124
                    "title": options.title || ""
NoSubject's avatar
NoSubject 已提交
125 126 127 128 129 130
                });
            }
            return true;
        }
        return false;
    };
R
roo00 已提交
131
    var _openWorkHTML = function (options) {
NoSubject's avatar
NoSubject 已提交
132 133 134 135 136 137 138 139
        var uri = new URI(window.location.href);
        var redirectlink = uri.getData("redirectlink");
        if (!redirectlink) {
            redirectlink = encodeURIComponent(locate.pathname + locate.search);
        } else {
            redirectlink = encodeURIComponent(redirectlink);
        }
        if (options.workId) {
R
roo00 已提交
140
            window.location = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
NoSubject's avatar
NoSubject 已提交
141
        } else if (options.workCompletedId) {
R
roo00 已提交
142
            window.location = "workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
NoSubject's avatar
NoSubject 已提交
143 144
        }
    };
R
roo00 已提交
145
    var _openWork = function (options) {
NoSubject's avatar
NoSubject 已提交
146 147
        if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
    };
R
roo00 已提交
148 149
    var _openDocument = function (appNames, options, statusObj) {
        var title = typeOf(options) === "object" ? (options.docTitle || options.title) : "";
NoSubject's avatar
NoSubject 已提交
150
        title = title || "";
R
roo00 已提交
151 152
        var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
        if (window.o2android && window.o2android.openO2CmsDocument) {
NoSubject's avatar
NoSubject 已提交
153
            window.o2android.openO2CmsDocument(options.documentId, title);
R
roo00 已提交
154 155 156 157
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument) {
            window.webkit.messageHandlers.openO2CmsDocument.postMessage({ "docId": options.documentId, "docTitle": title });
        } else {
            window.location = "appMobile.html?" + par + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
158 159
        }
    };
R
roo00 已提交
160 161 162
    var _openCms = function (appNames, options, statusObj) {
        var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
        if (window.o2android && window.o2android.openO2CmsApplication) {
NoSubject's avatar
NoSubject 已提交
163
            window.o2android.openO2CmsApplication(options.columnId, options.title || "");
R
roo00 已提交
164
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication) {
NoSubject's avatar
NoSubject 已提交
165
            window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
R
roo00 已提交
166 167
        } else {
            window.location = "appMobile.html?" + par + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
168 169
        }
    };
R
roo00 已提交
170 171 172
    var _openMeeting = function (appNames, options, statusObj) {
        var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
        if (window.o2android && window.o2android.openO2Meeting) {
NoSubject's avatar
NoSubject 已提交
173
            window.o2android.openO2Meeting("");
R
roo00 已提交
174
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting) {
NoSubject's avatar
NoSubject 已提交
175
            window.webkit.messageHandlers.openO2Meeting.postMessage("");
R
roo00 已提交
176 177
        } else {
            window.location = "appMobile.html?" + par + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
178 179 180
        }
    };

R
roo00 已提交
181 182 183
    var _openCalendar = function (appNames, options, statusObj) {
        var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
        if (window.o2android && window.o2android.openO2Calendar) {
NoSubject's avatar
NoSubject 已提交
184
            window.o2android.openO2Calendar("");
R
roo00 已提交
185
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar) {
NoSubject's avatar
NoSubject 已提交
186
            window.webkit.messageHandlers.openO2Calendar.postMessage("");
R
roo00 已提交
187 188
        } else {
            window.location = "appMobile.html?" + par + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
189 190
        }
    };
R
roo00 已提交
191 192
    var _openTaskCenter = function (appNames, options, statusObj) {
        var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
NoSubject's avatar
NoSubject 已提交
193
        var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
R
roo00 已提交
194 195
        if (tab === "done") tab = "taskCompleted";
        if (tab === "readed") tab = "readCompleted";
NoSubject's avatar
NoSubject 已提交
196

R
roo00 已提交
197
        if (window.o2android && window.o2android.openO2WorkSpace) {
NoSubject's avatar
NoSubject 已提交
198
            window.o2android.openO2WorkSpace(tab);
R
roo00 已提交
199
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace) {
NoSubject's avatar
NoSubject 已提交
200
            window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
R
roo00 已提交
201 202
        } else {
            window.location = "appMobile.html?" + par + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
203 204 205
        }
    };

R
roo00 已提交
206
    var _openApplicationMobile = function (appNames, options, statusObj) {
NoSubject's avatar
NoSubject 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
        switch (appNames) {
            case "process.Work":
                _openWork(options);
                break;
            case "cms.Document":
                _openDocument(appNames, options, statusObj);
                break;
            case "cms.Module":
                _openCms(appNames, options, statusObj);
                break;
            case "Meeting":
                _openMeeting(appNames, options, statusObj);
                break;
            case "Calendar":
                _openCalendar(appNames, options, statusObj);
                break;
            case "process.TaskCenter":
                _openTaskCenter(appNames, options, statusObj);
                break;
            default:
R
roo00 已提交
227 228 229
                var uri = new URI(window.location.href);
                var optionsStr = uri.getData("option");
                var statusStr = uri.getData("status");
R
roo00 已提交
230
                window.location = "appMobile.html?app=" + appNames + "&option=" + (optionsStr || "") + "&status=" + (statusStr || "") + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
231
        }
NoSubject's avatar
NoSubject 已提交
232 233
    };

NoSubject's avatar
NoSubject 已提交
234 235 236 237 238 239 240 241 242 243
    layout.openApplication = function (e, appNames, options, statusObj, inBrowser, taskitem, notCurrent) {
        if (appNames.substring(0, 4)==="@url"){
            var url = appNames.replace(/\@url\:/i, "");
            var a = new Element("a", {"href": url, "target": "_blank"});
            a.click();
            a.destroy();
            a = null;
            return true;
        }

R
roo00 已提交
244 245
        if (layout.app) {
            if (layout.mobile) {
NoSubject's avatar
NoSubject 已提交
246
                _openApplicationMobile(appNames, options, statusObj);
R
roo00 已提交
247 248 249 250 251 252 253 254
            } else {
                var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");

                if (layout.app.$openWithSelf) {
                    return window.location = "app.html?" + par + ((layout.debugger) ? "&debugger" : "");
                } else {
                    return window.open("app.html?" + par + ((layout.debugger) ? "&debugger" : ""), par);
                }
NoSubject's avatar
NoSubject 已提交
255
            }
R
roo00 已提交
256
        } else {
NoSubject's avatar
NoSubject 已提交
257
            var appPath = appNames.split(".");
R
roo00 已提交
258 259
            var appName = appPath[appPath.length - 1];
            _requireApp(appNames, function (appNamespace) {
NoSubject's avatar
NoSubject 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
                var appId = (options && options.appId) ? options.appId : ((appNamespace.options.multitask) ? "" : appName);

                if (appId && layout.desktop.apps && layout.desktop.apps[appId] && layout.desktop.apps[appId].window){
                    layout.desktop.apps[appId].setCurrent();
                }else{
                    if (options) options.appId = appId;
                    _createNewApplication(e, appNamespace, appName, (options || {"appId": appId}), statusObj, inBrowser, taskitem, notCurrent);
                }
                // if (appNamespace.options.multitask){
                //     if (options && options.appId){
                //         if (layout.desktop.apps[options.appId]){
                //             layout.desktop.apps[options.appId].setCurrent();
                //         }else {
                //             _createNewApplication(e, appNamespace, appName, options, obj, inBrowser);
                //         }
                //     }else{
                //         _createNewApplication(e, appNamespace, appName, options, obj, inBrowser);
                //     }
                // }else{
                //     if (layout.desktop.apps[appName]){
                //         layout.desktop.apps[appName].setCurrent();
                //     }else{
                //         _createNewApplication(e, appNamespace, appName, options, obj, inBrowser);
                //     }
                // }
                // _createNewApplication(e, appNamespace, appName, (options || {}), statusObj, inBrowser);
NoSubject's avatar
NoSubject 已提交
286 287 288 289
            }.bind(this));
        }
    };

R
roo00 已提交
290
    layout.refreshApp = function (app) {
NoSubject's avatar
NoSubject 已提交
291 292 293 294 295 296 297 298 299
        var status = app.recordStatus();

        var uri = new URI(window.location.href);
        var appNames = uri.getData("app");
        var optionsStr = uri.getData("option");
        var statusStr = uri.getData("status");
        if (status) statusStr = JSON.encode(status);

        var port = uri.get("port");
R
roo00 已提交
300
        window.location = uri.get("scheme") + "://" + uri.get("host") + ((port) ? ":" + port + "/" : "") + uri.get("directory ") + "?app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent(statusStr) + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "") + ((layout.debugger) ? "&debugger" : "");
NoSubject's avatar
NoSubject 已提交
301 302
    };

R
roo00 已提交
303
    layout.load = function (appNames, options, statusObj) {
NoSubject's avatar
NoSubject 已提交
304 305
        // layout.message = new o2.xDesktop.MessageMobile();
        // layout.message.load();
NoSubject's avatar
NoSubject 已提交
306 307 308

        layout.apps = [];
        layout.node = $("layout");
R
roo00 已提交
309
        var appName = appNames, m_status = statusObj, option = options;
NoSubject's avatar
NoSubject 已提交
310 311

        var topWindow = window.opener;
R
roo00 已提交
312 313
        if (topWindow) {
            try {
NoSubject's avatar
NoSubject 已提交
314 315
                if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
                if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
R
roo00 已提交
316 317
                if (!option) option = topWindow.layout.desktop.openBrowserOption;
            } catch (e) { }
NoSubject's avatar
NoSubject 已提交
318
        }
R
roo00 已提交
319
        layout.openApplication(null, appName, option || {}, m_status);
NoSubject's avatar
NoSubject 已提交
320
    };
NoSubject's avatar
NoSubject 已提交
321

R
roo00 已提交
322
})(layout);
NoSubject's avatar
NoSubject 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541

o2.addReady(function () {
    // layout.desktop = new (new Class({Implements: [Options, Events]}))();
    // layout.desktop.openApplication = layout.openApplication;
    // layout.desktop.refreshApp = layout.refreshApp;
    // layout.desktop.load = layout.load;

    //兼容方法
    Element.implement({
        "makeLnk": function (options) { }
    });
    layout.desktop.addEvent = function(type, e, d){
        window.addEvent(type, e, d);
    };
    layout.desktop.addEvents = function(e){
        window.addEvents(e);
    };

    var loadingNode = $("loaddingArea");
    var loadeds = 0;
    var loadCount = 16;
    var size = document.body.getSize();
    var _closeLoadingNode = function () {
        if (loadingNode) {
            loadingNode.destroy();
            loadingNode = null;
        }

    };
    var _loadProgressBar = function (complete) {
        if (loadingNode) {
            if (complete) {
                loadingNode.setStyles({ "width": "" + size.x + "px" });
                //loadingNode.set('morph', {duration: 100}).morph({"width": ""+size.x+"px"});
                window.setTimeout(_closeLoadingNode, 500);
            } else {
                loadeds++;
                var p = (loadeds / loadCount) * size.x;
                loadingNode.setStyles({ "width": "" + p + "px" });
                //loadingNode.set('morph', {duration: 100}).morph({"width": ""+p+"px"});
                if (loadeds >= loadCount) window.setTimeout(_closeLoadingNode, 500);
            }
        }
    };

    //异步载入必要模块
    layout.config = null;
    var configLoaded = false;
    var lpLoaded = false;
    var commonLoaded = false;
    var lp = o2.session.path + "/lp/" + o2.language + ".js";
    o2.load(lp, function () {
        _loadProgressBar();
        lpLoaded = true;
        if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
    });
    var modules = ["o2.xDesktop.Common", "o2.xDesktop.Actions.RestActions", "o2.xAction.RestActions"];
    o2.require(modules, {
        "onSuccess": function () {
            commonLoaded = true;
            if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
        },
        "onEvery": function () {
            _loadProgressBar();
        }
    });
    o2.getJSON("/x_desktop/res/config/config.json", function (config) {
        _loadProgressBar();
        layout.config = config;
        configLoaded = true
        if (configLoaded && commonLoaded && lpLoaded) _getDistribute(function () { _load(); });
    });

    var _getDistribute = function (callback) {
        if (layout.config.app_protocol === "auto") {
            layout.config.app_protocol = window.location.protocol;
        }
        o2.xDesktop.getServiceAddress(layout.config, function (service, center) {
            layout.serviceAddressList = service;
            layout.centerServer = center;
            layout.desktop.serviceAddressList = service;
            layout.desktop.centerServer = center;
            _loadProgressBar();
            if (callback) callback();
        }.bind(this));
    };

    var _load = function () {
        var _loadApp = function (json) {
            //用户已经登录
            layout.user = json.data;
            //layout.session = {};
            layout.session.user = json.data;
            layout.session.token = json.data.token;
            layout.desktop.session = layout.session;
            (function (layout) {
                var _loadResource = function (callback) {
                    var isLoadedA = false;
                    var isLoadedB = false;
                    //var isLoadedC = false;

                    var modules = [
                        "o2.xDesktop.Dialog",
                        "o2.xDesktop.UserData",
                        "o2.xDesktop.Access",
                        "o2.widget.UUID",
                        "o2.xDesktop.Menu",
                        "o2.xDesktop.Authentication",
                        // "o2.xDesktop.shortcut",
                        "o2.widget.PinYin",
                        "o2.xDesktop.Access"
                        // "o2.xDesktop.MessageMobile"
                    ];
                    //o2.xDesktop.requireApp("Common", "", null, false);
                    var _check = function () { if (isLoadedA && isLoadedB) if (callback) callback(); };

                    o2.load(["/o2_lib/mootools/plugin/mBox.min.js"], function () { _loadProgressBar(); isLoadedA = true; _check(); });
                    o2.require("o2.widget.Common", function () {
                        _loadProgressBar();
                        o2.require(modules, {
                            "onSuccess": function () {
                                o2.requireApp("Common", "", function () { _loadProgressBar(); isLoadedB = true; _check(); })
                            },
                            "onEvery": function () {
                                _loadProgressBar();
                            }
                        });
                    });
                };

                var _loadContent = function () {
                    _loadResource(function () {
                        _loadProgressBar(true);
                        while (layout.readys && layout.readys.length) {
                            layout.readys.shift().apply(window);
                        }

                    });
                };

                _loadContent();
            })(layout);
        };
        //先判断用户是否登录
        o2.Actions.get("x_organization_assemble_authentication").getAuthentication(function (json) {
            //已经登录
            _loadProgressBar();
            _loadApp(json);
        }.bind(this), function (json) {
            _loadProgressBar();
            //允许匿名访问
            if (layout.anonymous) {
                _loadProgressBar(true);
                _loadApp({
                    user: "anonymous",
                    session: {
                        user: {
                            name: "anonymous",
                            roleList: []
                        }
                    }
                });
            } else {
                //用户未经登录
                //打开登录页面
                var _loadResource = function (callback) {
                    var isLoadedA = false;
                    var isLoadedB = false;
                    //var isLoadedC = false;

                    //var lp = o2.session.path+"/lp/"+o2.language+".js";
                    var modules = [
                        "o2.xDesktop.Dialog",
                        "o2.xDesktop.UserData",
                        "o2.xDesktop.Access",
                        "o2.widget.UUID",
                        "o2.xDesktop.Menu",
                        //"o2.xDesktop.shortcut",
                        "o2.widget.PinYin",
                        "o2.xDesktop.Access",
                        //"o2.xDesktop.MessageMobile"
                    ];
                    //o2.xDesktop.requireApp("Common", "", null, false);
                    var _check = function () { if (isLoadedA && isLoadedB) if (callback) callback(); };

                    o2.load(["/o2_lib/mootools/plugin/mBox.min.js"], function () { _loadProgressBar(); isLoadedA = true; _check(); });
                    o2.require("o2.widget.Common", function () {
                        _loadProgressBar();
                        o2.require(modules, {
                            "onSuccess": function () {
                                o2.requireApp("Common", "", function () { isLoadedB = true; _check(); })
                            },
                            "onEvery": function () {
                                _loadProgressBar();
                            }
                        });
                    });
                };
                _loadResource(function () {
                    _loadProgressBar(true);
                    layout.openLogin();
                });
            }
        });

        layout.openLogin = function () {
            o2.require("o2.widget.Common", null, false);
            o2.require("o2.xDesktop.Authentication", function () {
                layout.authentication = new o2.xDesktop.Authentication({
                    "style": "flat",
                    "onLogin": _load.bind(layout)
                });
                layout.authentication.loadLogin(document.body);
                var loadingNode = $("browser_loading");
                if (loadingNode) loadingNode.fade("out");
            });
        };
    };
});