#set ($CHOOSE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.choose"))) #set ($BLANK_WARNING = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.blankwarning"))) #set ($DIALOG_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.dialogtitle"))) #set ($FORM_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.formtitle"))) #set ($FORM_DESCRIPTION = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.formdescription"))) #set ($FORM_ESTIMATE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.formestimate"))) #set ($FORM_TEAMMEMBERS = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.fromteammembers"))) #set ($SAVE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.save"))) #set ($CANCEL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.cancel"))) #set ($ADD_RESOURCE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.addresource"))) #set ($REMOVE_RESOURCE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.removeresource"))) #set ($ADD_RESOURCE_TT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.addresourcett"))) #set ($REMOVE_RESOURCE_TT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.removeresourcett"))) #set ($GRID_PERSON = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.gridperson"))) #set ($GRID_SPENT = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.gridspent"))) #set ($GRID_REMAINING = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.gridremaining"))) #set ($GRID_TOTAL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.gridtotal"))) #set ($GRID_ESTIMATE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.gridestimate"))) #set ($STATUS = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.status"))) #set ($STORY = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.story"))) #set ($LOAD_MSG = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.loadmsg"))) #set ($ADD_TASK_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.addtasktitle"))) #if ($canManageTasks) #set ($EDIT_TASK_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.edittasktitle"))) #else #set ($EDIT_TASK_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.viewtasktitle"))) #end #set ($SAVE_MSG = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.savemsg"))) #set ($ERROR_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.errortitle"))) #set ($SAVE_ERROR_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.saveerrortitle"))) #set ($UNASSIGNED = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.unassigned"))) #set ($FORM_INVALID_VALUES = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.forminvalidvalues"))) #set ($TOTALS = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.totals"))) #set ($ESTIMATE_MSG_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.estimatemsgtitle"))) #set ($ESTIMATE_MSG = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.estimatemsg"))) #set ($NO_RESOURCE_MSG = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.noresourcemsg"))) #set ($TASK_STATUS_ERROR = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.taskstatuserror"))) #set ($TASK_STATUS_ERROR_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.taskstatuserrortitle"))) #set ($USERMAP_ERROR = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.usermappingerror"))) #set ($USERMAP_INFO = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.usermappinginfo"))) #set ($OBSTACLE_MESSAGE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.obstaclewarning"))) #set ($REQUIRED_FIELD = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "FocusCommon", "requiredfield.error"))) #set ($DETAILS_TAB_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.details_tab_title"))) #set ($TESTS_TAB_TITLE = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.tests_tab_title"))) #set ($TESTS_TAB_TEST_CASE_LABEL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.tests_tab_test_case_label"))) #set ($TESTS_TAB_DESCRIPTION_LABEL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.tests_tab_description_label"))) #set ($TESTS_TAB_STATUS_LABEL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.tests_tab_status_label"))) #set ($TESTS_TAB_LAST_RUN_LABEL = $CommonFunctions.encodeJavaScriptString($CommonFunctions.getTermFromResourceBundle($currentUserId, "GTaskDialog", "gtaskdialog.tests_tab_last_run_label"))) var TDLabels = { CHOOSE: '$CHOOSE', BLANK_WARNING: '$BLANK_WARNING', DIALOG_TITLE: '$DIALOG_TITLE', FORM_TITLE: '$FORM_TITLE', FORM_DESCRIPTION: '$FORM_DESCRIPTION', FORM_ESTIMATE: '$FORM_ESTIMATE', FORM_TEAMMEMBERS: '$FORM_TEAMMEMBERS', SAVE: '$SAVE', CANCEL: '$CANCEL', ADD_RESOURCE: '$ADD_RESOURCE', REMOVE_RESOURCE: '$REMOVE_RESOURCE', ADD_RESOURCE_TT: '$ADD_RESOURCE_TT', REMOVE_RESOURCE_TT: '$REMOVE_RESOURCE_TT', GRID_PERSON: '$GRID_PERSON', GRID_SPENT: '$GRID_SPENT', GRID_REMAINING: '$GRID_REMAINING', GRID_TOTAL: '$GRID_TOTAL', GRID_ESTIMATE: '$GRID_ESTIMATE', STATUS: '$STATUS', STORY: '$STORY', LOAD_MSG: '$LOAD_MSG', ADD_TASK_TITLE: '$ADD_TASK_TITLE', EDIT_TASK_TITLE: '$EDIT_TASK_TITLE', SAVE_MSG: '$SAVE_MSG', ERROR_TITLE: '$ERROR_TITLE', UNASSIGNED: '$UNASSIGNED', FORM_INVALID_VALUES: '$FORM_INVALID_VALUES', TOTALS: '$TOTALS', ESTIMATE_MSG_TITLE: '$ESTIMATE_MSG_TITLE', ESTIMATE_MSG: '$ESTIMATE_MSG', NO_RESOURCE_MSG: '$NO_RESOURCE_MSG', DETAILS_TAB_TITLE: '$DETAILS_TAB_TITLE', TESTS_TAB_TITLE: '$TESTS_TAB_TITLE', TESTS_TAB_TEST_CASE_LABEL: '$TESTS_TAB_TEST_CASE_LABEL', TESTS_TAB_DESCRIPTION_LABEL: '$TESTS_TAB_DESCRIPTION_LABEL', TESTS_TAB_STATUS_LABEL: '$TESTS_TAB_STATUS_LABEL', TESTS_TAB_LAST_RUN_LABEL: '$TESTS_TAB_LAST_RUN_LABEL' } TDStatuses = { UPCOMING: '000000000001', STARTED: '000000000002', COMPLETED: '000000000003', CANCELLED: '000000000004' } TDFieldIds = { TASKID: 'taskid', STORYID: 'storyid', NAME: 'Name', DESCRIPTION: 'Description', STATUS: 'Status', ESTIMATEDEFFORT: 'EstimatedEffort', TEST_STATUS_ID: 'teststatusid', LAST_RUN_DATE: 'lastrundate', TEST_CASE: 'testname', TEST_DESCRIPTION: 'testdesc' } Actions = { ADD_TASK : 'add', EDIT_TASK : 'edit' }; /* * Task Dialog */ var taskDialog = { saveSuccessHandlerFn : null, // set up save success handler saveFailureHandlerFn : null, // set up save failure handler dlgTitle : null, statusCombo : null, statusDS : null, statusRec : null, storyCombo : null, storyDS : null, storyRec : null, dlgFormCtrl : null, dlgFormRec : null, estimateField: null, resourceFS : null, usersDS : null, userRec : null, userArray : null, editors : null, resourceRec: null, resourceDS: null, totalSpent: null, totalRemain: null, totalPlanned: null, addResBtn: null, removeResBtn: null, obstacleCount :0, dialogLoaded:false, obstacleButton:null, selectedTaskId: null, lastStatus: null, init : function() { taskDialog.createStatusComboBox(); taskDialog.createStoryComboBox(); taskDialog.createUsersDS(); taskDialog.createResourceGrid(); taskDialog.createForm(); // // form dialog if(!taskDialog.dialog){ taskDialog.dialog = new Bxt.BMSWindow({ id: 'tdlg-win', layout:'fit', width:500, height:480, closeAction:'hide', plain: true, items: taskDialog.dlgFormCtrl, modal: true, resizable : false, closable: true, renderTo: document.body, saveFunc: taskDialog.preSaveHandler, formCtrl: taskDialog.dlgFormCtrl }); }; // Intercept backspace key on dialog var keymap = new Ext.KeyMap('tdlg-win', { key: Ext.EventObject.BACKSPACE, fn: BxtUtil.handleBACKSPACEKey }); taskDialog.dialog.on('show', function(){ taskDialog.dlgTitle.getEl().dom.focus(); }, null, {delay: 100}); }, createForm : function() { taskDialog.resourceFS = new Ext.form.FieldSet({ title: TDLabels.FORM_TEAMMEMBERS, autoHeight:true, //collapsible: true, cls: 'resource-fieldset', items :[taskDialog.gridpanel] }); // title taskDialog.dlgTitle = new Ext.form.TextField({ id: 'taskDialogTaskId', fieldLabel: TDLabels.FORM_TITLE, name: 'name', anchor:'93%', allowBlank: false, maxLength: 75, validator : function(v) { if(v!= null && v.trim() == '') { return TDLabels.BLANK_WARNING; } return true; } }); taskDialog.estimateField = new Ext.form.NumberField({ id:'EstimatedEffort', fieldLabel: TDLabels.FORM_ESTIMATE, name: 'estimate', anchor:'100%', allowBlank: true, maxLength: 9, listeners: { focus: taskDialog.onFocusTaskEstimate} }); taskDialog.descField = new Ext.form.TextArea({ id:'taskDialogTaskDesc', fieldLabel: TDLabels.FORM_DESCRIPTION, name: 'Description', anchor: '93%', height: 92, maxLength: 2000 }); taskDialog.resourceFS.on('collapse', function(panel) { //taskDialog.dialog.setHeight(375); taskDialog.descriptionMaxLength = 200; }); taskDialog.resourceFS.on('expand', function(panel) { //taskDialog.dialog.setHeight(520); taskDialog.descriptionMaxLength = 400; }); taskDialog.saveButton = new Ext.Button({ id: 'taskDialogSaveButton', text: TDLabels.SAVE, minWidth : 75, handler: function(){ taskDialog.preSaveHandler(); } }); taskDialog.testCaseValuePanel = new Ext.Panel({ html: '
' }) taskDialog.descriptionValuePanel = new Ext.Panel({ html: '' }) taskDialog.lastRunValuePanel = new Ext.Panel({ html: '' }) var topTable = new Ext.Panel({ layout: 'table', border: false, cls: 'tests-tab-table-panel', defaults: { bodyStyle: 'padding: 10px 10px 0px 10px; border: none' }, layoutConfig: { columns: 2 }, items: [{ html: '' + TDLabels.TESTS_TAB_TEST_CASE_LABEL + '
' }, taskDialog.testCaseValuePanel ,{ html: '' + TDLabels.TESTS_TAB_DESCRIPTION_LABEL + '
' }, taskDialog.descriptionValuePanel ,{ html: '' + TDLabels.TESTS_TAB_STATUS_LABEL + '
' },{ html: '' },{ html: '' + TDLabels.TESTS_TAB_LAST_RUN_LABEL + '
' }, taskDialog.lastRunValuePanel ] }); var testsPanel = new Ext.Panel({ items: [topTable], bodyBorder: false }); taskDialog.testsTabPanel = new Ext.Panel({ title: TDLabels.TESTS_TAB_TITLE, border: false, items: [testsPanel] }); taskDialog.tabPanel = new Ext.TabPanel({ activeTab: 0, layoutOnTabChange: true, ctCls: 'tab-panel-container', border: false, defaults: { autoHeight: true, bodyStyle:'padding:10px' }, items:[{ title: TDLabels.DETAILS_TAB_TITLE, layout:'form', buttonAlign: 'right', labelAlign: 'right', labelWidth: 70, items: [{ id: 'taskDlgId', xtype: 'hidden', name: 'taskid' },{ id: 'obstacleCount', xtype: 'hidden', name: 'ObstacleCount' }, taskDialog.dlgTitle, taskDialog.descField, taskDialog.storyCombo, { layout: 'column', height: 22, items: [ { columnWidth:.47, layout: 'form', labelWidth: 70, items: [ taskDialog.estimateField ] }, { columnWidth:.46, layout: 'form', labelWidth: 55, items: [ taskDialog.statusCombo ] }] }, taskDialog.resourceFS, { id:'obstacle-msg', autowidth:true, height:20, html:obstacleMsg }] }] }); // form control var obstacleMsg = " " + "$OBSTACLE_MESSAGE"; taskDialog.dlgFormCtrl = new Ext.FormPanel({ buttonAlign: 'right', labelAlign: 'right', labelWidth: 70, frame:true, cls: 'task-form-panel', items: taskDialog.tabPanel, buttons: [ taskDialog.saveButton, { text: TDLabels.CANCEL, minWidth: 70, handler: function() { taskDialog.dialog.hide(); } }] }); }, preSaveHandler : function() { if(!taskDialog.dlgFormCtrl.form.isValid()) { BxtUtil.showErrorMsg(TDLabels.FORM_INVALID_VALUES) return; } taskDialog.dialog.confirmHide = true; // build JSON object to hold resources var resources = []; var ds = taskDialog.resourceDS; ds.commitChanges(); setTimeout("true", 5000); var count = ds.getCount(); for (var i = 0;i < count;i++) { resource = ds.getAt(i); var usr = resource.get('user'); if(usr === null || usr === '') { BxtUtil.showErrorMsg(TDLabels.NO_RESOURCE_MSG); return; } resources[i] = { 'resourceid' : resource.get('resourceid'), 'user': resource.get('user'), 'actual': resource.get('actual'), 'remain': resource.get('remain'), 'planned': resource.get('planned') }; } taskDialog.saveTask(resources); }, createResourceGrid : function() { // create resource record definition taskDialog.resourceRec = Ext.data.Record.create( [ {name: 'resourceid'}, {name: 'user'}, {name: 'actual', type: 'float'}, {name: 'remain', type: 'float'}, {name: 'planned', type: 'float'} ]); // create the data store taskDialog.resourceDS = new Ext.data.Store({ id : 0, proxy: new Ext.data.HttpProxy({url:'pbv/PBVAsyncHandler?action=GET-TASK'}), reader: new Ext.data.JsonReader({ totalProperty: 'resourceCount', root: 'resources' }, taskDialog.resourceRec), sortInfo:{field: 'user', direction: "ASC"} }); taskDialog.resourceDS.on('update', function(ds, record, op) { // if a resource has been edited update the estimated hours if (Ext.data.Record.EDIT == op) { if (TDStatuses.UPCOMING == taskDialog.statusCombo.getValue()) //Upcoming is the only state when estimate is editable { // set the resource remaining time equal to the estimated time record.set('remain', record.get('planned')); } // update task estimate if a resource estimate is entered var estimateTotal = taskDialog.calculateEstimated(); if (0 != estimateTotal) { taskDialog.estimateField.setValue(estimateTotal); } } }); // create editors for each column var editors = []; editors[0] = new Ext.form.ComboBox ({ name: 'name', store: taskDialog.usersDS, displayField: 'name', valueField: 'id', value: '', emptyText: TDLabels.CHOOSE, selectOnFocus: true, forceSelection : true, listClass: 'x-combo-list-small', mode: 'local', allowBlank: true, triggerAction: 'all', typeAhead: true, listeners: { select: taskDialog.onUserComboSelect, focus : taskDialog.onUserComboFocus} }); for(var col =1; col < 4; col++) { editors[col] = new Ext.form.NumberField({allowBlank:false, selectOnFocus: true, maxLength : 10 }) ; } taskDialog.editors = editors; taskDialog.addResBtn = new Ext.Button({text: TDLabels.ADD_RESOURCE, tooltip: TDLabels.ADD_RESOURCE_TT, iconCls: 'add'}); taskDialog.removeResBtn = new Ext.Button({text: TDLabels.REMOVE_RESOURCE, tooltip: TDLabels.REMOVE_RESOURCE_TT, iconCls: 'remove'}); var summary = new Ext.ux.grid.GridSummary(); function renderTotalsText() { return TDLabels.TOTALS; } taskDialog.gridpanel = new Ext.grid.EditorGridPanel({ store: taskDialog.resourceDS, columns: [ { header:'', hidden: true, width:15, dataIndex:'remain', renderer:function(v) { return '';}}, // dummy row {id:'user',header: TDLabels.GRID_PERSON, width: 140, sortable: false, resizable: false, dataIndex: 'user' ,editor: editors[0] ,summaryRenderer: renderTotalsText ,renderer: function(v,p) { var result = TDLabels.CHOOSE; for (var i = 0;i < taskDialog.userArray.length;i++) { if (v == taskDialog.userArray[i].id) { result = taskDialog.userArray[i].name; break; } } return result; } }, {header: TDLabels.GRID_SPENT, width: 60, sortable: false, resizable: false, dataIndex: 'actual',editor: editors[1], renderer: TBLRender.Number, summaryType: 'sum'}, {header: TDLabels.GRID_REMAINING, width: 60, sortable: false, resizable: false, dataIndex: 'remain',editor: editors[2], renderer: TBLRender.Number, summaryType: 'sum'}, {header: TDLabels.GRID_ESTIMATE, width: 60, sortable: false, resizable: false, dataIndex: 'planned',editor: editors[3], renderer: TBLRender.Number, summaryType: 'sum'} ], enableColumnMove: false, tbar : [ '->',taskDialog.addResBtn, {xtype: 'tbseparator'}, taskDialog.removeResBtn ], clicksToEdit: 1, cls: 'resource-grid-panel', stripeRows: false, autoExpandColumn: 'user', height:150, width:428, frame: false, border: true, bodyBorder: true, layout: 'fit', plugins: [summary], sm : new Ext.grid.RowSelectionModel() }); taskDialog.addResBtn.on('click', function() { var records = new Array(1); records[0] = new taskDialog.resourceRec({ resourceid : '', user: '', actual: 0, remain: 0, planned: 0 }); taskDialog.resourceDS.add(records); }); taskDialog.removeResBtn.on('click', function() { var selected = taskDialog.gridpanel.getSelectionModel().getSelected(); if (selected) { // get original resource estimate // if the estimate is zero then user could be estimating at // the task level, so don't change the estimate var estimateTotal = taskDialog.calculateEstimated(); var updateEstimate = false; if (0 != estimateTotal) { updateEstimate = true; } taskDialog.resourceDS.remove(selected); // update estimate field estimateTotal = taskDialog.calculateEstimated(); if (updateEstimate) { taskDialog.estimateField.setValue(estimateTotal); } taskDialog.filterUsers(); } }); }, createStatusComboBox : function() { // status taskDialog.statusRec = Ext.data.Record.create( [ { name:'id' }, { name:'value'}, { name:'seq'} ]); taskDialog.statusDS = new Ext.data.Store({ id : 0, reader: new Ext.data.JsonReader({ totalProperty: 'statusCount', root: 'statuses' }, taskDialog.statusRec), sortInfo:{field: 'seq', direction: "ASC"} }); taskDialog.statusCombo = new Ext.form.ComboBox({ // id: 'Status',// For some reason this causes the status dialog to disappear fieldLabel: TDLabels.STATUS, name: 'status', store: taskDialog.statusDS, displayField: 'value', valueField: 'id', value: '', selectOnFocus: true, forceSelection : true, listClass: 'x-combo-list-small', mode: 'local', allowBlank: true, triggerAction: 'all', editable: false, autoWidth: false, anchor: '100%', listeners : { select : taskDialog.onStatusSelect, beforeselect: function(){ taskDialog.lastStatus = taskDialog.statusCombo.getValue(); if(taskDialog.obstacleCount>0 && taskDialog.dialogLoaded) { ErrorHandlerLib.showErrorMsg('$TASK_STATUS_ERROR','$TASK_STATUS_ERROR_TITLE'); return false; } else return true; } } }); }, createStoryComboBox : function () { taskDialog.storyRec = Ext.data.Record.create( [ { name:'id' }, { name:'name', sortType:'asUCString' } ]); taskDialog.storyDS = new Ext.data.Store({ id : 0, proxy: new Ext.data.HttpProxy({url: 'pbv/PBVAsyncHandler?action=REQS-BY-SPRINT'}), reader: new Ext.data.JsonReader({ totalProperty: 'storyCount', root: 'stories' }, taskDialog.storyRec), sortInfo:{field: 'name', direction: "ASC"} }); taskDialog.storyCombo = new Ext.form.ComboBox({ fieldLabel: TDLabels.STORY, name: 'storyid', store: taskDialog.storyDS, displayField: 'name', valueField: 'id', value: '', selectOnFocus: true, forceSelection : true, listClass: 'x-combo-list-small', mode: 'local', allowBlank: true, triggerAction: 'all', editable: false, autoWidth: false, anchor: '93%' }); }, createUsersDS : function() { taskDialog.userRec = Ext.data.Record.create( [ { name:'id' }, { name:'name', sortType:'asUCString' } ]); taskDialog.usersDS = new Ext.data.Store({ id : 0, proxy: new Ext.data.HttpProxy({url:'pbv/PBVAsyncHandler?action=USERLIST'}), reader: new Ext.data.JsonReader({ totalProperty: 'userCount', root: 'users' }, taskDialog.userRec), sortInfo:{field: 'name', direction: "ASC"} }); taskDialog.usersDS.on('load', function() { taskDialog.userArray = new Array(); var ds = taskDialog.usersDS; for (var i = 0;i < ds.getCount();i++) { var user = ds.getAt(i); taskDialog.userArray[i] = { 'id' : user.get('id'), 'name' : user.get('name') }; } }); }, // ---------- Add/Edit/SaveTask ---------- addNewTask : function(sprintId, storyId, el, loadMask) { taskDialog.action = Actions.ADD_TASK; taskDialog.testStatus = null; taskDialog.dialog.confirmHide = false; taskDialog.lastStatus = null; taskDialog.selectedTaskId = null; // clear form taskDialog.resourceDS.removeAll(); taskDialog.saveButton.setDisabled(false); taskDialog.dlgFormCtrl.form.reset(); taskDialog.estimateField.setDisabled(false); var estimateTotal = taskDialog.calculateEstimated(); taskDialog.estimateField.setValue(estimateTotal); // reload data taskDialog.dialog.setTitle(TDLabels.ADD_TASK_TITLE); BxtLoadUtil.loadWidget( 'pbv/PBVAsyncHandler?action=LOAD-TASK', { sprintid: sprintId, storyid: storyId, isNew: true }, { el: el }, null,//loadMask is casing scrolling issues, so use progress bar taskDialog.loadDlgCallback, true//showProgress ); }, editTask : function(projectId, sprintId, taskId, isCopy, el, loadMask) { taskDialog.action = Actions.EDIT_TASK; taskDialog.dialog.confirmHide = false; if (!isCopy) { taskDialog.selectedTaskId = taskId; } else{ taskDialog.selectedTaskId = null; } taskDialog.lastStatus = null; taskDialog.testStatus = null; taskDialog.dialogLoaded =false; // clear form taskDialog.resourceDS.removeAll(); taskDialog.dlgFormCtrl.form.reset(); // reload data if(isCopy) { taskDialog.dialog.setTitle(TDLabels.ADD_TASK_TITLE); } else { taskDialog.dialog.setTitle(TDLabels.EDIT_TASK_TITLE); } BxtLoadUtil.loadWidget( 'pbv/PBVAsyncHandler?action=LOAD-TASK', { taskid: taskId, projectid: projectId, sprintid: sprintId, isCopy: isCopy, isNew: false }, { el: el }, null,//loadMask is casing scrolling issues, so use progress bar taskDialog.loadDlgCallback, true//showProgress ); }, loadDlgCallback : function(formJSON, action) { //********************* // Load Data Stores //********************* // load user combo data taskDialog.usersDS.loadData(formJSON); // load story combo data taskDialog.storyDS.loadData(formJSON); // load status combo data // taskDialog.statusDS.loadData(formJSON); // load resource grid data // check for resources and expand/collapse the form field accordingly if (formJSON.resourceCount > 0) { taskDialog.resourceDS.loadData(formJSON); //taskDialog.resourceFS.expand(); } else { //taskDialog.resourceFS.collapse(); } //********************* // Set Field Values //********************* taskDialog.tabPanel.activate(0); taskDialog.loadDlgComponents(formJSON.fields, false); // send status event to trigger form actions(enable/disable controls) var record = taskDialog.statusDS.getAt(taskDialog.statusDS.find('id', taskDialog.statusCombo.getValue())); taskDialog.statusCombo.fireEvent('select', taskDialog.statusCombo, record, taskDialog.statusDS.indexOf(record)); taskDialog.dialog.show(action.settings.el); if(formJSON.unmapped) { BxtUtil.showErrorMsg('$USERMAP_ERROR' + " " + formJSON.unmapped + "." + '$USERMAP_INFO'); taskDialog.saveButton.setDisabled(true); } else { taskDialog.saveButton.setDisabled(false); } #if (!$canManageTasks) taskDialog.saveButton.setDisabled(true); #end taskDialog.obstacleCount = formJSON.ObstacleCount; if (taskDialog.obstacleCount <=0) { document.getElementById('obstacle-msg').innerHTML = ''; } else { var obstacleMsg = " " + "$OBSTACLE_MESSAGE"; document.getElementById('obstacle-msg').innerHTML = obstacleMsg; } taskDialog.dialogLoaded = true; }, loadDlgComponents : function(fields,reload) { //********************* // Set Field Values //********************* if (fields) { for (var i = 0; i < fields.length; i++) { // get form component var fieldId = fields[i].fieldId; var cmp = taskDialog.getComponent(fieldId); if(cmp) { // check for component data and load if (fieldId == TDFieldIds.STATUS) { taskDialog.statusDS.loadData(fields[i].data); } else { if (null != fields[i].data) { cmp.store.loadData(fields[i].data); } } //localize blank text cmp.blankText = '$REQUIRED_FIELD'; // st field validation if (null != fields[i].required) { cmp.allowBlank = !fields[i].required; } if (null != fields[i].maxLength && -1 != fields[i].maxLength) { cmp.maxLength = fields[i].maxLength; } else { cmp.maxLength = undefined; } // set component value if (!reload) { var fieldValue = fields[i].value; if(null != fieldValue) { var fieldId = fields[i].fieldId; if (TDFieldIds.NAME == fieldId || TDFieldIds.DESCRIPTION == fieldId || TDFieldIds.TEST_CASE == fieldId || TDFieldIds.TEST_DESCRIPTION == fieldId) { fieldValue = g_encoder.unescapeBT(fieldValue); } if (TDFieldIds.NAME == fieldId || TDFieldIds.DESCRIPTION == fieldId) { cmp.setValue(fieldValue); } else if (TDFieldIds.TEST_STATUS_ID == fieldId) { var testStatus = fieldValue; taskDialog.testStatus = testStatus; var isTestTask = testStatus != null && testStatus != ""; cmp.setValue(isTestTask); } else if (TDFieldIds.LAST_RUN_DATE == fieldId) { // we should probably find a way to update taskDialog.lastRunValuePanel // rather than setting taskDialog.lastRunDate and using it in the // tab panel 'beforetabchange' event taskDialog.lastRunDate = fieldValue; } else if (TDFieldIds.TEST_CASE == fieldId) { // we should probably find a way to update taskDialog.testCaseValuePanel // rather than setting taskDialog.lastRunDate and using it in the // tab panel 'beforetabchange' event taskDialog.testCase = fieldValue; } else if (TDFieldIds.TEST_DESCRIPTION == fieldId) { // we should probably find a way to update taskDialog.descriptionValuePanel // rather than setting taskDialog.lastRunDate and using it in the // tab panel 'beforetabchange' event taskDialog.testDescription = fieldValue; } else { cmp.setValue(fieldValue); } }else { cmp.setValue(); } } } } } }, getComponent: function(fieldId) { if(fieldId == TDFieldIds.STORYID){ return taskDialog.storyCombo; } else if(fieldId == TDFieldIds.TASKID){ return Ext.getCmp(fieldId); }else if(fieldId == TDFieldIds.NAME){ return taskDialog.dlgTitle; } else if (fieldId ==TDFieldIds.DESCRIPTION){ return taskDialog.descField ; } else if(fieldId == TDFieldIds.STATUS){ return taskDialog.statusCombo ; } else if(fieldId == TDFieldIds.ESTIMATEDEFFORT){ return taskDialog.estimateField ; } else if(fieldId == TDFieldIds.LAST_RUN_DATE) { return taskDialog.lastRunValuePanel; } else if(fieldId == TDFieldIds.TEST_CASE) { return taskDialog.testCaseValuePanel; } else if(fieldId == TDFieldIds.TEST_DESCRIPTION) { return taskDialog.descriptionValuePanel; } else { return Ext.getCmp(fieldId); } }, saveTask : function(resources) { // post values to save. Some explicit submit parameters are here because // submit is sending the value of the combo box instead of its id. taskDialog.estimateField.setDisabled(false); // task level estimate enabled to submit value // escape name and description values var esc_name = g_encoder.escapeBT(taskDialog.dlgTitle.getValue()); var esc_desc = g_encoder.escapeBT(taskDialog.descField.getValue()); var params = { action:'SAVE-TASK', taskid: taskDialog.selectedTaskId, sprintid: teamboard.sprintCombobox.getValue(), storyid: taskDialog.storyCombo.getValue(), name: esc_name, desc: esc_desc, status: taskDialog.statusCombo.getValue(), estimate: taskDialog.estimateField.getValue(), resources: Ext.util.JSON.encode(resources) }; taskDialog.dlgFormCtrl.form.submit({url:'pbv/PBVAsyncHandler', waitMsg : ' ', waitTitle : TDLabels.SAVE_MSG, params : params, settings: {show: true, title:'$SAVE_ERROR_TITLE'}, success : function(form, action) { taskDialog.dialog.hide(); if(taskDialog.saveSuccessHandlerFn) { taskDialog.saveSuccessHandlerFn(form, action); } }, failure:function(form, action) { taskDialog.dialog.confirmHide = false; if(taskDialog.saveFailureHandlerFn) { taskDialog.saveFailureHandlerFn(form, action); } else { ErrorHandlerLib.onFormFailure(form, action); } } }); }, hasUnmappedUsers : function(formJSON) { //formJSON if(formJSON.resources) { var res = formJSON.resources; for(var i = 0; i < res.length; i++) { if(res[i].resourceid === '-') { return true; } } } return false; }, onStatusSelect: function(combo, rec, index){ var id = combo.getValue(); if (TDStatuses.UPCOMING == id) { //Upcoming taskDialog.gridpanel.getColumnModel().setEditable(1, true); // user combo taskDialog.gridpanel.getColumnModel().setEditable(2, false); //spent taskDialog.gridpanel.getColumnModel().setEditable(3, false); //remaining taskDialog.gridpanel.getColumnModel().setEditable(4, true); //estimated taskDialog.addResBtn.setDisabled(false); // add resource taskDialog.removeResBtn.setDisabled(false); //remove resource taskDialog.estimateField.setDisabled(false); // task level estimate // set all resource estimates to blank as default for upcoming status if (null != taskDialog.lastStatus && TDStatuses.UPCOMING != taskDialog.lastStatus) { taskDialog.zeroResourceTimeSpent(); taskDialog.zeroResourceEstimates(); taskDialog.zeroResourceTimeRemaining(); taskDialog.estimateField.setValue(''); } } else if (TDStatuses.STARTED == id) { //Started taskDialog.gridpanel.getColumnModel().setEditable(1, true); // user combo taskDialog.gridpanel.getColumnModel().setEditable(2, true); //spent taskDialog.gridpanel.getColumnModel().setEditable(3, true); //remaining taskDialog.gridpanel.getColumnModel().setEditable(4, false); //estimated taskDialog.addResBtn.setDisabled(false); // add resource taskDialog.removeResBtn.setDisabled(false); //remove resource taskDialog.estimateField.setDisabled(true); // task level estimate } else if (TDStatuses.COMPLETED == id || TDStatuses.CANCELLED == id) { //Completed taskDialog.gridpanel.getColumnModel().setEditable(1, false); // user combo taskDialog.gridpanel.getColumnModel().setEditable(2, false); //spent taskDialog.gridpanel.getColumnModel().setEditable(3, false); //remaining taskDialog.gridpanel.getColumnModel().setEditable(4, false); //estimated taskDialog.addResBtn.setDisabled(true); // add resource taskDialog.removeResBtn.setDisabled(true); //remove resource taskDialog.estimateField.setDisabled(true); // task level estimate // set all resource time remaining values to zero if (null != taskDialog.lastStatus && (TDStatuses.COMPLETED != taskDialog.lastStatus || TDStatuses.CANCELLED != taskDialog.lastStatus)) { taskDialog.zeroResourceTimeRemaining(); } } }, calculateEstimated : function() { var ds = taskDialog.resourceDS; var count = ds.getCount(); var estimateTotal = 0.0; for (var i = 0;i < count;i++) { estimateTotal += parseFloat(ds.getAt(i).get('planned')); } return estimateTotal; }, onUserComboFocus : function(combo) { var selectedUserId = combo.getValue(); taskDialog.filterUsers(selectedUserId); combo.setValue(selectedUserId); }, onUserComboSelect : function(combo, record, index) { taskDialog.gridpanel.stopEditing(); }, filterUsers : function(selectedUserId) { taskDialog.usersDS.filterBy(function(record, id) { var result = true; var ds = taskDialog.resourceDS; var userId = record.get('id'); if(userId == selectedUserId) { return true; } for (var i = 0;i < ds.getCount();i++) { var resource = ds.getAt(i); if (userId == resource.get('user')) { result = false; break; } } return result; }); }, onFocusTaskEstimate : function(field) { var ds = taskDialog.resourceDS; var count = ds.getCount(); // check for resources if (count > 0) { // check for resource level estimates var hasEstimate = false; for (var i = 0;i < count;i++) { if (ds.getAt(i).get('planned') != '0') { hasEstimate = true; } } // if user level estimates, then alert user if (hasEstimate) { Ext.Msg.show({ title: TDLabels.ESTIMATE_MSG_TITLE, msg: '' + TDLabels.ESTIMATE_MSG + '', buttons: Ext.Msg.OKCANCEL, fn: taskDialog.resetResourceEstimates, icon: Ext.MessageBox.QUESTION, animEl: taskDialog.estimateField.getEl() }); } } }, resetResourceEstimates : function(val) { if ('ok' == val) { taskDialog.zeroResourceEstimates(); } }, zeroResourceTimeRemaining : function() { var ds = taskDialog.resourceDS; ds.commitChanges(); var count = ds.getCount(); for (var i = 0; i < count; i++) { ds.getAt(i).set('remain', '0'); } ds.commitChanges(); }, zeroResourceEstimates : function() { var ds = taskDialog.resourceDS; ds.commitChanges(); var count = ds.getCount(); for (var i = 0; i < count; i++) { ds.getAt(i).set('planned', '0'); } ds.commitChanges(); }, zeroResourceTimeSpent : function() { var ds = taskDialog.resourceDS; ds.commitChanges(); var count = ds.getCount(); for (var i = 0; i < count; i++) { ds.getAt(i).set('actual', '0'); } ds.commitChanges(); } };