| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323 |
- Ext.require(['Gnt.plugin.TaskContextMenu', 'Sch.plugin.TreeCellEditing',
- 'Sch.plugin.Pan', 'Gnt.panel.Gantt', 'Gnt.column.PercentDone',
- 'Gnt.column.StartDate', 'Gnt.column.EndDate', 'Gnt.plugin.Printable',
- 'Gnt.widget.AssignmentCellEditor', 'Gnt.column.ResourceAssignment',
- 'Gnt.model.Assignment', 'erp.util.BaseUtil', 'Gnt.widget.Calendar']);
- Ext.onReady(function() {
- Gantt.init();
- Ext.QuickTips.init();
- });
- Gantt = {
- //tx2x9saq
- init : function() {
- Ext.define('Gnt.column.ResourceName', {
- extend : 'Gnt.column.ResourceName',
- text : "执行人"
- });
- Ext.define('Gnt.column.AssignmentUnits', {
- extend : 'Gnt.column.AssignmentUnits',
- text : "分配比例"
- });
- Ext.define('Gnt.widget.AssignmentField', {
- extend : 'Gnt.widget.AssignmentField',
- cancelText : "取消",
- closeText : "保存并关闭"
- });
- Ext.define('TaskResource', {
- extend : 'Sch.model.Resource',
- idProperty : 'EmCode',
- nameField : 'Name',
- fields : ['EmCode', 'Name', 'Id', 'EmId']
- });
- var taskResourceStore = Ext.create("Sch.data.ResourceStore", {
- model : 'TaskResource',
- autoLoad : true,
- // autoSync : true,
- proxy : {
- type : 'ajax',
- method : 'POST',
- reader : {
- root : 'resources',
- type : 'json'
- },
- extraParams : {
- condition : 'prjplan_id=3147'// formCondition
- },
- api : {
- read : basePath + 'task/resource.action'
- /*
- * create : 'e-create.php', destroy :
- * 'e-destroy.php', update : 'e-update.php'
- */
- },
- writer : {
- type : 'json',
- root : 'resources',
- encode : true,
- writeAllFields : true,
- listful : true,
- allowSingle : false
- }
- }
- });
- Ext.define('TaskEvent', {
- extend : 'Sch.model.Event',
- nameField : 'Name',
- startDateField : 'StartDate',
- endDateField : 'EndDate',
- resourceIdField : 'ResourceId',
- fields : [
- // Define your own model fields
- {
- name : 'StartDate',
- type : 'date',
- dateFormat : 'Y-m-d'
- }, {
- name : 'EndDate',
- type : 'date',
- dateFormat : 'Y-m-d'
- }, 'Name', 'ResourceId', 'TaskId']
- });
- Ext.define('MyResourceModel', {
- extend : 'Gnt.model.Resource',
- fields : [{
- name : 'EmCode',
- type : 'string'
- }, {
- name : 'EmId',
- type : 'int'
- }]
- });
- var resourceStore = Ext.create("Gnt.data.ResourceStore", {
- model : 'MyResourceModel',
- proxy : {
- type : 'ajax',
- method : 'GET',
- url : basePath + 'plm/resourceassignment.action',
- root : 'resources',
- reader : {
- type : 'json'
- }
- }
- });
- Ext.define('MyTaskModel', {
- extend : 'Gnt.model.Task',
- clsField : 'TaskType',
- fields : [{
- name : 'TaskType',
- type : 'string'
- }, {
- name : 'TaskColor',
- type : 'string'
- }, {
- name : 'prjplanid',
- type : 'int'
- }, {
- name : 'prjplanname',
- type : 'string'
- }, {
- name : 'recorder',
- type : 'string'
- }, {
- name : 'recorddate',
- type : 'string'
- }, {
- name : 'taskcode',
- type : 'string'
- }, {
- name : 'id',
- type : 'int'
- }]
- });
- Ext.define('MyDependencyModel', {
- extend : 'Gnt.model.Dependency',
- fields : [{
- name : 'Id',
- type : 'int'
- }]
- });
- var taskStore = Ext.create("Gnt.data.TaskStore", {
- model : 'MyTaskModel',
- sorters : 'StartDate',
- proxy : {
- type : 'ajax',
- headers : {
- "Content-Type" : 'application/json'
- },
- extraParams : {
- condition : 'prjplan_id=3147'// formCondition
- },
- api : {
- read : basePath + 'plm/gantt.action',
- create : basePath + 'plm/ganttcreate.action',
- destroy : 'webservices/Tasks.asmx/Delete',
- update : basePath + 'plm/ganttupdate.action'
- },
- writer : {
- type : 'json',
- root : 'jsonData',
- encode : true,
- nameProperty : 'data',
- allowSingle : false
- },
- reader : {
- type : 'json'
- }
- }
- });
- var allTaskStore = Ext.create("Sch.data.EventStore", {
- model : 'TaskEvent',
- resourceStore : taskResourceStore,
- autoLoad : true,
- proxy : {
- type : 'ajax',
- method : 'POST',
- reader : {
- root : 'assignments',
- type : 'json'
- },
- extraParams : {
- condition : 'prjplan_id=3147' // formCondition
- },
- api : {
- read : basePath + 'task/assignment.action'
- /*
- * create : 'e-create.php', destroy :
- * 'e-destroy.php', update : 'e-update.php'
- */
- },
- writer : {
- type : 'json',
- root : 'assignments',
- encode : true,
- writeAllFields : true,
- listful : true,
- allowSingle : false
- }
- }
- })
- var gantt = this.createGantt({
- resourceStore : resourceStore,
- taskStore : taskStore
- });
- var scheduler = this.createScheduler({
- resourceStore : resourceStore,
- eventStore : taskStore,
- // Share time axis
- timeAxis : gantt.getTimeAxis(),
- lockedGridConfig : {
- resizeHandles : 'e',
- resizable : {
- pinned : true
- },
- width : 300
- },
- // Share non-working time visualization
- plugins : new Sch.plugin.Zones({
- store : gantt.getWorkingTimePlugin().store
- })
- });
- var allTask = this.createAllTask({
- resourceStore : taskResourceStore,
- eventStore : allTaskStore
- });
- var vp = new Ext.Viewport({
- layout : 'border',
- items : [gantt, scheduler, allTask]
- });
- var ganttViewEl = gantt.getSchedulingView().el;
- var schedulerViewEl = scheduler.getSchedulingView().el;
- // Sync the scrolling
- 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();
- };
- // Since scheduler doesn't (yet) know of assignments, give it some help
- gantt.getAssignmentStore().on({
- update : fullRefresh,
- add : fullRefresh,
- remove : fullRefresh,
- refresh : fullRefresh,
- buffer : 1
- })
- },
- createAllTask : function(config) {
- return allTaskPanel = Ext.create("Sch.panel.SchedulerGrid", Ext.apply({
- title : '员工全部任务情况',
- eventBarTextField : 'Name',
- viewPreset : 'dayAndWeek',
- height : 20,
- region : 'south',
- split : true,
- timeAxis : gantt.getTimeAxis(),
- viewConfig : {
- forceFit : false
- },
- columns : [{
- header : 'Name',
- width : 130,
- dataIndex : 'Name'
- }]
- }, config));
- },
- createScheduler : function(config) {
- return A = Ext.create("Sch.SchedulerPanel", Ext.apply({
- // title : 'Resource panel',
- viewPreset : 'weekAndDayLetter',
- enableDragCreation : false,
- height : 20,
- layout : 'fit',
- region : 'south',
- split : true,
- columns : [{
- header : '员工姓名',
- width : 300,
- dataIndex : 'Name'
- }]
- }, config));
- },
- createGantt : function(config) {
- var BaseUtil = Ext.create('erp.util.BaseUtil');
- var startDate = new Date(2012, 9, 11);
- var endDate = Sch.util.Date.add(new Date(2012, 9, 11),
- Sch.util.Date.WEEK, 20);
- var start = new Date(2012, 9, 20), end = Sch.util.Date.add(new Date(
- 2012, 10, 20), Sch.util.Date.WEEK, 20);
- var calendar = new Gnt.data.Calendar({
- data : [{
- Date : new Date(2010, 0, 13),
- Cls : 'gnt-national-holiday'
- }, {
- Date : new Date(2010, 1, 1),
- Cls : 'gnt-company-holiday'
- }, {
- Date : new Date(2010, 0, 16),
- IsWorkingDay : true
- }]
- });
- Ext.define('MyAssignmentModel', {
- extend : 'Gnt.model.Assignment'
- });
- var assignmentStore = Ext.create("Gnt.data.AssignmentStore", {
- model : 'MyAssignmentModel',
- autoLoad : true,
- resourceStore : config.resourceStore,
- proxy : {
- method : 'GET',
- type : 'ajax',
- url : basePath + 'plm/resourceassignment.action',
- extraParams : {
- condition : 'prjplan_id=3147'// formCondition
- },
- reader : {
- type : 'json',
- root : 'assignments'
- }
- },
- listeners : {
- load : function() {
- config.resourceStore
- .loadData(this.proxy.reader.jsonData.resources);
- }
- }
- });
- var dependencyStore = Ext.create("Gnt.data.DependencyStore", {
- model : 'MyDependencyModel',
- autoLoad : true,
- proxy : {
- type : 'ajax',
- extraParams : {
- condition : 'prjplan_id=3147'// formCondition
- },
- url : basePath + 'plm/gantt/getdependency.action',
- method : 'GET',
- reader : {
- type : 'json',
- root : 'dependency'
- }
- }
- });
- var formCondition = 'prjplan_id=3147'//'prjplan_id=3147';
- return gantt = Ext.create("Gnt.panel.Gantt", Ext.apply({
- id : 'ganttid',
- region : 'center',
- leftLabelField : 'Name',
- highlightWeekends : true,
- loadMask : true,
- snapToIncrement : true,
- // title : 'Gantt panel with tasks and resources',
- startDate : new Date(2012, 9, 11),
- endDate : Sch.util.Date.add(new Date(2012, 11, 11),
- Sch.util.Date.WEEK, 20),
- viewPreset : 'weekAndDayLetter',
- tbar : [/*
- * { text : 'Previous', handler : function() { //
- * this.up('ganttpanel').shiftPrevious(); var m = window.A;
- * var n = Window.s2; m.height = 0; console.log(window); } }, {
- * text : 'Next', handler : function() { window.A = 200;
- * window.refresh; // this.up('ganttpanel').shiftNext(); } },
- */{
- xtype : 'buttongroup',
- title : '视图工具',
- columns : 3,
- items : [{
- iconCls : 'icon-prev',
- text : '向前',
- scope : this,
- handler : function() {
- gantt.shiftPrevious();
- }
- }, {
- iconCls : 'icon-next',
- text : '向后',
- scope : this,
- handler : function() {
- gantt.shiftNext();
- }
- }, {
- text : '缩放',
- iconCls : 'zoomfit',
- handler : function() {
- gantt.zoomToFit();
- },
- scope : this
- }, {
- text : '收缩',
- iconCls : 'icon-collapseall',
- scope : this,
- handler : function() {
- gantt.collapseAll();
- }
- }, {
- text : '展开',
- iconCls : 'icon-expandall',
- scope : this,
- loader : {
- loadMask : true
- },
- handler : function() {
- var loadMask = gantt.setLoading("正在展开",
- true);
- gantt.expandAll(loadMask.hide());
- // g.expandAll();
- }
- }, {
- iconCls : 'togglebutton',
- enableToggle : true,
- id : 'readonlybutton',
- text : '只读',
- pressed : true
- }]
- }, {
- xtype : 'buttongroup',
- title : '视图解析',
- columns : 2,
- items : [{
- iconCls : 'gnt-date',
- text : '6 周',
- scope : this,
- handler : function() {
- gantt.switchViewPreset('weekAndMonth');
- }
- }, {
- iconCls : 'gnt-date',
- text : '10周',
- scope : this,
- handler : function() {
- gantt
- .switchViewPreset('weekAndDayLetter');
- }
- }, {
- iconCls : 'gnt-date',
- text : '1 年',
- scope : this,
- handler : function() {
- gantt.switchViewPreset('monthAndYear');
- }
- }, {
- iconCls : 'gnt-date',
- text : '5 年',
- scope : this,
- handler : function() {
- var start = new Date(this.getStart()
- .getFullYear(), 0);
- gantt.switchViewPreset('monthAndYear',
- start, Ext.Date.add(start,
- Ext.Date.YEAR, 5));
- }
- }]
- }, {
- xtype : 'buttongroup',
- title : '操作区',
- columns : 3,
- items : [{
- iconCls : 'x-advance-print',
- text : '打印',
- handler : function() {
- // Make sure this fits horizontally on
- // one page.
- Ext.getCmp('gantt').zoomToFit();
- Ext.getCmp('gantt').print();
- }
- }, {
- text : '添加任务',
- iconCls : 'x-advance-add',
- handler : function() {
- var selectItem = gantt.selModel.selected.items[0];
- if (selectItem) {
- if (selectItem.data.Id) {
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/getData.action",
- params : {
- condition : formCondition
- },
- method : 'get',
- callback : function(
- options, success,
- response) {
- var rs = new Ext.decode(response.responseText);
- if (rs.exceptionInfo) {
- showError(rs.exceptionInfo);
- return;
- }
- if (rs.success) {
- var newTask = new gantt.taskStore.model(
- {
- Name : 'New task',
- leaf : true,
- PercentDone : 0,
- prjplanid : rs.data.prjplandata[0].prjplan_id,
- prjplanname : rs.data.prjplandata[0].prjplan_prjname,
- // taskcode:BaseUtil.getRandomNumber(),
- taskcode : (new Date())
- .getTime(),
- recorder : recorder,
- recorddate : recorddate,
- StartDate : selectItem.data.StartDate,// 给系统的默认时间
- EndDate : selectItem.data.EndDate
- });
- var record = gantt.selModel.selected.items[0];
- if (record.data.leaf) {
- record.data.leaf = false;
- record.data.expanded = true;
- }
- record
- .appendChild(newTask);
- }
- }
- });
- } else {
- showError("任务未生成不能给他添加子任务!");
- }
- } else {
- showError("请选择添加任务的父节点!");
- }
- }
- }, {
- text : '添加父任务',
- iconCls : 'x-advance-add',
- handler : function() {
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/getData.action",
- params : {
- condition : formCondition
- },
- method : 'get',
- callback : function(options,
- success, response) {
- var rs = new Ext.decode(response.responseText);
- if (rs.exceptionInfo) {
- showError(rs.exceptionInfo);
- return;
- }
- if (rs.success) {
- var newTask = new gantt.taskStore.model(
- {
- Name : 'New task',
- leaf : false,
- PercentDone : 0,
- prjplanid : rs.data.prjplandata[0].prjplan_id,
- prjplanname : rs.data.prjplandata[0].prjplan_prjname,
- // taskcode:BaseUtil.getRandomNumber(),
- recorder : recorder,
- recorddate : recorddate,
- parentId : 0
- });
- taskStore
- .getRootNode()
- .appendChild(newTask)
- }
- }
- });
- }
- },
- {
- iconCls : 'x-advance-save',
- id : 'savebutton',
- text : '保存',
- listeners : {
- 'afterrender' : function(btn, opts) {
- if (Ext.getCmp('readonlybutton').pressed) {
- btn.setDisabled(false);
- }
- }
- },
- handler : function() {
- // g.checkstore();//验证store是否填写完整 要求必填字段
- // 如 日期
- // 并且开始时间要小于或等于结束时间
- var options = {}, me = gantt.taskStore;
- de = gantt.dependencyStore;
- as = gantt.assignmentStore;
- var toCreate = me.getNewRecords(), toUpdate = me
- .getUpdatedRecords(), toDestroy = me
- .getRemovedRecords(), toCreateDependency = de
- .getNewRecords(), toDestroyDependency = de
- .getRemovedRecords(), toCreateassign = as
- .getNewRecords(), toUpdateassign = as
- .getUpdatedRecords(), toDestroyassign = as
- .getRemovedRecords(), needsSync = false;
- if (toCreate.length > 0) {
- var create = null;
- options.create = toCreate;
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toCreate.length; i++) {
- var data = toCreate[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data)
- + '#@';
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/ganttcreate.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toUpdate.length > 0) {
- options.update = toUpdate;
- needsSync = true;
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toUpdate.length; i++) {
- var data = toUpdate[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data)
- + '#@';
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/ganttupdate.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toDestroy.length > 0) {
- options.destroy = toDestroy;
- needsSync = true;
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toDestroy.length; i++) {
- var data = toDestroy[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data)
- + '#@';
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/ganttdelete.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toCreateDependency.length > 0) {
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toCreateDependency.length; i++) {
- var data = toCreateDependency[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data);
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/dependencycreate.action",
- params : {
- condition : formCondition,
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toDestroyDependency.length > 0) {
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toDestroyDependency.length; i++) {
- var data = toDestroyDependency[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data);
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/gantt/dependencydelete.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toCreateassign.length > 0) {
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toCreateassign.length; i++) {
- // var
- // ddd=g.selModel.selected.items[0];
- var data = toCreateassign[i].data;
- var id = data.TaskId;
- var task = gantt.taskStore
- .getById(id);
- var resourceId = data.ResourceId;
- var resource = gantt.resourceStore
- .getById(resourceId);
- data.StartDate = task.data.StartDate;
- data.EndDate = task.data.EndDate;
- data.resourcecode = resource.data.EmCode;
- data.detno = 1;
- data.Id = 0;
- data.resourcename = resource.data.Name;
- data_resourcetype = "";
- data.taskname = task.data.Name;
- data.emid = resource.data.EmId;
- data.prjid = task.data.prjplanid;
- data.prjname = task.data.prjplanname;
- jsonData[index++] = Ext.JSON
- .encode(data);
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/resource/createResource.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toUpdateassign.length > 0) {
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toUpdateassign.length; i++) {
- var data = toUpdateassign[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data);
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/resource/updateResource.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- if (toDestroyassign.length > 0) {
- var index = 0;
- var jsonData = new Array();
- for (var i = 0; i < toDestroyassign.length; i++) {
- var data = toDestroyassign[i].data;
- jsonData[index++] = Ext.JSON
- .encode(data);
- }
- Ext.Ajax.request({
- url : basePath
- + "plm/resource/deleteResource.action",
- params : {
- jsonData : unescape(jsonData
- .toString()
- .replace(/\\/g, "%"))
- },
- method : 'post',
- callback : function(options,
- success, response) {
- }
- });
- }
- // Ext.Msg.alert('提示','保存成功!');
- var gridCondition = getUrlParam("gridCondition");
- window.location.href = window.location.href
- + '?formCondition='
- + formCondition
- + '&gridCondition='
- + gridCondition;
- }
- }, {
- text : '删除任务',
- iconCls : 'x-advance-delete',
- handler : function() {
- var record = gantt.selModel.selected.items[0];
- if (record) {
- var parentNode = record.parentNode;
- if (parentNode.childNodes.length == 1) {
- parentNode.data.leaf = true;
- }
- parentNode.removeChild(record);
- } else {
- showError("请选择删除要删除任务!");
- }
- }
- }, {
- text : '查看成员',
- iconCls : 'x-advance-find',
- handler : function() {
- var panel = Ext
- .getCmp("resourceproject="
- + formCondition);
- value = formCondition.split("=")[1];
- var caller = "Resource";
- var url = basePath
- + "jsps/oa/persontask/taskforperson/taskforperson.jsp";
- var main = parent.Ext
- .getCmp("content-panel");
- if (!panel) {
- var title = "";
- if (value.toString().length > 4) {
- title = value
- .toString()
- .substring(value
- .toString().length
- - 4);
- } else {
- title = value;
- }
- panel = {
- // title :
- // main.getActiveTab().title+'('+title+')',
- title : '执行人(' + title + ')',
- tag : 'iframe',
- tabConfig : {
- tooltip : '执行人(' + title
- + ')'
- },
- frame : true,
- border : false,
- layout : 'fit',
- iconCls : 'x-tree-icon-tab-tab',
- html : '<iframe id="iframe_maindetail_'
- + caller
- + "_"
- + value
- + '" src="'
- + url
- + '?prjplanid='
- + value
- + '" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>',
- closable : true,
- listeners : {
- close : function() {
- main
- .setActiveTab(main
- .getActiveTab().id);
- }
- }
- };
- Ext.getCmp("ganttid").openTab(
- panel,
- "resourceproject="
- + formCondition);
- } else {
- main.setActiveTab(panel);
- }
- },
- scope : this
- }
- ]
- }, {
- xtype : 'buttongroup',
- title : '功能区',
- columns : 4,
- items : [{
- text : '突出关键链',
- iconCls : 'togglebutton',
- scope : this,
- enableToggle : true,
- handler : function(btn) {
- var v = gantt.getSchedulingView();
- if (btn.pressed) {
- v.highlightCriticalPaths(true);
- } else {
- v.unhighlightCriticalPaths(true);
- }
- }
- }, {
- iconCls : 'togglebutton',
- text : '未按时完成的任务',
- enableToggle : true,
- scope : this,
- handler : function(btn) {
- if (btn.pressed) {
- gantt.taskStore.filter(function(
- task) {
- return (task.get('EndDate') < new Date())
- && (task
- .get('PercentDone') < 100);
- });
- } else {
- gantt.taskStore.clearFilter();
- }
- }
- }, {
- iconCls : 'action',
- text : '突出任务>7天',
- scope : this,
- handler : function(btn) {
- gantt.taskStore.getRootNode()
- .cascadeBy(function(task) {
- if (Sch.util.Date
- .getDurationInDays(
- task
- .get('StartDate'),
- task
- .get('EndDate')) > 7) {
- var el = gantt
- .getSchedulingView()
- .getElementFromEventRecord(task);
- el && el.frame('lime');
- }
- }, this);
- }
- }, {
- iconCls : 'togglebutton',
- text : '筛选: 任务进度 < 30%',
- scope : this,
- enableToggle : true,
- toggleGroup : 'filter',
- handler : function(btn) {
- if (btn.pressed) {
- gantt.taskStore.filter(function(
- task) {
- return task.get('PercentDone') < 30;
- });
- } else {
- gantt.taskStore.clearFilter();
- }
- }
- }, {
- iconCls : 'togglebutton',
- text : '级联变化',
- scope : this,
- enableToggle : true,
- handler : function(btn) {
- gantt.setCascadeChanges(btn.pressed);
- }
- }, {
- enableToggle : true,
- text : '需提醒的任务',
- scope : this,
- iconCls : 'togglebutton',
- handler : function(btn) {
- if (btn.pressed) {
- gantt.taskStore.filter(function(
- task) {
- 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);
- });
- } else {
- gantt.taskStore.clearFilter();
- }
- }
- }, {
- iconCls : 'action',
- text : '最后任务',
- scope : this,
- handler : function(btn) {
- var latestEndDate = new Date(0), latest;
- gantt.taskStore.getRootNode()
- .cascadeBy(function(task) {
- if (task.get('EndDate') >= latestEndDate) {
- latestEndDate = task
- .get('EndDate');
- latest = task;
- }
- });
- gantt.getSchedulingView()
- .scrollEventIntoView(latest,
- true);
- }
- }, {
- xtype : 'textfield',
- emptyText : '搜索任务...',
- scope : this,
- width : 150,
- enableKeyEvents : true,
- listeners : {
- keyup : {
- fn : function(field, e) {
- var value = field.getValue();
- var regexp = new RegExp(Ext.String.escapeRegex(value),'i')
- if (value) {gantt.taskStore.filterTreeBy(function(task) {
- return regexp.test(task.get('Name'))
- });
- } else {
- gantt.taskStore
- .clearTreeFilter();
- }
- },
- scope : this
- },
- specialkey : {
- fn : function(field, e) {
- if (e.getKey() === e.ESC) {
- field.reset();
- }
- this.taskStore
- .clearTreeFilter();
- },
- scope : this
- }
- }
- }]
- }],
- lockedGridConfig : {
- width : 450,
- title : '任务表',
- collapsible : true
- },
- // Experimental
- schedulerConfig : {
- collapsible : true,
- title : '计划表'
- },
- leftLabelField : {
- dataIndex : 'Name',
- editor : {
- xtype : 'textfield'
- }
- },
- eventRenderer : function(task) {
- return {
- style : 'background-color: #' + task.data.TaskColor
- };
- },
- _fullScreenFn : (function() {
- var docElm = document.documentElement;
- if (docElm.requestFullscreen) {
- return "requestFullscreen";
- } else if (docElm.mozRequestFullScreen) {
- return "mozRequestFullScreen";
- } else if (docElm.webkitRequestFullScreen) {
- return "webkitRequestFullScreen";
- }
- })(),
- plugins : [
- Ext.create("Gnt.plugin.TaskContextMenu"),
- Ext.create("Sch.plugin.Pan"),
- assignmentEditor = Ext.create(
- 'Gnt.widget.AssignmentCellEditor', {
- assignmentStore : assignmentStore,
- resourceStore : config.resourceStore
- }),
- Ext.create('Sch.plugin.TreeCellEditing', {
- clicksToEdit : 1,
- listeners : {
- beforeedit : function() {
- return !Ext.getCmp('readonlybutton').pressed;
- }
- }
- }), new Gnt.plugin.Printable({
- printRenderer : function(task, tplData) {
- if (task.isMilestone()) {
- return;
- } else if (task.isLeaf()) {
- var availableWidth = tplData.width - 4, progressWidth = Math
- .floor(availableWidth
- * task.get('PercentDone') / 100);
- return {
- // Style borders to act as
- // background/progressbar
- progressBarStyle : Ext.String
- .format(
- 'width:{2}px;border-left:{0}px solid #7971E2;border-right:{1}px solid #E5ECF5;',
- progressWidth,
- availableWidth
- - progressWidth,
- availableWidth)
- };
- } else {
- var availableWidth = tplData.width - 2, progressWidth = Math
- .floor(availableWidth
- * task.get('PercentDone') / 100);
- return {
- // Style borders to act as
- // background/progressbar
- progressBarStyle : Ext.String
- .format(
- 'width:{2}px;border-left:{0}px solid #FFF3A5;border-right:{1}px solid #FFBC00;',
- progressWidth,
- availableWidth
- - progressWidth,
- availableWidth)
- };
- }
- },
- beforePrint : function(sched) {
- var v = sched.getSchedulingView();
- this.oldRenderer = v.eventRenderer;
- this.oldMilestoneTemplate = v.milestoneTemplate;
- v.milestoneTemplate = printableMilestoneTpl;
- v.eventRenderer = this.printRenderer;
- },
- afterPrint : function(sched) {
- var v = sched.getSchedulingView();
- v.eventRenderer = this.oldRenderer;
- v.milestoneTemplate = this.oldMilestoneTemplate;
- }
- })],
- tooltipTpl : new Ext.XTemplate(
- '<h4 class="tipHeader">{Name}</h4>',
- '<table class="taskTip">',
- '<tr><td>开始:</td> <td align="right">{[Ext.Date.format(values.StartDate, "y-m-d")]}</td></tr>',
- '<tr><td>结束:</td> <td align="right">{[Ext.Date.format(values.EndDate, "y-m-d")]}</td></tr>',
- '<tr><td>进度:</td><td align="right">{PercentDone}%</td></tr>',
- '</table>').compile(),
- applyPercentDone : function(value) {
- this.getSelectionModel().selected.each(function(task) {
- task.setPercentDone(value);
- });
- },
- showFullScreen : function() {
- this.el.down('.x-panel-body').dom[this._fullScreenFn]();
- },
- openTab : function(panel, id) {
- var o = (typeof panel == "string" ? panel : id || panel.id);
- var main = parent.Ext.getCmp("content-panel");
- var tab = main.getComponent(o);
- if (tab) {
- main.setActiveTab(tab);
- } else if (typeof panel != "string") {
- panel.id = o;
- var p = main.add(panel);
- main.setActiveTab(p);
- }
- },
- // Experimental, not X-browser
- _fullScreenFn : (function() {
- var docElm = document.documentElement;
- if (docElm.requestFullscreen) {
- return "requestFullscreen";
- } else if (docElm.mozRequestFullScreen) {
- return "mozRequestFullScreen";
- } else if (docElm.webkitRequestFullScreen) {
- return "webkitRequestFullScreen";
- }
- })(),
- columns : [{
- xtype : 'wbscolumn',
- header : '编号',
- width : 50
- }, {
- xtype : 'treecolumn',
- header : '任务',
- sortable : true,
- dataIndex : 'Name',
- width : 200,
- field : {
- allowBlank : false
- },
- renderer : function(v, meta, r) {
- if (!r.data.leaf)
- meta.tdCls = 'sch-gantt-parent-cell';
- return v;
- }
- }, {
- header : '执行人',
- width : 120,
- editor : assignmentEditor,
- xtype : 'resourceassignmentcolumn'
- }, {
- header : '开始时间',
- xtype : 'startdatecolumn',
- field : {
- xtype : 'datefield',
- allowBlank : false
- }
- }, {
- header : '结束时间',
- xtype : 'enddatecolumn',
- // hidden : true
- field : {
- xtype : 'datefield',
- allowBlank : false
- }
- }, {
- header : '持续时间',
- xtype : 'durationcolumn'
- }, {
- header : '完成率(%)',
- xtype : 'percentdonecolumn',
- width : 50
- },
- // column displaying task color
- {
- header : '颜色',
- xtype : 'templatecolumn',
- width : 50,
- tdCls : 'sch-column-color',
- field : {
- allowBlank : false
- },
- tpl : '<div class="color-column-inner" style="background-color:#{TaskColor}"> </div>',
- listeners : {
- click : function(panel, el, a, b, event, record) {
- event.stopEvent();
- this.rec = record;
- this.showColumnMenu(el, event, record);
- }
- },
- showColumnMenu : function(el, event, rec) {
- // if color menu is not present, create a new
- // Ext.menu.Menu instance
- if (!this.colorMenu) {
- this.colorMenu = new Ext.menu.Menu({
- cls : 'gnt-locked-colormenu',
- plain : true,
- items : [{
- text : '更改任务颜色',
- menu : {
- showSeparator : false,
- items : [Ext.create(
- 'Ext.ColorPalette', {
- listeners : {
- select : function(
- cp, color) {
- this.rec
- .set(
- 'TaskColor',
- color);
- },
- scope : this
- }
- })]
- }
- }]
- });
- }
- this.colorMenu.showAt(event.xy);
- }
- }],
- assignmentStore : assignmentStore,
- dependencyStore : dependencyStore
- }, config));
- }
- };
|