task.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. Ext.require(['Gnt.plugin.TaskContextMenu', 'Sch.plugin.TreeCellEditing',
  2. 'Sch.plugin.Pan', 'Gnt.panel.Gantt', 'Gnt.column.PercentDone',
  3. 'Gnt.column.StartDate', 'Gnt.column.EndDate', 'Gnt.plugin.Printable',
  4. 'Gnt.widget.AssignmentCellEditor', 'Gnt.column.ResourceAssignment',
  5. 'Gnt.model.Assignment', 'erp.util.BaseUtil', 'Gnt.widget.Calendar']);
  6. Ext.onReady(function() {
  7. Gantt.init();
  8. Ext.QuickTips.init();
  9. });
  10. Gantt = {
  11. //tx2x9saq
  12. init : function() {
  13. Ext.define('Gnt.column.ResourceName', {
  14. extend : 'Gnt.column.ResourceName',
  15. text : "执行人"
  16. });
  17. Ext.define('Gnt.column.AssignmentUnits', {
  18. extend : 'Gnt.column.AssignmentUnits',
  19. text : "分配比例"
  20. });
  21. Ext.define('Gnt.widget.AssignmentField', {
  22. extend : 'Gnt.widget.AssignmentField',
  23. cancelText : "取消",
  24. closeText : "保存并关闭"
  25. });
  26. Ext.define('TaskResource', {
  27. extend : 'Sch.model.Resource',
  28. idProperty : 'EmCode',
  29. nameField : 'Name',
  30. fields : ['EmCode', 'Name', 'Id', 'EmId']
  31. });
  32. var taskResourceStore = Ext.create("Sch.data.ResourceStore", {
  33. model : 'TaskResource',
  34. autoLoad : true,
  35. // autoSync : true,
  36. proxy : {
  37. type : 'ajax',
  38. method : 'POST',
  39. reader : {
  40. root : 'resources',
  41. type : 'json'
  42. },
  43. extraParams : {
  44. condition : 'prjplan_id=3147'// formCondition
  45. },
  46. api : {
  47. read : basePath + 'task/resource.action'
  48. /*
  49. * create : 'e-create.php', destroy :
  50. * 'e-destroy.php', update : 'e-update.php'
  51. */
  52. },
  53. writer : {
  54. type : 'json',
  55. root : 'resources',
  56. encode : true,
  57. writeAllFields : true,
  58. listful : true,
  59. allowSingle : false
  60. }
  61. }
  62. });
  63. Ext.define('TaskEvent', {
  64. extend : 'Sch.model.Event',
  65. nameField : 'Name',
  66. startDateField : 'StartDate',
  67. endDateField : 'EndDate',
  68. resourceIdField : 'ResourceId',
  69. fields : [
  70. // Define your own model fields
  71. {
  72. name : 'StartDate',
  73. type : 'date',
  74. dateFormat : 'Y-m-d'
  75. }, {
  76. name : 'EndDate',
  77. type : 'date',
  78. dateFormat : 'Y-m-d'
  79. }, 'Name', 'ResourceId', 'TaskId']
  80. });
  81. Ext.define('MyResourceModel', {
  82. extend : 'Gnt.model.Resource',
  83. fields : [{
  84. name : 'EmCode',
  85. type : 'string'
  86. }, {
  87. name : 'EmId',
  88. type : 'int'
  89. }]
  90. });
  91. var resourceStore = Ext.create("Gnt.data.ResourceStore", {
  92. model : 'MyResourceModel',
  93. proxy : {
  94. type : 'ajax',
  95. method : 'GET',
  96. url : basePath + 'plm/resourceassignment.action',
  97. root : 'resources',
  98. reader : {
  99. type : 'json'
  100. }
  101. }
  102. });
  103. Ext.define('MyTaskModel', {
  104. extend : 'Gnt.model.Task',
  105. clsField : 'TaskType',
  106. fields : [{
  107. name : 'TaskType',
  108. type : 'string'
  109. }, {
  110. name : 'TaskColor',
  111. type : 'string'
  112. }, {
  113. name : 'prjplanid',
  114. type : 'int'
  115. }, {
  116. name : 'prjplanname',
  117. type : 'string'
  118. }, {
  119. name : 'recorder',
  120. type : 'string'
  121. }, {
  122. name : 'recorddate',
  123. type : 'string'
  124. }, {
  125. name : 'taskcode',
  126. type : 'string'
  127. }, {
  128. name : 'id',
  129. type : 'int'
  130. }]
  131. });
  132. Ext.define('MyDependencyModel', {
  133. extend : 'Gnt.model.Dependency',
  134. fields : [{
  135. name : 'Id',
  136. type : 'int'
  137. }]
  138. });
  139. var taskStore = Ext.create("Gnt.data.TaskStore", {
  140. model : 'MyTaskModel',
  141. sorters : 'StartDate',
  142. proxy : {
  143. type : 'ajax',
  144. headers : {
  145. "Content-Type" : 'application/json'
  146. },
  147. extraParams : {
  148. condition : 'prjplan_id=3147'// formCondition
  149. },
  150. api : {
  151. read : basePath + 'plm/gantt.action',
  152. create : basePath + 'plm/ganttcreate.action',
  153. destroy : 'webservices/Tasks.asmx/Delete',
  154. update : basePath + 'plm/ganttupdate.action'
  155. },
  156. writer : {
  157. type : 'json',
  158. root : 'jsonData',
  159. encode : true,
  160. nameProperty : 'data',
  161. allowSingle : false
  162. },
  163. reader : {
  164. type : 'json'
  165. }
  166. }
  167. });
  168. var allTaskStore = Ext.create("Sch.data.EventStore", {
  169. model : 'TaskEvent',
  170. resourceStore : taskResourceStore,
  171. autoLoad : true,
  172. proxy : {
  173. type : 'ajax',
  174. method : 'POST',
  175. reader : {
  176. root : 'assignments',
  177. type : 'json'
  178. },
  179. extraParams : {
  180. condition : 'prjplan_id=3147' // formCondition
  181. },
  182. api : {
  183. read : basePath + 'task/assignment.action'
  184. /*
  185. * create : 'e-create.php', destroy :
  186. * 'e-destroy.php', update : 'e-update.php'
  187. */
  188. },
  189. writer : {
  190. type : 'json',
  191. root : 'assignments',
  192. encode : true,
  193. writeAllFields : true,
  194. listful : true,
  195. allowSingle : false
  196. }
  197. }
  198. })
  199. var gantt = this.createGantt({
  200. resourceStore : resourceStore,
  201. taskStore : taskStore
  202. });
  203. var scheduler = this.createScheduler({
  204. resourceStore : resourceStore,
  205. eventStore : taskStore,
  206. // Share time axis
  207. timeAxis : gantt.getTimeAxis(),
  208. lockedGridConfig : {
  209. resizeHandles : 'e',
  210. resizable : {
  211. pinned : true
  212. },
  213. width : 300
  214. },
  215. // Share non-working time visualization
  216. plugins : new Sch.plugin.Zones({
  217. store : gantt.getWorkingTimePlugin().store
  218. })
  219. });
  220. var allTask = this.createAllTask({
  221. resourceStore : taskResourceStore,
  222. eventStore : allTaskStore
  223. });
  224. var vp = new Ext.Viewport({
  225. layout : 'border',
  226. items : [gantt, scheduler, allTask]
  227. });
  228. var ganttViewEl = gantt.getSchedulingView().el;
  229. var schedulerViewEl = scheduler.getSchedulingView().el;
  230. // Sync the scrolling
  231. schedulerViewEl.on('scroll', function(ev, el) {
  232. ganttViewEl.scrollTo('left', el.scrollLeft);
  233. });
  234. ganttViewEl.on('scroll', function(ev, el) {
  235. schedulerViewEl.scrollTo('left', el.scrollLeft);
  236. });
  237. var fullRefresh = function() {
  238. scheduler.getSchedulingView().refresh();
  239. };
  240. // Since scheduler doesn't (yet) know of assignments, give it some help
  241. gantt.getAssignmentStore().on({
  242. update : fullRefresh,
  243. add : fullRefresh,
  244. remove : fullRefresh,
  245. refresh : fullRefresh,
  246. buffer : 1
  247. })
  248. },
  249. createAllTask : function(config) {
  250. return allTaskPanel = Ext.create("Sch.panel.SchedulerGrid", Ext.apply({
  251. title : '员工全部任务情况',
  252. eventBarTextField : 'Name',
  253. viewPreset : 'dayAndWeek',
  254. height : 20,
  255. region : 'south',
  256. split : true,
  257. timeAxis : gantt.getTimeAxis(),
  258. viewConfig : {
  259. forceFit : false
  260. },
  261. columns : [{
  262. header : 'Name',
  263. width : 130,
  264. dataIndex : 'Name'
  265. }]
  266. }, config));
  267. },
  268. createScheduler : function(config) {
  269. return A = Ext.create("Sch.SchedulerPanel", Ext.apply({
  270. // title : 'Resource panel',
  271. viewPreset : 'weekAndDayLetter',
  272. enableDragCreation : false,
  273. height : 20,
  274. layout : 'fit',
  275. region : 'south',
  276. split : true,
  277. columns : [{
  278. header : '员工姓名',
  279. width : 300,
  280. dataIndex : 'Name'
  281. }]
  282. }, config));
  283. },
  284. createGantt : function(config) {
  285. var BaseUtil = Ext.create('erp.util.BaseUtil');
  286. var startDate = new Date(2012, 9, 11);
  287. var endDate = Sch.util.Date.add(new Date(2012, 9, 11),
  288. Sch.util.Date.WEEK, 20);
  289. var start = new Date(2012, 9, 20), end = Sch.util.Date.add(new Date(
  290. 2012, 10, 20), Sch.util.Date.WEEK, 20);
  291. var calendar = new Gnt.data.Calendar({
  292. data : [{
  293. Date : new Date(2010, 0, 13),
  294. Cls : 'gnt-national-holiday'
  295. }, {
  296. Date : new Date(2010, 1, 1),
  297. Cls : 'gnt-company-holiday'
  298. }, {
  299. Date : new Date(2010, 0, 16),
  300. IsWorkingDay : true
  301. }]
  302. });
  303. Ext.define('MyAssignmentModel', {
  304. extend : 'Gnt.model.Assignment'
  305. });
  306. var assignmentStore = Ext.create("Gnt.data.AssignmentStore", {
  307. model : 'MyAssignmentModel',
  308. autoLoad : true,
  309. resourceStore : config.resourceStore,
  310. proxy : {
  311. method : 'GET',
  312. type : 'ajax',
  313. url : basePath + 'plm/resourceassignment.action',
  314. extraParams : {
  315. condition : 'prjplan_id=3147'// formCondition
  316. },
  317. reader : {
  318. type : 'json',
  319. root : 'assignments'
  320. }
  321. },
  322. listeners : {
  323. load : function() {
  324. config.resourceStore
  325. .loadData(this.proxy.reader.jsonData.resources);
  326. }
  327. }
  328. });
  329. var dependencyStore = Ext.create("Gnt.data.DependencyStore", {
  330. model : 'MyDependencyModel',
  331. autoLoad : true,
  332. proxy : {
  333. type : 'ajax',
  334. extraParams : {
  335. condition : 'prjplan_id=3147'// formCondition
  336. },
  337. url : basePath + 'plm/gantt/getdependency.action',
  338. method : 'GET',
  339. reader : {
  340. type : 'json',
  341. root : 'dependency'
  342. }
  343. }
  344. });
  345. var formCondition = 'prjplan_id=3147'//'prjplan_id=3147';
  346. return gantt = Ext.create("Gnt.panel.Gantt", Ext.apply({
  347. id : 'ganttid',
  348. region : 'center',
  349. leftLabelField : 'Name',
  350. highlightWeekends : true,
  351. loadMask : true,
  352. snapToIncrement : true,
  353. // title : 'Gantt panel with tasks and resources',
  354. startDate : new Date(2012, 9, 11),
  355. endDate : Sch.util.Date.add(new Date(2012, 11, 11),
  356. Sch.util.Date.WEEK, 20),
  357. viewPreset : 'weekAndDayLetter',
  358. tbar : [/*
  359. * { text : 'Previous', handler : function() { //
  360. * this.up('ganttpanel').shiftPrevious(); var m = window.A;
  361. * var n = Window.s2; m.height = 0; console.log(window); } }, {
  362. * text : 'Next', handler : function() { window.A = 200;
  363. * window.refresh; // this.up('ganttpanel').shiftNext(); } },
  364. */{
  365. xtype : 'buttongroup',
  366. title : '视图工具',
  367. columns : 3,
  368. items : [{
  369. iconCls : 'icon-prev',
  370. text : '向前',
  371. scope : this,
  372. handler : function() {
  373. gantt.shiftPrevious();
  374. }
  375. }, {
  376. iconCls : 'icon-next',
  377. text : '向后',
  378. scope : this,
  379. handler : function() {
  380. gantt.shiftNext();
  381. }
  382. }, {
  383. text : '缩放',
  384. iconCls : 'zoomfit',
  385. handler : function() {
  386. gantt.zoomToFit();
  387. },
  388. scope : this
  389. }, {
  390. text : '收缩',
  391. iconCls : 'icon-collapseall',
  392. scope : this,
  393. handler : function() {
  394. gantt.collapseAll();
  395. }
  396. }, {
  397. text : '展开',
  398. iconCls : 'icon-expandall',
  399. scope : this,
  400. loader : {
  401. loadMask : true
  402. },
  403. handler : function() {
  404. var loadMask = gantt.setLoading("正在展开",
  405. true);
  406. gantt.expandAll(loadMask.hide());
  407. // g.expandAll();
  408. }
  409. }, {
  410. iconCls : 'togglebutton',
  411. enableToggle : true,
  412. id : 'readonlybutton',
  413. text : '只读',
  414. pressed : true
  415. }]
  416. }, {
  417. xtype : 'buttongroup',
  418. title : '视图解析',
  419. columns : 2,
  420. items : [{
  421. iconCls : 'gnt-date',
  422. text : '6 周',
  423. scope : this,
  424. handler : function() {
  425. gantt.switchViewPreset('weekAndMonth');
  426. }
  427. }, {
  428. iconCls : 'gnt-date',
  429. text : '10周',
  430. scope : this,
  431. handler : function() {
  432. gantt
  433. .switchViewPreset('weekAndDayLetter');
  434. }
  435. }, {
  436. iconCls : 'gnt-date',
  437. text : '1 年',
  438. scope : this,
  439. handler : function() {
  440. gantt.switchViewPreset('monthAndYear');
  441. }
  442. }, {
  443. iconCls : 'gnt-date',
  444. text : '5 年',
  445. scope : this,
  446. handler : function() {
  447. var start = new Date(this.getStart()
  448. .getFullYear(), 0);
  449. gantt.switchViewPreset('monthAndYear',
  450. start, Ext.Date.add(start,
  451. Ext.Date.YEAR, 5));
  452. }
  453. }]
  454. }, {
  455. xtype : 'buttongroup',
  456. title : '操作区',
  457. columns : 3,
  458. items : [{
  459. iconCls : 'x-advance-print',
  460. text : '打印',
  461. handler : function() {
  462. // Make sure this fits horizontally on
  463. // one page.
  464. Ext.getCmp('gantt').zoomToFit();
  465. Ext.getCmp('gantt').print();
  466. }
  467. }, {
  468. text : '添加任务',
  469. iconCls : 'x-advance-add',
  470. handler : function() {
  471. var selectItem = gantt.selModel.selected.items[0];
  472. if (selectItem) {
  473. if (selectItem.data.Id) {
  474. Ext.Ajax.request({
  475. url : basePath
  476. + "plm/gantt/getData.action",
  477. params : {
  478. condition : formCondition
  479. },
  480. method : 'get',
  481. callback : function(
  482. options, success,
  483. response) {
  484. var rs = new Ext.decode(response.responseText);
  485. if (rs.exceptionInfo) {
  486. showError(rs.exceptionInfo);
  487. return;
  488. }
  489. if (rs.success) {
  490. var newTask = new gantt.taskStore.model(
  491. {
  492. Name : 'New task',
  493. leaf : true,
  494. PercentDone : 0,
  495. prjplanid : rs.data.prjplandata[0].prjplan_id,
  496. prjplanname : rs.data.prjplandata[0].prjplan_prjname,
  497. // taskcode:BaseUtil.getRandomNumber(),
  498. taskcode : (new Date())
  499. .getTime(),
  500. recorder : recorder,
  501. recorddate : recorddate,
  502. StartDate : selectItem.data.StartDate,// 给系统的默认时间
  503. EndDate : selectItem.data.EndDate
  504. });
  505. var record = gantt.selModel.selected.items[0];
  506. if (record.data.leaf) {
  507. record.data.leaf = false;
  508. record.data.expanded = true;
  509. }
  510. record
  511. .appendChild(newTask);
  512. }
  513. }
  514. });
  515. } else {
  516. showError("任务未生成不能给他添加子任务!");
  517. }
  518. } else {
  519. showError("请选择添加任务的父节点!");
  520. }
  521. }
  522. }, {
  523. text : '添加父任务',
  524. iconCls : 'x-advance-add',
  525. handler : function() {
  526. Ext.Ajax.request({
  527. url : basePath
  528. + "plm/gantt/getData.action",
  529. params : {
  530. condition : formCondition
  531. },
  532. method : 'get',
  533. callback : function(options,
  534. success, response) {
  535. var rs = new Ext.decode(response.responseText);
  536. if (rs.exceptionInfo) {
  537. showError(rs.exceptionInfo);
  538. return;
  539. }
  540. if (rs.success) {
  541. var newTask = new gantt.taskStore.model(
  542. {
  543. Name : 'New task',
  544. leaf : false,
  545. PercentDone : 0,
  546. prjplanid : rs.data.prjplandata[0].prjplan_id,
  547. prjplanname : rs.data.prjplandata[0].prjplan_prjname,
  548. // taskcode:BaseUtil.getRandomNumber(),
  549. recorder : recorder,
  550. recorddate : recorddate,
  551. parentId : 0
  552. });
  553. taskStore
  554. .getRootNode()
  555. .appendChild(newTask)
  556. }
  557. }
  558. });
  559. }
  560. },
  561. {
  562. iconCls : 'x-advance-save',
  563. id : 'savebutton',
  564. text : '保存',
  565. listeners : {
  566. 'afterrender' : function(btn, opts) {
  567. if (Ext.getCmp('readonlybutton').pressed) {
  568. btn.setDisabled(false);
  569. }
  570. }
  571. },
  572. handler : function() {
  573. // g.checkstore();//验证store是否填写完整 要求必填字段
  574. // 如 日期
  575. // 并且开始时间要小于或等于结束时间
  576. var options = {}, me = gantt.taskStore;
  577. de = gantt.dependencyStore;
  578. as = gantt.assignmentStore;
  579. var toCreate = me.getNewRecords(), toUpdate = me
  580. .getUpdatedRecords(), toDestroy = me
  581. .getRemovedRecords(), toCreateDependency = de
  582. .getNewRecords(), toDestroyDependency = de
  583. .getRemovedRecords(), toCreateassign = as
  584. .getNewRecords(), toUpdateassign = as
  585. .getUpdatedRecords(), toDestroyassign = as
  586. .getRemovedRecords(), needsSync = false;
  587. if (toCreate.length > 0) {
  588. var create = null;
  589. options.create = toCreate;
  590. var index = 0;
  591. var jsonData = new Array();
  592. for (var i = 0; i < toCreate.length; i++) {
  593. var data = toCreate[i].data;
  594. jsonData[index++] = Ext.JSON
  595. .encode(data)
  596. + '#@';
  597. }
  598. Ext.Ajax.request({
  599. url : basePath
  600. + "plm/gantt/ganttcreate.action",
  601. params : {
  602. jsonData : unescape(jsonData
  603. .toString()
  604. .replace(/\\/g, "%"))
  605. },
  606. method : 'post',
  607. callback : function(options,
  608. success, response) {
  609. }
  610. });
  611. }
  612. if (toUpdate.length > 0) {
  613. options.update = toUpdate;
  614. needsSync = true;
  615. var index = 0;
  616. var jsonData = new Array();
  617. for (var i = 0; i < toUpdate.length; i++) {
  618. var data = toUpdate[i].data;
  619. jsonData[index++] = Ext.JSON
  620. .encode(data)
  621. + '#@';
  622. }
  623. Ext.Ajax.request({
  624. url : basePath
  625. + "plm/gantt/ganttupdate.action",
  626. params : {
  627. jsonData : unescape(jsonData
  628. .toString()
  629. .replace(/\\/g, "%"))
  630. },
  631. method : 'post',
  632. callback : function(options,
  633. success, response) {
  634. }
  635. });
  636. }
  637. if (toDestroy.length > 0) {
  638. options.destroy = toDestroy;
  639. needsSync = true;
  640. var index = 0;
  641. var jsonData = new Array();
  642. for (var i = 0; i < toDestroy.length; i++) {
  643. var data = toDestroy[i].data;
  644. jsonData[index++] = Ext.JSON
  645. .encode(data)
  646. + '#@';
  647. }
  648. Ext.Ajax.request({
  649. url : basePath
  650. + "plm/gantt/ganttdelete.action",
  651. params : {
  652. jsonData : unescape(jsonData
  653. .toString()
  654. .replace(/\\/g, "%"))
  655. },
  656. method : 'post',
  657. callback : function(options,
  658. success, response) {
  659. }
  660. });
  661. }
  662. if (toCreateDependency.length > 0) {
  663. var index = 0;
  664. var jsonData = new Array();
  665. for (var i = 0; i < toCreateDependency.length; i++) {
  666. var data = toCreateDependency[i].data;
  667. jsonData[index++] = Ext.JSON
  668. .encode(data);
  669. }
  670. Ext.Ajax.request({
  671. url : basePath
  672. + "plm/gantt/dependencycreate.action",
  673. params : {
  674. condition : formCondition,
  675. jsonData : unescape(jsonData
  676. .toString()
  677. .replace(/\\/g, "%"))
  678. },
  679. method : 'post',
  680. callback : function(options,
  681. success, response) {
  682. }
  683. });
  684. }
  685. if (toDestroyDependency.length > 0) {
  686. var index = 0;
  687. var jsonData = new Array();
  688. for (var i = 0; i < toDestroyDependency.length; i++) {
  689. var data = toDestroyDependency[i].data;
  690. jsonData[index++] = Ext.JSON
  691. .encode(data);
  692. }
  693. Ext.Ajax.request({
  694. url : basePath
  695. + "plm/gantt/dependencydelete.action",
  696. params : {
  697. jsonData : unescape(jsonData
  698. .toString()
  699. .replace(/\\/g, "%"))
  700. },
  701. method : 'post',
  702. callback : function(options,
  703. success, response) {
  704. }
  705. });
  706. }
  707. if (toCreateassign.length > 0) {
  708. var index = 0;
  709. var jsonData = new Array();
  710. for (var i = 0; i < toCreateassign.length; i++) {
  711. // var
  712. // ddd=g.selModel.selected.items[0];
  713. var data = toCreateassign[i].data;
  714. var id = data.TaskId;
  715. var task = gantt.taskStore
  716. .getById(id);
  717. var resourceId = data.ResourceId;
  718. var resource = gantt.resourceStore
  719. .getById(resourceId);
  720. data.StartDate = task.data.StartDate;
  721. data.EndDate = task.data.EndDate;
  722. data.resourcecode = resource.data.EmCode;
  723. data.detno = 1;
  724. data.Id = 0;
  725. data.resourcename = resource.data.Name;
  726. data_resourcetype = "";
  727. data.taskname = task.data.Name;
  728. data.emid = resource.data.EmId;
  729. data.prjid = task.data.prjplanid;
  730. data.prjname = task.data.prjplanname;
  731. jsonData[index++] = Ext.JSON
  732. .encode(data);
  733. }
  734. Ext.Ajax.request({
  735. url : basePath
  736. + "plm/resource/createResource.action",
  737. params : {
  738. jsonData : unescape(jsonData
  739. .toString()
  740. .replace(/\\/g, "%"))
  741. },
  742. method : 'post',
  743. callback : function(options,
  744. success, response) {
  745. }
  746. });
  747. }
  748. if (toUpdateassign.length > 0) {
  749. var index = 0;
  750. var jsonData = new Array();
  751. for (var i = 0; i < toUpdateassign.length; i++) {
  752. var data = toUpdateassign[i].data;
  753. jsonData[index++] = Ext.JSON
  754. .encode(data);
  755. }
  756. Ext.Ajax.request({
  757. url : basePath
  758. + "plm/resource/updateResource.action",
  759. params : {
  760. jsonData : unescape(jsonData
  761. .toString()
  762. .replace(/\\/g, "%"))
  763. },
  764. method : 'post',
  765. callback : function(options,
  766. success, response) {
  767. }
  768. });
  769. }
  770. if (toDestroyassign.length > 0) {
  771. var index = 0;
  772. var jsonData = new Array();
  773. for (var i = 0; i < toDestroyassign.length; i++) {
  774. var data = toDestroyassign[i].data;
  775. jsonData[index++] = Ext.JSON
  776. .encode(data);
  777. }
  778. Ext.Ajax.request({
  779. url : basePath
  780. + "plm/resource/deleteResource.action",
  781. params : {
  782. jsonData : unescape(jsonData
  783. .toString()
  784. .replace(/\\/g, "%"))
  785. },
  786. method : 'post',
  787. callback : function(options,
  788. success, response) {
  789. }
  790. });
  791. }
  792. // Ext.Msg.alert('提示','保存成功!');
  793. var gridCondition = getUrlParam("gridCondition");
  794. window.location.href = window.location.href
  795. + '?formCondition='
  796. + formCondition
  797. + '&gridCondition='
  798. + gridCondition;
  799. }
  800. }, {
  801. text : '删除任务',
  802. iconCls : 'x-advance-delete',
  803. handler : function() {
  804. var record = gantt.selModel.selected.items[0];
  805. if (record) {
  806. var parentNode = record.parentNode;
  807. if (parentNode.childNodes.length == 1) {
  808. parentNode.data.leaf = true;
  809. }
  810. parentNode.removeChild(record);
  811. } else {
  812. showError("请选择删除要删除任务!");
  813. }
  814. }
  815. }, {
  816. text : '查看成员',
  817. iconCls : 'x-advance-find',
  818. handler : function() {
  819. var panel = Ext
  820. .getCmp("resourceproject="
  821. + formCondition);
  822. value = formCondition.split("=")[1];
  823. var caller = "Resource";
  824. var url = basePath
  825. + "jsps/oa/persontask/taskforperson/taskforperson.jsp";
  826. var main = parent.Ext
  827. .getCmp("content-panel");
  828. if (!panel) {
  829. var title = "";
  830. if (value.toString().length > 4) {
  831. title = value
  832. .toString()
  833. .substring(value
  834. .toString().length
  835. - 4);
  836. } else {
  837. title = value;
  838. }
  839. panel = {
  840. // title :
  841. // main.getActiveTab().title+'('+title+')',
  842. title : '执行人(' + title + ')',
  843. tag : 'iframe',
  844. tabConfig : {
  845. tooltip : '执行人(' + title
  846. + ')'
  847. },
  848. frame : true,
  849. border : false,
  850. layout : 'fit',
  851. iconCls : 'x-tree-icon-tab-tab',
  852. html : '<iframe id="iframe_maindetail_'
  853. + caller
  854. + "_"
  855. + value
  856. + '" src="'
  857. + url
  858. + '?prjplanid='
  859. + value
  860. + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>',
  861. closable : true,
  862. listeners : {
  863. close : function() {
  864. main
  865. .setActiveTab(main
  866. .getActiveTab().id);
  867. }
  868. }
  869. };
  870. Ext.getCmp("ganttid").openTab(
  871. panel,
  872. "resourceproject="
  873. + formCondition);
  874. } else {
  875. main.setActiveTab(panel);
  876. }
  877. },
  878. scope : this
  879. }
  880. ]
  881. }, {
  882. xtype : 'buttongroup',
  883. title : '功能区',
  884. columns : 4,
  885. items : [{
  886. text : '突出关键链',
  887. iconCls : 'togglebutton',
  888. scope : this,
  889. enableToggle : true,
  890. handler : function(btn) {
  891. var v = gantt.getSchedulingView();
  892. if (btn.pressed) {
  893. v.highlightCriticalPaths(true);
  894. } else {
  895. v.unhighlightCriticalPaths(true);
  896. }
  897. }
  898. }, {
  899. iconCls : 'togglebutton',
  900. text : '未按时完成的任务',
  901. enableToggle : true,
  902. scope : this,
  903. handler : function(btn) {
  904. if (btn.pressed) {
  905. gantt.taskStore.filter(function(
  906. task) {
  907. return (task.get('EndDate') < new Date())
  908. && (task
  909. .get('PercentDone') < 100);
  910. });
  911. } else {
  912. gantt.taskStore.clearFilter();
  913. }
  914. }
  915. }, {
  916. iconCls : 'action',
  917. text : '突出任务>7天',
  918. scope : this,
  919. handler : function(btn) {
  920. gantt.taskStore.getRootNode()
  921. .cascadeBy(function(task) {
  922. if (Sch.util.Date
  923. .getDurationInDays(
  924. task
  925. .get('StartDate'),
  926. task
  927. .get('EndDate')) > 7) {
  928. var el = gantt
  929. .getSchedulingView()
  930. .getElementFromEventRecord(task);
  931. el && el.frame('lime');
  932. }
  933. }, this);
  934. }
  935. }, {
  936. iconCls : 'togglebutton',
  937. text : '筛选: 任务进度 < 30%',
  938. scope : this,
  939. enableToggle : true,
  940. toggleGroup : 'filter',
  941. handler : function(btn) {
  942. if (btn.pressed) {
  943. gantt.taskStore.filter(function(
  944. task) {
  945. return task.get('PercentDone') < 30;
  946. });
  947. } else {
  948. gantt.taskStore.clearFilter();
  949. }
  950. }
  951. }, {
  952. iconCls : 'togglebutton',
  953. text : '级联变化',
  954. scope : this,
  955. enableToggle : true,
  956. handler : function(btn) {
  957. gantt.setCascadeChanges(btn.pressed);
  958. }
  959. }, {
  960. enableToggle : true,
  961. text : '需提醒的任务',
  962. scope : this,
  963. iconCls : 'togglebutton',
  964. handler : function(btn) {
  965. if (btn.pressed) {
  966. gantt.taskStore.filter(function(
  967. task) {
  968. return (Sch.util.Date
  969. .getDurationInDays(
  970. task
  971. .get('StartDate'),
  972. new Date()) > task
  973. .get('Duration')
  974. / 2)
  975. && (Sch.util.Date
  976. .getDurationInDays(
  977. task
  978. .get('StartDate'),
  979. new Date()) < task
  980. .get('Duration'))
  981. && (task
  982. .get('PercentDone') < 30);
  983. });
  984. } else {
  985. gantt.taskStore.clearFilter();
  986. }
  987. }
  988. }, {
  989. iconCls : 'action',
  990. text : '最后任务',
  991. scope : this,
  992. handler : function(btn) {
  993. var latestEndDate = new Date(0), latest;
  994. gantt.taskStore.getRootNode()
  995. .cascadeBy(function(task) {
  996. if (task.get('EndDate') >= latestEndDate) {
  997. latestEndDate = task
  998. .get('EndDate');
  999. latest = task;
  1000. }
  1001. });
  1002. gantt.getSchedulingView()
  1003. .scrollEventIntoView(latest,
  1004. true);
  1005. }
  1006. }, {
  1007. xtype : 'textfield',
  1008. emptyText : '搜索任务...',
  1009. scope : this,
  1010. width : 150,
  1011. enableKeyEvents : true,
  1012. listeners : {
  1013. keyup : {
  1014. fn : function(field, e) {
  1015. var value = field.getValue();
  1016. var regexp = new RegExp(Ext.String.escapeRegex(value),'i')
  1017. if (value) {gantt.taskStore.filterTreeBy(function(task) {
  1018. return regexp.test(task.get('Name'))
  1019. });
  1020. } else {
  1021. gantt.taskStore
  1022. .clearTreeFilter();
  1023. }
  1024. },
  1025. scope : this
  1026. },
  1027. specialkey : {
  1028. fn : function(field, e) {
  1029. if (e.getKey() === e.ESC) {
  1030. field.reset();
  1031. }
  1032. this.taskStore
  1033. .clearTreeFilter();
  1034. },
  1035. scope : this
  1036. }
  1037. }
  1038. }]
  1039. }],
  1040. lockedGridConfig : {
  1041. width : 450,
  1042. title : '任务表',
  1043. collapsible : true
  1044. },
  1045. // Experimental
  1046. schedulerConfig : {
  1047. collapsible : true,
  1048. title : '计划表'
  1049. },
  1050. leftLabelField : {
  1051. dataIndex : 'Name',
  1052. editor : {
  1053. xtype : 'textfield'
  1054. }
  1055. },
  1056. eventRenderer : function(task) {
  1057. return {
  1058. style : 'background-color: #' + task.data.TaskColor
  1059. };
  1060. },
  1061. _fullScreenFn : (function() {
  1062. var docElm = document.documentElement;
  1063. if (docElm.requestFullscreen) {
  1064. return "requestFullscreen";
  1065. } else if (docElm.mozRequestFullScreen) {
  1066. return "mozRequestFullScreen";
  1067. } else if (docElm.webkitRequestFullScreen) {
  1068. return "webkitRequestFullScreen";
  1069. }
  1070. })(),
  1071. plugins : [
  1072. Ext.create("Gnt.plugin.TaskContextMenu"),
  1073. Ext.create("Sch.plugin.Pan"),
  1074. assignmentEditor = Ext.create(
  1075. 'Gnt.widget.AssignmentCellEditor', {
  1076. assignmentStore : assignmentStore,
  1077. resourceStore : config.resourceStore
  1078. }),
  1079. Ext.create('Sch.plugin.TreeCellEditing', {
  1080. clicksToEdit : 1,
  1081. listeners : {
  1082. beforeedit : function() {
  1083. return !Ext.getCmp('readonlybutton').pressed;
  1084. }
  1085. }
  1086. }), new Gnt.plugin.Printable({
  1087. printRenderer : function(task, tplData) {
  1088. if (task.isMilestone()) {
  1089. return;
  1090. } else if (task.isLeaf()) {
  1091. var availableWidth = tplData.width - 4, progressWidth = Math
  1092. .floor(availableWidth
  1093. * task.get('PercentDone') / 100);
  1094. return {
  1095. // Style borders to act as
  1096. // background/progressbar
  1097. progressBarStyle : Ext.String
  1098. .format(
  1099. 'width:{2}px;border-left:{0}px solid #7971E2;border-right:{1}px solid #E5ECF5;',
  1100. progressWidth,
  1101. availableWidth
  1102. - progressWidth,
  1103. availableWidth)
  1104. };
  1105. } else {
  1106. var availableWidth = tplData.width - 2, progressWidth = Math
  1107. .floor(availableWidth
  1108. * task.get('PercentDone') / 100);
  1109. return {
  1110. // Style borders to act as
  1111. // background/progressbar
  1112. progressBarStyle : Ext.String
  1113. .format(
  1114. 'width:{2}px;border-left:{0}px solid #FFF3A5;border-right:{1}px solid #FFBC00;',
  1115. progressWidth,
  1116. availableWidth
  1117. - progressWidth,
  1118. availableWidth)
  1119. };
  1120. }
  1121. },
  1122. beforePrint : function(sched) {
  1123. var v = sched.getSchedulingView();
  1124. this.oldRenderer = v.eventRenderer;
  1125. this.oldMilestoneTemplate = v.milestoneTemplate;
  1126. v.milestoneTemplate = printableMilestoneTpl;
  1127. v.eventRenderer = this.printRenderer;
  1128. },
  1129. afterPrint : function(sched) {
  1130. var v = sched.getSchedulingView();
  1131. v.eventRenderer = this.oldRenderer;
  1132. v.milestoneTemplate = this.oldMilestoneTemplate;
  1133. }
  1134. })],
  1135. tooltipTpl : new Ext.XTemplate(
  1136. '<h4 class="tipHeader">{Name}</h4>',
  1137. '<table class="taskTip">',
  1138. '<tr><td>开始:</td> <td align="right">{[Ext.Date.format(values.StartDate, "y-m-d")]}</td></tr>',
  1139. '<tr><td>结束:</td> <td align="right">{[Ext.Date.format(values.EndDate, "y-m-d")]}</td></tr>',
  1140. '<tr><td>进度:</td><td align="right">{PercentDone}%</td></tr>',
  1141. '</table>').compile(),
  1142. applyPercentDone : function(value) {
  1143. this.getSelectionModel().selected.each(function(task) {
  1144. task.setPercentDone(value);
  1145. });
  1146. },
  1147. showFullScreen : function() {
  1148. this.el.down('.x-panel-body').dom[this._fullScreenFn]();
  1149. },
  1150. openTab : function(panel, id) {
  1151. var o = (typeof panel == "string" ? panel : id || panel.id);
  1152. var main = parent.Ext.getCmp("content-panel");
  1153. var tab = main.getComponent(o);
  1154. if (tab) {
  1155. main.setActiveTab(tab);
  1156. } else if (typeof panel != "string") {
  1157. panel.id = o;
  1158. var p = main.add(panel);
  1159. main.setActiveTab(p);
  1160. }
  1161. },
  1162. // Experimental, not X-browser
  1163. _fullScreenFn : (function() {
  1164. var docElm = document.documentElement;
  1165. if (docElm.requestFullscreen) {
  1166. return "requestFullscreen";
  1167. } else if (docElm.mozRequestFullScreen) {
  1168. return "mozRequestFullScreen";
  1169. } else if (docElm.webkitRequestFullScreen) {
  1170. return "webkitRequestFullScreen";
  1171. }
  1172. })(),
  1173. columns : [{
  1174. xtype : 'wbscolumn',
  1175. header : '编号',
  1176. width : 50
  1177. }, {
  1178. xtype : 'treecolumn',
  1179. header : '任务',
  1180. sortable : true,
  1181. dataIndex : 'Name',
  1182. width : 200,
  1183. field : {
  1184. allowBlank : false
  1185. },
  1186. renderer : function(v, meta, r) {
  1187. if (!r.data.leaf)
  1188. meta.tdCls = 'sch-gantt-parent-cell';
  1189. return v;
  1190. }
  1191. }, {
  1192. header : '执行人',
  1193. width : 120,
  1194. editor : assignmentEditor,
  1195. xtype : 'resourceassignmentcolumn'
  1196. }, {
  1197. header : '开始时间',
  1198. xtype : 'startdatecolumn',
  1199. field : {
  1200. xtype : 'datefield',
  1201. allowBlank : false
  1202. }
  1203. }, {
  1204. header : '结束时间',
  1205. xtype : 'enddatecolumn',
  1206. // hidden : true
  1207. field : {
  1208. xtype : 'datefield',
  1209. allowBlank : false
  1210. }
  1211. }, {
  1212. header : '持续时间',
  1213. xtype : 'durationcolumn'
  1214. }, {
  1215. header : '完成率(%)',
  1216. xtype : 'percentdonecolumn',
  1217. width : 50
  1218. },
  1219. // column displaying task color
  1220. {
  1221. header : '颜色',
  1222. xtype : 'templatecolumn',
  1223. width : 50,
  1224. tdCls : 'sch-column-color',
  1225. field : {
  1226. allowBlank : false
  1227. },
  1228. tpl : '<div class="color-column-inner" style="background-color:#{TaskColor}">&nbsp;</div>',
  1229. listeners : {
  1230. click : function(panel, el, a, b, event, record) {
  1231. event.stopEvent();
  1232. this.rec = record;
  1233. this.showColumnMenu(el, event, record);
  1234. }
  1235. },
  1236. showColumnMenu : function(el, event, rec) {
  1237. // if color menu is not present, create a new
  1238. // Ext.menu.Menu instance
  1239. if (!this.colorMenu) {
  1240. this.colorMenu = new Ext.menu.Menu({
  1241. cls : 'gnt-locked-colormenu',
  1242. plain : true,
  1243. items : [{
  1244. text : '更改任务颜色',
  1245. menu : {
  1246. showSeparator : false,
  1247. items : [Ext.create(
  1248. 'Ext.ColorPalette', {
  1249. listeners : {
  1250. select : function(
  1251. cp, color) {
  1252. this.rec
  1253. .set(
  1254. 'TaskColor',
  1255. color);
  1256. },
  1257. scope : this
  1258. }
  1259. })]
  1260. }
  1261. }]
  1262. });
  1263. }
  1264. this.colorMenu.showAt(event.xy);
  1265. }
  1266. }],
  1267. assignmentStore : assignmentStore,
  1268. dependencyStore : dependencyStore
  1269. }, config));
  1270. }
  1271. };