Replace file in queue when single select
I believe it wouldbe more clear when non-multiple selects would replace the file in queue.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { Directive, ElementRef, Input, HostListener } from '@angular/core';
|
import { Directive, ElementRef, Input, HostListener } from '@angular/core';
|
||||||
|
|
||||||
import { FileUploader } from './file-uploader.class';
|
import { FileUploader } from './file-uploader.class';
|
||||||
|
import { FileItem } from './file-item.class';
|
||||||
|
|
||||||
// todo: filters
|
// todo: filters
|
||||||
|
|
||||||
@@ -8,6 +9,8 @@ import { FileUploader } from './file-uploader.class';
|
|||||||
export class FileSelectDirective {
|
export class FileSelectDirective {
|
||||||
@Input() public uploader:FileUploader;
|
@Input() public uploader:FileUploader;
|
||||||
|
|
||||||
|
lastFile:FileItem;
|
||||||
|
|
||||||
protected element:ElementRef;
|
protected element:ElementRef;
|
||||||
|
|
||||||
public constructor(element:ElementRef) {
|
public constructor(element:ElementRef) {
|
||||||
@@ -22,7 +25,7 @@ export class FileSelectDirective {
|
|||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isEmptyAfterSelection():boolean {
|
public isMultiple():boolean {
|
||||||
return !!this.element.nativeElement.attributes.multiple;
|
return !!this.element.nativeElement.attributes.multiple;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +38,15 @@ export class FileSelectDirective {
|
|||||||
|
|
||||||
// if(!this.uploader.isHTML5) this.destroy();
|
// if(!this.uploader.isHTML5) this.destroy();
|
||||||
|
|
||||||
|
// if not multiple, remove previously added file so we can replace it with the new one
|
||||||
|
if(!this.isMultiple() && this.lastFile & !this.lastFile.uploaded) this.uploader.removeFromQueue(this.lastFile);
|
||||||
|
|
||||||
this.uploader.addToQueue(files, options, filters);
|
this.uploader.addToQueue(files, options, filters);
|
||||||
if (this.isEmptyAfterSelection()) {
|
|
||||||
|
// save file so we can remove it later
|
||||||
|
this.lastFile = this.uploader.queue[this.uploader.queue.length - 1];
|
||||||
|
|
||||||
|
if (this.isMultiple()) {
|
||||||
// todo
|
// todo
|
||||||
this.element.nativeElement.value = '';
|
this.element.nativeElement.value = '';
|
||||||
/*this.element.nativeElement
|
/*this.element.nativeElement
|
||||||
|
|||||||
Reference in New Issue
Block a user