Commit f35de22691a3feb3ac7a8ddaf2cdefd82dd72a9b
identity select implements dropdown or buttons to switch main id
Dominic Tarr committed on 12/16/2018, 9:21:16 PMParent: 8b3aaeec88d4185939047d2efe9162f3c3fa00bf
Files changed
apis/identity-select.js | changed |
apis/identity-select.js | ||
---|---|---|
@@ -4,39 +4,61 @@ | ||
4 | 4 | var sbot = this.sbot |
5 | 5 | var api = this.api |
6 | 6 | var context = this.context |
7 | 7 | var main = context.id || sbot.id |
8 | - return ['form', {method: 'POST'}, | |
9 | - ['div.IdentitySelector._menu', | |
10 | - ['input', {type: 'hidden', name: 'type', value: 'identitySelect'}], | |
11 | - ['div.Menu', | |
12 | - ['a', {href: toUrl('profile', {id:context.id})}, | |
13 | - api(['avatar'], {id: context.id, image: true}) | |
14 | - ], | |
15 | - ['ul', | |
16 | - function (cb) { | |
17 | - sbot.identities.list(function (err, ls) { | |
18 | - if(err) return cb(err) | |
19 | - cont.para(ls.filter(function (e) { | |
20 | - return e != context.id | |
21 | - }).map(function (id) { | |
22 | - return function (cb) { | |
23 | - sbot.names.getSignifier(id, function (err, name) { | |
24 | - cb(null, ['li', ['button', {type: 'submit', name: 'id', value: id}, name]]) | |
25 | - }) | |
26 | - } | |
27 | - }))(cb) | |
28 | - }) | |
29 | - } | |
8 | + var restrict = opts.restrict | |
9 | + //form to switch the main identity | |
10 | + if(false && opts.main === true) | |
11 | + return ['form', {method: 'POST'}, | |
12 | + ['div.IdentitySelector._menu', | |
13 | + ['input', {type: 'hidden', name: 'type', value: 'identitySelect'}], | |
14 | + ['div.Menu', | |
15 | + api('avatar', {id: context.id, image: true, name: false}), | |
16 | + ['ul', | |
17 | + function (cb) { | |
18 | + sbot.identities.list(function (err, ls) { | |
19 | + if(err) return cb(err) | |
20 | + cont.para(ls.filter(function (e) { | |
21 | + return e != context.id | |
22 | + }).map(function (id) { | |
23 | + return function (cb) { | |
24 | + sbot.names.getSignifier(id, function (err, name) { | |
25 | + cb(null, ['li', ['button', {type: 'submit', name: 'id', value: id}, name]]) | |
26 | + }) | |
27 | + } | |
28 | + }))(cb) | |
29 | + }) | |
30 | + } | |
31 | + ] | |
30 | 32 | ] |
31 | 33 | ] |
32 | 34 | ] |
33 | - ] | |
34 | -} | |
35 | + else {//an input to select id to publish a form from. | |
35 | 36 | |
37 | + if(restrict) | |
38 | + restrict = [].concat(restrict).map(function (e) { | |
39 | + return 'string' == typeof e ? e : e.link | |
40 | + }).filter(ref.isFeed) | |
36 | 41 | |
42 | + return function (cb) { | |
43 | + sbot.identities.list(function (err, ls) { | |
44 | + //move main identity to the front | |
45 | + console.log('main', main, ls.indexOf(main)) | |
46 | + console.log('list', ls) | |
47 | + ls.splice(ls.indexOf(main), 1) | |
48 | + ls.unshift(main) | |
49 | + console.log('after', ls) | |
37 | 50 | |
51 | + cb(null, [ | |
52 | + 'select', {name: 'id'}, | |
53 | + ].concat(ls.map(function (id) { | |
54 | + return function (cb) { | |
55 | + sbot.names.getSignifier(id, function (_, name) { | |
56 | + cb(null, ['option', {value: id, selected:id == main ? true : undefined}, name || id.substring(0, 10)]) | |
57 | + }) | |
58 | + } | |
59 | + })) ) | |
60 | + }) | |
61 | + } | |
62 | + } | |
63 | +} | |
38 | 64 | |
39 | - | |
40 | - | |
41 | - | |
42 | - |
Built with git-ssb-web