node-red-nodes/parsers/what3words/what3words.html

103 lines
3.8 KiB
HTML
Raw Normal View History

2015-05-29 18:49:19 +02:00
<!--
Copyright 2014 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="what3words">
<div class="form-row">
<label for="node-config-input-pushkey"><i class="fa fa-key"></i> API Key</label>
<input type="password" id="node-config-input-pushkey">
</div>
<div class="form-row">
<label for="node-input-lang"><i class="fa fa-language"></i> Language</label>
<select type="text" id="node-input-lang" style="width:73%;">
<option value="en">English</option>
<option value="de">German</option>
<option value="es">Spanish</option>
<option value="fr">French</option>
<option value="pt">Portuguese</option>
<option value="ru">Russian</option>
<option value="sv">Swedish</option>
<option value="tr">Turkish</option>
</select>
</div>
<br/>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="what3words">
<p>Uses what3words to convert a location to a unique three.word.combination .</p>
<p>Expects either <ul>
<li><b>msg.location.lat</b> and <b>msg.location.lon</b>, or </li>
<li><b>msg.payload</b> to contain a <i>lat,lon</i> string,</li>
</ul> and produces a msg.payload of unique.three.words .</p>
<p>Also does the reverse by accepting a <b>dot (.)</b> separated three.word.string in <b>msg.payload</b>, and adds the corresponding <b>msg.location</b> property.</p>
<p><b>Note:</b> This is an online service and requires a live internet connection.</p>
<p>The API-key is stored in a separate credentials file.</p>
<p>See <i><a href="http://www.what3words.com/" target="_new">what3words</a></i> for more details.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('what3words',{
category: 'location',
defaults: {
title: {value:""},
lang: {value:"en"},
name: {value:""}
},
color:"#DEBD5C",
inputs:1,
outputs:1,
icon: "arrow-in.png",
label: function() {
return this.name||"what3words";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$.getJSON('nma/'+this.id,function(data) {
if (data.hasPassword) {
$('#node-config-input-pushkey').val('__PWRD__');
} else {
$('#node-config-input-pushkey').val('');
}
});
},
oneditsave: function() {
var credentials = {};
var newPass = $('#node-config-input-pushkey').val();
if (newPass != '__PWRD__') {
credentials.pushkey = newPass;
$.ajax({
url: 'nma/'+this.id,
type: 'POST',
data: credentials,
success: function(result){}
});
}
},
ondelete: function() {
$.ajax({
url: 'nma/'+this.id,
type: 'DELETE',
success: function(result) {}
});
}
});
</script>