Updated: working version

This commit is contained in:
buchslava
2015-10-12 13:28:34 +03:00
parent b15fd587ae
commit 9edba490fc
10 changed files with 855 additions and 10 deletions

View File

@@ -1,21 +1,56 @@
/// <reference path="../../tsd.d.ts" />
import {
Component, View,
Component, View, OnInit, OnDestroy, OnChanges,
Directive, LifecycleEvent,
EventEmitter, ElementRef, Renderer,
CORE_DIRECTIVES, FORM_DIRECTIVES, NgClass
} from 'angular2/angular2';
import {FileUploader} from './file-uploader';
// todo: filters
@Directive({
selector: '[ng2-file-select]',
properties: ['config: ng2FileSelect']
properties: ['config: ng2FileSelect', 'uploader'],
host: {
'(change)': 'onChange()'
}
})
export class FileSelect {
public uploader:FileUploader;
public config:any = {};
constructor(private element:ElementRef, private renderer:Renderer) {
console.log('it works!');
constructor(private element:ElementRef) {
}
public getOptions() {
return this.uploader.options;
}
public getFilters() {
}
public isEmptyAfterSelection():boolean {
return !!this.element.nativeElement.attributes.multiple;
}
onChange() {
// let files = this.uploader.isHTML5 ? this.element.nativeElement[0].files : this.element.nativeElement[0];
let files = this.element.nativeElement.files;
let options = this.getOptions();
let filters = this.getFilters();
// if(!this.uploader.isHTML5) this.destroy();
this.uploader.addToQueue(files, options, filters);
if (this.isEmptyAfterSelection()) {
// todo
// this.element.nativeElement.properties.value = '';
/*this.element.nativeElement
.replaceWith(this.element = this.element.nativeElement.clone(true)); // IE fix*/
}
}
}