mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 14:45:35 +00:00
Add module copy functionality - drag module whilst holding 'alt' to copy
This commit is contained in:
@@ -12,20 +12,28 @@ export default class Module {
|
||||
* @param {Object} params Module parameters. Either grp/id or template
|
||||
*/
|
||||
constructor(params) {
|
||||
let properties = Object.assign({ grp: null, id: null, template: null, }, params);
|
||||
let properties = Object.assign({ grp: null, id: null, template: null }, params);
|
||||
|
||||
let template;
|
||||
if (properties.template == undefined) {
|
||||
return ModuleUtils.findModule(properties.grp, properties.id);
|
||||
if (properties.class != undefined) {
|
||||
// We already have a fully-formed module; copy the data over
|
||||
for (let p in properties) { this[p] = properties[p]; }
|
||||
} else if (properties.template != undefined) {
|
||||
// We have a template from coriolis-data; copy the data over
|
||||
for (let p in properties.template) { this[p] = properties.template[p]; }
|
||||
} else {
|
||||
template = properties.template;
|
||||
if (template) {
|
||||
// Copy all properties from coriolis-data template
|
||||
for (let p in template) { this[p] = template[p]; }
|
||||
}
|
||||
// We don't have a template; find it given the group and ID
|
||||
return ModuleUtils.findModule(properties.grp, properties.id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone an existing module
|
||||
* @return {Object} A clone of the existing module
|
||||
*/
|
||||
clone() {
|
||||
return new Module(JSON.parse(JSON.stringify(this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value for a given modification
|
||||
* @param {Number} name The name of the modification
|
||||
|
||||
Reference in New Issue
Block a user