Permalink
Browse files

Updates download.

  • Loading branch information...
1 parent b8503b6 commit 580653a1adb0195a0d9149b688ace26803bfbbe4 @lrsjng committed Sep 5, 2013
Showing with 27 additions and 34 deletions.
  1. +16 −0 src/_h5ai/client/js/inc/core/server.js
  2. +10 −33 src/_h5ai/client/js/inc/ext/download.js
  3. +1 −1 src/_h5ai/conf/options.json
@@ -23,6 +23,22 @@ modulejs.define('core/server', ['$', '_', 'config', 'core/location'], function (
} else {
callback();
}
+ },
+
+ formRequest: function (data) {
+
+ var $form = $('<form method="post" style="display:none;"/>')
+ .attr('action', location.getAbsHref());
+
+ _.each(data, function (val, key) {
+
+ $('<input type="hidden"/>')
+ .attr('name', key)
+ .attr('value', val)
+ .appendTo($form);
+ });
+
+ $form.appendTo('body').submit().remove();
}
});
@@ -1,40 +1,27 @@
-modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/server', 'core/location'], function (_, $, allsettings, resource, event, server, location) {
+modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/location', 'core/server'], function (_, $, allsettings, resource, event, location, server) {
var settings = _.extend({
enabled: false,
type: 'php-tar',
packageName: 'package'
}, allsettings.download),
- // formats = ['tar', 'zip'],
-
downloadBtnTemplate = '<li id="download">' +
'<a href="#">' +
'<img src="' + resource.image('download') + '" alt="download"/>' +
'<span class="l10n-download"/>' +
'</a>' +
'</li>',
- selectedHrefsStr = '',
- $download, $img,
-
- failed = function () {
-
- $download.addClass('failed');
- setTimeout(function () {
- $download.removeClass('failed');
- }, 1000);
- },
+ selectedItems = [],
onSelection = function (items) {
- selectedHrefsStr = '';
- if (items.length) {
- selectedHrefsStr = _.map(items, function (item) {
+ var $download = $('#download');
- return item.absHref;
- }).join('|:|');
+ selectedItems = items.slice(0);
+ if (selectedItems.length) {
$download.appendTo('#navbar').show();
} else {
$download.hide();
@@ -49,31 +36,21 @@ modulejs.define('ext/download', ['_', '$', 'core/settings', 'core/resource', 'co
action: 'download',
as: (settings.packageName || location.getItem().label) + '.' + extension,
type: type,
- hrefs: selectedHrefsStr
- },
- $form = $('<form action="#" method="post" style="display:none;"/>');
-
- _.each(query, function (val, key) {
-
- $('<input type="hidden"/>')
- .attr('name', key)
- .attr('value', val)
- .appendTo($form);
- });
+ hrefs: _.pluck(selectedItems, 'absHref').join('|:|')
+ };
- $form.appendTo('body').submit().remove();
+ server.formRequest(query);
},
init = function () {
- if (!settings.enabled || !server.api) {
+ if (!settings.enabled) {
return;
}
- $download = $(downloadBtnTemplate)
+ $(downloadBtnTemplate)
.find('a').on('click', onClick).end()
.appendTo('#navbar');
- $img = $download.find('img');
event.sub('selection', onSelection);
};
@@ -92,7 +92,7 @@ Options
Allow file deletion.
*/
"delete": {
- "enabled": true
+ "enabled": false
},
/* [EXPERIMENTAL]

0 comments on commit 580653a

Please sign in to comment.