📄 book.js
字号:
handler : function() {this.ownerCt.ownerCt.hide();}
}]
});
var window_edit_book = new Ext.Window({
title : '编辑图书信息',
width : 620,
resizable : false,
autoHeight : true,
modal : true,
closeAction : 'hide',
items : [bookEditForm]
});
var window_loan_book = new Ext.Window({
title : '借书管理',
width : 400,
resizable : false,
autoHeight : true,
modal : true,
closeAction : 'hide',
listeners : {
'hide' : function(){
this.findById('bookName').ownerCt.form.reset();
}
},
items : [loanLogForm]
});
var window_add_book = new Ext.Window({
title : '添加图书',
width : 600,
resizable : false,
autoHeight : true,
modal : true,
closeAction : 'hide',
listeners : {
'hide' : function() {
this.findById('book.bookName').ownerCt.ownerCt.ownerCt.form.reset();
}
},
items : [bookForm]
});
var btn_loan_book = new Ext.Button({
text : '借书管理',
handler : function(){
var record = grid_book.getSelectionModel().getSelected();
if(record){
window_loan_book.show();
loanLogForm.getForm().findField('loanLog.bookId').setValue(record.data.bookId);
loanLogForm.getForm().findField('loanLog.bookName').setValue(record.data.bookName);
loanLogForm.getForm().findField('_bookName').setValue(record.data.bookName);
}
}
});
var btn_return_book = new Ext.Button({
text : '确认还书',
handler : function(){
var record = grid_book.getSelectionModel().getSelected();
if(record){
var bookId = record.data.bookId;
Ext.Ajax.request({
url: 'returnBook.action',
success: function(){
Ext.Msg.show({
title : '成功提示',
msg : '还书操作成功!',
buttons : Ext.Msg.OK,
icon : Ext.Msg.INFO,
fn : function(){
record.set('state',1);
record.set('currentReader',''),
grid_book.fireEvent('rowclick',grid_book,grid_book.getStore().indexOf(record));
}
});
},
failure: function(){
Ext.Msg.show({
title : '错误提示',
msg : '还书操作失败!',
buttons : Ext.Msg.OK,
icon : Ext.Msg.ERROR
});
},
params: { bookId: bookId}
});
}
}
});
var btn_add_book = new Ext.Button({
text : '添加图书',
iconCls : 'icon-add',
handler : function() {
window_add_book.show();
}
});
var btn_edit_book = new Ext.Button({
text : '编辑图书',
iconCls : 'icon-edit',
handler : function(){
var record = grid_book.getSelectionModel().getSelected();
if(record){
window_edit_book.show();
bookEditForm.getForm().loadRecord(record);
}
}
})
var btn_del_book = new Ext.Button({
text : '删除图书',
iconCls : 'icon-del',
handler : function() {
var record = grid_book.getSelectionModel().getSelected();
if (record) {
Ext.Msg.confirm('确认删除', '你确定删除该条记录?', function(btn) {
if (btn == 'yes') {
Ext.Ajax.request({
url : 'deleteBook.action',
params : {bookId : record.data.bookId},
success : function() {grid_book.getStore().remove(record);},
failure : function() {
Ext.Msg.show({
title : '错误提示',
msg : '删除时发生错误!',
buttons : Ext.Msg.OK,
icon : Ext.Msg.ERROR
});
}
});
}
});
}
}
});
var searchBook = function() {
ds_book.baseParams.conditions = text_search_book.getValue();
ds_book.load({params : {start : 0,limit : 20}
});
}
var ds_book = new Ext.data.Store({
url : 'findAllBook.action',
reader : new Ext.data.JsonReader(
{totalProperty : 'totalProperty',root : 'root'},
[{name : 'bookId',type : 'int'},
{name : 'bookName',type : 'string'},
{name : 'author',type : 'string'},
{name : 'press',type : 'string'},
{name : 'price',type : 'string'},
{name : 'editionNo',type : 'string'},
{name : 'isbn',type : 'string'},
{name : 'categoryId',type : 'int'},
{name : 'categoryName',type : 'string'},
{name : 'wordCount',type : 'string'},
{name : 'pageCount',type : 'string'},
{name : 'bookSize',type : 'string'},
{name : 'paper',type : 'string'},
{name : 'pack',type : 'string'},
{name : 'imageUrl',type : 'string'},
{name : 'address',type : 'string'},
{name : 'editorRecommend',type : 'string'},
{name : 'description',type : 'string'},
{name : 'authorDesc',type : 'string'},
{name : 'state',type : 'int'},
{name : 'currentReaderId',type : 'int'},
{name : 'currentReader',type : 'string'},
{name : 'logId',type : 'int'}
])
});
var btn_search_book = new Ext.Button({
text : '查询',
iconCls : 'icon-search',
handler : searchBook
});
var text_search_book = new Ext.form.TextField({
name : 'textSearchBook',
width : 200,
emptyText : '请输入查询条件!!!!',
listeners : {
'specialkey' : function(field, e) {
if (e.getKey() == Ext.EventObject.ENTER) {
searchBook();
}
}
}
});
var grid_book = new Ext.grid.GridPanel({
region : 'center',
loadMask : {msg : '数据加载中...'},
enableColumnMove : false,
cm : cm_book,
ds : ds_book,
sm : new Ext.grid.RowSelectionModel({singleSelect : true}),
autoExpandColumn : 'address',
viewConfig : {forceFit : true},
plugins : expander,
tbar : [btn_add_book, '-',btn_edit_book, '-', btn_del_book, '-',
text_search_book,btn_search_book,'->',btn_loan_book,'-',btn_return_book],
bbar : new Ext.PagingToolbar({
pageSize : 20,
store : ds_book,
displayInfo : true,
displayMsg : '第 {0} - {1} 条 共 {2} 条',
emptyMsg : "没有记录"
}),
listeners : {
'rowdblclick':function(grid, rowIndex){
ds_loanlog.baseParams.bookId = grid.getStore().getAt(rowIndex).data.bookId;
ds_loanlog.load({params : {start : 0,limit : 10}});
},
'rowclick':function(grid,rowIndex){
btn_loan_book.setDisabled(grid.getStore().getAt(rowIndex).data.state == 0 ? true:false);
btn_return_book.setDisabled(grid.getStore().getAt(rowIndex).data.state == 1 ? true:false);
}
}
});
var ds_loanlog = new Ext.data.Store({
url : 'findAllLoanLog.action',
sortInfo : {field: 'loanTime', direction: 'DESC'},
reader : new Ext.data.JsonReader(
{totalProperty : 'totalProperty',root : 'root'},
[{name : 'logId',type : 'int'},
{name : 'bookId',type : 'int'},
{name : 'bookName',type : 'string'},
{name : 'loanTime'},
{name : 'loanDays',type : 'int'},
{name : 'preReturnTime'},
{name : 'returnTime'},
{name : 'readerId',type : 'int'},
{name : 'reader',type : 'string'},
{name : 'loannerId',type : 'int'},
{name : 'loanner',type : 'string'}]
)
});
var dateFormat = function(v){
if(v){
return v.substring(0,10)
}
return '未归还';
}
LoanLogPanel = Ext.extend(Ext.grid.GridPanel,{
constructor:function(){
LoanLogPanel.superclass.constructor.call(this,{
loadMask : {msg : '数据加载中...'},
cm : new Ext.grid.ColumnModel([
{header : '图书名称', width : 120,dataIndex : 'bookName',id : 'bookName',sortable : true},
{header : '借书人', width : 90, dataIndex : 'reader',sortable : true},
{header : '借出时间',width : 100, dataIndex : 'loanTime',renderer: dateFormat,sortable : true},
{header : '借出天数',width : 100, dataIndex : 'loanDays',sortable : true},
{header : '预计还书时间', width : 100,dataIndex : 'preReturnTime',renderer: dateFormat,sortable : true},
{header : '实际还书时间', width : 100,dataIndex : 'returnTime',renderer:dateFormat,sortable : true},
{header : '管理员', width : 100,dataIndex : 'loanner',menuDisabled : true}]
),
autoExpandColumn : 'bookName',
ds : ds_loanlog,
sm : new Ext.grid.RowSelectionModel({singleSelect : true}),
bbar : new Ext.PagingToolbar({
pageSize : 10,
store : ds_loanlog,
displayInfo : true,
displayMsg : '第 {0} - {1} 条 共 {2} 条',
emptyMsg : "没有记录"}
)
});
}
});
var book_panel = new Ext.Panel({
title : '图书管理',
iconCls : 'icon-plugin',
region : 'center',
border : 'layout',
frame : true,
layout:'border',
defaults: {
collapsible: true,
split: true
},
items: [{
region:'center',
layout : 'border',
items : [grid_book]
},{
region: 'south',
layout :'fit',
title : '图书借还记录',
height: 250,
minSize: 150,
maxSize: 286,
items : [new LoanLogPanel()]
}]
});
var p_book = {
id : 'book-panel',
border : false,
layout : 'border',
items : [book_panel]
}
ds_book.load({
params:{
start : 0,
limit : 20
}
})
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -