crud数据库操作
Code
服务端代码 echo '{success:true,msg:"'ok"'}';
//取得多选框值
function getIds(gridInfo) {
var s = gridInfo.getSelectionModel().getSelections();
if (s.length==0) {
return null;
}
var ids = [];
for (i=0;i<s.length;i++) {
ids.push(s[i].id);
}
ids = ids.join(',');
return ids;
}
//取得单条记录值
function getId(gridInfo) {
var s = gridInfo.getSelectionModel().getSelected();
if (s) {
return s.id;
}
return 0;
}
//回复留言
function write () {
var id = getId(grid);
if (!id) {
Ext.Msg.alert('错误', '请选择一条留言回复!');
} else {
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var postForm = new Ext.FormPanel({
baseCls: 'x-plain',
labelWidth: 55,
labelAlign: 'top',
buttonAlign:'right',
bodyStyle : 'padding-top:5px',
defaultType: 'textfield',
defaultWidth: '175',
items: [{
fieldLabel: '回复内容',
xtype:'htmleditor',
id:'post_comment',
anchor: '100%'
}],
buttons: [{
xtype:'submit',
text:'回复',
//回复函数开始
handler:function () {
Ext.MessageBox.show({
msg: '正在保存,请稍等
',progressText: 'Saving
',width:300,
wait:true,
waitConfig: {interval:200},
icon:'download',
animEl: 'save'
});
setTimeout(function(){}, 10000);
postForm.form.doAction('submit',{
url:'index.php?controller=board&action=post&id='+id,
method:'post',
params:'',
success:function(form,action){
if (action.result.msg=='ok') {
Ext.MessageBox.hide();
Ext.Msg.alert('恭喜','留言回复成功');
ds.reload();
} else {
Ext.Msg.alert('错误',action.result.msg);
}
},
failure:function(){
Ext.Msg.alert('错误','服务器出现错误请稍后再试!');
}
});
}
//回复函数结束
}]
});
var postWindow = new Ext.Window({
title: '留言回复',
width: 600,
height:280,
collapsible:true,
maximizable:true,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
modal:true,
items: postForm
});
postWindow.show();
}
}
//删除留言
function del() {
var ids = getIds(grid);
if (ids) {
var dialog = Ext.Msg.show({
title:'删除留言', msg: '你确认要删除选定留言?',
icon:Ext.MessageBox.QUESTION, width:300,
fn:function(btn) {
if (btn =='ok') {
//删除开始
Ext.Ajax.request({
url: 'index.php?controller=board&action=del&ids='+ids,
success: function(result){
Ext.Msg.alert('操作成功','留言已成功删除');
ds.reload();
}
});
//删除结束
}
},
buttons:{
ok:'确定',cancel:'取消'
}
});
} else {
Ext.Msg.alert('错误','请至少选择一条留言删除!');
}
}
//发布留言
function newBoard () {
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var boardForm = new Ext.FormPanel({
baseCls: 'x-plain',
labelWidth: 55,
labelAlign: 'top',
buttonAlign:'right',
bodyStyle : 'padding-top:5px',
defaultType: 'textfield',
defaultWidth: '175',
items: [{
fieldLabel: '留言标题',
id:'board_title',
name:'board_title',
allowBlank:false,
blankText:'标题不能为空',
anchor: '60%'
},{
fieldLabel: '留言内容',
xtype:'htmleditor',
id:'board_comment',
anchor: '100%'
}],
buttons: [{
text:'发表',
//发布函数开始
handler:function(){
if(boardForm.form.isValid()){
Ext.MessageBox.show({
msg: '正在保存,请稍等
',progressText: 'Saving
',width:300,
wait:true,
waitConfig: {interval:200},
icon:'download',
animEl: 'saving'
});
setTimeout(function(){}, 10000);
boardForm.form.doAction('submit',{
url:'index.php?controller=board&action=insert',
method:'post',
params:'',
success:function(form,action){
if (action.result.msg=='ok') {
Ext.MessageBox.hide();
Ext.Msg.alert('恭喜','留言发布成功');
ds.reload();
} else {
Ext.Msg.alert('错误',action.result.msg);
}
},
failure:function(){
Ext.Msg.alert('错误','服务器出现错误请稍后再试!');
}
});
}
}
//发布函数结束
},{
text:'取消'
}]
});
var postWindow = new Ext.Window({
title: '发布留言',
width: 600,
height:330,
collapsible:true,
maximizable:true,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
modal:true,
items: boardForm
});
postWindow.show();
}
//查看留言
function view () {
var id = getId(grid);
if (id) {
var postWindow = new Ext.Window({
title: '查看留言',
width: 450,
height:330,
collapsible:true,
maximizable:true,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
modal:true,
html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src=index.php?controller=board&action=getone&id='+id+'></iframe>'
});
postWindow.show();
} else {
Ext.Msg.alert('错误', '请选择一条留言查看!');
}
}

浙公网安备 33010602011771号