Ext.ns('App'); Ext.Loader.setConfig({ enabled: true, disableCaching : true, paths : { 'App': '/ERP/app/projectscheduler' } }); Ext.onReady(function() { Localize(); function getUrlParam(name){ var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)"); var r=window.location.search.substr(1).match(reg); if (r!=null) return decodeURI(r[2]); return null; }; var formCondition = getUrlParam('formCondition'); var prjName=getUrlParam('prjName'); var StartDate = new Date(getUrlParam('startDate')); var EndDate = new Date(getUrlParam('endDate')); var idlevel= getUrlParam('level'); StartDate =Ext.Date.add( StartDate, Ext.Date.DAY, -5); EndDate = Ext.Date.add( EndDate, Ext.Date.DAY, 5); App.Gantt.init(StartDate,EndDate,formCondition,idlevel,basePath,prjName); Ext.QuickTips.init(); }); Ext.require([ 'App.ProjectGanttPan' ]); App.Gantt = { init : function(StartDate,EndDate,formCondition,idlevel,basePath,prjName) { Ext.define('MyResource', { extend: 'Gnt.model.Resource', idProperty : 'id', nameField:'Name', fields: [{name:'id',type:'int'},{name:'Name',type:'string'}] }); var resourceStore = Ext.create("Gnt.data.ResourceStore", { model:'MyResource', autoLoad: true, proxy: { type: 'ajax', extraParams :{ condition:formCondition }, api: { create: basePath+'market/resource/createResource.action', read: basePath+'market/resource.action', update: basePath+'market/resource/updateResource.action', destroy: basePath+'market/resource/deleteResource.action' }, reader: { type: 'json', root:'data' }, writer:{ type:'json' }, async:false } }); Ext.define('MarketTaskModel', { extend : 'Gnt.model.Task', clsField : 'TaskType', idProperty:'id', fields : [ { name : 'index', type : 'int' }, { name : 'TaskType', type : 'string' }, { name : 'TaskColor', type : 'string'}, { name : 'parentId', type: 'int', defaultValue: 0, convert:function(a){return a + 0}}, { name : 'expanded', type : 'boolean' }, { name : 'id', type : 'int' } ] }); var taskStore = Ext.create("Gnt.data.TaskStore", { model:'MarketTaskModel', proxy: { type: 'ajax', extraParams :{ condition:formCondition, level:idlevel }, api: { create: basePath+'market/gantt/updateGantt.action', read: basePath+'market/getGantt.action', update: basePath+'market/gantt/updateGantt.action', destroy: basePath+'market/gantt/deleteGantt.action' }, reader: { type: 'json' }, writer:{ type:'json' }, async:false } }); var gantt = this.createGantt({ resourceStore : resourceStore, taskStore : taskStore, startDate : StartDate, endDate : EndDate, formCondition : formCondition, prjName : prjName, level : idlevel }); var scheduler = this.createScheduler({ resourceStore : resourceStore, eventStore : taskStore, timeAxis : gantt.getTimeAxis(), plugins : new Sch.plugin.Zones({ store : gantt.getWorkingTimePlugin().store }) }); var vp = new Ext.Viewport({ layout : 'border', items : [gantt, scheduler] }); var ganttViewEl = gantt.getSchedulingView().el; var schedulerViewEl = scheduler.getSchedulingView().el; schedulerViewEl.on('scroll', function(ev, el) { ganttViewEl.scrollTo('left', el.scrollLeft); }); ganttViewEl.on('scroll', function(ev, el) { schedulerViewEl.scrollTo('left', el.scrollLeft); }); var fullRefresh = function() { scheduler.getSchedulingView().refresh(); }; gantt.getAssignmentStore().on({ update : fullRefresh, add : fullRefresh, remove : fullRefresh, refresh : fullRefresh, buffer : 1 }) }, createScheduler : function(config) { return Ext.create("Sch.SchedulerPanel", Ext.apply({ viewPreset : 'weekAndDayLetter', enableDragCreation : false, height : 200, region : 'south', split : true, columns : [ {header : '员工姓名', width:210, dataIndex : 'Name'} ] }, config)); }, createGantt : function(config) { Ext.define('MyAssignment', { extend: 'Gnt.model.Assignment', idProperty : 'id', fields: [{name:'id',type:'int'},{name:'TaskId',type:'int'},{name:'ResourceId',type:'int'}] }); var assignmentStore = Ext.create("Gnt.data.AssignmentStore", { model:'MyAssignment', resourceStore : config.resourceStore, autoLoad:true, proxy: { type: 'ajax', extraParams :{ condition:config.formCondition, level :config.level }, api: { create:basePath+ 'market/updateAssignment.action', read: basePath+'market/getAssignment.action', update: basePath+'market/updateAssignment.action', destroy: basePath+'market/deleteAssignment.action' }, reader: { type: 'json', root: 'data' }, writer:{ type:'json' }, async:false } }); var dependencyStore = Ext.create("Gnt.data.DependencyStore", { autoLoad: true, proxy: { type: 'ajax', extraParams :{ condition:config.formCondition }, api: { create: basePath+'market/gantt/updateDependency.action', read: basePath+'market/gantt/getDependency.action', update: basePath+'market/gantt/updateDependency.action', destroy: basePath+'market/gantt/deleteDependency.action' }, reader: { type: 'json', root: 'data' }, writer:{ type:'json' } } }); return Ext.create("App.ProjectGanttPan", Ext.apply({ region : 'center', leftLabelField : 'Name', highlightWeekends : true, loadMask : true, snapToIncrement : true, rightLabelField : { dataIndex : 'id', renderer : function(value, record) { return '任务id: #' + value; } }, title : '项目计划明细: '+config.prjName+'', viewPreset : 'weekAndDayLetter', columns : [ { xtype : 'treecolumn', header : '任务', sortable:true, dataIndex : 'Name', width:200 }, { header : '资源分配', width:150, xtype : 'resourceassignmentcolumn' } ], assignmentStore : assignmentStore, dependencyStore : dependencyStore }, config)); } };