pandora/static/js/uploadPDFDialog.js

93 lines
2.6 KiB
JavaScript
Raw Normal View History

2013-02-21 14:03:48 +00:00
'use strict';
pandora.ui.uploadPDFDialog = function(options) {
var cancelled = false,
file,
selectFile,
$cancelButton,
$closeButton,
$content = Ox.Element().css({margin: '16px'}),
$progress,
$status = $('<div>').css({padding: '4px', paddingTop: '8px'}),
that = Ox.Dialog({
buttons: [
$closeButton = Ox.Button({
id: 'close',
2013-05-09 10:13:58 +00:00
title: Ox._('Close')
2013-02-21 14:03:48 +00:00
}).bindEvent({
click: function() {
that.triggerEvent('close');
}
}),
$cancelButton = Ox.Button({
id: 'cancel',
2013-05-09 10:13:58 +00:00
title: Ox._('Cancel'),
2013-02-21 14:03:48 +00:00
disabled: true
}).bindEvent({
click: function(data) {
2013-03-24 09:41:27 +00:00
cancelled = true;
pandora.$ui.upload && pandora.$ui.upload.abort();
$fileButton.show();
$cancelButton.hide()
$closeButton.show();
2013-02-21 14:03:48 +00:00
}
}),
],
content: $content,
height: 128,
removeOnClose: true,
width: 368,
2013-05-09 10:13:58 +00:00
title: Ox._('Upload PDF'),
2013-02-21 14:03:48 +00:00
})
.bindEvent({
close: function(data) {
that.close();
}
});
$content.append($status);
upload(options.file);
function resetProgress() {
$progress = Ox.Progressbar({
progress: 0,
showPercent: true,
showTime: true,
width: 304
});
$status.html('').append($progress);
}
function upload(file) {
resetProgress();
pandora.$ui.upload = pandora.chunkupload({
file: file,
url: '/api/upload/text/',
data: {
name: file.name,
id: options.id
},
}).bindEvent({
progress: function(data) {
2013-03-24 09:41:27 +00:00
$progress.options({progress: data.progress || 0});
2013-02-21 14:03:48 +00:00
},
done: function(data) {
2013-03-24 09:41:27 +00:00
if (data.progress == 1) {
2013-02-21 14:03:48 +00:00
Ox.Request.clearCache();
2015-04-20 08:13:56 +00:00
pandora.$ui.mainPanel.replaceElement(
1, pandora.$ui.textPanel = pandora.ui.textPanel()
);
2013-02-21 14:03:48 +00:00
that.close();
} else {
$content.html("failed: " + data.responseText);
}
2013-03-24 09:41:27 +00:00
}
2013-02-21 14:03:48 +00:00
});
}
return that;
};