File : dialogs/travelPropertiesDialog/TravelPropertiesDialog.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 DockableBaseDialog from '../baseDialog/DockableBaseDialog.js';
26
import TextInputControl from '../../controls/textInputControl/TextInputControl.js';
27
import theTranslator from '../../core/uiLib/Translator.js';
28
import theTravelNotesData from '../../data/TravelNotesData.js';
29
import SortableListControl from '../../controls/sortableListControl/SortableListControl.js';
30
import theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js';
31
import theTravelEditor from '../../core/TravelEditor.js';
32
import RouteContextMenu from '../../contextMenus/RouteContextMenu.js';
33
import TravelNameChangeEL from './TravelNameChangeEL.js';
34
import theConfig from '../../data/Config.js';
35
import { ROUTE_EDITION_STATUS } from '../../main/Constants.js';
36
37
/* ------------------------------------------------------------------------------------------------------------------------- */
38
/**
39
This class is the TravelPropertiesDialog
40
*/
41
/* ------------------------------------------------------------------------------------------------------------------------- */
42
43
class TravelPropertiesDialog extends DockableBaseDialog {
44
45
    /**
46
    The travel name control
47
    @type {TextInputControl}
48
    */
49
50
    #travelNameControl = null;
51
52
    /**
53
    The routes control
54
    @type {SortableListControl}
55
    */
56
57
    #travelRoutesControl = null;
58
59
    /**
60
    The constructor
61
    */
62
63
    constructor ( ) {
64
        super ( theConfig.travelPropertiesDialog.dialogX, theConfig.travelPropertiesDialog.dialogY );
65
    }
66
67
    /**
68
    Create all the controls needed for the dialog.
69
    Overload of the base class createContentHTML
70
    */
71
72
    createContentHTML ( ) {
73
        this.#travelNameControl = new TextInputControl (
74
            theTranslator.getText ( 'TravelPropertiesDialog - Name' ),
75
            { controlChange : new TravelNameChangeEL ( ) }
76
        );
77
        this.#travelNameControl.value = theTravelNotesData.travel.name;
78
        this.#travelRoutesControl = new SortableListControl (
79
            theTravelEditor.routeDropped,
80
            RouteContextMenu,
81
            theTranslator.getText ( 'TravelPropertiesDialog - Routes' )
82
        );
83
    }
84
85
    /**
86
    An array with the HTMLElements that have to be added in the content of the dialog.
87
    Overload of the BaseDialog contentHTMLElements property.
88
    @type {Array.<HTMLElement>}
89
    */
90
91
    get contentHTMLElements ( ) {
92
        return [
93
            this.#travelNameControl.controlHTMLElement,
94
            this.#travelRoutesControl.controlHTMLElement
95
        ];
96
    }
97
98
    /**
99
    The dialog title. Overload of the BaseDialog.title property
100
    @type {String}
101
    */
102
103
    get title ( ) { return theTranslator.getText ( 'TravelPropertiesDialog - Travel properties' ); }
104
105
    /**
106
    Add a route in the route list  of the dialog
107
    @param {Route} route The route to add
108
    @param {Array.<HTMLElement>} listItemsHTMLElements The list to witch the routes are added
109
    */
110
111
    #addRoute ( route, listItemsHTMLElements ) {
112
        const routeName =
113
        ( route.editionStatus === ROUTE_EDITION_STATUS.notEdited ? '' : '🔴\u00a0' ) +
114
        ( route.chain ? '⛓\u00a0' : '' ) +
115
        (
116
            route.objId === theTravelNotesData.editedRouteObjId ?
117
                theTravelNotesData.travel.editedRoute.computedName :
118
                route.computedName
119
        );
120
        listItemsHTMLElements.push (
121
            theHTMLElementsFactory.create (
122
                'div',
123
                {
124
                    textContent : routeName,
125
                    dataset : { ObjId : String ( route.objId ) }
126
                }
127
            )
128
        );
129
    }
130
131
    /**
132
    Update the content of the dialog
133
    */
134
135
    updateContent ( ) {
136
        if ( ! this.#travelRoutesControl ) {
137
            return;
138
        }
139
        const listItemsHTMLElements = [];
140
        theTravelNotesData.travel.routes.forEach (
141
            route => {
142
                if ( route.objId === theTravelNotesData.editedRouteObjId ) {
143
                    this.#addRoute ( theTravelNotesData.travel.editedRoute, listItemsHTMLElements );
144
                }
145
                else {
146
                    this.#addRoute ( route, listItemsHTMLElements );
147
                }
148
            }
149
        );
150
        this.#travelRoutesControl.updateContent ( listItemsHTMLElements );
151
        this.#travelNameControl.value = theTravelNotesData.travel.name;
152
    }
153
}
154
155
export default TravelPropertiesDialog;
156
157
/* --- End of file --------------------------------------------------------------------------------------------------------- */
158