该窗体的js代码如下,(事前,请引用Itemselector相关的js文件,相css,图片,等)
Ext.namespace("Neo");
Ext.namespace("Neo.frontdesk");
Neo.frontdesk.SendMsg = Ext.extend(Ext.Window, {
title : '消息发送',
layout : 'fit',
width : 650,
height : 320,
id : 'sendmsgWin',
draggable : true,
modal : true,
frame : true,
resizable : true,
initComponent : function() {
var cbmydstore =new Ext.data.Store( {
id:"cbmydstore",
autoLoad : true,
proxy : new Ext.data.HttpProxy({url:"mgr/tsjy.htm?action=GetAllUser"}),
reader: new Ext.data.JsonReader({
root:"data"},
[{name:"fullname"}])
});
Ext.apply(this, {
buttons : [{
text : '发送',
id : 'btnSubmit',
handler : function() {
var isForm=Ext.getCmp('sendmsgform');
if(isForm.form.findField('msgdetails').getValue().trim().length<=0)
{
Ext.ux.Toast.msg('提示', '消息不能为空。');
return;
}
if(isForm.form.findField('itemselector').getValue().trim().length>0){
Ext.Ajax.request({
url : 'mgr/tsjy.htm?action=addMsgs',
success : function() {
Ext.ux.Toast.msg('提示', '消息群发成功。');
Ext.getCmp('sendmsgWin').close();
var msggrid = Ext.getCmp('msgMenu');
msggrid.getStore().reload();
},
failure : function(action) {
if (action.failureType =='server') {
obj = Ext.util.JSON
.decode(action.response.responseText);
Ext.Msg.alert('错误:', obj.errors.reason);
}
},
params : {
receivers : isForm.form.findField('itemselector').getValue(),
msgdetails : isForm.form.findField('msgdetails').getValue()
}
});
}else{
Ext.ux.Toast.msg('提示', '找不到信息接收者。');
}
}
}, {
text : '取消',
id : 'btnCancel',
handler : function() {
Ext.getCmp('sendmsgWin').close();
}
}],
items : new Ext.form.FormPanel({
id : 'sendmsgform',
frame : true,
bodyStyle: 'padding:10px;',
items:[{
layout : 'column',
border : false,
items:[
{
layout : 'form',
columnWidth : .5,
items:[{
xtype:"itemselector",
name:"itemselector",
fieldLabel:"消息接收用户",
hideLabel : true,
dataFields:["fullname"],
msWidth:120,
msHeight:200,
toData:[],
valueField:"fullname",
displayField:"fullname",
imagePath:"public/scripts/extjs/ux/images/",
toLegend:"已选择用户列表",
fromLegend:"后台用户列表",
fromStore:cbmydstore
}]
},
{
columnWidth : .5,
layout : 'form',
xtype : 'fieldset',
collapsible : false,
height:200,
autoScroll:false,
align : "center",
title : '消息内容',
labelWidth:3,
items : [{
fieldLabel : '',
hideLabel :false,
xtype : 'textarea',
name : 'msgdetails',
id : 'msgdetails',
width : "99%",
height : 170,
allowBlank : false,
emptyText : '该项值不能为空',
blankText : '该项值不能为空'
}]
}]
}]
})
});
Neo.frontdesk.SendMsg.superclass.initComponent.apply(this,
arguments);
}
});
Ext.reg('sendmsg', Neo.frontdesk.SendMsg);
Java代码:
public void addMsgs(HttpServletRequest request, HttpServletResponse response)
throws Exception {
log.info("Someone come from ip address <"+ request.getRemoteAddr()
+">");
log.debug("reach addMsgs");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/json;charset=utf-8");
String receivers = (String) request.getParameter("receivers").trim();
String details=(String)request.getParameter("msgdetails").trim();
SecurityContext ctx = SecurityContextHolder.getContext();
User user = (User) ctx.getAuthentication().getPrincipal();
Operator operator = businessService.findOperatorByOpUserName(user.getUsername());
//获得群发人员名单
String[] receiver=receivers.split(",");
System.out.println(receiver.length);
for(int i=0;i<receiver.length;i++)
{
System.out.println(receiver[i].toString());
if(operator.getFullName().equals(receiver[i].toString())){}
else{
Msg msg=new Msg();
msg.setReceiver(receiver[i].toString());
msg.setSender(operator.getFullName());
msg.setMsgdetails(details);
msg.setSendtime(setTime());
msg.setIsread("0");
businessService.addNewMsg(msg);
}
}
response.getWriter().write("{success: true}");
}