* Version bump to 20180510.1 * Fix hass util * Fix translations * Bye paper-time-input * Add webpack config * Add webpack to package.json * Fix translation import * Disable web animations polyfill bad import * Disable importHref import * Update webpack config to build authorize.js * Build translations json * Build frontend correctly * Run eslint --fix * Load markdown JS on demand (#1155) * Add HTML imports (#1160) * Fix localize (#1161) * Fix Roboto in build (#1162) * Load web animations polyfill (#1163) * P3: Fix chart js (#1164) * P3: Fix Chart JS * Update timeline package * P3: panel resolver (#1165) * WIP * Initial importing of panels * Fix panel resolver * Fix automation and script editor (#1166) * Expose Polymer and Polymer.Element on window (#1167) * Remove unused import * eslint --fix * Es5 build (#1168) * Build for ES5 * Fix build_frontend * Remove stale comment * Migrate to use paper-material-styles (#1170) * Send parsed date to history/logbook (#1171) * Fork app storage behavior (#1172) * Add paper input with type time (#1173) * Fix authorize * Lint * Sort imports * Lint * Remove eslint-html * Do not lint authorize.html * Fix polymer lint * Try chrome 62 for wct * P3: Add patched iconset (#1175) * Add patched iconset * Lint * Test with latest Chrome again * Use less window.hassUtil * Teporarily use my fecha fork * Import correct intl.messageFormat * Update wct-browser-legacy to 1.0.0 * Include polyfill in right place * Fix IntlMessageFormat * Fix test not having a global scope * Rollup <_< * Fork app-localize-behavior * Disable wct tests * Lint
122 lines
4.0 KiB
JavaScript
122 lines
4.0 KiB
JavaScript
import '@polymer/paper-checkbox/paper-checkbox.js';
|
|
import '@polymer/paper-dropdown-menu/paper-dropdown-menu.js';
|
|
import '@polymer/paper-input/paper-input.js';
|
|
import '@polymer/paper-item/paper-item.js';
|
|
import '@polymer/paper-listbox/paper-listbox.js';
|
|
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
|
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
|
|
import '../util/hass-mixins.js';
|
|
import './ha-paper-slider.js';
|
|
|
|
class HaForm extends window.hassMixins.EventsMixin(PolymerElement) {
|
|
static get template() {
|
|
return html`
|
|
<style>
|
|
.error {
|
|
color: red;
|
|
}
|
|
</style>
|
|
<template is="dom-if" if="[[_isArray(schema)]]" restamp="">
|
|
<template is="dom-if" if="[[error.base]]">
|
|
[[computeError(error.base, schema)]]
|
|
</template>
|
|
|
|
<template is="dom-repeat" items="[[schema]]">
|
|
<ha-form data="[[_getValue(data, item)]]" schema="[[item]]" error="[[_getValue(error, item)]]" on-data-changed="_valueChanged" compute-label="[[computeLabel]]" compute-error="[[computeError]]"></ha-form>
|
|
</template>
|
|
</template>
|
|
<template is="dom-if" if="[[!_isArray(schema)]]" restamp="">
|
|
<template is="dom-if" if="[[error]]">
|
|
<div class="error">[[computeError(error, schema)]]</div>
|
|
</template>
|
|
|
|
<template is="dom-if" if="[[_equals(schema.type, "string")]]" restamp="">
|
|
<paper-input label="[[computeLabel(schema)]]" value="{{data}}"></paper-input>
|
|
</template>
|
|
|
|
<template is="dom-if" if="[[_equals(schema.type, "integer")]]" restamp="">
|
|
<template is="dom-if" if="[[_isRange(schema)]]" restamp="">
|
|
<div>
|
|
[[computeLabel(schema)]]
|
|
<ha-paper-slider pin="" value="{{data}}" min="[[schema.valueMin]]" max="[[schema.valueMax]]"></ha-paper-slider>
|
|
</div>
|
|
</template>
|
|
<template is="dom-if" if="[[!_isRange(schema)]]" restamp="">
|
|
<paper-input label="[[computeLabel(schema)]]" value="{{data}}" type="number"></paper-input>
|
|
</template>
|
|
</template>
|
|
|
|
<template is="dom-if" if="[[_equals(schema.type, "float")]]" restamp="">
|
|
<!--TODO-->
|
|
<paper-input label="[[computeLabel(schema)]]" value="{{data}}"></paper-input>
|
|
</template>
|
|
|
|
<template is="dom-if" if="[[_equals(schema.type, "boolean")]]" restamp="">
|
|
<paper-checkbox checked="{{data}}">[[computeLabel(schema)]]</paper-checkbox>
|
|
</template>
|
|
|
|
<template is="dom-if" if="[[_equals(schema.type, "select")]]" restamp="">
|
|
<paper-dropdown-menu label="[[computeLabel(schema)]]">
|
|
<paper-listbox slot="dropdown-content" attr-for-selected="item-name" selected="{{data}}">
|
|
<template is="dom-repeat" items="[[schema.options]]">
|
|
<paper-item item-name\$="[[item]]">[[item]]</paper-item>
|
|
</template>
|
|
</paper-listbox>
|
|
</paper-dropdown-menu>
|
|
</template>
|
|
|
|
</template>
|
|
`;
|
|
}
|
|
|
|
static get is() { return 'ha-form'; }
|
|
|
|
static get properties() {
|
|
return {
|
|
data: {
|
|
type: Object,
|
|
notify: true,
|
|
},
|
|
schema: Object,
|
|
error: Object,
|
|
|
|
// A function that will computes the label to be displayed for a given
|
|
// schema object.
|
|
computeLabel: {
|
|
type: Function,
|
|
value: () => schema => schema && schema.name,
|
|
},
|
|
|
|
// A function that will computes an error message to be displayed for a
|
|
// given error ID, and relevant schema object
|
|
computeError: {
|
|
type: Function,
|
|
value: () => (error, schema) => error, // eslint-disable-line no-unused-vars
|
|
},
|
|
};
|
|
}
|
|
|
|
_isArray(val) {
|
|
return Array.isArray(val);
|
|
}
|
|
|
|
_isRange(schema) {
|
|
return ('valueMin' in schema) && ('valueMax' in schema);
|
|
}
|
|
|
|
_equals(a, b) {
|
|
return a === b;
|
|
}
|
|
|
|
_getValue(obj, item) {
|
|
return obj[item.name];
|
|
}
|
|
|
|
_valueChanged(ev) {
|
|
this.set(['data', ev.model.item.name], ev.detail.value);
|
|
}
|
|
}
|
|
|
|
customElements.define(HaForm.is, HaForm);
|