forked from hoodiehq/hoodie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
328 lines (251 loc) · 9.85 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html>
<html>
<head>
<title>Hoodie Test page</title>
<link href="lib/prism/prism.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="container" style="margin: 50px auto; max-width: 920px;">
<pre><code class="language-javascript">
//
// initialize your Hoodie App
//
whereTheMagicHappens = 'https://yourapp.hood.ie';
hoodie = new Hoodie(whereTheMagicHappens);
//
// Account
//
// sign up
hoodie.account.signUp('[email protected]', 'secret')
// sign in
hoodie.account.signIn('[email protected]', 'secret')
// sign out
hoodie.account.signOut()
// change password
hoodie.account.changePassword('currentpassword', 'newpassword')
// change username
hoodie.account.changeUsername('currentpassword', 'newusername')
// reset password
hoodie.account.resetPassword('[email protected]')
// destroy account and all its data
hoodie.account.destroy()
//
// Store
//
// add a new object
type = 'couch'
attributes = {color: "red"}
hoodie.store.add(type, attributes )
.done ( function(newObject) { } )
// save an object
type = 'couch'
id = 'abc4567'
attributes = {color: "red", name: "relax"}
hoodie.store.save( type, id, attributes )
.done ( function(object) { } )
// update an existing object
type = 'couch'
id = 'abc4567'
update = {size: 2}
hoodie.store.update( type, id, update )
.done ( function(updatedObject) { } )
// find one object
type = 'couch'
id = 'abc4567'
hoodie.store.find( type, id )
.done ( function(object) { } )
// Load all objects
hoodie.store.findAll()
.done ( function(objects) { } )
// Load all objects from one type
type = 'couch'
hoodie.store.findAll( type )
.done ( function(objects) { } )
// remove an existing object
type = 'couch'
id = 'abc4567'
hoodie.store.remove( type, id )
.done ( function(removedObject) { } )
// listen to store events
hoodie.store.on( 'add', function( newObject) { } )
// new doc created
hoodie.store.on( 'add', function( newObject) { } )
// existing doc updated
hoodie.store.on( 'update', function( updatedObject) { } )
// doc removed
hoodie.store.on( 'remove', function( removedObject) { } )
// any of the events above
hoodie.store.on( 'change', function( event, changedObject) { } )
// all listeners can be filtered by type
hoodie.store.on( "couch:add", function( newObject) { } )
hoodie.store.on( "couch:update", function( updatedObject) { } )
hoodie.store.on( "couch:remove", function( removedObject) { } )
hoodie.store.on( "couch:change", function( event, changedObject) { } )
// ... and by type and id
hoodie.store.on( "couch:uuid123:add", function( newObject) { } )
hoodie.store.on( "couch:uuid123:update", function( updatedObject) { } )
hoodie.store.on( "couch:uuid123:remove", function( removedObject) { } )
hoodie.store.on( "couch:uuid123:change", function( event, changedObject) { } )
//
// Synchronization
//
// When signed in, local changes do get synched automatically.
// You can subscribe to remote updates
//
// new doc created
hoodie.remote.on( 'add', function( newObject) { } )
// existing doc updated
hoodie.remote.on( 'update', function( updatedObject) { } )
// doc removed
hoodie.remote.on( 'remove', function( removedObject) { } )
// any of the events above
hoodie.remote.on( 'change', function( event, changedObject) { } )
// all listeners can be filtered by type
hoodie.remote.on( "couch:add", function( newObject) { } )
hoodie.remote.on( "couch:update", function( updatedObject) { } )
hoodie.remote.on( "couch:remove", function( removedObject) { } )
hoodie.remote.on( "couch:change", function( event, changedObject) { } )
// ... and by type and id
hoodie.remote.on( "couch:uuid123:add", function( newObject) { } )
hoodie.remote.on( "couch:uuid123:update", function( updatedObject) { } )
hoodie.remote.on( "couch:uuid123:remove", function( removedObject) { } )
hoodie.remote.on( "couch:uuid123:change", function( event, changedObject) { } )
//
// Tasks
//
// Tasks get picked up by backend workers in the background. You can
// think of them as special kind of objects that the describe specific
// tasks that you want backend logic for to be accomplished.
//
// If a task has been completed successfully, it gets removed. If there
// is an error, it stays in the task store to be handled or removed.
//
// start a new task. Once it was finished, the succes callback gets
// called. If something went wrong, error callback gets called instead
hoodie.task.start('message', {to: 'joe', text: 'Party machen?'})
.then( showMessageSent, showMessageError )
// cancel a pending task
hoodie.task.cancel('message', '123')
// restart a pending or canceled task
hoodie.task.restart('message', '123', { extraProperty: 'value' })
// canceled all pending tasks
hoodie.task.restartAll()
// restart all pending or canceled tasks
hoodie.task.restartAll()
//
// task events:
//
// * start
// * cancel
// * error
// * success
// listen to new tasks
hoodie.task.on( 'start', function( newTask) { } )
// task canceled
hoodie.task.on( 'cancel', function( canceledTask) { } )
// task could not be completed
hoodie.task.on( 'error', function( errorMessage, task) { } )
// task completed successfully
hoodie.task.on( 'success', function( completedTask) { } )
// all listeners can be filtered by type
hoodie.task.on( "message:start", function( newMessageTask, options) { } )
hoodie.task.on( "message:cancel", function( canceledMessageTask, options) { } )
hoodie.task.on( "message:error", function( errorMessage, messageTask, options) { } )
hoodie.task.on( "message:success", function( completedMessageTask, options) { } )
hoodie.task.on( "message:change", function( eventName, messageTask, options) { } )
// ... and by type and id
hoodie.task.on( "message:123:start", function( newMessageTask, options) { } )
hoodie.task.on( "message:123:cancel", function( canceledMessageTask), options { } )
hoodie.task.on( "message:123:error", function( errorMessage, messageTask, options) { } )
hoodie.task.on( "message:123:success", function( completedMessageTask, options) { } )
hoodie.task.on( "message:123:change", function( eventName, messageTask, options) { } )
// note: if "change" event is error, the error message gets passed as options.error
//
// Public Shares (Public User Stores)
// (work in progress)
//
// Select data you want to share with others and control exactly what will
// be shared
//
// make couch object with id "abc4567" public
hoodie.store.find("couch","abc4567").publish()
// make couch with id "abc4567" public, but do only show the color, hide
// all other attributes
hoodie.store.find("couch","abc4567").publish(['color'])
// make couch with id "abc4567" private again
hoodie.store.find("couch","abc4567").unpublish()
// find all couch objects from user "joe"
hoodie.user("joe").findAll("couch").done( function(couches) { ... })
//
// Global Public Store
// (work in progress)
//
// When enabled, all publicly shared objects by all users will be
// available through the hoodie.global API
//
// find all public songs from all users
hoodie.global.findAll("song").done( function(songs) { ... })
//
// Sharing
// (work in progress)
//
// The hoodie.share module allows to share objects with other users. A share
// can be public, which means everybody knowing its id can access it. Or the
// access can be limited to specific users. Optionally, a password can be set
// for additional security. Access can be differenciated between read and write.
//
// add a new share
hoodie.share.add().done( function(share) {} )
// grant / revoke access
share.grantReadAccess()
share.grantWriteAccess()
share.revokeReadAccess()
share.revokeWriteAccess()
share.grantReadAccess('[email protected]')
share.revomeWriteAccess(['[email protected]','[email protected]'])
// add all todo objects to the share
hoodie.store.findAll('todo').shareAt(share.id)
// remove a specific todo from the share
hoodie.store.find('todo', '123').unshareAt(share.id)
// add a new share and add some of my objects to it in one step
hoodie.store.findAll('todo').share()
.done( function(todos, share) { alert('shared at ' + share.id) } )
// remove objects from all shares
hoodie.store.findAll('todo').unshare()
// remove share
hoodie.share.remove(share.id)
// open a share and load all its objects
hoodie.share('shareIdHere').findAll()
.done( function(objects) { } )
// subscribe / unsubscribe
hoodie.share('shareId').subscribe()
hoodie.share('shareId').unsubscribe()
//
// Send emails
// (work in progress)
//
email = {
to : ['[email protected]'],
cc : ['[email protected]'],
subject : 'rule the wolrd',
body : "we can do it!\nSigned, Joe"
}
hoodie.email.send( email )
// synched to server
.progress ( function(email) { } )
// email sent successfully
.done ( function(email) { } )
// something went wrong
.fail ( function(err) { } )
//
// hoodie.js API docs
// http://hoodiehq.github.com/hoodie.js/doc/hoodie.html
//
</code></pre>
</div>
<!-- deplendencies for hoodie -->
<script src="lib/jquery/jquery.js"></script>
<script src="dist/hoodie.js"></script>
<script src="lib/prism/prism.js"></script>
</body>
</html>