-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattribute-editor.html
112 lines (100 loc) · 3.7 KB
/
attribute-editor.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
101
102
103
104
105
106
107
108
109
110
111
112
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-dialog-scrollable/paper-dialog-scrollable.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../iron-signals/iron-signals.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<dom-module id="attribute-editor">
<template>
<style>
:host {
display: inline:block;
padding: 5px;
background: white;
position: relative;
top: -10px;
left: -30px;
border-radius: 5px;
}
iron-icon {
cursor: pointer;
}
</style>
<iron-icon icon="icons:create" on-click="open"></iron-icon>
<paper-dialog>
<h2>Edit Attributes</h2>
<paper-dialog-scrollable>
<template is="dom-repeat" items="{{localusercontent}}">
<paper-input label$="{{item.key}}" value$="[[item.value]]" on-change="_handleValueChange"></paper-input>
</template>
</paper-dialog-scrollable>
<div class="buttons">
<paper-button dialog-dismiss>Cancel</paper-button>
<paper-button on-click="_handleSave">Accept</paper-button>
</div>
</paper-dialog>
<iron-signals on-iron-signal-attribute-save="_initiateAttributeSave"></iron-signals>
</template>
<script>
Polymer({
is: 'attribute-editor',
properties: {
usercontent: {
type: Object,
notify: true,
},
localusercontent: {
type: Object,
notify: true
},
path: {
type: String,
value: '',
notify: true,
reflectToAttribute: true
}
},
open: function() {
this.set('localusercontent',[]);
this._convertObjToArray(this.usercontent)
this.$$('paper-dialog').open();
},
_handleSave: function() {
for(var i=0; i< this.localusercontent.length; i++) {
let data = this.localusercontent[i];
this.set('usercontent.' + data.key, data.value);
}
this.fire('value-changed', {
usercontent: this.usercontent,
contentId: this.contentId
});
// close the dialog box
this.$$('paper-dialog').close();
},
_convertObjToArray: function(obj) {
for(var key in obj) {
this.push('localusercontent', {
key: key,
value: obj[key]
});
}
},
_handleValueChange: function(e, detail) {
this.localusercontent[e.model.index]['value'] = e.target.value;
},
_initiateAttributeSave: function() {
this.fire('iron-signal', {
name: 'page-operation',
data: {
operation: 'save',
path: this.path,
contentnode: this.contentId,
value: this.usercontent
}
});
}
})
</script>
</dom-module>