Name
global.ScrumSprintStateWatcher
Description
Update percent_complete in Sprint when its state changes
Script
var ScrumSprintStateWatcher = Class.create();
ScrumSprintStateWatcher.SPRINT_CANCELLED = 4;
ScrumSprintStateWatcher.SPRINT_COMPLETED = 3;
ScrumSprintStateWatcher.prototype = {
initialize: function(sprint) {
this.sprint = sprint;
},
sprintStateChanged: function() {
if ( this.sprint.state != ScrumSprintStateWatcher.SPRINT_CANCELLED && this.sprint.state != ScrumSprintStateWatcher.SPRINT_COMPLETED ) {
this.sprintReopened();
}
else if ( this.sprint.state == ScrumSprintStateWatcher.SPRINT_COMPLETED ) {
this.sprintCompleted();
}
},
sprintStateSet: function() {
if ( this.sprint.state == ScrumSprintStateWatcher.SPRINT_COMPLETED ) {
this.sprintCompleted();
}
else if ( this.sprint.state == ScrumSprintStateWatcher.SPRINT_CANCELLED ) {
this.sprintCancelled();
}
else {
this.sprintOpened();
}
},
sprintOpened: function() {
this.sprint.percent_complete = 0;
},
sprintReopened: function() {
this.sprint.percent_complete = 0;
},
sprintCancelled: function() {
this.sprint.percent_complete = 0;
this.setSprintDurationToZero();
},
sprintCancelRevoked: function() {
this.setSprintDurationToOne();
},
sprintCompleted: function() {
this.sprint.percent_complete = 100;
},
setSprintDurationToZero: function() {
var now = gs.nowDateTime();
this.sprint.duration = gs.dateDiff(now, now, false);
},
setSprintDurationToOne: function() {
this.sprint.duration = new GlideDateTime("1970-01-02 00:00:00");
},
type: 'ScrumSprintStateWatcher'
}
Sys ID
5f0b46368f0221001a83cfd827bdeeab