UNPKG

ngx-monitorias-uniandes-lib

Version:

This library is used for Monitorias-Uniandes system.

317 lines 12.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var combo_box_modeldata_1 = require("./model-data/combo-box.modeldata"); //@Combo Box Component //Author: Edgar David Sandoval G. var ComboBox = /** @class */ (function () { function ComboBox() { //Data Handling this.selectedElements = []; //Reference for all the statics this.ComboBoxReference = ComboBox; this.id = ""; //Select State this.selectStates = ComboBox.SELECT; //Option button group Diferentiator (for multiple combo box instances) this.optionInstance = ""; this.enableSelectionState = false; this.disableCheckBoxesSelection = false; // Selection events this.onSelection = new core_1.EventEmitter(); this.onMultiSelection = new core_1.EventEmitter(); this.onSelectionState = new core_1.EventEmitter(); this.multiSelect = false; this.selectFirst = false; this.compact = false; } Object.defineProperty(ComboBox.prototype, "selectState", { set: function (state) { this.changeSelectionState(state); }, enumerable: true, configurable: true }); Object.defineProperty(ComboBox.prototype, "preSelect", { set: function (elements) { this.preSelectedElements = elements; this.preSelectAction(); }, enumerable: true, configurable: true }); Object.defineProperty(ComboBox.prototype, "hiddenElements", { set: function (elements) { this.hideElements = elements; this.hideAction(); }, enumerable: true, configurable: true }); //================== PUBLIC METHODS====================== //Gets the list of select elements and sets them into the selectedElements attribute //================== PUBLIC METHODS====================== //Gets the list of select elements and sets them into the selectedElements attribute ComboBox.prototype.getSelectedElements = //================== PUBLIC METHODS====================== //Gets the list of select elements and sets them into the selectedElements attribute function () { var _this = this; this.selectedElements = []; this.data.forEach(function (element) { if (element.object != null) { if (element.selected) { _this.selectedElements.push(element.object); } } }); return this.selectedElements; }; //Gets single selected element //Gets single selected element ComboBox.prototype.getSelectedElement = //Gets single selected element function () { if (this.selectedSingle != null) { return this.selectedSingle.object; } else { return null; } }; //Changes selection state and fires selection events //Changes selection state and fires selection events ComboBox.prototype.changeSelectionState = //Changes selection state and fires selection events function (state) { if (state == ComboBox.ALL) { this.disableCheckBoxesSelection = true; } else if (state == ComboBox.NONE) { this.disableCheckBoxesSelection = true; } else if (state == ComboBox.SELECT) { this.disableCheckBoxesSelection = false; } this.selectStates = state; this.onSelectionState.emit(this.selectStates); }; //Resets default combo state (Overrides pre selected items) //Resets default combo state (Overrides pre selected items) ComboBox.prototype.reset = //Resets default combo state (Overrides pre selected items) function () { this.data.forEach(function (element) { element.selected = false; }); this.selectedElements = []; this.selectedSingle = null; this.changeSelectionState(ComboBox.ALL); this.selectFirstDefault(); this.fireSelectEvents(); }; // Selects elements on preSelect attribute // Selects elements on preSelect attribute ComboBox.prototype.select = // Selects elements on preSelect attribute function () { this.preSelectAction(); }; //Hide elements on hiddenElements Attribute //Hide elements on hiddenElements Attribute ComboBox.prototype.hide = //Hide elements on hiddenElements Attribute function () { this.hideAction(); }; //======================Internal Methods============================ //Html method delegate for singleSelection //======================Internal Methods============================ //Html method delegate for singleSelection ComboBox.prototype.onSelectionChange = //======================Internal Methods============================ //Html method delegate for singleSelection function () { this.onSelection.emit(this.getSelectedElement()); }; //Html method delegate for multiSelection //Html method delegate for multiSelection ComboBox.prototype.onMultiSelectionChange = //Html method delegate for multiSelection function () { this.onMultiSelection.emit(this.getSelectedElements()); }; //Fires before data population on child //Fires before data population on child ComboBox.prototype.selectionParamsBeforeReset = //Fires before data population on child function () { if (!this.selectFirst) { var nmodeldata = new combo_box_modeldata_1.ComboBoxModelData(false, false, true, "", null); this.data.push(nmodeldata); } }; //Fires after data population on child //Fires after data population on child ComboBox.prototype.selectionParamsAfterReset = //Fires after data population on child function () { this.hideAction(); this.selectFirstDefault(); this.preSelectAction(); this.fireSelectEvents(); }; ComboBox.prototype.fireSelectEvents = function () { if (this.multiSelect) { this.onMultiSelectionChange(); } else { this.onSelectionChange(); } }; // Reset default selection mode. Overrides preSelected elements. // Reset default selection mode. Overrides preSelected elements. ComboBox.prototype.selectFirstDefault = // Reset default selection mode. Overrides preSelected elements. function () { var _this = this; if (this.selectFirst) { if (this.data.length > 0) { var fnd_1 = false; this.data.forEach(function (element) { if (!element.hidden && !fnd_1) { _this.selectedSingle = element; element.selected = true; fnd_1 = true; } }); } } else { if (!this.multiSelect) { this.selectedSingle = this.data[0]; this.data[0].selected = true; } } }; // Click event on multi select mode // Click event on multi select mode ComboBox.prototype.onMultipleListElementClicked = // Click event on multi select mode function (element) { if (!this.disabled) { element.selected = !element.selected; //Verify if the element is unselected to deselect "selec tall" element if (!element.selected) { this.data.forEach(function (verifySel) { if (verifySel.object == null) { if (verifySel.selected) { verifySel.selected = false; } } }); } if (element.object == null) { this.data.forEach(function (elementin) { elementin.selected = element.selected; }); } this.selectedSingle = element; this.onMultiSelectionChange(); } }; // Click event on single select mode // Click event on single select mode ComboBox.prototype.onSelectSingleElement = // Click event on single select mode function (element) { if (!this.disabled) { this.data.forEach(function (elementin) { elementin.selected = false; }); element.selected = true; this.selectedSingle = element; this.onSelectionChange(); } }; //Render on html Selected elements from attribute "preselect". Resets all selections; //Render on html Selected elements from attribute "preselect". Resets all selections; ComboBox.prototype.preSelectAction = //Render on html Selected elements from attribute "preselect". Resets all selections; function () { var _this = this; if (this.preSelectedElements != null && this.data != null) { if (this.preSelectedElements.length > 0) { this.data.forEach(function (element) { element.selected = false; }); this.data.forEach(function (elementin) { if (elementin.object != null || elementin.nameid === "") { _this.preSelectedElements.forEach(function (selval) { if (elementin.nameid == selval && !elementin.hidden) { elementin.selected = true; _this.selectedSingle = elementin; } }); } }); } } else { if (this.data) { this.reset(); } } }; //Render on html hidden elements from attribute "hideElements"; //Render on html hidden elements from attribute "hideElements"; ComboBox.prototype.hideAction = //Render on html hidden elements from attribute "hideElements"; function () { var _this = this; if (this.hideElements != null && this.data != null) { if (this.hideElements.length > 0) { this.data.forEach(function (element) { element.hidden = false; }); this.data.forEach(function (elementin) { if (elementin.object != null) { _this.hideElements.forEach(function (selval) { if (elementin.nameid == selval) { elementin.hidden = true; } }); } }); } } }; // selection mode ComboBox.SINGLE = 0; ComboBox.MULTIPLE = 1; //Visualization mode ComboBox.COMPACT = 0; ComboBox.FULL_SIZE = 1; // Select States ComboBox.SELECT = 2; ComboBox.NONE = 1; ComboBox.ALL = 0; ComboBox.propDecorators = { "multiSelect": [{ type: core_1.Input },], "selectFirst": [{ type: core_1.Input },], "compact": [{ type: core_1.Input },], "disabled": [{ type: core_1.Input },], "id": [{ type: core_1.Input },], "selectState": [{ type: core_1.Input, args: ['selectState',] },], "optionInstance": [{ type: core_1.Input },], "enableSelectionState": [{ type: core_1.Input },], "preSelect": [{ type: core_1.Input, args: ['preSelect',] },], "hiddenElements": [{ type: core_1.Input, args: ['hiddenElements',] },], "onSelection": [{ type: core_1.Output },], "onMultiSelection": [{ type: core_1.Output },], "onSelectionState": [{ type: core_1.Output },], }; return ComboBox; }()); exports.ComboBox = ComboBox; //# sourceMappingURL=combo-box.js.map