📄 book.js
字号:
var Book = Ext.data.Record.create([
{name : 'bookId',mapping : 'bookId',type : 'int'},
{name : 'bookName', mapping : 'bookName',type : 'string'},
{name : 'author',mapping : 'author',type : 'string'},
{name : 'press',mapping : 'press',type : 'string'},
{name : 'price',mapping : 'price',type : 'string'},
{name : 'editionNo',mapping : 'editionNo',type : 'string'},
{name : 'isbn', mapping : 'isbn',type : 'string'},
{name : 'categoryId',mapping : 'categoryId',type : 'int'},
{name : 'categoryName', mapping : 'categoryName',type : 'string'},
{name : 'wordCount',mapping : 'wordCount',type : 'string'},
{name : 'pageCount',mapping : 'pageCount',type : 'string'},
{name : 'bookSize', mapping : 'bookSize',type : 'string'},
{name : 'paper',mapping : 'paper',type : 'string'},
{name : 'pack', mapping : 'pack',type : 'string'},
{name : 'imageUrl', mapping : 'imageUrl',type : 'string'},
{name : 'address',mapping : 'address',type : 'string'},
{name : 'editorRecommend',mapping : 'editorRecommend', type : 'string'},
{name : 'description',mapping : 'description',type : 'string'},
{name : 'authorDesc',mapping : 'authorDesc',type : 'string'},
{name : 'state',mapping : 'state',type : 'int'}
]);
var categoryId;
var ds_category_select = new Ext.data.Store({
url : 'findAllCategoryName.action',
reader : new Ext.data.JsonReader({
root : 'root'
}, [{name : 'categoryId',type : 'int'},
{name : 'categoryName',type : 'string'}
])
});
var expander = new Ext.grid.RowExpander({
tpl : new Ext.Template('<p><table width="480" style="padding-left:20px" border="0" cellspacing="0" cellpadding="0">'
+ '<tr><td width="133" valign="top"><img src="{imageUrl}" onerror=\'this.src="/bmsh/images/nopic.jpg"\'/></td>'
+ '<td width="476" colspan="4"><table width="100%" border="0" cellspacing="6" cellpadding="4">'
+ '<tr><td width="19%" align="right" nowrap="nowrap">作 者:</td>'
+ '<td width="38%" nowrap="nowrap"> {author}</td><td width="15%" align="right" nowrap="nowrap"> </td>'
+ '<td width="28%" nowrap="nowrap"> </td></tr><tr><td align="right" nowrap="nowrap">出 版 社:</td>'
+ '<td nowrap="nowrap">{press}</td><td align="right" nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr><tr>'
+ '<td align="right" nowrap="nowrap">版 次:</td>'
+ '<td nowrap="nowrap">{editionNo}</td><td align="right" nowrap="nowrap">页 数:</td>'
+ '<td nowrap="nowrap">{pageCount}</td></tr><tr><td align="right" nowrap="nowrap">I S B N:</td>'
+ '<td nowrap="nowrap">{isbn}</td><td align="right" nowrap="nowrap">开 本:</td>'
+ '<td nowrap="nowrap">{bookSize}</td></tr><tr><td align="right" nowrap="nowrap">所属类别:</td>'
+ '<td nowrap="nowrap">{categoryName}</td><td align="right" nowrap="nowrap">纸 张:</td>'
+ '<td nowrap="nowrap">{paper}</td></tr><tr><td align="right" nowrap="nowrap">藏书地址:</td>'
+ '<td nowrap="nowrap">{address}</td><td align="right" nowrap="nowrap">包 装:</td>'
+ '<td nowrap="nowrap">{pack}</td></tr><tr><td align="right" nowrap="nowrap">定 价:</td>'
+ '<td nowrap="nowrap"><strong>¥</strong>{price}</td><td align="right" nowrap="nowrap">字 数:</td>'
+ '<td nowrap="nowrap">{wordCount}</td></tr></table></td></tr><tr><td colspan="5" valign="top"> </td></tr><tr>'
+ '<td colspan="5" valign="top"><h4>编辑推荐</h4></td></tr><tr><td colspan="5" valign="top">{editorRecommend}</td>'
+ '</tr><tr><td colspan="5" valign="top"> </td></tr><tr><td colspan="5" valign="top"><h4>内容简介</h4></td>'
+ '</tr><tr><td colspan="5" valign="top">{description}</td></tr><tr>'
+ '<td colspan="5" valign="top"> </td></tr><tr><td colspan="5" valign="top"><h4>作者简介</h4></td></tr><tr>'
+ '<td colspan="5" valign="top">{authorDesc}</td></tr></table></p>')
});
var cm_book = new Ext.grid.ColumnModel([expander,
{header : '图书名称', width : 120,dataIndex : 'bookName', sortable : true},
{header : '作者',width : 40, dataIndex : 'author',sortable : true},
{header : '定价',width : 30, dataIndex : 'price',sortable : true},
{header : '所属分类', width : 90, sortable : true,dataIndex : 'categoryName'},
{header : '当前读者',width : 40,dataIndex : 'currentReader',menuDisabled : true},
{header : '当前状态',width : 40,dataIndex : 'state',renderer : function(v) {return v == 0 ? '已借出' : '未借出'}, menuDisabled : true},
{header : '藏书地址', width : 90, dataIndex : 'address',id : 'address',sortable : true}]
);
var address,_editAddress;// 藏书地址
var cbb_company_for_book_update = new Ext.form.ComboBox({
name : '_companyName',
width : 120,
valueField : 'companyId',
displayField : 'companyName',
editable : false,
selectOnFocus : true,
mode : 'remote',
store : ds_company_select,
triggerAction : 'all',
loadingText : '加载中...',
fieldLabel : '所属分公司',
listeners : {
'select' : function() {
cbb_dept_for_book_update.reset();
ds_dept_select.baseParams.companyId = cbb_company_for_book_update.getValue();
ds_dept_select.reload();
_editAddress = cbb_company_for_book_update.getEl().dom.value;
bookEditForm.getForm().findField('address').setValue(_editAddress);
}
}
});
var cbb_dept_for_book_update = new Ext.form.ComboBox({
name : '_deptNo',
editable : false,
selectOnFocus : true,
width : 100,
displayField : 'deptName',
mode : 'remote',
store : ds_dept_select,
triggerAction : 'all',
loadingText : '加载中...',
fieldLabel : '所属部门',
listeners : {
'beforequery' : function(queryEvent) {
if (!cbb_company_for_book_update.getValue()) {
queryEvent.cancel = true;
}
},
'select' : function(combo, record, index) {
_editAddress += cbb_dept_for_book_update.getValue();
bookEditForm.getForm().findField('address').setValue(_editAddress);
}
}
});
var cbb_company_for_book = new Ext.form.ComboBox({
name : 'companyName',
width : 120,
valueField : 'companyId',
displayField : 'companyName',
editable : false,
selectOnFocus : true,
mode : 'remote',
store : ds_company_select,
triggerAction : 'all',
loadingText : '加载中...',
fieldLabel : '所属分公司',
listeners : {
'select' : function() {
cbb_dept_for_book.reset();
ds_dept_select.baseParams.companyId = cbb_company_for_book.getValue();
ds_dept_select.reload();
address = cbb_company_for_book.getEl().dom.value;
bookForm.getForm().findField('book.address').setValue(address);
}
}
});
var cbb_dept_for_book = new Ext.form.ComboBox({
name : 'deptNo',
editable : false,
selectOnFocus : true,
width : 100,
displayField : 'deptName',
mode : 'remote',
store : ds_dept_select,
triggerAction : 'all',
loadingText : '加载中...',
fieldLabel : '所属部门',
listeners : {
'beforequery' : function(queryEvent) {
if (!cbb_company_for_book.getValue()) {
queryEvent.cancel = true;
}
},
'select' : function(combo, record, index) {
address += cbb_dept_for_book.getValue();
bookForm.getForm().findField('book.address').setValue(address);
}
}
});
var bookEditForm = new Ext.FormPanel({
url : 'updateBook.action',
labelAlign : 'right',
labelWidth : 70,
bodyStyle : 'padding:5px',
border : false,
fileUpload : true,
baseCls : 'x-plain',
items : [{
layout : 'column',
border : false,
baseCls : 'x-plain',
items : [{
columnWidth : .5,
layout : 'form',
baseCls : 'x-plain',
border : false,
defaultType : 'textfield',
defaults : {anchor : '93%'},
items : [{
xtype : 'hidden',
name : 'bookId'
},{
fieldLabel : '图书名称',
name : 'bookName',
allowBlank : false,
maxLength : 50
}, {
xtype : 'combo',
fieldLabel : '所属分类',
id : 'category_edit',
hiddenName : 'categoryId',
valueField : 'categoryId',
displayField : 'categoryName',
mode : 'remote',
store : new Ext.data.Store({
autoLoad : true,
proxy : new Ext.data.HttpProxy({
url : 'findAllCategoryName.action'
}),
reader : new Ext.data.JsonReader({
root : 'root'
}, [{name : 'categoryId',type : 'int'},
{name : 'categoryName',type : 'string'}
])
}),
selectOnFocus : true,
editable : false,
triggerAction : 'all',
loadingText : '加载中...',
listeners : {
'select' : function(combo, record, index) {
this.ownerCt.ownerCt.ownerCt.form.findField('categoryName').setValue(record.data.categoryName);
}
}
}, {xtype : 'hidden',name : 'categoryName'},
{xtype : 'hidden',name : 'imageUrl'},
{fieldLabel : '作者',name : 'author',maxLength : 50},
{fieldLabel : 'ISBN',name : 'isbn', maxLength : 50},
{fieldLabel : '字数', name : 'wordCount',maxLength : 25},
{fieldLabel : '页数',name : 'pageCount',maxLength : 25},
{fieldLabel : '开本',name : 'bookSize', maxLength : 25},
{fieldLabel : '封面图片', name : 'upload',inputType : 'file'}]
}, {
columnWidth : .5,
layout : 'form',
border : false,
baseCls : 'x-plain',
defaultType : 'textfield',
defaults : {anchor : '93%'},
items : [
{fieldLabel : '出版社',name : 'press',maxLength : 50},
{fieldLabel : '定价(元)',xtype : 'numberfield',name : 'price',maxValue : 1000},
{fieldLabel : '版次',name : 'editionNo',maxLength : 25},
{fieldLabel : '纸张',name : 'paper',maxLength : 25},
{fieldLabel : '包装',name : 'pack',maxLength : 25},
{xtype : 'hidden',name : 'address',maxLength : 50},
{xtype : 'hidden',value : '1',name : 'state'},
cbb_company_for_book_update, cbb_dept_for_book_update]
}]
},{
xtype : 'panel',
baseCls : 'x-plain',
bodyBorder : false,
layout : 'form',
defaultType : 'textarea',
defaults : {anchor:'95%'},
items : [{fieldLabel : '内容简介',name : 'description',maxLength : 500},
{fieldLabel : '编辑推荐',name : 'editorRecommend',maxLength : 500},
{fieldLabel : '作者简介',name : 'authorDesc',maxLength : 500}]
}],
buttonAlign : 'center',
minButtonWidth : 60,
buttons : [{
text : '修改',
handler : function(btn){
if (bookEditForm.getForm().isValid()) {
btn.disable();
bookEditForm.getForm().submit({
waitTitle : '请稍候',
waitMsg : '正在修改数据,请稍候...',
success : function(form,action) {
Ext.Msg.show({
title : '成功提示',
msg : '数据修改成功!',
buttons : Ext.Msg.OK,
fn : function(){btn.enable()},
icon : Ext.Msg.INFO
});
var store = grid_book.getStore();
var book = new Book({
bookId : form.findField('bookId').getValue(),
bookName : form.findField('bookName').getValue(),
categoryId : form.findField('categoryId').getValue(),
categoryName : Ext.get('category_edit').dom.value,
author : form.findField('author').getValue(),
press : form.findField('press').getValue(),
price : form.findField('price').getValue(),
editionNo : form.findField('editionNo').getValue(),
isbn : form.findField('isbn').getValue(),
wordCount : form.findField('wordCount').getValue(),
pageCount : form.findField('pageCount').getValue(),
bookSize : form.findField('bookSize').getValue(),
paper : form.findField('paper').getValue(),
pack : form.findField('pack').getValue(),
imageUrl : action.result.imageUrl,
address : form.findField('address').getValue(),
description : form.findField('description').getValue(),
editorRecommend : form.findField('editorRecommend').getValue(),
authorDesc : form.findField('authorDesc').getValue(),
state : form.findField('state').getValue()
});
var index = store.indexOf(grid_book.getSelectionModel().getSelected());
store.remove(grid_book.getSelectionModel().getSelected());
store.insert(index,book);
grid_book.getSelectionModel().selectRow(index);
},
failure : function(form, action) {
Ext.Msg.show({
title : '错误提示',
msg : action.result.contentTypeIsValid ? '操作失败' : '操作失败,文件类型不正确!',
buttons : Ext.Msg.OK,
fn : function() {btn.enable();},
icon : Ext.Msg.ERROR
});
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -