From 283400f21171daf05edd04105a4a19f3c231fda7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Sandstr=C3=B6m?= Date: Thu, 24 Sep 2015 22:37:30 +0200 Subject: [PATCH] support code format --- .../more-info-alarm_control_panel.html | 8 ++--- .../more-info-alarm_control_panel.js | 35 ++++++++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/more-infos/more-info-alarm_control_panel.html b/src/more-infos/more-info-alarm_control_panel.html index e721cca8a2..ba8c5c0519 100644 --- a/src/more-infos/more-info-alarm_control_panel.html +++ b/src/more-infos/more-info-alarm_control_panel.html @@ -6,12 +6,12 @@ diff --git a/src/more-infos/more-info-alarm_control_panel.js b/src/more-infos/more-info-alarm_control_panel.js index 72089cfca3..8230effa2d 100644 --- a/src/more-infos/more-info-alarm_control_panel.js +++ b/src/more-infos/more-info-alarm_control_panel.js @@ -34,17 +34,44 @@ export default new Polymer({ type: Boolean, value: false, }, + code_input_visible: { + type: Boolean, + value: false, + }, + code_input_enabled: { + type: Boolean, + value: false, + }, + code_format: { + type: String, + value: '', + }, + code_valid: { + type: Boolean, + value: false, + }, }, - enteredCodeChanged(ev) { - this.entered_code = ev.target.value; + validate_code(code) { + if(this.code_format == null){ + this.code_valid = true; + return; + } + var re = new RegExp(this.code_format); + this.code_valid = re.test(code); + }, + entered_code_changed(ev) { + this.validate_code(ev.target.value); }, stateObjChanged(newVal) { if (newVal) { - this.disarm_button_enabled = newVal.state === 'armed_home' || newVal.state === 'armed_away'; + this.code_format = newVal.attributes.code_format; + this.validate_code(this.entered_code); + this.code_input_visible = newVal.attributes.code_format != null; + this.code_input_enabled = (newVal.state === 'armed_home' || newVal.state === 'armed_away' || newVal.state === 'disarmed'); + this.disarm_button_enabled = (newVal.state === 'armed_home' || newVal.state === 'armed_away'); this.arm_home_button_enabled = newVal.state === 'disarmed'; this.arm_away_button_enabled = newVal.state === 'disarmed'; } - this.async(() => this.fire('iron-resize'), 500); }, callService(service, data) {