GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0bfeeb...7b7241 )
by Florian
01:16
created

Markers.toXmlWpts   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 9.4285
1
/*jslint
2
  indent: 4
3
*/
4
5
/*global
6
  $,
7
  Conversion, Coordinates, Lines, Marker, Storage,
8
  id2alpha, Lang, showAlert, trackMarker, showProjectionDialog
9
*/
10
11
var Markers = {};
12
Markers.m_map = null;
13
Markers.m_markers = null;
14
15
16
Markers.init = function (themap) {
17
    'use strict';
18
19
    this.m_map = themap;
20
    this.m_markers = [];
21
22
    var id;
23
    for (id = 0; id !== 26 * 10; id = id + 1) {
24
        this.m_markers[id] = new Marker(this, id);
25
    }
26
};
27
28
29
Markers.getSize = function () {
30
    'use strict';
31
32
    return this.m_markers.length;
33
};
34
35
36
Markers.isValid = function (id) {
37
    'use strict';
38
39
    return 0 <= id && id < this.m_markers.length;
40
};
41
42
43
Markers.getById = function (id) {
44
    'use strict';
45
46
    if (id < 0 || id >= this.m_markers.length) {
47
        return null;
48
    }
49
50
    return this.m_markers[id];
51
};
52
53
54
Markers.getUsedMarkers = function () {
55
    'use strict';
56
57
    var count = 0;
58
    this.m_markers.map(function (m) {
59
        if (!m.isFree()) {
60
            count = count + 1;
61
        }
62
    });
63
    return count;
64
};
65
66
67
Markers.getFreeMarkers = function () {
68
    'use strict';
69
70
    return this.getSize() - this.getUsedMarkers();
71
};
72
73
74
Markers.getFreeId = function () {
75
    'use strict';
76
77
    var id;
78
    for (id = 0; id < this.m_markers.length; id = id + 1) {
79
        if (this.m_markers[id].isFree()) {
80
            return id;
81
        }
82
    }
83
    return -1;
84
};
85
86
87
Markers.getNextUsedId = function (id) {
88
    'use strict';
89
90
    var i;
91
    for (i = id + 1; i < this.m_markers.length; i = i + 1) {
92
        if (!this.m_markers[i].isFree()) {
93
            return i;
94
        }
95
    }
96
    return -1;
97
};
98
99
100
Markers.removeById = function (id) {
101
    'use strict';
102
103
    if (id >= 0 && id < this.m_markers.length) {
104
        this.m_markers[id].clear();
105
    }
106
};
107
108
109
Markers.deleteAll = function () {
110
    'use strict';
111
112
    this.m_markers.map(
113
        function (m) {
114
            m.clear();
115
        }
116
    );
117
};
118
119
120
Markers.store = function () {
121
    'use strict';
122
123
    var ids = [];
124
    this.m_markers.map(
125
        function (m) {
126
            if (!m.isFree()) {
127
                ids.push(m.getId());
128
            }
129
        }
130
    );
131
    Storage.set('markers', ids.join(":"));
132
};
133
134
135
Markers.toString = function () {
136
    'use strict';
137
138
    var parts = [];
139
    this.m_markers.map(
140
        function (m) {
141
            if (!m.isFree()) {
142
                parts.push(m.toString());
143
            }
144
        }
145
    );
146
    return parts.join("*");
147
};
148
149
150
Markers.toXmlWpts = function () {
151
    'use strict';
152
153
    var data = '';
154
155
    this.m_markers.map(
156
        function (m) {
157
            if (!m.isFree()) {
158
                data += m.toXmlWpt();
159
                data += '\n';
160
            }
161
        }
162
    );
163
164
    return data;
165
};
166
167
168
Markers.update = function () {
169
    'use strict';
170
171
    this.m_markers.map(
172
        function (m) {
173
            m.update();
174
        }
175
    );
176
};
177
178
179
Markers.handleMarkerCleared = function () {
180
    'use strict';
181
182
    if (this.getUsedMarkers() === 0) {
183
        $('#btnmarkers2').hide();
184
    }
185
186
    Lines.updateTotalDistance();
187
    this.store();
188
};
189
190
191
Markers.goto = function (id) {
192
    'use strict';
193
194
    trackMarker('goto');
195
196
    var m = this.getById(id);
197
    if (m) {
198
        this.m_map.setCenter(m.getPosition());
199
    }
200
};
201
202
203
Markers.center = function (id) {
204
    'use strict';
205
206
    trackMarker('center');
207
208
    var m = this.getById(id);
209
    if (m) {
210
        m.setPosition(this.m_map.getCenter());
211
    }
212
};
213
214
215
Markers.newMarker = function (coordinates, id, radius, name, color) {
216
    'use strict';
217
218
    radius = Math.max(radius, 0);
219
220
    if (id < 0 || id >= this.getSize() || !this.getById(id).isFree()) {
221
        id = this.getFreeId();
222
        if (id < 0) {
223
            showAlert(
224
                Lang.t("dialog.error"),
225
                Lang.t("dialog.toomanymarkers_error.content").replace(/%1/, Markers.getSize())
226
            );
227
            return null;
228
        }
229
    }
230
231
    var self = this,
232
        marker,
233
        div,
234
        nextid;
235
236
    if (!name) {
237
        name = id2alpha(id);
238
    }
239
    if (!coordinates) {
240
        coordinates = this.m_map.getCenter();
241
    }
242
243
    marker = this.getById(id);
244
    marker.initialize(this.m_map, name, coordinates, radius, color);
245
    div = this.createMarkerDiv(id);
246
247
    nextid = this.getNextUsedId(id);
248
    if (nextid < 0) {
249
        $('#dynMarkerDiv').append(div);
250
    } else {
251
        $(div).insertBefore('#dyn' + nextid);
252
    }
253
254
    $('#dyn' + id + ' > .edit').keydown(function (e) {
255
        if (e.which === 27) {
256
            self.leaveEditMode(id, false);
257
        } else if (e.which === 13) {
258
            self.leaveEditMode(id, true);
259
        }
260
    });
261
262
    $('#btnmarkers2').show();
263
    $('#btnmarkersdelete1').removeAttr('disabled');
264
    $('#btnmarkersdelete2').removeAttr('disabled');
265
266
    marker.update();
267
    this.store();
268
    Lines.updateLinesMarkerAdded();
269
270
    return marker;
271
};
272
273
274
Markers.createMarkerDiv = function (id) {
275
    'use strict';
276
277
    return "<div id=\"dyn" + id + "\">" +
278
            "<table class=\"view\" style=\"width: 100%; vertical-align: middle;\">\n" +
279
            "    <tr>\n" +
280
            "        <td rowspan=\"3\" style=\"vertical-align: top\">\n" +
281
            "            <img class=\"icon\" src=\"\" />\n" +
282
            "        </td>\n" +
283
            "        <td style=\"text-align: center\"><i class=\"fa fa-map-marker\"></i></td>\n" +
284
            "        <td class=\"name\" colspan=\"2\">marker</td>\n" +
285
            "    </tr>\n" +
286
            "    <tr>\n" +
287
            "        <td style=\"text-align: center\"><i class=\"fa fa-globe\"></i></td>\n" +
288
            "        <td class=\"coords\" colspan=\"2\">N 48° 00.123 E 007° 51.456</td>\n" +
289
            "    </tr>\n" +
290
            "    <tr>\n" +
291
            "        <td style=\"text-align: center\"><i class=\"fa fa-circle-o\"></i></td>\n" +
292
            "        <td class=\"radius\">16100 m</td>\n" +
293
            "        <td>\n" +
294
            "            <div class=\"btn-group\" style=\"padding-bottom: 2px; padding-top: 2px; float: right\">\n" +
295
            "            <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.edit_marker\" type=\"button\"  onclick=\"Markers.enterEditMode(" + id + ");\"><i class=\"fa fa-edit\"></i></button>\n" +
296
            "            <button class=\"my-button btn btn-mini btn-danger\" data-i18n=\"[title]sidebar.markers.delete_marker\" type=\"button\" onClick=\"Markers.removeById(" + id + ");\"><i class=\"fa fa-trash-o\"></i></button>\n" +
297
            "            <button class=\"my-button btn btn-mini btn-info\" data-i18n=\"[title]sidebar.markers.move_to\" type=\"button\" onClick=\"Markers.goto(" + id + ");\"><i class=\"fa fa-search\"></i></button>\n" +
298
            "            <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.center\" type=\"button\" onClick=\"Markers.center(" + id + ");\"><i class=\"fa fa-crosshairs\"></i></button>\n" +
299
            "            <button class=\"my-button btn btn-mini btn-success\" data-i18n=\"[title]sidebar.markers.project\" type=\"button\" onClick=\"Markers.projectFromMarker(" + id + ");\"><i class=\"fa fa-location-arrow\"></i></button>\n" +
300
            "            </div>\n" +
301
            "        </td>\n" +
302
            "    </tr>\n" +
303
            "</table>\n" +
304
            "<table class=\"edit\" style=\"display: none; width: 100%; vertical-align: middle;\">\n" +
305
            "    <tr>\n" +
306
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-map-marker\"></i>&nbsp;</td>\n" +
307
            "        <td><input data-i18n=\"[title]sidebar.markers.name;[placeholder]sidebar.markers.name_placeholder\" class=\"name form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
308
            "    </tr>\n" +
309
            "    <tr>\n" +
310
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-globe\"></i>&nbsp;</td>\n" +
311
            "        <td><input data-i18n=\"[title]sidebar.markers.coordinates;[placeholder]sidebar.markers.coordinates_placeholder\" class=\"coords form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
312
            "    </tr>\n" +
313
            "    <tr>\n" +
314
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-circle-o\"></i>&nbsp;</td>\n" +
315
            "        <td><input data-i18n=\"[title]sidebar.markers.radius;[placeholder]sidebar.markers.radius_placeholder\" class=\"radius form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
316
            "    </tr>\n" +
317
            "    <tr>\n" +
318
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-paint-brush\"></i>&nbsp;</td>\n" +
319
            "        <td><input data-i18n=\"[title]sidebar.markers.color;[placeholder]sidebar.markers.color_placeholder\" class=\"color form-control input-block-level\" type=\"color\" style=\"margin-bottom: 0px;\" value=\"#FF0000\" /></td>\n" +
320
            "    </tr>\n" +
321
            "    <tr>\n" +
322
            "        <td colspan=\"2\" style=\"text-align: right\">\n" +
323
            "            <button class=\"btn btn-small btn-primary\" type=\"button\" onclick=\"Markers.leaveEditMode(" + id + ", true);\" data-i18n=\"dialog.ok\">OK</button>\n" +
324
            "            <button class=\"btn btn-small\" type=\"button\" onclick=\"Markers.leaveEditMode(" + id + ", false);\" data-i18n=\"dialog.cancel\">CANCEL</button>\n" +
325
            "        </td>\n" +
326
            "    </tr>\n" +
327
            "</table>" +
328
            "</div>";
329
};
330
331
332
Markers.enterEditMode = function (id) {
333
    'use strict';
334
335
    trackMarker('edit');
336
    var m = this.getById(id);
337
    if (!m) {
338
        return;
339
    }
340
341
    $('#dyn' + id + ' > .edit .name').val(m.getName());
342
    $('#dyn' + id + ' > .edit .coords').val(Coordinates.toString(m.getPosition()));
343
    $('#dyn' + id + ' > .edit .radius').val(m.getRadius());
344
    $('#dyn' + id + ' > .edit .color').val('#' + m.m_color);
345
346
    $('#dyn' + id + ' > .view').hide();
347
    $('#dyn' + id + ' > .edit').show();
348
};
349
350
351
Markers.leaveEditMode = function (id, takenew) {
352
    'use strict';
353
354
    if (!takenew) {
355
        $('#dyn' + id + ' > .view').show();
356
        $('#dyn' + id + ' > .edit').hide();
357
        return;
358
    }
359
360
    var m = this.getById(id),
361
        name = $('#dyn' + id + ' > .edit .name').val(),
362
        s_coords = $('#dyn' + id + ' > .edit .coords').val(),
363
        s_radius = $('#dyn' + id + ' > .edit .radius').val(),
364
        s_color = $('#dyn' + id + ' > .edit .color').val(),
365
        coords = Coordinates.fromString(s_coords),
366
        radius = Conversion.getInteger(s_radius, 0, 100000000000),
367
        errors = [];
368
369
    name = name.replace(/[^a-zA-Z0-9\-_]/g, "_");
370
371
    if (!coords) {
372
        errors.push(Lang.t("sidebar.markers.error_badcoordinates").replace(/%1/, s_coords));
373
    }
374
    if (radius === null) {
375
        errors.push(Lang.t("sidebar.markers.error_badradius").replace(/%1/, s_radius));
376
    }
377
    if (!(/#[a-fA-F0-9]{6}$/.test(s_color))) {
378
        errors.push(Lang.t("sidebar.markers.error_badcolor").replace(/%1/, s_color));
379
    }
380
381
    if (errors.length > 0) {
382
        showAlert(Lang.t("dialog.error"), errors.join("<br /><br />"));
383
        return;
384
    }
385
386
    m.setNamePositionRadiusColor(name, coords, radius, s_color.substr(1));
387
388
    $('#dyn' + id + ' > .view').show();
389
    $('#dyn' + id + ' > .edit').hide();
390
391
    Lines.updateLinesMarkerAdded();
392
};
393
394
395
Markers.projectFromMarker = function (id) {
396
    'use strict';
397
398
    trackMarker('project');
399
400
    var mm = Markers.getById(id),
401
        oldpos = mm.getPosition();
402
403
    showProjectionDialog(
404
        function (data1, data2) {
405
            var angle = Conversion.getFloat(data1, 0, 360),
406
                dist = Conversion.getFloat(data2, 0, 100000000000),
407
                newpos,
408
                newmarker;
409
410
            if (angle === null) {
411
                showAlert(
412
                    Lang.t("dialog.error"),
413
                    Lang.t("dialog.projection.error_bad_bearing").replace(/%1/, data1)
414
                );
415
                return;
416
            }
417
418
            if (dist === null) {
419
                showAlert(
420
                    Lang.t("dialog.error"),
421
                    Lang.t("dialog.projection.error_bad_distance").replace(/%1/, data2)
422
                );
423
                return;
424
            }
425
426
            newpos = Coordinates.projection_geodesic(oldpos, angle, dist);
427
            newmarker = Markers.newMarker(newpos, -1, 0, "P_" + mm.getName(), mm.getColor());
428
            if (newmarker) {
429
                showAlert(
430
                    Lang.t("dialog.information"),
431
                    Lang.t("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha())
432
                );
433
            }
434
        }
435
    );
436
};
437