mwf.xapplication.query = mwf.xapplication.query || {};
mwf.xapplication.query.query = mwf.xapplication.query.query || {};
mwf.xdesktop.requireapp("query.query", "viewer", null, false);
/** @classdesc statement 数据中心的查询视图。本章节的脚本上下文请看{@link module:querystatement|querystatement}。
* @class
* @o2cn 查询视图
* @extends mwf.xapplication.query.query.viewer
* @o2category querystatement
* @o2range {querystatement}
* @hideconstructor
* @example
* //在查询视图的事件中获取该类
* var view = this.target;
* @example
* //在查询视图的条目中,操作条组件中,分页事件中获取该类
* var view = this.target.view;
* @example
* //调用api进行提示
* this.querystatement.notice("this is my information", "info");
* */
mwf.xapplication.query.query.statement = mwf.qstatement = new class(
/** @lends mwf.xapplication.query.query.statement# */
{
extends: mwf.qviewer,
options: {
"lazy": false,
/**
* @ignore
* @event mwf.xapplication.query.query.statement#queryloadcategoryrow
*/
/**
* @ignore
* @event mwf.xapplication.query.query.statement#postloadcategoryrow
*/
/**
* 导出查询excel的事件,这个时候导出数据已经准备好,this.target可获得查询视图对象。this.event如下:
* {
* data : data, //对象数组,导出的数据,第一个数组为标题。修改后导出的excel内容也会修改。
* colwidtharray : colwidtharr, //数组,每列的宽度
* title : excelname //字符串,导出的文件名
* }
* @event mwf.xapplication.query.query.statement#export
*/
/**
* 导出查询excel,产生每行后执行的事件,this.target可获得查询视图对象,可以通过this.event获取下列内容
* {
* data : data, //对象,当前行导出的数据。修改后导出的excel内容也会修改。
* index : 1, //数字,导出的行号,从1开始
* source : source //对象,从后台获取的源数据
* }
* @event mwf.xapplication.query.query.statement#exportrow
*/
"moduleevents": ["queryload", "postload", "postloadpagedata", "postloadpage", "selectrow", "unselectrow",
"queryloaditemrow", "postloaditemrow", "queryloadcategoryrow", "postloadcategoryrow", "export", "exportrow"]
},
initialize: function (container, json, options, app, parentmacro) {
//本类有三种事件,
//一种是通过 options 传进来的事件,包括 loadview、opendocument、select、unselect
//一种是用户配置的 事件, 在this.options.moduleevents 中定义的作为类事件
//还有一种也是用户配置的事件,不在this.options.moduleevents 中定义的作为 this.node 的dom事件
this.setoptions(options);
this.path = "../x_component_query_query/$viewer/";
this.csspath = "../x_component_query_query/$viewer/" this.options.style "/css.wcss";
this._loadcss();
this.lp = mwf.xapplication.query.query.lp;
this.app = app;
this.container = $(container);
this.json = json || {};
this.parentmacro = parentmacro;
this.originaljson = object.clone(json);
this.viewjson = null;
this.filteritems = [];
this.searchstatus = "none"; //none, custom, default
this.items = [];
this.selecteditems = [];
this.hidecolumns = [];
this.opencolumns = [];
this.parameter = {};
this.gridjson = null;
if (this.options.isload) {
this.init(function () {
this.load();
}.bind(this));
}
},
init: function (callback) {
if (this.json.view && this.json.format) {
this.viewjson = json.decode(this.json.view);
this.statementjson = this.json;
this.statementjson.viewjson = this.viewjson;
if (callback) callback();
} else {
this.getview(callback);
}
},
loadmacro: function (callback) {
mwf.require("mwf.xscript.macro", function () {
this.macro = new mwf.macro.viewcontext(this);
if (callback) callback();
}.bind(this));
},
createactionbarnode: function () {
this.actionbarareanode.empty();
if (typeof(this.json.showactionbar) === "boolean" && this.json.showactionbar !== true) return;
if (typeof(this.viewjson.actionbarhidden) === "boolean") {
if (this.viewjson.actionbarhidden === true || !this.viewjson.actionbarlist || !this.viewjson.actionbarlist.length) return;
this.actionbar = new mwf.xapplication.query.query.statement.actionbar(this.actionbarareanode, this.viewjson.actionbarlist[0], this, {});
this.actionbar.load();
}
},
_loadpagenode: function () {
this.viewpageareanode.empty();
if( this.viewjson.pagingbarhidden === true ){
return;
}
if (!this.paging) {
var json;
if (!this.viewjson.paginglist || !this.viewjson.paginglist.length) {
json = {
"firstpagetext": this.lp.firstpage,
"lastpagetext": this.lp.lastpage
};
} else {
json = this.viewjson.paginglist[0];
// var jsonstr = json.stringify(json);
// jsonstr = o2.bindjson(jsonstr, {"lp": mwf.xapplication.query.query.lp.form});
// json = json.parse(jsonstr);
}
this.paging = new mwf.xapplication.query.query.statement.paging(this.viewpageareanode, json, this, {});
this.paging.load();
} else {
this.paging.reload();
}
},
// _initpage: function(){
// var i = this.count/this.json.pagesize;
// this.pages = (i.toint() 0 ){
value = this.parseparametervalue(configs[0], value);
}else{
if (typeof(value) === "date") {
if( ["sql", "sqlscript"].contains(this.statementjson.format) ){
value = value.format("db");
}else{
value = "{ts '" value.format("db") "'}"
}
}
}
this.parameter[p] = value;
}
},
parseparametervalue: function( f, value ){
// var user = layout.user;
if (typeof(value) === "date") {
value = value.format("db");
}
switch (value) {
case "@person":
// value = user.distinguishedname;
value = "";
break;
case "@identitylist":
// value = user.identitylist.map(function (d) {
// return d.distinguishedname;
// });
value = "";
break;
case "@unitlist":
// o2.actions.load("x_organization_assemble_express").unitaction.listwithperson({"personlist": [user.distinguishedname]}, function (json) {
// value = json.unitlist;
// }, null, false);
value = "";
break;
case "@unitalllist":
// o2.actions.load("x_organization_assemble_express").unitaction.listwithidentitysupnested({"personlist": [user.distinguishedname]}, function (json) {
// value = json.unitlist;
// }, null, false);
value = "";
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( !["sql", "sqlscript"].contains(this.statementjson.format) ) {
if( typeof(value) === "string" && value.substr(0, 1) !== "{" ){
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;
},
loadcurrentpagedata: function (callback, async, type) {
//是否需要在翻页的时候清空之前的items ?
debugger;
if (this.pageloading) return;
this.pageloading = true;
if( this.io ){
this.items.each(function(item){
this.io.unobserve(item.node);
}.bind(this))
}
this.items = [];
var p = this.currentpage;
var d = {
"filterlist": this.filterlist,
"parameter": this.parameter
};
while (this.viewtable.rows.length > 1) {
this.viewtable.deleterow(-1);
}
if( this.viewtable.rows.length>0 && !this.viewtable.rows[0].hasclass("viewtitleline") ){
this.viewtable.deleterow(0);
}
this.contentareanode.scrollto(0, 0);
//this.createloadding();
this.fireevent("beforeloadpagedata", [d])
this.loadviewres = o2.actions.load("x_query_assemble_surface").statementaction.executev2(
this.options.statementid || this.options.statementname || this.options.statementalias ||
this.json.statementid || this.json.statementname || this.json.statementalias,
type || "data", p, this.json.pagesize, d, function (json) {
if (type === "all" || type === "count") {
if (typeof(json.count) === "number") {
this.count = json.count;
var i = this.count / this.json.pagesize;
this.pages = (i.toint() < i) ? i.toint() 1 : i;
}
}
this.gridjson = json.data;
this.setselectedableflag();
this.fireevent("postloadpagedata");
// if (this.viewjson.group.column){
// this.gridjson = json.data.groupgrid;
// }else{
// this.gridjson = json.data.grid;
this.loaddata();
// }
if (this.gridjson.length) this._loadpagenode();
if (this.loadingareanode) {
this.loadingareanode.destroy();
this.loadingareanode = null;
}
this.pageloading = false;
this.fireevent("loadview"); //options 传入的事件
this.fireevent("postloadpage");
if (callback) callback(json);
}.bind(this), null, async === false ? false : true);
},
getview: function (callback) {
this.getviewres = o2.actions.load("x_query_assemble_surface").statementaction.get(
this.json.statementid || this.json.statementname || this.json.statementalias,
function (json) {
var viewdata = json.decode(json.data.view);
if (!this.json.pagesize) this.json.pagesize = viewdata.pagesize || "20";
this.viewjson = viewdata.data;
this.json.application = json.data.query;
//this.json = object.merge(this.json, json.data);
this.statementjson = json.data;
this.statementjson.viewjson = this.viewjson;
if (callback) callback();
}.bind(this)
);
},
loaddata: function () {
if (this.getselectflag() === "multi" && this.viewjson.allowselectall) {
if (this.selecttitlecell && this.selecttitlecell.retrieve("selectallloaded")) {
this.setunselectallstyle();
} else {
this.createselectallnode();
}
} else if (this.selectallnode) {
this.clearselectallstyle();
}
if (this.gridjson.length) {
// if( !this.options.paging ){
this.gridjson.each(function (line, i) {
this.items.push(new mwf.xapplication.query.query.statement.item(this, line, null, i, null, this.options.lazy));
}.bind(this));
// }else{
// this.loadpaging();
// }
} else {
if (this.viewpageareanode) this.viewpageareanode.empty();
}
},
loaddatabypaging: function () {
if (this.isitemsloading) return;
if (!this.isitemsloaded) {
var from = math.min(this.pagenumber * this.options.perpagecount, this.gridjson.length);
var to = math.min((this.pagenumber 1) * this.options.perpagecount 1, this.gridjson.length);
this.isitemsloading = true;
for (var i = from; i < to; i ) {
this.items.push(new mwf.xapplication.query.query.statement.item(this, this.gridjson[i], null, i, null, this.options.lazy));
}
this.isitemsloading = false;
this.pagenumber ;
if (to == this.gridjson.length) this.isitemsloaded = true;
}
},
getfilter: function () {
var filterdata = [];
if (this.searchstatus === "custom") {
if (this.filteritems.length) {
this.filteritems.each(function (filter) {
if( !filter.data.logic )filter.data.logic = "and";
filterdata.push(filter.data);
}.bind(this));
}
}
if (this.searchstatus === "default") {
var key = this.viewsearchinputnode.get("value");
if (key && key !== this.lp.searchkeywork) {
this.viewjson.customfilterlist.each(function (entry) {
if (entry.formattype === "textvalue") {
var d = {
"path": entry.path,
"value": key,
"formattype": entry.formattype,
"logic": "or",
"comparison": "like"
};
filterdata.push(d);
}
if (entry.formattype === "numbervalue") {
var v = key.tofloat();
if (!isnan(v)) {
var d = {
"path": entry.path,
"value": v,
"formattype": entry.formattype,
"logic": "or",
"comparison": "like"
};
filterdata.push(d);
}
}
}.bind(this));
}
}
return (filterdata.length) ? filterdata : null;
},
viewsearchcustomaddtofilter: function () {
var pathidx = this.viewsearchcustompathlistnode.selectedindex;
var comparisonidx = this.viewsearchcustomcomparisonlistnode.selectedindex;
if (pathidx === -1) {
mwf.xdesktop.notice("error", {
"x": "left",
"y": "top"
}, this.lp.filtererrortitle, this.viewsearchcustompathlistnode, {"x": 0, "y": 85});
return false;
}
if (comparisonidx === -1) {
mwf.xdesktop.notice("error", {
"x": "left",
"y": "top"
}, this.lp.filtererrorcomparison, this.viewsearchcustomcomparisonlistnode, {"x": 0, "y": 85});
return false;
}
var pathoption = this.viewsearchcustompathlistnode.options[pathidx];
var entry = pathoption.retrieve("entry");
if (entry) {
var pathtitle = entry.title;
var path = entry.path;
var comparison = this.viewsearchcustomcomparisonlistnode.options[comparisonidx].get("value");
var comparisontitle = this.viewsearchcustomcomparisonlistnode.options[comparisonidx].get("text");
var value = "";
if (entry.valuetype === "script" && entry.valuescript && entry.valuescript.code) {
var idx = this.viewsearchcustomvaluenode.selectedindex;
if (idx !== -1) {
var v = this.viewsearchcustomvaluenode.options[idx].get("value");
value = entry.formattype === "booleanvalue" ? (v === "true") : v;
}
} else {
switch (entry.formattype) {
case "numbervalue":
value = this.viewsearchcustomvaluenode.get("value");
break;
case "datetimevalue":
value = this.viewsearchcustomvaluenode.get("value");
break;
case "booleanvalue":
var idx = this.viewsearchcustomvaluenode.selectedindex;
if (idx !== -1) {
var v = this.viewsearchcustomvaluenode.options[idx].get("value");
value = (v === "true");
}
break;
default:
value = this.viewsearchcustomvaluenode.get("value");
}
}
if (value === "") {
mwf.xdesktop.notice("error", {
"x": "left",
"y": "top"
}, this.lp.filtererrorvalue, this.viewsearchcustomvaluecontentnode, {"x": 0, "y": 85});
return false;
}
this.filteritems.push(new mwf.xapplication.query.query.statement.filter(this, {
"logic": "and",
"path": path,
"title": pathtitle,
"comparison": comparison,
"comparisontitle": comparisontitle,
"value": value,
"formattype": (entry.formattype == "datetimevalue") ? "datetimevalue" : entry.formattype
}, this.viewsearchcustomfiltercontentnode));
this.searchcustomview();
}
},
searchview: function(){
debugger;
if (this.viewjson.customfilterlist) {
var key = this.viewsearchinputnode.get("value");
if (key && key !== this.lp.searchkeywork) {
var filterdata = [];
this.filteritems = [];
this.viewjson.customfilterlist.each(function (entry) {
if (entry.formattype === "textvalue") {
var d = {
"path": entry.path,
"value": key,
"formattype": entry.formattype,
"logic": "or",
"comparison": "like"
};
filterdata.push(d);
this.filteritems.push({"data":d});
}
if (entry.formattype === "numbervalue") {
var v = key.tofloat();
if (!isnan(v)) {
var d = {
"path": entry.path,
"value": v,
"formattype": entry.formattype,
"logic": "or",
"comparison": "equals"
};
filterdata.push(d);
this.filteritems.push({"data":d});
}
}
}.bind(this));
if( this.json.filter ){
this.json.filter.clone().each(function(f){
filterdata.push(f);
})
}
this.createviewnode({"filterlist": filterdata});
}else{
this.filteritems = [];
var filterdata = this.json.filter ? this.json.filter.clone() : [];
this.createviewnode( {"filterlist": filterdata} );
}
}
},
//搜索相关结束
/**
* @method mwf.xapplication.query.query.statement#getparentenvironment
* @summary 如果当前视图是嵌入在表单或者页面中,使用该方法获取表单或页面的上下文。
* @see {@link module:querystatement.getparentenvironment|详情查看 this.querystatement.getparentenvironment}
* @return {object}
* @example
* this.target.getparentenvironment();
*/
/**
* @method mwf.xapplication.query.query.statement#getpagedata
* @summary 获取当前页的数据。
* @see {@link module:querystatement.getpagedata|详情查看 this.querystatement.getpagedata}
* @return {object}
* @example
* this.target.getpagedata();
*/
/**
* @method mwf.xapplication.query.query.statement#topage
* @summary 跳转到指定的页面。
* @see {@link module:querystatement.topage|详情查看 this.querystatement.topage}
* @param {number} pagenumber 需要跳转的页码
* @param {function} callback 跳转的页面数据加载完成以后的回调方法。
* @example
* // 跳转到第2页并且获取该页的数据。
* this.target.topage( 2, function(){
* var data = this.target.getpagedata();
* }.bind(this) )
*/
/**
* @method mwf.xapplication.query.query.statement#getselecteddata
* @summary获取选中的条目的数据。
* @see {@link module:querystatement.getselecteddata|详情查看 this.querystatement.getselecteddata}
* @static
* @return {object[]} 选中的条目的数据。
* @o2syntax
* var data = this.target.getselecteddata();
*/
/**
* @method mwf.xapplication.query.query.statement#switchview
* @ignore
*/
/**
* @method mwf.xapplication.query.query.statement#getviewinfor
* @ignore
*/
/**
* @summary 获取视查询图的配置信息。
* @see {@link module:querystatement.getstatementinfor|详情查看 this.querystatement.getstatementinfor}
* @return {object}
* @example
* this.target.getstatementinfor();
*/
getstatementinfor: function () {
return this.statementjson;
},
/**
* @summary 获取视图当前页的基本信息。
* @see {@link module:querystatement.getpageinfor|详情查看 this.querystatement.getpageinfor}
* @return {object}
* @example
* this.target.getpageinfor();
*/
getpageinfor: function () {
return {
pages: this.pages,
perpagecount: this.json.pagesize,
currentpagenumber: this.currentpage
};
},
/**
* @summary 把当前视图切换成另外一个视图。
* @see {@link module:querystatement.switchstatement|详情查看 this.querystatement.switchstatement}
* @param {object} json 需要跳转的参数配置
*/
switchstatement: function (json) {
this.switchview(json);
},
/**
* @summary 设置查询视图的过滤条件,该方法不能修改视图中默认的过滤条件(在开发视图的时候添加的过滤条件),而是在这上面新增。
* @see {@link module:querystatement.setstatementfilter|详情查看 this.querystatement.setstatementfilter}
* @param {(viewfilter[]|viewfilter|null)} [filter] 过滤条件
* @param {statementparameter} [parameter] 过滤条件。
* @param {function} callback 过滤完成并重新加载数据后的回调方法。
*/
setfilter: function (filter, parameter, callback) {
if (this.lookuping || this.pageloading) return;
if (!filter) filter = [];
if (!parameter) parameter = {};
this.json.filter = filter;
this.json.parameter = parameter;
if (this.viewareanode) {
this.createviewnode({"filterlist": this.json.filter.clone()}, callback);
}
},
getexporttotalcount: function(){
return this.count || 100000;
},
// getexportmaxcount: function(){
// return 2000;
// },
exportview: function(){
var _self = this;
var total = this.getexporttotalcount();
var lp = this.lp.viewexport;
var node = this.exportexceldlgnode = new element("div");
var html = "" lp.filename ":"
" "
"
";
html = "" lp.exportrange ":"
" " lp.to ""
" " lp.item ""
"
";
html = "" ( lp.description.replace("{count}", total )) "
";
node.set("html", html);
var check = function () {
if(this.value.length == 1){
this.value = this.value.replace(/[^1-9]/g,'');
}else{
this.value = this.value.replace(/\d/g,'');
}
if( this.value.toint() > total ){
this.value = total;
}
}
node.getelement(".start").addevent( "keyup", function(){ check.call(this) } );
node.getelement(".end").addevent( "keyup", function(){ check.call(this) } );
var dlg = o2.dl.open({
"title": this.lp.exportexcel,
"style": "user",
"isresize": false,
"content": node,
"width": 600,
"height" : 260,
"buttonlist": [
{
"type": "ok",
"text": mwf.lp.process.button.ok,
"action": function (d, e) {
var start = node.getelement(".start").get("value");
var end = node.getelement(".end").get("value");
var filename = node.getelement(".filename").get("value");
if( !start || !end ){
mwf.xdesktop.notice("error", {"x": "left", "y": "top"}, lp.inputintegernotice, node, {"x": 0, "y": 85});
return false;
}
start = math.max(start.toint(), 1);
end = end.toint();
if( end < start ){
mwf.xdesktop.notice("error", {"x": "left", "y": "top"}, lp.startlargetthanendnotice, node, {"x": 0, "y": 85});
return false;
}
debugger;
this.exportexcelstart = start;
this.exportexcelend = end;
this._exportview(start, end, filename);
dlg.close();
}.bind(this)
},
{
"type": "cancel",
"text": mwf.lp.process.button.cancel,
"action": function () { dlg.close(); }
}
]
});
},
// exportview: function(){
// var excelname = this.statementjson.name;
//
// var p = this.currentpage;
// var d = {
// "filterlist": this.filterlist,
// "parameter": this.parameter
// };
//
// this.createloadding();
//
// debugger;
//
// var exportarray = [];
//
// var titlearray = [];
// var colwidtharr = [];
// var dateindexarray = [];
// var numberindexarray = [];
// var idx = 0;
// object.each(this.entries, function (c, k) {
// if (this.hidecolumns.indexof(k) === -1 && c.exportenable !== false) {
// titlearray.push(c.displayname);
// colwidtharr.push(c.exportwidth || 200);
// if( c.istime )dateindexarray.push(idx);
// if( c.isnumber )numberindexarray.push(idx);
// idx ;
// }
// }.bind(this));
// exportarray.push(titlearray);
//
// o2.actions.load("x_query_assemble_surface").statementaction.executev2(
// this.options.statementid || this.options.statementname || this.options.statementalias ||
// this.json.statementid || this.json.statementname || this.json.statementalias,
// "data", 1, 100000, d, function (json) {
//
// json.data.each(function (d, i) {
// var dataarray = [];
// object.each(this.entries, function (c, k) {
// if (this.hidecolumns.indexof(k) === -1 && c.exportenable !== false) {
// var text = this.getexporttext(c, k, d);
// // if( c.isnumber && typeof(text) === "string" && (parsefloat(text).tostring() !== "nan") ){
// // text = parsefloat(text);
// // }
// dataarray.push( text );
// }
// }.bind(this));
// //exportrow事件
// var argu = {"index":i, "source": d, "data":dataarray};
// this.fireevent("exportrow", [argu]);
// exportarray.push( argu.data || dataarray );
// }.bind(this));
//
// //export事件
// var arg = {
// data : exportarray,
// colwidtharray : colwidtharr,
// title : excelname
// };
// this.fireevent("export", [arg]);
//
// if (this.loadingareanode) {
// this.loadingareanode.destroy();
// this.loadingareanode = null;
// }
//
// new mwf.xapplication.query.query.statement.excelutils().exporttoexcel(
// arg.data || exportarray,
// arg.title || excelname,
// arg.colwidtharray || colwidtharr,
// dateindexarray, //日期格式列下标
// numberindexarray //数字格式列下标
// );
//
// }.bind(this));
// },
_exportview: function(start, end, filename){
var excelname = filename || this.statementjson.name;
var p = this.currentpage;
var d = {
"filterlist": this.filterlist,
"parameter": this.parameter
};
this.createloadding();
var exportarray = [];
var titlearray = [];
var colwidtharr = [];
var dateindexarray = [];
var numberindexarray = [];
var idx = 0;
object.each(this.entries, function (c, k) {
if (this.hidecolumns.indexof(k) === -1 && c.exportenable !== false) {
titlearray.push(c.displayname);
colwidtharr.push(c.exportwidth || 200);
if( c.istime )dateindexarray.push(idx);
if( c.isnumber )numberindexarray.push(idx);
idx ;
}
}.bind(this));
exportarray.push(titlearray);
this.loadexportdata(start, end, d, function (datalist) {
var index = 0;
datalist.each(function (data, j) {
data.each(function (d, i) {
index = index 1;
var dataarray = [];
object.each(this.entries, function (c, k) {
if (this.hidecolumns.indexof(k) === -1 && c.exportenable !== false) {
var text = this.getexporttext(c, k, d);
// if( c.isnumber && typeof(text) === "string" && (parsefloat(text).tostring() !== "nan") ){
// text = parsefloat(text);
// }
dataarray.push( text );
}
}.bind(this));
//exportrow事件
var argu = {"index":index, "source": d, "data":dataarray};
this.fireevent("exportrow", [argu]);
exportarray.push( argu.data || dataarray );
}.bind(this));
}.bind(this));
//export事件
var arg = {
data : exportarray,
colwidtharray : colwidtharr,
title : excelname
};
this.fireevent("export", [arg]);
if (this.loadingareanode) {
this.loadingareanode.destroy();
this.loadingareanode = null;
}
new mwf.xapplication.query.query.statement.excelutils().exporttoexcel(
arg.data || exportarray,
arg.title || excelname,
arg.colwidtharray || colwidtharr,
dateindexarray, //日期格式列下标
numberindexarray //数字格式列下标
);
}.bind(this))
},
loadexportdata: function(start, end, body, callback){
start = start - 1;
var differ = end - start;
var count;
// if( differ < 10 ){
// count = 10;
// }else if( differ < 100 ){
// count = 100;
// }else if( differ < 1000 ){
// count = 1000;
// }else{
// count = 10000; bai boi bai boy buy boy
// }
if( differ < 10000 ){
count = differ;
}else{
count = 10000;
}
var page = math.floor( start / count ) 1;
var startindex = start % count;
var endindex = end % count;
var loaded = (page - 1)*count;
var list = [];
do{
var promise = o2.actions.load("x_query_assemble_surface").statementaction.executev2(
this.options.statementid || this.options.statementname || this.options.statementalias ||
this.json.statementid || this.json.statementname || this.json.statementalias,
"data", page, count, body);
list.push(promise);
loaded = loaded count;
page = page 1;
}while( end > loaded );
var result = [];
promise.all( list ).then(function (arr) {
arr.each(function (json, i) {
var data = json.data;
var length = json.data.length;
if( i === 0 && i === list.length - 1 ){
data.splice( 0, startindex );
if( length > endindex && endindex > 0 ){
data.splice( endindex - startindex , length - endindex );
}
}else if( i === 0 ){
data.splice( 0, startindex );
}else if( i=== list.length - 1 ){
if( length > endindex && endindex > 0 )data.splice( endindex, length - endindex );
}
result.push(data);
});
if( callback )callback(result);
});
},
getdatabypath: function (obj, path) {
var pathlist = path.split(".");
for (var i = 0; i < pathlist.length; i ) {
var p = pathlist[i];
if ((/(^[1-9]\d*$)/.test(p))) p = p.toint();
if (obj[p]) {
obj = obj[p];
} else if(obj[p] === undefined || obj[p] === null) {
obj = "";
break;
} else {
obj = obj[p];
break;
}
}
return obj
},
getexporttext: function (c, k, data) {
var path = c.path, code = c.code, obj = data;
if (!path) {
return ""
} else if (path === "$all") {
} else {
obj = this.getdatabypath(obj, path);
}
try{
if (code && code.trim()) obj = this.macro.exec(code, {
"value": obj,
"data": data,
"entry": c,
"json": c
});
}catch (e) {}
var toname = function (value) {
if (typeof(value) === "array") {
array.each(value, function (v, idx) {
value[idx] = toname(v)
})
} else if (typeof(value) === "object") {
object.each(value, function (v, key) {
value[key] = toname(v);
})
} else if (typeof(value) === "string") {
value = o2.name.cn(value)
}
return value;
};
var d;
if (obj != undefined && obj != null) {
if (typeof(obj) === "array") {
d = c.isname ? json.stringify(toname(array.clone(obj))) : json.stringify(obj);
} else if (typeof(obj) === "object") {
d = c.isname ? json.stringify(toname(object.clone(obj))) : json.stringify(obj);
} else {
d = c.isname ? o2.name.cn(obj.tostring()) : obj;
}
}
return d;
}
});
/** @classdesc statementitem 数据中心的查询视图的条目。本章节的脚本上下文请看{@link module:querystatement|querystatement}。
* @class
* @extends mwf.xapplication.query.query.viewer.item
* @o2cn 查询视图的条目(行)
* @o2category querystatement
* @o2range {querystatement}
* @hideconstructor
* @example
* //在查询视图中获取行
* var item = this.target.items[0];
*/
mwf.xapplication.query.query.statement.item = new class(
/** @lends mwf.xapplication.query.query.statement.item# */
{
extends: mwf.xapplication.query.query.viewer.item,
initialize: function (view, data, prev, i, category, lazy) {
this.view = view;
this.data = data;
this.datastring = json.stringify(data);
this.css = this.view.css;
this.isselected = false;
/**
* @ignore
*/
this.category = category;
this.prev = prev;
this.idx = i;
this.clazztype = "item";
this.lazy = lazy;
this.load();
},
_load: function () {
this.loading = true;
if(!this.node)this.view.fireevent("queryloaditemrow", [null, this]);
var viewstyles = this.view.viewjson.viewstyles;
var viewcontenttdnode = (viewstyles && viewstyles["contenttd"]) ? viewstyles["contenttd"] : this.css.viewcontenttdnode;
if(!this.node)this.loadnode();
//if (this.view.json.select==="single" || this.view.json.select==="multi"){
this.selecttd = new element("td", {"styles": viewcontenttdnode}).inject(this.node);
this.selecttd.setstyles({"cursor": "pointer"});
if (this.view.json.itemstyles) this.selecttd.setstyles(this.view.json.itemstyles);
//var selectflag = this.view.json.select || this.view.viewjson.select || "none";
var selectflag = this.view.getselectflag();
if (this.data.$selectedenable && ["multi", "single"].contains(selectflag) && this.view.viewjson.selectboxshow === "always") {
var viewstyles = this.view.viewjson.viewstyles;
if (viewstyles) {
if (selectflag === "single") {
this.selecttd.setstyles(viewstyles["radionode"]);
} else {
this.selecttd.setstyles(viewstyles["checkboxnode"]);
}
} else {
var iconname = "checkbox";
if (selectflag === "single") iconname = "radiobox";
this.selecttd.setstyles({"background": " center center no-repeat"});
}
}
if (this.view.isselecttdhidden()) {
this.selecttd.hide();
}
//}
//序号
var sequence = 1 this.view.json.pagesize * (this.view.currentpage - 1) this.idx;
this.data["$sequence"] = sequence;
if (this.view.viewjson.issequence === "yes") {
this.sequencetd = new element("td", {"styles": viewcontenttdnode}).inject(this.node);
this.sequencetd.setstyles({
"width": "30px",
"text-align": "center"
});
this.sequencetd.set("text", sequence);
}
object.each(this.view.entries, function (c, k) {
//if (cell){
if (this.view.hidecolumns.indexof(k) === -1) {
var td = new element("td", {"styles": viewcontenttdnode}).inject(this.node);
var cell = this.gettext(c, k, td); //this.data[k];
if (cell === undefined || cell === null) cell = "";
// if (k!== this.view.viewjson.group.column){
var v = cell;
if (c.ishtml) {
td.set("html", v);
} else {
td.set("text", v);
}
if (typeof(c.contentproperties) === "object") td.setproperties(c.contentproperties);
if (this.view.json.itemstyles) td.setstyles(this.view.json.itemstyles);
if (typeof(c.contentstyles) === "object") td.setstyles(c.contentstyles);
// }else{
// if (this.view.json.itemstyles) td.setstyles(this.view.json.itemstyles);
// }
if (this.view.opencolumns.indexof(k) !== -1) {
this.setopenwork(td, c)
}
// if (k!== this.view.viewjson.group.column){
object.each(c.events || {}, function (e, key) {
if (e.code) {
if (key === "loadcontent") {
this.view.macro.fire(e.code,
{"node": td, "json": c, "data": v, "view": this.view, "row": this});
} else if (key !== "loadtitle") {
td.addevent(key, function (event) {
return this.view.macro.fire(
e.code,
{"node": td, "json": c, "data": v, "view": this.view, "row": this},
event
);
}.bind(this));
}
}
}.bind(this));
// }
}
//}
}.bind(this));
if(this.placeholdertd){
this.placeholdertd.destroy();
this.placeholdertd = null;
}
//默认选中
var selectedflag;
var defaultselectedscript = this.view.json.defaultselectedscript || this.view.viewjson.defaultselectedscript;
if (!this.isselected && defaultselectedscript) {
// var flag = this.view.json.select || this.view.viewjson.select || "none";
// if ( flag ==="single" || flag==="multi"){
//
// }
selectedflag = this.view.macro.exec(defaultselectedscript,
{"node": this.node, "data": this.data, "view": this.view, "row": this});
}
//判断是不是在selecteditems中,用户手工选择
if (!this.isselected && this.view.selecteditems.length) {
for (var i = 0; i < this.view.selecteditems.length; i ) {
if (this.view.selecteditems[i].datastring === this.datastring) {
selectedflag = "true";
break;
}
}
}
if (selectedflag) {
if (selectedflag === "multi" || selectedflag === "single") {
this.select(selectedflag);
} else if (selectedflag.tostring() === "true") {
var f = this.view.json.select || this.view.viewjson.select || "none";
if (f === "single" || f === "multi") {
this.select();
}
}
}
this.setevent();
this.view.fireevent("postloaditemrow", [null, this]);
this.loading = false;
this.loaded = true;
},
selected: function( from ){
for(var i=0; i