partial refactoring for info command, new nasty devel username to check deeper login...
[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 function info_fld(dobj)
25 {
26     var fields = { login: { type: 'value' },
27                    state: { type: 'value', perms: 'ro' },
28                    guar: { type: 'value', perms: 'ro' },
29                    match: { type: 'value', perms: 'ro' },
30                    game: { type: 'value', perms: 'ro' },
31                    friend: { type: 'radio' },
32                    skill: { type: 'radio' },
33                    trust: { type: 'radio' }
34                  };
35
36     return (new Fieldify(dobj, fields));
37  }
38
39 function info_show(username)
40 {
41     var info_in_in = server_request('mesg', 'chatt|/info ' +
42                                             encodeURIComponent(username));
43     var info_in = JSON.parse(info_in_in);
44     var info = null;
45
46     if (info_in.ret == 0) {
47         info = info_fld($('info'));
48         info.json2dom(info_in);
49         info.visible(true);
50         }
51     else {
52         alert("error: open info window failed");
53     }
54 }
55
56 var g__info_show_target = "";
57 function info_show_cb(e)
58 {
59     if (g__info_show_target == e.target.innerHTML) {
60         g__info_show_target = "";
61         info_show(e.target.innerHTML);
62     }
63     else {
64         g__info_show_target = e.target.innerHTML;
65     }
66 }
67
68 function info_save()
69 {
70     var ret;
71
72     info = info_fld($('info'));
73     ret = info.dom2json();
74
75     console.log(ret);
76
77     if (0 == 1) {
78         if (typeof(g_prefs) == 'undefined')
79             return false;
80
81         ret = server_request('mesg', 'info|save','__POST__', 'prefs', JSON.stringify(g_prefs));
82
83         if (ret == 1)
84             $('preferences').style.visibility = 'hidden';
85     }
86 }
87
88 function info_reset()
89 {
90     var ret;
91
92     ret = server_request('mesg', 'prefs|reset');
93 }