-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfd-polymer-properties.html
100 lines (94 loc) · 2.45 KB
/
fd-polymer-properties.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
97
98
99
100
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-icons/core-icons.html">
<polymer-element name="fd-properties" attributes="properties">
<template>
<style>
:host {
display: block;
width: 100%;
}
.fd-prop-name{
background-color: green;
color: white;
border-radius: 5px;
margin: 0px 5px;
padding: 1px 2px;
}
.fd-prop-value{
background-color: yellow;
color: #444;
border-radius: 5px;
border:none;
margin: 1px 1px;
}
.fd-pm-icon{
border-radius: 50%;
border: 2px solid #444;
color: #444;
}
</style>
<div layout vertical right>
<div >{{'properties' | translate}}:</div>
<template repeat="{{item in items}}">
<div layout horizontal left>
<div class="fd-prop-name">{{item}}</div>
=
<div class="fd-prop-value">
<input id="{{item}}"
type="text" class="fd-prop-value"
value="{{properties[item]}}" size="{{properties[item].length}}"
on-blur="{{updatePropValue}}">
</input>
</div>
<core-icon class="fd-pm-icon" icon="delete" on-tap="{{delProp}}" data="{{item}}">
</core-icon>
</div>
</template>
<!-- new property -->
<div layout horizontal left>
<div class="fd-prop-name">
<input id="newPropName"
type="text" class="fd-prop-name"/>
</div>
=
<div class="fd-prop-value">
<input id="newPropValue"
type="text" class="fd-prop-value"/>
</div>
<core-icon class="fd-pm-icon" icon="add" on-tap="{{addProp}}">
</core-icon>
</div>
</div>
</template>
<script>
Polymer("fd-properties",{
items: undefined,
updateItems: function(){
if (!!this.properties){
this.items = Object.keys(this.properties);
}
},
propertiesChanged: function(){
this.updateItems();
},
// filter function to use in looping objects
delProp: function(e,d,t){
toBeRemoved=t.attributes['data'].value;
delete this.properties[toBeRemoved];
this.updateItems();
},
addProp: function(){
this.properties[this.$.newPropName.value] = this.$.newPropValue.value;
this.updateItems();
this.$.newPropName.value = "";
this.$.newPropValue.value = "";
},
updatePropValue: function(e,d,target){
var id = target.attributes['id'].value;
this.properties[id].value=target.value;
}
});
</script>
</polymer-element>