File : controls/addressControl/AddressControl.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 theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js';
26
import theTranslator from '../../core/uiLib/Translator.js';
27
import BaseControl from '../baseControl/BaseControl.js';
28
29
/* ------------------------------------------------------------------------------------------------------------------------- */
30
/**
31
This class is the address control of the NoteDialog
32
*/
33
/* ------------------------------------------------------------------------------------------------------------------------- */
34
35
class AddressControl extends BaseControl {
36
37
    /**
38
    The address input
39
    @type {HTMLElement}
40
    */
41
42
    #addressInput;
43
44
    /**
45
    The reset address buton
46
    @type {HTMLElement}
47
    */
48
49
    #addressButton;
50
51
    /**
52
    The constructor
53
    @param {NoteDialogEventListeners} eventListeners A reference to the eventListeners object of the NoteDialog
54
    */
55
56
    constructor ( eventListeners ) {
57
58
        super ( );
59
60
        // HTMLElements creation
61
        const headerControlElement = theHTMLElementsFactory.create (
62
            'div',
63
            {
64
                className : 'TravelNotes-BaseDialog-FlexRow'
65
            },
66
            this.controlHTMLElement );
67
        this.#addressButton = theHTMLElementsFactory.create (
68
            'div',
69
            {
70
                className : 'TravelNotes-BaseDialog-Button',
71
                title : theTranslator.getText ( 'AddressControl - Reset address' ),
72
                textContent : '🔄'
73
            },
74
            headerControlElement
75
        );
76
        theHTMLElementsFactory.create (
77
            'text',
78
            {
79
                value : theTranslator.getText ( 'AddressControl - Address' )
80
            },
81
            headerControlElement
82
        );
83
        this.#addressInput = theHTMLElementsFactory.create (
84
            'input',
85
            {
86
                type : 'text',
87
                className : 'TravelNotes-AdressControl-InputText',
88
                dataset : { Name : 'address' }
89
            },
90
            theHTMLElementsFactory.create (
91
                'div',
92
                {
93
                    className : 'TravelNotes-BaseDialog-FlexRow'
94
                },
95
                this.controlHTMLElement )
96
        );
97
98
        // event listeners
99
        if ( eventListeners.controlFocus ) {
100
            this.#addressInput.addEventListener ( 'focus', eventListeners.controlFocus );
101
        }
102
        if ( eventListeners.controlInput ) {
103
            this.#addressInput.addEventListener ( 'input', eventListeners.controlInput );
104
        }
105
        if ( eventListeners.addressButtonClick ) {
106
            this.#addressButton.addEventListener ( 'click', eventListeners.addressButtonClick );
107
        }
108
    }
109
110
    /**
111
    Remove event listeners
112
    @param {NoteDialogEventListeners} eventListeners A reference to the eventListeners object of the NoteDialog
113
    */
114
115
    destructor ( eventListeners ) {
116
        if ( eventListeners.controlFocus ) {
117
            this.#addressInput.removeEventListener ( 'focus', eventListeners.controlFocus );
118
        }
119
        if ( eventListeners.controlInput ) {
120
            this.#addressInput.removeEventListener ( 'input', eventListeners.controlInput );
121
        }
122
        if ( eventListeners.addressButtonClick ) {
123
            this.#addressButton.removeEventListener ( 'click', eventListeners.addressButtonClick );
124
        }
125
    }
126
127
    /**
128
    The address value in the control
129
    @type {String}
130
    */
131
132
    get address ( ) { return this.#addressInput.value; }
133
134
    set address ( Value ) { this.#addressInput.value = Value; }
135
136
}
137
138
export default AddressControl;
139
140
/* --- End of file --------------------------------------------------------------------------------------------------------- */
141