Ext.define('AM.controller.JokeController',{
extend:'Ext.app.Controller',
GridDoActionUtil:Ext.create('AM.util.GridDoActionUtils'),
init:function(){
this.getGridObj=function(button){
return button.ownerCt.ownerCt;
}
this.getTreeObj=function(button){
return button.ownerCt.ownerCt.ownerCt.ownerCt.child('#west-tree').child('#joke-tree');
}
this.getJokeEditObj = function(button){
return button.ownerCt.child('#joke-edit');
}
this.control({
'jokedit button[id=save]':{
click:function(addButton){
alert(this.getJokeEditObj);
// formBind: true,
// disabled: true,
// handler: function() {
// var fform = this.up('window').down('form').getForm();
// console.info(fform);
// if (fform.isValid()) {
// alert('1');
// fform.submit({
// url:'AppJoke/addUpdateJoke!addOrUpdate',
// success: function(fform, action) {
// Ext.Msg.alert('Success', action.result.msg);
// },
// failure: function(fform, action) {
// Ext.Msg.alert('Failed', action.result.msg);
// }
// });
// }
// }
}
},
'jokeTree':{
itemclick:function(tree,record,item,index,e,options){
var view= Ext.get('joke-view');
//var store = view.getStore();
this.GridDoActionUtil.changeTab(view,record);
}
},
"winimportview button[id=upload]":{
click: function(sm, selections,a,c){
var form=Ext.getCmp("formimport");
if (form.getForm().isValid()) {
//重置信息提示框
Ext.getCmp("resultmsg").body.update("正在导入数据,请稍候...");
form.getForm().submit({
url: Qas.getAppName() + '',
method : 'POST',
waitTitle:'请等待...',
waitMsg: '正在上传Excel文件,分析导入数据,请稍候...',
success : function(form,action) {
console.log("ServerJson="+action.response.responseText);
Ext.getCmp("resultmsg").body.update(action.result.msg);
},
failure : function(form, action){//500内部错误
console.log("ServerJson="+action.response.responseText);
Ext.getCmp("resultmsg").body.update(action.result.msg);
}
});
}
}
},
'jokelist button[id=import]':{
click:function(importButton){
var importWin = Ext.create("AM.view.WinImportView");
importWin.show();
}
},
'jokelist button[id=delete]':{
click:function(deleteButton){
var grid=this.getGridObj(deleteButton);
this.GridDoActionUtil.doDelete(grid);
}
},
'jokelist button[id=save]':{
click:function(saveButton){
var grid=this.getGridObj(saveButton);
this.GridDoActionUtil.doSave(grid);
}
},
'jokelist button[id=add]':{
click:function(addButton){
//var addWin=Ext.getCmp('joke-edit');
var win = Ext.create("AM.view.JokeEdit");
win.show();
}
}//,
//设定列表添加按钮事件
// 'jokelist button[id=add]':{
// click:function(addButton){
//
// var grid=this.getGridObj(addButton);
// var modelObj={
// id:'',
// joke:'',
// type:'',
// createTime:''
// }
// this.GridDoActionUtil.doInsert(grid,modelObj);
//
// }
// }
});
},
views:[
'MainLayout',
'JokeList',
'JokeTree',
'JokeEdit'
],
stores:[
'JokeStore4Tree',
'JokeStore'
],
models:[
'JokeModel'
]
})
Ext.define('AM.model.JokeModel',{
extend:'Ext.data.Model',
fields:[
{name:'id',type:'int'},
{name:'joke',type:'string'},
{name:'type',type:'int'},
{name:'createTime'}
],
validations:[
{type:'presence',field:'joke',
presenceMessage:'内容不能为空'},
{type:'presence',field:'type',
presenceMessage:'类型不能为空'}
]
});
Ext.define('AM.model.JokeModel4Tree',{
extend:'Ext.data.Model',
fields:[
{name:'id',type:'auto'},
{name:'menuBean',type:'auto'},
{name:'text',type:'auto'},
{name:'cls',type:'auto'},
{name:'leaf',type:'auto'},
{name:'type',type:'auto'},
{name:'children',type:'auto'}
]
});
/**
* ClassName:部门实体数据集
*/
Ext.define('AM.store.JokeStore',{
extend:'Ext.data.Store',
model:'AM.model.JokeModel',
pageSize:25,
proxy:{
api:{
update:'AppJoke/joke!saveOrUpdate',
remove:'AppJoke/joke!delete'
},
type:'ajax',
url:'xxxx/xxxx!list',
reader:{
type:'json',
root:'root',
totalProperty:'total'
},
writer:{
type:'json'
}
},
autoLoad:true
})
Ext.define('AM.store.JokeStore4Tree',{
extend:'Ext.data.TreeStore',
defaultRootId:'root',
proxy:{
type:'ajax',
url:'xxx/xxxxx!list',
reader:'json'
}
})
Ext.QuickTips.init();
Ext.define('AM.view.JokeEdit', {
extend: 'Ext.window.Window',
alias : 'widget.jokedit',
title : '笑话添加编辑',
layout: 'fit',
id:'joke-edit',
autoShow: true,
modal:true,
frame:false,
border : false,
bodyBorder : false,
initComponent: function() {
var states = Ext.create('Ext.data.Store', {
fields: ['type', 'name'],
data : [
{"type":0, "name":"xxxxx"},
{"type":1, "name":"xxxxxxx"},
{"type":2, "name":"xxxxx"},
{"type":3, "name":"xxxxx"}
]
});
this.items = [{
xtype:'form',
url:'Pmjoke/AppJoke/addUpdateJoke!addOrUpdate',
defaults:{
margin:'2 2 2 10',
labelSeparator :':',//分隔符
labelWidth : 70,//标签宽度
//width : 150,//字段宽度
allowBlank : false,
blankText : '不允许为空',
labelAlign : 'right',
msgTarget :'qtip'
},
items:[{
xtype: 'textfield',
name :'id',
fieldLabel: '序号',
hidden:true
},{
xtype: 'textarea',
width:350,
height:200,
name :'joke',
fieldLabel: 'xx'
},{
xtype: 'comboBox',
name : 'type',
fieldLabel: 'xx类型',
editor:{
xtype:'combobox',
store:states,
displayField:'name',
valueField:'type',
listeners:{
select:function(combo,record,index){
isEdit = true;
}
}
}
},{
xtype: 'datefield',
name : 'createTime',
fieldLabel: '创建时间',
hidden:true
}]
}];
this.buttons = [{
text: '保存',
//action: 'save'
formBind: true,
//disabled: true,
handler: function() {
var fform = this.up('form').getForm();
console.info(fform);
if (fform.isValid()) {
alert('1');
fform.submit({
url:'Pmjoke/AppJoke/addUpdateJoke!addOrUpdate',
success: function(fform, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(fform, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
}
}
},{
text: '取消',
scope: this,
handler: this.close
}];
this.callParent(arguments);
}
});
/**
* 笑话管理列表实体
*/
Ext.define('AM.view.JokeList',{
extend:'Ext.grid.Panel',
alias:'widget.jokelist',
store:'JokeStore',
id:'joke-view',
// width:550,
// height:500,
forceFit:true,
selModel:{
selType:'checkboxmodel'
},
border:0,
multiSelect:true,
frame:true,
tbar:[
{xtype:'button',text:'添加',id:'add',iconCls:'table_add'},
{xtype:'button',text:'删除',id:'delete',iconCls:'table_remove'},
{xtype:'button',text:'保存',id:'save',iconCls:'table_save'},
{xtype:'button',text:'导入',id:'import',iconCls:'table_import'},
{xtype:'button',text:'导出',id:'export',iconCls:'table_export'}
],
dockedItems:[{
xtype:'pagingtoolbar',
store:'JokeStore',
dock:'bottom',
displayInfo:true
}],
initComponent:function(){
this.editing = Ext.create('Ext.grid.plugin.CellEditing');
this.plugins=[this.editing];
this.callParent(arguments);
},
states:Ext.create('Ext.data.Store', {
fields: ['type', 'name'],
data : [
{"type":0, "name":"普通xx"},
{"type":1, "name":"xx"},
{"type":2, "name":"成人xx"},
{"type":3, "name":"x事"}
]
}),
enableKeyNav:true,
columnLines:true,
columns:[
{text:'编号',dataIndex:'id',width:50,
hidden:true
},
{text:'xx',dataIndex:'joke',width:700,
field:{
xtype:'textfield',
allowBlank:false
}
},
{text:'类型',dataIndex:'type',width:100,
editor:{
xtype:'combobox',
store:this.states,
displayField:'name',
valueField:'type',
listeners:{
select:function(combo,record,index){
isEdit = true;
}
}
}
},
{text:'创建时间',dataIndex:'createTime',width:150,xtype : 'datecolumn',
format:'Y年m月d日'
}
]
})
Ext.define('AM.view.JokeTree',{
extend:'Ext.tree.Panel',
alias:'widget.jokeTree',
rootVisible:true,//不展示根
displayField:'text',
title:'xx导航',
animate:false,
id:'tree-store',
store:'JokeStore4Tree'
})
Ext.define('AM.view.MainLayout',{
extend:'Ext.panel.Panel',
alias:'widget.mainlayout',
defaults:{
split:true,
bodyStyle:'padding:1px'
},
layout:'border',
resizable:true,
items:[{
title:'xx树形',
region:'west',
//iconCls:'joke-tree',
xtype:'treepanel',
margins:'5 2 5 5',
width:200,
collapsible:true,
id:'west-tree',
layout:'fit',
items:[{
title:'xx导航',
xtype:'jokeTree',
id:'joke-tree'
}]
},{
title:'数据表格',
region:'center',
//iconCls:'joke-table',
xtype:'panel',
//width:.85,
id:'center-grid',
margins:'5 5 5 0',
layout:'fit',
items:[{
title:'xx管理',
id:'joke-grid',
xtype:'jokelist'
}]
}]
})
Ext.require(['Ext.form.field.File']);
Ext.define('AM.view.WinImportView', {
extend : 'Ext.window.Window',
alias : 'widget.winimportview',
// width : 450,
// height : 260,
layout : 'fit',
resizable : true,
frame : false,
modal : true,
border : false,
bodyBorder : false,
items : [{//items_win_begin
border : false,
bodyBorder : false,
id:'formimport',
xtype : 'form',
frame: true,
fileUpload:true,
layout: 'anchor',
defaults: {
anchor: '100%'
},
bodyPadding: 5,
fieldDefaults: {
labelAlign: 'right',
msgTarget : 'side'
},
items: [{//item_form_begin
xtype: 'fieldset',
collapsible: true,
title: 'Excel导入',
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items: [{//item_fieldset1_begin
xtype: 'container',
layout : {
type : 'table',//内部容器用表格风格排版
columns : 1,
bodyStyle : 'padding:0 0 0 0'
},
defaultType: 'textfield',
items: [{//item_container_begin
xtype: 'filefield',
name: 'file',
fieldLabel: '请选择Excel文件',
width:400,
allowBlank: false,
buttonText: ' 浏 览 ',
buttonConfig: {
//iconCls: 'upload-icon'
}
}/*,{
width:400,
html:'<a href='+Pmjoke.getAppName() + '/template/Excel/ApImportTemplate.xls> 模板文件下载 </a>[提示:只有按照模板格式整理Excel表,才允许导入数据]'
}*/,{
xtype:'panel',
frame:true,
autoScroll:true,
height:120,
width:400,
name:'resultmsg',
id:'resultmsg',
html:''//在后台动态更改
}]//item_container_end
}]//item_fieldset1_end
}]//item_form_END
}],//items_win_end
dockedItems : [ {
xtype : 'toolbar',
dock : 'bottom',
items : [ '->', {
xtype : 'button',
text : '导入Excel数据',
iconCls : 'save',
action: 'import',
scale : 'small'
},{
xtype : 'button',
text : '取消',
iconCls : 'cancel',
handler : function(m, e) {
this.ownerCt.ownerCt.close();
}
}]
}]//dockedItems结束
});[b]
[/b][b][/b]