UNPKG

bitfront-library

Version:

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

194 lines 9.49 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseSublistComponent = void 0; var core_1 = require("@angular/core"); var store_1 = require("@ngrx/store"); var shared_1 = require("../../../shared"); var bit_toolbar_component_1 = require("../../../shared/component/bit-toolbar.component"); var fromModels = require("../../models"); var base_component_1 = require("./base.component"); var i0 = require("@angular/core"); var i1 = require("@ngrx/store"); var i2 = require("../../../shared"); var _c0 = ["tableview"]; /** * Componente que implementa un sub listado * T: entidad, * V: Definicion de la interface del state */ var BaseSublistComponent = /** @class */ (function (_super) { __extends(BaseSublistComponent, _super); function BaseSublistComponent(store, messageService, factoryCreateAction, fnCreateNewObject, fnCopyObject) { var _this = _super.call(this, store) || this; _this.store = store; _this.messageService = messageService; _this.factoryCreateAction = factoryCreateAction; _this.fnCreateNewObject = fnCreateNewObject; _this.fnCopyObject = fnCopyObject; _this.femenino = false; // si tenemos que mostrar los textos en femenino o no (p. ej., Nou vs Nova) _this.reloadFromServer = true; //indica si una vez añadido un elemento, llamaos al servidor para recargar la lista. Por defecto sí lo hace. _this.onChange = new core_1.EventEmitter(); return _this; } BaseSublistComponent.prototype.ngOnInit = function () { this.loadItems(); }; BaseSublistComponent.prototype.ngOnDestroy = function () { _super.prototype.ngOnDestroy.call(this); }; /** Controlamos si la propiedad initLoad cambia a true para cargar la lista de documentos */ BaseSublistComponent.prototype.ngOnChanges = function (changes) { // console.log('BaseSublist OnChanges', changes); for (var propName in changes) { if (propName === "forceReload") { this.forceReload && this.forceReload.subscribe(function (x) { this.loadItems(); }.bind(this)); } } }; /** Mostramos el inner form. */ BaseSublistComponent.prototype.gotoForm = function (data) { console.log("showForm called"); if (data) { this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.SHOW_ITEM_FOR_UPDATE, this.fnCopyObject(data))); } else { this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.SHOW_ITEM_FOR_INSERT, this.fnCreateNewObject(this.parent.id))); } }; /** metodos de BaseSubListComponent */ //Nos presionan algún botón del toolbar BaseSublistComponent.prototype.onToolbarButtonPressed = function (button) { console.log("Button pressed: " + button); if (button === bit_toolbar_component_1.BitToolbarComponent.NEW_BUTTON) { this.gotoForm(); } else if (button === bit_toolbar_component_1.BitToolbarComponent.DELETE_BUTTON) { var p = this.messageService.confirm("Està segur que vol eliminar els elements seleccionats? Aquesta acciò no es podrà desfer."); var local_1 = this; p.then(function (confirmacion) { if (confirmacion) { local_1.deleteItems(); } }); } else { this.otherAction(button); } }; /** Cualquier otra accion que no sea la típica de guardar o eliminar */ BaseSublistComponent.prototype.otherAction = function (action) { console.warn("otherAction " + action + " pressed"); }; BaseSublistComponent.prototype.deleteItem = function (id) { console.log("deleteItem called for id " + id); this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.DELETE_ITEMS, [id])); //this.onChange.emit(true); <----tenemos que emitir este valor cuando se haya eliminado el elemento }; /** Inserta o actualiza el documento */ BaseSublistComponent.prototype.saveItem = function (item) { console.log("saveItem called for item " + item); this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.SAVE_ITEM, item)); }; BaseSublistComponent.prototype.loadItems = function () { console.log("load items called for campanya id " + this.parent.id); this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.LOAD_ITEMS, this.parent)); }; /** nos piden cerrar el formulario */ BaseSublistComponent.prototype.closeForm = function (event) { this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.CLOSE_ITEM)); }; /** Nos checkean algún item del listado */ BaseSublistComponent.prototype.onItemChecked = function (selectedItems) { console.log("element selected"); this.store.dispatch(this.factoryCreateAction(fromModels.GENERIC_TYPE.ITEMS_SELECTED, selectedItems)); //TODO Implementado pero no verificado /* this.selectedItems = selectedItems; if (this.toolbar[BitToolbarComponent.DELETE_BUTTON]) { if (selectedItems !== null && selectedItems.length > 0) { this.toolbar[BitToolbarComponent.DELETE_BUTTON].visible = true; } else { this.toolbar[BitToolbarComponent.DELETE_BUTTON].visible = false; } this.updateToolbar(); }*/ }; /** Elimina los documentos seleccionados */ BaseSublistComponent.prototype.deleteItems = function () { console.log("delete items"); /* this.store //Ojo que al borrarse los enlaces la propiedad itemsSelected se pone a [] y esta accion podría volver a dispararse .select(fromStore.getCampanyaEnlacesItemsSelected) .subscribe(enlaces => { if (enlaces && enlaces.length > 0) { this.store.dispatch(new fromStore.DeleteEnlaces(enlaces)); } else { if (this.tableView != null) this.tableView.selectedItems = []; } }); */ //TODO Implementado pero no verificado /* this.callDeleteItems(this.parent, items).subscribe(result => { this.lista = this.lista.filter(item => items.indexOf("" + item.id) < 0); this.postDelete(result); }); */ }; /** Función para hacer algo después de haber eliminado los elementos seleccionados */ BaseSublistComponent.prototype.postDelete = function (result) { console.log("postDelete llamado"); //TODO Implementado pero no verificado /* this.toolbar[BitToolbarComponent.DELETE_BUTTON].visible = false; this.updateToolbar(); if (this.tableView != null) this.tableView.selectedItems = []; <----tenemos que actualizar este valor cuando se haya eliminado el elemento */ }; BaseSublistComponent.ɵfac = function BaseSublistComponent_Factory(t) { i0.ɵɵinvalidFactory(); }; BaseSublistComponent.ɵdir = i0.ɵɵdefineDirective({ type: BaseSublistComponent, viewQuery: function BaseSublistComponent_Query(rf, ctx) { if (rf & 1) { i0.ɵɵviewQuery(_c0, 1); } if (rf & 2) { var _t = void 0; i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.tableView = _t.first); } }, inputs: { parent: "parent", parentField: "parentField", initLoad: "initLoad", itemsPreloaded: "itemsPreloaded", femenino: "femenino", forceReload: "forceReload", reloadFromServer: "reloadFromServer" }, outputs: { onChange: "onChange" }, features: [i0.ɵɵInheritDefinitionFeature, i0.ɵɵNgOnChangesFeature] }); return BaseSublistComponent; }(base_component_1.BaseComponent)); exports.BaseSublistComponent = BaseSublistComponent; (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BaseSublistComponent, [{ type: core_1.Directive }], function () { return [{ type: i1.Store }, { type: i2.MessageService }, { type: undefined }, { type: undefined }, { type: undefined }]; }, { tableView: [{ type: core_1.ViewChild, args: ["tableview", { static: false }] }], parent: [{ type: core_1.Input }], parentField: [{ type: core_1.Input }], initLoad: [{ type: core_1.Input }], itemsPreloaded: [{ type: core_1.Input }], femenino: [{ type: core_1.Input }], forceReload: [{ type: core_1.Input }], reloadFromServer: [{ type: core_1.Input }], onChange: [{ type: core_1.Output }] }); })(); //# sourceMappingURL=base-sublist.component.js.map