(js) New action to mark task as completed

Fixes #4531
This commit is contained in:
Francis Lachapelle
2018-08-31 16:45:03 -04:00
parent 3881bc408d
commit 7aa3e1f160
3 changed files with 37 additions and 6 deletions
@@ -758,6 +758,31 @@
this.status != 'cancelled');
};
/**
* @function markAsCompleted
* @memberof Component.prototype
* @desc Mark the task as completed.
* @returns a promise of the HTTP operation
*/
Component.prototype.markAsCompleted = function() {
var _this = this, dlp;
if (this.type == 'task') {
dlp = Component.$Preferences.$mdDateLocaleProvider;
this.percentComplete = 100;
this.completed = new Date();
this.completed.$dateFormat = Component.$Preferences.defaults.SOGoLongDateFormat;
this.status = 'completed';
this.localizedCompletedDate = dlp.formatDate(this.completed);
this.localizedCompletedTime = dlp.formatTime(this.completed);
return this.$save().catch(function() {
_this.$reset();
});
}
else {
return Component.$q.reject('Only tasks can be mark as completed');
}
};
/**
* @function coversFreeBusy
* @memberof Component.prototype