this.show_hidden = false;
this.enable_upload = true;
this.enable_remove = true;
+ this.enable_download = false;
this.root_directory = '/etc/luci-uploads';
},
* @default true
*/
+ /**
+ * Toggle download file functionality.
+ *
+ * @name LuCI.form.FileUpload.prototype#enable_download
+ * @type boolean
+ * @default false
+ */
+
/**
* Specify the root directory for file browsing.
*
show_hidden: this.show_hidden,
enable_upload: this.enable_upload,
enable_remove: this.enable_remove,
+ enable_download: this.enable_download,
root_directory: this.root_directory,
disabled: (this.readonly != null) ? this.readonly : this.map.readonly
});
* remotely depends on the ACL setup for the current session. This option
* merely controls whether the file remove controls are rendered or not.
*
+ * @property {boolean} [enable_download=false]
+ * Specifies whether the widget allows the user to download files.
+ *
* @property {string} [root_directory=/etc/luci-uploads]
* Specifies the remote directory the upload and file browsing actions take
* place in. Browsing to directories outside the root directory is
show_hidden: false,
enable_upload: true,
enable_remove: true,
+ enable_download: false,
root_directory: '/etc/luci-uploads'
}, options);
},
'class': 'btn',
'click': UI.prototype.createHandlerFn(this, 'handleReset')
}, [ _('Deselect') ]) : '',
+ this.options.enable_download && list[i].type == 'file' ? E('button', {
+ 'class': 'btn',
+ 'click': UI.prototype.createHandlerFn(this, 'handleDownload', entrypath, list[i])
+ }, [ _('Download') ]) : '',
this.options.enable_remove ? E('button', {
'class': 'btn cbi-button-negative',
'click': UI.prototype.createHandlerFn(this, 'handleDelete', entrypath, list[i])
this.handleCancel(ev);
},
+ /** @private */
+ handleDownload: function(path, fileStat, ev) {
+ fs.read_direct(path, 'blob').then(function (blob) {
+ var url = window.URL.createObjectURL(blob);
+ var a = document.createElement('a');
+ a.style.display = 'none';
+ a.href = url;
+ a.download = fileStat.name;
+ document.body.appendChild(a);
+ a.click();
+ window.URL.revokeObjectURL(url);
+ }).catch(function(err) {
+ alert(_('Download failed: %s').format(err.message));
+ });
+ },
+
/** @private */
handleSelect: function(path, fileStat, ev) {
var browser = dom.parent(ev.target, '.cbi-filebrowser'),