Mjs.Dialogs.ImportGraph = {
DIALOG_ID : "#dialog-import-graph",
open: function(){
Mjs.Dialogs.ImportGraph._open();
},
_open: function() {
$( Mjs.Dialogs.ImportGraph.DIALOG_ID ).dialog( "open" );
},
init: function() {
$( Mjs.Dialogs.ImportGraph.DIALOG_ID ).dialog({
resizable: true,
autoOpen: false,
modal: true,
dialogClass: 'dialog-container-import-graph',
height: 300,
title: 'Paste xml into the text area below',
width: 500,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
},
Save: function() {
var emEl = $('.error-message', this);
emEl.removeClass('ui-state-highlight');
emEl.html('');
if (Mjs.Dialogs.ImportGraph.importGraph(this)) {
$( this ).dialog( "close" );
}
}
},
open: function() {
$('.xml-import', this).val('');
var emEl = $('.error-message', this);
emEl.removeClass('ui-state-highlight');
emEl.html('');
}
});
},
importGraph: function(dialogEl) {
// grab string out of textarea.
var xmlString = $('.xml-import').val().trim();
var xmlDoc = null, xml = null;
try {
// use jQuery.parseXML to create a doc
xmlDoc = $.parseXML(xmlString);
// convert elements to connectors and codelines
xml = $(xmlDoc);
} catch (e) {
var errorElem = $('.error-message', dialogEl);
errorElem.html(e.message);
errorElem.addClass('ui-state-highlight');
console.error(e);
return false;
}
var xmlBranches = xml.find('branch');
var xmlDepotPathMappings = xml.find('depotPathMapping');
var xmlBranchSpecMappings = xml.find('branchSpecMapping');
// add codelines to the collections
// which should trigger the drawing of the codelines
_.each(xmlBranches, function(branchEl) {
var params = {
height : branchEl.getAttribute('height'),
name : branchEl.getAttribute('name'),
type : branchEl.getAttribute('type'),
x : branchEl.getAttribute('x'),
y : branchEl.getAttribute('y'),
width : branchEl.getAttribute('width'),
id : branchEl.getAttribute('id'),
};
Mjs.Collections.codelineCollection.add(params);
});
_.each(xmlDepotPathMappings, function(specEl) {
var params = {
direction : specEl.getAttribute('direction'),
joints: specEl.getAttribute('joints'),
latestTarget: specEl.getAttribute('latestTarget'),
name : specEl.getAttribute('name'),
source : specEl.getAttribute('source'),
target : specEl.getAttribute('target'),
sourceAnchor : specEl.getAttribute('sourceAnchor'),
sourceChanges : specEl.getAttribute('sourceChanges'),
targetChanges : specEl.getAttribute('targetChanges'),
sourceNumCL : specEl.getAttribute('sourceCount'),
targetNumCL : specEl.getAttribute('targetCount'),
sourcePath : specEl.getAttribute('sourcePath'),
targetPath : specEl.getAttribute('targetPath')
};
params.type = 'path';
Mjs.Collections.connectorCollection.add(params);
});
_.each(xmlBranchSpecMappings, function(specEl) {
var params = {
direction : specEl.getAttribute('direction'),
joints : specEl.getAttribute('joints'),
latestTarget : specEl.getAttribute('latestTarget'),
name : specEl.getAttribute('name'),
source : specEl.getAttribute('source'),
target : specEl.getAttribute('target'),
sourceAnchor : specEl.getAttribute('sourceAnchor'),
sourceChanges : specEl.getAttribute('sourceChanges'),
targetChanges : specEl.getAttribute('targetChanges'),
sourceNumCL : specEl.getAttribute('sourceCount'),
targetNumCL : specEl.getAttribute('targetCount')
};
params.type = 'branch';
Mjs.Collections.connectorCollection.add(params);
});
return true;
}
};