wisemapping-open-source/wise-editor/src/main/webapp/js/editor.js

173 lines
5.4 KiB
JavaScript
Raw Normal View History

2012-02-21 19:37:15 +01:00
/*
2012-10-05 01:48:01 +02:00
* Copyright [2012] [wisemapping]
2012-02-21 19:37:15 +01:00
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var designer = null;
function buildDesigner(options) {
2014-03-05 02:48:31 +01:00
var container = $("#"+options.container);
2012-02-21 19:37:15 +01:00
$assert(container, 'container could not be null');
// Register load events ...
designer = new mindplot.Designer(options, container);
2012-07-01 22:21:02 +02:00
designer.addEvent('loadSuccess', function () {
2014-03-09 09:42:44 +01:00
window.waitDialog.close();
window.waitDialog = null;
window.mindmapLoadReady = true;
2012-02-21 19:37:15 +01:00
});
2014-03-05 00:47:23 +01:00
var onerrorFn = function (message, url, lineNo) {
2012-09-23 15:39:56 +02:00
// Ignore errors ...
if (message === "Script error." && lineNo == 0) {
2012-09-23 15:30:42 +02:00
// http://stackoverflow.com/questions/5913978/cryptic-script-error-reported-in-javascript-in-chrome-and-firefox
return;
}
2012-11-05 03:20:21 +01:00
// Transform error ...
2012-09-23 15:39:56 +02:00
var errorMsg = message;
if (typeof(message) === 'object' && message.srcElement && message.target) {
if (message.srcElement == '[object HTMLScriptElement]' && message.target == '[object HTMLScriptElement]') {
errorMsg = 'Error loading script';
} else {
errorMsg = 'Event Error - target:' + message.target + ' srcElement:' + message.srcElement;
}
}
2012-09-23 15:39:56 +02:00
errorMsg = errorMsg.toString();
2012-09-23 15:30:42 +02:00
new Request({
2012-07-01 22:21:02 +02:00
method:'post',
2012-11-11 06:18:25 +01:00
url:"/c/restful/logger/editor",
2012-07-01 22:21:02 +02:00
headers:{"Content-Type":"application/json", "Accept":"application/json"},
emulation:false,
urlEncoded:false
}).post(JSON.encode({
2012-11-05 03:20:21 +01:00
jsErrorMsg:"Message: '" + errorMsg + "', line:'" + lineNo + "', url: :" + url,
2012-07-01 22:21:02 +02:00
jsStack:window.errorStack,
userAgent:navigator.userAgent,
mapId:options.mapId}));
2012-09-23 15:39:56 +02:00
// Close loading dialog ...
if (window.waitDialog) {
2014-03-09 09:42:44 +01:00
window.waitDialog.close();
2012-09-23 15:39:56 +02:00
window.waitDialog = null;
}
// Open error dialog only in case of mindmap loading errors. The rest of the error are reported but not display the dialog.
// Remove this in the near future.
if (!window.mindmapLoadReady) {
2012-11-06 01:55:19 +01:00
$notifyModal($msg('UNEXPECTED_ERROR_LOADING'));
}
2012-03-08 04:11:54 +01:00
};
2014-03-05 00:47:23 +01:00
// @Todo: Remove this after all is fixed.
// window.onerror = onerrorFn;
2012-02-21 19:37:15 +01:00
// Configure default persistence manager ...
var persistence;
if (options.persistenceManager) {
if (options.persistenceManager instanceof String) {
persistence = eval("new " + options.persistenceManager + "()");
2012-02-21 19:37:15 +01:00
}
else {
persistence = options.persistenceManager;
2012-02-21 19:37:15 +01:00
}
} else {
2013-02-03 17:47:31 +01:00
persistence = new mindplot.LocalStorageManager("samples/{id}.xml");
2012-02-21 19:37:15 +01:00
}
mindplot.PersistenceManager.init(persistence);
// Register toolbar event ...
if ($('#toolbar')) {
var menu = new mindplot.widget.Menu(designer, 'toolbar', options.mapId, "");
2012-02-21 19:37:15 +01:00
// If a node has focus, focus can be move to another node using the keys.
2012-07-01 22:21:02 +02:00
designer._cleanScreen = function () {
2012-02-21 19:37:15 +01:00
menu.clear()
};
}
return designer;
}
function loadDesignerOptions(jsonConf) {
// Load map options ...
var result;
2012-02-21 19:37:15 +01:00
if (jsonConf) {
var request = new Request.JSON({
2012-07-01 22:21:02 +02:00
url:jsonConf,
2012-02-21 19:37:15 +01:00
async:false,
2012-07-01 22:21:02 +02:00
onSuccess:function (options) {
this.options = options;
2012-02-21 19:37:15 +01:00
2012-07-01 22:21:02 +02:00
}.bind(this)
2012-02-21 19:37:15 +01:00
}
);
request.get();
result = this.options;
}
else {
// Set workspace screen size as default. In this way, resize issues are solved.
var containerSize = {
2012-07-01 22:21:02 +02:00
height:parseInt(screen.height),
width:parseInt(screen.width)
2012-02-21 19:37:15 +01:00
};
var viewPort = {
2012-07-01 22:21:02 +02:00
height:parseInt(window.innerHeight - 70), // Footer and Header
width:parseInt(window.innerWidth)
2012-02-21 19:37:15 +01:00
};
result = {readOnly:false, zoom:0.85, saveOnLoad:true, size:containerSize, viewPort:viewPort, container:'mindplot', locale:'en'};
2012-02-21 19:37:15 +01:00
}
return result;
}
editor = {};
2014-03-09 09:42:44 +01:00
editor.WaitDialog = new Class({
initialize:function () {
this.panel = this._buildPanel();
},
_buildPanel:function () {
var result = $('#load');
var content = result.find('.modal-content');
var winH = $(window).height();
2014-03-09 09:42:44 +01:00
//Set the popup window to center
content.css('margin-top', winH/2 - content.height()/2);
2014-03-09 09:42:44 +01:00
return result;
},
show:function () {
2014-03-15 07:55:57 +01:00
this.panel.modal('show');
2014-03-09 09:42:44 +01:00
},
close: function() {
2014-03-15 07:55:57 +01:00
this.panel.modal('hide');
2014-03-09 09:42:44 +01:00
}
});
2012-02-21 19:37:15 +01:00
// Show loading dialog ...
2014-03-09 09:42:44 +01:00
waitDialog = new editor.WaitDialog();
waitDialog.show();
2012-02-21 19:37:15 +01:00
// Loading libraries ...
2014-03-05 02:48:31 +01:00
jQuery.getScript("js/mindplot-min.js");