parent
785abe5b99
commit
fc598fae2e
4 changed files with 68 additions and 1 deletions
|
|
@ -122,4 +122,7 @@
|
||||||
'car-test'
|
'car-test'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// regex needs to be in sync with server, see ServerHandler.getTrackName()
|
||||||
|
BR.conf.tracknameAllowedChars = 'a-zA-Z0-9 \\._\\-';
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,20 @@ footer {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input#trackname:invalid,
|
||||||
|
input#trackname:focus:invalid {
|
||||||
|
border-color: orange;
|
||||||
|
}
|
||||||
|
:not(output):-moz-ui-invalid:not(:focus),
|
||||||
|
:not(output):-moz-ui-invalid:-moz-focusring:not(:focus) {
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.validation-warning {
|
||||||
|
color: orange;
|
||||||
|
font-size: small;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* elevation diagram
|
* elevation diagram
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -594,6 +594,10 @@
|
||||||
class="form-control"
|
class="form-control"
|
||||||
id="trackname"
|
id="trackname"
|
||||||
/>
|
/>
|
||||||
|
<span
|
||||||
|
id="trackname-message"
|
||||||
|
class="validation-warning"
|
||||||
|
></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<fieldset id="export-format" class="form-group">
|
<fieldset id="export-format" class="form-group">
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,24 @@ BR.Export = L.Class.extend({
|
||||||
initialize: function(router) {
|
initialize: function(router) {
|
||||||
this.router = router;
|
this.router = router;
|
||||||
this.exportButton = $('#exportButton');
|
this.exportButton = $('#exportButton');
|
||||||
|
var trackname = (this.trackname = document.getElementById('trackname'));
|
||||||
|
this.tracknameAllowedChars = BR.conf.tracknameAllowedChars;
|
||||||
|
|
||||||
|
if (this.tracknameAllowedChars) {
|
||||||
|
this.tracknameMessage = document.getElementById(
|
||||||
|
'trackname-message'
|
||||||
|
);
|
||||||
|
var patternRegex = new RegExp(
|
||||||
|
'[' + this.tracknameAllowedChars + ']+'
|
||||||
|
);
|
||||||
|
|
||||||
|
// warn about special characters getting removed by server quick fix (#194)
|
||||||
|
trackname.pattern = patternRegex.toString().slice(1, -1);
|
||||||
|
trackname.addEventListener(
|
||||||
|
'input',
|
||||||
|
L.bind(this._validationMessage, this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.exportButton.on('click', L.bind(this._generateTrackname, this));
|
this.exportButton.on('click', L.bind(this._generateTrackname, this));
|
||||||
L.DomUtil.get('submitExport').onclick = L.bind(this._export, this);
|
L.DomUtil.get('submitExport').onclick = L.bind(this._export, this);
|
||||||
|
|
@ -53,8 +71,25 @@ BR.Export = L.Class.extend({
|
||||||
link.dispatchEvent(evt);
|
link.dispatchEvent(evt);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_validationMessage: function() {
|
||||||
|
var trackname = this.trackname;
|
||||||
|
var replaceRegex = new RegExp(
|
||||||
|
'[^' + this.tracknameAllowedChars + ']',
|
||||||
|
'g'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (trackname.validity.patternMismatch) {
|
||||||
|
var replaced = trackname.value.replace(replaceRegex, '');
|
||||||
|
var patternStr = this.tracknameAllowedChars.replace(/\\/g, '');
|
||||||
|
this.tracknameMessage.textContent =
|
||||||
|
'[' + patternStr + '] --> ' + replaced;
|
||||||
|
} else {
|
||||||
|
this.tracknameMessage.textContent = '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_generateTrackname: function() {
|
_generateTrackname: function() {
|
||||||
var trackname = document.getElementById('trackname');
|
var trackname = this.trackname;
|
||||||
this._getCityAtPosition(
|
this._getCityAtPosition(
|
||||||
this.latLngs[0],
|
this.latLngs[0],
|
||||||
L.bind(function(from) {
|
L.bind(function(from) {
|
||||||
|
|
@ -63,6 +98,9 @@ BR.Export = L.Class.extend({
|
||||||
L.bind(function(to) {
|
L.bind(function(to) {
|
||||||
var distance = document.getElementById('distance')
|
var distance = document.getElementById('distance')
|
||||||
.innerHTML;
|
.innerHTML;
|
||||||
|
if (this.tracknameAllowedChars) {
|
||||||
|
distance = distance.replace(',', '.'); // temp. fix (#202)
|
||||||
|
}
|
||||||
if (!from || !to) {
|
if (!from || !to) {
|
||||||
trackname.value = null;
|
trackname.value = null;
|
||||||
} else if (from === to) {
|
} else if (from === to) {
|
||||||
|
|
@ -76,6 +114,14 @@ BR.Export = L.Class.extend({
|
||||||
{ from: from, to: to, distance: distance }
|
{ from: from, to: to, distance: distance }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.tracknameAllowedChars) {
|
||||||
|
// temp. fix: replace and remove characters that will get removed by server quick fix (#194)
|
||||||
|
trackname.value = trackname.value
|
||||||
|
.replace(/[>)]/g, '')
|
||||||
|
.replace(/ \(/g, ' - ');
|
||||||
|
this._validationMessage();
|
||||||
|
}
|
||||||
}, this)
|
}, this)
|
||||||
);
|
);
|
||||||
}, this)
|
}, this)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue