Commit bc0e4750 authored by CarlosGC1989's avatar CarlosGC1989
Browse files

Refactoriza listado tabla, Fix #15

parent d5ef2b81
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -495,6 +495,11 @@ define([
			this.seriesData.definitionIndex = definitionIndexObj;
		},

		_localDeselected: function() {

			this._localClearSelection();
		},

		_localClearSelection: function() {

			this._publish(this.dataDefinitionList.getChildChannel("browser", "CLEAR_SELECTION"));
+5 −0
Original line number Diff line number Diff line
@@ -178,6 +178,11 @@ define([

		_subClear: function() {

			this._clear();
		},

		_clear: function() {

			this._clearData();
		},

+18 −6
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ define([
			lang.mixin(this, this.config);

			aspect.before(this, "_addItem", lang.hitch(this, this._addHierarchicalTableItem));
			aspect.before(this, "_addClassCols", lang.hitch(this, this._addClassHierarchicalCols));
			aspect.after(this, "_addClassColumns", lang.hitch(this, this._addClassHierarchicalColumns));
			aspect.before(this, "_clearTableStyle", lang.hitch(this, this._clearHierarchicalTableStyle));
		},

		postCreate: function() {
@@ -57,15 +58,26 @@ define([
			}
		},

		_addClassHierarchicalCols: function() {
		_clearHierarchicalTableStyle: function() {

			while (this._hierarchicalTableStyle.rules.length) {
				this._hierarchicalTableStyle.deleteRule(0);
			}
		},

		_addClassHierarchicalColumns: function() {

			for (var i = 1; i <= this._countPath; i++) {
				this._addClassHierarchicalColumn(i);
			}
		},

				var value = (this._countPath * 2) - (2 * i - 1) + 0.5,
		_addClassHierarchicalColumn: function(position) {

			var value = (this._countPath * 2) - (2 * position - 1) + 0.5,
			style = "justify-content: flex-start;width: 30rem; padding-right: " + value +	"rem !important;";

				this._hierarchicalTableStyle.insertRule(".table-col-hierrarchical-" + i + " { " + style + " }");
			}
			this._hierarchicalTableStyle.insertRule(".table-col-hierrarchical-" + position + " { " + style + " }");
		}
	});
});
+181 −81
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ define([

			aspect.after(this, "_definitionRow", lang.hitch(this, this._definitionTableRow));
			aspect.before(this, "_configRow", lang.hitch(this, this._configTableRow));
			aspect.before(this, "_clear", lang.hitch(this, this._clearTable));
		},

		_setTableConfigurations: function() {
@@ -111,16 +112,6 @@ define([
			});
		},

		_subListEventItem: function(res) {

			var rules = this._tableStyle.rules,
				value = res.value;

			this._tableStyle.rules[rules.length - value].style.display = res.actionSelect ? "flex" : "none";

			this._updateWidth();
		},

		_initializeTable: function() {

			this.headerOptionListMenu = new declare([ListMenu, _ShowOnEvt]).extend(_ShowInTooltip)(this.headerOptionConfig);
@@ -146,6 +137,16 @@ define([
			this._tableStyle = this._tableStyle.sheet;
		},

		_subListEventItem: function(res) {

			var rules = this._tableStyle.rules,
				value = res.value;

			this._tableStyle.rules[rules.length - value].style.display = res.actionSelect ? "flex" : "none";

			this._updateWidth();
		},

		_getNodeBaseList: function() {

			return this.containerScroll;
@@ -153,15 +154,26 @@ define([

		_addData: function(res) {

			this._clearData();
			this._clear();

			this._proccesNewData(res);

			this._createHeaders();
			this._showListMenu();
			this._addClassCols();
			this._addOthers();
		},

			this._updateWidth();
		_clearTable: function() {

			this._clearHeaders();
			this._setStyleInNodes(0);
		},

		_proccesNewData: function(res) {

			var data = this._parserIndexData(res);

			for (var i= 0; i < data.length; i++) {
				this._addItem(data[i]);
			}
		},

		_parserIndexData: function(res) {
@@ -182,13 +194,13 @@ define([
			return data;
		},

		_proccesNewData: function(res) {
		_addOthers: function() {

			var data = this._parserIndexData(res);
			this._createHeaders();
			this._showListMenu();
			this._addClassColumns();

			for (var i= 0; i < data.length; i++) {
				this._addItem(data[i]);
			}
			setTimeout(lang.hitch(this, this._updateWidth), 200);
		},

		_updateWidth: function() {
@@ -197,30 +209,62 @@ define([
				return;
			}

			this._setStyleInNodes(this._calculateWidthCount());
		},

		_calculateWidthCount: function() {

			var nodeRow = this.rowsContainerNode.firstChild.firstChild,
				children = nodeRow.children;
				widthCount = 0;

			for (var i = 0; i < children.length; i++) {

				if (children[i]) {
					widthCount += children[i].clientWidth;
				}
			}

			var minWidthHeaders = widthCount + this._correctionHeaderRow,
				paddingHeaders = this._paddingHeaderRow;
			return widthCount;
		},

		_setStyleInNodes: function(widthCount) {

			this._calculateMinWidthAndPaddingRightHeaders(widthCount);

			this._setStyleInHeaders(widthCount);
			this._setStyleInContentList(widthCount);
		},

		_setStyleInHeaders: function(widthCount) {

			var style = "min-width:" + this._minWidthHeaders + "px; padding-right: " + this._paddingRightHeaders + "px;";

			this.headersNode.setAttribute("style", style);
		},

		_calculateMinWidthAndPaddingRightHeaders: function(widthCount) {

			if (!this.rowsContainerNode.firstChild) {
				return;
			}

			var buttonsWidth = 0,
				nodeRow = this.rowsContainerNode.firstChild.firstChild,
				children = nodeRow.children;

			if (this._definitionButtonsRow) {
				var buttonsWidth = children[children.length - 1].clientWidth;
				minWidthHeaders -= buttonsWidth;
				paddingHeaders += buttonsWidth;
				buttonsWidth = children[children.length - 1].clientWidth;
			}

			this.headersNode.setAttribute("style", "min-width:" + minWidthHeaders +
				"px; padding-right: " + paddingHeaders + "px;");
			this._minWidthHeaders = widthCount + this._correctionHeaderRow - buttonsWidth;
			this._paddingRightHeaders = this._paddingHeaderRow + buttonsWidth;
		},

		_setStyleInContentList: function(widthCount) {

			var style = "min-width:" + (widthCount + this._valueRow) + "px;";

			this.contentListNode.setAttribute("style", "min-width:" + (widthCount + this._valueRow) + "px;");
			this.contentListNode.setAttribute("style", style);
		},

		_afterShow: function(obj) {
@@ -228,39 +272,53 @@ define([
			setTimeout(lang.hitch(this, this._updateWidth), 200);
		},

		_addClassCols: function() {
		_addClassColumns: function() {

			var columns = this.tableConfig.columns;

			this._classCount = 1;
			this._clearTableStyle();

			for (var i = 0; i < columns.length; i++) {
				var column = columns[i];
				this._addClassColumnType(columns[i]);
			}
		},

		_clearTableStyle: function() {

			this._classCount = 1;

				if (!column.type) {
					this._addClassCol(columns[i]);
				} else if (column.type === "arrayColumns") {
					this._addClassArrayColumns(columns[i]);
			while (this._tableStyle.rules.length) {
				this._tableStyle.deleteRule(0);
			}
		},

		_addClassColumnType: function(column) {

			this._currentColumn = column;

			if (this._isTypeArrayColumns()) {
				this._addClassArrayColumns();
			} else {
				this._addClassColumn();
			}
		},

		_addClassCol: function(column) {
		_addClassColumn: function() {

			var styleBasic = "min-width: 5rem; width: 5rem; display: flex; justify-content: center;",
				style = column.style || "";
				style = this._currentColumn.style || "";

			this._tableStyle.insertRule(".table-col-" + (this._classCount) + " { " + styleBasic + style + " } ");

			this._classCount ++;
		},

		_addClassArrayColumns: function(column, i) {
		_addClassArrayColumns: function() {

			var value = column.countData;
			var value = this._currentColumn.countData;

			for (var n = 0; n < value; n++) {
				this._addClassCol(column);
				this._addClassColumn(this._currentColumn);
			}
		},

@@ -299,69 +357,102 @@ define([

		_createHeaders: function() {

			var columns = this.tableConfig.columns,
				totalColumns = columns.length;

			for (var i = 0; i < totalColumns; i++) {
				this._createHeaderWithType(columns[i]);
			}
		},

		_clearHeaders: function() {

			this._headersData = [];

			while (this.headersNode.firstChild) {
				put(this.headersNode.firstChild, '!');
			}
		},

			var columns = this.tableConfig.columns,
				totalColumns = columns.length,
				headerConfig = this.tableConfig.header || {};
		_createHeaderWithType: function(column) {

			for (var i = 0; i < totalColumns; i++) {
				var column = columns[i],
					type = column.type,
					propHeader = column.propertyHeader;

				if (!type) {
					this._createHeader(column, this._getContentHeader(column), headerConfig);
				} else if (type == "arrayColumns" && this._headers[propHeader]) {
					this._createHeadersArrayColumns(column, this._headers[propHeader]);
				}
			var propHeader = column.propertyHeader;

			this._currentColumn = column;

			if (this._isTypeArrayColumns() && this._headers[propHeader]) {
				column.countData = this._headers[propHeader].length;
				this._createHeadersArrayColumns(this._headers[propHeader]);
			} else {
				this._createHeader(this._getContentHeader(), this.tableConfig.header || {});
			}
		},

		_createHeadersArrayColumns: function(column, dataHeader) {

			var headerConfig = this.tableConfig.header || {},
				itemHeader,	content, label;
		_createHeadersArrayColumns: function(dataHeader) {

			for (var i = 0; i < dataHeader.length; i++) {
				itemHeader = dataHeader[i];
				var content = dataHeader[i].label || this._getContentHeader();

				this._createHeader(content, this.tableConfig.header || {});
			}
		},

		_createHeader: function(content, headerConfig) {

			this._addHeaderInData(content);

				content = itemHeader.label || this._getContentHeader(column);
			var node = this._addNodeHeader();

				this._createHeader(column, content, headerConfig);
			if (this._isConfigWithTemplate()) {
				node.innerHTML = content;
			} else {
				node.innerText = this._formatContent(content, headerConfig.format);
			}
		},

		_createHeader: function(column, content, headerConfig) {
		_addNodeHeader: function() {

			return put(this.headersNode, 'span' + this._getClassHeader());
		},

			this._addHeaderInData(column, content);
		_getClassHeader: function() {

			var children = this.headersNode.children.length,
				colClass = 'table-col-' + (children + 1);
				colClass = '.table-cell.table-col-' + (children + 1);

			if (!children) {
				colClass += '.table-cell-header-1';
			}

			var node = put(this.headersNode, 'span.table-cell.' + colClass),
				format = headerConfig.format;
			return colClass;
		},

		_formatContent: function(content, format) {

			format = format || this._currentColumn.format;

			if (!column.template) {
			if (format) {
					content = format(content);
				return format(content);
			}

				node.innerText = content;
			} else {
				node.innerHTML = content;
			return content;
		},

		_isConfigWithTemplate: function() {

			if (this._currentColumn.template) {
				return true;
			}

			return false;
		},

		_addHeaderInData: function(content) {

			this._headersData.push(this._getPropertiesHeaders(content));
		},

		_addHeaderInData: function(column, content) {
		_getPropertiesHeaders: function(content) {

			var obj = {
					item: {
@@ -371,22 +462,31 @@ define([
					select: true
				};

			if (column.noDisabled) {
			if (this._currentColumn.noDisabled) {
				obj.item.noDisabled = true;
			}

			if (column.noSelect) {
			if (this._currentColumn.noSelect) {
				obj.select = false;
			}

			this._headersData.push(obj);
			return obj;
		},

		_getContentHeader: function(obj) {
		_getContentHeader: function() {

			var label = obj.label || obj.property;
			var label = this._currentColumn.label || this._currentColumn.property;

			return this.i18n[label] || label;
		},

		_isTypeArrayColumns: function() {

			if (this._currentColumn.type == "arrayColumns") {
				return true;
			}

			return false;
		}
	});
});
+10 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ define([
					ADD_TO_QUERY: "addToQuery",
					GO_TO_PAGE: "goToPage",
					SET_TOTAL: "setTotal",
					RESET_PAGINATION: "resetPagination"
					RESET_PAGINATION: "resetPagination",
					CLEAR: "clear"
				}
			};

@@ -54,6 +55,9 @@ define([
			},{
				channel : this.getChannel("RESET_PAGINATION"),
				callback: "_subResetPagination"
			},{
				channel: this._buildChannel(this.browserChannel, this.actions.CLEAR),
				callback: "_subClearBrowser"
			});
		},

@@ -110,6 +114,11 @@ define([
			this._setTotal(req.value);
		},

		_subClearBrowser: function() {

			this._setTotal(0);
		},

		postCreate: function() {

			this.inherited(arguments);
Loading