From 2a9956ec91f97ccedca6b03d9bcc2a5a73616466 Mon Sep 17 00:00:00 2001 From: Daniel Gerhardt <code@dgerhardt.net> Date: Fri, 1 Feb 2019 12:11:21 +0100 Subject: [PATCH] Extract MessageBox for CSV export to a component --- .../view/components/CsvExportMessageBox.js | 86 +++++++++++++++++++ .../app/view/speaker/AudienceQuestionPanel.js | 61 +------------ 2 files changed, 89 insertions(+), 58 deletions(-) create mode 100644 src/main/webapp/app/view/components/CsvExportMessageBox.js diff --git a/src/main/webapp/app/view/components/CsvExportMessageBox.js b/src/main/webapp/app/view/components/CsvExportMessageBox.js new file mode 100644 index 000000000..8799a4951 --- /dev/null +++ b/src/main/webapp/app/view/components/CsvExportMessageBox.js @@ -0,0 +1,86 @@ +/* + * This file is part of ARSnova Mobile. + * Copyright (C) 2011-2012 Christian Thomas Weber + * Copyright (C) 2012-2019 The ARSnova Team and Contributors + * + * ARSnova Mobile is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * ARSnova Mobile is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ARSnova Mobile. If not, see <http://www.gnu.org/licenses/>. + */ +Ext.define('ARSnova.view.components.CsvExportMessageBox', { + extend: 'Ext.MessageBox', + + config: { + exportCallback: Ext.emptyFn, + + hideOnMaskTap: true, + cls: 'importExportFilePanel', + title: Messages.QUESTIONS_EXPORT_MSBOX_TITLE + }, + + initialize: function () { + this.add([{ + xtype: 'button', + iconCls: 'icon-close', + cls: 'closeButton', + handler: function () { this.getParent().hide(); } + }, { + html: Messages.QUESTIONS_CSV_EXPORT_DELIMITER_INFO, + cls: 'x-msgbox-text' + }, { + xtype: 'container', + layout: 'vbox', + defaults: { + scope: this + }, + items: [ + { + xtype: 'fieldset', + itemId: 'csvDelimiterField', + defaults: { + xtype: 'radiofield', + labelWidth: '60%' + }, + items: [{ + name: 'delimiter', + label: Messages.QUESTIONS_CSV_EXPORT_COMMA, + value: ',', + checked: true + }, { + name: 'delimiter', + label: Messages.QUESTIONS_CSV_EXPORT_SEMICOLON, + value: ';' + }, { + name: 'delimiter', + label: Messages.QUESTIONS_CSV_EXPORT_TABULATOR, + value: '\t' + }] + }, { + xtype: 'togglefield', + itemId: 'excelField', + name: 'excel', + label: Messages.QUESTIONS_CSV_EXPORT_EXCEL, + labelWidth: '60%' + }, { + xtype: 'button', + ui: 'action', + text: Messages.EXPORT_BUTTON_LABEL, + handler: function () { + var csvDelimiterField = this.down('#csvDelimiterField'); + var excelField = this.down('#excelField'); + this.getExportCallback()(csvDelimiterField.items.items[0].getGroupValue(), excelField.getValue()); + this.hide(); + } + }] + }]); + } +}); diff --git a/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js b/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js index ec4fc4849..aaa428a28 100644 --- a/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js +++ b/src/main/webapp/app/view/speaker/AudienceQuestionPanel.js @@ -22,6 +22,7 @@ Ext.define('ARSnova.view.speaker.AudienceQuestionPanel', { requires: [ 'ARSnova.view.Caption', 'ARSnova.model.Question', + 'ARSnova.view.components.CsvExportMessageBox', 'ARSnova.view.speaker.MultiVoteStatusButton', 'ARSnova.view.speaker.MultiQuestionStatusButton', 'ARSnova.view.speaker.SortQuestionsPanel' @@ -315,64 +316,8 @@ Ext.define('ARSnova.view.speaker.AudienceQuestionPanel', { }] }); - this.exportCsvPanel = Ext.create('Ext.MessageBox', { - hideOnMaskTap: true, - cls: 'importExportFilePanel', - title: Messages.QUESTIONS_EXPORT_MSBOX_TITLE, - items: [{ - xtype: 'button', - iconCls: 'icon-close', - cls: 'closeButton', - handler: function () { this.getParent().hide(); } - }, { - html: Messages.QUESTIONS_CSV_EXPORT_DELIMITER_INFO, - cls: 'x-msgbox-text' - }, { - xtype: 'container', - layout: 'vbox', - defaults: { - scope: this - }, - items: [ - { - xtype: 'fieldset', - itemId: 'csvDelimiterField', - defaults: { - xtype: 'radiofield', - labelWidth: '60%' - }, - items: [{ - name: 'delimiter', - label: Messages.QUESTIONS_CSV_EXPORT_COMMA, - value: ',', - checked: true - }, { - name: 'delimiter', - label: Messages.QUESTIONS_CSV_EXPORT_SEMICOLON, - value: ';' - }, { - name: 'delimiter', - label: Messages.QUESTIONS_CSV_EXPORT_TABULATOR, - value: '\t' - }] - }, { - xtype: 'togglefield', - itemId: 'excelField', - name: 'excel', - label: Messages.QUESTIONS_CSV_EXPORT_EXCEL, - labelWidth: '60%' - }, { - xtype: 'button', - ui: 'action', - text: Messages.EXPORT_BUTTON_LABEL, - handler: function () { - var csvDelimiterField = this.exportCsvPanel.down('#csvDelimiterField'); - var excelField = this.exportCsvPanel.down('#excelField'); - this.exportCsv(csvDelimiterField.items.items[0].getGroupValue(), excelField.getValue()); - this.exportCsvPanel.hide(); - } - }] - }] + this.exportCsvPanel = Ext.create('ARSnova.view.components.CsvExportMessageBox', { + exportCallback: Ext.bind(this.exportCsv, this) }); this.actionButtonPanel = Ext.create('Ext.Panel', { -- GitLab