-
Notifications
You must be signed in to change notification settings - Fork 2
/
cuba-app.html
94 lines (79 loc) · 2.02 KB
/
cuba-app.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="cuba-js-script.html">
<!--
The `cuba-app` element is used for initialization and configuration connection to CUBA REST API.
Adds `cuba` object to the global JS scope.
-->
<dom-module id="cuba-app">
<template>
<style>
:host {
display: block;
}
</style>
<slot></slot>
</template>
<script>
(function(){
"use strict";
Polymer({
is: 'cuba-app',
/**
* Fired on attempt to access REST API without or with expired token.
* Usually it means that user login required. See `cuba-login`
*
* @event cuba-token-expired
*/
/**
* Fired when CubaApp instance created
*
* @event cuba-app-initialized
*/
properties: {
/**
* Connection URL to CUBA REST API v2.
* Trailing slash required.
*/
apiUrl: {
type: String
},
/**
* App name
*/
name: {
type: String,
value: ""
},
/**
* Instance of CubaApp, see https://github.com/cuba-platform/cuba-rest-js.git
*
* @type {cuba.CubaApp}
*/
app: {
type: Object,
readOnly: true,
notify: true
}
},
observers: ['_setupApp(apiUrl, name)'],
_setupApp: function(apiUrl, name) {
if (apiUrl == null) {
return;
}
if (this.app) {
throw new Error("Cuba app is already initialized");
}
this._setApp(cuba.initializeApp({
name: this.name,
apiUrl: this.apiUrl,
storage: localStorage
}));
this.fire('cuba-app-initialized');
this.app.onTokenExpiry(function() {
this.fire('cuba-token-expired');
}.bind(this));
}
});
})();
</script>
</dom-module>