node-red-node-openweathermap
Version:
A Node-RED node that gets the weather report from openweathermap
302 lines (292 loc) • 17.1 kB
HTML
<!--
Copyright 2014,2020 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/html" data-template-name="openweathermap">
<div class="form-row">
<label for="node-input-apikey"><i class="fa fa-key"></i> <span data-i18n="weather.label.apikey"></span></label>
<input type="password" id="node-input-apikey">
</div>
<div class="form-row">
<label for="node-input-language"><i class="fa fa-globe"></i> <span data-i18n="weather.label.language"></span></label>
<select id="node-input-language" style="width:170px">
<option value="en" data-i18n="weather.label.option_lang_en"></option>
<option value="ar" data-i18n="weather.label.option_lang_ar"></option>
<option value="bg" data-i18n="weather.label.option_lang_bg"></option>
<option value="ca" data-i18n="weather.label.option_lang_ca"></option>
<option value="cz" data-i18n="weather.label.option_lang_cz"></option>
<option value="de" data-i18n="weather.label.option_lang_de"></option>
<option value="el" data-i18n="weather.label.option_lang_el"></option>
<option value="es" data-i18n="weather.label.option_lang_es"></option>
<option value="fa" data-i18n="weather.label.option_lang_fa"></option>
<option value="fi" data-i18n="weather.label.option_lang_fi"></option>
<option value="fr" data-i18n="weather.label.option_lang_fr"></option>
<option value="gl" data-i18n="weather.label.option_lang_gl"></option>
<option value="hr" data-i18n="weather.label.option_lang_hr"></option>
<option value="hu" data-i18n="weather.label.option_lang_hu"></option>
<option value="it" data-i18n="weather.label.option_lang_it"></option>
<option value="ja" data-i18n="weather.label.option_lang_ja"></option>
<option value="kr" data-i18n="weather.label.option_lang_kr"></option>
<option value="la" data-i18n="weather.label.option_lang_la"></option>
<option value="lt" data-i18n="weather.label.option_lang_lt"></option>
<option value="mk" data-i18n="weather.label.option_lang_mk"></option>
<option value="nl" data-i18n="weather.label.option_lang_nl"></option>
<option value="pl" data-i18n="weather.label.option_lang_pl"></option>
<option value="pt" data-i18n="weather.label.option_lang_pt"></option>
<option value="ro" data-i18n="weather.label.option_lang_ro"></option>
<option value="ru" data-i18n="weather.label.option_lang_ru"></option>
<option value="sk" data-i18n="weather.label.option_lang_sk"></option>
<option value="sl" data-i18n="weather.label.option_lang_sl"></option>
<option value="sv" data-i18n="weather.label.option_lang_sv"></option>
<option value="tr" data-i18n="weather.label.option_lang_tr"></option>
<option value="uk" data-i18n="weather.label.option_lang_uk"></option>
<option value="vi" data-i18n="weather.label.option_lang_vi"></option>
<option value="zh_tw" data-i18n="weather.label.option_lang_zh_tw"></option>
<option value="zh" data-i18n="weather.label.option_lang_zh"></option>
<option value="msg" data-i18n="weather.label.option_lang_xx"></option>
</select>
</div>
<div class="form-row">
<label><span> </span></label>
<select id="node-input-wtype" style="width:300px">
<option value="current" data-i18n="weather.label.option_current"></option>
<option value="forecast" data-i18n="weather.label.option_5dayforecast"></option>
<option value="onecall" data-i18n="weather.label.option_onecall"></option>
</select>
</div>
<div class="form-row" id="weather-location-type-select-row">
<label for="weather-location-type-select"><i class="fa fa-globe"></i> <span data-i18n="weather.label.location"></span></label>
<select id="weather-location-type-select" style="width:300px">
<option value="city" data-i18n="weather.label.option_city"></option>
<option value="coordinates" data-i18n="weather.label.option_coordinates"></option>
</select>
</div>
<div class="form-row weather-location-type" id="weather-location-type-city">
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.city"></span></label>
<input type="text" class="weather-location-input" style="width: 180px; margin-bottom:7px" id="node-input-city" data-i18n="[placeholder]weather.placeholder.city"></input>
</br>
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.country"></span></label>
<input type="text" class="weather-location-input" style="width: 180px; margin-bottom:7px" id="node-input-country" data-i18n="[placeholder]weather.placeholder.country"></input>
</div>
<div class="form-row weather-location-type hidden" id="weather-location-type-coordinates">
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.latitude"></span></label><input type="text" class="weather-location-input" id="node-input-lat" style="width: 180px; margin-bottom:7px" data-i18n="[placeholder]weather.placeholder.latitude">
</br>
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.longitude"></span></label><input type="text" class="weather-location-input" id="node-input-lon" style="width: 180px; margin-bottom:7px" data-i18n="[placeholder]weather.placeholder.longitude">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> <span data-i18n="weather.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]weather.placeholder.name">
</div>
<div class="form-tips">
<span data-i18n="[html]weather.tip"></span>
</div>
<div class="form-tips">
<span data-i18n="[html]weather.note"></span>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('openweathermap',{
category: 'weather',
color: '#FFCC66',
defaults: {
name: {value:""},
wtype: {value:"current"},
lon: {value:"", validate:function(v) {return ((v>=-180) && (v<=180));} },
lat: {value:"", validate:function(v) {return ((v>=-90) && (v<=90));} },
city: {value:""},
country: {value:""},
language: {value:"en"},
},
credentials: {
apikey: {type:"password", required:true}
},
inputs:1,
outputs:1,
icon: "weather.png",
label: function() {
return this.name||this.city||this._("weather.label.weather");
},
oneditprepare: function() {
$("#node-input-wtype").change(function() {
var type = $("#node-input-wtype option:selected").val();
if(type === "onecall") {
$("#weather-location-type-select").val("coordinates");
$("#weather-location-type-select-row").hide();
$(".weather-location-type").hide();
$("#weather-location-type-coordinates").show();
} else {
$("#weather-location-type-select-row").show();
$("#weather-location-type-select").change(function() {
var id = $("#weather-location-type-select option:selected").val();
$(".weather-location-type").hide();
$("#weather-location-type-"+id).show();
});
if (this.lon !== ""||this.lat !== "") {
$("#weather-location-type-select").val("coordinates");
} else {
$("#weather-location-type-select").val("city");
}
var id = $("#weather-location-type-select option:selected").val();
$(".weather-location-type").hide();
$("#weather-location-type-"+id).show();
}
}.bind(this));
},
oneditsave: function() {
var type = $("#weather-location-type-select option:selected").val();
if (type == "coordinates") {
$("#node-input-city").val("");
$("#node-input-country").val("");
} else if (type == "city") {
$("#node-input-lon").val("");
$("#node-input-lat").val("");
}
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<script type="text/html" data-template-name="openweathermap in">
<div class="form-row">
<label for="node-input-apikey"><i class="fa fa-key"></i> <span data-i18n="weather.label.apikey"></span></label>
<input type="password" id="node-input-apikey">
</div>
<div class="form-row">
<label for="node-input-language"><i class="fa fa-globe"></i> <span data-i18n="weather.label.language"></span></label>
<select id="node-input-language" style="width:170px">
<option value="en" data-i18n="weather.label.option_lang_en"></option>
<option value="ar" data-i18n="weather.label.option_lang_ar"></option>
<option value="bg" data-i18n="weather.label.option_lang_bg"></option>
<option value="ca" data-i18n="weather.label.option_lang_ca"></option>
<option value="cz" data-i18n="weather.label.option_lang_cz"></option>
<option value="de" data-i18n="weather.label.option_lang_de"></option>
<option value="el" data-i18n="weather.label.option_lang_el"></option>
<option value="es" data-i18n="weather.label.option_lang_es"></option>
<option value="fa" data-i18n="weather.label.option_lang_fa"></option>
<option value="fi" data-i18n="weather.label.option_lang_fi"></option>
<option value="fr" data-i18n="weather.label.option_lang_fr"></option>
<option value="gl" data-i18n="weather.label.option_lang_gl"></option>
<option value="hr" data-i18n="weather.label.option_lang_hr"></option>
<option value="hu" data-i18n="weather.label.option_lang_hu"></option>
<option value="it" data-i18n="weather.label.option_lang_it"></option>
<option value="ja" data-i18n="weather.label.option_lang_ja"></option>
<option value="kr" data-i18n="weather.label.option_lang_kr"></option>
<option value="la" data-i18n="weather.label.option_lang_la"></option>
<option value="lt" data-i18n="weather.label.option_lang_lt"></option>
<option value="mk" data-i18n="weather.label.option_lang_mk"></option>
<option value="nl" data-i18n="weather.label.option_lang_nl"></option>
<option value="pl" data-i18n="weather.label.option_lang_pl"></option>
<option value="pt" data-i18n="weather.label.option_lang_pt"></option>
<option value="ro" data-i18n="weather.label.option_lang_ro"></option>
<option value="ru" data-i18n="weather.label.option_lang_ru"></option>
<option value="sk" data-i18n="weather.label.option_lang_sk"></option>
<option value="sl" data-i18n="weather.label.option_lang_sl"></option>
<option value="sv" data-i18n="weather.label.option_lang_sv"></option>
<option value="tr" data-i18n="weather.label.option_lang_tr"></option>
<option value="uk" data-i18n="weather.label.option_lang_uk"></option>
<option value="vi" data-i18n="weather.label.option_lang_vi"></option>
<option value="zh_tw" data-i18n="weather.label.option_lang_zh_tw"></option>
<option value="zh" data-i18n="weather.label.option_lang_zh"></option>
<option value="msg" data-i18n="weather.label.option_lang_xx"></option>
</select>
</div>
<div class="form-row">
<label><span> </span></label>
<select id="node-input-wtype" style="width:300px">
<option value="current" data-i18n="weather.label.option_current"></option>
<option value="forecast" data-i18n="weather.label.option_5dayforecast"></option>
</select>
</div>
<div class="form-row">
<label for="weather-location-type-select"><i class="fa fa-globe"></i> <span data-i18n="weather.label.location"></span></label>
<select id="weather-location-type-select" style="width:300px">
<option value="city" data-i18n="weather.label.option_city"></option>
<option value="coordinates" data-i18n="weather.label.option_coordinates"></option>
</select>
</div>
<div class="form-row weather-location-type" id="weather-location-type-city">
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.city"></span></label>
<input type="text" class="weather-location-input" style="width: 180px; margin-bottom:7px" id="node-input-city" data-i18n="[placeholder]weather.placeholder.city"></input>
</br>
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.country"></span></label>
<input type="text" class="weather-location-input" style="width: 180px; margin-bottom:7px" id="node-input-country" data-i18n="[placeholder]weather.placeholder.country"></input>
</div>
<div class="form-row weather-location-type hidden" id="weather-location-type-coordinates">
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.latitude"></span></label><input type="text" class="weather-location-input" id="node-input-lat" style="width: 180px; margin-bottom:7px" data-i18n="[placeholder]weather.placeholder.latitude">
</br>
<label for=""><i class="weather-location-type"></i> <span data-i18n="weather.label.longitude"></span></label><input type="text" class="weather-location-input" id="node-input-lon" style="width: 180px; margin-bottom:7px" data-i18n="[placeholder]weather.placeholder.longitude">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> <span data-i18n="weather.label.name"></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]weather.placeholder.name">
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('openweathermap in',{
category: 'weather',
color: '#FFCC66',
defaults: {
name: {value:""},
wtype: {value:"current"},
lon: {value:"", validate:function(v) {return ((v>=-180) && (v<=180));} },
lat: {value:"", validate:function(v) {return ((v>=-90) && (v<=90));} },
city: {value:""},
country: {value:""},
language: {value:"en"}
},
credentials: {
apikey: {type:"password", required:true}
},
inputs:0,
outputs:1,
icon: "weather.png",
label: function() {
return this.name||this.city||this._("weather.label.weather");
},
oneditprepare: function() {
$("#weather-location-type-select").change(function() {
var id = $("#weather-location-type-select option:selected").val();
$(".weather-location-type").hide();
$("#weather-location-type-"+id).show();
});
if (this.lon !== ""||this.lat !== "") {
$("#weather-location-type-select").val("coordinates");
} else {
$("#weather-location-type-select").val("city");
}
var id = $("#weather-location-type-select option:selected").val();
$(".weather-location-type").hide();
$("#weather-location-type-"+id).show();
},
oneditsave: function() {
var type = $("#weather-location-type-select option:selected").val();
if (type == "coordinates") {
$("#node-input-city").val("");
$("#node-input-country").val("");
} else if (type == "city") {
$("#node-input-lon").val("");
$("#node-input-lat").val("");
}
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});
</script>
<style>
.weather-location-type {
padding-left: 110px;
}
.weather-location-input{
margin-bottom: 10px;
}
</style>