用Ext做的后台操作(包括,增,删,改,查)和一个异步加载的Ext树(2)

http://cam.taoke.alimama.com/event.php?pid=mm_10972871_0_0&eventid=100012
这里主要是后台的异步树上的一些Action.和一个FormPanle,代码挺全
由于工作时间的需要,没有太多的时间给大家写注释了,如果有什么不明白的话,可以给我评论,我会即使的回复...
function createField(fieldLabel, id, name1, value) {

var field = new Ext.form.TextField({
fieldLabel : fieldLabel,
width : 380,
itemCls : 'all-field',
clearCls : 'allow-float',
allowBlank : false,
name : name1,
value : value
});

return field;

}
function saveHandler(win, requestUrl, node, formPanel, isUpdate) {
/*
* Ext.MessageBox.show({ title:'请稍候', msg:'保存中,请稍后...', progress:true,
* buttons: {cancel:'取消'} });
*/

var form = formPanel.getForm();
form.submit({
url : requestUrl,
waitMsg : '保存中,请稍候...',
params : {},
success : function(response, request) {
if (!isUpdate) {
Ext.MessageBox.confirm("状态", "保存成功,继续添加吗?", function(btn) {
if (btn != 'yes') {
win.close();
}

});
} else {
Ext.MessageBox.alert('状态', '保存成功!');
win.close();
}

if (node.isLeaf()) {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
} else {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
}
},
failure : function() {
Ext.MessageBox.alert('状态', '保存失败!');
if (node.isLeaf()) {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
} else {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
}
}

});
}
// 修改form
function updateForm(node, id, title, win, requestUrl, value, isUpdate) {
var form0 = new Ext.FormPanel({
id : id,
labelWidth : 75, // label settings here cascade unless overridden
frame : true,
title : title,
bodyStyle : 'padding:5px 5px 0',
width : 350,
defaults : {
width : 230
}

});
var nameField = createField('章节名称', 'createItemText' + id + node.id,
'name', value);

form0.add(nameField);
form0.addButton({
text : '保存',
handler : function() {
saveHandler(win, requestUrl, node, form0, isUpdate);
}
});
return form0;
}
// 创建form
function createForm(node, id, title, win, requestUrl, value, isUpdate) {
var form0 = new Ext.FormPanel({
id : id,
labelWidth : 75, // label settings here cascade unless overridden
frame : true,
title : title,
bodyStyle : 'padding:5px 5px 0',
width : 500
// defaults : {
// width : 230
// }

});
var nameField = createField('章节名称', 'createItemText' + id + node.id,
'name', value);
var unitField = createField('组织名称', 'createItemText' + id + node.id,
'unit', value);
var areaField = new Ext.form.TextArea({
fieldLabel : '章节编辑',
// width:980,
// x:400,
// y:400,
// itemCls:'all-field',
// clearCls:'allow-float',
// allowBlank:true,
// style:"width:100px;height:60px;",
// autocomplete: "off",
// height:400,
height : 400,
width : 500,
grow : false,
name : 'sectionText'
});
form0.add(nameField);
form0.add(unitField);
form0.add(areaField);
form0.addButton({
text : '保存',
handler : function() {
saveHandler(win, requestUrl, node, form0, isUpdate);
}
});
return form0;
}
// 编辑form
function editorForm(node, id, title, win, requestUrl, value, isUpdate) {
var form0 = new Ext.FormPanel({
id : id,
labelWidth : 75, // label settings here cascade unless overridden
frame : true,
title : title,
bodyStyle : 'padding:5px 5px 0',
width : 500,
// defaults : {
// width : 1230
// },
reader : new Ext.data.JsonReader({
root : 'list',
fields : [{
name : 'sectionText'
}]
})

});
// var
// nameField=createField('章节名称','createItemText'+id+node.id,'sectionText',value
// );
var nameField = new Ext.form.TextArea({
fieldLabel : '章节编辑',
grow : false,
// inputType : 'textarea',
height : 450,
width : 500,
// labelWidth : 1000,
// growMin : 5,
// labelStyle : 'width:1000px;height:1000px',
// growMax:true,
// width:980,
// x:400,
// y:400,
// itemCls:'all-field',
// clearCls:'allow-float',
// allowBlank:false,

// style:"width:300px;overflow-y:visible",
name : 'sectionText'
});
form0.add(nameField);
form0.addButton({
text : '保存',
handler : function() {
saveHandler(win, requestUrl, node, form0, isUpdate);
}
});
var id = node.id;
form0.getForm().load({
url : '/getSectionText/?id=' + id,
waitMsg : 'Loading'
});
return form0;
}

// 2 创建 tab panel
function createTabPanel(node, e, type, win) {

var createUrl = '/createSection/?id=' + node.attributes.id;
var updateUrl = '/updateSection/?id=' + node.attributes.id;
var editorUrl = '/editorSection/?id=' + node.attributes.id;

var panel = new Ext.TabPanel({
// el: 'hello-tabs',
autoTabs : true,
activeTab : 0,
deferredRender : false,
border : false
});

var form0 = createForm(node, 'form0' + node.id, '新建子章节', win, createUrl,
'', false);
var form1 = updateForm(node, 'form1' + node.id, '修改章节名称', win, updateUrl,
node.text, true);
var form2 = editorForm(node, 'form2' + node.id, '章节编辑', win, editorUrl, '',
true);
panel.add(form2);
panel.add(form0);
panel.add(form1);

return panel;
}
// 组装
function itemManage(node, e) {
var type = "电子书章节管理"
// create the window on the first click and reuse on subsequent clicks
var win = Ext.getCmp('win' + type + node.id);
if (!win) {
win = new Ext.Window({
title : type,
id : 'win' + type + node.id,
layout : 'fit',
maximizable : true,// 最大化
collapsible : true,// 可折叠
width : 800,
height : 600,
// closeAction:'hide',
plain : true
});
var tab = createTabPanel(node, e, type, win);
win.add(tab);
}
win.show();

}

// grid.addListener('rowdbclick',function(){
// alert("123");
// });
Ext.ux.makeMenu = function(node, event, title, requestUrl) {
var rightClick = new Ext.menu.Menu({
id : 'rightClickCont' + node.id,
items : [{
id : node.id + "menu",
text : title,
// 增加菜单点击事件
handler : function() {
Ext.Ajax.request({
url : requestUrl,
params : {

},
success : function(response, request) {
Ext.MessageBox.alert("状态", "删除成功", function() {
});
if (node.isLeaf()) {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
} else {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
}
},
failure : function() {
// Ext.MessageBox.hide();
Ext.MessageBox.alert('状态', '删除失败!');
if (node.isLeaf()) {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
} else {
var root = node.getOwnerTree().root;
root.reload();
root.expand(true, true);
}
}
});
}
}]
});
event.preventDefault();
rightClick.showAt(event.getXY());// 取得鼠标点击坐标,展示菜单

};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值