File : dialogs/printRouteMapDialog/PrintRouteMapDialog.js

1
/*
2
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v4.0.0:
21
        - created from v3.6.0
22
Doc reviewed 202208
23
 */
24
25
import theTranslator from '../../core/uiLib/Translator.js';
26
import theConfig from '../../data/Config.js';
27
import ModalBaseDialog from '../baseDialog/ModalBaseDialog.js';
28
import theTravelNotesData from '../../data/TravelNotesData.js';
29
import NumberInputControl from '../../controls/numberInputControl/NumberInputControl.js';
30
import CheckboxInputControl from '../../controls/checkboxInputControl/CheckboxInputControl.js';
31
import RadioInputControl from '../../controls/radioInputControl/RadioInputControl.js';
32
import PrintRouteMapOptions from './PrintRouteMapOptions.js';
33
import { ZERO } from '../../main/Constants.js';
34
35
/* ------------------------------------------------------------------------------------------------------------------------- */
36
/**
37
This class create and manage the print route map dialog
38
*/
39
/* ------------------------------------------------------------------------------------------------------------------------- */
40
41
class PrintRouteMapDialog extends ModalBaseDialog {
42
43
    /**
44
    The paper width input
45
    @type {NumberInputControl}
46
    */
47
48
    #paperWidthControl;
49
50
    /**
51
    The paper height input
52
    @type {NumberInputControl}
53
    */
54
55
    #paperHeightControl;
56
57
    /**
58
    The border width input
59
    @type {NumberInputControl}
60
    */
61
62
    #borderWidthControl;
63
64
    /**
65
    The zoom factor input
66
    @type {NumberInputControl}
67
    */
68
69
    #zoomFactorControl;
70
71
    /**
72
    The print notes control
73
    @type {CheckboxInputControl}
74
    */
75
76
    #printNotesControl;
77
78
    /**
79
    The Firefox browser control
80
    @type {RadioInputControl}
81
    */
82
83
    #firefoxBrowserControl;
84
85
    /**
86
    The greatest acceptable zoom to avoid to mutch tiles asked to OSM
87
    @type {Number}
88
    */
89
90
    // eslint-disable-next-line no-magic-numbers
91
    static get #MAX_ZOOM ( ) { return 15; }
92
93
    /**
94
    The constructor
95
    */
96
97
    constructor ( ) {
98
        super ( );
99
    }
100
101
    /**
102
    Create all the controls needed for the dialog.
103
    Overload of the base class createContentHTML
104
    */
105
106
    createContentHTML ( ) {
107
        this.#paperWidthControl = new NumberInputControl (
108
            {
109
                beforeText : theTranslator.getText ( 'PrintRouteMapDialog - Paper width' ),
110
                afterText : theTranslator.getText ( 'PrintRouteMapDialog - Paper width units' ),
111
                value : theConfig.printRouteMap.paperWidth
112
            }
113
        );
114
        this.#paperHeightControl = new NumberInputControl (
115
            {
116
                beforeText : theTranslator.getText ( 'PrintRouteMapDialog - Paper height' ),
117
                afterText : theTranslator.getText ( 'PrintRouteMapDialog - Paper height units' ),
118
                value : theConfig.printRouteMap.paperHeight
119
            }
120
        );
121
        this.#borderWidthControl = new NumberInputControl (
122
            {
123
                beforeText : theTranslator.getText ( 'PrintRouteMapDialog - Border width' ),
124
                afterText : theTranslator.getText ( 'PrintRouteMapDialog - Border width units' ),
125
                value : theConfig.printRouteMap.borderWidth
126
            }
127
        );
128
        this.#zoomFactorControl = new NumberInputControl (
129
            {
130
                beforeText : theTranslator.getText ( 'PrintRouteMapDialog - Zoom factor' ),
131
                value : Math.min ( theConfig.printRouteMap.zoomFactor, PrintRouteMapDialog.#MAX_ZOOM ),
132
                min : theTravelNotesData.map.getMinZoom ( ),
133
                max : Math.min ( theTravelNotesData.map.getMaxZoom ( ), PrintRouteMapDialog.#MAX_ZOOM )
134
            }
135
        );
136
        this.#printNotesControl = new CheckboxInputControl (
137
            {
138
                afterText : theTranslator.getText ( 'PrintRouteMapDialog - Print notes' ),
139
                checked : theConfig.printRouteMap.printNotes
140
            }
141
        );
142
        this.#firefoxBrowserControl = new RadioInputControl (
143
            {
144
                headerText : theTranslator.getText ( 'PrintRouteMapDialog - Print with' ),
145
                buttons : [
146
                    {
147
                        label : 'Firefox',
148
                        checked : theConfig.printRouteMap.firefoxBrowser
149
                    },
150
                    {
151
                        label : theTranslator.getText ( 'PrintRouteMapDialog - Another browser' ),
152
                        checked : ! theConfig.printRouteMap.firefoxBrowser
153
                    }
154
                ]
155
            }
156
        );
157
    }
158
159
    /**
160
    Overload of the ModalBaseDialog.show ( ) method.
161
    */
162
163
    show ( ) {
164
        let showPromise = super.show ( );
165
        this.addCssClass ( 'TravelNotes-PrintRouteMapDialog' );
166
        return showPromise;
167
    }
168
169
    /**
170
    Overload of the BaseDialog.onOk ( ) method. Called when the Ok button is clicked
171
    */
172
173
    onOk ( ) {
174
        const printRouteMapOptions = new PrintRouteMapOptions ( );
175
        printRouteMapOptions.paperWidth = this.#paperWidthControl.value;
176
        printRouteMapOptions.paperHeight = this.#paperHeightControl.value;
177
        printRouteMapOptions.borderWidth = this.#borderWidthControl.value;
178
        printRouteMapOptions.zoomFactor = this.#zoomFactorControl.value;
179
        printRouteMapOptions.printNotes = this.#printNotesControl.checked;
180
        printRouteMapOptions.firefoxBrowser = ZERO === this.#firefoxBrowserControl.value;
181
        Object.freeze ( printRouteMapOptions );
182
        super.onOk ( printRouteMapOptions );
183
    }
184
185
    /**
186
    Get an array with the HTMLElements that have to be added in the content of the dialog.
187
    @type {Array.<HTMLElement>}
188
    */
189
190
    get contentHTMLElements ( ) {
191
        return [
192
            this.#paperWidthControl.controlHTMLElement,
193
            this.#paperHeightControl.controlHTMLElement,
194
            this.#borderWidthControl.controlHTMLElement,
195
            this.#zoomFactorControl.controlHTMLElement,
196
            this.#printNotesControl.controlHTMLElement,
197
            this.#firefoxBrowserControl.controlHTMLElement
198
        ];
199
    }
200
201
    /**
202
    Return the dialog title. Overload of the BaseDialog.title property
203
    @type {String}
204
    */
205
206
    get title ( ) { return theTranslator.getText ( 'PrintRouteMapDialog - Print' ); }
207
208
}
209
210
export default PrintRouteMapDialog;
211
212
/* --- End of file --------------------------------------------------------------------------------------------------------- */
213