advanced1.js 49 KB

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