Ext.define('erp.view.oa.task.TaskSetGrid',{
extend: 'Ext.grid.Panel',
alias: 'widget.TaskGridPanel',
id: 'taskgrid',
emptyText : '无数据',
columnLines : true,
autoScroll : true,
requires:['erp.view.core.trigger.DbfindTrigger','erp.view.core.form.FileField'],
plugins: Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
}),
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragGroup: 'taskgrid',
dropGroup: 'taskgrid'
}
},
keyField:'id',
listeners:{
itemclick:function(selModel,record){
if(record.data.handstatus!='已完成') Ext.getCmp('attachfile').setDisabled(false);
selModel.ownerCt.GridUtil.onGridItemClick(selModel, record);
}
},
activemenu:null,
columns:[{
text:'ID',
dataIndex:'id',
width:0,
},{
cls : "x-grid-header-1",
text: '任务名称',
dataIndex: 'name',
flex:1,
readOnly:true
},{
cls : "x-grid-header-1",
text: '责任人编号',
dataIndex: 'resourcecode',
editable:true,
editor:{
xtype:'dbfindtrigger',
hideTrigger: false,
name:'resourcecode',
which:'grid',
dbfind:'Employee|em_code',
listeners:{
focus: function(t){
t.setHideTrigger(false);
t.setReadOnly(false);
var record = Ext.getCmp('taskgrid').selModel.getLastSelected();
var canextra = record.data['handstatus'];
if(handstatus == '已完成'){
showError("当前任务已完成不允许变更!");
t.setHideTrigger(true);
t.setReadOnly(true);
}
}
}
},
flex: 0.5,
},{
cls : "x-grid-header-1",
text:'责任人',
dataIndex: 'resourcename',
flex: 0.5,
readOnly:true
},{
cls : "x-grid-header-1",
text:'责任人ID',
dataIndex: 'resourceemid',
width:0,
readOnly:true
},{
cls:'x-grid-header-1',
text:'激活方式',
width:120,
xtype:'combocolumn',
dataIndex:'triggertype',
editor: {
xtype: 'combo',
store: {
fields: ['display', 'value'],
data :[{
display:'自动触发',value:'AUTO'
},{
display:'提交触发',value:'COMMIT'
},{
display:'审核触发',value:'AUDIT'
},{
display:'节点触发',value:'NODETRIG'
}],
},
displayField: 'display',
valueField: 'value',
queryMode: 'local'
},
// editor: {
// xtype: 'combo',
// listConfig:{
// maxHeight:180
// },
// queryMode: 'local',
// displayField: 'display',
// valueField: 'value',
// store:Ext.create('Ext.data.Store', {
// fields: ['display', 'value'],
// data : [
// {display:'自动触发', "value": 'AUTO'},
// {display:'提交触发', "value": 'COMMIT'},
// {display:'审核触发', "value": 'AUDIT'},
// {display":'节点触发', "value": 'NODETRIG'}
// ]
// }),
//// onTriggerClick:function(e){
//// var me=this;
//// var grid=Ext.getCmp('taskgrid');
//// var selected=grid.getSelectionModel().getSelection()[0];
//// if(grid.activemenu==null){
//// var items=grid.getTiggerProcessNodeItems();
//// grid.activemenu=Ext.create('Ext.menu.Menu', {
//// async:false,
//// id: 'mainMenu',
//// ownerCt : this.ownerCt,
//// renderTo:Ext.getBody(),
//// width:'120',
//// style: {
//// overflow: 'visible',
//// },
//// defaults:{
//// handler:grid.setTriggerType
//// },
//// items: [{
//// text: '提交触发'
//// },{
//// text: '审核触发'
//// },{
//// text: '立即触发'
//// },{
//// text:'节点触发',
//// iconCls:'main-msg',
//// menu: {
//// defaults:{
//// handler:grid.setTriggerType
//// },
//// items: items
//// }
//// }]
//// });
//// }
//// grid.activemenu.alignTo(e.getTarget() , 'tl-bl?',[-105,0]);
//// grid.activemenu.show();
//// if (!me.readOnly && !me.disabled) {
//// if (me.isExpanded) {
//// me.collapse();
//// } else {
//// me.expand();
//// }
//// me.inputEl.focus();
//// }
//// }
// }
},{
cls:'x-grid-header-1',
text:'当前状态',
logic:'ignore',
flex:0.3,
dataIndex:'handstatus',
readOnly:true,
renderer:function(val,mata,record){
if(val=='已完成'){
return '
' +
'' + val + '';
}else if(val=='已启动'){
return '
' +
'' + val + '';
}else {
return '
'+'' + val + '';
}
}
},{
dataIndex:'attachs',
text:'附件',
width:0
}],
keyValue:null,
FlowCaller:null,
BaseUtil: Ext.create('erp.util.BaseUtil'),
GridUtil: Ext.create('erp.util.GridUtil'),
selModel: Ext.create('Ext.selection.CheckboxModel',{
headerWidth: 0
}),
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})],
requires: ['erp.view.core.grid.YnColumn'],
tbar: [{
xtype: 'button',
text: '载入模板',
iconCls: 'x-button-icon-save',
cls: 'x-btn-gray',
scope:this,
handler:function (btn){
var grid=Ext.getCmp('taskgrid'),bool=false;
Ext.Array.each(grid.store.data.items,function(item){
if(item.data.id) {
bool=true;
return
}
});
if(bool){
warnMsg('已载入相应的任务模板,是否要重新生成?', function(button){
if(button == 'yes'){
btn.ownerCt.ownerCt.loadTaskTemplate();
}
});
}else btn.ownerCt.ownerCt.loadTaskTemplate();
}
},{
id:'attachform',
xtype:'form',
layout:'column',
bodyStyle: 'background: transparent no-repeat 0 0;border: none;',
items: [{
xtype: 'filefield',
name: 'file',
buttonOnly: true,
hideLabel: true,
disabled:true,
width: 90,
height: 17,
id:'attachfile',
buttonConfig: {
iconCls: 'x-button-icon-pic',
text: '上传附件',
},
listeners: {
change: function(field){
var filename = '';
if(contains(field.value, "\\", true)){
filename = field.value.substring(field.value.lastIndexOf('\\') + 1);
} else {
filename = field.value.substring(field.value.lastIndexOf('/') + 1);
}
field.ownerCt.getForm().submit({
url: basePath + 'common/upload.action?em_code=' + em_code,
waitMsg: "正在解析文件信息",
success: function(fp,o){
if(o.result.error){
showError(o.result.error);
} else {
Ext.Msg.alert("恭喜", filename + " 上传成功!");
field.setDisabled(true);
var record=Ext.getCmp('grid').selModel.lastSelected;
if(record){
record.set('attachs',filename+";"+o.result.filepath);
}
}
}
});
}
}}]
}],
menu:null,
store: Ext.create('Ext.data.Store', {
fields:[{name:'id',type:'int'},{name:'name',type:'string'},{name:'resourcecode',type:'string'},
{name:'resourcename',type:'string'},{name:'resourceemid',type:'string'},{name:'handstatus',type:'string'},{name:'triggertype',type:'string'}],
data:[]
}),
initComponent : function(){
this.getGridStore(this,this.keyValue,this.FlowCaller);
this.callParent(arguments);
},
dbfinds:[{
dbGridField: "em_code",
field: "resourcecode",
},{
dbGridField: "em_name",
field: "resourcename",
},{
dbGridField: "em_id",
field: "resourceemid",
}],
getGridStore:function(grid,keyValue,caller){
grid.GridUtil.loadNewStore(grid,{
caller:'ProjectMainTask',
condition:"sourcecaller='"+caller+"' and sourceid="+keyValue +" order by detno"
});
},
loadTaskTemplate:function(){
var me=this;
Ext.Ajax.request({
url : basePath + 'oa/task/loadTaskTemplate.action',
params: {
caller:me.FlowCaller,
keyValue:me.keyValue,
_noc:1
},
method : 'post',
callback : function(options,success,response){
var localJson = new Ext.decode(response.responseText);
if(localJson.success){
Ext.create('erp.util.GridUtil').loadNewStore(me,{
caller:'ProjectMainTask',
condition:'sourceid='+me.keyValue+" and sourcecaller='"+me.FlowCaller+"'"+" order by detno"
});
}
}
});
},
getTiggerProcessNodeItems:function(){
var grid=Ext.getCmp('taskgrid');
var tabpanel=grid.ownerCt;
var nodegrid=tabpanel.items.items[0];
var items=new Array();
Ext.Array.each(nodegrid.store.data.items,function(item){
items.push({text:item.data.JP_NODENAME});
});
return items;
},
setTriggerType:function(item){
var grid=Ext.getCmp('taskgrid');
var selected=grid.getSelectionModel().getSelection()[0];
selected.set('triggertype',item.text);
},
loadNewStore:function(grid,caller,id){
grid.GridUtil.loadNewStore(grid,{
caller:'ProjectMainTask',
condition:'sourceid='+id+" and sourcecaller='"+caller+"'" +" order by detno"
});
}
});