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

source

mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/** @class associateddocument 视图选择组件。
 * @o2cn 视图选择
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var sourcetext = this.form.get("fieldid"); //获取组件
 * //方法2
 * var sourcetext = this.target; //在组件本身的脚本中获取
 * @extends mwf.xapplication.process.xform.button
 * @o2category formcomponents
 * @o2range {process|cms}
 * @hideconstructor
 */
mwf.xapplication.process.xform.associateddocument = mwf.appassociateddocument =  new class({
	implements: [events],
	extends: mwf.app$module,
    options: {
        /**
         * 视图参数(options)已经准备好,还未加载视图时执行。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
         * @event mwf.xapplication.process.xform.associateddocument#beforeloadview
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 异步加载视图后执行。
         * @event mwf.xapplication.process.xform.associateddocument#loadview
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 选中视图中的一条记录后执行。可以通过this.event获取该次选择的记录。
         * @event mwf.xapplication.process.xform.associateddocument#select
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 取消选中视图中的一条记录后执行。可以通过this.event获取该次取消选择的记录。
         * @event mwf.xapplication.process.xform.associateddocument#unselect
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 点击确定后执行的事件。可以通过this.event获取选择的记录列表。
         * @event mwf.xapplication.process.xform.associateddocument#selectresult
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 选择完成后,并且整理了关联文档数据后事件。可以通过this.event获取记录列表。
         * @event mwf.xapplication.process.xform.associateddocument#afterselectresult
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 删除关联文档前执行的事件。可以通过this.event获取删除的记录。
         * @event mwf.xapplication.process.xform.associateddocument#deletedocument
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        // /**
        //  * 打开关联文档前执行的事件。
        //  * @event mwf.xapplication.process.xform.associateddocument#opendocument
        //  * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
        //  */
        "moduleevents": ["load", "queryload", "postload", "beforeloadview", "loadview", "select", "unselect", "selectresult", "afterselectresult", "deletedocument","opendocument"]
    },
	_loaduserinterface: function(){
        this.node.set({
            "id": this.json.id,
            "mwftype": this.json.type
        });
        this.documentlist = [];
        var button = this.node.getelement("button");
        if( this.isreadonly() ){
            if( button )button.hide();
        }else{
            if (!button) button = new element("button");
            this.button = button;
            this.button.set({
                "text": this.json.buttontext,
                "styles": this.json.buttonstyles
            });
            this.button.addevent("click", function(){
                this.selecteddata = null;
                this.selectview(function(data){
                    // if(data.length === 0){
                    //     this.form.notice(mwf.xapplication.process.xform.lp.selectdocnote, "info");
                    //     return;
                    // }
                    var d = data.map(function (d) {
                        return {
                            "type": d.type === "process" ? "processplatform" : "cms",
                            "site": this.json.site || this.json.id,
                            "view": d.view,
                            "bundle": d.bundle
                        }
                    }.bind(this));
                    this.selectdocument(d);
                }.bind(this));
            }.bind(this));
        }
        if(this.json.recoverystyles){
            this.node.setstyles(this.json.recoverystyles);
        }
        this.documentlistnode = this.node.getelement(".mwfadcontent");
        this.documentlistnode.setstyles( this.json.documentlistnodestyles || {} );
        this.loadassociateddocument();
	},
    selectdocument: function(data){
        this.cancelallassociated( function () {
            if( data && data.length ){
                o2.actions.load("x_processplatform_assemble_surface").correlationaction.createwithjob(this.form.businessdata.work.job, {
                    targetlist: data
                }, function (json) {
                    this.status = "showresult";
                    if(this.dlg.titletext)this.dlg.titletext.set("text", mwf.xapplication.process.xform.lp.associatedresult);
                    var oknode = this.dlg.button.getfirst();
                    if(oknode){
                        oknode.hide();
                        var cancelbutton = oknode.getnext();
                        if(cancelbutton)cancelbutton.set("value", o2.lp.widget.close);
                    }
                    if( (json.data.failurelist && json.data.failurelist.length) || (json.data.successlist && json.data.successlist.length)  ){
                        this.showcreateresult(json.data.failurelist, json.data.successlist);
                    }
                    this.loadassociateddocument(function () {
                        this.fireevent("afterselectresult", [this.documentlist]);
                    }.bind(this));
                }.bind(this));
            }else{
                this.status = "showresult";
                this.loadassociateddocument(function () {
                    this.fireevent("afterselectresult", [this.documentlist]);
                }.bind(this));
                if( this.dlg )this.dlg.close();
            }
        }.bind(this));
    },
    cancelallassociated: function( callback ){
	    var _self = this;
	    if( this.documentlist.length ){
            var ids = [];
            if( this.json.reserve === false ){
                ids = this.documentlist.map(function (doc) {
                    return doc.id;
                });
            }else{
                var viewids = (this.json.queryview || []).map(function (view) {
                   return view.id;
                });
                var docs = this.documentlist.filter(function (doc) {
                    return viewids.contains( doc.view );
                });
                ids = docs.map(function (doc) {
                    return doc.id;
                });
            }
            o2.actions.load("x_processplatform_assemble_surface").correlationaction.deletewithjob(this.getbundle(), {
                idlist: ids
            },function (json) {
                //this.documentlist = [];
                if(callback)callback();
            }.bind(this));
        }else{
	        if(callback)callback();
        }
    },
    loadassociateddocument: function( callback ){
        this.documentlistnode.empty();
	    o2.actions.load("x_processplatform_assemble_surface").correlationaction.listwithjobwithsite(this.form.businessdata.work.job, (this.json.site || this.json.id), function (json) {
            this.documentlist = json.data;
            this.showdocumentlist();
            if(callback)callback();
        }.bind(this));
    },
    showcreateresult: function(failurelist, successlist){
	    this.viewlist.each(function (view) {
            view.showassociateddocumentresult(failurelist, successlist);
        })
    },
    showdocumentlist: function(){
        this.documentlist.each(function(d){
            if(d.targetcreatorperson)d.targetcreatorpersoncn = d.targetcreatorperson.split("@")[0];
        })
        this.documentlistnode.empty();
	    switch (this.json.mode) {
            case "text":
                this.loaddocumentlisttext();  break;
            case "script":
                this.loaddocumentlistscript();  break;
            case "default":
            default:
                this.loaddocumentlistdefault();  break;
        }
    },
    loaddocumentlistdefault: function(){
        this.documentlist.each(function (d) {
            var itemnode = new element("div", {
                styles:  this.form.css.associateddocumentitem
            }).inject( this.documentlistnode );
            var iconnode = new element("div", {
                styles:  this.form.css[ d.targettype === "processplatform" ? "associateddocumentworkicon" : "associateddocumentcmsicon" ]
            }).inject( itemnode );
            var deletenode;
            if( !this.isreadonly() ){
                deletenode = new element("div", {
                    styles:  this.form.css.associateddocumentdelete
                }).inject( itemnode );
                deletenode.hide();
            }
            var textnode = new element("div", {
                styles:  this.form.css.associateddocumenttext,
                text: d.targettitle
            }).inject( itemnode );
            this._loaddocument(d, itemnode, deletenode)
        }.bind(this))
    },
    loaddocumentlisttext: function(){
        var lp = mwf.xapplication.process.xform.lp;
        this.documentlist.each(function (d) {
            var html = this.json.textstyle;
            if (this.json.textstylescript && this.json.textstylescript.code) {
                this.form.macro.environment.line = d;
                html = this.form.macro.exec(this.json.textstylescript.code, this);
            }
            html = html.replace(/\{targettitle\}/g, o2.txt(d.targettitle));
            html = html.replace(/\{targetstarttime\}/g, (d.targettype === "processplatform") ? d.targetstarttime : d.targetstarttime);
            html = html.replace(/\{targetcreatorpersoncn\}/g, o2.txt((d.targettype === "processplatform") ? d.targetcreatorpersoncn : d.targetcreatorpersoncn));
            html = html.replace(/\{targettype\}/g, o2.txt((d.targettype === "processplatform") ? lp.work : lp.document));
            html = html.replace(/\{targetcategory\}/g, o2.txt((d.targettype === "processplatform") ? d.targetcategory : d.targetcategory));
            var itemnode = new element("div", {
                styles:  this.form.css.associateddocumentitem,
                html: html
            }).inject(this.documentlistnode);
            var deletenode = itemnode.getelement("[data-o2-action='delete']");
            deletenode.hide();
            this._loaddocument(d, itemnode, deletenode);
        }.bind(this))
    },
    loaddocumentlistscript: function(){
        if (this.json.displayscript && this.json.displayscript.code){
            var code = this.json.displayscript.code;
            this.documentlist.each(function(d){
                var itemnode = new element("div", {
                    styles:  this.form.css.associateddocumentitem,
                }).inject(this.documentlistnode);
                this.form.macro.environment.line = d;
                var r = this.form.macro.exec(code, this);
                var t = o2.typeof(r);
                if (t==="string"){
                    itemnode.set("html", r);
                }else if (t==="element"){
                    r.inject(itemnode);
                }
                var deletenode = itemnode.getelement("[data-o2-action='delete']");
                deletenode.hide();
                this._loaddocument(d, itemnode, deletenode);
            }.bind(this));
        }
    },
    _loaddocument: function(d, itemnode, deletenode){
        itemnode.addevents({
            "mouseover": function () {
                if(deletenode)deletenode.show();
                itemnode.setstyles( this.form.css.associateddocumentitem_over )
            }.bind(this),
            "mouseout": function () {
                if(deletenode)deletenode.hide();
                itemnode.setstyles( this.form.css.associateddocumentitem )
            }.bind(this),
            "click": function (e) {
                this.opendoc(e, d);
            }.bind(this),
        });
        if( deletenode ){
            if( !this.isreadonly() ){
                deletenode.addevents({
                    "click": function (ev) {
                        this.cancelassociated(ev, d, itemnode);
                        ev.stoppropagation();
                    }.bind(this)
                });
            }else{
                deletenode.hide();
            }
        }
        if( this.json.showcard !== false ){
            this.createinfornode( itemnode, d );
        }
    },
    cancelassociated: function(e, d, itemnode){
        var lp = mwf.xapplication.process.xform.lp;
        var _self = this;
        this.form.confirm("warn", e, lp.cancelassociatedtitle, lp.cancelassociated.replace("{title}", o2.txt(d.targettitle)), 370, 120, function () {
            _self.fireevent("deletedocument", [d]);
            o2.actions.load("x_processplatform_assemble_surface").correlationaction.deletewithjob(_self.form.businessdata.work.job, {
                idlist: [d.id]
            },function (json) {
                itemnode.destroy();
                _self.documentlist.erase(d);
                this.close();
                //this.showdocumentlist();
            }.bind(this));
        }, function () {
            this.close();
        }, null, null, this.form.json.confirmstyle);
    },
    createinfornode: function(itemnode, d){
        var lp = mwf.xapplication.process.xform.lp;
        var infornode = new element("div");
        var html = "";
        var linestyle = "clear: both; overflow:hidden";
        var titlestyle = "width:60px; float:left; font-weight: bold";
        var contentstyle = "width:120px; float:left; margin-left:10px";
        if( d.targettype === "processplatform" ){
            html  = "
" lp.documenttype ":
" lp.work "
"; html = "
" lp.processname ":
" d.targetcategory "
"; html = "
" lp.draftperson ":
" d.targetcreatorpersoncn "
"; html = "
" lp.drafttime ":
" d.targetstarttime "
"; }else{ html = "
" lp.documenttype ":
" lp.document "
"; html = "
" lp.categoryname ":
" d.targetcategory "
"; html = "
" lp.publishperson ":
" d.targetcreatorpersoncn "
"; html = "
" lp.publishtime ":
" d.targetstarttime "
"; } infornode.set("html", html); if (!layout.mobile){ this.tooltip = new mbox.tooltip({ content: infornode, setstyles: {content: {padding: 15, lineheight: 20}}, attach: itemnode, transition: 'flyin' }); } }, getbundle: function(){ return this.form.businessdata.work.job; }, selectview: function(callback){ this.status = "select"; var viewdatalist = this.json.queryview; if( !viewdatalist )return; viewdatalist = typeof(viewdatalist) === "array" ? viewdatalist : [viewdatalist]; if (viewdatalist.length){ var selectedjobs = this.documentlist.map(function (d) { return d.targetbundle; }); var disableselectjobs = []; //var disableselectjobs = array.clone(selectedjobs); disableselectjobs.push( this.getbundle() ); debugger; var viewjsonlist = []; this.selectedbundlemap = {}; this.documentlist.each(function (d) { var viewid = d.properties.view; if( !this.selectedbundlemap[viewid] )this.selectedbundlemap[viewid] = []; this.selectedbundlemap[viewid].push( d.targetbundle ); }.bind(this)); viewdatalist.each(function (viewdata) { var filter = null; var filterlist = (this.json.viewfilterscriptlist || []).filter(function (f) { return f.id === viewdata.id; }); if( filterlist.length ){ filter = this.form.macro.exec(filterlist[0].script.code, this); } var viewjson = { "application": viewdata.appname, "viewname": viewdata.name, "viewid": viewdata.id, "istitle": this.json.istitle || "yes", "select": this.json.select || "single", "titlestyles": this.json.titlestyles, "itemstyles": this.json.itemstyles, "isexpand": this.json.isexpand || "no", "showactionbar" : this.json.actionbar === "show", "filter": filter, //"defaultselectedscript" : function (obj) { // return selectedjobs.contains(obj.data.bundle); //}, "selectedablescript" : function (obj) { return !disableselectjobs.contains(obj.data.bundle); } }; viewjsonlist.push( viewjson ); }.bind(this)); this.fireevent("beforeloadview", [viewdatalist]); var options = {}; // var width = options.width || "850"; // var height = options.height || "700"; var width = this.json.dialogwidth || "850"; var height = this.json.dialogheight || "700"; if (layout.mobile){ var size = document.body.getsize(); width = size.x; height = size.y; options.style = "viewmobile"; } width = width.toint(); height = height.toint(); var size = this.form.app.content.getsize(); var x = (size.x-width)/2; var y = (size.y-height)/2; if (x<0) x = 0; if (y<0) y = 0; if (layout.mobile){ x = 20; y = 0; } var _self = this; mwf.require("mwf.xdesktop.dialog", function(){ var dlg = new mwf.xdesktop.dialog({ "title": this.json.title || mwf.xapplication.process.xform.lp.associateddocument, "style": options.style || "view", "top": y, "left": x-20, "fromtop":y, "fromleft": x-20, "width": width, "height": height, "html": "", "masknode": layout.mobile?$(document.body) : this.form.app.content, "container": layout.mobile?$(document.body) : this.form.app.content, "buttonlist": [ { "text": mwf.lp.process.button.ok, "action": function(){ //if (callback) callback(_self.view.selecteditems); var array = []; _self.viewlist.each(function (view) { //var orgindata = [], orginbundles = _self.selectedbundlemap[view.json.id] || []; //orgindata = orginbundles.map(function(bundle){ // return { // bundle: bundle, // type: view.json.type, // view: view.json.id // }; //}.bind(this)); //var data = [], data1 = view.getdata(); //data1.each(function (d) { // if( !orginbundles.contains( d.bundle ) ){ // d.type = view.json.type; // d.view = view.json.id; // data.push( d ); // } //}.bind(this)); //array = array.concat(orgindata, data); var data = view.getdata().map(function (d) { d.type = view.json.type; d.view = view.json.id; return d; }.bind(this)); array = array.concat(data); }.bind(this)); _self.fireevent("selectresult", [array]); if (callback) callback(array, this); //this.close(); } }, { "text": mwf.lp.process.button.cancel, "action": function(){this.close();} } ], "onqueryclose": function () { this.dlg = null; }.bind(this), "onpostshow": function(){ if(layout.mobile){ dlg.node.setstyle("z-index",200); } mwf.require("mwf.widget.tab", null, false); this.tab = new mwf.widget.tab(dlg.content, {"style": "script"}); this.tab.load(); mwf.xdesktop.requireapp("query.query", "viewer", function(){ // this.view = new mwf.xapplication.query.query.viewer(dlg.content, viewjson, { // "style": "select" // }, this.form.app, this.form.macro ); this.viewlist = []; viewjsonlist.each(function (viewjson, index) { var tabviewnode = element("div", {"styles": {"height": "100%"}}); var pageviewnode = new element("div.pageviewnode").inject(tabviewnode); var viewpage = this.tab.addtab(tabviewnode, viewjson.viewname); var selectedbundles = this.selectedbundlemap[ viewjson.viewid ] || []; //this.viewpage.showtabim(); var viewheight = dlg.content.getsize().y - this.tab.tabnodecontainer.getsize().y; pageviewnode.setstyle("height", viewheight); debugger; var view = new mwf.xapplication.query.query.viewer(pageviewnode, viewjson, { "isloadcontent": this.status !== "showresult", "isloadactionbar": this.status !== "showresult", "isloadsearchbar": this.status !== "showresult", "style": "select", "defaultbundles": this.selectedbundlemap[viewjson.viewid] || [], "onloadview": function(){ this.fireevent("loadview"); }.bind(this), "onselect": function(item){ this.fireevent("select", [item]); }.bind(this), "onunselect": function(item){ selectedbundles.erase( item.data.bundle ); this.fireevent("unselect", [item]); }.bind(this), "onopendocument": function(options, item){ this.openoptions = { "options": options, "item": item }; this.fireevent("openviewdocument", [this.openoptions]); this.openoptions = null; }.bind(this) }, this.form.app, this.form.macro); viewpage.viewer = view; this.viewlist.push(view); viewpage.addevent("postshow", function () { if( viewpage.viewer && viewpage.viewer.node ){ viewpage.viewer.setcontentheight(); } // var viewheight = dlg.content.getsize().y - this.tab.tabnodecontainer.getsize().y; // pageviewnode.setstyle("height", viewheight); }.bind(this)); if( index === 0 )viewpage.showtabim(); }.bind(this)); }.bind(this)); }.bind(this) }); this.dlg = dlg; dlg.show(); if (layout.mobile){ var backaction = dlg.node.getelement(".mwf_dialod_action_back"); var okaction = dlg.node.getelement(".mwf_dialod_action_ok"); if (backaction) backaction.addevent("click", function(e){ dlg.close(); }.bind(this)); if (okaction) okaction.addevent("click", function(e){ //if (callback) callback(this.view.selecteditems); if (callback) callback(this.view.getdata()); dlg.close(); }.bind(this)); } // mwf.xdesktop.requireapp("process.xform", "widget.view", function(){ // this.view = new mwf.xapplication.process.xform.widget.view(dlg.content.getfirst(), viewjson, {"style": "select"}); // }.bind(this)); // mwf.xdesktop.requireapp("query.query", "viewer", function(){ // this.view = new mwf.xapplication.query.query.viewer(dlg.content, viewjson, {"style": "select"}); // }.bind(this)); }.bind(this)); } }, opendoc: function(e, d){ if( d.targettype === "processplatform" ){ o2.actions.load("x_processplatform_assemble_surface").jobaction.findworkworkcompleted(d.targetbundle, function( json ){ var workcompletedlist = json.data.workcompletedlist || [], worklist = json.data.worklist || []; if( !workcompletedlist.length && !worklist.length ){ this.form.notice(mwf.xapplication.process.xform.lp.docdeleted, "info"); }else{ this.form.macro.environment.form.openjob(d.targetbundle, null, null, function ( app ) { this.fireevent("opendocument", [app]); //options 传入的事件 }.bind(this)); } }.bind(this)); }else{ o2.actions.load("x_cms_assemble_control").documentaction.query_get(d.targetbundle, function(){ this.form.macro.environment.form.opendocument(d.targetbundle); }.bind(this), function(){ this.form.notice(mwf.xapplication.process.xform.lp.docdeleted, "info"); return true; }.bind(this)) } } });
网站地图