2014-05-04 17:26:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
(function() {
|
2016-02-23 08:15:37 +00:00
|
|
|
window.onerror = function(error, url, line, column, errorObj) {
|
|
|
|
if (error == 'TypeError: Attempted to assign to readonly property.') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
var stack = (errorObj && errorObj.stack) || "(no stack trace available)";
|
|
|
|
|
|
|
|
!/^resource:/.test(url) && oml.api.logError({
|
|
|
|
text: error + "\n\n" + stack,
|
|
|
|
url: document.location.pathname + ' at ' + url,
|
|
|
|
line: line
|
|
|
|
});
|
|
|
|
} catch(e) {}
|
|
|
|
};
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
var animationInterval,
|
|
|
|
enableDebugMode = getLocalStorage('oml.enableDebugMode'),
|
|
|
|
omlVersion = getOMLVersion(),
|
2014-09-29 13:17:59 +00:00
|
|
|
oxjsPath = '/static/oxjs/' + (enableDebugMode ? 'dev' : 'min'),
|
2014-05-04 17:26:43 +00:00
|
|
|
terminal,
|
|
|
|
theme = getLocalStorage('Ox.theme')
|
|
|
|
&& JSON.parse(localStorage['Ox.theme'])
|
|
|
|
|| 'oxlight';
|
|
|
|
|
|
|
|
loadImages(function(images) {
|
|
|
|
loadScreen(images);
|
|
|
|
loadOxJS(loadOML);
|
|
|
|
});
|
|
|
|
|
|
|
|
function getLocalStorage(key) {
|
|
|
|
try {
|
|
|
|
return localStorage[key];
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOMLVersion() {
|
|
|
|
var i, path, scripts = document.getElementsByTagName('script');
|
|
|
|
for (i = 0; i < scripts.length; i++) {
|
|
|
|
if(/oml.js/.test(scripts[i].src)) {
|
|
|
|
return scripts[i].src.replace(/.*\?/, '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initOML(data) {
|
|
|
|
Ox.extend(oml, {
|
|
|
|
$ui: {},
|
|
|
|
config: data.config,
|
2016-01-10 13:53:29 +00:00
|
|
|
user: data.user,
|
2019-01-17 10:30:22 +00:00
|
|
|
readOnly: data.readOnly,
|
2016-01-10 13:53:29 +00:00
|
|
|
version: data.version
|
2014-05-04 17:26:43 +00:00
|
|
|
});
|
2019-01-17 10:30:22 +00:00
|
|
|
if (oml.readOnly) {
|
|
|
|
oml.user.ui = oml.localStorage('ui') || oml.user.ui;
|
|
|
|
}
|
2014-05-17 08:17:34 +00:00
|
|
|
['preferences', 'ui'].forEach(function(key) {
|
|
|
|
// make sure all valid settings are present
|
|
|
|
oml.user[key] = Ox.extend(
|
|
|
|
Ox.clone(data.config.user[key], true),
|
|
|
|
oml.user[key]
|
|
|
|
);
|
|
|
|
// make sure no invalid settings are present
|
|
|
|
Object.keys(oml.user[key]).forEach(function(key_) {
|
|
|
|
if (Ox.isUndefined(oml.config.user[key][key_])) {
|
|
|
|
delete oml.user[key][key_];
|
|
|
|
}
|
|
|
|
});
|
2014-05-04 17:26:43 +00:00
|
|
|
});
|
|
|
|
// TODO: make sure listView, listSort and itemView are valid
|
|
|
|
Ox.extend(oml.config, {
|
|
|
|
filters: oml.config.itemKeys.filter(function(key) {
|
|
|
|
return key.filter;
|
|
|
|
}).map(function(key) {
|
|
|
|
return {
|
|
|
|
id: key.id,
|
2016-01-13 10:25:47 +00:00
|
|
|
sort: [{
|
|
|
|
key: key.id == 'date' ? 'name' : 'items',
|
|
|
|
operator: '-'
|
|
|
|
}],
|
2014-05-04 17:26:43 +00:00
|
|
|
title: key.title,
|
|
|
|
type: Ox.isArray(key.type) ? key.type[0] : key.type
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
findKeys: oml.config.itemKeys.filter(function(key) {
|
|
|
|
return key.find;
|
|
|
|
}),
|
|
|
|
sortKeys: oml.config.itemKeys.filter(function(key) {
|
|
|
|
return key.sort && key.columnWidth;
|
|
|
|
}).map(function(key) {
|
|
|
|
return Ox.extend({
|
|
|
|
operator: oml.getSortOperator(key.id)
|
|
|
|
}, key, {
|
|
|
|
format: function(value) {
|
|
|
|
return key.format
|
|
|
|
? Ox['format' + Ox.toTitleCase(key.format.type)].apply(
|
|
|
|
this, [value].concat(key.format.args || [])
|
|
|
|
)
|
2014-05-14 18:46:31 +00:00
|
|
|
: Ox.isArray(key.type) ? (value || []).join(', ')
|
|
|
|
: (value || '');
|
2014-05-04 17:26:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
oml.config.listSettings = {};
|
|
|
|
Ox.forEach(oml.config.user.ui, function(value, key) {
|
|
|
|
if (/^list[A-Z]/.test(key)) {
|
|
|
|
oml.config.listSettings[key] = key[4].toLowerCase() + key.slice(5);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
oml.URL.init().parse(function() {
|
|
|
|
oml.clipboard = Ox.Clipboard();
|
|
|
|
oml.history = Ox.History();
|
2014-05-19 15:00:33 +00:00
|
|
|
Ox.$window.on({
|
|
|
|
resize: oml.resizeWindow
|
|
|
|
});
|
2015-06-06 17:54:44 +00:00
|
|
|
Ox.$document.on({
|
|
|
|
dragenter: function(event) {
|
2019-01-24 08:26:59 +00:00
|
|
|
if (Ox.contains(event.originalEvent.dataTransfer.types, 'Files')) {
|
|
|
|
event.originalEvent.preventDefault();
|
|
|
|
event.originalEvent.stopPropagation();
|
|
|
|
if (!$('#importScreen').length && !$('#closedScreen').length) {
|
|
|
|
oml.ui.importScreen().appendTo(Ox.$body);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log(event.originalEvent.dataTransfer);
|
2016-01-12 07:39:40 +00:00
|
|
|
}
|
2015-06-06 17:54:44 +00:00
|
|
|
},
|
|
|
|
dragover: function(event) {
|
2016-01-12 07:39:40 +00:00
|
|
|
event.originalEvent.preventDefault();
|
|
|
|
event.originalEvent.stopPropagation();
|
2015-06-06 17:54:44 +00:00
|
|
|
},
|
2016-01-12 07:57:09 +00:00
|
|
|
dragstart: function(event) {
|
|
|
|
event.originalEvent.preventDefault();
|
|
|
|
event.originalEvent.stopPropagation();
|
|
|
|
},
|
2015-06-06 17:54:44 +00:00
|
|
|
drop: function(event) {
|
2016-01-12 07:39:40 +00:00
|
|
|
$('#importScreen').remove();
|
2016-01-13 16:17:32 +00:00
|
|
|
if (event.originalEvent.dataTransfer.files.length) {
|
2016-01-12 07:39:40 +00:00
|
|
|
event.originalEvent.preventDefault();
|
|
|
|
event.originalEvent.stopPropagation();
|
2015-06-06 17:54:44 +00:00
|
|
|
oml.upload(event.originalEvent.dataTransfer.files, function(response) {
|
|
|
|
setTimeout(function() {
|
2016-01-12 08:52:20 +00:00
|
|
|
oml.reloadLists();
|
2015-06-06 17:54:44 +00:00
|
|
|
oml.UI.set({listSelection: response.data.ids});
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-05-04 17:26:43 +00:00
|
|
|
oml.$ui.appPanel = oml.ui.appPanel().appendTo(Ox.$body);
|
2014-05-17 11:45:57 +00:00
|
|
|
oml.$ui.loadingIcon.updateElement(Ox.Request.requests());
|
2014-05-04 17:26:43 +00:00
|
|
|
Ox.Request.bindEvent({
|
|
|
|
error: function(data) {
|
2014-05-17 11:45:57 +00:00
|
|
|
oml.$ui.errorDialog = oml.ui.errorDialog().updateElement(data).open();
|
2014-05-04 17:26:43 +00:00
|
|
|
},
|
|
|
|
request: function(data) {
|
2014-05-17 11:45:57 +00:00
|
|
|
oml.$ui.loadingIcon.updateElement(data.requests);
|
2014-05-04 17:26:43 +00:00
|
|
|
}
|
|
|
|
});
|
2014-05-19 15:00:33 +00:00
|
|
|
if (oml.user.preferences.extensions) {
|
2014-05-04 17:26:43 +00:00
|
|
|
try {
|
|
|
|
eval(oml.user.preferences.extensions)
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
|
|
|
removeScreen();
|
2016-01-08 04:32:24 +00:00
|
|
|
oml.bindEvent({
|
|
|
|
close: function() {
|
2016-01-12 07:39:40 +00:00
|
|
|
if (!$('#closedScreen').length) {
|
|
|
|
oml.ui.closedScreen().appendTo(Ox.$body);
|
2016-01-08 04:32:24 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
open: function() {
|
2016-01-12 07:39:40 +00:00
|
|
|
$('#closedScreen').remove();
|
2016-01-08 04:32:24 +00:00
|
|
|
}
|
|
|
|
});
|
2014-05-04 17:26:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadImages(callback) {
|
|
|
|
var images = {};
|
|
|
|
images.logo = document.createElement('img');
|
|
|
|
images.logo.onload = function() {
|
|
|
|
images.logo.style.position = 'absolute';
|
|
|
|
images.logo.style.left = 0;
|
|
|
|
images.logo.style.top = 0;
|
|
|
|
images.logo.style.right = 0;
|
|
|
|
images.logo.style.bottom = '96px';
|
|
|
|
images.logo.style.width = '256px';
|
|
|
|
images.logo.style.height = '256px';
|
|
|
|
images.logo.style.margin = 'auto';
|
|
|
|
images.logo.style.MozUserSelect = 'none';
|
|
|
|
images.logo.style.MSUserSelect = 'none';
|
|
|
|
images.logo.style.OUserSelect = 'none';
|
|
|
|
images.logo.style.WebkitUserSelect = 'none';
|
|
|
|
images.loadingIcon = document.createElement('img');
|
|
|
|
images.loadingIcon.setAttribute('id', 'loadingIcon');
|
|
|
|
images.loadingIcon.style.position = 'absolute';
|
2016-01-08 03:33:34 +00:00
|
|
|
images.loadingIcon.style.left = '16px';
|
2014-05-04 17:26:43 +00:00
|
|
|
images.loadingIcon.style.top = '256px'
|
|
|
|
images.loadingIcon.style.right = 0;
|
|
|
|
images.loadingIcon.style.bottom = 0;
|
|
|
|
images.loadingIcon.style.width = '32px';
|
|
|
|
images.loadingIcon.style.height = '32px';
|
|
|
|
images.loadingIcon.style.margin = 'auto';
|
|
|
|
images.loadingIcon.style.MozUserSelect = 'none';
|
|
|
|
images.loadingIcon.style.MSUserSelect = 'none';
|
|
|
|
images.loadingIcon.style.OUserSelect = 'none';
|
|
|
|
images.loadingIcon.style.WebkitUserSelect = 'none';
|
|
|
|
images.loadingIcon.src = oxjsPath
|
2014-09-29 13:17:59 +00:00
|
|
|
+ '/UI/themes/' + theme + '/svg/symbolLoading.svg';
|
2014-05-04 17:26:43 +00:00
|
|
|
callback(images);
|
|
|
|
};
|
|
|
|
images.logo.src = '/static/png/oml.png';
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadOML(browserSupported) {
|
|
|
|
window.oml = Ox.App({
|
|
|
|
name: 'oml',
|
|
|
|
socket: 'ws://' + document.location.host + '/ws',
|
|
|
|
url: '/api/'
|
|
|
|
}).bindEvent({
|
|
|
|
load: function(data) {
|
|
|
|
data.browserSupported = browserSupported;
|
|
|
|
oml.ui = {};
|
|
|
|
loadOMLFiles(function() {
|
2019-01-31 07:07:49 +00:00
|
|
|
Ox.getFile('/static/css/oml.css', function() {
|
|
|
|
initOML(data);
|
|
|
|
})
|
2014-05-04 17:26:43 +00:00
|
|
|
});
|
2016-04-14 19:27:30 +00:00
|
|
|
},
|
|
|
|
updatestatus: function(data) {
|
|
|
|
document.location.href = document.location.protocol + '//'
|
|
|
|
+ document.location.host;
|
2014-05-04 17:26:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadOMLFiles(callback) {
|
|
|
|
var path = '/static/';
|
|
|
|
if (enableDebugMode) {
|
|
|
|
Ox.getJSON(path + 'json/js.json?' + Ox.random(1000000), function(files) {
|
|
|
|
Ox.getFile(files.map(function(file) {
|
|
|
|
return path + 'js/' + file + '?' + omlVersion;
|
|
|
|
}), callback);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Ox.getScript(path + 'js/oml.min.js?' + omlVersion, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadOxJS(callback) {
|
|
|
|
var head = document.head
|
|
|
|
|| document.getElementsByTagName('head')[0]
|
|
|
|
|| document.documentElement,
|
|
|
|
script = document.createElement('script');
|
|
|
|
script.onload = function() {
|
2014-05-21 00:02:39 +00:00
|
|
|
Ox.load({UI: {theme: theme}}, function() {
|
2016-01-19 11:10:58 +00:00
|
|
|
Ox.formatBoolean = function(value) {
|
|
|
|
return value ? 'yes' : 'no';
|
|
|
|
};
|
2014-05-21 00:02:39 +00:00
|
|
|
Ox.formatUpper = function(string) {
|
|
|
|
return string.toUpperCase();
|
|
|
|
};
|
|
|
|
callback();
|
|
|
|
});
|
2014-05-04 17:26:43 +00:00
|
|
|
};
|
|
|
|
script.src = oxjsPath + '/Ox.js?' + omlVersion;
|
|
|
|
script.type = 'text/javascript';
|
|
|
|
head.appendChild(script);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadScreen(images) {
|
|
|
|
var loadingScreen = document.createElement('div');
|
|
|
|
loadingScreen.setAttribute('id', 'loadingScreen');
|
|
|
|
loadingScreen.className = 'OxScreen';
|
|
|
|
loadingScreen.style.position = 'absolute';
|
|
|
|
loadingScreen.style.width = '100%';
|
|
|
|
loadingScreen.style.height = '100%';
|
|
|
|
loadingScreen.style.backgroundColor = theme == 'oxlight' ? 'rgb(224, 224, 224)'
|
|
|
|
: theme == 'oxmedium' ? 'rgb(144, 144, 144)' : 'rgb(32, 32, 32)';
|
|
|
|
loadingScreen.style.zIndex = '1002';
|
|
|
|
loadingScreen.appendChild(images.logo);
|
|
|
|
loadingScreen.appendChild(images.loadingIcon);
|
|
|
|
// FF3.6 document.body can be undefined here
|
|
|
|
window.onload = function() {
|
|
|
|
document.body.style.margin = 0;
|
2019-01-31 11:22:27 +00:00
|
|
|
if (!animationInterval) {
|
|
|
|
document.body.appendChild(loadingScreen);
|
|
|
|
startAnimation();
|
|
|
|
}
|
2014-05-04 17:26:43 +00:00
|
|
|
};
|
|
|
|
// IE8 does not call onload if already loaded before set
|
|
|
|
document.body && window.onload();
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadTerminal() {
|
|
|
|
terminal = document.createElement('div');
|
|
|
|
terminal.style.display = 'none';
|
|
|
|
terminal.style.position = 'absolute';
|
|
|
|
terminal.style.width = '100%';
|
|
|
|
terminal.style.height = '100%';
|
|
|
|
terminal.style.zIndex = '1003';
|
|
|
|
}
|
|
|
|
|
|
|
|
function log(message) {
|
|
|
|
var line = document.createElement('div');
|
|
|
|
line.innerHTML = message;
|
|
|
|
terminal.appendChild(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeScreen() {
|
|
|
|
var $loadingScreen = $('#loadingScreen');
|
|
|
|
$loadingScreen.animate({
|
|
|
|
opacity: 0
|
|
|
|
}, 1000, function() {
|
|
|
|
$loadingScreen.remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function startAnimation() {
|
|
|
|
var css, deg = 0, loadingIcon = document.getElementById('loadingIcon'),
|
|
|
|
previousTime = +new Date();
|
|
|
|
animationInterval = setInterval(function() {
|
|
|
|
var currentTime = +new Date(),
|
|
|
|
delta = (currentTime - previousTime) / 1000;
|
|
|
|
previousTime = currentTime;
|
|
|
|
deg = Math.round((deg + delta * 360) % 360 / 30) * 30;
|
|
|
|
css = 'rotate(' + deg + 'deg)';
|
|
|
|
loadingIcon.style.MozTransform = css;
|
|
|
|
loadingIcon.style.MSTransform = css;
|
|
|
|
loadingIcon.style.OTransform = css;
|
|
|
|
loadingIcon.style.WebkitTransform = css;
|
|
|
|
loadingIcon.style.transform = css;
|
|
|
|
}, 83);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopAnimation() {
|
|
|
|
clearInterval(animationInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
}());
|