pandora_amp/static/js/importDocumentsDialog.amp.js

94 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-11-05 19:45:42 +00:00
'use strict';
pandora.ui.importDocumentsDialog = function() {
2018-11-05 20:27:03 +00:00
var dialogHeight = 128 + 16,
2018-11-05 19:45:42 +00:00
dialogWidth = 512 + 16,
formWidth = getFormWidth(),
$button,
$content = Ox.Element(),
value,
$input = [
2018-11-05 20:27:03 +00:00
Ox.Input({
type: 'textarea',
height: 128,
2018-11-05 19:45:42 +00:00
width: 512
}).css({
margin: '8px'
}).bindEvent({
change: function(data) {
$button.options({disabled: !data.value});
value = data.value
}
}).appendTo($content),
],
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'cancel',
title: Ox._('Cancel')
})
.bindEvent({
click: function() {
that.close();
}
}),
$button = Ox.Button({
2018-11-05 20:27:03 +00:00
disabled: false,
2018-11-05 19:45:42 +00:00
id: 'import',
title: Ox._('Import URLs')
})
.bindEvent({
click: importDocuments
})
],
closeButton: true,
content: $content,
height: dialogHeight,
removeOnClose: true,
title: Ox._('Import Documents'),
width: dialogWidth
})
.bindEvent({
resize: setSize
});
function getFormWidth() {
return dialogWidth - 32 - Ox.UI.SCROLLBAR_SIZE;
}
function setSize(data) {
dialogHeight = data.height;
dialogWidth = data.width;
formWidth = getFormWidth();
$input.forEach(function($element) {
$element.options({width: formWidth});
});
}
function importDocuments() {
that.options({content: Ox.LoadingScreen().start()});
var urls = value.trim().split('\n');
pandora.api.importDocuments({
urls: urls
}, function(result) {
2018-11-05 20:27:03 +00:00
Ox.Request.clearCache()
2018-11-05 19:45:42 +00:00
if (result.data.taskId) {
pandora.wait(result.data.taskId, function(result) {
that.close();
2018-11-05 20:27:03 +00:00
if (pandora.user.ui.section == 'documents' && !pandora.user.ui.document.length) {
pandora.$ui.list.reloadList()
} else {
pandora.URL.push('/documents/grid/created')
}
})
2018-11-05 19:45:42 +00:00
} else {
that.options({content: 'Failed'});
}
})
}
return that;
};