-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patheco-json-schema-boolean.html
96 lines (82 loc) · 2.26 KB
/
eco-json-schema-boolean.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<link rel="import" href="../polymer/polymer.html"/>
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html"/>
<dom-module id="eco-json-schema-boolean">
<link rel="import" href="../paper-checkbox/paper-checkbox.html"/>
<template>
<style>
:host {
display: block;
}
</style>
<paper-checkbox
id="checkbox"
checked="{{value}}"
invalid="[[error]]">[[_label]]</paper-checkbox>
</template>
<script>
Polymer({
is: 'eco-json-schema-boolean',
properties: {
schema: {
type: Object,
observer: '_schemaChanged'
},
value: {
type: Boolean,
notify: true,
value: false
},
error: {
type: Boolean,
value: false
}
},
ready: function () {
},
detached: function () {
},
_schemaChanged: function () {
var schema = this.schema;
var inputEl = this.$.checkbox;
if (schema.component && schema.component.properties) {
Object.keys(schema.component.properties).forEach(function(prop) {
inputEl[prop] = schema.component.properties[prop];
});
}
if (schema.title) {
this._label = schema.title;
}
},
_isSchemaValue: function (type) {
return this._isSchemaBoolean(type) || this._isSchemaNumber(type) || this._isSchemaString(type);
},
_isSchemaBoolean: function (type) {
if (Array.isArray(type)) {
return type.indexOf('boolean') !== -1;
} else {
return type === 'boolean';
}
},
_isSchemaNumber: function(type) {
if (Array.isArray(type)) {
return type.indexOf('number') !== -1 || type.indexOf('integer') !== -1;
} else {
return type === 'number' || type === 'integer';
}
},
_isSchemaString: function (type) {
if (Array.isArray(type)) {
return type.indexOf('string') !== -1;
} else {
return type === 'string';
}
},
_isSchemaObject: function (type) {
return type === 'object';
},
_isSchemaArray: function (type) {
return type === 'array';
}
});
</script>
</dom-module>