mwf.xdesktop.requireapp("process.xform", "$module", null, false);
mwf.xdesktop.requireapp("process.xform", "button", null, false);
/** @class viewselector 视图选择组件。
* @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.viewselector = mwf.appviewselector = new class({
implements: [events],
extends: mwf.xapplication.process.xform.button,
options: {
/**
* 视图参数(options)已经准备好,还未加载视图时执行。可以通过this.event得到视图参数,并可修改this.event修改视图的加载。
* @event mwf.xapplication.process.xform.viewselector#beforeloadview
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 视图设计已经获取,容器也已经准备好。
* @event mwf.xapplication.process.xform.viewselector#loadviewlayout
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 异步加载视图后执行。
* @event mwf.xapplication.process.xform.viewselector#loadview
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 选中视图中的一条记录后执行。
* @event mwf.xapplication.process.xform.viewselector#select
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 打开视图中的一条记录后执行。
* @event mwf.xapplication.process.xform.viewselector#opendocument
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["load", "beforeloadview", "loadview", "queryload", "postload", "select", "opendocument"]
},
_loaduserinterface: function(){
var button = this.node.getelement("button");
if (!button) button = new element("button");
button.inject(this.node, "after");
this.node.destroy();
this.node = button;
this.node.set({
"id": this.json.id,
"text": this.json.name || this.json.id,
"styles": this.form.json.buttonstyle || this.form.css.buttonstyles,
"mwftype": this.json.type
});
if(this.json.recoverystyles){
this.node.setstyles(this.json.recoverystyles);
}
this.node.addevent("click", function(){
this.selecteddata = null;
this.selectview(function(data){
this.doresult(data);
}.bind(this));
}.bind(this));
},
doresult: function(data){
if (this.json.result === "script"){
this.selecteddata = data;
return (this.json.selectedscript.code) ? this.form.macro.exec(this.json.selectedscript.code, this) : "";
}else{
object.each(this.json.selectedsetvalues, function(v, k){
var value = "";
data.each(function(d, idx){
object.each(d.data, function(dv, dk){
if (dk===v) value = (value) ? (value ", " dv) : dv;
}.bind(this));
}.bind(this));
var field = this.form.all[k];
if (field){
field.setdata(value);
if (value){
if (field.descriptionnode) field.descriptionnode.setstyle("display", "none");
}else{
if (field.descriptionnode) field.descriptionnode.setstyle("display", "block");
}
}
}.bind(this));
}
},
selectcmsview: function(callback){
var viewdata = this.json.cmsviewname;
if (viewdata){
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": viewdata.appid,
"viewname": viewdata.name,
"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
};
var options = {};
var width = options.width || "800";
var height = options.height || "450";
var size;
if (layout.mobile){
size = document.body.getsize();
width = size.x;
height = size.y;
options.style = "viewmobile";
}
width = width.toint();
height = height.toint();
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 || "select view",
"style": options.style || "view",
"top": y,
"left": x-20,
"fromtop":y,
"fromleft": x-20,
"width": width,
"height": height,
"html": "",
"masknode": this.form.app.content,
"container": this.form.app.content,
"buttonlist": [
{
"text": mwf.lp.process.button.ok,
"action": function(){
//if (callback) callback(_self.view.selecteditems);
if (callback) callback(_self.view.getdata());
this.close();
}
},
{
"text": mwf.lp.process.button.cancel,
"action": function(){this.close();}
}
]
});
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.cmsview", function(){
// this.view = new mwf.xapplication.process.xform.widget.cmsview(dlg.content.getfirst(), viewjson, {"style": "select"});
// }.bind(this));
mwf.xdesktop.requireapp("process.application", "viewer", function(){
this.view = new mwf.xapplication.process.application.viewer(dlg.content, 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"
});
}.bind(this));
}.bind(this));
}
},
selectprocessview: function(callback){
var viewdata = this.json.processviewname;
if (viewdata){
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": viewdata.application,
"viewname": viewdata.name,
"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
};
var options = {};
var width = options.width || "800";
var height = options.height || "600";
var size;
if (layout.mobile){
size = document.body.getsize();
width = size.x;
height = size.y;
options.style = "viewmobile";
}
width = width.toint();
height = height.toint();
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 || "select view",
"style": options.style || "view",
"top": y,
"left": x-20,
"fromtop":y,
"fromleft": x-20,
"width": width,
"height": height,
"html": "",
"masknode": this.form.app.content,
"container": this.form.app.content,
"buttonlist": [
{
"text": mwf.lp.process.button.ok,
"action": function(){
//if (callback) callback(_self.view.selecteditems);
if (callback) callback(_self.view.getdata());
this.close();
}
},
{
"text": mwf.lp.process.button.cancel,
"action": function(){this.close();}
}
]
});
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("process.application", "viewer", function(){
this.view = new mwf.xapplication.process.application.viewer(dlg.content, viewjson);
}.bind(this));
}.bind(this));
}
},
selectqueryview: function(callback){
var viewdata = this.json.queryview;
if (viewdata){
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": 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" : this.json.defaultselectedscript ? this.json.defaultselectedscript.code : null,
"selectedablescript" : this.json.selectedablescript ? this.json.selectedablescript.code : null
};
this.fireevent("beforeloadview", [viewjson]);
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 || "select view",
"style": options.style || "view",
"top": y,
"left": x-20,
"fromtop":y,
"fromleft": x-20,
"width": width,
"height": height,
"html": "",
"maxheightpercent": layout.mobile ? "100%" : "98%",
"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);
if (callback) callback(_self.view.getdata());
this.close();
}
},
{
"text": mwf.lp.process.button.cancel,
"action": function(){this.close();}
}
],
"onpostshow": function(){
if(layout.mobile){
dlg.node.setstyle("z-index",200);
}
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.view = new mwf.xapplication.query.query.viewer(dlg.content, viewjson, {
"style": "select",
"onloadlayout": function () {
this.fireevent("loadviewlayout");
}.bind(this),
"onloadview": function(){
this.fireevent("loadview");
}.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));
}.bind(this)
});
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));
}
},
selectview: function(callback){
if (this.json.queryview){
this.selectqueryview(callback);
}else{
if (this.json.selectviewtype==="cms"){
this.selectcmsview(callback);
}else{
this.selectprocessview(callback);
}
}
}
});
source