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", "beforeLoadPageData", "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 ?
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.totalMap = {};
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;
this.totalMap = {};
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 = "