pads_app
Version:
playground of algorithms for Distributed Systems(PADS)
106 lines (80 loc) • 3.24 kB
JavaScript
/*globals define, WebGMEGlobal*/
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Mon May 23 2016 13:09:52 GMT-0500 (CDT).
*/
define(['css!./styles/VisualizersWidget.css'], function () {
'use strict';
var VisualizersWidget,
WIDGET_CLASS = 'visualizers';
VisualizersWidget = function (logger, container) {
this._logger = logger.fork('Widget');
this._el = container;
this.nodes = {};
this._initialize();
this._logger.debug('ctor finished');
};
VisualizersWidget.prototype._initialize = function () {
var width = this._el.width(),
height = this._el.height(),
self = this;
// set widget class
this._el.addClass(WIDGET_CLASS);
// Create a dummy header
this._el.append('<h3>Visualizers Events:</h3>');
// Registering to events can be done with jQuery (as normal)
this._el.on('dblclick', function (event) {
event.stopPropagation();
event.preventDefault();
self.onBackgroundDblClick();
});
};
VisualizersWidget.prototype.onWidgetContainerResize = function (width, height) {
this._logger.debug('Widget is resizing...');
};
// Adding/Removing/Updating items
VisualizersWidget.prototype.addNode = function (desc) {
if (desc) {
// Add node to a table of nodes
var node = document.createElement('div'),
label = 'children';
if (desc.childrenIds.length === 1) {
label = 'child';
}
this.nodes[desc.id] = desc;
node.innerHTML = 'Adding node "' + desc.name + '" (click to view). It has ' +
desc.childrenIds.length + ' ' + label + '.';
this._el.append(node);
node.onclick = this.onNodeClick.bind(this, desc.id);
}
};
VisualizersWidget.prototype.removeNode = function (gmeId) {
var desc = this.nodes[gmeId];
this._el.append('<div>Removing node "' + desc.name + '"</div>');
delete this.nodes[gmeId];
};
VisualizersWidget.prototype.updateNode = function (desc) {
if (desc) {
this._logger.debug('Updating node:', desc);
this._el.append('<div>Updating node "' + desc.name + '"</div>');
}
};
/* * * * * * * * Visualizer event handlers * * * * * * * */
VisualizersWidget.prototype.onNodeClick = function (/*id*/) {
// This currently changes the active node to the given id and
// this is overridden in the controller.
};
VisualizersWidget.prototype.onBackgroundDblClick = function () {
this._el.append('<div>Background was double-clicked!!</div>');
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
VisualizersWidget.prototype.destroy = function () {
};
VisualizersWidget.prototype.onActivate = function () {
this._logger.debug('VisualizersWidget has been activated');
};
VisualizersWidget.prototype.onDeactivate = function () {
this._logger.debug('VisualizersWidget has been deactivated');
};
return VisualizersWidget;
});