mwf.xdesktop.requireapp("process.xform", "$module", null, false);
//mwf.xdesktop.requireapp("process.xform", "widget.view", null, false);
/** @class statement 查询视图组件。
* @o2cn 查询视图
* @example
* //可以在脚本中获取该组件
* //方法1:
* var statement = this.form.get("fieldid"); //获取组件
* //方法2
* var statement = this.target; //在组件本身的脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.statement = mwf.appstatement = new class(
/** @lends mwf.xapplication.process.xform.statement# */
{
extends: mwf.app$module,
options: {
/**
* 视图参数(options)已经准备好,还未加载视图时执行。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
* @event mwf.xapplication.process.xform.statement#beforeloadview
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 视图设计已经获取,容器也已经准备好。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
* @event mwf.xapplication.process.xform.statement#loadviewlayout
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 异步加载查询视图后执行。
* @event mwf.xapplication.process.xform.statement#loadview
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 选中查询视图中的一条记录后执行。
* @event mwf.xapplication.process.xform.statement#select
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 取消选中查询视图中的一条记录后执行。
* @since v8.0
* @event mwf.xapplication.process.xform.statement#unselect
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 打开查询视图中的一条记录后执行。
* @event mwf.xapplication.process.xform.statement#opendocument,可以通过this.event得到打开的文档参数
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["load", "beforeloadview", "loadviewlayout", "loadview", "queryload", "postload", "select", "unselect", "opendocument"]
},
_loaduserinterface: function(){
mwf.xdesktop.requireapp("query.query", "statement", null, false);
this.node.empty();
},
_afterloaded: function(){
if (this.json.querystatement){
this.loadview();
}
},
/**
* @summary 重新加载查询视图
* @example
* this.form.get("fieldid").reload()
*/
reload: function( callback ){
if (this.view){
if (this.view.loadviewres && this.view.loadviewres.res) if (this.view.loadviewres.res.isrunning()) this.view.loadviewres.res.cancel();
if (this.view.getviewres && this.view.getviewres.res) if (this.view.getviewres.res.isrunning()) this.view.getviewres.res.cancel();
}
this.node.empty();
this.loadview( callback );
},
/**
* @summary 当查询视图被设置为延迟加载(未立即载入),通过active方法激活
* @example
* this.form.get("fieldid").active()
*/
active: function( callback ){
if (this.view){
if (!this.view.loadingareanode) this.view.loadview( callback );
}else{
this.loadview( callback );
}
},
loadview: function( callback ){
if (!this.json.querystatement) return "";
var filter = null;
if (this.json.filterlist && this.json.filterlist.length){
filter = [];
this.json.filterlist.each(function(entry){
entry.value = this.form.macro.exec(entry.code.code, this);
//delete entry.code;
filter.push(entry);
}.bind(this));
}
var parameter = null;
if( this.json.parameterlist && this.json.parameterlist.length ){
parameter = {};
this.json.parameterlist.each(function(entry){
parameter[entry.parameter] = this.parseparameter(entry);
}.bind(this));
}
//var data = json.parse(this.json.data);
var viewjson = {
"application": (this.json.querystatement) ? this.json.querystatement.appname : this.json.application,
"statementname": (this.json.querystatement) ? this.json.querystatement.name : this.json.statementname,
"statementid": (this.json.querystatement) ? this.json.querystatement.id : this.json.statementid,
"istitle": this.json.istitle || "yes",
"select": this.json.select || "none",
"titlestyles": this.json.titlestyles,
"itemstyles": this.json.itemstyles,
"isexpand": this.json.isexpand || "no",
"showactionbar" : this.json.actionbar === "show",
"filter": filter,
"parameter": parameter,
"parameterlist": this.json.parameterlist,
"defaultselectedscript" : this.json.defaultselectedscript ? this.json.defaultselectedscript.code : null,
"selectedablescript" : this.json.selectedablescript ? this.json.selectedablescript.code : null
};
this.fireevent("beforeloadview", [viewjson]);
//mwf.xdesktop.requireapp("query.query", "viewer", function(){
/**
* @summary statement组件,平台使用该组件实现查询视图的功能
* @member {mwf.xapplication.query.query.statement}
* @example
* //可以在脚本中获取该组件
* var view = this.form.get("fieldid").view; //获取组件对象
*/
this.view = new mwf.xapplication.query.query.statement(this.node, viewjson, {
"isload": (this.json.loadview!=="no"),
"resizenode": (this.node.getstyle("height").tostring().tolowercase()!=="auto" && this.node.getstyle("height").toint()>0),
"onloadlayout": function () {
this.fireevent("loadviewlayout");
}.bind(this),
"onloadview": function(){
this.fireevent("loadview");
if(callback)callback();
}.bind(this),
"onselect": function(item){
this.fireevent("select", [item]);
}.bind(this),
"onunselect": function(item){
this.fireevent("unselect", [item]);
}.bind(this),
"onopendocument": function(options, item){
this.openoptions = {
"options": options,
"item": item
};
this.fireevent("opendocument", [this.openoptions]);
this.openoptions = null;
}.bind(this)
}, this.form.app, this.form.macro);
//}.bind(this));
},
/**
* @summary 获取查询视图被选中行的数据
* @return {object[]} 被选中行的数据
* @example
* var data = this.form.get("fieldid").getdata();
*/
getdata: function(){
if (this.view.selecteditems.length){
var arr = [];
this.view.selecteditems.each(function(item){
arr.push(item.data);
});
return arr;
}else{
return [];
}
},
parseparameter: function (f) {
var value = f.value;
if( f.valuetype === "script" ){
value = this.form.macro.exec(f.valuescript ? f.valuescript.code : "", this);
}
return value;
// 后面的放在 querystatement中解析了
// if (typeof(value) === "date") {
// value = value.format("db");
// }
// var user = layout.user;
// switch (value) {
// case "@person":
// value = user.distinguishedname;
// break;
// case "@identitylist":
// value = user.identitylist.map(function (d) {
// return d.distinguishedname;
// });
// break;
// case "@unitlist":
// o2.actions.load("x_organization_assemble_express").unitaction.listwithperson({"personlist": [user.distinguishedname]}, function (json) {
// value = json.unitlist;
// }, null, false);
// break;
// case "@unitalllist":
// o2.actions.load("x_organization_assemble_express").unitaction.listwithidentitysupnested({"personlist": [user.distinguishedname]}, function (json) {
// value = json.unitlist;
// }, null, false);
// break;
// case "@year":
// value = (new date().getfullyear()).tostring();
// break;
// case "@season":
// var m = new date().format("%m");
// if (["01", "02", "03"].contains(m)) {
// value = "1"
// } else if (["04", "05", "06"].contains(m)) {
// value = "2"
// } else if (["07", "08", "09"].contains(m)) {
// value = "3"
// } else {
// value = "4"
// }
// break;
// case "@month":
// value = new date().format("%y-%m");
// break;
// case "@time":
// value = new date().format("db");
// break;
// case "@date":
// value = new date().format("%y-%m-%d");
// break;
// default:
// }
//
// if (f.formattype === "datetimevalue" || f.formattype === "datetimevalue") {
// value = "{ts '" value "'}"
// } else if (f.formattype === "datevalue") {
// value = "{d '" value "'}"
// } else if (f.formattype === "timevalue") {
// value = "{t '" value "'}"
// }
// return value;
}
});
source