-
Notifications
You must be signed in to change notification settings - Fork 3
/
profile-module.js
71 lines (69 loc) · 1.81 KB
/
profile-module.js
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
RemoteStorage.defineModule('profile', function(privateClient, publicClient){
publicClient.declareType('profile', {
'type' : 'object',
'properties' : {
'name' : {
'type' : 'string'
},
'screenname' : {
'type' : 'string'
},
'homepage' : {
'type' : 'string',
},
'profile_image_url': {
'type' : 'string'
},
'location' :{
'type' : 'string'
},
'description' : {
'type' : 'string'
}
},
})
var keys = ['name', 'screenname', 'homepage', 'profile_image_url', 'location', 'description']//Object.keys(publicClient.schemas[Object.keys(publicClient.schemas)[0]].properties);
return {
'exports' : {
'keys' : keys,
'save' : function(data){
publicClient.getObject('me').then(
function(old_data){
if(old_data){
keys.forEach( function(k){
if(typeof(data[k]) === 'undefined')
data[k] = old_data[k]
})
}
return publicClient.storeObject('profile', 'me',data);
})
},
'template' : function(){
return publicClient.getFile('template');
},
'load' : function(){
return publicClient.getObject('me');
},
/*'deploy' : function(){
publicClient.getObject('me').then( function(me){
var page = ""
publicClient.getFile('template').then( function(template){
var page = template.data ;
Object.keys(me).forEach( function(k) {
page = page.replace( new RegExp('(\\$'+key+')'), me[key] )
})
})
return remoteStorage.www.up('profile.html',
'text/html',
page)
})
},
'link' : function(){
return publicClient.getItemURL('profile.html');
},*/
'onchange' : function(callback){
return publicClient.on('change', callback);
}
}
}
})