
scout.filechooser.FileChooser.js Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2014-2015 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
******************************************************************************/
scout.FileChooser = function() {
scout.FileChooser.parent.call(this);
this._files = [];
this._glassPaneRenderer;
};
scout.inherits(scout.FileChooser, scout.ModelAdapter);
scout.FileChooser.prototype._init = function(model) {
scout.FileChooser.parent.prototype._init.call(this, model);
this._glassPaneRenderer = new scout.GlassPaneRenderer(this.session, this, true);
};
/**
* @override ModelAdapter
*/
scout.FileChooser.prototype._initKeyStrokeContext = function(keyStrokeContext) {
scout.FileChooser.parent.prototype._initKeyStrokeContext.call(this, keyStrokeContext);
keyStrokeContext.registerKeyStroke([
new scout.FocusAdjacentElementKeyStroke(this.session, this),
new scout.ClickActiveElementKeyStroke(this, [
scout.keys.SPACE, scout.keys.ENTER
]),
new scout.CloseKeyStroke(this, function() {
return this.$cancelButton;
}.bind(this))
]);
};
scout.FileChooser.prototype._render = function($parent) {
// Render modality glasspanes (must precede adding the file chooser to the DOM)
this._glassPaneRenderer.renderGlassPanes();
this.$container = $parent.appendDiv('file-chooser');
var $handle = this.$container.appendDiv('drag-handle');
this.$container.makeDraggable($handle);
this.$container.appendDiv('closable')
.on('click', function() {
this._doCancel();
}.bind(this));
this.$content = this.$container.appendDiv('file-chooser-content');
this.$title = this.$content.appendDiv('file-chooser-title')
.text(this.session.text(this.multiSelect ? 'ui.ChooseFiles' : 'ui.ChooseFile'));
this.$fileInputField = $parent.makeElement('')
.attr('type', 'file')
.prop('multiple', this.multiSelect)
.attr('accept', this.acceptTypes)
.on('change', this._onFileChange.bind(this));
if (scout.device.supportsFile()) {
this.$fileInputField.appendTo(this.$container);
// Install DnD support
this.$container.on('dragenter', this._onDragEnterOrOver.bind(this))
.on('dragover', this._onDragEnterOrOver.bind(this))
.on('drop', this._onDrop.bind(this));
// explanation for file chooser
this.$content.appendDiv('file-chooser-label')
.text(this.session.text('ui.FileChooserHint'));
// List of files
this.$files = this.$content.appendElement('', 'file-chooser-files');
scout.scrollbars.install(this.$files, {
parent: this
});
} else {
// legacy iframe code
this.$legacyFormTarget = this.$fileInputField.appendElement('
© 2015 - 2025 Weber Informatics LLC | Privacy Policy