UNPKG

bitfront-library

Version:

Angular CLI project with components and classes used by other Angular projects of the BIT foundation.

172 lines 10.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BitUploadComponent = void 0; var core_1 = require("@angular/core"); var i0 = require("@angular/core"); var i1 = require("@angular/common"); var i2 = require("../directive/focus-register.directive"); var _c0 = ["inputFile"]; function BitUploadComponent_div_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "div", 7); i0.ɵɵelementStart(1, "label", 8); i0.ɵɵtext(2); i0.ɵɵelement(3, "i", 9); i0.ɵɵelementEnd(); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r0 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵpropertyInterpolate("for", ctx_r0.id); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate1(" ", ctx_r0.getSearchLabel(), "\u00A0\u00A0"); } } function BitUploadComponent_button_2_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "button", 10); i0.ɵɵtext(1, " Carrega\u00A0\u00A0"); i0.ɵɵelement(2, "span", 11); i0.ɵɵelementEnd(); } } function BitUploadComponent_img_3_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelement(0, "img", 12); } } function BitUploadComponent_div_6_div_1_div_1_Template(rf, ctx) { if (rf & 1) { var _r10 = i0.ɵɵgetCurrentView(); i0.ɵɵelementStart(0, "div", 17); i0.ɵɵelementStart(1, "div", 18); i0.ɵɵtext(2); i0.ɵɵelementEnd(); i0.ɵɵelementStart(3, "div", 19); i0.ɵɵtext(4); i0.ɵɵelementEnd(); i0.ɵɵelementStart(5, "div", 20); i0.ɵɵelementStart(6, "button", 21); i0.ɵɵlistener("click", function BitUploadComponent_div_6_div_1_div_1_Template_button_click_6_listener() { i0.ɵɵrestoreView(_r10); var i_r8 = ctx.index; var ctx_r9 = i0.ɵɵnextContext(3); return ctx_r9.removeFile(i_r8); }); i0.ɵɵelement(7, "span", 22); i0.ɵɵelementEnd(); i0.ɵɵelementEnd(); i0.ɵɵelementEnd(); } if (rf & 2) { var file_r7 = ctx.$implicit; i0.ɵɵadvance(2); i0.ɵɵtextInterpolate(file_r7.name); i0.ɵɵadvance(2); i0.ɵɵtextInterpolate1("", file_r7.size, " bytes"); } } function BitUploadComponent_div_6_div_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "div", 15); i0.ɵɵtemplate(1, BitUploadComponent_div_6_div_1_div_1_Template, 8, 2, "div", 16); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r5 = i0.ɵɵnextContext(2); i0.ɵɵadvance(1); i0.ɵɵproperty("ngForOf", ctx_r5.filesToUpload); } } function BitUploadComponent_div_6_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "div", 13); i0.ɵɵtemplate(1, BitUploadComponent_div_6_div_1_Template, 2, 1, "div", 14); i0.ɵɵelementEnd(); } if (rf & 2) { var ctx_r4 = i0.ɵɵnextContext(); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx_r4.showFiles && ctx_r4.filesToUpload != null); } } var BitUploadComponent = /** @class */ (function () { function BitUploadComponent() { this.id = "file"; this.multiple = false; this.onFileChange = new core_1.EventEmitter(); this.filesToUpload = []; } BitUploadComponent.prototype.ngAfterContentInit = function () { var _this = this; this.resetEmitter && this.resetEmitter.subscribe(function (x) { _this.filesToUpload = []; _this.inputFile.nativeElement.value = ""; //esto lo hacemos para que se dispare el evento (change) si seleccionan un fichero ya seleccionado _this.onFileChange.emit(_this.filesToUpload); }); }; /** Se dispara cada vez que el usuario selecciona uno o varios ficheros */ BitUploadComponent.prototype.fileChangeEvent = function (fileInput) { var temp = fileInput.target.files; //ficheros seleccionados for (var i = 0; i < temp.length; i++) { //añadimos los nuevos ficheros seleccionados a la lista this.filesToUpload.push(temp[i]); } this.onFileChange.emit(this.filesToUpload); //comunicamos hacia arriba los ficheros seleccionados }; /** Se dispara cuando el usuario elimina un fichero de la lista */ BitUploadComponent.prototype.removeFile = function (pos) { this.filesToUpload.splice(pos, 1); this.inputFile.nativeElement.value = ""; //esto lo hacemos para que se dispare el evento (change) si seleccionan un fichero ya seleccionado this.onFileChange.emit(this.filesToUpload); }; BitUploadComponent.prototype.getSearchLabel = function () { if (this.searchLabel) { return this.searchLabel; } else { return "Cerca " + (this.multiple ? "fitxer/s" : "fitxer") + " al disc dur"; } }; BitUploadComponent.ɵfac = function BitUploadComponent_Factory(t) { return new (t || BitUploadComponent)(); }; BitUploadComponent.ɵcmp = i0.ɵɵdefineComponent({ type: BitUploadComponent, selectors: [["bit-upload"]], viewQuery: function BitUploadComponent_Query(rf, ctx) { if (rf & 1) { i0.ɵɵviewQuery(_c0, 1); } if (rf & 2) { var _t = void 0; i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.inputFile = _t.first); } }, inputs: { simple: "simple", showFiles: "showFiles", id: "id", multiple: "multiple", resetEmitter: ["reset", "resetEmitter"], searchLabel: "searchLabel", uploading: "uploading" }, outputs: { onFileChange: "onFileChange" }, decls: 7, vars: 7, consts: [[1, "row", "separador"], ["class", "col-sm-12", 4, "ngIf"], ["type", "submit", "class", "btn btn-default btn-upload-simple", 4, "ngIf"], ["width", "40", "height", "40", "src", "assets/images/load.gif", 4, "ngIf"], ["type", "file", 3, "id", "name", "multiple", "change"], ["inputFile", ""], ["class", "doclist-upload doclist-upload-simple", 4, "ngIf"], [1, "col-sm-12"], [1, "btn", "btn-upload", "btn-upload-simple", 3, "for"], [1, "fa", "fa-cloud-upload"], ["type", "submit", 1, "btn", "btn-default", "btn-upload-simple"], [1, "glyphicon", "glyphicon-cloud-upload"], ["width", "40", "height", "40", "src", "assets/images/load.gif"], [1, "doclist-upload", "doclist-upload-simple"], ["class", "simple", 4, "ngIf"], [1, "simple"], ["class", "row row-upload", 4, "ngFor", "ngForOf"], [1, "row", "row-upload"], [1, "col-sm-7"], [1, "col-xs-3"], [1, "col-sm-2"], [1, "btn", "btn-default", "btn-upload-simple", 3, "click"], [1, "fa", "fa-close"]], template: function BitUploadComponent_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "div", 0); i0.ɵɵtemplate(1, BitUploadComponent_div_1_Template, 4, 2, "div", 1); i0.ɵɵtemplate(2, BitUploadComponent_button_2_Template, 3, 0, "button", 2); i0.ɵɵtemplate(3, BitUploadComponent_img_3_Template, 1, 0, "img", 3); i0.ɵɵelementStart(4, "input", 4, 5); i0.ɵɵlistener("change", function BitUploadComponent_Template_input_change_4_listener($event) { return ctx.fileChangeEvent($event); }); i0.ɵɵelementEnd(); i0.ɵɵtemplate(6, BitUploadComponent_div_6_Template, 2, 1, "div", 6); i0.ɵɵelementEnd(); } if (rf & 2) { i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx.multiple || ctx.filesToUpload.length == 0); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", !ctx.uploading && ctx.filesToUpload.length != 0); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx.uploading); i0.ɵɵadvance(1); i0.ɵɵpropertyInterpolate("id", ctx.id); i0.ɵɵpropertyInterpolate("name", ctx.id); i0.ɵɵpropertyInterpolate("multiple", ctx.multiple ? "multiple" : null); i0.ɵɵadvance(2); i0.ɵɵproperty("ngIf", ctx.filesToUpload.length != 0); } }, directives: [i1.NgIf, i2.FocusRegisterDirective, i1.NgForOf], encapsulation: 2 }); return BitUploadComponent; }()); exports.BitUploadComponent = BitUploadComponent; (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BitUploadComponent, [{ type: core_1.Component, args: [{ selector: "bit-upload", template: "\n <div class=\"row separador\">\n <!-- *ngIf=\"simple\" -->\n <div class=\"col-sm-12\" *ngIf=\"multiple || filesToUpload.length == 0\">\n <label for=\"{{ id }}\" class=\"btn btn-upload btn-upload-simple\">\n {{ getSearchLabel() }}&nbsp;&nbsp;<i class=\"fa fa-cloud-upload\"></i>\n </label>\n </div>\n <button type=\"submit\" *ngIf=\"!uploading && filesToUpload.length != 0\" class=\"btn btn-default btn-upload-simple\">\n Carrega&nbsp;&nbsp;<span class=\"glyphicon glyphicon-cloud-upload\"></span>\n </button>\n <img *ngIf=\"uploading\" width=\"40\" height=\"40\" src=\"assets/images/load.gif\" />\n <input\n #inputFile\n type=\"file\"\n id=\"{{ id }}\"\n name=\"{{ id }}\"\n multiple=\"{{ multiple ? 'multiple' : null }}\"\n (change)=\"fileChangeEvent($event)\"\n />\n <div class=\"doclist-upload doclist-upload-simple\" *ngIf=\"filesToUpload.length != 0\">\n <div *ngIf=\"showFiles && filesToUpload != null\" class=\"simple\">\n <div class=\"row row-upload\" *ngFor=\"let file of filesToUpload; let i = index\">\n <div class=\"col-sm-7\">{{ file.name }}</div>\n <div class=\"col-xs-3\">{{ file.size }} bytes</div>\n <div class=\"col-sm-2\">\n <button (click)=\"removeFile(i)\" class=\"btn btn-default btn-upload-simple\">\n <span class=\"fa fa-close\"></span>\n </button>\n </div>\n </div>\n </div>\n </div>\n </div>\n " }] }], function () { return []; }, { simple: [{ type: core_1.Input }], showFiles: [{ type: core_1.Input }], id: [{ type: core_1.Input }], multiple: [{ type: core_1.Input }], resetEmitter: [{ type: core_1.Input, args: ["reset"] }], searchLabel: [{ type: core_1.Input }], uploading: [{ type: core_1.Input }], inputFile: [{ type: core_1.ViewChild, args: ["inputFile"] }], onFileChange: [{ type: core_1.Output }] }); })(); //# sourceMappingURL=bit-upload.component.js.map