mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/** @class log 流程记录组件。
* @o2cn 流程记录组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var log = this.form.get("name"); //获取组件
* //方法2
* var log = this.target; //在组件事件脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process}
* @hideconstructor
*/
mwf.xapplication.process.xform.log = mwf.applog = new class(
/** @lends mwf.xapplication.process.xform.log# */
{
extends: mwf.app$module,
options: {
/**
* 加载数据后事件。
* @event mwf.xapplication.process.xform.log#postloaddata
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
* @example
* //触发该事件的时候可以获取到流程数据worklog
* var worklog = this.target.worklog;
* //可以修改worklog达到定制化流程记录的效果
* do something
*/
/**
* 加载每行流程信息以后触发,可以通过this.event获得下列信息:
*
* {
* "data" : {}, //当前行流程信息
* "node" : logtasknode, //当前节点
* "log" : object, //指向流程记录
* "type" : "task" //"task"表示待办,"taskcompleted"表示已办
* }
* @event mwf.xapplication.process.xform.log#postloadline
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["load", "queryload", "postload", "postloaddata", "postloadline"]
},
_loaduserinterface: function(){
this.node.empty();
this.node.setstyle("-webkit-user-select", "text");
if (this.form.businessdata){
if (this.json.logtype!=="record"){
if (this.form.businessdata.workloglist){
if( this.form.businessdata.work.completedtime && !this.form.ischeckworklogendactivity ){
this.checkworklogendactivity();
}
this.worklog = array.clone(this.form.businessdata.workloglist);
this.fireevent("postloaddata");
this.loadworklog();
}
}else{
if (this.form.businessdata.recordlist){
this.worklog = array.clone(this.form.businessdata.recordlist);
this.fireevent("postloaddata");
this.loadrecordlog();
}
}
}
},
loadrecordlog: function(){
if( !this.json.category || this.json.category === "none" ){
if (this.json.mode==="table"){
this.loadrecordlogtable();
}else if (this.json.mode==="text"){
this.loadrecordlogtext();
}else if (this.json.mode==="media"){
this.loadrecordlogmedia();
}else{
this.loadrecordlogdefault();
}
}else{
// this.loadcategorylist("_loadrecordcategorylist", "_loadrecordcategorylist");
this.loadrecordcategorylist();
if( !this.categorylist.length )return;
this.expandcount = 0;
if( this.json.expand && this.json.expand === "enable" ){
this.expandcount = parseint( this.json.expandcount );
}
this.table = new element("table", this.json.tableproperties).inject( this.node );
this.categorylist.each( function( key, idx ){
var list = this.categoryjson[key];
if( list && list.length ){
var tr = new element("tr").inject( this.table );
if( this.expandcount && (idx 1) > this.expandcount ){
tr.setstyle("display","none");
}
var text = key;
if( this.json.category === "unit" ){
text = key.split("@")[0];
}
new element("td", {
styles : this.json.titletdstyles,
text : text
}).inject( tr );
var td = new element("td", {
styles : this.json.contenttdstyles
}).inject( tr );
var div = new element("div",{
styles : this.json.contentdivstyles || {}
}).inject( td );
if( this.json.sorttypeincategory === "completedtimeasc" || this.json.sorttypeincategory === "completedtimedesc" ){
list.sort(function(a, b){
if( this.json.sorttypeincategory === "completedtimeasc" ) {
return date.parse(a.recordtime) - date.parse(b.recordtime);
}else if( this.json.sorttypeincategory === "completedtimedesc" ) {
return date.parse(b.recordtime) - date.parse(a.recordtime);
}
}.bind(this));
// sortedlist = [];
// list.each( function( log ){
// if (log.taskcompletedlist.length) {
// log.taskcompletedlist.each(function (t) {
// var copylog = object.clone( log );
// copylog.readlist = [];
// copylog.readcompletedlist = [];
// copylog.tasklist = [];
// copylog.taskcompletedlist = [t];
// sortedlist.push( copylog );
// }.bind(this));
// }
// }.bind(this));
// sortedlist.sort(function(a, b){
// if( this.json.sorttypeincategory === "completedtimeasc" ) {
// return date.parse(a.taskcompletedlist[0].completedtime) - date.parse(b.taskcompletedlist[0].completedtime);
// }else if( this.json.sorttypeincategory === "completedtimedesc" ) {
// return date.parse(b.taskcompletedlist[0].completedtime) - date.parse(a.taskcompletedlist[0].completedtime);
// }
// }.bind(this));
// list.each( function( log ) {
// if (log.tasklist.length) {
// log.tasklist.each(function (t) {
// var copylog = object.clone(log);
// copylog.readlist = [];
// copylog.readcompletedlist = [];
// copylog.taskcompletedlist = [];
// copylog.tasklist = [t];
// sortedlist.push(copylog);
// }.bind(this));
// }
// })
}
if (this.json.mode==="table"){
this.loadrecordlogtable( list, div );
}else if (this.json.mode==="text"){
this.loadrecordlogtext( list, div );
}else if (this.json.mode==="media"){
this.loadrecordlogmedia( list, div );
}else{
this.loadrecordlogdefault( list, div );
}
this._loadtablestyles();
}
}.bind(this));
if( this.categorylist.length > this.expandcount ){
this.loadexpandcollapsenode();
}
}
},
_loadrecordcategorylist : function( category ){
this.categorylist = [];
this.categoryjson = {};
this.unitindex = (this.json.unitlevel || "1").toint() - 1;
if( category === "fromopiniongroup" ){
this.worklog.sort( function( a, b ){
if( a.properties.fromopiniongroup && b.properties.fromopiniongroup ) {
var array1 = a.properties.fromopiniongroup.split("#");
var array2 = b.properties.fromopiniongroup.split("#");
for (var i = 0; i < array1.length; i ) {
var value1 = array1[i];
var value2 = array2[i];
if (this.isnumber(value1) && this.isnumber(value2)) {
if (parsefloat(value1) !== parsefloat(value2)) {
return parsefloat(value1) - parsefloat(value2);
}else{
if( this.json.sorttypeincategory === "none" ){
return 0;
}else{
return date.parse(a.recordtime) - date.parse(b.recordtime);
}
}
} else if (!this.isnumber(value1) && !this.isnumber(value2)) {
if( this.json.sorttypeincategory === "none" ){
return 0;
}else{
return date.parse(a.recordtime) - date.parse(b.recordtime);
}
} else {
return this.isnumber(value1) ? -1 : 1;
}
}
return date.parse(a.recordtime) - date.parse(b.recordtime);
}else if( a.properties.fromopiniongroup || b.properties.fromopiniongroup ){
return a.properties.fromopiniongroup ? -1 : 1;
}else{
if( this.json.sorttypeincategory === "none" ){
return 0;
}else{
return date.parse(a.recordtime) - date.parse(b.recordtime);
}
}
}.bind(this))
}
this.worklog.each( function(log, idx){
var key;
if( this.json.category === "activitygroup" ) {
if (log.properties.fromopiniongroup) {
var arr = log.properties.fromopiniongroup.split("#");
key = arr[arr.length - 1];
} else {
key = log.fromactivityname;
}
}else if( this.json.category === "unitlevelname" ){
if( log.properties.unitlevelname ){
var namearray = log.properties.unitlevelname.split("/");
if( namearray.length > this.unitindex ){
key = namearray[this.unitindex];
}else{
key = namearray.getlast();
}
}
}else{
key = log[category];
}
if( key && this.checkrecordshow(log)){
if( this.categorylist.indexof( key ) === -1 ){
this.categorylist.push( key );
}
if( !this.categoryjson[key] )this.categoryjson[key] = [];
this.categoryjson[key].push( log );
}
}.bind(this))
},
loadrecordlogtable: function( list, container ){
var tasktable = new element("table", {
"styles": this.form.css.logtabletask,
"border": "0",
"cellspacing": "0",
"cellpadding": "3px",
"width": "100%"
}).inject(container || this.node);
var tr = tasktable.insertrow(0).setstyles(this.form.css.logtabletasktitleline);
var td = tr.insertcell(0).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.person);
td = tr.insertcell(1).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.activity);
td = tr.insertcell(2).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.department);
td = tr.insertcell(3).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.starttime);
td = tr.insertcell(4).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.completedtime);
td = tr.insertcell(5).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.route);
td = tr.insertcell(6).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.opinion);
td = tr.insertcell(7).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.arrivedactivitys);
td = tr.insertcell(8).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.arrivedusers);
if( list ){
list.each(function(log, idx){
this.loadrecordlogline_table(log, idx, tasktable );
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkrecordshow(log)) this.loadrecordlogline_table(log, idx, tasktable );
}.bind(this));
}
},
checkrecordshow: function(log){
var flag = true;
if (this.json.filterscript && this.json.filterscript.code){
this.form.macro.environment.log = log;
this.form.macro.environment.list = null;
flag = this.form.macro.exec(this.json.filterscript.code, this);
}else{
var isexactmatch = function (property) {
return property && o2.typeof(property)==="array" && property.length && property[0] === "yes";
};
if (this.json.filteractivity && this.json.filteractivity.length){
filteractivitys = this.json.filteractivity;
if(isexactmatch(this.json.filteractivityexactmatch)){ //精确匹配
flag = filteractivitys.split(/[;|,|\n]/gm).contains(log.fromactivityname); //用;,和空格分隔成数组
}else{
flag = (filteractivitys.indexof(log.fromactivityname)!==-1);
}
}
if (this.json.filteractivityalias && this.json.filteractivityalias.length){
filteractivityalias = this.json.filteractivityalias;
//flag = ((log.fromactivityalias) && filteractivityalias.indexof(log.fromactivityalias)!==-1);
if(log.fromactivityalias){
if(isexactmatch(this.json.filteractivityaliasexactmatch)){ //精确匹配
flag = filteractivityalias.split(/[;|,|\n]/gm).contains(log.fromactivityalias); //用;,和空格分隔成数组
}else{
flag = (filteractivityalias.indexof(log.fromactivityalias)!==-1);
}
}else{
flag = false;
}
}
if (this.json.filterperson && this.json.filterperson.length){
if(isexactmatch(this.json.filterpersonexactmatch)) { //精确匹配
flag = false;
var filterpersonslist = this.json.filterperson.split(/[;|,|\n]/gm);
var matcharr = log.person.split("@").concat([log.person]);
for(var i=0; i < filterpersonslist.length; i ){
if( matcharr.contains(filterpersonslist[i]) ){
flag = true;
break;
}
}
}else{
flag = (this.json.filterperson.indexof(log.person)!==-1);
if (!flag) flag = (this.json.filterperson.indexof(o2.name.cn(log.person))!==-1);
}
}
//if (this.json.filterroute && this.json.filterroute.length){
// filterroutes = this.json.filterroute;
// flag = (filterroutes.indexof(log.properties.routename)!==-1);
//}
if (this.json.filterroute && this.json.filterroute.length){
filterroutes = this.json.filterroute;
if(isexactmatch(this.json.filterrouteexactmatch)){ //精确匹配
flag = filterroutes.split(/[;|,|\n]/gm).contains(log.properties.routename); //用;,和空格分隔成数组
}else{
flag = (filterroutes.indexof(log.properties.routename)!==-1);
}
}
}
return flag;
},
loadrecordlogline_table: function(log, idx, tasktable){
var style = ((idx % 2)===0) ? "logtabletaskline" : "logtabletaskline_even";
if (log.type==="currenttask"){
if (this.json.istask) this.loadrecordtaskline_table(log, tasktable, true, style);
}else{
this.loadrecordtaskline_table(log, tasktable, false, style);
}
},
loadrecordtaskline_table: function(task, table, istask, style){
// var style = "logtabletaskline";
// "logtabletaskline_even"
css = (istask) ? object.merge(this.form.css["logtabletaskline_task"], this.form.css[style] ): this.form.css[style];
if (istask) style = "logtabletaskline_task";
var tr = table.insertrow(table.rows.length);
var td = tr.insertcell(0).setstyles(css);
var person = (task.person) ? task.person.substring(0, task.person.indexof("@")) : "";
if (task.properties.empowerfromidentity){
var ep = o2.name.cn(task.properties.empowerfromidentity);
person = person " " mwf.xapplication.process.xform.lp.replace " " ep;
}
if (task.type === "empower") task.properties.starttime = task.recordtime;
td.set("text", person);
td = tr.insertcell(1).setstyles(css);
td.set("text", task.fromactivityname || "");
td = tr.insertcell(2).setstyles(css);
td.set("text", (task.unit) ? task.unit.substring(0, task.unit.indexof("@")) : "");
td = tr.insertcell(3).setstyles(css);
td.set("text", task.properties.starttime || "");
td = tr.insertcell(4).setstyles(css);
td.set("text", task.recordtime || "");
var router, opinion, arrivedactivitys, arrivedusers;
arrivedactivitys = task.properties.nextmanuallist.map(function(o){
return o.activityname;
}).join(",");
arrivedusers = (task.properties.nextmanualtaskidentitylist && task.properties.nextmanualtaskidentitylist.length) ? o2.name.cns(task.properties.nextmanualtaskidentitylist).join(",") : "";
switch (task.type) {
case "empower":
router = mwf.xapplication.process.xform.lp.empower;
var empowerto = (task.properties.nextmanualtaskidentitylist && task.properties.nextmanualtaskidentitylist.length) ? o2.name.cns(task.properties.nextmanualtaskidentitylist).join(",") : "";
opinion = mwf.xapplication.process.xform.lp.empowerto empowerto;
task.properties.starttime = task.recordtime;
break;
case "retract":
router = mwf.xapplication.process.xform.lp.retract;
opinion = mwf.xapplication.process.xform.lp.retract;
break;
case "reroute":
router = task.properties.routename || mwf.xapplication.process.xform.lp.reroute;
opinion = task.properties.opinion || mwf.xapplication.process.xform.lp.rerouteto ": " arrivedactivitys;
break;
case "rollback":
router = task.properties.routename || mwf.xapplication.process.xform.lp.rollback;
opinion = task.properties.opinion || mwf.xapplication.process.xform.lp.rollbackto ": " task.arrivedactivityname;
break;
case "reset":
// var resetuser = task.properties.nextmanualtaskidentitylist.erase(task.identity);
// resetusertext = o2.name.cns(resetuser).join(",");
router = task.properties.routename || mwf.xapplication.process.xform.lp.reset;
opinion = task.properties.opinion || ""
break;
case "appendtask":
case "back":
case "addsplit":
case "urge":
case "expire":
case "read":
default:
router = task.properties.routename || "";
opinion = task.properties.opinion || "";
}
td = tr.insertcell(5).setstyles(css);
td.set("text",router);
var opiniontd = tr.insertcell(6).setstyles(css);
opiniontd.set("html", "" o2.txt(opinion) "");
td = tr.insertcell(7).setstyles(css);
td.set("text",o2.txt(arrivedactivitys));
td = tr.insertcell(8).setstyles(css);
td.set("html", arrivedusers);
var atts = [];
if (task.properties.mediaopinion){
var mediaids = task.properties.mediaopinion.split(",");
if (this.form.businessdata.attachmentlist){
this.form.businessdata.attachmentlist.each(function(att){
if (att.site==="$mediaopinion"){
if (mediaids.indexof(att.id)!==-1) atts.push(att);
}
}.bind(this));
}
if (atts.length) this.loadmediaopinion(atts, opiniontd.getfirst(), "table");
}
this.fireevent("postloadline",[{
"data" : task,
"node" : tr,
"atts" : atts,
"log" : this,
"type" : istask ? "task" : "taskcompleted"
}]);
},
loadrecordlogdefault: function(list, container){
var logactivitynode = new element("div", {"styles": this.form.css.logactivitynode_record}).inject(container || this.node);
if( list ){
list.each(function(log, idx){
this.loadrecordlogline_default(log, idx, logactivitynode);
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkrecordshow(log)) this.loadrecordlogline_default(log, idx, logactivitynode);
}.bind(this));
}
},
loadrecordlogline_default: function(log, idx, container){
//var style = ((idx % 2)===0) ? "logtabletaskline_even" : "logtabletaskline";
var style = ((idx % 2)===0) ? "logactivitychildrecordnode" : "logactivitychildrecordnode_even";
var childnode = new element("div", {"styles": this.form.css[style]}).inject((container || this.node));
if (log.type==="currenttask"){
if (this.json.istask) this.loadrecordtaskline_default(log, childnode, true);
}else{
this.loadrecordtaskline_default(log, childnode, false);
}
},
loadrecordtaskline_default: function(task, node, istask, margin, iszebra, nodestyle, noiconnode){
var style = "logtasknode";
var textstyle = "logtaskfloattextnode";
if (nodestyle){
style = "logtasktextnode";
textstyle = "logtasktextnode";
}
var logtasknode = new element("div", {"styles": this.form.css[style]}).inject(node);
var iconnode;
if( !noiconnode ){
iconnode = new element("div", {"styles": this.form.css.logtaskiconnode_record}).inject(logtasknode);
}
var textnode = new element("div", {"styles": this.form.css[textstyle]}).inject(logtasknode);
if (iszebra){
logtasknode.setstyles(this.form.css[this.lineclass]);
if (this.lineclass === "logtasknode"){
this.lineclass = "logtasknode_even";
}else{
this.lineclass = "logtasknode";
}
}
var left = 0;
if( iconnode ){
if (margin) iconnode.setstyle("margin-left", margin);
left = iconnode.getstyle("margin-left").toint();
left = left 28;
}
if( !nodestyle ){
textnode.setstyle("margin-left",left "px");
}
var html;
var company = "";
var atts = [];
if (!istask){
company = (task.unitlist) ? task.unitlist[task.unitlist.length-1] : "";
html = this.json.textstyle;
var lp = mwf.xapplication.process.xform.lp;
if (task.type=="empower") html = "{person}({department})" lp.in "【{activity}】" lp.activity "," lp.empowerto "{empowerto}。({time})";
var nexttasktext = (task.properties.nextmanualtaskidentitylist && task.properties.nextmanualtaskidentitylist.length) ? o2.name.cns(task.properties.nextmanualtaskidentitylist).join(",") : "";
if (this.json.textstylescript && this.json.textstylescript.code){
this.form.macro.environment.log = task;
this.form.macro.environment.list = null;
html = this.form.macro.exec(this.json.textstylescript.code, this);
}
// var person = (task.person) ? task.person.substring(0, task.person.indexof("@")) : "";
// if( task.type !== "empowertask" && task.empowerfromidentity){
// person = person " " lp.replace " " o2.name.cn(task.empowerfromidentity||"");
// }
var person = (task.person) ? task.person.substring(0, task.person.indexof("@")) : "";
if (task.properties.empowerfromidentity){
var ep = o2.name.cn(task.properties.empowerfromidentity);
person = person " " mwf.xapplication.process.xform.lp.replace " " ep;
}
var router, opinion, arrivedactivitys, arrivedusers;
arrivedactivitys = task.properties.nextmanuallist.map(function(o){
return o.activityname;
}).join(",");
arrivedusers = (task.properties.nextmanualtaskidentitylist && task.properties.nextmanualtaskidentitylist.length) ? o2.name.cns(task.properties.nextmanualtaskidentitylist).join(",") : "";
switch (task.type) {
case "empower":
router = mwf.xapplication.process.xform.lp.empower;
var empowerto = (task.properties.nextmanualtaskidentitylist && task.properties.nextmanualtaskidentitylist.length) ? o2.name.cns(task.properties.nextmanualtaskidentitylist).join(",") : "";
opinion = mwf.xapplication.process.xform.lp.empowerto empowerto;
task.properties.starttime = task.recordtime;
break;
case "retract":
router = mwf.xapplication.process.xform.lp.retract;
opinion = mwf.xapplication.process.xform.lp.retract;
break;
case "reroute":
router = task.properties.routename || mwf.xapplication.process.xform.lp.reroute;
opinion = task.properties.opinion || mwf.xapplication.process.xform.lp.rerouteto ": " arrivedactivitys;
break;
case "rollback":
router = task.properties.routename || mwf.xapplication.process.xform.lp.rollback;
opinion = task.properties.opinion || mwf.xapplication.process.xform.lp.rollbackto ": " task.arrivedactivityname;
break;
case "reset":
// var resetuser = task.properties.nextmanualtaskidentitylist.erase(task.identity);
// resetusertext = o2.name.cns(resetuser).join(",");
// router = mwf.xapplication.process.xform.lp.resetto ":" resetusertext;
router = task.properties.routename || mwf.xapplication.process.xform.lp.reset;
opinion = task.properties.opinion || ""
break;
case "appendtask":
case "back":
case "addsplit":
case "urge":
case "expire":
case "read":
case "task":
case "empowertask":
default:
router = task.properties.routename || "";
opinion = task.properties.opinion || "";
}
html = html.replace(/\{person\}/g, person );
html = html.replace(/\{department\}/g, (task.unit) ? task.unit.substring(0, task.unit.indexof("@")) : "");
html = html.replace(/\{route\}/g, o2.txt(router));
html = html.replace(/\{time\}/g, task.recordtime);
html = html.replace(/\{date\}/g, new date().parse(task.recordtime).format("%y-%m-%d"));
html = html.replace(/\{opinion\}/g, o2.txt(opinion));
html = html.replace(/\{company\}/g, company.substring(0, company.indexof("@")));
html = html.replace(/\{starttime\}/g, task.properties.starttime);
html = html.replace(/\{startdate\}/g, new date().parse(task.properties.starttime).format("%y-%m-%d"));
html = html.replace(/\{activity\}/g, o2.txt(task.fromactivityname));
html = html.replace(/\{arrivedactivity\}/g, o2.txt(arrivedactivitys));
html = html.replace(/\{img\}/g, "");
html = html.replace(/\{empowerto\}/g, arrivedusers);
html = html.replace(/\{next\}/g, nexttasktext);
//var html = mwf.xapplication.process.xform.lp.nextuser task.person "(" task.department ")" ", "
// mwf.xapplication.process.xform.lp.selectroute ": [" task.routename "], "
// mwf.xapplication.process.xform.lp.submitat ": " task.completedtime ", "
// mwf.xapplication.process.xform.lp.idea ": " (task.opinion || "") "";
textnode.set("html", html);
var imgnode = textnode.getelement(".mwf_log_img");
if (task.properties.mediaopinion){
var mediaids = task.properties.mediaopinion.split(",");
// var atts = [];
if (this.form.businessdata.attachmentlist){
this.form.businessdata.attachmentlist.each(function(att){
if (att.site==="$mediaopinion"){
if (mediaids.indexof(att.id)!==-1) atts.push(att);
}
}.bind(this));
}
if (atts.length){
if (imgnode){
this.loadmediaopinion_show(atts, task, imgnode, true);
// atts.each(function(att){
// this.loadmediaopinion_image_show(att, task, imgnode);
// }.bind(this));
}else{
this.loadmediaopinion(atts, textnode, "default");
}
}
}
}else{
var person = (task.person) ? task.person.substring(0, task.person.indexof("@")) : "";
if (task.properties.empowerfromidentity){
var ep = o2.name.cn(task.properties.empowerfromidentity);
person = person " " mwf.xapplication.process.xform.lp.replace " " ep;
}
html = person "(" task.unit.substring(0, task.unit.indexof("@")) "), 【" task.fromactivityname "】" mwf.xapplication.process.xform.lp.processing ", "
mwf.xapplication.process.xform.lp.cometime ": " task.properties.starttime;
textnode.set("html", html);
if(iconnode)iconnode.setstyle("background-image", "");
}
this.fireevent("postloadline",[{
"data" : task,
"atts" : atts,
"node" : logtasknode,
"log" : this,
"type" : istask ? "task" : "taskcompleted"
}]);
},
loadrecordlogtext: function(list, container){
this.lineclass = "logtasknode";
if( list ){
list.each(function(log, idx){
this.loadrecordlogline_text(log, idx, container);
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkrecordshow(log)) this.loadrecordlogline_text(log, idx, container);
}.bind(this));
}
},
loadrecordlogline_text: function(log, idx, container){
if (log.type==="currenttask"){
if (this.json.istask) this.loadrecordtaskline_text(log, container || this.node, true);
}else{
this.loadrecordtaskline_text(log, container || this.node, false);
}
},
loadrecordtaskline_text: function(task, node, istask){
this.loadrecordtaskline_default(task, node, istask, "0px", false, true, true);
},
loadrecordlogmedia: function(list, container){
if( list ){
list.each(function(log, idx){
this.loadrecordlogline_media(log, idx, container);
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkrecordshow(log)) this.loadrecordlogline_media(log, idx, container);
}.bind(this));
}
},
loadrecordlogline_media: function(log, idx, container){
this.loadrecordtaskline_media(log, container);
},
loadrecordtaskline_media: function(task, container){
if (task.properties.mediaopinion){
var mediaids = task.properties.mediaopinion.split(",");
var atts = [];
if (this.form.businessdata.attachmentlist){
this.form.businessdata.attachmentlist.each(function(att){
if (att.site==="$mediaopinion"){
if (mediaids.indexof(att.id)!==-1) atts.push(att);
}
}.bind(this));
}
var iscompleted = !!task.recordtime;
task.completedtime = task.recordtime;
var node = new element("div").inject( container || this.node );
if (atts.length) this.loadmediaopinion_show(atts, task, node);
this.fireevent("postloadline",[{
"data" : task,
"atts" : atts,
"node" : node,
"log" : this,
"type" : iscompleted ? "taskcompleted" : "task"
}]);
}
},
//worklog -----------------------------------------------------------------------------
checkworklogendactivity: function(){
//判断流程已经结束,但是taskcompletedlist为空,则补上系统自动流转
var workloglist = this.form.businessdata.workloglist;
for( var i=workloglist.length-1; i>-1; i-- ){
var log = workloglist[i];
if( log.arrivedactivitytype === "end" ){
if( !log.taskcompletedlist )log.taskcompletedlist = [];
if( log.taskcompletedlist.length === 0 ){
log.taskcompletedlist.push({
"id": log.id,
"starttime": log.fromtime,
"completedtime": log.arrivedtime,
"person": mwf.xapplication.process.xform.lp.systemsubmit "@system@p",
"identity": mwf.xapplication.process.xform.lp.systemsubmit "@system@i",
"unit": "",
"activityname": log.arrivedactivityname,
"activitytoken": "",
"routename": log.routename,
"opinion": "",
"processingtype": "autoflow",
"properties": {
"prevtaskidentitylist": [],
"nexttaskidentitylist": [],
"prevtasklist": [],
"prevtask": {},
"opinion": ""
}
})
}
this.form.ischeckworklogendactivity = true;
return;
}
}
},
loadworklog: function(){
if( !this.json.category || this.json.category === "none" ){
if (this.json.mode==="table"){
this.loadworklogtable();
}else if (this.json.mode==="text"){
this.loadworklogtext();
}else if (this.json.mode==="media"){
this.loadworklogmedia();
}else{
this.loadworklogdefault();
}
}else{
this.loadcategorylist();
if( !this.categorylist.length )return;
this.expandcount = 0;
if( this.json.expand && this.json.expand === "enable" ){
this.expandcount = parseint( this.json.expandcount || 0 );
}
this.table = new element("table", this.json.tableproperties).inject( this.node );
this.categorylist.each( function( key, idx ){
var list = this.categoryjson[key];
if( list && list.length ){
var tr = new element("tr").inject( this.table );
if( this.expandcount && (idx 1) > this.expandcount ){
tr.setstyle("display","none");
}
var text = key;
if( this.json.category === "unit" ){
text = key.split("@")[0];
}
new element("td", {
styles : this.json.titletdstyles,
text : text
}).inject( tr );
var td = new element("td", {
styles : this.json.contenttdstyles
}).inject( tr );
var div = new element("div",{
styles : this.json.contentdivstyles || {}
}).inject( td );
var sortedlist = list;
if( this.json.sorttypeincategory === "completedtimeasc" || this.json.sorttypeincategory === "completedtimedesc" ){
sortedlist = [];
list.each( function( log ){
if (log.taskcompletedlist.length) {
log.taskcompletedlist.each(function (t) {
var copylog = object.clone( log );
copylog.readlist = [];
copylog.readcompletedlist = [];
copylog.tasklist = [];
copylog.taskcompletedlist = [t];
sortedlist.push( copylog );
}.bind(this));
}
}.bind(this));
sortedlist.sort(function(a, b){
if( this.json.sorttypeincategory === "completedtimeasc" ) {
return date.parse(a.taskcompletedlist[0].completedtime) - date.parse(b.taskcompletedlist[0].completedtime);
}else if( this.json.sorttypeincategory === "completedtimedesc" ) {
return date.parse(b.taskcompletedlist[0].completedtime) - date.parse(a.taskcompletedlist[0].completedtime);
}
}.bind(this));
list.each( function( log ) {
if (log.tasklist.length) {
log.tasklist.each(function (t) {
var copylog = object.clone(log);
copylog.readlist = [];
copylog.readcompletedlist = [];
copylog.taskcompletedlist = [];
copylog.tasklist = [t];
sortedlist.push(copylog);
}.bind(this));
}
})
}
if (this.json.mode==="table"){
this.loadworklogtable( sortedlist, div );
}else if (this.json.mode==="text"){
this.loadworklogtext( sortedlist, div );
}else if (this.json.mode==="media"){
this.loadworklogmedia( sortedlist, div );
}else{
this.loadworklogdefault( sortedlist, div );
}
this._loadtablestyles();
}
}.bind(this));
if( this.categorylist.length > this.expandcount ){
this.loadexpandcollapsenode();
}
}
},
// loadcategorylist : function(m1, m2){
// var category;
// if( this.json.category === "activity" ){
// category = "fromactivityname";
// this[m1 || "_loadcategorylist"]( category );
// }else if( this.json.category === "unit" ){
// category = "unit";
// this[m2 || "_loadcategorylitbysubdata"]( category );
// }else if( this.json.category === "activitygroup" ){
// category = "fromopiniongroup";
// this[m1 || "_loadcategorylist"]( category );
// }else{
// category = this.json.category;
// this[m1 || "_loadcategorylist"]( category );
// }
// },
loadcategorylist : function(){
var category;
switch(this.json.category) {
case "activity":
category = "fromactivityname";
this._loadcategorylist(category);
break;
case "unit":
category = "unit";
this._loadcategorylitbysubdata(category);
break;
case "activitygroup":
category = "fromopiniongroup";
this._loadcategorylist(category);
break;
default:
category = this.json.category;
this._loadcategorylist(category);
break;
}
},
loadrecordcategorylist: function(){
var category;
switch(this.json.category) {
case "activity":
category = "fromactivityname";
this._loadrecordcategorylist(category);
break;
case "unit":
category = "unit";
this._loadrecordcategorylist(category);
break;
case "activitygroup":
category = "fromopiniongroup";
this._loadrecordcategorylist(category);
break;
case "unitlevelname":
category = "unitlevelname";
this._loadrecordcategorylist(category);
break;
default:
category = this.json.category;
this._loadrecordcategorylist(category);
break;
}
},
// isnumber : function( d ){
// return parsefloat(d).tostring() !== "nan"
// },
_loadcategorylist : function( category ){
this.categorylist = [];
this.categoryjson = {};
if( category === "fromopiniongroup" ){
this.worklog.sort( function( a, b ){
if( a.fromopiniongroup && b.fromopiniongroup ) {
var array1 = a.fromopiniongroup.split("#");
var array2 = b.fromopiniongroup.split("#");
for (var i = 0; i < array1.length; i ) {
var value1 = array1[i];
var value2 = array2[i];
if (this.isnumber(value1) && this.isnumber(value2)) {
if (parsefloat(value1) !== parsefloat(value2)) {
return parsefloat(value1) - parsefloat(value2);
}else{
if( this.json.sorttypeincategory === "none" ){
return 0;
}else{
return date.parse(a.fromtime) - date.parse(b.fromtime);
}
}
} else if (!this.isnumber(value1) && !this.isnumber(value2)) {
if( this.json.sorttypeincategory === "none" ){
return 0;
}else{
return date.parse(a.fromtime) - date.parse(b.fromtime);
}
} else {
return this.isnumber(value1) ? -1 : 1;
}
}
return date.parse(a.fromtime) - date.parse(b.fromtime);
}else if( a.fromopiniongroup || b.fromopiniongroup ){
return a.fromopiniongroup ? -1 : 1;
}else{
if( this.json.sorttypeincategory === "none" ){
return 0;
}else{
return date.parse(a.fromtime) - date.parse(b.fromtime);
}
}
}.bind(this))
}
this.worklog.each( function(log, idx){
var key;
if( this.json.category === "activitygroup" ){
if( log.fromopiniongroup ){
var arr = log.fromopiniongroup.split("#");
key = arr[arr.length-1]
}else{
key = log.fromactivityname;
}
}else{
key = log[category];
}
if( key && this.checkshow(log)){
var flag = false;
for( var i=0; i< log.taskcompletedlist.length; i ){
var taskcompleted = log.taskcompletedlist[i];
flag = this.checklistshow(log, taskcompleted);
if( flag )break;
}
if (!flag && this.json.istask){
for( var i=0; i< this.json.istask.length; i ){
var task = log.tasklist[i];
flag = this.checklistshow(log, task);
if( flag )break;
}
}
if(flag){
if( this.categorylist.indexof( key ) === -1 ){
this.categorylist.push( key );
}
if( !this.categoryjson[key] )this.categoryjson[key] = [];
this.categoryjson[key].push( log );
}
}
}.bind(this))
},
_loadcategorylitbysubdata : function( category ){
this.categorylist = [];
this.categoryjson = {};
this.worklog.each( function(log, idx){
var key = log[category];
if( this.checkshow(log) ){
var flag = false;
for( var i=0; i< log.taskcompletedlist.length; i ){
var taskcompleted = log.taskcompletedlist[i];
flag = this.checklistshow(log, taskcompleted);
if( flag )break;
}
if (!flag && this.json.istask){
for( var i=0; i< this.json.istask.length; i ){
var task = log.tasklist[i];
flag = this.checklistshow(log, task);
if( flag )break;
}
}
if(flag){
var log_copy = object.clone(log);
log_copy.taskcompletedlist = [];
log_copy.tasklist = [];
log_copy.readcompletedlist = [];
log_copy.readlist = [];
var sub_categorylist = [];
var sub_categoryjson = {};
for( var i=0; i< log.taskcompletedlist.length; i ){
var d = log.taskcompletedlist[i];
var key = d[category];
if( key ){
if( sub_categorylist.indexof( key ) === -1 ){
sub_categorylist.push( key );
}
if( !sub_categoryjson[key] )sub_categoryjson[key] = object.clone(log_copy);
sub_categoryjson[key].taskcompletedlist.push( d );
}
}
for( var i=0; i< log.tasklist.length; i ){
var d = log.tasklist[i];
var key = d[category];
if( key ){
if( sub_categorylist.indexof( key ) === -1 ){
sub_categorylist.push( key );
}
if( !sub_categoryjson[key] )sub_categoryjson[key] = object.clone(log_copy);
sub_categoryjson[key].tasklist.push( d );
}
}
for( var i=0; i< log.readcompletedlist.length; i ){
var d = log.readcompletedlist[i];
var key = d[category];
if( key ){
if( sub_categorylist.indexof( key ) === -1 ){
sub_categorylist.push( key );
}
if( !sub_categoryjson[key] )sub_categoryjson[key] = object.clone(log_copy);
sub_categoryjson[key].readcompletedlist.push( d );
}
}
for( var i=0; i< log.readlist.length; i ){
var d = log.readlist[i];
var key = d[category];
if( key ){
if( sub_categorylist.indexof( key ) === -1 ){
sub_categorylist.push( key );
}
if( !sub_categoryjson[key] )sub_categoryjson[key] = object.clone(log_copy);
sub_categoryjson[key].readlist.push( d );
}
}
sub_categorylist.each( function(key){
if( this.categorylist.indexof( key ) === -1 ){
this.categorylist.push( key );
}
}.bind(this));
for( var key in sub_categoryjson ){
if( !this.categoryjson[key] )this.categoryjson[key] = [];
this.categoryjson[key].push( sub_categoryjson[key] );
}
}
}
}.bind(this))
},
_loadtableborderstyle: function(){
if (this.json.tablestyles && this.json.tablestyles.border){
this.table.set("cellspacing", "0");
this.table.setstyles({
"border-top": this.json.tablestyles.border,
"border-left": this.json.tablestyles.border
});
var ths = this.table.getelements("th");
if( ths && ths.length ){
ths.setstyles({
"border-bottom": this.json.tablestyles.border,
"border-right": this.json.tablestyles.border
});
}
var tds = this.table.getelements("td");
if( tds && tds.length ) {
tds.setstyles({
"border-bottom": this.json.tablestyles.border,
"border-right": this.json.tablestyles.border
});
}
}
},
_loadtablestyles: function(){
object.each(this.json.tablestyles || {}, function(value, key){
var reg = /^border\w*/ig;
if (!key.test(reg)){
this.table.setstyle(key, value);
}
}.bind(this));
this._loadtableborderstyle();
},
loadexpandcollapsenode : function(){
if( this.json.expand && this.json.expand === "enable" ){
if( this.json.expandhtml ){
this.expandnode = new element("div",{
"html" : this.json.expandhtml
}).inject( this.node, "bottom" );
this.expandnode.addevent("click", function(){
if( !this.json.category || this.json.category === "none" ){
}else{
this.table.getelements("tr").setstyle("display","");
this.expandnode.setstyle("display","none");
this.collapsenode.setstyle("display","");
}
}.bind(this))
}
if( this.json.collapsehtml ){
this.collapsenode = new element("div",{
"html" : this.json.collapsehtml,
"styles" : { "display" : "none" }
}).inject( this.node, "bottom" );
this.collapsenode.addevent("click", function(){
if( !this.json.category || this.json.category === "none" ){
}else{
var trs = this.table.getelements("tr");
for( var i=0; i= this.expandcount ){
trs[i].setstyle("display","none");
}
}
this.expandnode.setstyle("display","");
this.collapsenode.setstyle("display","none");
}
}.bind(this))
}
}
},
loadworklogmedia: function(list, container){
if( list ){
list.each(function(log, idx){
this.loadworklogline_media(log, idx, container);
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkshow(log)) this.loadworklogline_media(log, idx, container);
}.bind(this));
}
},
loadworklogline_media: function(log, idx, container){
if (log.taskcompletedlist.length){
log.taskcompletedlist.each(function(taskcompleted){
if (this.checklistshow(log, taskcompleted)) this.loadtaskline_media(taskcompleted, log, container);
}.bind(this));
}
},
loadtaskline_media: function(task, log, container){
if (task.mediaopinion){
var mediaids = task.mediaopinion.split(",");
var atts = [];
if (this.form.businessdata.attachmentlist){
this.form.businessdata.attachmentlist.each(function(att){
if (att.site==="$mediaopinion"){
if (mediaids.indexof(att.id)!==-1) atts.push(att);
}
}.bind(this));
}
var node = new element("div").inject( container || this.node );
if (atts.length) this.loadmediaopinion_show(atts, task, node);
this.fireevent("postloadline",[{
"data" : task,
"atts" : atts,
"node" : node,
"log" : this,
"type" : !!task.completedtime ? "taskcompleted" : "task"
}]);
}
},
loadmediaopinion_show: function(atts, task, container, noname){
atts.each(function(att){
//if (!att.contenttype) att.contenttype = "image";
if (att.type){
if (att.type.indexof("image")!==-1){
this.loadmediaopinion_image_show(att, task, container, noname);
}else if(att.type.indexof("video")!==-1){
this.loadmediaopinion_video_show(att, task, container);
}else if(att.type.indexof("audio")!==-1){
this.loadmediaopinion_voice_show(att, task, container);
}else{
this.loadmediaopinion_voice_show(att, task, container);
}
}
}.bind(this));
},
loadmediaopinion_image_show: function(att, task, container, noname){
var url = this.getmediaopinion;
var node = new element("div", {"styles": {"overflow": "hidden"}}).inject( container || this.node);
if (!noname){
var textnode = new element("div", {
"styles": {
"line-height": "28px",
"height": "28px"
},
"text": task.person.substring(0, task.person.indexof("@")) "(" task.completedtime ")"
}).inject(node);
}
//var img = new element("img", {"src": url, "styles": {"background-color": "#ffffff"}}).inject(node);
//
//var height = 200;
//var width = 300;
//if (layout.mobile){
// var size = img.getsize();
// width = 200;
// height = 200*(size.y/size.x);
//}
//img.setstyles({"width": "" width "px", "height": "" height "px"});
var imgnode = new element("div").inject(node);
var width;
if (layout.mobile){
width = 200;
}else{
var pnode = node.getparent();
var offset = imgnode.getposition( pnode );
//width = math.min( pnode.getsize().x - offset.x - 2, 800 );
width = pnode.getsize().x - offset.x - 42;
}
var img = new element("img", {
"src": url,
"styles" : { width : width "px" },
"events" : {
load : function(ev){
var nh=ev.target.naturalheight;
var nw = ev.target.naturalwidth;
if( !layout.mobile && ( this.isnumber( this.json.handwritingwidth ) || this.isnumber( this.json.handwritingheight ) ) ){
var size = this.getimagesize( nw, nh );
img.setstyles(size);
imgnode.setstyles(size);
}else{
var x = math.min(nw, width);
img.setstyles({"width": "" x "px"});
imgnode.setstyles({"width": "" x "px"});
}
}.bind(this)
}
}).inject(imgnode);
// var size = img.getsize();
// var x_y = size.x/size.y;
// if (size.y>260){
// var y = 260;
// var x = 260*x_y;
// img.setstyles({"width": "" x "px", "height": "" y "px"})
// }
},
isnumber : function( d ){
return parsefloat(d).tostring() !== "nan"
},
getimagesize : function(naturalwidth, naturalheight ){
var ww = this.json.handwritingwidth;
var wh = this.json.handwritingheight;
if( this.isnumber(ww) && !this.isnumber(wh) ){
return {
width : math.min( naturalwidth, parseint( ww ) ) "px",
height : "auto"
}
}else if( !this.isnumber(ww) && this.isnumber(wh) ){
return {
width : "auto",
height : math.min( naturalheight, parseint( wh ) ) "px"
}
}else if( this.isnumber(ww) && this.isnumber(wh) ){
var flag = ( naturalwidth / parseint(ww) ) > ( naturalheight / parseint(wh) );
if( flag ){
return {
width : math.min( naturalwidth, parseint( ww ) ) "px",
height : "auto"
}
}else{
return {
width : "auto",
height : math.min( naturalheight, parseint( wh ) ) "px"
}
}
}
},
loadmediaopinion_video_show: function(att, task, container){
},
loadmediaopinion_voice_show: function(att, task, container){
//var node = new element("audio").inject(this.node);
var url = this.getmediaopinion;
var div = new element("div", {"styles": {"overflow": "hidden"}}).inject(container || this.node);
var textnode = new element("div", {
"styles": {
"line-height": "28px",
"height": "28px"
},
"text": task.person.substring(0, task.person.indexof("@")) "(" task.completedtime ")"
}).inject(div);
var node = new element("audio", {"loop": false, "controls": true}).inject(div);
node.set("src", url);
//this.audionode.play();
},
loadworklogtable: function( list, container ){
if( list ){
list.each(function(log, idx){
this.loadworklogline_table(log, idx, container );
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkshow(log)) this.loadworklogline_table(log, idx, container );
}.bind(this));
}
},
loadworklogline_table: function(log, idx, container){
if (!log.readlist) log.readlist = [];
if (!log.readcompletedlist) log.readcompletedlist = [];
if (log.taskcompletedlist.length || log.readlist.length || log.readcompletedlist.length || (this.json.istask && log.tasklist.length)){
var logactivitynode = new element("div", {"styles": this.form.css.logactivitynode}).inject( container || this.node);
var titlenode = new element("div", {"styles": this.form.css.logactivitytitlenode}).inject(logactivitynode);
var childnode = new element("div", {"styles": this.form.css.logactivitychildnode}).inject(logactivitynode);
var iconnode = new element("div", {"styles": this.form.css.logactivityiconnode}).inject(titlenode);
var fromavtivitynode = new element("div", {"styles": this.form.css.logactivityfromnode}).inject(titlenode);
var arrownode = new element("div", {"styles": this.form.css.logactivityarrownode}).inject(titlenode);
var arrivedavtivitynode = new element("div", {"styles": this.form.css.logactivityarrivednode}).inject(titlenode);
var timenode = new element("div", {"styles": this.form.css.logactivitytimenode}).inject(titlenode);
if (log.connected){
iconnode.setstyle("background-image", "");
}else{
iconnode.setstyle("background-image", "");
}
fromavtivitynode.set("html", "" log.fromactivityname "");
if (log.arrivedactivityname){
arrownode.setstyle("background-image", "");
arrivedavtivitynode.set("html", "" log.arrivedactivityname "");
timenode.set("html", "" mwf.xapplication.process.xform.lp.begin ": " log.fromtime "
" mwf.xapplication.process.xform.lp.end ": " log.arrivedtime)
}else{
timenode.set("html", "" mwf.xapplication.process.xform.lp.begin ": " log.fromtime)
}
if ((idx % 2)===0){
logactivitynode.setstyles(this.form.css.logactivitynode_even);
titlenode.setstyles(this.form.css.logactivitytitlenode_even);
}
var tasktable = new element("table", {
"styles": this.form.css.logtabletask,
"border": "0",
"cellspacing": "0",
"cellpadding": "3px",
"width": "100%"
}).inject(childnode);
var tr = tasktable.insertrow(0).setstyles(this.form.css.logtabletasktitleline);
var td = tr.insertcell(0).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.person);
td = tr.insertcell(1).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.department);
td = tr.insertcell(2).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.starttime);
td = tr.insertcell(3).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.completedtime);
td = tr.insertcell(4).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.route);
td = tr.insertcell(5).setstyles(this.form.css.logtabletasktitle);
td.set("text", mwf.xapplication.process.xform.lp.opinion);
log.taskcompletedlist.each(function(taskcompleted){
if (this.checklistshow(log, taskcompleted)) this.loadtaskline_table(taskcompleted, tasktable, log, false);
}.bind(this));
if (this.json.isshowread!==false){
var readnames = [];
var readcompletednames = [];
if (log.readlist && log.readlist.length){
log.readlist.each(function(read){
readnames.push(mwf.name.cn(read.person));
});
}
if (log.readcompletedlist && log.readcompletedlist.length){
log.readcompletedlist.each(function(read){
readcompletednames.push(mwf.name.cn(read.person));
});
}
this.loadreadline_default(readnames, readcompletednames, childnode);
}
if (this.json.istask){
log.tasklist.each(function(task){
if (this.checklistshow(log, task)) this.loadtaskline_table(task, tasktable, log, true);
}.bind(this));
}
}
},
loadtaskline_table: function(task, table, log, istask){
var style = "logtabletaskline";
if (istask) style = "logtabletaskline_task";
var tr = table.insertrow(table.rows.length);
var td = tr.insertcell(0).setstyles(this.form.css[style]);
td.set("text", task.person.substring(0, task.person.indexof("@")) || "");
td = tr.insertcell(1).setstyles(this.form.css[style]);
td.set("text", task.unit.substring(0, task.unit.indexof("@")) || "");
td = tr.insertcell(2).setstyles(this.form.css[style]);
td.set("text", task.starttime || "");
td = tr.insertcell(3).setstyles(this.form.css[style]);
td.set("text", task.completedtime || "");
td = tr.insertcell(4).setstyles(this.form.css[style]);
td.set("text", (task.processingtype=="empower") ? mwf.xapplication.process.xform.lp.empower : task.routename || "");
td = tr.insertcell(5).setstyles(this.form.css[style]);
var op = (task.properties && task.properties.opinion) ? task.properties.opinion : task.opinion;
var opinion = (task.processingtype=="empower") ? mwf.xapplication.process.xform.lp.empowerto o2.name.cn(task.empowertoidentity || "") : "" o2.txt(op || "") "";
td.set("html", opinion);
var atts = [];
if (task.mediaopinion){
var mediaids = task.mediaopinion.split(",");
if (this.form.businessdata.attachmentlist){
this.form.businessdata.attachmentlist.each(function(att){
if (att.site==="$mediaopinion"){
if (mediaids.indexof(att.id)!==-1) atts.push(att);
}
}.bind(this));
}
if (atts.length) this.loadmediaopinion(atts, td.getfirst(), "table");
}
this.fireevent("postloadline",[{
"data" : task,
"atts" : atts,
"node" : tr,
"log" : this,
"type" : istask ? "task" : "taskcompleted"
}]);
},
loadworklogtext: function(list, container){
this.lineclass = "logtasknode";
if( list ){
list.each(function(log, idx){
this.loadworklogline_text(log, idx, container);
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkshow(log)) this.loadworklogline_text(log, idx, container);
}.bind(this));
}
},
loadworklogline_text: function(log, idx, container){
log.taskcompletedlist.each(function(taskcompleted){
if (this.checklistshow(log, taskcompleted)) this.loadtaskline_text(taskcompleted, container || this.node, log, false);
}.bind(this));
if (this.json.istask){
log.tasklist.each(function(task){
if (this.checklistshow(log, task)) this.loadtaskline_text(task, container || this.node, log, true);
}.bind(this));
}
},
loadtaskline_text: function(task, node, log, istask){
this.loadtaskline_default(task, node, log, istask, "0px", false, true, true);
},
checkshow: function(log){
var flag = true;
if (this.json.filterscript && this.json.filterscript.code){
this.form.macro.environment.log = log;
this.form.macro.environment.list = null;
flag = this.form.macro.exec(this.json.filterscript.code, this);
}else{
var isexactmatch = function (property) {
return property && o2.typeof(property)==="array" && property.length && property[0] === "yes";
};
if (this.json.filteractivity && this.json.filteractivity.length){
filteractivitys = this.json.filteractivity;
if(isexactmatch(this.json.filteractivityexactmatch)){ //精确匹配
flag = filteractivitys.split(/[;|,|\n]/gm).contains(log.fromactivityname); //用;,和空格分隔成数组
}else{
flag = (filteractivitys.indexof(log.fromactivityname)!==-1);
}
}
if (this.json.filteractivityalias){
if (this.json.filteractivityalias.length){
filteractivityalias = this.json.filteractivityalias;
if(log.fromactivityalias){
if(isexactmatch(this.json.filteractivityaliasexactmatch)){ //精确匹配
flag = filteractivityalias.split(/[;|,|\n]/gm).contains(log.fromactivityalias); //用;,和空格分隔成数组
}else{
flag = (filteractivityalias.indexof(log.fromactivityalias)!==-1);
}
}
}
}
if (this.json.filterperson && this.json.filterperson.length){
flag = false;
filterpersons = this.json.filterperson;
var tmptaskcompletedlist = [];
if(isexactmatch(this.json.filterpersonexactmatch)) { //精确匹配
var filterpersonslist = filterpersons.split(/[;|,|\n]/gm);
log.taskcompletedlist.each(function(taskcompleted){
var matcharr = (taskcompleted.person "@" taskcompleted.identity).split("@").concat([taskcompleted.person, taskcompleted.identity]);
for(var i=0; i < filterpersonslist.length; i ){
if( matcharr.contains(filterpersonslist[i]) ){
tmptaskcompletedlist.push(taskcompleted);
break;
}
}
}.bind(this));
}else{
log.taskcompletedlist.each(function(taskcompleted){
if ((filterpersons.indexof(taskcompleted.person)!==-1) || (filterpersons.indexof(taskcompleted.identity)!==-1)){
tmptaskcompletedlist.push(taskcompleted);
}
}.bind(this));
}
if (tmptaskcompletedlist.length){
//log.taskcompletedlist = [];
//log.taskcompletedlist = tmptaskcompletedlist;
flag = true;
}
}
if (this.json.filterroute && this.json.filterroute.length){
filterroutes = this.json.filterroute;
if(isexactmatch(this.json.filterrouteexactmatch)){ //精确匹配
flag = filterroutes.split(/[;|,|\n]/gm).contains(log.routename); //用;,和空格分隔成数组
}else{
flag = (filterroutes.indexof(log.routename)!==-1);
}
}
}
return flag;
},
checklistshow: function(log, list){
var flag = true;
if (this.json.filterscript && this.json.filterscript.code){
this.form.macro.environment.log = log;
this.form.macro.environment.list = list;
flag = this.form.macro.exec(this.json.filterscript.code, this);
}else{
var isexactmatch = function (property) {
return property && o2.typeof(property)==="array" && property.length && property[0] === "yes";
};
if (this.json.filterperson && this.json.filterperson.length){
var filterperson = this.json.filterperson;
flag = false;
if(isexactmatch(this.json.filterpersonexactmatch)) { //精确匹配
var filterpersonslist = filterperson.split(/[;|,|\n]/gm);
var matcharr = (list.person "@" list.identity).split("@").concat([list.person, list.identity]);
for(var i=0; i < filterpersonslist.length; i ){
if( matcharr.contains(filterpersonslist[i]) ){
flag = true;
break;
}
}
}else{
flag = ((filterpersons.indexof(list.person)!==-1)|| (filterpersons.indexof(list.identity)!==-1));
}
}
// if (this.json.filterperson && this.json.filterperson.length){
// flag = ((filterpersons.indexof(list.person)!==-1)|| (filterpersons.indexof(list.identity)!==-1));
// }
}
return flag;
},
loadworklogdefault: function(list, container){
//var text = this.json.textstyle;
if( list ){
list.each(function(log, idx){
this.loadworklogline_default(log, idx, container);
}.bind(this));
}else{
this.worklog.each(function(log, idx){
if (this.checkshow(log)) this.loadworklogline_default(log, idx, container);
}.bind(this));
}
},
loadworklogline_default: function(log, idx, container){
if (!log.readlist) log.readlist = [];
if (!log.readcompletedlist) log.readcompletedlist = [];
if (log.taskcompletedlist.length || log.readlist.length || log.readcompletedlist.length || (this.json.istask && log.tasklist.length)) {
var logactivitynode = new element("div", {"styles": this.form.css.logactivitynode}).inject(container || this.node);
var titlenode = new element("div", {"styles": this.form.css.logactivitytitlenode}).inject(logactivitynode);
var childnode = new element("div", {"styles": this.form.css.logactivitychildnode}).inject(logactivitynode);
var iconnode = new element("div", {"styles": this.form.css.logactivityiconnode}).inject(titlenode);
var fromavtivitynode = new element("div", {"styles": this.form.css.logactivityfromnode}).inject(titlenode);
var arrownode = new element("div", {"styles": this.form.css.logactivityarrownode}).inject(titlenode);
var arrivedavtivitynode = new element("div", {"styles": this.form.css.logactivityarrivednode}).inject(titlenode);
var readactionnode = new element("div", {"styles": this.form.css.logactivityreadactionnode}).inject(titlenode);
var timenode = new element("div", {"styles": this.form.css.logactivitytimenode}).inject(titlenode);
if (log.connected) {
iconnode.setstyle("background-image", "");
} else {
iconnode.setstyle("background-image", "");
}
fromavtivitynode.set("html", "" log.fromactivityname "");
if (log.arrivedactivityname) {
arrownode.setstyle("background-image", "");
arrivedavtivitynode.set("html", "" log.arrivedactivityname "");
timenode.set("html", "" mwf.xapplication.process.xform.lp.begin ": " log.fromtime "
" mwf.xapplication.process.xform.lp.end ": " log.arrivedtime)
} else {
timenode.set("html", "" mwf.xapplication.process.xform.lp.begin ": " log.fromtime)
}
// if ((log.readlist && log.readlist.length) || (log.readcompletedlist && log.readcompletedlist.length)){
// readactionnode.set("text", mwf.xapplication.process.xform.lp.worklogread);
// }
if ((idx % 2) === 0) {
logactivitynode.setstyles(this.form.css.logactivitynode_even);
titlenode.setstyles(this.form.css.logactivitytitlenode_even);
}
log.taskcompletedlist.each(function (taskcompleted) {
if (this.checklistshow(log, taskcompleted)) this.loadtaskline_default(taskcompleted, childnode, log, false);
}.bind(this));
if (this.json.isshowread!==false){
var readnames = [];
var readcompletednames = [];
if (log.readlist && log.readlist.length){
log.readlist.each(function(read){
readnames.push(mwf.name.cn(read.person));
});
}
if (log.readcompletedlist && log.readcompletedlist.length){
log.readcompletedlist.each(function(read){
readcompletednames.push(mwf.name.cn(read.person));
});
}
//if (readcompletednames.length)
this.loadreadline_default(readnames, readcompletednames, childnode);
}
if (this.json.istask) {
log.tasklist.each(function (task) {
if (this.checklistshow(log, task)) this.loadtaskline_default(task, childnode, log, true);
}.bind(this));
}
}
},
loadreadline_default: function(readnames, readcompletednames, node){
var html = "";
var logreadnode = new element("div", {"styles": this.form.css.logreadtextnode}).inject(node);
if (readnames.length){
var readstrtitle = readnames.join(", ");
var readstr = (readnames.length>20) ? (readnames.slice(0,20).join(", ") mwf.xapplication.process.xform.lp.andsoforth ): readstrtitle;
html = "" (this.json.showreadtitle || mwf.xapplication.process.xform.lp.showreadtitle) ": " readstr " ";
//var logreadpersonnode = new element("div", {"styles": this.form.css.logreadtextnode}).inject(logreadnode);
}
if (readcompletednames.length){
var readcompletedstrtitle = readcompletednames.join(", ");
var readcompletedstr = (readcompletednames.length>20) ? (readcompletednames.slice(0,20).join(", ") mwf.xapplication.process.xform.lp.andsoforth ): readcompletedstrtitle;
html = "" (this.json.showreadcompletedtitle || mwf.xapplication.process.xform.lp.showreadcompletedtitle) ": " readcompletedstr " ";
}
if (html) logreadnode.set("html", html);
},
loadtaskline_default: function(task, node, log, istask, margin, iszebra, nodestyle, noiconnode){
var style = "logtasknode";
var textstyle = "logtaskfloattextnode";
if (nodestyle){
style = "logtasktextnode";
textstyle = "logtasktextnode";
}
var logtasknode = new element("div", {"styles": this.form.css[style]}).inject(node);
var iconnode;
if( !noiconnode ){
iconnode = new element("div", {"styles": this.form.css.logtaskiconnode}).inject(logtasknode);
}
var textnode = new element("div", {"styles": this.form.css[textstyle]}).inject(logtasknode);
if (iszebra){
logtasknode.setstyles(this.form.css[this.lineclass]);
if (this.lineclass === "logtasknode"){
this.lineclass = "logtasknode_even";
}else{
this.lineclass = "logtasknode";
}
}
var left = 28;
if( iconnode ){
if (margin) iconnode.setstyle("margin-left", margin);
left = iconnode.getstyle("margin-left").toint();
left = left 28;
}
if( !nodestyle ){
textnode.setstyle("margin-left",left "px");
}
var html;
var company = "";
var atts = [];
if (!istask){
company = (task.unitlist) ? task.unitlist[task.unitlist.length-1] : "";
var html = this.json.textstyle;
if (task.processingtype=="empower") html = mwf.xapplication.process.xform.lp.empowertohtml;
var nexttasktext = "";
if (task.processingtype=="empower"){
var nexttaskparts = [];
if (task.nexttaskidentitylisttext){
var nestids = task.nexttaskidentitylisttext.split(",");
nexttaskparts = o2.name.cns(nestids);
}else{
// var nexttasks = o2.name.cns(log.nexttaskidentitylist).join(", ");
// var nexttaskcompleteds = o2.name.cns(log.nexttaskcompletedidentitylist).join(", ");
var nexttasks = (log.nexttaskidentitylist && log.nexttaskidentitylist.length) ? o2.name.cns(log.nexttaskidentitylist).join(", ") : "";
var nexttaskcompleteds = (log.nexttaskcompletedidentitylist && log.nexttaskcompletedidentitylist.length) ? o2.name.cns(log.nexttaskcompletedidentitylist).join(", ") : "";
if (nexttasks) nexttaskparts.push(nexttasks);
if (nexttaskcompleteds) nexttaskparts.push(nexttaskcompleteds);
}
nexttasktext = nexttaskparts.join(", ");
}else{
nexttasktext = (task.empowertoidentity) ? o2.name.cn(task.empowertoidentity) : "";
}
if (this.json.textstylescript && this.json.textstylescript.code){
this.form.macro.environment.log = log;
this.form.macro.environment.list = null;
html = this.form.macro.exec(this.json.textstylescript.code, this);
}
//如果是自动流转,强制使用默认格式
if (task.processingtype==="autoflow") html = mwf.xapplication.process.xform.lp.autoflowhtml;
var person = task.person.substring(0, task.person.indexof("@"));
if( task.processingtype !== "empower" && task.empowerfromidentity){
person = person " 代 " o2.name.cn(task.empowerfromidentity||"");
}
html = html.replace(/\{person\}/g, person );
html = html.replace(/\{department\}/g, task.unit.substring(0, task.unit.indexof("@")));
html = html.replace(/\{route\}/g, o2.txt(task.routename));
html = html.replace(/\{time\}/g, task.completedtime);
html = html.replace(/\{date\}/g, new date().parse(task.completedtime).format("%y-%m-%d"));
var op = (task.properties && task.properties.opinion) ? task.properties.opinion : task.opinion;
html = html.replace(/\{opinion\}/g, o2.txt(op || ""));
html = html.replace(/\{company\}/g, company.substring(0, company.indexof("@")));
html = html.replace(/\{starttime\}/g, task.starttime);
html = html.replace(/\{startdate\}/g, new date().parse(task.starttime).format("%y-%m-%d"));
html = html.replace(/\{activity\}/g, o2.txt(log.fromactivityname));
html = html.replace(/\{arrivedactivity\}/g, o2.txt(log.arrivedactivityname));
html = html.replace(/\{img\}/g, "");
html = html.replace(/\{empowerto\}/g, ((task.empowertoidentity) ? o2.name.cn(task.empowertoidentity) : ""));
html = html.replace(/\{nexttask\}/g, nexttasks);
html = html.replace(/\{nexttaskcompleted\}/g, nexttaskcompleteds);
html = html.replace(/\{next\}/g, nexttasktext);
//var html = mwf.xapplication.process.xform.lp.nextuser task.person "(" task.department ")" ", "
// mwf.xapplication.process.xform.lp.selectroute ": [" task.routename "], "
// mwf.xapplication.process.xform.lp.submitat ": " task.completedtime ", "
// mwf.xapplication.process.xform.lp.idea ": " (task.opinion || "") "";
textnode.set("html", html);
var imgnode = textnode.getelement(".mwf_log_img");
if (task.mediaopinion){
var mediaids = task.mediaopinion.split(",");
// var atts = [];
if (this.form.businessdata.attachmentlist){
this.form.businessdata.attachmentlist.each(function(att){
if (att.site==="$mediaopinion"){
if (mediaids.indexof(att.id)!==-1) atts.push(att);
}
}.bind(this));
}
if (atts.length){
if (imgnode){
this.loadmediaopinion_show(atts, task, imgnode, true);
// atts.each(function(att){
// this.loadmediaopinion_image_show(att, task, imgnode);
// }.bind(this));
}else{
this.loadmediaopinion(atts, textnode, "default");
}
}
}
}else{
//company = task.unitlist[task.unitlist.length-1];
html = task.person.substring(0, task.person.indexof("@")) "(" task.unit.substring(0, task.unit.indexof("@")) ")" mwf.xapplication.process.xform.lp.processing ", "
mwf.xapplication.process.xform.lp.cometime ": " task.starttime;
textnode.set("html", html);
if(iconnode)iconnode.setstyle("background-image", "");
}
this.fireevent("postloadline",[{
"data" : task,
"node" : logtasknode,
"atts" : atts,
"log" : this,
"type" : istask ? "task" : "taskcompleted"
}]);
},
loadmediaopinion: function(atts, node, type){
atts.each(function(att){
if (!att.type) att.type = "image";
if (att.type.indexof("image")!==-1){
if( this.json.handwritingexpanded ){
this.loadmediaopinion_image_show(att, null, node, true)
}else if( type === "table" && !layout.mobile ){
this.loadmediaopinion_image_tooltip(att, node);
}else{
this.loadmediaopinion_image(att, node);
}
}else if(att.type.indexof("video")!==-1){
this.loadmediaopinion_video(att, node);
}else if(att.type.indexof("audio")!==-1){
this.loadmediaopinion_voice(att, node);
}else {
if (this.json.handwritingexpanded){
this.loadmediaopinion_image_show(att, null, node, true)
}else if( type === "table" && !layout.mobile ){
this.loadmediaopinion_image_tooltip(att, node);
}else{
this.loadmediaopinion_image(att, node);
}
}
}.bind(this));
},
getmediaopinionurl: function(att){
var action = mwf.actions.get("x_processplatform_assemble_surface");
var url = action.action.actions["getattachmentstream"].uri;
if (this.form.businessdata.workcompleted){
url = action.action.actions["getworkcompletedattachmentstream"].uri;
url = url.replace("{id}", att.id);
url = url.replace("{workcompletedid}", this.form.businessdata.workcompleted.id);
}else{
url = url.replace("{id}", att.id);
url = url.replace("{workid}", this.form.businessdata.work.id);
}
url = action.action.address url;
return o2.filter;
},
loadmediaopinion_image_tooltip : function(att, node){
var iconnode = new element("div", {"styles": this.form.css.logmediaicon}).inject(node.getparent());
iconnode.setstyle("background-image", "");
iconnode.set("title", mwf.xapplication.process.xform.lp.mediaopinion_image);
if( !this.mtooltipsloaded )o2.xdesktop.requireapp("template", "mtooltips", null, false);
this.mtooltipsloaded = true;
var tooltip = new mtooltips(this.form.app.content, iconnode, this.form.app, null, {
axis : "y", "delay" : 350,
nodestyles : {
"max-width" : "800px"
}
});
tooltip.contentnode = new element("div",{
styles : { width : "100%" , height : "100%" }
});
var img = new element("img", {
"src": this.getmediaopinion,
"events" : {
load : function(ev){
var nh = ev.target.naturalheight;
var nw = ev.target.naturalwidth;
if( this.isnumber( this.json.handwritingwidth ) || this.isnumber( this.json.handwritingheight ) ){
var size = this.getimagesize( nw, nh );
ev.target.setstyles(size);
}else{
var x = math.min(nw, 800);
ev.target.setstyles({"width": "" x "px"});
}
}.bind(this)
}
}).inject(tooltip.contentnode);
},
loadmediaopinion_image: function(att, node){
var iconnode = new element("div", {"styles": this.form.css.logmediaicon}).inject(node.getparent());
iconnode.setstyle("background-image", "");
iconnode.set("title", mwf.xapplication.process.xform.lp.mediaopinion_image);
iconnode.addevents({
"click": function(e){
if (e.target.mediaopinioncontentnode) return "";
var url = this.getmediaopinion;
// if (this.mediaopinioncontentnode){
// this.mediaopinioncontentnode.destroy();
// this.mediaopinioncontentnode = null;
// }
var imgnode = new element("div", {"styles": this.form.css.logmediaopinioncontent}).inject(node.getparent(),"after");
if (!layout.mobile) imgnode.setstyle("margin-left", "40px");
//this.mediaopinioncontentnode = imgnode;
e.target.mediaopinioncontentnode = imgnode;
var imgclosenode = new element("div", {"styles": this.form.css.logmediaopinioncontentclose}).inject(imgnode);
imgclosenode.addevent("click", function(){ imgnode.destroy(); e.target.mediaopinioncontentnode = "";});
var imgareanode = new element("div", {"styles": this.form.css.logmediaopinioncontentarea}).inject(imgnode);
// var height = 260;
// var width = 390;
var width;
//var height;
if (layout.mobile){
width = node.getparent().getparent().getsize().x-2;
//height = width*2/3;
}else{
var pnode = node.getparent().getparent();
var offset = imgnode.getposition( pnode );
width = math.min( pnode.getsize().x - offset.x - 42, 800 );
}
var img = new element("img", {
"src": url,
"styles" : { width : width "px" },
"events" : {
load : function(ev){
var nh = ev.target.naturalheight;
var nw = ev.target.naturalwidth;
if( !layout.mobile && ( this.isnumber( this.json.handwritingwidth ) || this.isnumber( this.json.handwritingheight ) ) ){
var size = this.getimagesize( nw, nh );
img.setstyles(size);
imgnode.setstyles(size);
}else{
var x = math.min(nw, width);
img.setstyles({"width": "" x "px"});
imgnode.setstyles({"width": "" x "px"});
}
}.bind(this)
}
}).inject(imgareanode);
//img.setstyles({"width": "" width "px"});
//imgnode.setstyles({"width": "" width "px"});
//img.setstyles({"width": "" width "px", "height": "" height "px"});
//imgnode.setstyles({"width": "" width "px", "height": "" height "px"});
// var size = img.getsize();
// var x_y = size.x/size.y;
//if (size.y>260){
//}
// var p = iconnode.getposition(this.form.app.content);
// var s = iconnode.getsize();
// var size = (layout.mobile) ? {"x": width, "y": height}: imgnode.getsize();
// var contentsize = this.form.app.content.getsize();
// var contentscroll = (layout.mobile) ? document.body.getfirst().getscroll() : {"x": 0, "y": 0};
// var y = p.y-size.y;
// var x = p.x s.x/2-size.x/2;
//
// if (x<10) x = 10;
// if (x size.x>contentsize.x-10) x = contentsize.x-size.x-20;
// if (y size.y>contentsize.y-10) y = contentsize.y-size.y-20;
// if (y<10) y = 10;
// y=y contentscroll.y;
//
// if (layout.mobile){
// x = 0;
// }
// imgnode.setstyles({
// "top": "" y "px",
// "left": "" x "px"
// });
// this.hidemediaopinionnodefun = this.hidemediaopinionnode.bind(this);
// this.form.node.addevent("mousedown", this.hidemediaopinionnodefun);
e.stoppropagation();
}.bind(this)
});
},
hidemediaopinionnode: function(){
if (this.mediaopinioncontentnode){
this.mediaopinioncontentnode.destroy();
this.mediaopinioncontentnode = null;
}
// if (this.hidemediaopinionnodefun) this.form.node.removeevent("click", this.hidemediaopinionnodefun);
},
loadmediaopinion_video: function(att, node){
var iconnode = new element("div", {"styles": this.form.css.logmediaicon}).inject(node.getparent());
iconnode.setstyle("background-image", "");
iconnode.set("title", mwf.xapplication.process.xform.lp.mediaopinion_video);
},
loadmediaopinion_voice: function(att, node){
// this.form.css.logmediaicon.width = "60px";
// var iconnode = new element("audio", {
// "styles": this.form.css.logmediaicon,
// "controls": true,
// "html": ""
// }).inject(node.getparent());
var iconnode = new element("div", {"styles": this.form.css.logmediaicon}).inject(node.getparent());
iconnode.setstyle("background-image", "");
iconnode.set("title", mwf.xapplication.process.xform.lp.mediaopinion_voice);
iconnode.addevents({
"click": function(e){
var url = this.getmediaopinion;
this.audionode = new element("audio", {"loop": false});
this.audionode.set("src", url);
this.audionode.play();
e.stoppropagation();
}.bind(this)
});
}
});
source