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

source

mwf.xdesktop.requireapp("process.xform", "$module", null, false);
//mwf.require("mwf.widget.tree", null, false);
//mwf.require("mwf.widget.toolbar", null, false);
/** @class actionbar 操作条组件。
 * @o2cn 操作条
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var actionbar = this.form.get("name"); //获取操作条
 * //方法2
 * var actionbar = this.target; //在操作条和操作本身的事件脚本中获取
 * @extends mwf.xapplication.process.xform.$module
 * @o2category formcomponents
 * @o2range {process|cms}
 * @hideconstructor
 */
mwf.xapplication.process.xform.actionbar = mwf.appactionbar =  new class(
    /** @lends mwf.xapplication.process.xform.actionbar# */
    {
        extends: mwf.app$module,
        options: {
            /**
             * 组件加载前触发。当前组件的queryload事件还没有在form里注册,通过this.form.get("fieldid")不能获取到当前组件,需要用this.target获取当前组件。
             * @event mwf.xapplication.process.xform.actionbar#queryload
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            /**
             * 组件加载时触发。
             * @event mwf.xapplication.process.xform.actionbar#load
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            /**
             * 组件加载后事件.由于加载过程中有异步处理,这个时候操作条有可能还未生成。
             * @event mwf.xapplication.process.xform.actionbar#postload
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            /**
             * 组件加载后事件。这个时候操作条已生成
             * @event mwf.xapplication.process.xform.actionbar#afterload
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            "moduleevents": ["load", "queryload", "postload", "afterload"]
        },
        /**
         * @summary 重新加载操作条。会触发afterload事件
         * @example
         * this.form.get("name").reload(); //显示操作条
         */
        reload : function(){
            this._loaduserinterface();
        },
        _loaduserinterface: function(){
            // if (this.form.json.mode == "mobile"){
            //     this.node.empty();
            // }else if (common.browser.platform.ismobile){
            //     this.node.empty();
            // }else{
            this.toolbarnode = this.node.getfirst("div");
            if(!this.toolbarnode)return;
            this.toolbarnode.empty();
            mwf.require("mwf.widget.toolbar", function(){
                /**
                 * @summary toolbar组件,平台使用该组件生成操作条。
                 * @member {o2.widget.toolbar}
                 * @example
                 *  //可以在脚本中获取该组件
                 * var toolbarwidget = this.form.get("fieldid").toolbarwidget; //获取组件对象
                 */
                this.toolbarwidget = new mwf.widget.toolbar(this.toolbarnode, {
                    "style": this.json.style,
                    "onpostload" : function(){
                        this.fireevent("afterload");
                    }.bind(this)
                }, this);
                if (this.json.actionstyles) this.toolbarwidget.css = this.json.actionstyles;
                //alert(this.readonly)
                if( this.json.multitools ){ //自定义操作和系统操作混合的情况,用 system : true 来区分系统和自定义
                    var addreadactionflag = !this.json.hidesystemtools && !this.json.hidereadedaction; //是否需要增加已阅
                    var jsonstr = json.stringify(this.json.multitools);
                    jsonstr = o2.bindjson(jsonstr, {"lp": mwf.xapplication.process.xform.lp.form});
                    this.json.multitools = json.parse(jsonstr);
                    this.json.multitools.each( function (tool) {
                        if( tool.system ){
                            if( !this.json.hidesystemtools ){
                                if( tool.id === "action_readed" )addreadactionflag = false;
                                this.settoolbars([tool], this.toolbarnode, this.readonly);
                            }
                        }else{
                            this.setcustomtoolbars([tool], this.toolbarnode);
                        }
                    }.bind(this));
                    if( addreadactionflag ){
                        var addactions = [
                            {
                                "type": "mwftoolbarbutton",
                                "img": "read.png",
                                "title": mwf.xapplication.process.xform.lp.setreaded,
                                "action": "readedwork",
                                "text": mwf.xapplication.process.xform.lp.readed,
                                "id": "action_readed",
                                "control": "allowreadprocessing",
                                "condition": "",
                                "read": true
                            }
                        ];
                        this.settoolbars(addactions, this.toolbarnode, this.readonly);
                    }
                    this.toolbarwidget.load();
                }else{
                    if (this.json.hidesystemtools){
                        this.setcustomtoolbars(this.json.tools, this.toolbarnode);
                        this.toolbarwidget.load();
                    }else{
                        if (this.json.defaulttools){
                            var addactions = [
                                {
                                    "type": "mwftoolbarbutton",
                                    "img": "read.png",
                                    "title": mwf.xapplication.process.xform.lp.setreaded,
                                    "action": "readedwork",
                                    "text": mwf.xapplication.process.xform.lp.readed,
                                    "id": "action_readed",
                                    "control": "allowreadprocessing",
                                    "condition": "",
                                    "read": true
                                }
                            ];
                            //this.form.businessdata.control.allowreflow =
                            //this.json.defaulttools.push(o);
                            this.settoolbars(this.json.defaulttools, this.toolbarnode, this.readonly);
                            if( !this.json.hidereadedaction ){
                                this.settoolbars(addactions, this.toolbarnode, this.readonly);
                            }
                            this.setcustomtoolbars(this.json.tools, this.toolbarnode);
                            this.toolbarwidget.load();
                        }else{
                            mwf.getjson(this.form.path "toolbars.json", function(json){
                                this.settoolbars(json, this.toolbarnode, this.readonly, true);
                                this.setcustomtoolbars(this.json.tools, this.toolbarnode);
                                this.toolbarwidget.load();
                            }.bind(this), null);
                        }
                    }
                }
                if (this.toolbarwidget.items["action_goback"]){
                    // 异步判断是否有可退回的活动
                    if (this.form.businessdata.task) o2.actions.load('x_processplatform_assemble_surface').workaction.v2listactivitygoback(this.form.businessdata.task.work, function(json){
                        if (json.data.length){
                            this.toolbarwidget.items["action_goback"].show();
                        }
                    }.bind(this));
                }
            }.bind(this));
        },
        setcustomtoolbars: function(tools, node){
            var path = "../x_component_process_formdesigner/module/actionbar/";
            var iconpath = "";
            if( this.json.customiconstyle ){
                iconpath = this.json.customiconstyle "/";
            }
            tools.each(function(tool){
                var flag = true;
                if (this.readonly){
                    flag = tool.readshow;
                }else{
                    flag = tool.editshow;
                }
                if (flag){
                    flag = true;
                    if (tool.control){
                        flag = this.form.businessdata.control[tool.control]
                    }
                    if (tool.condition){
                        var hideflag = this.form.macro.exec(tool.condition, this);
                        flag = !hideflag;
                    }
                    if (flag){
                        var actionnode = new element("div", {
                            "id": tool.id,
                            "mwfnodetype": tool.type,
                            "mwfbuttonimage": path "" this.form.options.style "/custom/" iconpath tool.img,
                            "title": tool.title,
                            "mwfbuttonaction": "runcustomaction",
                            "mwfbuttontext": tool.text
                        }).inject(node);
                        if( this.json.customiconoverstyle ){
                            actionnode.set("mwfbuttonimageover" , path "" this.form.options.style  "/custom/" this.json.customiconoverstyle  "/"  tool.img );
                        }
                        if( tool.properties ){
                            actionnode.set(tool.properties);
                        }
                        if (tool.actionscript){
                            actionnode.store("script", tool.actionscript);
                        }
                        if (tool.sub){
                            var subnode = node.getlast();
                            this.setcustomtoolbars(tool.sub, subnode);
                        }
                    }
                }
            }.bind(this));
        },
        getimagepath: function(img, iscustom){
            var path = "../x_component_process_formdesigner/module/actionbar/";
            if( iscustom ){
                var iconpath = this.json.customiconstyle ? (this.json.customiconstyle  "/") : "";
                return path "" this.form.options.style "/custom/" iconpath img;
            }else{
                return path (this.options.style||"default")  "/tools/"  (this.json.style || "default")  "/" img;
            }
        },
        getimageoverpath: function(img, iscustom){
            var path = "../x_component_process_formdesigner/module/actionbar/";
            if( iscustom && this.json.customiconoverstyle ){
                return path "" this.form.options.style  "/custom/" this.json.customiconoverstyle  "/"  img
            }else{
                return path "" (this.options.style||"default") "/tools/" ( this.json.iconoverstyle || "default" ) "/" img;
            }
        },
        settoolbaritem: function(tool, node, readonly, nocondition){
            var path = "../x_component_process_formdesigner/module/actionbar/";
            var flag = true;
            if (tool.control){
                flag = this.form.businessdata.control[tool.control]
            }
            if (!nocondition) if (tool.condition){
                var hideflag = this.form.macro.exec(tool.condition, this);
                flag = flag && (!hideflag);
            }
            if (tool.id == "action_downloadall" || tool.id == "action_print"){
                if (!this.form.businessdata.work.starttime){
                    flag = false;
                }
            }
            if (tool.id == "action_delete"){
                if (!this.form.businessdata.work || !this.form.businessdata.work.id){
                    flag = false;
                }
            }
            if (tool.id == "action_rollback") tool.read = true;
            if (readonly) if (!tool.read) flag = false;
            if (flag){
                var actionnode = new element("div", {
                    "id": tool.id,
                    "mwfnodetype": tool.type,
                    //"mwfbuttonimage": this.form.path "" this.form.options.style "/actionbar/" tool.img,
                    "mwfbuttonimage": this.getimagepath(tool.img, tool.customimg),
                    "title": tool.title,
                    "mwfbuttonaction": tool.action,
                    "mwfbuttontext": tool.text,
                    "mwfhide": (tool.id === "action_goback") ? 'true' : ''
                }).inject(node);
                if( this.json.iconoverstyle ){
                    actionnode.set("mwfbuttonimageover" , this.getimageoverpath(tool.img, tool.customimg) );
                }
                if( tool.properties ){
                    actionnode.set(tool.properties);
                }
                if (tool.sub){
                    var subnode = node.getlast();
                    this.settoolbars(tool.sub, subnode, readonly, nocondition);
                }
            }
        },
        /**
         * @summary 根据操作id获取操作,该方法在操作条的afterload事件中有效,操作的操作脚本有效。
         *  @param {string} id - 必选,操作id.
         *  @return {o2.widget.toolbarbutton} 操作
         *  @example
         *  var actionbar = this.form.get("name"); //获取操作条
         *  var item = actionbar.getitem( "action_delete" ); //获取删除操作
         *  item.node.hide(); //隐藏删除操作的节点
         *  item.node.click(); //触发操作的click事件
         */
        getitem : function( id ){
            if( this.toolbarwidget && id ){
                return this.toolbarwidget.items[id]
            }
        },
        /**
         * @summary 获取所有操作,该方法在操作条的afterload事件中有效,操作的操作脚本有效。
         *  @return {array} 操作数组
         *  @example
         *  var actionbar = this.form.get("name"); //获取操作条
         *  var itemlist = actionbar.getallitem(); //获取操作数组
         *  itemlist[1].node.hide(); //隐藏第一个操作
         */
        getallitem : function(){
            return this.toolbarwidget ? this.toolbarwidget.childrenbutton : [];
        },
        settoolbars: function(tools, node, readonly, nocondition){
            tools.each(function(tool){
                this.settoolbaritem(tool, node, readonly, nocondition);
            }.bind(this));
        },
        runcustomaction: function(bt){
            var script = bt.node.retrieve("script");
            this.form.macro.exec(script, this);
        },
        savework: function(){
            debugger;
            this.form.savework();
        },
        closework: function(){
            this.form.closework();
        },
        flowwork: function(){
            this.form.flowwork();
        },
        processwork: function(){
            this.form.processwork();
        },
        resetwork: function(){
            this.form.resetwork();
        },
        addtask: function(){
            this.form.addtask();
        },
        retractwork: function(e, ev){
            this.form.retractwork(e, ev);
        },
        reroutework: function(e, ev){
            this.form.reroutework(e, ev);
        },
        deletework: function(){
            this.form.deletework();
        },
        printwork: function(){
            this.form.printwork();
        },
        readedwork: function(b,e){
            this.form.readedwork(e);
        },
        addsplit: function(e){
            this.form.addsplit(e);
        },
        rollback: function(e){
            this.form.rollback(e);
        },
        downloadall: function(e){
            this.form.downloadall(e);
        },
        monitor: function(e){
            this.form.monitor(e);
        },
        presswork: function(e){
            this.form.presswork(e);
        },
        pausetask: function(e){
            var p = this.form.pausetask(e);
            if (p){
                p.then(function(){
                    e.settext(mwf.xapplication.process.xform.lp.resume);
                    e.options.action = "resumetask";
                    var img = e.picnode.getelement("img");
                    var src = img.get("src");
                    src = src.substr(0, src.lastindexof("/"));
                    src = src "/resume.png";
                    img.set("src", src);
                }.bind(this), function(){});
            }
        },
        resumetask: function(e){
            var p = this.form.resumetask(e);
            if (p){
                p.then(function(){
                    e.settext( mwf.xapplication.process.xform.lp.pause);
                    e.options.action = "pausetask";
                    var img = e.picnode.getelement("img");
                    var src = img.get("src");
                    src = src.substr(0, src.lastindexof("/"));
                    src = src "/pause.png";
                    img.set("src", src);
                }.bind(this), function(){});
            }
        },
        goback: function(e){
            this.form.goback(e);
        },
        terminate: function(e, ev){
            this.form.terminatework(e, ev);
        }
    });
网站地图