Mjs.Dialogs.ExportGraph = {
DIALOG_ID : "#dialog-export-graph",
open: function(){
Mjs.Dialogs.ExportGraph._open();
},
_open: function() {
$( Mjs.Dialogs.ExportGraph.DIALOG_ID ).dialog( "open" );
},
init: function() {
$( Mjs.Dialogs.ExportGraph.DIALOG_ID ).dialog({
resizable: false,
autoOpen: false,
modal: true,
dialogClass: 'dialog-container-export-graph',
height: 300,
title: 'Copy the xml and paste it into a file',
width: 500,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
},
open: function() {
var dialogElWrapper = $( Mjs.Dialogs.ExportGraph.DIALOG_ID )
.data().dialog.uiDialog;
var textarea = $( ".xml-export" );
textarea.val(Mjs.Dialogs.ExportGraph.exportGraph());
textarea.selectonfocus();
}
});
},
exportGraph: function() {
var xmlOutput = [];
xmlOutput.push('<?xml version="1.0" encoding="UTF-8" standalone="no"?>');
// TODO: does eclipse need the version information?
xmlOutput.push('<graphs version="2011.2/398861">');
// TODO: only dealing with one graph, so hardcoding here seems fine
xmlOutput.push('<graph id="graph0" name="Page 1">');
Mjs.Dialogs.ExportGraph._exportCollection(
Mjs.Collections.connectorCollection.toArray(), xmlOutput
);
Mjs.Dialogs.ExportGraph._exportCollection(
Mjs.Collections.codelineCollection.toArray(), xmlOutput
);
xmlOutput.push('</graph>');
xmlOutput.push('</graphs>');
return xmlOutput.join('');
},
_exportCollection: function(collection, buffer) {
_.each(collection, function(obj, index) {
buffer.push(obj.toXml());
buffer.push("\n");
});
},
};