Browse Source

+ Export to XLS and XLSX

Piotr Labudda 6 years ago
parent
commit
2958266a26
1 changed files with 33 additions and 34 deletions
  1. 33 34
      tools/Bocian.php.view.js

+ 33 - 34
tools/Bocian.php.view.js

@@ -2386,39 +2386,27 @@ var P5UI__Bocian__ExportFieldSelectOverlay = createReactClass({
 
 	handleExportToHTML: function (event) {
 		event.preventDefault();
-		var selected = this.props.exportFieldsStore.state.selected;
-		DBG && console.log('DBG:P5UI__Bocian__ExportFieldSelectOverlay:handleExportToHTML', { selected: selected, props: this.props })
-		var format = 'html';
-		var exportUrl = [ 'index.php?_route=ViewTableAjax&_task=export&namespace=' + this.props.namespace,
-			'format=' + format,
-			'flds=' + Array.from(selected).join(','),
-			'sortCol=' + (this.props.sortCol || ''),
-			'sortDir=' + (this.props.sortDir ? "desc" : "asc"),
-			this.props.queryFilter
-		].join('&');
-		var win = window.open(exportUrl, '_blank');
-		win.focus();
+		this.openExportWindow('html');
 	},
 	handleExportToCSV: function (event) {
 		event.preventDefault();
-		var selected = this.props.exportFieldsStore.state.selected;
-		DBG && console.log('DBG:P5UI__Bocian__ExportFieldSelectOverlay:handleExportToCSV', { selected: selected })
-		var format = 'csv';
-		var exportUrl = [ 'index.php?_route=ViewTableAjax&_task=export&namespace=' + this.props.namespace,
-			'format=' + format,
-			'flds=' + Array.from(selected).join(','),
-			'sortCol=' + (this.props.sortCol || ''),
-			'sortDir=' + (this.props.sortDir ? "desc" : "asc"),
-			this.props.queryFilter
-		].join('&');
-		var win = window.open(exportUrl, '_blank');
-		win.focus();
+		this.openExportWindow('csv');
 	},
 	handleExportToLatin2CSV: function (event) {
 		event.preventDefault();
+		this.openExportWindow('csv_cp1250');
+	},
+	handleExportToXLS: function (event) {
+		event.preventDefault();
+		this.openExportWindow('xls');
+	},
+	handleExportToXLSX: function (event) {
+		event.preventDefault();
+		this.openExportWindow('xlsx');
+	},
+	openExportWindow: function (format) {
 		var selected = this.props.exportFieldsStore.state.selected;
-		DBG && console.log('DBG:P5UI__Bocian__ExportFieldSelectOverlay:handleExportToLatin2CSV', { selected: selected })
-		var format = 'csv_cp1250';
+		DBG && console.log('DBG:P5UI__Bocian__ExportFieldSelectOverlay:openExportWindow', { format: format, selected: selected })
 		var exportUrl = [ 'index.php?_route=ViewTableAjax&_task=export&namespace=' + this.props.namespace,
 			'format=' + format,
 			'flds=' + Array.from(selected).join(','),
@@ -2476,6 +2464,22 @@ var P5UI__Bocian__ExportFieldSelectOverlay = createReactClass({
 			])
 		]);
 	},
+	renderExportToXLS: function () {
+		return h('li', {}, [
+			h('a', { href: "#", onClick: this.handleExportToXLS, style: { 'font-size': "small", 'font-weight': "normal", 'margin-bottom': "0" } }, [
+				h('i', { className: "glyphicon glyphicon-share" }),
+				" Export do XLS"
+			])
+		]);
+	},
+	renderExportToXLSX: function () {
+		return h('li', {}, [
+			h('a', { href: "#", onClick: this.handleExportToXLSX, style: { 'font-size': "small", 'font-weight': "normal", 'margin-bottom': "0" } }, [
+				h('i', { className: "glyphicon glyphicon-share" }),
+				" Export do XLSX"
+			])
+		]);
+	},
 
 	render: function () {
 		if (!this.props.exportFields) console.warn('DBG: missing this.props.exportFields', { 'this.props': this.props });
@@ -2500,6 +2504,8 @@ var P5UI__Bocian__ExportFieldSelectOverlay = createReactClass({
 			this.renderExportToHTML(),
 			this.renderExportToCSV(),
 			this.renderExportToLatin2CSV(),
+			this.renderExportToXLS(),
+			this.renderExportToXLSX(),
 		]));
 	}
 });
@@ -2548,13 +2554,6 @@ var P5UI__Bocian__ExportTable = createReactClass({ // @props: { namespace, expor
 	handleToggleDropdown: function (event) {
 		var offsetLeft = 0;
 		var offsetTop = 0;
-		DBG && console.log('DBG:P5UI__Bocian__ExportTable:handleToggleDropdown', {
-			event,
-			target: event.target,
-			targetBox: event.target.getBoundingClientRect(),
-			'top': event.target.offsetTop, 'left': event.target.offsetLeft,
-			'this___node__type': (this._node) ? this._node.nodeType : null,
-		});
 
 		this.removePopup();
 		if (!this.state.isOpen) {
@@ -2580,7 +2579,7 @@ var P5UI__Bocian__ExportTable = createReactClass({ // @props: { namespace, expor
 				h(Unstated.Provider, {}, [
 					h(Unstated.Subscribe, { to: [ exportFieldsContainer ] },
 						function (exportFieldsCont) {
-							console.log('DBG:exportFieldsCont', { exportFieldsCont })
+							DBG && console.log('DBG:exportFieldsCont', { exportFieldsCont })
 							return h(P5UI__Bocian__ExportFieldSelectOverlay, Object.assign({}, self__props, {
 								exportFields: exportFields,
 								btnBBox: btnBBox,