-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaas-document.html
More file actions
113 lines (95 loc) · 2.63 KB
/
caas-document.html
File metadata and controls
113 lines (95 loc) · 2.63 KB
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
113
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<link rel="import" href="../caas-crud-behavior/caas-crud-behavior.html">
<!--
`caas-document`
@demo demo/index.html
-->
<dom-module id="caas-document">
<template>
<iron-ajax
id="readDocument"
headers="[[_requestHeaders]]"
url="[[apiEndpoint]]/[[route]]"
method="GET"
last-response="{{document}}"
debounce-duration="[[debounceDuration]]"
auto="[[autoRead]]"
loading="{{reading}}"
on-response="_handleReadResponse"
on-error="_handleReadResponseError"
></iron-ajax>
<iron-ajax
id="updateDocument"
headers="[[_requestHeaders]]"
url="[[apiEndpoint]]/[[route]]"
method="PUT"
content-type="application/json"
body='[[document]]'
debounce-duration="[[debounceDuration]]"
loading="{{updating}}"
on-response="_handleUpdateResponse"
on-error="_handleUpdateResponseError"
></iron-ajax>
<iron-ajax
id="deleteDocument"
headers="[[_requestHeaders]]"
url="[[apiEndpoint]]/[[route]]"
method="DELETE"
body='{"id":[[document.id]]}'
debounce-duration="[[debounceDuration]]"
loading="{{deleting}}"
on-response="_handleDeleteResponse"
on-error="_handleDeleteResponseError"
></iron-ajax>
</template>
<script>
Polymer({
is: 'caas-document',
behaviors: [CaasCrudBehavior],
properties: {
/**
* The document object
*/
document: {
type: Object,
notify: true
},
},
observers: [
'_handleDocumentValueChanged(document.*)'
],
/**
* Download `document`
*/
read: function() {
this._sendAjaxRequest('read');
},
/**
* Save `document`
*/
update: function() {
this._sendAjaxRequest('update');
},
/**
* Delete `document`
*/
delete: function() {
this._sendAjaxRequest('delete');
},
notifyProperties: function(properties) {
var properties = properties || Object.keys(this.document);
for(var i in properties) {
this.notifyPath('document.' + properties[i], this.document[properties[i]]);
}
},
_handleDocumentValueChanged(documentChange) {
this.notifyProperties();
this.fire('document-value-changed', documentChange);
if(this.accessToken && this.autoUpdate) {
this.update();
}
},
});
</script>
</dom-module>