Added error handling, and refactored CopyAction slightly
This commit is contained in:
@@ -70,8 +70,12 @@ define(
|
||||
* @param {string} verb the verb to display for the action (e.g. "Move")
|
||||
* @param {string} [suffix] a string to display in the dialog title;
|
||||
* default is "to a new location"
|
||||
* @param {function} progressCallback a callback function that will
|
||||
* be invoked to update invoker on progress. This is optional and
|
||||
* may not be implemented by all composing actions. The signature of
|
||||
* the callback function will depend on the service being invoked.
|
||||
*/
|
||||
function AbstractComposeAction(locationService, composeService, context, verb, suffix, progressCallback) {
|
||||
function AbstractComposeAction(locationService, composeService, context, verb, suffix) {
|
||||
if (context.selectedObject) {
|
||||
this.newParent = context.domainObject;
|
||||
this.object = context.selectedObject;
|
||||
@@ -87,10 +91,9 @@ define(
|
||||
this.composeService = composeService;
|
||||
this.verb = verb || "Compose";
|
||||
this.suffix = suffix || "to a new location";
|
||||
this.progressCallback = progressCallback;
|
||||
}
|
||||
|
||||
AbstractComposeAction.prototype.perform = function () {
|
||||
AbstractComposeAction.prototype.perform = function (progressCallback) {
|
||||
var dialogTitle,
|
||||
label,
|
||||
validateLocation,
|
||||
@@ -98,7 +101,6 @@ define(
|
||||
composeService = this.composeService,
|
||||
currentParent = this.currentParent,
|
||||
newParent = this.newParent,
|
||||
progressCallback = this.progressCallback,
|
||||
object = this.object;
|
||||
|
||||
if (newParent) {
|
||||
|
||||
@@ -35,43 +35,57 @@ define(
|
||||
* @memberof platform/entanglement
|
||||
*/
|
||||
function CopyAction(locationService, copyService, dialogService, notificationService, context) {
|
||||
var notification,
|
||||
this.dialogService = dialogService;
|
||||
this.notificationService = notificationService;
|
||||
AbstractComposeAction.call(this, locationService, copyService, context, "Duplicate", "to a location");
|
||||
}
|
||||
|
||||
CopyAction.prototype = Object.create(AbstractComposeAction.prototype);
|
||||
|
||||
CopyAction.prototype.perform = function() {
|
||||
var self = this,
|
||||
notification,
|
||||
notificationModel = {
|
||||
title: "Copying objects",
|
||||
unknownProgress: false,
|
||||
severity: "info",
|
||||
};
|
||||
|
||||
|
||||
function progress(phase, totalObjects, processed){
|
||||
if (phase.toLowerCase() === 'preparing'){
|
||||
dialogService.showBlockingMessage({
|
||||
self.dialogService.showBlockingMessage({
|
||||
title: "Preparing to copy objects",
|
||||
unknownProgress: true,
|
||||
severity: "info",
|
||||
});
|
||||
} else if (phase.toLowerCase() === "copying") {
|
||||
dialogService.dismiss();
|
||||
self.dialogService.dismiss();
|
||||
if (!notification) {
|
||||
notification = notificationService.notify(notificationModel);
|
||||
notification = self.notificationService.notify(notificationModel);
|
||||
}
|
||||
notificationModel.progress = (processed / totalObjects) * 100;
|
||||
notificationModel.title = ["Copying ", processed, "of ", totalObjects, "objects"].join(" ");
|
||||
if (processed >= totalObjects){
|
||||
notificationModel.title = ["Copied ", processed, "of ", totalObjects, "objects"].join(" ");
|
||||
if (processed === totalObjects){
|
||||
notification.dismiss();
|
||||
self.notificationService.info(["Successfully copied ", totalObjects, " items."].join(""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new AbstractComposeAction(
|
||||
locationService,
|
||||
copyService,
|
||||
context,
|
||||
"Duplicate",
|
||||
"to a location",
|
||||
progress
|
||||
);
|
||||
}
|
||||
|
||||
AbstractComposeAction.prototype.perform.call(this, progress)
|
||||
.then(function(){
|
||||
self.notificationService.info("Copying complete.");
|
||||
},
|
||||
function (error){
|
||||
//log error
|
||||
//Show more general error message
|
||||
self.notificationService.notify({
|
||||
title: "Error copying objects.",
|
||||
severity: "error",
|
||||
hint: error.message
|
||||
});
|
||||
});
|
||||
};
|
||||
return CopyAction;
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user