openmedialibrary/static/js/appPanel.js

82 lines
No EOL
2.5 KiB
JavaScript

'use strict';
oml.ui.appPanel = function() {
var ui = oml.user.ui,
that = Ox.SplitPanel({
elements: [
{
element: oml.$ui.mainMenu = oml.ui.mainMenu(),
size: 20
},
{
element: oml.$ui.mainPanel = oml.ui.mainPanel()
}
],
orientation: 'vertical'
})
.bindEvent({
oml_page: function(data) {
setPage(data.value, data.previousValue);
}
});
setPage(ui.page);
function setPage(page, previousPage) {
var dialogs = {
welcomeDialog: ['welcome'],
appDialog: ['about', 'faq', 'terms', 'development', 'contact'],
updateDialog: ['update'],
userDialog: ['preferences', 'peers', 'transfers'],
importExportDialog: ['import', 'export']
};
// close dialogs
if (Ox.every(dialogs, function(pages) {
return !Ox.contains(pages, page);
}) && Ox.some(dialogs, function(pages) {
return Ox.contains(pages, previousPage)
})) {
$('.OxDialog:visible').each(function() {
Ox.$elements[$(this).data('oxid')].close();
});
}
// open dialogs
Ox.forEach(dialogs, function(pages, dialog) {
if (Ox.contains(pages, page) && !Ox.contains(pages, previousPage)) {
$('.OxDialog:visible').each(function() {
Ox.$elements[$(this).data('oxid')].close();
});
oml.$ui[dialog] = oml.ui[dialog]().open();
}
});
}
oml.bindEvent({
transfer: Ox.throttle(function(data) {
oml.$ui.list.value(data.id, {
mediastate: data.progress < 1 ? 'transferring' : 'available'
});
oml.$ui.browser.value(data.id, {
mediastate: data.progress < 1 ? 'transferring' : 'available'
});
if (data.progress == 1 && data.id == ui.item) {
Ox.Request.clearCache();
oml.$ui.infoView.updateElement(ui.item);
}
})
});
that.reload = function() {
Ox.Request.cancel();
Ox.Request.clearCache();
oml.unbindEvent();
oml.$ui.appPanel.remove();
oml.$ui.appPanel = oml.ui.appPanel().appendTo(Ox.$body);
return that;
};
return that;
};