update info form with new Fieldify, use on-change callback to manage friendship subfo...
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Mon, 8 Feb 2016 06:35:17 +0000 (07:35 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Mon, 8 Feb 2016 06:35:17 +0000 (07:35 +0100)
web/index.php
web/info.js

index d9a52c3..d641a6f 100644 (file)
@@ -1433,18 +1433,18 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
 <td class="le data">Fidato: <span class="bff_id"></span></td></tr>
 <tr><td class="le ri triple" colspan="3"><b><?php echo $mlang_room['info_frie'][$G_lang]; ?></b></td>
 <td class="le data triple">
-<input type="radio" name="friend" class="friend_id" value="black" onclick="info_onlyifknown_isvisible();">
+<input type="radio" name="friend" class="friend_id" value="black">
 <span class="friend_t_id" data-ffy-value="black">Da evitare</span>
 </td></tr>
 <tr>
-<td class="le info-opt data"><input type="radio" name="friend" class="friend_id" value="unknown"
-    onclick="info_onlyifknown_isvisible();"><span class="friend_t_id" data-ffy-value="unknown">Sconosciuto</span></td>
-<td class="le info-opt data"><input type="radio" name="friend" class="friend_id" value="test"
-    onclick="info_onlyifknown_isvisible();"><span class="friend_t_id" data-ffy-value="test">In prova</span></td>
-<td class="ri info-opt data"><input type="radio" name="friend" class="friend_id" value="friend"
-    onclick="info_onlyifknown_isvisible();"><span class="friend_t_id" data-ffy-value="friend">Amico</span></td>
-<td class="ri info-opt data"><input type="radio" name="friend" class="friend_id" value="bff"
-    onclick="info_onlyifknown_isvisible();"><span class="friend_t_id" data-ffy-value="bff">Amico fidato</span></td>
+<td class="le info-opt data"><input type="radio" name="friend" class="friend_id" value="unknown">
+    <span class="friend_t_id" data-ffy-value="unknown">Sconosciuto</span></td>
+<td class="le info-opt data"><input type="radio" name="friend" class="friend_id" value="test">
+    <span class="friend_t_id" data-ffy-value="test">In prova</span></td>
+<td class="ri info-opt data"><input type="radio" name="friend" class="friend_id" value="friend">
+    <span class="friend_t_id" data-ffy-value="friend">Amico</span></td>
+<td class="ri info-opt data"><input type="radio" name="friend" class="friend_id" value="bff">
+    <span class="friend_t_id" data-ffy-value="bff">Amico fidato</span></td>
 </tr>
 <tr class="onlyifknown_gid">
 <td class="le head"><span><?php echo $mlang_room['info_skill'][$G_lang]; ?>:</span></td>
index 8a3a73d..bd2a281 100644 (file)
@@ -25,6 +25,17 @@ var mlang_info = { 'btn_close' : { 'it' : 'Chiudi.',
                                    'en' : 'Close.' }
                  };
 
+function info_onlyifknown_isvisible_cb(item)
+{
+    var vis = 'inherit';
+
+    if (item.value == 'black' || item.value == 'unknown') {
+        vis = 'hidden';
+    }
+
+    $('info').getElementsByClassName('onlyifknown_gid')[0].style.visibility = vis;
+    return true;
+}
 
 function info_fld(dobj)
 {
@@ -47,7 +58,7 @@ function info_fld(dobj)
                    match: { type: 'value', perms: 'ro' },
                    game: { type: 'value', perms: 'ro' },
                    party: { type: 'value', perms: 'ro' },
-                   friend: { type: 'radio' },
+                   friend: { type: 'radio', cb: info_onlyifknown_isvisible_cb },
                    skill: { type: 'radio' },
                    trust: { type: 'radio' }
                  };
@@ -66,7 +77,6 @@ function info_show(username)
     if (info_in.ret == 0) {
         info = info_fld($('info'));
         info.json2dom(info_in);
-        info_onlyifknown_isvisible();
         info.visible(true);
         }
     else {
@@ -108,25 +118,3 @@ function info_save()
         alert(ret);
     }
 }
-function info_onlyifknown_isvisible()
-{
-    var vis = 'inherit';
-    var arr = Fieldify.get_dom_elements([$('info')], 'friend');
-    var obj = null;
-
-    for (var k = 0 ; k < arr.length ; k++) {
-        if (arr[k].checked == true) {
-            obj = arr[k];
-            break;
-        }
-    }
-    if (obj == null) {
-        return false;
-    }
-
-    if (obj.value == 'black' || obj.value == 'unknown') {
-        vis = 'hidden';
-    }
-    $('info').getElementsByClassName('onlyifknown_gid')[0].style.visibility = vis;
-    return true;
-}