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

source

mwf.xdesktop.requireapp("process.xform", "$module", null, false);
//mwf.require("mwf.widget.tree", null, false);
/** @class sidebar 侧边操作条。
 * @o2cn 侧边操作条
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var sidebar = this.form.get("fieldid"); //获取侧边操作条
 * //方法2
 * var sidebar = this.target; //在侧边操作条和操作本身的事件脚本中获取
 * @extends mwf.xapplication.process.xform.$module
 * @o2category formcomponents
 * @o2range {process}
 * @hideconstructor
 */
mwf.xapplication.process.xform.sidebar = mwf.appsidebar =  new class(
    /** @lends mwf.xapplication.process.xform.sidebar# */
{
	extends: mwf.app$module,
        options: {
            /**
             * 组件加载前触发。当前组件的queryload事件还没有在form里注册,通过this.form.get("fieldid")不能获取到当前组件,需要用this.target获取当前组件。
             * @event mwf.xapplication.process.xform.sidebar#queryload
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            /**
             * 组件加载时触发。
             * @event mwf.xapplication.process.xform.sidebar#load
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            /**
             * 组件加载后事件.由于加载过程中有异步处理,这个时候操作条有可能还未生成。
             * @event mwf.xapplication.process.xform.sidebar#postload
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            /**
             * 组件加载后事件。这个时候操作条已生成
             * @event mwf.xapplication.process.xform.sidebar#afterload
             * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
             */
            "moduleevents": ["load", "queryload", "postload", "afterload"]
        },
    _loaduserinterface: function(){
        this.node.setstyles(this.form.css.sidebar);
        this.node.setstyles({
           "min-width":"126px",
           "max-width":"240px",
           "width": "auto"
        });
        // this.node.setstyle("width", this.node.getsize().x "px");
        this.toolbarnode = this.node.getfirst("div");
        this.toolbarnode.empty();
        if (this.form.businessdata.task){
            mwf.require("mwf.widget.toolbar", function(){
                var toolbars = [];
                //this.form.businessdata.task.routenamelist.each(function(route, i){
                //    if (!this.json.defaulttools) this.json.defaulttools = [];
                //    var o= {
                //        "type": "mwftoolbarbutton",
                //        "img": "submit.png",
                //        "title": route,
                //        "action": "processwork:" route,
                //        "text": route,
                //        "id": "action_processwork",
                //        "control": "allowprocessing",
                //        "condition": "",
                //        "read": false
                //    };
                //    toolbars.push(o);
                //}.bind(this));
                ( this.getroutenamelist() || [] ).each(function(route, i){
                    if (!this.json.defaulttools) this.json.defaulttools = [];
                    var o= {
                        "type": "mwftoolbarbutton",
                        "img": "submit.png",
                        "title": route.displayname,
                        "action": "processwork:" route.routename,
                        "text": route.displayname,
                        "id": "action_processwork",
                        "control": "allowprocessing",
                        "condition": "",
                        "read": false
                    };
                    toolbars.push(o);
                }.bind(this));
                this.json.defaulttools = toolbars.concat(this.json.defaulttools);
                //this.json.defaulttools.unshift(o);
                /**
                 * @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);
                //alert(this.readonly)
                if (this.json.hidesystemtools){
                    if (this.json.tools.length){
                        this.setcustomtoolbars(this.json.tools, this.toolbarnode);
                        this.toolbarwidget.load();
                    }else{
                        this.toolbarnode.setstyle("display", "none");
                    }
                }else{
                    if (this.json.defaulttools.length || this.json.tools.length){
                        if (this.json.defaulttools){
                            this.settoolbars(this.json.defaulttools, 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), false);
                        }
                    }else{
                        this.toolbarnode.setstyle("display", "none");
                    }
                }
                if (this.toolbarwidget.children.length){
                    //this.form.app.addevent("resize", this.loadposition.bind(this));
                    this.node.setstyle("display", "none");
                    window.settimeout(this.loadposition.bind(this), 500);
                    var _self = this;
                    this.form.app.content.getfirst().addevent("scroll", function(e){
                        _self.loadposition(this);
                    });
                    this.form.app.addevent("resize", function(e){
                        _self.loadposition(this);
                    });
                }else{
                    this.toolbarnode.setstyle("display", "none");
                }
            }.bind(this));
        }else{
            this.node.setstyle("display", "none");
        }
    },
    loadposition: function(){
        // this.node.setstyle("display", "block");
        // var parent = this.node.getparent();
        // while(parent && (!parent.get("mwftype"))) parent = parent.getparent();
        //
        // var top = this.json.styles.top;
        // this.sidenode = parent || this.form.node;
        //
        // var size = this.form.app.content.getsize();
        // var scroll = this.form.app.content.getscroll();
        // var sidesize = this.sidenode.getsize();
        //
        // var y = (scroll.y size.y/2)-sidesize.y/2;
        // var x = 5;
        //
        // var position = "centerright";
        // var edge = "centerleft";
        // if (!parent){
        //     edge = "centerright";
        //     x = 5;
        // }
        //
        // if (this.json.barposition=="left"){
        //     position = "centerleft";
        //     edge = "centerright";
        //     x = -5;
        //     if (!parent){
        //         edge = "centerleft";
        //         x = 5;
        //     }
        // }
        //
        // this.node.position({
        //     "relativeto": this.sidenode,
        //     "position": position,
        //     "edge": edge,
        //     "offset" : {"y": y, "x": x}
        // });
        // this.json.styles.top = top;
        // if (top) this.node.setstyle("top", top);
        this.node.setstyle("display", "block");
        var parent = this.node.getparent();
        while(parent && (!parent.get("mwftype"))) parent = parent.getparent();
        this.sidenode = parent || this.form.node;
        var size = this.form.app.content.getsize();
        //var scroll = this.form.designer.designnode.getscroll();
        var sidesize = this.sidenode.getsize();
        var sideposition = this.sidenode.getposition(this.sidenode.getoffsetparent());
        var nodesize = this.node.getsize();
        if (sidesize.y>size.y){
            var center = (size.y/2-nodesize.y/2);
            if (center(sideposition.y sidesize.y)){
                var tmp = (sideposition.y sidesize.y)-nodesize.y;
                this.node.setstyle("top", "" tmp "px");
            }else{
                this.node.setstyle("top", "" center "px");
            }
        }else{
            var top = sideposition.y sidesize.y/2-nodesize.y/2;
            if (top>size.y){
                if (sideposition.y nodesize.y>size.y){
                    this.node.setstyle("top", "" sideposition.y "px");
                }else{
                    var tmp = size.y-nodesize.y;
                    this.node.setstyle("top", "" tmp "px");
                }
            }else if(top<=0){
                if(sideposition.y sidesize.y size.x ){
            left = size.x - nodesize.x - 5;
        }else{
            left = sidesize.x sideposition.x 5;
        }
        this.node.setstyle("left", "" left "px");
        this.node.setstyle("position", "absolute");
        this.node.setstyles({"right": "auto", "bottom": "auto"});
        // this.json.styles = this.node.getstyles(["top", "left", "bottom", "right", "position"]);
        //
        // var p = this.sidenode.getposition();
        // var s = this.sidenode.getsize();
        // this.sideposition = {"p": p, "s": s};
    },
    setcustomtoolbars: function(tools, node){
        var path = "../x_component_process_formdesigner/module/actionbar/";
        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": this.form.path "" this.form.options.style "/actionbar/" tool.img,
                        "mwfbuttonimage": path (this.form.options.style||"default")  "/custom/" tool.img,
                        "title": tool.title,
                        "mwfbuttonaction": "runcustomaction",
                        "mwfbuttontext": tool.text
                    }).inject(node);
                    if (tool.actionscript){
                        actionnode.store("script", tool.actionscript);
                    }
                    if (tool.sub){
                        var subnode = node.getlast();
                        this.setcustomtoolbars(tool.sub, subnode);
                    }
                }
            }
        }.bind(this));
    },
    settoolbars: function(tools, node, readonly, nocondition){
        var path = "../x_component_process_formdesigner/module/actionbar/";
        tools.each(function(tool){
            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 = !hideflag;
            }
            if (tool.id == "action_processwork"){
                if (!this.form.businessdata.task){
                    flag = false;
                }
            }
            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": path (this.form.options.style||"default")  "/tools/default/" tool.img,
                    "title": tool.title,
                    "mwfbuttonaction": tool.action,
                    "mwfbuttontext": tool.text
                }).inject(node);
                if (tool.sub){
                    var subnode = node.getlast();
                    this.settoolbars(tool.sub, subnode, readonly, nocondition);
                }
            }
        }.bind(this));
    },
    getroutenamelist: function( routelist ){
        var _self = this;
        var list = [];
        if( !routelist )routelist = this.getroutedatalist();
        routelist.each(function(route, i){
            if( route.hiddenscripttext && this.form && this.form.macro ){
                if( this.form.macro.exec(route.hiddenscripttext, this).tostring() === "true" )return;
            }
            var routename = route.name;
            if( route.displaynamescripttext && this.form && this.form.macro ){
                routename = this.form.macro.exec(route.displaynamescripttext, this);
            }
            list.push({
                "routeid" : route.id,
                "displayname" : routename,
                "routename" : route.name
            })
        }.bind(this));
        return list;
    },
    getroutedatalist : function(){
        if(this.routedatalist)return this.routedatalist;
        if (this.form && this.form.businessdata && this.form.businessdata.task && this.form.businessdata.task.routenamedisable){
            this.routedatalist = [{
                "id": o2.uuid(),
                "asyncsupported": false,
                "soledirect": false,
                "name": "继续流转",
                "alias": "",
                "selectconfiglist": []
            }];
            return this.routedatalist;
        }
        if( this.form && this.form.businessdata && this.form.businessdata.routelist ){
            this.form.businessdata.routelist.sort( function(a, b){
                var aidx = parseint(a.ordernumber || "9999999");
                var bidx = parseint(b.ordernumber || "9999999");
                return aidx - bidx;
            }.bind(this));
            this.form.businessdata.routelist.each( function(d){
                d.selectconfiglist = json.parse(d.selectconfig || "[]");
            }.bind(this));
            this.routedatalist = this.form.businessdata.routelist;
        }
        if( !this.routedatalist && this.form && this.form.businessdata && this.form.businessdata.task && this.form.businessdata.task ){
            o2.actions.get("x_processplatform_assemble_surface").listroute( {"valuelist":this.form.businessdata.task.routelist} , function( json ){
                json.data.sort(function(a, b){
                    var aidx = parseint(a.ordernumber || "9999999");
                    var bidx = parseint(b.ordernumber || "9999999");
                    return aidx - bidx;
                }.bind(this));
                json.data.each( function(d){
                    d.selectconfiglist = json.parse( d.selectconfig || "[]" );
                }.bind(this));
                this.routedatalist = json.data;
            }.bind(this), null, false );
        }
        return this.routedatalist;
    },
    isopinionrequired: function( routename ){
        var routelist = this.getroutedatalist();
        for( var i=0; i
网站地图