mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 01:46:35 +00:00
fixed some code review comments
This commit is contained in:
parent
5a39c16437
commit
793e3ec6c3
@ -6,12 +6,12 @@
|
|||||||
<dom-module id='more-info-alarm_control_panel'>
|
<dom-module id='more-info-alarm_control_panel'>
|
||||||
<template>
|
<template>
|
||||||
<div class='layout horizontal'>
|
<div class='layout horizontal'>
|
||||||
<paper-input label='code' input='[[entered_code]]' pattern='[[code_format]]' on-keyup='entered_code_changed' type='password' hidden$='[[!code_input_visible]]' disabled$='[[!code_input_enabled]]'></paper-input>
|
<paper-input label='code' value$='{{enteredCode}}' pattern$='[[codeFormat]]' type='password' hidden$='[[!codeInputVisible]]' disabled$='[[!codeInputEnabled]]'></paper-input>
|
||||||
</div>
|
</div>
|
||||||
<div class='layout horizontal'>
|
<div class='layout horizontal'>
|
||||||
<paper-button on-tap='handleDisarmTap' hidden$='[[!disarm_button_enabled]]' disabled$='[[!code_valid]]'>Disarm</paper-button>
|
<paper-button on-tap='handleDisarmTap' hidden$='[[!disarmButtonVisible]]' disabled$='[[!codeValid]]'>Disarm</paper-button>
|
||||||
<paper-button on-tap='handleHomeTap' hidden$='[[!arm_home_button_enabled]]' disabled$='[[!code_valid]]'>Arm Home</paper-button>
|
<paper-button on-tap='handleHomeTap' hidden$='[[!armHomeButtonVisible]]' disabled$=[[!codeValid]]>Arm Home</paper-button>
|
||||||
<paper-button on-tap='handleAwayTap' hidden$='[[!arm_away_button_enabled]]' disabled$='[[!code_valid]]'>Arm Away</paper-button>
|
<paper-button on-tap='handleAwayTap' hidden$='[[!armAwayButtonVisible]]' disabled$='[[!codeValid]]'>Arm Away</paper-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</dom-module>
|
</dom-module>
|
||||||
|
@ -5,72 +5,72 @@ import Polymer from '../polymer';
|
|||||||
export default new Polymer({
|
export default new Polymer({
|
||||||
is: 'more-info-alarm_control_panel',
|
is: 'more-info-alarm_control_panel',
|
||||||
handleDisarmTap() {
|
handleDisarmTap() {
|
||||||
this.callService('alarm_disarm', {code: this.entered_code});
|
this.callService('alarm_disarm', {code: this.enteredCode});
|
||||||
},
|
},
|
||||||
handleHomeTap() {
|
handleHomeTap() {
|
||||||
this.callService('alarm_arm_home', {code: this.entered_code});
|
this.callService('alarm_arm_home', {code: this.enteredCode});
|
||||||
},
|
},
|
||||||
handleAwayTap() {
|
handleAwayTap() {
|
||||||
this.callService('alarm_arm_away', {code: this.entered_code});
|
this.callService('alarm_arm_away', {code: this.enteredCode});
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
stateObj: {
|
stateObj: {
|
||||||
type: Object,
|
type: Object,
|
||||||
observer: 'stateObjChanged',
|
observer: 'stateObjChanged',
|
||||||
},
|
},
|
||||||
entered_code: {
|
enteredCode: {
|
||||||
type: String,
|
type: String,
|
||||||
value: '',
|
value: '',
|
||||||
},
|
},
|
||||||
disarm_button_enabled: {
|
disarmButtonVisible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
arm_home_button_enabled: {
|
armHomeButtonVisible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
arm_away_button_enabled: {
|
armAwayButtonVisible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
code_input_visible: {
|
codeInputVisible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
code_input_enabled: {
|
codeInputEnabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
code_format: {
|
codeFormat: {
|
||||||
type: String,
|
type: String,
|
||||||
value: '',
|
value: '',
|
||||||
},
|
},
|
||||||
code_valid: {
|
codeValid: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
computed: 'validateCode(enteredCode, codeFormat)',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
validate_code(code) {
|
validateCode: function(code, format) {
|
||||||
const re = new RegExp(this.code_format);
|
const re = new RegExp(format);
|
||||||
if (this.code_format === null) {
|
if (format === null) {
|
||||||
this.code_valid = true;
|
return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
this.code_valid = re.test(code);
|
return re.test(code);
|
||||||
},
|
|
||||||
entered_code_changed(ev) {
|
|
||||||
this.validate_code(ev.target.value);
|
|
||||||
},
|
},
|
||||||
stateObjChanged(newVal) {
|
stateObjChanged(newVal) {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
this.code_format = newVal.attributes.code_format;
|
this.codeFormat = newVal.attributes.code_format;
|
||||||
this.validate_code(this.entered_code);
|
this.codeInputVisible = this.codeFormat !== null;
|
||||||
this.code_input_visible = newVal.attributes.code_format !== null;
|
this.codeInputEnabled = (
|
||||||
this.code_input_enabled = (newVal.state === 'armed_home' || newVal.state === 'armed_away' || newVal.state === 'disarmed');
|
newVal.state === 'armed_home' ||
|
||||||
this.disarm_button_enabled = (newVal.state === 'armed_home' || newVal.state === 'armed_away');
|
newVal.state === 'armed_away' ||
|
||||||
this.arm_home_button_enabled = newVal.state === 'disarmed';
|
newVal.state === 'disarmed');
|
||||||
this.arm_away_button_enabled = newVal.state === 'disarmed';
|
this.disarmButtonVisible = (
|
||||||
|
newVal.state === 'armed_home' ||
|
||||||
|
newVal.state === 'armed_away');
|
||||||
|
this.armHomeButtonVisible = newVal.state === 'disarmed';
|
||||||
|
this.armAwayButtonVisible = newVal.state === 'disarmed';
|
||||||
}
|
}
|
||||||
this.async(() => this.fire('iron-resize'), 500);
|
this.async(() => this.fire('iron-resize'), 500);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user