8a3a73dbf6f61d93ab9e3288cfa8dafa35d6714f
[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', perms: 'key' },
32                    state: { type: 'value', perms: 'ro' },
33                    guar: { type: 'value', perms: 'ro' },
34
35                    widefriend: { type: 'fields', fields: { skill: { type: 'value', perms: 'ro' },
36                                                            black: { type: 'value', perms: 'ro' },
37                                                            test: { type: 'value', perms: 'ro'},
38                                                            friend: { type: 'value', perms: 'ro'},
39                                                            bff: { type: 'value', perms: 'ro'}
40                                                          } },
41                    narrowfriend: { type: 'fields', fields: { skill: { type: 'value', perms: 'ro' },
42                                                              black: { type: 'value', perms: 'ro'},
43                                                              test: { type: 'value', perms: 'ro'},
44                                                              friend: { type: 'value', perms: 'ro'},
45                                                              bff: { type: 'value', perms: 'ro'}
46                                                          } },
47                    match: { type: 'value', perms: 'ro' },
48                    game: { type: 'value', perms: 'ro' },
49                    party: { type: 'value', perms: 'ro' },
50                    friend: { type: 'radio' },
51                    skill: { type: 'radio' },
52                    trust: { type: 'radio' }
53                  };
54
55     var ret = new Fieldify([dobj], fields);
56     return (ret);
57  }
58
59 function info_show(username)
60 {
61     var info_in_in = server_request('index_wr.php', sess, 'mesg', 'chatt|/info ' +
62                                             encodeURIComponent(username));
63     var info_in = JSON.parse(info_in_in);
64     var info = null;
65
66     if (info_in.ret == 0) {
67         info = info_fld($('info'));
68         info.json2dom(info_in);
69         info_onlyifknown_isvisible();
70         info.visible(true);
71         }
72     else {
73         var noti = new notify(gst, info_in.mesg, 0, mlang_info['btn_close'][g_lang], 400, 150);
74     }
75 }
76
77 var g__info_show_target = "";
78 function info_show_cb(e)
79 {
80     if (g__info_show_target == e.target.innerHTML) {
81         g__info_show_target = "";
82         info_show(e.target.innerHTML);
83     }
84     else {
85         g__info_show_target = e.target.innerHTML;
86     }
87 }
88
89 function info_reset()
90 {
91     var ret, target;
92
93     Fieldify.reset($('info'));
94 }
95
96 function info_save()
97 {
98     var info, jinfo, ret;
99
100     jinfo = Fieldify.dom2json($('info'));
101
102     ret = server_request('index_wr.php', sess, 'mesg', 'info|save','__POST__', 'info', JSON.stringify(jinfo));
103
104     if (ret == 1) {
105         Fieldify.actualize($('info'));
106     }
107     else {
108         alert(ret);
109     }
110 }
111 function info_onlyifknown_isvisible()
112 {
113     var vis = 'inherit';
114     var arr = Fieldify.get_dom_elements([$('info')], 'friend');
115     var obj = null;
116
117     for (var k = 0 ; k < arr.length ; k++) {
118         if (arr[k].checked == true) {
119             obj = arr[k];
120             break;
121         }
122     }
123     if (obj == null) {
124         return false;
125     }
126
127     if (obj.value == 'black' || obj.value == 'unknown') {
128         vis = 'hidden';
129     }
130     $('info').getElementsByClassName('onlyifknown_gid')[0].style.visibility = vis;
131     return true;
132 }