projectScheduler.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. Ext.ns('App');
  2. Ext.Loader.setConfig({
  3. enabled: true,
  4. disableCaching : true,
  5. paths : {
  6. 'App': '/ERP/app/projectscheduler'
  7. }
  8. });
  9. Ext.onReady(function() {
  10. Localize();
  11. function getUrlParam(name){
  12. var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
  13. var r=window.location.search.substr(1).match(reg);
  14. if (r!=null) return decodeURI(r[2]);
  15. return null;
  16. };
  17. var formCondition = getUrlParam('formCondition');
  18. var prjName=getUrlParam('prjName');
  19. var StartDate = new Date(getUrlParam('startDate'));
  20. var EndDate = new Date(getUrlParam('endDate'));
  21. var idlevel= getUrlParam('level');
  22. StartDate =Ext.Date.add( StartDate, Ext.Date.DAY, -5);
  23. EndDate = Ext.Date.add( EndDate, Ext.Date.DAY, 5);
  24. App.Gantt.init(StartDate,EndDate,formCondition,idlevel,basePath,prjName);
  25. Ext.QuickTips.init();
  26. });
  27. Ext.require([
  28. 'App.ProjectGanttPan'
  29. ]);
  30. App.Gantt = {
  31. init : function(StartDate,EndDate,formCondition,idlevel,basePath,prjName) {
  32. Ext.define('MyResource', {
  33. extend: 'Gnt.model.Resource',
  34. idProperty : 'id',
  35. nameField:'Name',
  36. fields: [{name:'id',type:'int'},{name:'Name',type:'string'}]
  37. });
  38. var resourceStore = Ext.create("Gnt.data.ResourceStore", {
  39. model:'MyResource',
  40. autoLoad: true,
  41. proxy: {
  42. type: 'ajax',
  43. extraParams :{
  44. condition:formCondition
  45. },
  46. api: {
  47. create: basePath+'market/resource/createResource.action',
  48. read: basePath+'market/resource.action',
  49. update: basePath+'market/resource/updateResource.action',
  50. destroy: basePath+'market/resource/deleteResource.action'
  51. },
  52. reader: {
  53. type: 'json',
  54. root:'data'
  55. },
  56. writer:{
  57. type:'json'
  58. },
  59. async:false
  60. }
  61. });
  62. Ext.define('MarketTaskModel', {
  63. extend : 'Gnt.model.Task',
  64. clsField : 'TaskType',
  65. idProperty:'id',
  66. fields : [
  67. { name : 'index', type : 'int' },
  68. { name : 'TaskType', type : 'string' },
  69. { name : 'TaskColor', type : 'string'},
  70. { name : 'parentId', type: 'int', defaultValue: 0, convert:function(a){return a + 0}},
  71. { name : 'expanded', type : 'boolean' },
  72. { name : 'id', type : 'int' }
  73. ]
  74. });
  75. var taskStore = Ext.create("Gnt.data.TaskStore", {
  76. model:'MarketTaskModel',
  77. proxy: {
  78. type: 'ajax',
  79. extraParams :{
  80. condition:formCondition,
  81. level:idlevel
  82. },
  83. api: {
  84. create: basePath+'market/gantt/updateGantt.action',
  85. read: basePath+'market/getGantt.action',
  86. update: basePath+'market/gantt/updateGantt.action',
  87. destroy: basePath+'market/gantt/deleteGantt.action'
  88. },
  89. reader: {
  90. type: 'json'
  91. },
  92. writer:{
  93. type:'json'
  94. },
  95. async:false
  96. }
  97. });
  98. var gantt = this.createGantt({
  99. resourceStore : resourceStore,
  100. taskStore : taskStore,
  101. startDate : StartDate,
  102. endDate : EndDate,
  103. formCondition : formCondition,
  104. prjName : prjName,
  105. level : idlevel
  106. });
  107. var scheduler = this.createScheduler({
  108. resourceStore : resourceStore,
  109. eventStore : taskStore,
  110. timeAxis : gantt.getTimeAxis(),
  111. plugins : new Sch.plugin.Zones({
  112. store : gantt.getWorkingTimePlugin().store
  113. })
  114. });
  115. var vp = new Ext.Viewport({
  116. layout : 'border',
  117. items : [gantt, scheduler]
  118. });
  119. var ganttViewEl = gantt.getSchedulingView().el;
  120. var schedulerViewEl = scheduler.getSchedulingView().el;
  121. schedulerViewEl.on('scroll', function(ev, el) { ganttViewEl.scrollTo('left', el.scrollLeft); });
  122. ganttViewEl.on('scroll', function(ev, el) { schedulerViewEl.scrollTo('left', el.scrollLeft); });
  123. var fullRefresh = function() {
  124. scheduler.getSchedulingView().refresh();
  125. };
  126. gantt.getAssignmentStore().on({
  127. update : fullRefresh,
  128. add : fullRefresh,
  129. remove : fullRefresh,
  130. refresh : fullRefresh,
  131. buffer : 1
  132. })
  133. },
  134. createScheduler : function(config) {
  135. return Ext.create("Sch.SchedulerPanel", Ext.apply({
  136. viewPreset : 'weekAndDayLetter',
  137. enableDragCreation : false,
  138. height : 200,
  139. region : 'south',
  140. split : true,
  141. columns : [
  142. {header : '员工姓名', width:210, dataIndex : 'Name'}
  143. ]
  144. }, config));
  145. },
  146. createGantt : function(config) {
  147. Ext.define('MyAssignment', {
  148. extend: 'Gnt.model.Assignment',
  149. idProperty : 'id',
  150. fields: [{name:'id',type:'int'},{name:'TaskId',type:'int'},{name:'ResourceId',type:'int'}]
  151. });
  152. var assignmentStore = Ext.create("Gnt.data.AssignmentStore", {
  153. model:'MyAssignment',
  154. resourceStore : config.resourceStore,
  155. autoLoad:true,
  156. proxy: {
  157. type: 'ajax',
  158. extraParams :{
  159. condition:config.formCondition,
  160. level :config.level
  161. },
  162. api: {
  163. create:basePath+ 'market/updateAssignment.action',
  164. read: basePath+'market/getAssignment.action',
  165. update: basePath+'market/updateAssignment.action',
  166. destroy: basePath+'market/deleteAssignment.action'
  167. },
  168. reader: {
  169. type: 'json',
  170. root: 'data'
  171. },
  172. writer:{
  173. type:'json'
  174. },
  175. async:false
  176. }
  177. });
  178. var dependencyStore = Ext.create("Gnt.data.DependencyStore", {
  179. autoLoad: true,
  180. proxy: {
  181. type: 'ajax',
  182. extraParams :{
  183. condition:config.formCondition
  184. },
  185. api: {
  186. create: basePath+'market/gantt/updateDependency.action',
  187. read: basePath+'market/gantt/getDependency.action',
  188. update: basePath+'market/gantt/updateDependency.action',
  189. destroy: basePath+'market/gantt/deleteDependency.action'
  190. },
  191. reader: {
  192. type: 'json',
  193. root: 'data'
  194. },
  195. writer:{
  196. type:'json'
  197. }
  198. }
  199. });
  200. return Ext.create("App.ProjectGanttPan", Ext.apply({
  201. region : 'center',
  202. leftLabelField : 'Name',
  203. highlightWeekends : true,
  204. loadMask : true,
  205. snapToIncrement : true,
  206. rightLabelField : {
  207. dataIndex : 'id',
  208. renderer : function(value, record) {
  209. return '任务id: #' + value;
  210. }
  211. },
  212. title : '<h style="color: red"><b>项目计划明细: '+config.prjName+'</b></h>',
  213. viewPreset : 'weekAndDayLetter',
  214. columns : [
  215. {
  216. xtype : 'treecolumn',
  217. header : '任务',
  218. sortable:true,
  219. dataIndex : 'Name',
  220. width:200
  221. },
  222. {
  223. header : '资源分配',
  224. width:150,
  225. xtype : 'resourceassignmentcolumn'
  226. }
  227. ],
  228. assignmentStore : assignmentStore,
  229. dependencyStore : dependencyStore
  230. }, config));
  231. }
  232. };