2014-03-18 16:01:24 +00:00
|
|
|
var Diagram = require('diagram-js');
|
2014-03-21 20:10:01 +00:00
|
|
|
|
|
|
|
var Importer = require('./Importer'),
|
|
|
|
Model = require('./Model');
|
2014-03-18 16:01:24 +00:00
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
function Viewer(container) {
|
2014-03-18 16:01:24 +00:00
|
|
|
this.container = container;
|
|
|
|
}
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
Viewer.prototype.importXML = function(xml, done) {
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
Model.fromXML(xml, 'bpmn:Definitions', function(err, definitions) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.importDefinitions(definitions, done);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
Viewer.prototype.importDefinitions = function(definitions, done) {
|
2014-03-18 16:01:24 +00:00
|
|
|
|
|
|
|
if (this.diagram) {
|
|
|
|
this.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.diagram = this.createDiagram();
|
|
|
|
this.definitions = definitions;
|
|
|
|
|
|
|
|
Importer.importBpmnDiagram(this.diagram, definitions, done);
|
|
|
|
};
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
Viewer.prototype.createDiagram = function() {
|
2014-03-18 16:01:24 +00:00
|
|
|
return new Diagram({ canvas: { container: this.container }});
|
|
|
|
};
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
Viewer.prototype.clear = function() {
|
2014-03-18 16:01:24 +00:00
|
|
|
this.container.innerHTML = '';
|
|
|
|
};
|
|
|
|
|
2014-03-20 15:18:23 +00:00
|
|
|
module.exports = Viewer;
|