/**
* Copyright (c) 2006-2020, JGraph Holdings Ltd
* Copyright (c) 2006-2020, draw.io AG
*/
var StorageDialog = function(editorUi, fn, rowLimit)
{
rowLimit = (rowLimit != null) ? rowLimit : 2;
var div = document.createElement('div');
div.style.textAlign = 'center';
div.style.whiteSpace = 'nowrap';
div.style.paddingTop = '0px';
div.style.paddingBottom = '20px';
var buttons = document.createElement('div');
buttons.style.border = '1px solid #d3d3d3';
buttons.style.borderWidth = '1px 0px 1px 0px';
buttons.style.padding = '10px 0px 20px 0px';
var count = 0, totalBtns = 0;
var container = document.createElement('div');
container.style.paddingTop = '2px';
buttons.appendChild(container);
var p3 = document.createElement('p');
function addLogo(img, title, mode, clientName, labels, clientFn)
{
totalBtns++;
if (++count > rowLimit)
{
mxUtils.br(container);
count = 1;
}
var button = document.createElement('a');
button.style.overflow = 'hidden';
button.style.display = 'inline-block';
button.className = 'geBaseButton';
button.style.boxSizing = 'border-box';
button.style.fontSize = '11px';
button.style.position = 'relative';
button.style.margin = '4px';
button.style.marginTop = '8px';
button.style.marginBottom = '0px';
button.style.padding = '8px 10px 8px 10px';
button.style.width = '88px';
button.style.height = '100px';
button.style.whiteSpace = 'nowrap';
button.setAttribute('title', title);
var label = document.createElement('div');
label.style.textOverflow = 'ellipsis';
label.style.overflow = 'hidden';
label.style.position = 'absolute';
label.style.bottom = '8px';
label.style.left = '0px';
label.style.right = '0px';
mxUtils.write(label, title);
button.appendChild(label);
if (img != null)
{
var logo = document.createElement('img');
logo.setAttribute('src', img);
logo.setAttribute('border', '0');
logo.setAttribute('align', 'absmiddle');
logo.style.width = '60px';
logo.style.height = '60px';
logo.style.paddingBottom = '6px';
button.appendChild(logo);
}
else
{
label.style.paddingTop = '5px';
label.style.whiteSpace = 'normal';
// Handles special case
if (mxClient.IS_IOS)
{
button.style.padding = '0px 10px 20px 10px';
button.style.top = '6px';
}
else if (mxClient.IS_FF)
{
label.style.paddingTop = '0px';
label.style.marginTop = '-2px';
}
}
if (labels != null)
{
for (var i = 0; i < labels.length; i++)
{
mxUtils.br(label);
mxUtils.write(label, labels[i]);
}
}
function initButton()
{
mxEvent.addListener(button, 'click', (clientFn != null) ? clientFn : function()
{
if (mode == App.MODE_GOOGLE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
{
// Tries immediate authentication
editorUi.drive.checkToken(mxUtils.bind(this, function()
{
editorUi.spinner.stop();
editorUi.setMode(mode, true);
fn();
}));
}
else if (mode == App.MODE_ONEDRIVE && editorUi.spinner.spin(document.body, mxResources.get('authorizing')))
{
// Tries immediate authentication
editorUi.oneDrive.checkToken(mxUtils.bind(this, function()
{
editorUi.spinner.stop();
editorUi.setMode(mode, true);
fn();
}), function(err)
{
editorUi.spinner.stop();
editorUi.handleError(err);
});
}
else
{
editorUi.setMode(mode, true);
fn();
}
});
};
// Supports lazy loading
if (clientName != null && editorUi[clientName] == null)
{
logo.style.visibility = 'hidden';
mxUtils.setOpacity(label, 10);
var size = 12;
var spinner = new Spinner({
lines: 12, // The number of lines to draw
length: size, // The length of each line
width: 5, // The line thickness
radius: 10, // The radius of the inner circle
rotate: 0, // The rotation offset
color: 'light-dark(#000000, #C0C0C0)',
speed: 1.5, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
top: '40%',
zIndex: 2e9 // The z-index (defaults to 2000000000)
});
spinner.spin(button);
// Timeout after 30 secs
var timeout = window.setTimeout(function()
{
if (editorUi[clientName] == null)
{
spinner.stop();
button.style.display = 'none';
}
}, 30000);
editorUi.addListener('clientLoaded', mxUtils.bind(this, function(sender, evt)
{
if (editorUi[clientName] != null && evt.getProperty('client') == editorUi[clientName])
{
window.clearTimeout(timeout);
mxUtils.setOpacity(label, 100);
logo.style.visibility = '';
spinner.stop();
initButton();
if (clientName == 'drive' && p3.parentNode != null)
{
p3.parentNode.removeChild(p3);
}
}
}));
}
else
{
initButton();
}
container.appendChild(button);
};
var hd = document.createElement('p');
hd.style.cssText = 'font-size:22px;padding:4px 0 16px 0;margin:0;color:gray;';
mxUtils.write(hd, mxResources.get('saveDiagramsTo') + ':');
div.appendChild(hd);
var addButtons = function()
{
count = 0;
if (typeof window.DriveClient === 'function')
{
addLogo(IMAGE_PATH + '/google-drive-logo.svg', mxResources.get('googleDrive'), App.MODE_GOOGLE, 'drive');
}
if (typeof window.OneDriveClient === 'function')
{
addLogo(IMAGE_PATH + '/onedrive-logo.svg', mxResources.get('oneDrive'), App.MODE_ONEDRIVE, 'oneDrive');
}
if (urlParams['noDevice'] != '1')
{
addLogo(IMAGE_PATH + '/osa_drive-harddisk.png', mxResources.get('device'), App.MODE_DEVICE);
}
if (isLocalStorage && (urlParams['browser'] == '1' || urlParams['offline'] == '1'))
{
addLogo(IMAGE_PATH + '/osa_database.png', mxResources.get('browser'), App.MODE_BROWSER);
}
if (typeof window.DropboxClient === 'function')
{
addLogo(IMAGE_PATH + '/dropbox-logo.svg', mxResources.get('dropbox'), App.MODE_DROPBOX, 'dropbox');
}
if (editorUi.gitHub != null)
{
addLogo(IMAGE_PATH + '/github-logo.svg', mxResources.get('github'), App.MODE_GITHUB, 'gitHub');
}
if (editorUi.gitLab != null)
{
addLogo(IMAGE_PATH + '/gitlab-logo.svg', mxResources.get('gitlab'), App.MODE_GITLAB, 'gitLab');
}
};
div.appendChild(buttons);
addButtons();
var later = document.createElement('span');
later.style.position = 'absolute';
later.style.cursor = 'pointer';
later.style.bottom = '27px';
later.style.color = 'gray';
later.style.userSelect = 'none';
later.style.textAlign = 'center';
later.style.left = '50%';
mxUtils.setPrefixedStyle(later.style, 'transform', 'translate(-50%,0)');
mxUtils.write(later, mxResources.get('decideLater'));
div.appendChild(later);
mxEvent.addListener(later, 'click', function()
{
editorUi.hideDialog();
var prev = Editor.useLocalStorage;
editorUi.createFile(editorUi.defaultFilename,
null, null, null, null, null, null, true);
Editor.useLocalStorage = prev;
});
// Checks if Google Drive is missing after a 5 sec delay
if (mxClient.IS_SVG && isLocalStorage && urlParams['gapi'] != '0' &&
(document.documentMode == null || document.documentMode >= 10))
{
window.setTimeout(function()
{
if (editorUi.drive == null)
{
// To check for Disconnect plugin in chrome use mxClient.IS_GC and check for URL:
// chrome-extension://jeoacafpbcihiomhlakheieifhpjdfeo/scripts/vendor/jquery/jquery-2.0.3.min.map
p3.style.padding = '7px';
p3.style.fontSize = '9pt';
p3.style.marginTop = '-14px';
p3.innerHTML = '' +
' ' + mxResources.get('googleDriveMissingClickHere') + '';
div.appendChild(p3);
}
}, 5000);
}
this.container = div;
};
/**
* Constructs a dialog for creating new files from templates.
*/
var SplashDialog = function(editorUi)
{
var div = document.createElement('div');
div.style.textAlign = 'center';
if (mxClient.IS_CHROMEAPP || EditorUi.isElectronApp)
{
var elt = editorUi.addLanguageMenu(div, false, '28px');
if (elt != null)
{
elt.style.bottom = '24px';
}
}
var logo = document.createElement('img');
logo.setAttribute('border', '0');
logo.setAttribute('align', 'absmiddle');
logo.style.width = '32px';
logo.style.height = '32px';
logo.style.marginRight = '8px';
logo.style.marginTop = '-4px';
var buttons = document.createElement('div');
buttons.style.margin = '8px 0px 0px 0px';
buttons.style.padding = '18px 0px 24px 0px';
var service = '';
if (editorUi.mode == App.MODE_GOOGLE)
{
logo.src = IMAGE_PATH + '/google-drive-logo.svg';
service = mxResources.get('googleDrive');
}
else if (editorUi.mode == App.MODE_DROPBOX)
{
logo.src = IMAGE_PATH + '/dropbox-logo.svg';
service = mxResources.get('dropbox');
}
else if (editorUi.mode == App.MODE_ONEDRIVE)
{
logo.src = IMAGE_PATH + '/onedrive-logo.svg';
service = mxResources.get('oneDrive');
}
else if (editorUi.mode == App.MODE_GITHUB)
{
logo.src = IMAGE_PATH + '/github-logo.svg';
service = mxResources.get('github');
}
else if (editorUi.mode == App.MODE_GITLAB)
{
logo.src = IMAGE_PATH + '/gitlab-logo.svg';
service = mxResources.get('gitlab');
}
else if (editorUi.mode == App.MODE_BROWSER)
{
logo.src = IMAGE_PATH + '/osa_database.png';
service = mxResources.get('browser');
}
else if (editorUi.mode == App.MODE_TRELLO)
{
logo.src = IMAGE_PATH + '/trello-logo.svg';
service = mxResources.get('trello');
}
else
{
logo.src = IMAGE_PATH + '/osa_drive-harddisk.png';
buttons.style.paddingBottom = '10px';
buttons.style.paddingTop = '30px';
service = mxResources.get('device');
}
var btn = document.createElement('button');
btn.className = 'geBigButton';
btn.style.marginBottom = '8px';
btn.style.fontSize = '18px';
btn.style.padding = '10px';
btn.style.width = '340px';
if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
{
buttons.style.border = '1px solid #d3d3d3';
buttons.style.borderWidth = '1px 0px 1px 0px';
var table = document.createElement('table');
var tbody = document.createElement('tbody');
var row = document.createElement('tr');
var left = document.createElement('td');
var right = document.createElement('td');
table.setAttribute('align', 'center');
left.appendChild(logo);
var title = document.createElement('div');
title.style.fontSize = '22px';
title.style.paddingBottom = '6px';
title.style.color = 'gray';
mxUtils.write(title, service);
right.style.textAlign = 'left';
right.appendChild(title);
row.appendChild(left);
row.appendChild(right);
tbody.appendChild(row);
table.appendChild(tbody);
div.appendChild(table);
var change = document.createElement('span');
change.style.cssText = 'position:absolute;cursor:pointer;bottom:27px;color:gray;userSelect:none;text-align:center;left:50%;';
mxUtils.setPrefixedStyle(change.style, 'transform', 'translate(-50%,0)');
mxUtils.write(change, mxResources.get('changeStorage'));
mxEvent.addListener(change, 'click', function()
{
editorUi.hideDialog(false);
editorUi.setMode(null);
editorUi.clearMode();
editorUi.showSplash(true);
});
div.appendChild(change);
}
else
{
buttons.style.padding = '42px 0px 10px 0px';
btn.style.marginBottom = '12px';
}
mxUtils.write(btn, mxResources.get('createNewDiagram'));
mxEvent.addListener(btn, 'click', function()
{
editorUi.hideDialog();
editorUi.actions.get('new').funct();
});
buttons.appendChild(btn);
mxUtils.br(buttons);
var btn = document.createElement('button');
btn.className = 'geBigButton';
btn.style.marginBottom = '22px';
btn.style.fontSize = '18px';
btn.style.padding = '10px';
btn.style.width = '340px';
mxUtils.write(btn, mxResources.get('openExistingDiagram'));
mxEvent.addListener(btn, 'click', function()
{
editorUi.actions.get('open').funct();
});
buttons.appendChild(btn);
var storage = 'undefined';
if (editorUi.mode == App.MODE_GOOGLE)
{
storage = mxResources.get('googleDrive');
}
else if (editorUi.mode == App.MODE_DROPBOX)
{
storage = mxResources.get('dropbox');
}
else if (editorUi.mode == App.MODE_ONEDRIVE)
{
storage = mxResources.get('oneDrive');
}
else if (editorUi.mode == App.MODE_GITHUB)
{
storage = mxResources.get('github');
}
else if (editorUi.mode == App.MODE_GITLAB)
{
storage = mxResources.get('gitlab');
}
else if (editorUi.mode == App.MODE_TRELLO)
{
storage = mxResources.get('trello');
}
else if (editorUi.mode == App.MODE_DEVICE)
{
storage = mxResources.get('device');
}
else if (editorUi.mode == App.MODE_BROWSER)
{
storage = mxResources.get('browser');
}
if (!mxClient.IS_CHROMEAPP && !EditorUi.isElectronApp)
{
function addLogout(logout)
{
btn.style.marginBottom = '24px';
var link = document.createElement('a');
link.style.display = 'inline-block';
link.style.color = 'gray';
link.style.cursor = 'pointer';
link.style.marginTop = '6px';
mxUtils.write(link, mxResources.get('signOut'));
// Makes room after last big buttons
btn.style.marginBottom = '16px';
buttons.style.paddingBottom = '18px';
mxEvent.addListener(link, 'click', function()
{
editorUi.confirm(mxResources.get('areYouSure'), function()
{
logout();
});
});
buttons.appendChild(link);
};
if (editorUi.mode == App.MODE_GOOGLE && editorUi.drive != null)
{
var driveUsers = editorUi.drive.getUsersList();
if (driveUsers.length > 0)
{
var title = document.createElement('span');
title.style.marginTop = '6px';
mxUtils.write(title, mxResources.get('changeUser') + ':');
// Makes room after last big buttons
btn.style.marginBottom = '16px';
buttons.style.paddingBottom = '18px';
buttons.appendChild(title);
var usersSelect = document.createElement('select');
usersSelect.style.marginLeft = '4px';
usersSelect.style.width = '140px';
for (var i = 0; i < driveUsers.length; i++)
{
var option = document.createElement('option');
mxUtils.write(option, driveUsers[i].displayName);
option.value = i;
usersSelect.appendChild(option);
//More info (email) about the user in a disabled option
option = document.createElement('option');
option.innerHTML = ' ';
mxUtils.write(option, '<' + driveUsers[i].email + '>');
option.setAttribute('disabled', 'disabled');
usersSelect.appendChild(option);
}
//Add account option
var option = document.createElement('option');
mxUtils.write(option, mxResources.get('addAccount'));
option.value = driveUsers.length;
usersSelect.appendChild(option);
mxEvent.addListener(usersSelect, 'change', function()
{
var userIndex = usersSelect.value;
var existingAccount = driveUsers.length != userIndex;
if (existingAccount)
{
editorUi.drive.setUser(driveUsers[userIndex]);
}
editorUi.drive.authorize(existingAccount, function()
{
editorUi.setMode(App.MODE_GOOGLE);
editorUi.hideDialog();
editorUi.showSplash();
}, function(resp)
{
editorUi.handleError(resp, null, function()
{
editorUi.hideDialog();
editorUi.showSplash();
});
}, true);
});
buttons.appendChild(usersSelect);
}
else
{
addLogout(function()
{
editorUi.drive.logout();
});
}
}
else if (editorUi.mode == App.MODE_ONEDRIVE && editorUi.oneDrive != null && !editorUi.oneDrive.noLogout)
{
addLogout(function()
{
editorUi.oneDrive.logout();
});
}
else if (editorUi.mode == App.MODE_GITHUB && editorUi.gitHub != null)
{
addLogout(function()
{
editorUi.gitHub.logout();
editorUi.openLink('https://www.github.com/logout');
});
}
else if (editorUi.mode == App.MODE_GITLAB && editorUi.gitLab != null)
{
addLogout(function()
{
editorUi.gitLab.logout();
// Must use POST request to sign out of GitLab
// see https://gitlab.com/gitlab-org/gitlab/-/issues/202291
var form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', DRAWIO_GITLAB_URL + '/users/sign_out');
form.setAttribute('target', '_blank');
document.body.appendChild(form);
form.submit();
form.parentNode.removeChild(form);
});
}
else if (editorUi.mode == App.MODE_TRELLO && editorUi.trello != null)
{
if (editorUi.trello.isAuthorized())
{
addLogout(function()
{
editorUi.trello.logout();
});
}
}
else if (editorUi.mode == App.MODE_DROPBOX && editorUi.dropbox != null)
{
// NOTE: Dropbox has a logout option in the picker
addLogout(function()
{
editorUi.dropbox.logout();
editorUi.openLink('https://www.dropbox.com/logout');
});
}
}
div.appendChild(buttons);
this.container = div;
};
/**
* Constructs a new embed dialog
*/
var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, title, tweet, previewTitle, filename)
{
tweet = (tweet != null) ? tweet : 'Check out the diagram I made using @drawio';
var div = document.createElement('div');
var maxSize = 500000;
// Checks if result is a link
var validUrl = /^https?:\/\//.test(result) || /^mailto:\/\//.test(result);
if (title != null)
{
mxUtils.write(div, title);
}
else
{
mxUtils.write(div, mxResources.get((result.length < maxSize) ?
((validUrl) ? 'link' : 'mainEmbedNotice') : 'preview') + ':');
}
mxUtils.br(div);
var size = document.createElement('div');
size.style.position = 'absolute';
size.style.top = '30px';
size.style.right = '30px';
size.style.color = 'gray';
mxUtils.write(size, editorUi.formatFileSize(result.length));
div.appendChild(size);
// Using DIV for faster rendering
var text = document.createElement('textarea');
text.setAttribute('autocomplete', 'off');
text.setAttribute('autocorrect', 'off');
text.setAttribute('autocapitalize', 'off');
text.setAttribute('spellcheck', 'false');
text.style.fontFamily = 'monospace';
text.style.wordBreak = 'break-all';
text.style.marginTop = '10px';
text.style.resize = 'none';
text.style.height = '150px';
text.style.width = '440px';
text.style.border = '1px solid gray';
text.value = mxResources.get('updatingDocument');
div.appendChild(text);
mxUtils.br(div);
this.init = function()
{
window.setTimeout(function()
{
if (result.length < maxSize)
{
text.value = result;
text.focus();
if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5)
{
text.select();
}
else
{
document.execCommand('selectAll', false, null);
}
}
else
{
text.setAttribute('readonly', 'true');
text.value = mxResources.get('tooLargeUseDownload');
}
}, 0);
};
var buttons = document.createElement('div');
buttons.style.position = 'absolute';
buttons.style.bottom = '36px';
buttons.style.right = '32px';
var previewBtn = null;
// Loads forever in IE9
if (EmbedDialog.showPreviewOption && !mxIsElectron &&
(!mxClient.IS_CHROMEAPP || validUrl) && !navigator.standalone && (validUrl ||
(mxClient.IS_SVG && (document.documentMode == null || document.documentMode > 9))))
{
previewBtn = mxUtils.button((previewTitle != null) ? previewTitle :
mxResources.get((result.length < maxSize) ? 'preview' : 'openInNewWindow'), function()
{
var value = (result.length < maxSize) ? text.value : result;
if (previewFn != null)
{
previewFn(value);
}
else
{
if (validUrl)
{
try
{
var win = editorUi.openLink(value);
if (win != null && (timeout == null || timeout > 0))
{
window.setTimeout(mxUtils.bind(this, function()
{
try
{
if (win != null && win.location.href != null &&
win.location.href.substring(0, 8) != value.substring(0, 8))
{
win.close();
editorUi.handleError({message: mxResources.get('drawingTooLarge')});
}
}
catch (e)
{
// ignore
}
}), timeout || 500);
}
}
catch (e)
{
editorUi.handleError({message: e.message || mxResources.get('drawingTooLarge')});
}
}
else
{
var wnd = window.open();
var doc = (wnd != null) ? wnd.document : null;
if (doc != null)
{
doc.writeln('