-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuba-service-form.html
More file actions
66 lines (58 loc) · 1.48 KB
/
cuba-service-form.html
File metadata and controls
66 lines (58 loc) · 1.48 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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../cuba-app/cuba-app-aware-behavior.html">
<link rel="import" href="cuba-form-behavior.html">
<!--
`cuba-service-form`
-->
<dom-module id="cuba-service-form">
<template>
<style>
:host {
display: block;
}
</style>
<form id="form">
<slot></slot>
</form>
</template>
<script>
Polymer({
is: 'cuba-service-form',
behaviors: [CubaAppAwareBehavior, CubaFormBehavior],
properties: {
serviceName: String,
method: String,
params: {
type: Object
},
result: {
type: Object,
notify: true,
readOnly: true
}
},
ready: function() {
this.$.form.addEventListener('submit', function(event) {
event.preventDefault();
this.submit();
return false;
}.bind(this));
},
/**
* Send data to server.
*/
submit: function() {
this._clearErrors();
return this.app.invokeService(this.serviceName, this.method, this.params).then(function(resp) {
this._setResult(resp);
this.fire('cuba-form-response', {response: resp});
return resp;
}.bind(this), function(errResp) {
this._handleError(errResp);
this.fire('cuba-form-error', {errorResponse: errResp});
return errResp;
}.bind(this));
}
});
</script>
</dom-module>