src/mixins/Enableable/RemoveFromPlugin/RemoveFromPlugin.js
/*globals define*/
/*jshint node:true, browser:true*/
/**
* Generated by PluginGenerator from webgme on Wed Jul 29 2015 20:28:43 GMT-0500 (CDT).
*/
define(["plugin/PluginBase"], function (PluginBase) {
"use strict";
/**
* Initializes a new instance of RemoveFromPlugin.
* @class
* @augments {PluginBase}
* @classdesc This class represents the plugin RemoveFromPlugin.
* @constructor
*/
var RemoveFromPlugin = function () {
// Call base class' constructor.
PluginBase.call(this);
this.pluginMetadata = {
name: "ComponentDisabler",
version: "2.0.0",
configStructure: [
{
name: "field",
displayName: "Field",
description: "Field of root node to add to",
value: null,
valueType: "string",
readOnly: false,
},
{
name: "attribute",
displayName: "Attribute",
description: "Attribute to add to field",
value: "",
valueType: "string",
readOnly: false,
},
],
};
};
// Prototypal inheritance from PluginBase.
RemoveFromPlugin.prototype = Object.create(PluginBase.prototype);
RemoveFromPlugin.prototype.constructor = RemoveFromPlugin;
/**
* Main function for the plugin to execute. This will perform the execution.
* Notes:
* - Always log with the provided logger.[error,warning,info,debug].
* - Do NOT put any user interaction logic UI, etc. inside this method.
* - callback always has to be called even if error happened.
*
* @param {function(string, plugin.PluginResult)} callback - the result callback
*/
RemoveFromPlugin.prototype.main = function (callback) {
// Use self to access core, project, result, logger etc from PluginBase.
// These are all instantiated at this point.
var self = this,
currentConfig = self.getCurrentConfig(),
field = currentConfig.field,
attribute = currentConfig.attribute,
index,
attributes;
if (!currentConfig.field) {
self.result.setSuccess(false);
self.logger.info("No field provided");
return callback("No field provided", self.result);
}
// Add to root node's "field" attribute
attributes = self.core.getRegistry(self.rootNode, field).split(" ");
self.logger.info("Current values for " + field + ":", attributes);
index = attributes.indexOf(attribute);
if (index !== -1) {
attributes.splice(index, 1);
self.logger.info("Setting " + field + " to " + attributes.join(" "));
}
self.core.setRegistry(self.rootNode, field, attributes.join(" "));
// This will save the changes. If you don't want to save;
// exclude self.save and call callback directly from this scope.
self.result.setSuccess(true);
self.save("Removed " + attribute + " from " + field, function (err) {
callback(null, self.result);
});
};
return RemoveFromPlugin;
});