<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css" />
<script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="lib/ext/ext-all.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>通讯录</title>
</head>
<body>
<script language="javascript">
function showEmail(value){
return "<a href='mailto:" + value + "'>" + value + "</a>";
}
function showUrl(value){
return "<a href='" + value + "' target='_blank'>" + value + "</a>";
}
Ext.onReady(function(){
Ext.applyIf(Ext.form.VTypes , {
"telphone":function(_v){
return /(^\d{3}\-\d{7,8}$)|(^\d{4}\-\d{7,8}$)|(^\d{3}\d{7,8}$)|(^\d{4}\d{7,8}$)|(^\d{7,8}$)/.test(_v) ;
},
"telphoneText":"该输入项必须是电话号码格式,格式如:025-52356579,02552356579,52356579",
"telphoneMask":/[0-9\-]/i,
"mobile":function(_v){
return /^1[1-9][0-9]\d{8}$/.test(_v) ;
},
"mobileText":"该输入项必须是手机号码格式,格式如:13584087357",
"mobileMask":/[0-9]/i
}) ;
var store = new Ext.data.JsonStore({
//autoLoad: true,
url: "data.asp",
root: "results",
totalProperty: "total",
fields: ["id", "userName", "phone", "workEmail", "proEmail", "workQq", "proQq", "work", "homePhone", "homeAddress", "webUrl"]
});
var sm = new Ext.grid.CheckboxSelectionModel({
header: " ",
sortable: true,
width: 20
});
var colM = new Ext.grid.ColumnModel([sm, {
header: "ID",
dataIndex: "id",
sortable: true,
width: 30
}, {
header: "姓名",
dataIndex: "userName",
sortable: true,
width: 50
}, {
header: "手机",
dataIndex: "phone",
sortable: true,
width: 80
}, {
header: "办公邮箱",
dataIndex: "workEmail",
sortable: true,
renderer: showEmail,
width: 150
}, {
header: "私人邮箱",
dataIndex: "proEmail",
sortable: true,
renderer: showEmail,
width: 150
}, {
header: "工作QQ",
dataIndex: "workQq",
sortable: true,
width: 80
}, {
header: "私人QQ",
dataIndex: "proQq",
sortable: true,
width: 80
}, {
header: "家庭地址",
dataIndex: "homeAddress",
width: 200
}, {
header: "家庭电话",
dataIndex: "homePhone"
}, {
header: "工作单位",
dataIndex: "work"
}, {
header: "个人主页",
dataIndex:"webUrl",
renderer: showUrl
}]);
Ext.QuickTips.init();
var s_pannel = new Ext.FormPanel({
height: 20,
labelWidth: 70,
baseCls: "x-plain",
defaults: {
width: 150,
height: 10
},
defaultType: "textfield",
items: [{
fieldLabel: "请输入姓名",
id: "title",
name: "title",
allowBlank: false,//禁止为空
blankText: "搜索内容不能为空"
}]
});
var tb_text = new Ext.Toolbar.TextItem(" ");
var grid = new Ext.grid.GridPanel({
renderTo: "test",
title: "通讯录",
height: 625,
width: 999,
cm: colM,
loadMask: true,
store: store,
autoExpandColumn: 10,
tbar: [s_pannel,tb_text, {
xtype: "tbseparator"
}, {
text: " 搜索",
icon: "img/page_find.png",
cls: "x-btn-text-icon",
handler: function(){
store.load({
params: {
start: 0,
limit: 24,
title: Ext.get("title").dom.value
}
})
}
}, {
xtype: "tbseparator"
}, {
text: "添加",
icon: "img/chart_pie_add.png",
cls: "x-btn-text-icon",
handler: _add
}, {
xtype: "tbseparator"
}, {
text: "修改",
icon: "img/chart_pie_edit.png",
cls: "x-btn-text-icon",
handler: _edit
}, {
xtype: "tbseparator"
}, {
text: "删除",
icon: "img/chart_pie_delete.png",
cls: "x-btn-text-icon",
handler: _del
}],
bbar: new Ext.PagingToolbar({
pageSize: 24,
store: store,
displayInfo: true,
displayMsg: "当前 {0} 到 {1} 共 {2}",
emptyMsg: "没有数据返回",
items: null
})
});
function _add(){
Ext.form.Field.prototype.msgTarget = "side";
var window_form_add = new Ext.FormPanel({
id: "window_form_add",
name: "window_form_add",
labelWidth: 60,
labelAlign: "right",
baseCls: "x-plain",
bodyStyle: "padding:5px 5px 0",
width: 350,
frame: true,
defaults: {
width: 320,
height: 290
},
defaultType: "textfield",//默认字段类型
items: [{
xtype: "fieldset",
title: "联系信息",
defaults: {
xtype: "textfield",
width: 200
},
items: [{
name: "userName",
fieldLabel: "姓名",
allowBlank: false,
blankText: "姓名不能为空",
emptyText: "请输入您的姓名"
}, {
name: "phone",
fieldLabel: "手机号码",
allowBlank: false,
vtype: "mobile",
blankText: "手机号码不能为空",
emptyText: "请输入您的手机号码"
}, {
name: "workEmail",
fieldLabel: "办公邮箱",
vtype: "email",
emailText: "Email格式不正确"
}, {
name: "proEmail",
fieldLabel: "私人邮箱",
allowBlank: false,
blankText: "私人邮箱不能为空",
vtype: "email",
emailText: "Email格式不正确",
emptyText: "请输入您的邮箱"
}, {
name: "workQq",
fieldLabel: "工作QQ"
}, {
name: "proQq",
fieldLabel: "私人QQ",
allowBlank: false,
blankText: "私人QQ不能为空",
emptyText: "请输入您的QQ号码"
}, {
name: "work",
fieldLabel: "工作单位"
}, {
name: "homePhone",
fieldLabel: "家庭电话",
vtype: "telphone"
}, {
name: "homeAddress",
fieldLabel: "家庭地址"
}, {
name: "webUrl",
fieldLabel: "个人主页",
value: "http://"
}]
}],
buttons: [{
text: "确定",
handler: function(){
if (add_widow.getComponent("window_form_add").form.isValid()) {
add_widow.getComponent("window_form_add").form.submit({
waitTitle: "请稍候",
waitMsg: "正在提交数据,请稍候....",
url: "action.asp?action=add",
method: "POST",
success: function(form, action){
var Result = action.result.success;
if (Result == false) {
Ext.MessageBox.alert("提示", action.result.message);
}
else
if (Result == true) {
Ext.MessageBox.alert("提示", action.result.message);
add_widow.hide();
store.load({
params: {
start: 0,
limit: 24,
flag: true
}
});
}
},
failure: function(form, action){
Ext.MessageBox.alert("提示", "服务器请求错误,请稍后再试!");
}
})
}
}
}, {
text: "重置",
handler: function(){
window_form_add.form.reset();
}
}]
});
var add_widow = new Ext.Window({
title: "添加信息",
width: 350,
height: 370,
modal: true,
maximizable: true,
items: window_form_add
});
add_widow.show();
}
function _edit(){//显示选择行
var rows = grid.getSelectionModel().getSelections();
if(rows.length == 0){
Ext.Msg.alert("警告","请先选择需要修改的记录!");
return;
}
if (rows) {
for (var i = 0; i < rows.length; i++) {
Ext.form.Field.prototype.msgTarget = "side";
var window_form_edit = new Ext.FormPanel({
id: "window_form_edit",
name: "window_form_edit",
labelWidth: 60,
labelAlign: "right",
baseCls: "x-plain",
bodyStyle: "padding:5px 5px 0",
width: 350,
frame