';
var takeEditPopupTimeout = null;
function onSearch(e) {
if (e.keyCode === 13) {
var toolbar = w2ui['toolbar-down'];
map.search(L.DomUtil.get('search-input').value);
toolbar.enable('searchprev');
toolbar.enable('searchnext');
toolbar.show('cancelsearch');
}
else {
map.fire('requestloksession');
}
}
function onClick(id) {
if (w2ui['toolbar-up'].get(id) !== null) {
var toolbar = w2ui['toolbar-up'];
var item = toolbar.get(id) ;
}
else if (w2ui['formulabar'].get(id) !== null) {
toolbar = w2ui['formulabar'];
item = toolbar.get(id) ;
}
else if (w2ui['toolbar-down'].get(id) !== null) {
toolbar = w2ui['toolbar-down'];
item = toolbar.get(id) ;
}
else if (w2ui['spreadsheet-toolbar'].get(id) !== null) {
toolbar = w2ui['spreadsheet-toolbar'];
item = toolbar.get(id) ;
}
else if (w2ui['presentation-toolbar'].get(id) != null) {
toolbar = w2ui['presentation-toolbar'];
item = toolbar.get(id);
}
else {
throw new Error('unknown id: ' + id);
}
var docLayer = map._docLayer;
map.focus();
if (item.disabled) {
return;
}
if (item.uno) {
if (item.unosheet && map.getDocType() === 'spreadsheet') {
map.toggleCommandState(item.unosheet);
}
else {
map.toggleCommandState(item.uno);
}
}
else if (id === 'zoomin' && map.getZoom() < map.getMaxZoom()) {
map.zoomIn(1);
}
else if (id === 'zoomout' && map.getZoom() > map.getMinZoom()) {
map.zoomOut(1);
}
else if (id === 'zoomreset') {
map.setZoom(map.options.zoom);
}
else if (id === 'prev' || id === 'next') {
if (docLayer._docType === 'text') {
map.goToPage(id);
}
else {
map.setPart(id);
}
}
else if (id === 'menu:file:saveas') {
var dialog = '' +
'' +
'' +
'' +
'' +
'';
vex.dialog.open({
message: 'Save as:',
input: dialog,
callback: onSaveAs
});
}
else if (id === 'takeedit') {
if (!item.checked) {
map._socket.sendMessage('takeedit');
// And advertise which page we're on.
map._socket.sendMessage('setclientpart part=' + map._docLayer._selectedPart);
}
}
else if (id === 'searchprev') {
map.search(L.DomUtil.get('search-input').value, true);
}
else if (id === 'searchnext') {
map.search(L.DomUtil.get('search-input').value);
}
else if (id === 'cancelsearch') {
map.resetSelection();
toolbar.hide('cancelsearch');
toolbar.disable('searchprev');
toolbar.disable('searchnext');
L.DomUtil.get('search-input').value = '';
}
else if (id === 'presentation' && map.getDocType() === 'presentation') {
map.fire('fullscreen');
}
else if (id === 'insertpage') {
map.insertPage();
}
else if (id === 'duplicatepage') {
map.duplicatePage();
}
else if (id === 'deletepage') {
vex.dialog.confirm({
message: _("Are you sure you want to delete this page?"),
callback: onDelete
});
}
else if (id === 'firstrecord') {
$('#spreadsheet-tab-scroll').scrollLeft(0);
}
// TODO: We should get visible tab's width instead of 60px
else if (id === 'nextrecord') {
$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft()+60);
}
else if (id === 'prevrecord') {
$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft()-60);
}
else if (id === 'lastrecord') {
$('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').prop("scrollWidth"));
}
else if (id === 'insertgraphic') {
L.DomUtil.get('insertgraphic').click();
}
else if (id === 'fontcolor') {
// absolutely no idea why, but without the timeout, the popup is
// closed as soon as it is opend
setTimeout(function () {$('#fontColorPicker').colorpicker('showPalette')}, 0);
}
else if (id === 'backcolor') {
// absolutely no idea why, but without the timeout, the popup is
// closed as soon as it is opend
setTimeout(function () {$('#backColorPicker').colorpicker('showPalette')}, 0);
}
else if (id === 'sum') {
L.DomUtil.get('formulaInput').value = '=SUM()';
L.DomUtil.get('formulaInput').focus();
map.cellEnterString(L.DomUtil.get('formulaInput').value);
}
else if (id === 'function') {
L.DomUtil.get('formulaInput').value = '=';
L.DomUtil.get('formulaInput').focus();
map.cellEnterString(L.DomUtil.get('formulaInput').value);
}
else if (id === 'cancelformula') {
L.DomUtil.get('formulaInput').value = '';
map.cellEnterString(L.DomUtil.get('formulaInput').value);
}
else if (id === 'acceptformula') {
map.cellEnterString(L.DomUtil.get('formulaInput').value);
}
else if (id === 'more') {
$('#toolbar-up-more').toggle();
if ($('#toolbar-up-more').is(':visible')) {
toolbar.check('more');
}
else {
toolbar.uncheck('more');
}
resizeToolbar();
}
else if (id === 'help') {
var w = window.innerWidth / 2;
var h = window.innerHeight / 2;
$.modal('