mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/** @class relatedlink 相关推荐组件,本组件根据其当前流程实例的相关性分数列式其他流程实例(带权限)。
* @o2cn 相关推荐组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var relatedlink = this.form.get("relatedlink"); //获取组件
* //方法2
* var relatedlink = this.target; //在组件本身的脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @since v7.3
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.relatedlink = mwf.apprelatedlink = new class(
/** @lends mwf.xapplication.process.xform.relatedlink# */
{
implements: [events],
extends: mwf.xapplication.process.xform.$module,
options: {
/**
* 加载数据后事件。
* @event mwf.xapplication.process.xform.relatedlink#postloaddata
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
* @example
* //触发该事件的时候可以获取到链接数据linkdata
* var linkdata = this.target.linkdata;
* //可以修改linkdata达到定制化链接数据的效果
* do something
*/
/**
* 创建每行需要导入的数据后触发,this.event指向当前链接对象。
* @event mwf.xapplication.process.xform.relatedlink#postloadlink
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
* @example
* this.event格式如下:
* {
* node: domelement,
* data: {
* "title", "标题一",
* ...
* }
* }
*/
"moduleevents": ["queryload","postload", "afterload", "postloaddata", "postloadlink"]
},
_loaduserinterface: function(){
this.node.empty();
this.node.setstyle("-webkit-user-select", "text");
switch (this.json.activetype) {
case "click":
this.loadbutton();
break;
case "delay":
break;
case "immediately":
this.loadcontent();
break;
}
},
loadbutton: function(){
this.buttonnode = new element("div.rlbutton", {
"styles": this.json.buttonstyles || {},
"text": this.json.buttontext,
"events":{
click: function () {
this.active();
this.buttonnode.destroy();
this.buttonnode = null;
}.bind(this)
}
}).inject( this.node );
},
/**
* @summary 当相关推荐被设置为延迟激活,通过active方法激活
* @param {function} callback 激活后的回调
* @example
* var relativelink = this.form.get("fieldid");
* relativelink.active(function(){
* //do someting
* })
*/
active: function( callback ){
if( !this.loaded ){
this.loadcontent( callback );
}else{
if(callback)callback();
}
},
loadcontent: function( callback ){
o2.actions.load("x_query_assemble_surface").morelikethisaction.post({
flag: this.getflag(),
category: this.getcategory(),
count: (this.json.count || 6).toint()
}, function(json){
this.linkdata = json.data.morelikethislist;
this.fireevent("postloaddata");
this.loadlinks();
this.loaded = true;
this.fireevent("afterload");
if(callback)callback();
}.bind(this));
},
getflag: function(){
return this.form.businessdata.work.id;
// if (this.form.businessdata.work && !this.form.businessdata.work.completedtime) {
// return this.form.businessdata.work.id;
// } else {
// return this.form.businessdata.workcompleted.id;
// }
},
getcategory: function(){
return "processplatform";
},
loadlinks: function(){
switch (this.json.mode){
case "script":
this.loadlinkbyscript();
break;
case "text":
this.loadlinkdefault();
break;
default:
this.loadlinktable();
}
},
loadlinktable: function(){
var table = new element("table", {
"styles": this.json.tablestyles || this.form.css.relatedlinktable,
"border": "0",
"cellspacing": "0",
"cellpadding": "3px",
"width": "100%"
}).inject(this.node);
var tr = table.insertrow(0); //.setstyles( this.form.css.relatedlinktabletitleline );
var lp = mwf.xapplication.process.xform.lp;
var thstyle = this.json.tabletitlecellstyles || this.form.css.relatedlinktabletitle;
var td = tr.insertcell(0).setstyles(thstyle);
td.set("text", lp.title);
td = tr.insertcell(1).setstyles(thstyle);
td.set("text", lp.creatorperson);
td = tr.insertcell(2).setstyles(thstyle);
td.set("text", lp.creatorunit);
td = tr.insertcell(3).setstyles(thstyle);
td.set("text", lp.createtime);
td = tr.insertcell(4).setstyles(thstyle);
td.set("text", lp.updatetime);
td = tr.insertcell(5).setstyles(thstyle);
td.set("text", lp.score);
var tdstyle = this.json.tablecontentcellstyles || this.form.css.relatedlinktablecell;
this.linkdata.each(function (log, idx) {
var tr = table.insertrow(table.rows.length);
tr.setstyles( this.json.tablecontentlinestyles || this.form.css.relatedlinktableline );
tr.addevents({
"mouseover": function () {
tr.setstyles( this.json.tablecontentlinestyles_over || this.form.css.relatedlinktableline_over )
}.bind(this),
"mouseout": function () {
tr.setstyles( this.json.tablecontentlinestyles || this.form.css.relatedlinktableline )
}.bind(this)
})
var td = tr.insertcell(0).setstyles( tdstyle );
td.set("text", log.title);
td.setstyles( this.json.tablecontentcellstyles_title || this.form.css.relatedlinktablecell_title );
td = tr.insertcell(1).setstyles(tdstyle);
td.set("text", log.creatorperson);
td = tr.insertcell(2).setstyles(tdstyle);
td.set("text", log.creatorunit);
td = tr.insertcell(3).setstyles(tdstyle);
td.set("text", log.createtime);
td = tr.insertcell(4).setstyles(tdstyle);
td.set("text", log.updatetime);
td = tr.insertcell(5).setstyles(tdstyle);
td.set("text", log.score);
this.setopenevent(tr, log);
this.fireevent("postloadlink", [{
node: tr,
data: log
}]);
}.bind(this))
},
loadlinkbyscript: function(){
if (this.json.displayscript && this.json.displayscript.code){
var code = this.json.displayscript.code;
this.linkdata.each(function(log){
this.form.macro.environment.link = log;
var r = this.form.macro.exec(code, this);
var t = o2.typeof(r);
if (t==="string"){
this.node.appendhtml(r);
}else if (t==="element"){
this.node.appendchild(r);
}
var node = this.node.getlast();
this.setopenevent(node, log);
this.fireevent("postloadlink", [{
node: node,
data: log
}]);
}.bind(this));
}
},
loadlinkdefault: function(){
var text = this.json.textstyle;
var readpersons = [];
this.lineclass = "relatedlinknode";
this.linkdata.each(function(log, i){
var div = new element("div", {styles: this.form.css[this.lineclass]}).inject(this.node);
var rightdiv = new element("div", {styles: this.form.css.relatedlinktextnode}).inject(div);
var html = text.replace(/{flag}/g, log.flag)
.replace(/{createdate}/g, log.createtime.substring(0.10))
.replace(/{createtime}/g, log.createtime)
.replace(/{updatedate}/g, log.updatetime.substring(0.10))
.replace(/{updatetime}/g, log.updatetime)
.replace(/{creatorunit}/g, o2.name.cn(log.creatorunit))
.replace(/{creatorperson}/g, o2.name.cn(log.creatorperson))
.replace(/{title}/g, log.title || "");
rightdiv.appendhtml(html);
if (this.lineclass === "relatedlinknode"){
this.lineclass = "relatedlinknode_even";
}else{
this.lineclass = "relatedlinknode";
}
this.setopenevent(div, log);
this.fireevent("postloadlink", [{
node: div,
data: log
}]);
}.bind(this));
},
setopenevent: function(node, data){
node.setstyle("cursor", "pointer");
if (data.category==="cms"){
node.addevent("click", function(ev){
this.opencmsdocument( data, false);
ev.stoppropagation();
}.bind(this));
}else{
node.addevent("click", function(ev){
this.openwork(data);
ev.stoppropagation();
}.bind(this));
}
},
openwork: function(data){
var appid = "process.work" data.flag;
// if (layout.desktop.apps[appid]){
// if (!layout.desktop.apps[appid].window){
// layout.desktop.apps[appid] = null;
// layout.openapplication(null, layout.desktop.apps[appid].options.name, layout.desktop.apps[appid].options, layout.desktop.apps[appid].options.app, false, this, false);
// }else{
// layout.desktop.apps[appid].setcurrent();
// }
// }else {
var op = {
"jobid": data.flag,
"appid": appid
};
return layout.desktop.openapplication(this.event, "process.work", op);
// }
},
opencmsdocument : function( data, isedited ){
var appid = "cms.document" data.flag;
// if (layout.desktop.apps[appid]){
// if (!layout.desktop.apps[appid].window){
// layout.desktop.apps[appid] = null;
// layout.openapplication(null, layout.desktop.apps[appid].options.name, layout.desktop.apps[appid].options, layout.desktop.apps[appid].options.app, false, this, false);
// }else{
// layout.desktop.apps[appid].setcurrent();
// }
// }else {
var options = {
"documentid": data.flag,
"appid": appid,
"readonly" : !isedited
};
layout.desktop.openapplication(null, "cms.document", options);
// }
}
});
source