type 'fields' added to Fieldify class
[brisk.git] / web / info.js
1 /*
2  *  brisk - info.js
3  *
4  *  Copyright (C) 2015      Matteo Nastasi
5  *                          mailto: nastasi@alternativeoutput.it
6  *                                  matteo.nastasi@milug.org
7  *                          web: http://www.alternativeoutput.it
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details. You should have received a
18  * copy of the GNU General Public License along with this program; if
19  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20  * Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23
24 var mlang_info = { 'btn_close' : { 'it' : 'Chiudi.',
25                                    'en' : 'Close.' }
26                  };
27
28
29 function info_fld(dobj)
30 {
31     var fields = { login: { type: 'value' },
32                    state: { type: 'value', perms: 'ro' },
33                    guar: { type: 'value', perms: 'ro' },
34
35                    widefriend: { type: 'fields', fields: { black: { type: 'value', perms: 'ro' },
36                                                            test: { type: 'value', perms: 'ro'},
37                                                            friend: { type: 'value', perms: 'ro'},
38                                                            bff: { type: 'value', perms: 'ro'}
39                                                          } },
40                    narrowfriend: { type: 'fields', fields: { black: { type: 'value', perms: 'ro'},
41                                                              test: { type: 'value', perms: 'ro'},
42                                                              friend: { type: 'value', perms: 'ro'},
43                                                              bff: { type: 'value', perms: 'ro'}
44                                                          } },
45                    match: { type: 'value', perms: 'ro' },
46                    game: { type: 'value', perms: 'ro' },
47                    friend: { type: 'radio' },
48                    skill: { type: 'radio' },
49                    trust: { type: 'radio' }
50                  };
51
52     return (new Fieldify(dobj, fields));
53  }
54
55 function info_show(username)
56 {
57     var info_in_in = server_request('mesg', 'chatt|/info ' +
58                                             encodeURIComponent(username));
59     var info_in = JSON.parse(info_in_in);
60     var info = null;
61
62     if (info_in.ret == 0) {
63         info = info_fld($('info'));
64         info.json2dom(info_in);
65         info.visible(true);
66         }
67     else {
68         var noti = new notify(gst, info_in.mesg, 0, mlang_info['btn_close'][g_lang], 400, 150);
69     }
70 }
71
72 var g__info_show_target = "";
73 function info_show_cb(e)
74 {
75     if (g__info_show_target == e.target.innerHTML) {
76         g__info_show_target = "";
77         info_show(e.target.innerHTML);
78     }
79     else {
80         g__info_show_target = e.target.innerHTML;
81     }
82 }
83
84 function info_reset()
85 {
86     var ret, target;
87
88     target = $('info').getElementsByClassName('login_id')[0].innerHTML;
89     return info_show(target);
90 }
91
92 function info_save()
93 {
94     var info, jinfo, ret;
95
96     info = info_fld($('info'));
97     jinfo = info.dom2json();
98
99     ret = server_request('mesg', 'info|save','__POST__', 'info', JSON.stringify(jinfo));
100
101     if (ret == 1) {
102         $('info').style.visibility = 'hidden';
103     }
104     else {
105         alert(ret);
106     }
107 }