add new Fieldfy class to manage forms (minimal), new user 'info' form
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Fri, 23 Oct 2015 16:58:27 +0000 (18:58 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Fri, 23 Oct 2015 16:58:27 +0000 (18:58 +0200)
web/Obj/brisk.phh
web/commons.js
web/fieldify.js [new file with mode: 0644]
web/index.php
web/room.css
web/room.js

index a171273..f044b4a 100644 (file)
@@ -1693,7 +1693,20 @@ class Brisk
           $jret = json_encode(array("ret" => $ret, "mesg" => $mesg));
       }
       else {
-          $jret = json_encode(array("ret" => 0, "mesg" => "", "guar" => $guar_login));
+          $jret = json_encode(array("ret" => 0,
+                                    "mesg" => "",
+                                    "login" => $user_login,
+                                    // FIXME: state internationalization
+                                    "state" =>
+                                    ($user_item->type & USER_FLAG_TY_APPR ? "Apprendista" :
+                                     ($user_item->type & USER_FLAG_TY_CERT ? "Certificato" :
+                                      ($user_item->type & (USER_FLAG_TY_NORM | USER_FLAG_TY_SUPER) ?
+                                       "Normale" : "Stato sconosciuto"))),
+                                    "guar" => ($user_item->type & USER_FLAG_TY_APPR ?
+                                               "" : $guar_login),
+                                    "match" => $user_item->match_cnt,
+                                    "game" => $user_item->game_cnt,
+                                    "friend" => "unknown"));
       }
 
       return $jret;
index 463169d..c317957 100644 (file)
@@ -359,7 +359,7 @@ function chatt_checksend(obj,e)
 function act_chatt(value)
 {
     if (value.substring(0, 6) == "/info ") {
-        show_user_info(value.substring(6));
+        info_show(value.substring(6));
     }
     else {
         send_mesg("chatt|"+encodeURIComponent(value));
diff --git a/web/fieldify.js b/web/fieldify.js
new file mode 100644 (file)
index 0000000..254dd0d
--- /dev/null
@@ -0,0 +1,54 @@
+
+// fieldsdescr = { name: { type: 'typename' }, ... }
+function Fieldify(ancestor, fieldsdescr)
+{
+    this.ancestor = ancestor;
+    
+    this.field = new Array();
+    for (k in fieldsdescr) {
+        this.field[k] = fieldsdescr[k];
+    }
+}
+
+Fieldify.prototype = {
+    ancestor: null,
+    field: null,
+    
+    visible: function(is_visible) {
+        this.ancestor.style.visibility = (is_visible ? "visible" : "hidden" );
+    },
+
+    // { 'name': 'value' }
+    populate: function(field_values)
+    {
+        for (k in this.field) {
+            if (this.field[k].type == 'value') {
+                this.fld_value_set(k, field_values[k]);
+            }
+            else if (this.field[k].type == 'radio') {
+                this.fld_radio_set(k, field_values[k]);
+            }
+        }
+    },
+
+    fld_value_set: function(name, value)
+    {
+        console.log(name + "=" + value);
+        this.ancestor.getElementsByClassName(name + '_id')[0].innerHTML = value;
+    },
+    
+    fld_radio_set: function(name, value)
+    {
+        var arr = this.ancestor.getElementsByClassName(name + '_id');
+
+        console.log(name + "=" + value);
+
+        for (k in arr) {
+            if (arr[k].value == value)
+                arr[k].checked = true;
+            else 
+                arr[k].checked = false;
+        }
+    },
+    tap: null
+}
index a3be749..26f12f3 100644 (file)
@@ -228,6 +228,18 @@ $mlang_room = array( 'userpassuse'  => array('it' => 'Il tuo nickname &egrave; g
                                              'en' => 'Send a message to the administrator:'),
                      'mesgtoadm_sub'=> array('it' => 'soggetto:',
                                              'en' => 'subject:'),
+                     'info_login' => array('it' => 'Utente:',
+                                          'en' => 'User:'),
+                     'info_state' => array('it' => 'Stato:',
+                                          'en' => 'State:'),
+                     'info_guar' => array('it' => 'Garante:',
+                                          'en' => 'Guarantee:'),
+                     'info_match' => array('it' => 'Partite:',
+                                           'en' => 'Matches:'),
+                     'info_game' => array('it' => 'Mani:',
+                                          'en' => 'Hands:'),
+                     'info_frie' => array('it' => 'Conoscenza:',
+                                          'en' => 'Friendship:'),
                      );
 
 require_once("briskin5/Obj/briskin5.phh");
@@ -989,6 +1001,7 @@ supported by:<br>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <link rel="shortcut icon" href="img/brisk_ico.png">
 <script type="text/javascript" src="commons.js"></script>
+<script type="text/javascript" src="fieldify.js"></script>
 <script type="text/javascript" src="prefs.js"></script>
 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
 <script type="text/javascript" src="menu.js"></script>
@@ -1156,6 +1169,7 @@ cookie_law(null);
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <link rel="shortcut icon" href="img/brisk_ico.png">
 <script type="text/javascript" src="commons.js"></script>
+<script type="text/javascript" src="fieldify.js"></script>
 <script type="text/javascript" src="prefs.js"></script>
 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
 <script type="text/javascript" src="menu.js"></script>
@@ -1359,6 +1373,29 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
 <div id="xhrlog"></div>
 <div id="xhrdeltalog"></div>
 </div>
+
+<div id="info" class="notify" style="z-index: 200; width: 400px; margin-left: -200px; height: 340px; top: 150px; visibility: hidden;">
+<table class="info">
+<tr><td class="le"><?php echo $mlang_room['info_login'][$G_lang]; ?></td><td class="ri"><span class="login_id"></span></td></tr>
+<tr><td class="le"><?php echo $mlang_room['info_state'][$G_lang]; ?></td><td class="ri"><span class="state_id"></span></td></tr>
+<tr><td class="le"><?php echo $mlang_room['info_guar'][$G_lang]; ?></td><td class="ri"><span class="guar_id"></span></td></tr>
+<tr><td class="le"><?php echo $mlang_room['info_match'][$G_lang]; ?></td><td class="ri"><span class="match_id"></span></td></tr>
+<tr><td class="le"><?php echo $mlang_room['info_game'][$G_lang]; ?></td><td class="ri"><span class="game_id"></span></td></tr>
+<tr><td class="le ri" colspan="2"><?php echo $mlang_room['info_frie'][$G_lang]; ?></td></tr>
+<tr><td class="le"><input type="radio" name="friend" class="friend_id" value="black">Da evitare</td>
+    <td class="ri noborder"><input type="radio" name="friend" class="friend_id" value="friend">Amico</td></tr>
+<tr><td class="le info-opt"><input type="radio" name="friend" class="friend_id" value="unknown">Sconosciuto</td>
+<td class="ri info-opt"><input type="radio" name="friend" class="friend_id" value="bff">Amico fidato</td></tr>
+<tr><td class="le info-opt"><input type="radio" name="friend" class="friend_id" value="test">In prova</td></tr>
+</table>
+<div style="position: absolute; bottom: 8px; margin: auto; width: 100%;">
+<input type="submit" class="input_sub" style="bottom: 4px;" onclick="$('info').style.visibility = 'hidden';" value="<?php echo $mlang_room['btn_close'][$G_lang]; ?>"/>
+<!-- <input type="submit" class="input_sub" style="bottom: 4px;" onclick="prefs_reset();" value="<?php echo $mlang_room['btn_reset'][$G_lang]; ?>"/>
+<input type="submit" class="input_sub" style="bottom: 4px;" onclick="prefs_save();" value="<?php echo $mlang_room['btn_save'][$G_lang]; ?>"/> -->
+</div>
+
+</div>
+
 <div id="preferences" class="notify" style="z-index: 200; width: 600px; margin-left: -300px; height: 240px; top: 150px; visibility: hidden;">
 <div id="preferences_child" style="border-bottom: 1px solid gray; overflow: auto; height: 370px;">
 
index 4f15cb9..a9318ce 100644 (file)
@@ -459,4 +459,33 @@ img.tickbut {
 
 span.id_usr {
     cursor: pointer;
-}
\ No newline at end of file
+}
+
+table.info {
+    margin: auto;
+    border-collapse: collapse;
+}
+
+table.info td {
+    border-top: 1px solid grey;
+    padding: 4px;
+    width: 50%;
+}
+
+table.info td.info-opt {
+    border-top: 0px;
+    padding: 0px 4px 4px 4px;
+    }
+
+table.info td.noborder {
+    border-top: 0px;
+    }
+
+table.info td.le {
+    padding-left: 16px;
+    }
+
+table.info td.ro {
+    padding-right: 16px;
+    }
+
index c7efc62..f6d6d24 100644 (file)
@@ -442,10 +442,26 @@ var g_user_info_target = "";
 function info_show(username)
 {
     // ret = server_request('mesg', 'prefs|save','__POST__', 'prefs', JSON.stringify(g_prefs));
-    var udata = server_request('mesg', 'chatt|/info ' + username);
+    var info_in = JSON.parse(server_request('mesg', 'chatt|/info ' + username));
+    var info = null;
 
+    if (info_in.ret == 0) {
+        var fields = { login: { type: 'value' },
+                       state: { type: 'value' },
+                       guar: { type: 'value' },
+                       match: { type: 'value' },
+                       game: { type: 'value' },
+                       friend: { type: 'radio' } };
+
+        info = new Fieldify($('info'), fields);
+        info.populate(info_in);
+        info.visible(true);
+        }
+    else {
+        console.log("some error: open a dialog");
+    }
     // FIXME: just to be finished
-    console.log(udata);
+    console.log(info);
 }
 
 function click_update_cb(e)