91 lines
3.9 KiB
JavaScript
Raw Normal View History

2015-06-11 14:22:18 -07:00
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define */
define(
['./AbstractComposeAction'],
function (AbstractComposeAction) {
"use strict";
2015-06-12 10:08:34 -07:00
/**
* The CopyAction is available from context menus and allows a user to
* deep copy an object to another location of their choosing.
*
* @implements {Action}
* @constructor
* @memberof platform/entanglement
2015-06-12 10:08:34 -07:00
*/
2015-10-29 17:15:20 -07:00
function CopyAction($log, locationService, copyService, dialogService, notificationService, context) {
this.dialogService = dialogService;
this.notificationService = notificationService;
2015-10-29 17:15:20 -07:00
this.$log = $log;
AbstractComposeAction.call(this, locationService, copyService, context, "Duplicate", "to a location");
}
CopyAction.prototype = Object.create(AbstractComposeAction.prototype);
CopyAction.prototype.perform = function() {
var self = this,
notification,
2015-10-28 17:05:05 -07:00
notificationModel = {
title: "Copying objects",
unknownProgress: false,
severity: "info",
};
2015-10-28 17:05:05 -07:00
function progress(phase, totalObjects, processed){
if (phase.toLowerCase() === 'preparing'){
self.dialogService.showBlockingMessage({
2015-10-28 17:05:05 -07:00
title: "Preparing to copy objects",
unknownProgress: true,
severity: "info",
});
} else if (phase.toLowerCase() === "copying") {
self.dialogService.dismiss();
2015-10-28 17:05:05 -07:00
if (!notification) {
notification = self.notificationService.notify(notificationModel);
2015-10-28 17:05:05 -07:00
}
notificationModel.progress = (processed / totalObjects) * 100;
notificationModel.title = ["Copied ", processed, "of ", totalObjects, "objects"].join(" ");
2015-10-28 17:05:05 -07:00
}
}
AbstractComposeAction.prototype.perform.call(this, progress)
.then(function(){
2015-10-29 17:40:17 -07:00
notification.dismiss();
self.notificationService.info("Copying complete.");
2015-10-29 17:15:20 -07:00
})
.catch(function (error){
self.$log.error("Error copying objects. ", error);
//Show more general error message
self.notificationService.notify({
title: "Error copying objects.",
severity: "error",
hint: error.message
});
});
};
return CopyAction;
}
);