maxGraph/javascript/examples/grapheditor/www/js/Dialogs.js

2253 lines
56 KiB
JavaScript
Raw Normal View History

2012-05-21 20:32:26 +00:00
/**
* Copyright (c) 2006-2012, JGraph Ltd
*/
/**
* Constructs a new dialog.
*/
function Dialog(editorUi, elt, w, h, modal, closable, onClose)
{
var dx = 0;
2013-12-20 16:51:26 +00:00
if (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8))
2012-05-21 20:32:26 +00:00
{
2013-12-09 08:35:20 +00:00
// Adds padding as a workaround for box model in older IE versions
// This needs to match the total padding of geDialog in CSS
2013-12-20 16:51:26 +00:00
dx = 80;
2012-05-21 20:32:26 +00:00
}
w += dx;
h += dx;
var left = Math.max(0, Math.round((document.body.scrollWidth - w) / 2));
var top = Math.max(0, Math.round((Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) - h) / 3));
2012-06-14 12:43:20 +00:00
var div = editorUi.createDiv('geDialog');
2012-05-21 20:32:26 +00:00
div.style.width = w + 'px';
div.style.height = h + 'px';
div.style.left = left + 'px';
div.style.top = top + 'px';
2014-10-03 12:49:36 +00:00
div.style.zIndex = this.zIndex;
2012-05-21 20:32:26 +00:00
if (this.bg == null)
{
this.bg = editorUi.createDiv('background');
this.bg.style.position = 'absolute';
this.bg.style.background = 'white';
this.bg.style.left = '0px';
this.bg.style.top = '0px';
this.bg.style.bottom = '0px';
this.bg.style.right = '0px';
2014-10-03 12:49:36 +00:00
this.bg.style.zIndex = this.zIndex;
2013-11-11 12:31:46 +00:00
2013-07-19 09:51:30 +00:00
mxUtils.setOpacity(this.bg, this.bgOpacity);
2012-05-21 20:32:26 +00:00
2012-07-20 10:35:30 +00:00
if (mxClient.IS_QUIRKS)
2012-05-21 20:32:26 +00:00
{
new mxDivResizer(this.bg);
}
}
if (modal)
{
document.body.appendChild(this.bg);
}
div.appendChild(elt);
document.body.appendChild(div);
if (closable)
{
var img = document.createElement('img');
img.setAttribute('src', IMAGE_PATH + '/close.png');
img.setAttribute('title', mxResources.get('close'));
2012-06-14 12:43:20 +00:00
img.className = 'geDialogClose';
2012-05-21 20:32:26 +00:00
img.style.top = (top + 14) + 'px';
img.style.left = (left + w + 38 - dx) + 'px';
2014-10-03 12:49:36 +00:00
img.style.zIndex = this.zIndex;
2012-05-21 20:32:26 +00:00
mxEvent.addListener(img, 'click', mxUtils.bind(this, function()
{
2013-11-11 12:31:46 +00:00
editorUi.hideDialog(true);
2012-05-21 20:32:26 +00:00
}));
document.body.appendChild(img);
this.dialogImg = img;
}
this.onDialogClose = onClose;
this.container = div;
2014-08-29 08:54:05 +00:00
editorUi.editor.fireEvent(new mxEventObject('showDialog'));
2012-05-21 20:32:26 +00:00
};
2014-10-03 12:49:36 +00:00
/**
*
*/
Dialog.prototype.zIndex = mxPopupMenu.prototype.zIndex - 1;
2013-07-19 09:51:30 +00:00
/**
* Removes the dialog from the DOM.
*/
Dialog.prototype.bgOpacity = 80;
2012-05-21 20:32:26 +00:00
/**
* Removes the dialog from the DOM.
*/
2013-11-11 12:31:46 +00:00
Dialog.prototype.close = function(cancel)
2012-05-21 20:32:26 +00:00
{
if (this.onDialogClose != null)
{
2013-11-11 12:31:46 +00:00
this.onDialogClose(cancel);
2012-05-21 20:32:26 +00:00
this.onDialogClose = null;
}
if (this.dialogImg != null)
{
this.dialogImg.parentNode.removeChild(this.dialogImg);
this.dialogImg = null;
}
this.container.parentNode.removeChild(this.container);
this.bg.parentNode.removeChild(this.bg);
};
/**
* Constructs a new open dialog.
*/
2014-04-13 06:49:20 +00:00
var OpenDialog = function()
2012-05-21 20:32:26 +00:00
{
var iframe = document.createElement('iframe');
iframe.style.backgroundColor = 'transparent';
iframe.allowTransparency = 'true';
iframe.style.borderStyle = 'none';
iframe.style.borderWidth = '0px';
iframe.style.overflow = 'hidden';
iframe.frameBorder = '0';
2013-12-20 16:51:26 +00:00
// Adds padding as a workaround for box model in older IE versions
var dx = (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8)) ? 20 : 0;
2014-06-02 08:21:19 +00:00
iframe.setAttribute('width', (360 + dx) + 'px');
iframe.setAttribute('height', (230 + dx) + 'px');
2012-05-21 20:32:26 +00:00
iframe.setAttribute('src', OPEN_FORM);
this.container = iframe;
};
/**
* Constructs a new color dialog.
*/
2014-04-13 06:49:20 +00:00
var ColorDialog = function(editorUi, color, apply, cancelFn)
2012-05-21 20:32:26 +00:00
{
this.editorUi = editorUi;
var input = document.createElement('input');
input.style.marginBottom = '10px';
input.style.width = '216px';
// Required for picker to render in IE
if (mxClient.IS_IE)
{
input.style.marginTop = '10px';
document.body.appendChild(input);
}
2014-01-08 16:23:20 +00:00
this.init = function()
{
if (!mxClient.IS_TOUCH)
{
input.focus();
}
};
2012-05-21 20:32:26 +00:00
var picker = new jscolor.color(input);
picker.pickerOnfocus = false;
picker.showPicker();
var div = document.createElement('div');
jscolor.picker.box.style.position = 'relative';
jscolor.picker.box.style.width = '230px';
jscolor.picker.box.style.height = '100px';
jscolor.picker.box.style.paddingBottom = '10px';
div.appendChild(jscolor.picker.box);
2012-12-18 13:09:38 +00:00
var center = document.createElement('center');
2012-05-21 20:32:26 +00:00
2012-12-18 13:09:38 +00:00
function addPresets(presets, rowLength)
2012-05-21 20:32:26 +00:00
{
2012-12-18 13:09:38 +00:00
rowLength = (rowLength != null) ? rowLength : 12;
2012-05-21 20:32:26 +00:00
var table = document.createElement('table');
table.style.borderCollapse = 'collapse';
table.setAttribute('cellspacing', '0');
table.style.marginBottom = '20px';
table.style.cellSpacing = '0px';
var tbody = document.createElement('tbody');
table.appendChild(tbody);
2012-12-18 13:09:38 +00:00
var rows = presets.length / rowLength;
2012-05-21 20:32:26 +00:00
for (var row = 0; row < rows; row++)
{
var tr = document.createElement('tr');
2012-12-18 13:09:38 +00:00
for (var i = 0; i < rowLength; i++)
2012-05-21 20:32:26 +00:00
{
(function(clr)
{
var td = document.createElement('td');
td.style.border = '1px solid black';
td.style.padding = '0px';
td.style.width = '16px';
td.style.height = '16px';
if (clr == 'none')
{
td.style.background = 'url(\'' + IMAGE_PATH + '/nocolor.png' + '\')';
}
else
{
td.style.backgroundColor = '#' + clr;
}
tr.appendChild(td);
mxEvent.addListener(td, 'click', function()
{
if (clr == 'none')
{
picker.fromString('ffffff');
input.value = 'none';
}
else
{
picker.fromString(clr);
}
});
2012-12-18 13:09:38 +00:00
})(presets[row * rowLength + i]);
2012-05-21 20:32:26 +00:00
}
tbody.appendChild(tr);
}
center.appendChild(table);
2012-12-18 13:09:38 +00:00
return table;
2012-05-21 20:32:26 +00:00
};
div.appendChild(input);
mxUtils.br(div);
// Adds presets
2012-12-18 13:09:38 +00:00
var table = addPresets(['E6D0DE', 'CDA2BE', 'B5739D', 'E1D5E7', 'C3ABD0', 'A680B8', 'D4E1F5', 'A9C4EB', '7EA6E0', 'D5E8D4', '9AC7BF', '67AB9F', 'D5E8D4', 'B9E0A5', '97D077', 'FFF2CC', 'FFE599', 'FFD966', 'FFF4C3', 'FFCE9F', 'FFB570', 'F8CECC', 'F19C99', 'EA6B66'], 12);
table.style.marginBottom = '8px';
table = addPresets(['none', 'FFFFFF', 'E6E6E6', 'CCCCCC', 'B3B3B3', '999999', '808080', '666666', '4D4D4D', '333333', '1A1A1A', '000000', 'FFCCCC', 'FFE6CC', 'FFFFCC', 'E6FFCC', 'CCFFCC', 'CCFFE6', 'CCFFFF', 'CCE5FF', 'CCCCFF', 'E5CCFF', 'FFCCFF', 'FFCCE6', 'FF9999', 'FFCC99', 'FFFF99', 'CCFF99', '99FF99', '99FFCC', '99FFFF', '99CCFF', '9999FF', 'CC99FF', 'FF99FF', 'FF99CC', 'FF6666', 'FFB366', 'FFFF66', 'B3FF66', '66FF66', '66FFB3', '66FFFF', '66B2FF', '6666FF', 'B266FF', 'FF66FF', 'FF66B3', 'FF3333', 'FF9933', 'FFFF33', '99FF33', '33FF33', '33FF99', '33FFFF', '3399FF', '3333FF', '9933FF', 'FF33FF', 'FF3399', 'FF0000', 'FF8000', 'FFFF00', '80FF00', '00FF00', '00FF80', '00FFFF', '007FFF', '0000FF', '7F00FF', 'FF00FF', 'FF0080', 'CC0000', 'CC6600', 'CCCC00', '66CC00', '00CC00', '00CC66', '00CCCC', '0066CC', '0000CC', '6600CC', 'CC00CC', 'CC0066', '990000', '994C00', '999900', '4D9900', '009900', '00994D', '009999', '004C99', '000099', '4C0099', '990099', '99004D', '660000', '663300', '666600', '336600', '006600', '006633', '006666', '003366', '000066', '330066', '660066', '660033', '330000', '331A00', '333300', '1A3300', '003300', '00331A', '003333', '001933', '000033', '190033', '330033', '33001A']);
table.style.marginBottom = '16px';
div.appendChild(center);
2012-05-21 20:32:26 +00:00
var buttons = document.createElement('div');
2012-12-18 13:09:38 +00:00
buttons.style.textAlign = 'right';
2012-05-21 20:32:26 +00:00
buttons.style.whiteSpace = 'nowrap';
2014-04-01 11:30:48 +00:00
buttons.appendChild(mxUtils.button(mxResources.get('cancel'), function()
{
editorUi.hideDialog();
if (cancelFn != null)
{
cancelFn();
}
}));
2012-05-21 20:32:26 +00:00
var applyFunction = (apply != null) ? apply : this.createApplyFunction();
buttons.appendChild(mxUtils.button(mxResources.get('apply'), function()
{
var color = input.value;
if (color != 'none')
{
color = '#' + color;
}
applyFunction(color);
editorUi.hideDialog();
}));
if (color != null)
{
if (color == 'none')
{
picker.fromString('ffffff');
input.value = 'none';
}
else
{
picker.fromString(color);
}
}
div.appendChild(buttons);
this.picker = picker;
this.colorInput = input;
this.container = div;
};
/* Creates function to apply value */
ColorDialog.prototype.createApplyFunction = function()
{
return mxUtils.bind(this, function(color)
{
2012-05-30 16:26:17 +00:00
this.editorUi.editor.graph.setCellStyles(this.currentColorKey, (color == 'none') ? 'none' : color);
2012-05-21 20:32:26 +00:00
});
};
/**
* Constructs a new about dialog.
*/
2014-04-13 06:49:20 +00:00
var AboutDialog = function(editorUi)
2012-05-21 20:32:26 +00:00
{
var div = document.createElement('div');
div.setAttribute('align', 'center');
var h3 = document.createElement('h3');
mxUtils.write(h3, mxResources.get('about') + ' GraphEditor');
div.appendChild(h3);
var img = document.createElement('img');
img.style.border = '0px';
img.setAttribute('width', '176');
img.setAttribute('width', '151');
img.setAttribute('src', IMAGE_PATH + '/logo.png');
div.appendChild(img);
mxUtils.br(div);
mxUtils.write(div, 'Powered by mxGraph ' + mxClient.VERSION);
mxUtils.br(div);
var link = document.createElement('a');
link.setAttribute('href', 'http://www.jgraph.com/');
link.setAttribute('target', '_blank');
mxUtils.write(link, 'www.jgraph.com');
div.appendChild(link);
mxUtils.br(div);
mxUtils.br(div);
div.appendChild(mxUtils.button(mxResources.get('close'), function()
{
editorUi.hideDialog();
}));
this.container = div;
};
/**
2012-06-01 10:53:50 +00:00
* Constructs a new page setup dialog.
2012-05-21 20:32:26 +00:00
*/
2014-04-13 06:49:20 +00:00
var PageSetupDialog = function(editorUi)
2012-05-21 20:32:26 +00:00
{
2013-12-09 08:35:20 +00:00
// Defines possible page sizes. Needs to be lazy initialized to add any translations.
if (PageSetupDialog.formats == null)
{
PageSetupDialog.formats = [{key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1652)},
{key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT},
{key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 584, 826)},
{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT},
{key: 'tabloid', title: 'US-Tabloid (279 mm x 432 mm)', format: new mxRectangle(0, 0, 1100, 1700)},
{key: 'custom', title: mxResources.get('custom'), format: null}];
}
2012-05-21 20:32:26 +00:00
var graph = editorUi.editor.graph;
var row, td;
2012-06-01 10:53:50 +00:00
2012-05-21 20:32:26 +00:00
var table = document.createElement('table');
table.style.width = '100%';
table.style.height = '100%';
var tbody = document.createElement('tbody');
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
mxUtils.write(td, mxResources.get('paperSize') + ':');
row.appendChild(td);
2013-12-09 08:35:20 +00:00
var portraitCheckBox = document.createElement('input');
portraitCheckBox.setAttribute('name', 'format');
portraitCheckBox.setAttribute('type', 'radio');
2012-05-21 20:32:26 +00:00
2013-12-09 08:35:20 +00:00
var landscapeCheckBox = document.createElement('input');
landscapeCheckBox.setAttribute('name', 'format');
landscapeCheckBox.setAttribute('type', 'radio');
2012-05-21 20:32:26 +00:00
2013-12-09 08:35:20 +00:00
var formatRow = document.createElement('tr');
formatRow.style.display = 'none';
2012-05-21 20:32:26 +00:00
2013-12-09 08:35:20 +00:00
var customRow = document.createElement('tr');
customRow.style.display = 'none';
2012-06-01 10:53:50 +00:00
2013-12-09 08:35:20 +00:00
// Adds all papersize options
var paperSizeSelect = document.createElement('select');
var detected = false;
var pf = new Object();
for (var i = 0; i < PageSetupDialog.formats.length; i++)
2012-06-01 10:53:50 +00:00
{
2013-12-09 08:35:20 +00:00
var f = PageSetupDialog.formats[i];
pf[f.key] = f;
var paperSizeOption = document.createElement('option');
paperSizeOption.setAttribute('value', f.key);
mxUtils.write(paperSizeOption, f.title);
paperSizeSelect.appendChild(paperSizeOption);
if (f.format != null)
{
if (graph.pageFormat.width == f.format.width && graph.pageFormat.height == f.format.height)
{
paperSizeOption.setAttribute('selected', 'selected');
portraitCheckBox.setAttribute('checked', 'checked');
2014-05-05 08:30:00 +00:00
portraitCheckBox.defaultChecked = true;
2013-12-09 08:35:20 +00:00
formatRow.style.display = '';
detected = true;
}
else if (graph.pageFormat.width == f.format.height && graph.pageFormat.height == f.format.width)
{
paperSizeOption.setAttribute('selected', 'selected');
landscapeCheckBox.setAttribute('checked', 'checked');
2014-05-05 08:30:00 +00:00
landscapeCheckBox.defaultChecked = true;
2013-12-09 08:35:20 +00:00
formatRow.style.display = '';
detected = true;
}
}
// Selects custom format which is last in list
else if (!detected)
{
paperSizeOption.setAttribute('selected', 'selected');
customRow.style.display = '';
}
2012-06-01 10:53:50 +00:00
}
td = document.createElement('td');
td.style.fontSize = '10pt';
td.appendChild(paperSizeSelect);
row.appendChild(td);
tbody.appendChild(row);
2013-12-09 08:35:20 +00:00
formatRow = document.createElement('tr');
formatRow.style.height = '60px';
2012-06-01 10:53:50 +00:00
td = document.createElement('td');
2013-12-09 08:35:20 +00:00
formatRow.appendChild(td);
2012-05-21 20:32:26 +00:00
2012-06-01 10:53:50 +00:00
td = document.createElement('td');
td.style.fontSize = '10pt';
2013-12-09 08:35:20 +00:00
td.appendChild(portraitCheckBox);
mxUtils.write(td, ' ' + mxResources.get('portrait'));
landscapeCheckBox.style.marginLeft = '10px';
2012-06-01 10:53:50 +00:00
td.appendChild(landscapeCheckBox);
mxUtils.write(td, ' ' + mxResources.get('landscape'));
2013-12-09 08:35:20 +00:00
formatRow.appendChild(td);
2012-06-01 10:53:50 +00:00
2013-12-09 08:35:20 +00:00
tbody.appendChild(formatRow);
2012-06-01 10:53:50 +00:00
row = document.createElement('tr');
2013-12-09 08:35:20 +00:00
td = document.createElement('td');
customRow.appendChild(td);
2012-06-01 10:53:50 +00:00
td = document.createElement('td');
td.style.fontSize = '10pt';
2013-12-09 08:35:20 +00:00
var widthInput = document.createElement('input');
widthInput.setAttribute('size', '6');
widthInput.setAttribute('value', graph.pageFormat.width);
td.appendChild(widthInput);
mxUtils.write(td, ' x ');
2012-06-01 10:53:50 +00:00
2013-12-09 08:35:20 +00:00
var heightInput = document.createElement('input');
heightInput.setAttribute('size', '6');
heightInput.setAttribute('value', graph.pageFormat.height);
td.appendChild(heightInput);
mxUtils.write(td, ' Pixel');
2012-06-01 10:53:50 +00:00
2013-12-09 08:35:20 +00:00
customRow.appendChild(td);
customRow.style.height = '60px';
tbody.appendChild(customRow);
var updateInputs = function()
{
var f = pf[paperSizeSelect.value];
if (f.format != null)
{
widthInput.value = f.format.width;
heightInput.value = f.format.height;
customRow.style.display = 'none';
formatRow.style.display = '';
}
else
{
formatRow.style.display = 'none';
customRow.style.display = '';
}
};
mxEvent.addListener(paperSizeSelect, 'change', updateInputs);
updateInputs();
2012-06-01 10:53:50 +00:00
row = document.createElement('tr');
td = document.createElement('td');
td.colSpan = 2;
td.setAttribute('align', 'right');
2014-04-01 11:30:48 +00:00
td.appendChild(mxUtils.button(mxResources.get('cancel'), function()
{
editorUi.hideDialog();
}));
2013-12-09 08:35:20 +00:00
td.appendChild(mxUtils.button(mxResources.get('apply'), function()
2012-06-01 10:53:50 +00:00
{
editorUi.hideDialog();
var ls = landscapeCheckBox.checked;
2013-12-09 08:35:20 +00:00
var f = pf[paperSizeSelect.value];
var size = f.format;
if (size == null)
{
size = new mxRectangle(0, 0, parseInt(widthInput.value), parseInt(heightInput.value));
}
if (ls)
{
size = new mxRectangle(0, 0, size.height, size.width);
}
2013-12-20 16:51:26 +00:00
editorUi.setPageFormat(size);
2012-06-01 10:53:50 +00:00
}));
row.appendChild(td);
tbody.appendChild(row);
tbody.appendChild(row);
table.appendChild(tbody);
this.container = table;
};
/**
* Constructs a new print dialog.
*/
2014-04-13 06:49:20 +00:00
var PrintDialog = function(editorUi)
2012-06-01 10:53:50 +00:00
{
var graph = editorUi.editor.graph;
var row, td;
var table = document.createElement('table');
table.style.width = '100%';
table.style.height = '100%';
var tbody = document.createElement('tbody');
2012-05-21 20:32:26 +00:00
row = document.createElement('tr');
var pageCountCheckBox = document.createElement('input');
pageCountCheckBox.setAttribute('type', 'checkbox');
td = document.createElement('td');
td.style.paddingRight = '10px';
td.style.fontSize = '10pt';
td.appendChild(pageCountCheckBox);
mxUtils.write(td, ' ' + mxResources.get('posterPrint') + ':');
row.appendChild(td);
var pageCountInput = document.createElement('input');
pageCountInput.setAttribute('value', '1');
pageCountInput.setAttribute('type', 'number');
pageCountInput.setAttribute('min', '1');
pageCountInput.setAttribute('size', '4');
pageCountInput.setAttribute('disabled', 'disabled');
pageCountInput.style.width = '50px';
td = document.createElement('td');
td.style.fontSize = '10pt';
td.appendChild(pageCountInput);
2013-12-09 08:35:20 +00:00
mxUtils.write(td, ' ' + mxResources.get('pages') + ' (max)');
2012-05-21 20:32:26 +00:00
row.appendChild(td);
tbody.appendChild(row);
mxEvent.addListener(pageCountCheckBox, 'change', function()
{
if (pageCountCheckBox.checked)
{
pageCountInput.removeAttribute('disabled');
}
else
{
pageCountInput.setAttribute('disabled', 'disabled');
}
});
row = document.createElement('tr');
td = document.createElement('td');
td.colSpan = 2;
td.style.paddingTop = '40px';
td.setAttribute('align', 'right');
2014-01-31 14:27:56 +00:00
function preview(print)
2012-05-21 20:32:26 +00:00
{
2013-12-09 08:35:20 +00:00
var pf = graph.pageFormat || mxConstants.PAGE_FORMAT_A4_PORTRAIT;
2012-05-21 20:32:26 +00:00
var scale = 1 / graph.pageScale;
if (pageCountCheckBox.checked)
{
var pageCount = parseInt(pageCountInput.value);
if (!isNaN(pageCount))
{
scale = mxUtils.getScaleForPageCount(pageCount, graph, pf);
}
}
// Negative coordinates are cropped or shifted if page visible
var gb = graph.getGraphBounds();
var autoOrigin = pageCountCheckBox.checked;
var border = 0;
var x0 = 0;
var y0 = 0;
// Computes unscaled, untranslated graph bounds
var x = (gb.width > 0) ? gb.x / graph.view.scale - graph.view.translate.x : 0;
var y = (gb.height > 0) ? gb.y / graph.view.scale - graph.view.translate.y : 0;
if (x < 0 || y < 0)
{
autoOrigin = true;
if (graph.pageVisible)
{
var ps = graph.pageScale;
var pw = pf.width * ps;
var ph = pf.height * ps;
x0 = (x > 0) ? x : pf.width * -Math.floor(Math.min(0, x) / pw) + Math.min(0, x) / graph.pageScale;
y0 = (y > 0) ? y : pf.height * -Math.floor(Math.min(0, y) / ph) + Math.min(0, y) / graph.pageScale;
}
else
{
x0 = 10;
y0 = 10;
}
}
2014-01-31 14:27:56 +00:00
return PrintDialog.showPreview(PrintDialog.createPrintPreview(graph, scale, pf, border, x0, y0, autoOrigin, print), print);
2012-05-21 20:32:26 +00:00
};
2014-04-01 11:30:48 +00:00
td.appendChild(mxUtils.button(mxResources.get('cancel'), function()
2012-05-21 20:32:26 +00:00
{
editorUi.hideDialog();
}));
td.appendChild(mxUtils.button(mxResources.get('preview'), function()
{
editorUi.hideDialog();
2014-01-31 14:27:56 +00:00
preview(false);
2012-05-21 20:32:26 +00:00
}));
2014-04-01 11:30:48 +00:00
td.appendChild(mxUtils.button(mxResources.get('print'), function()
2012-05-21 20:32:26 +00:00
{
editorUi.hideDialog();
2014-04-01 11:30:48 +00:00
preview(true);
2012-05-21 20:32:26 +00:00
}));
2014-04-01 11:30:48 +00:00
2012-05-21 20:32:26 +00:00
row.appendChild(td);
tbody.appendChild(row);
tbody.appendChild(row);
table.appendChild(tbody);
this.container = table;
};
2014-01-31 14:27:56 +00:00
/**
* Constructs a new print dialog.
*/
PrintDialog.showPreview = function(preview, print)
{
var result = preview.open();
if (print)
{
result.print();
}
return result;
};
2014-01-13 16:13:21 +00:00
/**
* Constructs a new print dialog.
*/
PrintDialog.createPrintPreview = function(graph, scale, pf, border, x0, y0, autoOrigin)
{
var preview = new mxPrintPreview(graph, scale, pf, border, x0, y0);
preview.title = mxResources.get('preview');
2014-02-10 12:26:10 +00:00
preview.printBackgroundImage = true;
2014-01-13 16:13:21 +00:00
preview.autoOrigin = autoOrigin;
return preview;
};
2014-01-31 14:27:56 +00:00
/**
* Constructs a new filename dialog.
*/
2014-06-11 13:13:38 +00:00
var FilenameDialog = function(editorUi, filename, buttonText, fn, label, validateFn)
2012-05-21 20:32:26 +00:00
{
var row, td;
var table = document.createElement('table');
var tbody = document.createElement('tbody');
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
2014-01-08 16:23:20 +00:00
td.style.width = '120px';
mxUtils.write(td, (label || mxResources.get('filename')) + ':');
2012-05-21 20:32:26 +00:00
row.appendChild(td);
var nameInput = document.createElement('input');
2013-11-11 12:31:46 +00:00
nameInput.setAttribute('value', filename || '');
2012-05-21 20:32:26 +00:00
nameInput.style.width = '180px';
2013-12-20 16:51:26 +00:00
this.init = function()
{
nameInput.focus();
2014-04-13 06:49:20 +00:00
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
nameInput.select();
}
else
{
document.execCommand('selectAll');
}
2013-12-20 16:51:26 +00:00
};
2012-05-21 20:32:26 +00:00
td = document.createElement('td');
td.appendChild(nameInput);
row.appendChild(td);
tbody.appendChild(row);
row = document.createElement('tr');
td = document.createElement('td');
td.colSpan = 2;
2013-11-11 12:31:46 +00:00
td.style.paddingTop = '20px';
2012-05-21 20:32:26 +00:00
td.style.whiteSpace = 'nowrap';
td.setAttribute('align', 'right');
2014-04-01 11:30:48 +00:00
td.appendChild(mxUtils.button(mxResources.get('cancel'), function()
{
editorUi.hideDialog();
}));
2013-11-11 12:31:46 +00:00
var genericBtn = mxUtils.button(buttonText, function()
2012-05-21 20:32:26 +00:00
{
2014-06-11 13:13:38 +00:00
if (validateFn == null || validateFn(nameInput.value))
{
editorUi.hideDialog();
fn(nameInput.value);
}
2012-05-21 20:32:26 +00:00
});
2014-04-01 11:30:48 +00:00
mxEvent.addListener(nameInput, 'keyup', function(e)
2012-05-21 20:32:26 +00:00
{
2014-04-01 11:30:48 +00:00
if (e.keyCode == 13)
{
2014-06-11 13:13:38 +00:00
genericBtn.click();
2014-04-01 11:30:48 +00:00
}
else if (e.keyCode == 27)
{
editorUi.hideDialog();
}
});
2012-05-21 20:32:26 +00:00
2014-04-01 11:30:48 +00:00
td.appendChild(genericBtn);
2012-05-21 20:32:26 +00:00
row.appendChild(td);
tbody.appendChild(row);
tbody.appendChild(row);
table.appendChild(tbody);
this.container = table;
};
2014-01-31 14:27:56 +00:00
/**
* Constructs a new textarea dialog.
*/
2014-04-13 06:49:20 +00:00
var TextareaDialog = function(editorUi, title, url, fn, cancelFn, cancelTitle)
2013-12-20 16:51:26 +00:00
{
var row, td;
var table = document.createElement('table');
var tbody = document.createElement('tbody');
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
td.style.width = '100px';
mxUtils.write(td, title);
row.appendChild(td);
tbody.appendChild(row);
row = document.createElement('tr');
td = document.createElement('td');
var nameInput = document.createElement('textarea');
mxUtils.write(nameInput, url || '');
nameInput.style.width = '300px';
nameInput.style.height = '100px';
2014-03-14 13:24:50 +00:00
this.textarea = nameInput;
2014-04-01 11:30:48 +00:00
2013-12-20 16:51:26 +00:00
this.init = function()
{
nameInput.focus();
};
td = document.createElement('td');
td.appendChild(nameInput);
row.appendChild(td);
tbody.appendChild(row);
row = document.createElement('tr');
td = document.createElement('td');
td.style.paddingTop = '20px';
td.style.whiteSpace = 'nowrap';
td.setAttribute('align', 'right');
2014-03-14 13:24:50 +00:00
td.appendChild(mxUtils.button(cancelTitle || mxResources.get('cancel'), function()
2013-12-20 16:51:26 +00:00
{
editorUi.hideDialog();
2014-01-08 16:23:20 +00:00
if (cancelFn != null)
{
cancelFn();
}
2013-12-20 16:51:26 +00:00
}));
2014-04-01 11:30:48 +00:00
if (fn != null)
{
var genericBtn = mxUtils.button(mxResources.get('apply'), function()
{
editorUi.hideDialog();
fn(nameInput.value);
});
td.appendChild(genericBtn);
}
2013-12-20 16:51:26 +00:00
row.appendChild(td);
tbody.appendChild(row);
table.appendChild(tbody);
this.container = table;
};
2012-05-21 20:32:26 +00:00
/**
* Constructs a new edit file dialog.
*/
2014-04-13 06:49:20 +00:00
var EditFileDialog = function(editorUi)
2012-05-21 20:32:26 +00:00
{
var div = document.createElement('div');
div.style.textAlign = 'right';
var textarea = document.createElement('textarea');
textarea.style.width = '600px';
textarea.style.height = '374px';
textarea.value = mxUtils.getPrettyXml(editorUi.editor.getGraphXml());
div.appendChild(textarea);
// Enables dropping files
if (fileSupport)
{
function handleDrop(evt)
{
evt.stopPropagation();
evt.preventDefault();
2012-06-01 10:53:50 +00:00
if (evt.dataTransfer.files.length > 0)
{
var file = evt.dataTransfer.files[0];
2012-05-21 20:32:26 +00:00
var reader = new FileReader();
2013-11-18 15:18:56 +00:00
reader.onload = function(e)
{
2013-12-09 08:35:20 +00:00
textarea.value = e.target.result;
2013-11-18 15:18:56 +00:00
};
2012-05-21 20:32:26 +00:00
reader.readAsText(file);
}
};
function handleDragOver(evt)
{
evt.stopPropagation();
evt.preventDefault();
};
// Setup the dnd listeners.
textarea.addEventListener('dragover', handleDragOver, false);
textarea.addEventListener('drop', handleDrop, false);
}
2012-05-30 16:26:17 +00:00
2014-04-01 11:30:48 +00:00
div.appendChild(mxUtils.button(mxResources.get('cancel'), function()
{
editorUi.hideDialog();
}));
2012-05-30 16:26:17 +00:00
var select = document.createElement('select');
select.style.width = '180px';
2012-05-21 20:32:26 +00:00
2014-07-25 06:48:01 +00:00
var replaceOption = document.createElement('option');
replaceOption.setAttribute('value', 'replace');
mxUtils.write(replaceOption, mxResources.get('replaceExistingDrawing'));
select.appendChild(replaceOption);
2012-05-30 16:26:17 +00:00
var newOption = document.createElement('option');
newOption.setAttribute('value', 'new');
mxUtils.write(newOption, mxResources.get('openInNewWindow'));
select.appendChild(newOption);
2012-05-21 20:32:26 +00:00
2012-05-30 16:26:17 +00:00
var importOption = document.createElement('option');
importOption.setAttribute('value', 'import');
mxUtils.write(importOption, mxResources.get('addToExistingDrawing'));
select.appendChild(importOption);
div.appendChild(select);
div.appendChild(mxUtils.button(mxResources.get('ok'), function()
2012-05-21 20:32:26 +00:00
{
2014-01-31 14:27:56 +00:00
// Removes all illegal control characters before parsing
2014-07-31 12:29:23 +00:00
var data = editorUi.editor.graph.zapGremlins(mxUtils.trim(textarea.value));
2014-01-31 14:27:56 +00:00
2012-05-30 16:26:17 +00:00
if (select.value == 'new')
{
window.openFile = new OpenFile(function()
{
editorUi.hideDialog();
window.openFile = null;
});
2014-01-31 14:27:56 +00:00
window.openFile.setData(data, null);
2012-05-30 16:26:17 +00:00
window.open(editorUi.getUrl());
}
else if (select.value == 'replace')
2012-05-21 20:32:26 +00:00
{
2013-12-20 16:51:26 +00:00
try
{
2014-01-31 14:27:56 +00:00
var doc = mxUtils.parseXml(data);
2013-12-20 16:51:26 +00:00
editorUi.editor.setGraphXml(doc.documentElement);
editorUi.hideDialog();
}
catch (e)
{
mxUtils.alert(e.message);
}
2012-05-30 16:26:17 +00:00
}
else if (select.value == 'import')
{
2014-01-31 14:27:56 +00:00
var doc = mxUtils.parseXml(data);
2012-05-30 16:26:17 +00:00
var model = new mxGraphModel();
var codec = new mxCodec(doc);
codec.decode(doc.documentElement, model);
var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(children));
editorUi.hideDialog();
}
2012-05-21 20:32:26 +00:00
}));
2014-04-01 11:30:48 +00:00
2012-05-21 20:32:26 +00:00
this.container = div;
};
/**
* Constructs a new export dialog.
*/
2014-04-13 06:49:20 +00:00
var ExportDialog = function(editorUi)
2012-05-21 20:32:26 +00:00
{
var graph = editorUi.editor.graph;
var bounds = graph.getGraphBounds();
var scale = graph.view.scale;
var width = Math.ceil(bounds.width / scale);
var height = Math.ceil(bounds.height / scale);
var row, td;
var table = document.createElement('table');
var tbody = document.createElement('tbody');
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
td.style.width = '100px';
mxUtils.write(td, mxResources.get('filename') + ':');
row.appendChild(td);
var nameInput = document.createElement('input');
nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
nameInput.style.width = '180px';
td = document.createElement('td');
td.appendChild(nameInput);
row.appendChild(td);
tbody.appendChild(row);
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
mxUtils.write(td, mxResources.get('format') + ':');
row.appendChild(td);
var imageFormatSelect = document.createElement('select');
imageFormatSelect.style.width = '180px';
var pngOption = document.createElement('option');
pngOption.setAttribute('value', 'png');
mxUtils.write(pngOption, 'PNG - Portable Network Graphics');
imageFormatSelect.appendChild(pngOption);
var gifOption = document.createElement('option');
gifOption.setAttribute('value', 'gif');
mxUtils.write(gifOption, 'GIF - Graphics Interchange Format');
imageFormatSelect.appendChild(gifOption);
var jpgOption = document.createElement('option');
jpgOption.setAttribute('value', 'jpg');
mxUtils.write(jpgOption, 'JPG - JPEG File Interchange Format');
imageFormatSelect.appendChild(jpgOption);
var pdfOption = document.createElement('option');
pdfOption.setAttribute('value', 'pdf');
mxUtils.write(pdfOption, 'PDF - Portable Document Format');
imageFormatSelect.appendChild(pdfOption);
var svgOption = document.createElement('option');
svgOption.setAttribute('value', 'svg');
mxUtils.write(svgOption, 'SVG - Scalable Vector Graphics');
imageFormatSelect.appendChild(svgOption);
2014-04-01 11:30:48 +00:00
if (ExportDialog.showXmlOption)
{
var xmlOption = document.createElement('option');
xmlOption.setAttribute('value', 'xml');
2014-05-12 09:58:11 +00:00
mxUtils.write(xmlOption, 'XML - Extensible Markup Language');
2014-04-01 11:30:48 +00:00
imageFormatSelect.appendChild(xmlOption);
}
2012-05-21 20:32:26 +00:00
td = document.createElement('td');
td.appendChild(imageFormatSelect);
row.appendChild(td);
tbody.appendChild(row);
2013-08-21 09:32:40 +00:00
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
mxUtils.write(td, mxResources.get('backgroundColor') + ':');
row.appendChild(td);
var backgroundInput = document.createElement('input');
backgroundInput.setAttribute('value', (graph.background || '#FFFFFF'));
backgroundInput.style.width = '80px';
var backgroundCheckbox = document.createElement('input');
backgroundCheckbox.setAttribute('type', 'checkbox');
2014-04-01 11:30:48 +00:00
backgroundCheckbox.checked = graph.background == null || graph.background == mxConstants.NONE;
2013-08-21 09:32:40 +00:00
td = document.createElement('td');
td.appendChild(backgroundInput);
td.appendChild(backgroundCheckbox);
mxUtils.write(td, mxResources.get('transparent'));
row.appendChild(td);
tbody.appendChild(row);
2012-05-21 20:32:26 +00:00
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
mxUtils.write(td, mxResources.get('width') + ':');
row.appendChild(td);
var widthInput = document.createElement('input');
widthInput.setAttribute('value', width);
widthInput.style.width = '180px';
td = document.createElement('td');
td.appendChild(widthInput);
row.appendChild(td);
tbody.appendChild(row);
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
mxUtils.write(td, mxResources.get('height') + ':');
row.appendChild(td);
var heightInput = document.createElement('input');
heightInput.setAttribute('value', height);
heightInput.style.width = '180px';
td = document.createElement('td');
td.appendChild(heightInput);
row.appendChild(td);
tbody.appendChild(row);
2013-08-21 09:32:40 +00:00
2012-05-21 20:32:26 +00:00
row = document.createElement('tr');
td = document.createElement('td');
td.style.fontSize = '10pt';
2012-05-30 16:26:17 +00:00
mxUtils.write(td, mxResources.get('borderWidth') + ':');
2012-05-21 20:32:26 +00:00
row.appendChild(td);
var borderInput = document.createElement('input');
borderInput.setAttribute('value', width);
borderInput.style.width = '180px';
borderInput.value = '0';
td = document.createElement('td');
td.appendChild(borderInput);
row.appendChild(td);
tbody.appendChild(row);
table.appendChild(tbody);
// Handles changes in the export format
function formatChanged()
{
var name = nameInput.value;
var dot = name.lastIndexOf('.');
if (dot > 0)
{
nameInput.value = name.substring(0, dot + 1) + imageFormatSelect.value;
}
else
{
nameInput.value = name + '.' + imageFormatSelect.value;
}
if (imageFormatSelect.value === 'xml')
{
widthInput.setAttribute('disabled', 'true');
heightInput.setAttribute('disabled', 'true');
borderInput.setAttribute('disabled', 'true');
}
else
{
widthInput.removeAttribute('disabled');
heightInput.removeAttribute('disabled');
borderInput.removeAttribute('disabled');
}
2013-08-21 09:32:40 +00:00
if (imageFormatSelect.value === 'png' || imageFormatSelect.value === 'svg')
{
backgroundCheckbox.removeAttribute('disabled');
}
else
{
backgroundCheckbox.setAttribute('disabled', 'disabled');
}
2012-05-21 20:32:26 +00:00
};
mxEvent.addListener(imageFormatSelect, 'change', formatChanged);
formatChanged();
function checkValues()
{
2013-08-21 09:32:40 +00:00
if (widthInput.value * heightInput.value > MAX_AREA || widthInput.value <= 0)
2012-05-21 20:32:26 +00:00
{
widthInput.style.backgroundColor = 'red';
}
else
{
widthInput.style.backgroundColor = '';
}
2013-08-21 09:32:40 +00:00
if (widthInput.value * heightInput.value > MAX_AREA || heightInput.value <= 0)
2012-05-21 20:32:26 +00:00
{
heightInput.style.backgroundColor = 'red';
}
else
{
heightInput.style.backgroundColor = '';
}
};
mxEvent.addListener(widthInput, 'change', function()
{
if (width > 0)
{
heightInput.value = Math.ceil(parseInt(widthInput.value) * height / width);
}
else
{
heightInput.value = '0';
}
checkValues();
});
mxEvent.addListener(heightInput, 'change', function()
{
if (height > 0)
{
widthInput.value = Math.ceil(parseInt(heightInput.value) * width / height);
}
else
{
widthInput.value = '0';
}
checkValues();
});
2013-08-21 09:32:40 +00:00
// Resuable image export instance
2012-05-21 20:32:26 +00:00
var imgExport = new mxImageExport();
2013-08-21 09:32:40 +00:00
function getSvg()
{
var b = Math.max(0, parseInt(borderInput.value)) + 1;
var scale = parseInt(widthInput.value) / width;
2014-01-08 16:23:20 +00:00
var bg = null;
2013-08-21 09:32:40 +00:00
if (backgroundInput.value != '' && backgroundInput.value != mxConstants.NONE && !backgroundCheckbox.checked)
{
2014-01-08 16:23:20 +00:00
bg = backgroundInput.value;
2013-08-21 09:32:40 +00:00
}
2014-01-08 16:23:20 +00:00
2014-06-11 13:13:38 +00:00
return graph.getSvg(bg, scale, b);
2013-08-21 09:32:40 +00:00
};
function getXml()
{
return mxUtils.getXml(editorUi.editor.getGraphXml());
};
2012-05-21 20:32:26 +00:00
row = document.createElement('tr');
td = document.createElement('td');
td.setAttribute('align', 'right');
2014-04-01 11:30:48 +00:00
td.style.paddingTop = '16px';
td.colSpan = 2;
2013-08-21 09:32:40 +00:00
2014-04-01 11:30:48 +00:00
var saveBtn = mxUtils.button(mxResources.get('export'), mxUtils.bind(this, function()
2012-05-21 20:32:26 +00:00
{
if (parseInt(widthInput.value) <= 0 && parseInt(heightInput.value) <= 0)
{
mxUtils.alert(mxResources.get('drawingEmpty'));
}
else
{
var format = imageFormatSelect.value;
2013-08-21 09:32:40 +00:00
var name = encodeURIComponent(nameInput.value);
2012-05-21 20:32:26 +00:00
if (format == 'xml')
{
2013-08-21 09:32:40 +00:00
var xml = encodeURIComponent(getXml());
2013-12-09 08:35:20 +00:00
new mxXmlRequest(SAVE_URL, 'filename=' + name + '&xml=' + xml).simulate(document, '_blank');
2012-05-21 20:32:26 +00:00
}
else if (format == 'svg')
{
2014-04-01 11:30:48 +00:00
var xml = mxUtils.getXml(getSvg());
2013-08-21 09:32:40 +00:00
2012-05-21 20:32:26 +00:00
if (xml.length < MAX_REQUEST_SIZE)
{
xml = encodeURIComponent(xml);
new mxXmlRequest(SAVE_URL, 'filename=' + name + '&format=' + format +
2014-04-01 11:30:48 +00:00
'&xml=' + xml).simulate(document, '_blank');
2012-05-21 20:32:26 +00:00
}
else
{
mxUtils.alert(mxResources.get('drawingTooLarge'));
mxUtils.popup(xml);
}
}
else
{
2014-04-01 11:30:48 +00:00
var xml = null;
var w = 0;
var h = 0;
if (ExportDialog.imgExportFormat == 'svg')
{
var svgRoot = getSvg();
w = parseInt(svgRoot.getAttribute('width'));
h = parseInt(svgRoot.getAttribute('height'));
xml = mxUtils.getXml(svgRoot);
}
else
{
var b = Math.max(0, parseInt(borderInput.value)) + 1;
var scale = parseInt(widthInput.value) / width;
var bounds = graph.getGraphBounds();
var vs = graph.view.scale;
// New image export
var xmlDoc = mxUtils.createXmlDocument();
var root = xmlDoc.createElement('output');
xmlDoc.appendChild(root);
// Renders graph. Offset will be multiplied with state's scale when painting state.
var xmlCanvas = new mxXmlCanvas2D(root);
xmlCanvas.translate(Math.floor((b / scale - bounds.x) / vs), Math.floor((b / scale - bounds.y) / vs));
xmlCanvas.scale(scale / vs);
imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
// Puts request data together
w = Math.ceil(bounds.width * scale / vs + 2 * b);
h = Math.ceil(bounds.height * scale / vs + 2 * b);
xml = mxUtils.getXml(root);
}
2012-05-21 20:32:26 +00:00
// Requests image if request is valid
2013-11-11 12:31:46 +00:00
if (xml != null && xml.length <= MAX_REQUEST_SIZE && w > 0 && h > 0 && w * h < MAX_AREA)
2012-05-21 20:32:26 +00:00
{
2013-08-21 09:32:40 +00:00
var bg = '';
if (backgroundInput.value != '' && backgroundInput.value != mxConstants.NONE &&
(format != 'png' || !backgroundCheckbox.checked))
{
bg = '&bg=' + backgroundInput.value;
}
2012-05-21 20:32:26 +00:00
new mxXmlRequest(EXPORT_URL, 'filename=' + name + '&format=' + format +
2014-04-01 11:30:48 +00:00
bg + '&w=' + w + '&h=' + h + '&' + ExportDialog.imgExportFormat + '=' +
encodeURIComponent(xml)).simulate(document, '_blank');
2012-05-21 20:32:26 +00:00
}
else
{
mxUtils.alert(mxResources.get('drawingTooLarge'));
}
}
editorUi.hideDialog();
}
2013-08-21 09:32:40 +00:00
}));
2014-04-01 11:30:48 +00:00
2012-05-21 20:32:26 +00:00
td.appendChild(mxUtils.button(mxResources.get('cancel'), function()
{
editorUi.hideDialog();
}));
2014-04-01 11:30:48 +00:00
td.appendChild(saveBtn);
2012-05-21 20:32:26 +00:00
row.appendChild(td);
tbody.appendChild(row);
table.appendChild(tbody);
this.container = table;
};
2013-07-12 07:09:46 +00:00
2014-04-01 11:30:48 +00:00
/**
* Global switches for the export dialog.
*/
ExportDialog.imgExportFormat = 'xml';
ExportDialog.showXmlOption = true;
2013-07-12 07:09:46 +00:00
/**
* Constructs a new metadata dialog.
*/
2014-04-13 06:49:20 +00:00
var MetadataDialog = function(ui, cell)
2013-07-12 07:09:46 +00:00
{
var div = document.createElement('div');
div.style.height = '310px';
div.style.overflow = 'auto';
var value = ui.editor.graph.getModel().getValue(cell);
// Converts the value to an XML node
if (!mxUtils.isNode(value))
{
var doc = mxUtils.createXmlDocument();
var obj = doc.createElement('object');
obj.setAttribute('label', value || '');
value = obj;
}
// Creates the dialog contents
var form = new mxForm('properties');
2014-04-01 11:30:48 +00:00
form.table.style.width = '100%';
2014-06-02 08:21:19 +00:00
form.table.style.paddingRight = '20px';
2013-07-12 07:09:46 +00:00
var attrs = value.attributes;
var names = [];
var texts = [];
var count = 0;
2014-06-02 08:21:19 +00:00
// FIXME: Fix remove button for quirks mode
var addRemoveButton = function(text, name)
{
text.parentNode.style.marginRight = '12px';
var removeAttr = document.createElement('a');
var img = mxUtils.createImage(IMAGE_PATH + '/close.png');
img.style.height = '9px';
img.style.fontSize = '9px';
img.style.marginBottom = '7px';
removeAttr.className = 'geButton';
removeAttr.setAttribute('title', mxResources.get('delete'));
removeAttr.style.margin = '0px';
removeAttr.style.width = '14px';
removeAttr.style.height = '14px';
removeAttr.style.fontSize = '14px';
removeAttr.style.cursor = 'pointer';
removeAttr.style.marginLeft = '6px';
removeAttr.appendChild(img);
var removeAttrFn = (function(name)
{
return function()
{
var count = 0;
for (var j = 0; j < names.length; j++)
{
if (names[j] == name)
{
texts[j] = null;
form.table.deleteRow(count);
break;
}
if (texts[j] != null)
{
count++;
}
}
};
})(name);
mxEvent.addListener(removeAttr, 'click', removeAttrFn);
text.parentNode.style.whiteSpace = 'nowrap';
text.parentNode.appendChild(removeAttr);
};
var addTextArea = function(index, name, value)
{
names[index] = name;
texts[index] = form.addTextarea(names[count] + ':', value, 2);
texts[index].style.width = '100%';
addRemoveButton(texts[index], name);
};
2013-07-12 07:09:46 +00:00
for (var i = 0; i < attrs.length; i++)
{
if (attrs[i].nodeName != 'label')
{
2014-06-02 08:21:19 +00:00
addTextArea(count, attrs[i].nodeName, attrs[i].nodeValue);
2013-07-12 07:09:46 +00:00
count++;
}
}
div.appendChild(form.table);
2014-05-12 09:58:11 +00:00
var newProp = document.createElement('div');
newProp.style.whiteSpace = 'nowrap';
newProp.style.marginTop = '6px';
mxUtils.write(newProp, mxResources.get('addProperty') + ':');
mxUtils.br(newProp);
var nameInput = document.createElement('input');
nameInput.setAttribute('placeholder', mxResources.get('enterPropertyName'));
nameInput.setAttribute('type', 'text');
nameInput.setAttribute('size', (mxClient.IS_QUIRKS) ? '18' : '22');
nameInput.style.marginLeft = '2px';
newProp.appendChild(nameInput);
mxUtils.write(newProp, ':');
var valueInput = document.createElement('input');
valueInput.setAttribute('placeholder', mxResources.get('enterValue'));
valueInput.setAttribute('type', 'text');
valueInput.setAttribute('size', (mxClient.IS_QUIRKS) ? '18' : '22');
valueInput.style.marginLeft = '6px';
newProp.appendChild(valueInput);
div.appendChild(newProp);
2013-07-12 07:09:46 +00:00
2014-05-12 09:58:11 +00:00
var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
2013-07-12 07:09:46 +00:00
{
2014-05-12 09:58:11 +00:00
ui.hideDialog.apply(ui, arguments);
});
var applyBtn = mxUtils.button(mxResources.get('apply'), function()
{
if (nameInput.value.length > 0)
2013-07-12 07:09:46 +00:00
{
2014-05-12 09:58:11 +00:00
var name = nameInput.value;
2013-07-12 07:09:46 +00:00
2014-06-02 08:21:19 +00:00
if (name != null && name.length > 0 && name != 'label')
2013-07-12 07:09:46 +00:00
{
2013-07-19 09:51:30 +00:00
try
{
2014-05-12 09:58:11 +00:00
var idx = mxUtils.indexOf(names, name);
2013-07-19 09:51:30 +00:00
2014-06-02 08:21:19 +00:00
if (idx >= 0 && texts[idx] != null)
2014-05-12 09:58:11 +00:00
{
texts[idx].value = valueInput.value;
texts[idx].focus();
}
else
{
// Checks if the name is valid
var clone = value.cloneNode(false);
clone.setAttribute(name, '');
2014-06-02 08:21:19 +00:00
if (idx >= 0)
{
names.splice(idx, 1);
texts.splice(idx, 1);
}
2014-05-12 09:58:11 +00:00
names.push(name);
var text = form.addTextarea(name + ':', valueInput.value, 2);
text.style.width = '100%';
texts.push(text);
2014-06-02 08:21:19 +00:00
addRemoveButton(text, name);
2014-05-12 09:58:11 +00:00
text.focus();
}
applyBtn.innerHTML = mxResources.get('apply');
nameInput.value = '';
valueInput.value = '';
2013-07-19 09:51:30 +00:00
}
catch (e)
{
mxUtils.alert(e);
}
2013-07-12 07:09:46 +00:00
}
}
2014-05-12 09:58:11 +00:00
else
2013-07-12 07:09:46 +00:00
{
2014-05-12 09:58:11 +00:00
try
{
ui.hideDialog.apply(ui, arguments);
// Clones and updates the value
value = value.cloneNode(true);
for (var i = 0; i < names.length; i++)
{
2014-06-02 08:21:19 +00:00
if (texts[i] == null)
{
value.removeAttribute(names[i]);
}
else
{
value.setAttribute(names[i], texts[i].value);
}
2014-05-12 09:58:11 +00:00
}
// Updates the value of the cell (undoable)
ui.editor.graph.getModel().setValue(cell, value);
}
catch (e)
2013-07-12 07:09:46 +00:00
{
2014-05-12 09:58:11 +00:00
mxUtils.alert(e);
2013-07-12 07:09:46 +00:00
}
}
});
2014-04-01 11:30:48 +00:00
2014-05-12 09:58:11 +00:00
mxEvent.addListener(nameInput, 'change', function()
{
applyBtn.innerHTML = mxResources.get((nameInput.value.length > 0) ? 'add' : 'apply');
});
2013-07-12 07:09:46 +00:00
var buttons = document.createElement('div');
2014-05-12 09:58:11 +00:00
buttons.style.marginTop = '18px';
2013-07-12 07:09:46 +00:00
buttons.style.textAlign = 'right';
2014-04-01 11:30:48 +00:00
buttons.appendChild(cancelBtn);
2013-07-12 07:09:46 +00:00
buttons.appendChild(applyBtn);
div.appendChild(buttons);
this.container = div;
};
2014-04-01 11:30:48 +00:00
2014-04-13 06:49:20 +00:00
/**
* Constructs a new link dialog.
*/
var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
{
var div = document.createElement('div');
2014-05-15 19:58:36 +00:00
mxUtils.write(div, mxResources.get('editLink') + ':');
2014-04-13 06:49:20 +00:00
var inner = document.createElement('div');
inner.className = 'geTitle';
inner.style.backgroundColor = 'transparent';
inner.style.borderColor = 'transparent';
inner.style.whiteSpace = 'nowrap';
inner.style.textOverflow = 'clip';
inner.style.cursor = 'default';
if (!mxClient.IS_VML)
{
inner.style.paddingRight = '20px';
}
var linkInput = document.createElement('input');
linkInput.setAttribute('value', initialValue);
2014-05-12 09:58:11 +00:00
linkInput.setAttribute('placeholder', 'http://www.example.com/');
2014-04-13 06:49:20 +00:00
linkInput.setAttribute('type', 'text');
linkInput.style.marginTop = '6px';
linkInput.style.width = '300px';
linkInput.style.backgroundImage = 'url(' + IMAGE_PATH + '/clear.gif)';
linkInput.style.backgroundRepeat = 'no-repeat';
linkInput.style.backgroundPosition = '100% 50%';
linkInput.style.paddingRight = '14px';
var cross = document.createElement('div');
cross.setAttribute('title', mxResources.get('reset'));
cross.style.position = 'relative';
cross.style.left = '-16px';
cross.style.width = '12px';
cross.style.height = '14px';
cross.style.cursor = 'pointer';
// Workaround for inline-block not supported in IE
cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
// Needed to block event transparency in IE
cross.style.background = 'url(' + IMAGE_PATH + '/transparent.gif)';
mxEvent.addListener(cross, 'click', function()
{
linkInput.value = '';
linkInput.focus();
});
inner.appendChild(linkInput);
inner.appendChild(cross);
div.appendChild(inner);
this.init = function()
{
linkInput.focus();
2014-05-15 19:58:36 +00:00
if (mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
{
linkInput.select();
}
else
{
document.execCommand('selectAll');
}
2014-04-13 06:49:20 +00:00
};
var btns = document.createElement('div');
btns.style.marginTop = '14px';
btns.style.textAlign = 'right';
btns.appendChild(mxUtils.button(mxResources.get('cancel'), function()
{
editorUi.hideDialog();
}));
mxEvent.addListener(linkInput, 'keyup', function(e)
{
if (e.keyCode == 13)
{
editorUi.hideDialog();
fn(linkInput.value);
}
else if (e.keyCode == 27)
{
editorUi.hideDialog();
}
});
btns.appendChild(mxUtils.button(btnLabel, function()
{
editorUi.hideDialog();
fn(linkInput.value);
}));
div.appendChild(btns);
this.container = div;
};
2014-05-05 08:30:00 +00:00
/**
*
*/
var OutlineWindow = function(editorUi, x, y, w, h)
{
var graph = editorUi.editor.graph;
var div = document.createElement('div');
div.style.position = 'absolute';
div.style.width = '100%';
div.style.height = '100%';
div.style.border = '1px solid whiteSmoke';
div.style.overflow = 'hidden';
this.window = new mxWindow(mxResources.get('outline'), div, x, y, w, h, true, true);
this.window.destroyOnClose = false;
this.window.setMaximizable(false);
this.window.setResizable(true);
this.window.setClosable(true);
this.window.setVisible(true);
this.window.setLocation = function(x, y)
{
x = Math.max(0, x);
y = Math.max(0, y);
mxWindow.prototype.setLocation.apply(this, arguments);
};
mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
{
var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var x = this.window.getX();
var y = this.window.getY();
if (x + this.window.table.clientWidth > iw)
{
x = Math.max(0, iw - this.window.table.clientWidth);
}
if (y + this.window.table.clientHeight > ih)
{
y = Math.max(0, ih - this.window.table.clientHeight);
}
if (this.window.getX() != x || this.window.getY() != y)
{
this.window.setLocation(x, y);
}
}));
var outline = editorUi.createOutline(this.window);
this.window.addListener(mxEvent.RESIZE, mxUtils.bind(this, function()
{
outline.update(false);
outline.outline.sizeDidChange();
}));
this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
{
outline.suspended = false;
outline.update();
}));
this.window.addListener(mxEvent.HIDE, mxUtils.bind(this, function()
{
outline.suspended = true;
}));
this.window.addListener(mxEvent.NORMALIZE, mxUtils.bind(this, function()
{
outline.suspended = false;
outline.update();
}));
this.window.addListener(mxEvent.MINIMIZE, mxUtils.bind(this, function()
{
outline.suspended = true;
}));
var outlineCreateGraph = outline.createGraph;
outline.createGraph = function(container)
{
var g = outlineCreateGraph.apply(this, arguments);
g.gridEnabled = false;
g.pageScale = graph.pageScale;
g.pageFormat = graph.pageFormat;
g.background = graph.background;
g.pageVisible = graph.pageVisible;
var current = mxUtils.getCurrentStyle(graph.container);
div.style.backgroundColor = current.backgroundColor;
return g;
};
function update()
{
outline.outline.pageScale = graph.pageScale;
outline.outline.pageFormat = graph.pageFormat;
outline.outline.pageVisible = graph.pageVisible;
outline.outline.background = graph.background;
var current = mxUtils.getCurrentStyle(graph.container);
div.style.backgroundColor = current.backgroundColor;
if (graph.view.backgroundPageShape != null && outline.outline.view.backgroundPageShape != null)
{
outline.outline.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
}
outline.outline.refresh();
};
outline.init(div);
editorUi.editor.addListener('resetGraphView', update);
editorUi.addListener('pageFormatChanged', update);
editorUi.addListener('backgroundColorChanged', update);
editorUi.addListener('backgroundImageChanged', update);
editorUi.addListener('pageViewChanged', function()
{
update();
outline.update(true);
});
if (outline.outline.dialect == mxConstants.DIALECT_SVG)
{
var zoomInAction = editorUi.actions.get('zoomIn');
var zoomOutAction = editorUi.actions.get('zoomOut');
mxEvent.addMouseWheelListener(function(evt, up)
{
var outlineWheel = false;
var source = mxEvent.getSource(evt);
while (source != null)
{
if (source == outline.outline.view.canvas.ownerSVGElement)
{
outlineWheel = true;
break;
}
source = source.parentNode;
}
if (outlineWheel)
{
if (up)
{
zoomInAction.funct();
}
else
{
zoomOutAction.funct();
}
mxEvent.consume(evt);
}
});
}
};
2014-04-01 11:30:48 +00:00
/**
*
*/
2014-04-13 06:49:20 +00:00
var LayersWindow = function(editorUi, x, y, w, h)
2014-04-01 11:30:48 +00:00
{
var graph = editorUi.editor.graph;
var div = document.createElement('div');
div.style.background = 'whiteSmoke';
2014-05-05 08:30:00 +00:00
div.style.border = '1px solid whiteSmoke';
2014-04-01 11:30:48 +00:00
div.style.height = '100%';
div.style.marginBottom = '10px';
div.style.overflow = 'auto';
function refresh()
{
var layerCount = graph.model.getChildCount(graph.model.root);
var selectionLayer = null;
div.innerHTML = '';
function addLayer(index, label, child, defaultParent)
{
var ldiv = document.createElement('div');
ldiv.style.overflow = 'hidden';
ldiv.style.position = 'relative';
ldiv.style.padding = '4px';
ldiv.style.height = '22px';
ldiv.style.display = 'block';
ldiv.style.cursor = 'pointer';
ldiv.style.backgroundColor = '#e5e5e5';
ldiv.style.borderWidth = '0px 0px 1px 0px';
2014-05-05 08:30:00 +00:00
ldiv.style.borderColor = '#c3c3c3';
2014-04-01 11:30:48 +00:00
ldiv.style.borderStyle = 'solid';
ldiv.style.whiteSpace = 'nowrap';
var left = document.createElement('div');
left.style.display = 'inline-block';
left.style.overflow = 'hidden';
var inp = document.createElement('input');
inp.setAttribute('type', 'checkbox');
inp.setAttribute('title', mxResources.get('hideIt', [child.value || mxResources.get('background')]));
inp.style.marginRight = '4px';
inp.style.marginTop = '4px';
left.appendChild(inp);
inp.value = graph.model.isVisible(child);
if (graph.model.isVisible(child))
{
inp.setAttribute('checked', 'checked');
2014-05-05 08:30:00 +00:00
inp.defaultChecked = true;
2014-04-01 11:30:48 +00:00
}
else
{
ldiv.style.color = 'gray';
}
if (mxClient.IS_SVG)
{
mxEvent.addListener(inp, 'change', function(evt)
{
if (graph.isEnabled())
{
graph.model.setVisible(child, !graph.model.isVisible(child));
}
});
if (!mxClient.IS_FF)
{
mxEvent.addListener(inp, 'click', function(evt)
{
mxEvent.consume(evt);
});
}
}
else
{
mxEvent.addListener(inp, 'click', function(evt)
{
if (graph.isEnabled())
{
graph.model.setVisible(child, !graph.model.isVisible(child));
}
});
}
mxUtils.write(left, label);
ldiv.appendChild(left);
var right = document.createElement('div');
right.style.display = 'inline-block';
right.style.textAlign = 'right';
right.style.whiteSpace = 'nowrap';
if (mxClient.IS_QUIRKS)
{
ldiv.style.height = '34px';
}
ldiv.className = (mxClient.IS_QUIRKS) ? '' : 'geToolbarContainer';;
right.style.position = 'absolute';
right.style.right = '6px';
right.style.top = '6px';
// Poor man's change layer order
if (index > 1)
{
var img2 = document.createElement('a');
img2.setAttribute('title', mxResources.get('toBack'));
img2.className = 'geButton';
img2.style.cssFloat = 'none';
img2.innerHTML = '&#9650;';
img2.style.width = '14px';
img2.style.height = '14px';
img2.style.fontSize = '14px';
img2.style.margin = '0px';
img2.style.marginTop = '-1px';
right.appendChild(img2);
mxEvent.addListener(img2, 'click', function(evt)
{
if (graph.isEnabled())
{
graph.addCell(child, graph.model.root, index - 1);
}
mxEvent.consume(evt);
});
}
if (index > 0 && index < layerCount - 1)
{
var img1 = document.createElement('a');
img1.setAttribute('title', mxResources.get('toFront'));
img1.className = 'geButton';
img1.style.cssFloat = 'none';
img1.innerHTML = '&#9660;';
img1.style.width = '14px';
img1.style.height = '14px';
img1.style.fontSize = '14px';
img1.style.margin = '0px';
img1.style.marginTop = '-1px';
right.appendChild(img1);
mxEvent.addListener(img1, 'click', function(evt)
{
if (graph.isEnabled())
{
graph.addCell(child, graph.model.root, index + 1);
}
mxEvent.consume(evt);
});
}
if (index > 0)
{
var img = document.createElement('a');
img.className = 'geButton';
img.style.cssFloat = 'none';
img.innerHTML = 'X';
img.setAttribute('title', mxResources.get('delete'));
img.style.margin = '0px';
img.style.marginTop = '-2px';
img.style.width = '14px';
img.style.height = '14px';
img.style.fontSize = '14px';
right.appendChild(img);
mxEvent.addListener(img, 'click', function(evt)
{
if (graph.isEnabled())
{
editorUi.confirm(mxResources.get('removeIt', [child.value]) + '?', function()
{
graph.model.beginUpdate();
try
{
graph.removeCells([child]);
graph.setDefaultParent(null);
}
finally
{
graph.model.endUpdate();
}
});
}
mxEvent.consume(evt);
});
}
ldiv.appendChild(right);
div.appendChild(ldiv);
mxEvent.addListener(ldiv, 'dblclick', function(evt)
{
if (graph.isEnabled())
{
var dlg = new FilenameDialog(editorUi, child.value || mxResources.get('background'), mxResources.get('rename'), mxUtils.bind(this, function(newValue)
{
if (newValue != null)
{
graph.getModel().setValue(child, newValue);
}
}), mxResources.get('enterName'));
editorUi.showDialog(dlg.container, 300, 80, true, true);
dlg.init();
}
mxEvent.consume(evt);
});
if (graph.getDefaultParent() == child)
{
ldiv.style.background = '#e6eff8';
selectionLayer = child;
}
else
{
mxEvent.addListener(ldiv, 'click', function(evt)
{
if (graph.isEnabled())
{
graph.setDefaultParent(defaultParent);
graph.view.setCurrentRoot(null);
refresh();
}
});
}
};
// Cannot be moved or deleted
var defaultLayer = graph.model.getChildAt(graph.model.root, 0);
addLayer(0, defaultLayer.value || mxResources.get('background'), defaultLayer, null);
for (var i = 1; i < layerCount; i++)
{
(mxUtils.bind(this, function(child)
{
addLayer(i, child.value, child, child);
}))(graph.model.getChildAt(graph.model.root, i));
}
if (selectionLayer != null)
{
var ldiv = document.createElement('div');
ldiv.className = (mxClient.IS_QUIRKS) ? '' : 'geToolbarContainer';
ldiv.style.display = 'block';
ldiv.style.position = 'relative';
ldiv.style.overflow = 'hidden';
ldiv.style.paddingTop = '7px';
ldiv.style.display = 'block';
ldiv.style.whiteSpace = 'nowrap';
if (mxClient.IS_QUIRKS)
{
ldiv.style.filter = 'none';
}
var link = document.createElement('a');
mxUtils.write(link, mxResources.get('moveSelectionTo', [selectionLayer.value || mxResources.get('background')]));
link.style.marginTop = '-2px';
link.className = 'geLabel';
link.style.cursor = 'pointer';
mxEvent.addListener(link, 'click', function(evt)
{
if (graph.isEnabled())
{
graph.moveCells(graph.getSelectionCells(), 0, 0, false, selectionLayer);
}
mxEvent.consume(evt);
});
ldiv.appendChild(link);
div.appendChild(ldiv);
}
var ldiv = document.createElement('div');
ldiv.className = (mxClient.IS_QUIRKS) ? '' : 'geToolbarContainer';
ldiv.style.display = 'block';
ldiv.style.position = 'relative';
ldiv.style.overflow = 'hidden';
ldiv.style.paddingTop = '7px';
ldiv.style.display = 'block';
ldiv.style.whiteSpace = 'nowrap';
var link = document.createElement('a');
2014-05-05 08:30:00 +00:00
mxUtils.write(link, mxResources.get('addLayer'));
2014-04-01 11:30:48 +00:00
link.style.marginTop = '-2px';
link.className = 'geLabel';
link.style.cursor = 'pointer';
mxEvent.addListener(link, 'click', function(evt)
{
if (graph.isEnabled())
{
var dlg = new FilenameDialog(editorUi, mxResources.get('layer') + ' ' + layerCount, mxResources.get('create'), mxUtils.bind(this, function(newValue)
{
if (newValue != null && newValue.length > 0)
{
graph.model.beginUpdate();
try
{
var cell = graph.addCell(new mxCell(newValue), graph.model.root);
graph.setDefaultParent(cell);
}
finally
{
graph.model.endUpdate();
}
}
}), mxResources.get('enterName'));
editorUi.showDialog(dlg.container, 300, 80, true, true);
dlg.init();
}
mxEvent.consume(evt);
});
ldiv.appendChild(link);
div.appendChild(ldiv);
};
refresh();
graph.model.addListener(mxEvent.CHANGE, function()
{
refresh();
});
this.window = new mxWindow(mxResources.get('layers'), div, x, y, w, h, true, true);
this.window.destroyOnClose = false;
this.window.setMaximizable(false);
this.window.setResizable(true);
this.window.setClosable(true);
this.window.setVisible(true);
2014-05-05 08:30:00 +00:00
this.window.setLocation = function(x, y)
{
x = Math.max(0, x);
y = Math.max(0, y);
mxWindow.prototype.setLocation.apply(this, arguments);
};
mxEvent.addListener(window, 'resize', mxUtils.bind(this, function()
{
var iw = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var ih = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var x = this.window.getX();
var y = this.window.getY();
if (x + this.window.table.clientWidth > iw)
{
x = Math.max(0, iw - this.window.table.clientWidth);
}
if (y + this.window.table.clientHeight > ih)
{
y = Math.max(0, ih - this.window.table.clientHeight);
}
if (this.window.getX() != x || this.window.getY() != y)
{
this.window.setLocation(x, y);
}
}));
2014-04-01 11:30:48 +00:00
};