o2oa api: x-游戏厅捕鱼达人

source

mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/** @class application 门户中嵌入的系统component对象或网页iframe(模块部署中配置的网页url)。
 * @o2cn 嵌入的系统应用
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var application = this.form.get("fieldid"); //获取组件
 * //方法2
 * var application = this.target; //在组件本身的脚本中获取
 * @extends mwf.xapplication.process.xform.$module
 * @o2category formcomponents
 * @o2range {portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.application = mwf.appapplication =  new class(
    /** @lends mwf.xapplication.process.xform.application# */
    {
    extends: mwf.app$module,
    options: {
        /**
         * component对象初始化后,加载之前触发,this.event可获取component对象。
         * @event mwf.xapplication.process.xform.application#queryloadapplication
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        "moduleevents": ["load", "queryload", "postload", "queryloadapplication"]
    },
    _loaduserinterface: function(){
        /**
         * @ignore
         * @member parentline
         * @memberof mwf.xapplication.process.xform.application#
         */
        /**
         * @ignore
         * @member getsource
         * @memberof mwf.xapplication.process.xform.application#
         */
        this.node.empty();
        if( this.json.activetype !== "delay" ){
            if( !o2.api ){
                mwf.require("mwf.framework", function () {
                    this.loadapplication();
                }.bind(this));
            }else{
                this.loadapplication();
            }
        }
    },
    /**
     * @summary 当组件被设置为延迟激活,通过active方法激活
     * @param {function} callback 激活后的回调方法(不保证组件加载完成),另外已经激活过该方法还会被执行。
     * @example
     * var app = this.form.get("fieldid");
     * app.active(function(){
     *     //do someting
     * })
     */
    active: function(callback){
        if (!this.loaded) {
            this.reload(callback);
        } else {
            if (callback) callback();
        }
    },
    /**
     * @summary 重新加载嵌入对象
     * @param {function} callback 重载后的回调
     * @example
     * this.form.get("fieldid").reload()
     */
    reload: function(callback){
        this.clean();
        this.loadapplication( callback );
    },
    /**
     * @summary 清除当前嵌入的对象
     * @example
     * this.form.get("fieldid").clean()
     */
    clean: function(){
        if(this.component){
            try{
                this.component.close();
                if(this.node)this.node.empty();
            }catch (e) {
                console.log(e);
                if(this.node)this.node.empty();
            }
            this.component = null;
        }
        if( this.iframe ){
            this.iframe.destroy();
            if(this.node)this.node.empty();
            this.iframe = null;
        }
    },
    loadapplication: function ( callback ) {
        this.clean();
        if(this.node){
            this.node.empty();
            this.node.setstyles({
                "position": "relative"
            });
            if( !this.json.styles || (!this.json.styles["background"] && !this.json.styles["background-color"] )){
                this.node.setstyle("background-color", "#eee");
            }
        }
        var status = this.getcomponentstatus() || {};
        var options = this.getcomponentoptions() || {};
        this.getcomponentpath(function (componentpath) {
            if( componentpath && componentpath.indexof("@url:") === 0 ){
                this.loadiframe( componentpath.substring(5, componentpath.length ), callback );
            }else{
                this.loadcomponent( componentpath, status, options, callback );
            }
        }.bind(this))
    },
    /**
     * @summary 加载iframe
     * @param {string} src iframe的src,如'https://www.baidu.com/'
     * @example
     * this.form.get("fieldid").clean(); //清除当前嵌入的对象
     * this.form.get("fieldid").loadiframe('https://www.baidu.com/'); //加载iframe
     */
    loadiframe: function( src, callback ){
        var attr = {
            "src": src,
            "width": "100%",
            "height": "100%",
            "frameborder": "0px",
            "scrolling": "auto",
            "seamless": "seamless"
        };
        /**
         * @summary 当模块部署中配置的是@url:开头的链接时,嵌入的iframe.
         * @member {object}
         * @example
         * var iframe = this.form.get("fieldid").iframe; //获取iframe
         * iframe.src; //获取iframe的地址
         */
        this.iframe = new element("iframe", attr).inject( this.node );
        this.loaded = true;
        if(callback)callback();
    },
    /**
     * @summary 加载系统组件
     * @param {string} path 组件的路径,如'calendar'
     * @param {object} [status] 组件的状态
     * @param {object} [options] 组件的选项
     * @example
     * this.form.get("fieldid").clean(); //清除当前嵌入的对象
     * this.form.get("fieldid").loadcomponent('calendar'); //加载日程安排
     * @example
     * this.form.get("fieldid").clean(); //清除当前嵌入的对象
     * this.form.get("fieldid").loadcomponent('cms.module', {
     *  "columnid":"25434995-45d2-4c9a-a344-55ad0deff071"
     *  }); //加载id为25434995-45d2-4c9a-a344-55ad0deff071的内容管理栏目
     */
    loadcomponent: function ( path, status, options, callback ) {
        var clazz = mwf.xapplication;
        if( o2.typeof(path) !== "string" )return;
        path.split(".").each(function (a) {
            clazz[a] = clazz[a] || {};
            clazz = clazz[a];
        });
        clazz.options = clazz.options || {};
        var _load = function () {
            if( clazz.main ){
                var opt = options || {};
                var stt = status || {};
                opt.embededparent = this.node;
                /**
                 * @summary 嵌入的component对象.
                 * @member {object}
                 * @example
                 * var app = this.form.get("fieldid").component; //获取component对象
                 * app.recordstatus(); //获取应用的当前状态
                 * app.refresh();      //刷新应用
                 * app.dialog(option); //弹出一个对话框(详见mwf.widget.dialog)
                 * app.notice(content, type, target, where, offset); //显示一个通知消息
                 * app.confirm(type, e, title, text, width, height, ok, cancel); //显示一个确认框
                 * app.alert(type, e, title, text, width, height); //弹出一个信息框
                 * app.addevent(type, fun); //为应用绑定一个事件
                 */
                this.component = new clazz.main(this.form.app.desktop, opt);
                this.component.status = stt;
                this.fireevent("queryloadapplication", this.component);
                this.component.load();
                this.component.seteventtarget(this.form.app);
                var _self = this;
                this.component.refresh = function () {
                    if( layout.inbrowser ){
                        window.location.reload();
                    }else{
                        _self.form.app.refresh();
                    }
                };
            }else{
                if( mwf.xapplication.process && mwf.xapplication.process.xform && mwf.xapplication.process.xform.lp ){
                    this.form.app.notice(mwf.xapplication.process.xform.lp.applicationnotfound ":" path, "error");
                }else{
                    this.form.app.notice(this.form.app.lp.applicationnotfound ":" path, "error");
                }
            }
            this.loaded = true;
            if(callback)callback();
        }.bind(this);
        try{
            mwf.xdesktop.requireapp(path, "lp." o2.language, null, false);
            mwf.xdesktop.requireapp(path, "main", null, false);
            if (clazz.loading && clazz.loading.then){
                clazz.loading.then(function(){
                    _load();
                });
            }else{
                _load();
            }
        }catch (e) {
            this.form.app.notice( e.message, "error" );
        }
    },
    /**
     * @summary 获取获取表单设计配置的component对象的路径
     * @param {function} callback 获取路径后的回调方法,参数为路径
     * @example
     * this.form.get("fieldid").getcomponentpath(function(path){
     *     //path为路径
     * })
     */
    getcomponentpath: function(callback){
        var path;
        if (this.json.componenttype==="script"){
            if (this.json.componentscript && this.json.componentscript.code){
                path = this.form.macro.exec(this.json.componentscript.code, this);
            }
        }else{
            if (this.json.componentselected && this.json.componentselected!=="none"){
                path = this.json.componentselected;
            }else{
                path = "";
            }
        }
        promise.resolve(path).then(function (p) {
            callback(p || "");
        })
    },
    /**
     * @summary 获取表单设计配置的component对象的参数
     * @return 设置的参数
     * @example
     * var param = this.form.get("fieldid").getcomponentoptions()
     */
    getcomponentoptions : function(){
        var params = "";
        if( this.json.optionstype === "map" ){
            params = this.json.optionsmaplist;
        }else if( this.json.optionstype === "script" ){
            var code = (this.json.optionsscript) ? this.json.optionsscript.code : "";
            if (code){
                params = this.form.macro.exec(code, this);
            }
        }
        return params;
    },
    /**
     * @summary 获取表单设计配置的component对象的状态
     * @return 设置的状态
     * @example
     * var param = this.form.get("fieldid").getcomponentstatus()
     */
    getcomponentstatus: function(){
        var params = "";
        if( this.json.statustype === "map" ){
            params = this.json.statusmaplist;
        }else if( this.json.statustype === "script" ){
            var code = (this.json.statusscript) ? this.json.statusscript.code : "";
            if (code){
                params = this.form.macro.exec(code, this);
            }
        }
        return params;
    }
});
网站地图