mwf.xdesktop.requireapp("process.xform", "$module", null, false);
//mwf.xdesktop.requireapp("process.xform", "widget.view", null, false);
/** @class view 视图组件。
* @o2cn 视图
* @example
* //可以在脚本中获取该组件
* //方法1:
* var view = this.form.get("fieldid"); //获取组件
* //方法2
* var view = this.target; //在组件本身的脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.view = mwf.appview = new class(
/** @lends mwf.xapplication.process.xform.view# */
{
extends: mwf.app$module,
options: {
/**
* 视图参数(options)已经准备好,还未加载视图时执行。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
* @event mwf.xapplication.process.xform.view#beforeloadview
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 视图设计已经获取,容器也已经准备好。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
* @event mwf.xapplication.process.xform.view#loadviewlayout
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 异步加载视图后执行。
* @event mwf.xapplication.process.xform.view#loadview
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 选中视图中的一条记录后执行。
* @event mwf.xapplication.process.xform.view#select
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 取消选中视图中的一条记录后执行。
* @since v8.0
* @event mwf.xapplication.process.xform.view#unselect
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 打开视图中的一条记录后执行。
* @event mwf.xapplication.process.xform.view#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", "viewer", null, false);
this.node.empty();
},
_afterloaded: function(){
if (this.json.queryview){
this.loadview();
}else{
if (this.json.selectviewtype==="cms"){
this.loadcmsview();
}else if (this.json.selectviewtype==="process"){
this.loadprcessview();
}else{
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.queryview || !this.json.queryview.name || !this.json.queryview.appname) 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 data = json.parse(this.json.data);
var viewjson = {
"application": (this.json.queryview) ? this.json.queryview.appname : this.json.application,
"viewname": (this.json.queryview) ? this.json.queryview.name : this.json.viewname,
"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,
"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 view组件,平台使用该组件实现视图的功能
* @member {mwf.xapplication.query.query.viewer}
* @example
* //可以在脚本中获取该组件
* var view = this.form.get("fieldid").view; //获取组件对象
*/
this.view = new mwf.xapplication.query.query.viewer(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));
},
loadprcessview: function(){
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 viewjson = {
"application": this.json.processview.application,
"viewname": this.json.processview.name,
"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
};
mwf.xdesktop.requireapp("process.application", "viewer", function(){
this.view = new mwf.xapplication.process.application.viewer(this.node, viewjson, {
"resizenode": (this.node.getstyle("height").tostring().tolowercase()!=="auto" && this.node.getstyle("height").toint()>0),
"onselect": function(){
this.fireevent("select");
}.bind(this)
});
}.bind(this));
},
loadcmsview: function(){
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 viewjson = {
"application": this.json.cmsview.appid,
"viewname": this.json.cmsview.name,
"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
};
mwf.xdesktop.requireapp("process.application", "viewer", function(){
this.view = new mwf.xapplication.process.application.viewer(this.node, viewjson, {
"actions": {
"lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"put"},
"getview": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
},
"actionroot": "x_cms_assemble_control",
"resizenode": (this.node.getstyle("height").tostring().tolowercase()!=="auto" && this.node.getstyle("height").toint()>0),
"onselect": function(){
this.fireevent("select");
}.bind(this)
});
}.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 [];
}
}
});
source