ext.datagrid.js
来自「anewssystem新闻发布系统集成使用了spring hibernate f」· JavaScript 代码 · 共 678 行 · 第 1/2 页
JS
678 行
var datagrids = new Array(), comboboxArray = new Array(), nowDate = new Date(), nowFormateDate = nowDate.dateFormat("Y年m月d日");
Ext.DataGrid = function(config) {
var cfg = config;
this.dlg;
this.dlgTitle = config.dlgTitle == undefined ? "" : config.dlgTitle;
this.dlgDiv = cfg.gridDiv + "-dlg";
this.tabs;
this.dlgContentDiv = cfg.dlgContentDiv;
this.dlgWidth = cfg.dlgWidth;
this.dlgHeight = cfg.dlgHeight;
this.yesBtn;
this.noBtn;
this.gridDiv = cfg.gridDiv;
this.paging = cfg.paging;
this.pageInfo = cfg.pageInfo;
this.pageSize = cfg.pageSize;
this.grid;
this.dataModel;
this.colModel;
this.defaultSort;
this.header;
this.column = new Array();
this.fields;
this.initPaging = !cfg.initPaging ? true : cfg.initPaging;
this.exec = eval(cfg.exec);
this.url = setSitePath("./sandbox/listMenu.htm");
this.rowid = cfg.gridDiv + "_rowid";
this.colClick = false;
this.row;
this.checkList = new Array();
this.params;
this.datagrids;
this.dialogActivate;
if(!this.editor) {
Ext.DataGrid.superclass.constructor.call(this);
}
};
Ext.extend(Ext.DataGrid, Ext.DaoFactory, {
hideDlg : function(B) {
this.datagrids = datagrids.length;
datagrids[this.datagrids] = this;
for(var A = 0; A < datagrids.length; A++) {
if(datagrids[A].dlgDiv != this.dlgDiv || B) {
if(typeof datagrids[A].dlg == "object" && datagrids[A].dlg.isVisible()) {
datagrids[A].dlg.hide();
}
}
}
}, showDlg : function(tbBtn) {
var b = tbBtn.cls == "view" ? true : eval("this." + tbBtn.cls + "()");
if(b) {
if(!this.dlg) {
this.createDialog();
}
this.hideDlg();
this.tabs.getTab(0).setText(tbBtn.text + this.dlgTitle);
this.setDialog({
width : this.dlgWidth,
height : this.dlgHeight,
tbBtn : tbBtn
});
if(tbBtn.cls == "view") {
this.dlg.show(tbBtn.btnText);
if(!this.dialogActivate) {
this.yesBtn.hide();
this.tabs.getTab(0).on("activate", function() {
this.yesBtn.hide();
}, this, true);
}
} else {
this.dlg.show(tbBtn.getEl());
if(!this.dialogActivate) {
this.yesBtn.show();
this.tabs.getTab(0).on("activate", function() {
this.yesBtn.show();
}, this, true);
}
}
this.tabs.activate(0);
}
datagrids._obj = this;
}, createDlgContentDiv : function() {
var K = document.getElementById(this.dlgContentDiv), I = document.createElement("div");
I.id = this.gridDiv + "-content";
I.appendChild(K);
var A = document.createElement("div"), H = document.createElement("div"), J = document.createElement("div");
A.id = "dlg-msg";
H.id = "post-wait";
H.className = "posting-msg";
J.className = "waitting";
J.innerHTML = "正在保存,请稍候...";
H.appendChild(J);
A.appendChild(H);
var B = document.createElement("div"), C = document.createElement("div"), F = document.createElement("div"), D = document.createElement("div"), L = document.createElement("div"), E = document.createElement("div"), G = document.createElement("div");
B.id = this.dlgDiv;
B.style.visibility = "hidden";
C.className = "x-dlg-hd";
F.className = "x-dlg-bd";
G.className = "x-dlg-ft";
D.className = "x-dlg-tab";
L.className = "x-dlg-tab";
L.title=" 帮助 ";
E.innerHTML = "<div id='help-content'><div id='standard-panel'>帮助...</div></div><div id='temp-content'></div>";
L.appendChild(E);
F.appendChild(D);
F.appendChild(L);
G.appendChild(A);
B.appendChild(C);
B.appendChild(F);
B.appendChild(G);
document.body.appendChild(B);
document.body.appendChild(I);
datagrids._obj = this;
}, createDialog : function() {
if(this.editor) {
alert("error!\neditgrid不允许设置link属性!");
}
var A = this.dlgWidth, B = this.dlgHeight;
this.createDlgContentDiv();
this.dlg = new Ext.BasicDialog(this.dlgDiv, {
modal : false,
autoTabs : true,
width : (A == undefined ? 500 : A),
height : (B == undefined ? 300 : B),
shadow : false,
minWidth : 200,
minHeight : 100,
closable : true
});
this.dlg.addKeyListener(27, this.dlg.hide, this.dlg);
this.yesBtn = this.dlg.addButton("确定", function() {
}, this.dlg);
this.tabs = this.dlg.getTabs();
this.tabs.getTab(1).on("activate", function(){
this.yesBtn.hide();
}, this, true);
this.tabs.getTab(0).setContent();
var C = $(this.gridDiv + "-content");
this.tabs.getTab(0).setContent(C.innerHTML);
this.applyElements();
document.body.removeChild(C);
if(this.dialogActivate) {
this.dialogActivate.call(this);
}
this.noBtn = this.dlg.addButton("取消", this.dlg.hide, this.dlg);
}, applyElements : function(B) {
//var D = $(this.dlgContentDiv).getElementsByTagName("input"), G = $(this.dlgContentDiv).getElementsByTagName("textarea"), A = D.length + G.length;
var div = Ext.get(this.dlgContentDiv);
var D = div.query("input"), G = div.query("textarea"), A = D.length + G.length;
for(var C = 0; C < A; C++) {
var F, E = C < D.length ? D[C] : G[Math.abs(A - C - G.length)];
try {
var vType = E.getAttribute("vtype");
if(vType == "date") {
F = Forms.date(E);
} else if(vType == "textArea") {
F = Forms.textArea(E);
} else if(vType == "comboBox") {
F = Forms.comboBox(E);
} else if(vType == "treeField") {
F = Forms.treeField(E);
} else if(("text,hidden,password").indexOf(E.type) >= 0) {
F = Forms.input(E);
}
}catch(e) {
var buff = "";
for (var i in e) {
buff += i + "," + e[i] + "\n";
}
alert(buff);
}
this.column[this.column.length] = {
id : E.id,
type : E.type,
vType : E.getAttribute("vtype"),
allowBlank : E.getAttribute("allowblank"),
alt : E.alt,
format : E.getAttribute("format"),
obj : F
}
}
//alert(this.column.length);
}, checkValue : function() {
// 返回的结果,应该是result
var C = new Array();
// TODO:
var J = true;
// 遍历所有字段
var result = {};
for(i = 0; i < this.column.length; i++) {
// M是当前字段,currentField
var M = this.column[i];
//console.info(M);
//console.info(M.id);
// B是当前值,currentValue
var B = M.obj.getValue();
// K是是否通过验证,isValid
var K = Forms.validateField(M.obj, B);
// 如果没通过验证,就返回null
if(!K) {
M.obj.focus();
return null;
}
// 遇到下拉列表的时候,特殊处理
if(M.vType == "comboBox"){
// 当前字段的dom
var H = M.obj.el.dom;
// 取value
B = H.key;
// 如果是多选
if(H.multiple == "true") {
var D = B.split(",");
var I = M.obj.getText().split(",");
var F = "";
var G = "";
for(var A = 0; A < D.length; A++) {
var E = D[A].split("|"), L = A < D.length - 1 ? "," : "";
F += E[0] + L;
G += E[1] + L;
}
B = F + "|" + G;
}
C[i] = B;
} else if(M.vType == "date") {
C[i] = B == "" ? "" : B.dateFormat("Y-m-d");
result[M.id] = B == "" ? "" : B.dateFormat("Y-m-d");
} else {
C[i] = B;
result[M.id] = M.obj.getValue();
}
//var str = "result." + M.id + "=\'" + M.obj.getValue() + "\';";
//console.debug(str);
//eval(str);
}
//var buff = "";
//for (var i in result) {
// buff += i + "," + result[i] + " "
//}
//console.error(buff);
return result;
}, setDialog : function(A) {
this.yesBtn.cls = A.tbBtn.cls;
this.yesBtn.setText(A.tbBtn.btnText);
this.yesBtn.setHandler(function() {
this.save(A.tbBtn.cls)
}, this);
}, setValueofEmpty : function(A) {
if(A) {
for(i = 0; i < this.column.length; i++) {
var B = this.column[i];
if(B.vType == "date") {
if(B.obj.defValue != undefined) {
B.obj.setValue(B.obj.defValue);
} else {
B.obj.setValue(nowDate);
}
} else if(B.vType == "comboBox"){
if(B.obj.el.dom.allowBlank == "true") {
B.obj.setValue("");
B.obj.el.dom.key = "";
}
} else if(B.vType == "textArea") {
B.obj.setValue("");
} else if(("text,password").indexOf(B.type) >= 0) {
if(B.obj.defValue != undefined) {
B.obj.el.dom.value = B.obj.defValue;
}
} else {
B.obj.el.dom.value = "";
}
if(B.obj.disabled) {
B.obj.enable();
}
}
return true
}
}, setValue : function(G, E) {
var B;
if(G) {
B = this.dataModel.getAt(G);
} else {
var D = this.grid.selModel.getSelected;
if(D) {
B = this.dataModel.getAt(this.checkList[this.checkList.length - 1]);
B = B ? B : this.grid.selModel.getSelected();
} else {
B = this.grid.selModel.selection.record;
}
}
for(var A = 0; A < this.column.length; A++) {
var H = this.column[A], C = B.data[H.id] + "";
if(H.vType == "date") {
H.obj.setValue(this.date(C));
} else if(H.vType == "comboBox") {
var F = H.obj.el.dom;
if(C.indexOf("|")>=0) {
C = C.split("|");
C[1] = String.format(C[1], "|");
H.obj.setValue(C[1]);
F.key = C[0];
} else {
H.obj.setValue(C);
F.key = C;
}
if(C.length == 0) {
H.obj.setValue(H.obj.emptyText);
}
} else if(H.type == "password") {
H.obj.setValue("______");
} else if("text,hidden,textArea".indexOf(H.type) >= 0) {
if(C && C != "undefined") {
if(H.obj.getEl().dom.format == "date") {
C = this.date(C);
}
H.obj.setValue(C);
}
}
if(this.yesBtn && this.yesBtn.cls == "view" && !E) {
if(!H.obj.disabled) {
H.obj.disable();
}
} else if(H.obj.disabled) {
H.obj.enable();
}
}
}, getRowId : function() {
return $(this.rowid).value;
}, setRowId : function(A) {
$(this.rowid).value = A;
}, getSelectedId : function() {
var A = this.grid ? this.grid : this, B = A.selModel.getSelected(), C = "0";
if(B) {
C = objectEval(B.data["idno"]).id;
}
return C;
}, getSelectedColValueByName : function(C) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?