Added error handling in frontend debug forms

This commit is contained in:
Paulus Schoutsen 2015-01-14 23:56:53 -08:00
parent 8c62ae4ce5
commit ced3d595cc
3 changed files with 43 additions and 25 deletions

View file

@ -10,7 +10,11 @@
<polymer-element name="event-fire-dialog" attributes="api">
<template>
<ha-action-dialog id="dialog" heading="Fire Event" class='two-column'>
<ha-action-dialog
id="dialog"
heading="Fire Event"
class='two-column'
closeSelector='[dismissive]'>
<div layout horizontal>
<div class='ha-form'>
@ -68,15 +72,15 @@ Polymer({
},
clickFireEvent: function() {
var data;
if(this.$.inputData.value !== "") {
data = JSON.parse(this.$.inputData.value);
} else {
data = {};
try {
this.api.fire_event(
this.$.inputType.value,
this.$.inputData.value ? JSON.parse(this.$.inputData.value) : {});
this.$.dialog.close();
} catch (err) {
alert("Error parsing JSON: " + err);
}
this.api.fire_event(this.$.inputType.value, data);
}
});
</script>

View file

@ -10,7 +10,10 @@
<polymer-element name="service-call-dialog" attributes="api">
<template>
<ha-action-dialog id="dialog" heading="Call Service">
<ha-action-dialog
id="dialog"
heading="Call Service"
closeSelector='[dismissive]'>
<core-style ref='ha-dialog'></core-style>
@ -45,7 +48,7 @@
Polymer({
ready: function() {
// to ensure callback methods work..
this.serviceSelected = this.serviceSelected.bind(this)
this.serviceSelected = this.serviceSelected.bind(this);
},
show: function(domain, service, serviceData) {
@ -65,16 +68,17 @@ Polymer({
},
clickCallService: function() {
var data;
if(this.$.inputData.value != "") {
data = JSON.parse(this.$.inputData.value);
}
try {
this.api.call_service(
this.$.inputDomain.value,
this.$.inputService.value,
data);
this.$.inputData.value ? JSON.parse(this.$.inputData.value) : {});
this.$.dialog.close();
} catch (err) {
alert("Error parsing JSON: " + err);
}
}
});
</script>

View file

@ -9,12 +9,16 @@
<polymer-element name="state-set-dialog" attributes="api">
<template>
<ha-action-dialog id="dialog" heading="Set State">
<ha-action-dialog
id="dialog"
heading="Set State"
closeSelector='[dismissive]'>
<core-style ref='ha-dialog'></core-style>
<p>
This dialog will update the representation of the device within Home Assistant. This will not communicate with the actual device.
This dialog will update the representation of the device within Home Assistant.<br />
This will not communicate with the actual device.
</p>
<div layout horizontal>
@ -81,12 +85,18 @@ Polymer({
this.setStateData(state.attributes);
},
clickSetState: function() {
this.api.set_state(
this.$.inputEntityID.value,
this.$.inputState.value,
JSON.parse(this.$.inputData.value)
clickSetState: function(ev) {
try {
this.api.set_state(
this.$.inputEntityID.value,
this.$.inputState.value,
this.$.inputData.value ? JSON.parse(this.$.inputData.value) : {}
);
this.$.dialog.close();
} catch (err) {
alert("Error parsing JSON: " + err);
}
}
});
</script>