Fieldify: add multiple ancestor object to allow multi-tr fields
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Thu, 10 Dec 2015 17:41:51 +0000 (18:41 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Thu, 10 Dec 2015 17:41:51 +0000 (18:41 +0100)
web/Obj/dbase_pgsql.phh
web/fieldify.js
web/index.php
web/info.js

index 79924e4..520a4f0 100644 (file)
@@ -858,11 +858,11 @@ INSERT INTO %smails (code, ucode, type, tstamp, subj, body_txt, body_htm, hash)
 
     function friendship_default()
     {
-        return (array(usersnet_friend_getlabel(1) => "//",
-                      usersnet_friend_getlabel(2) => "//",
-                      usersnet_friend_getlabel(3) => "//",
-                      usersnet_friend_getlabel(4) => "//",
-                      usersnet_friend_getlabel(5) => "//"));
+        return (array(usersnet_friend_getlabel(1) => "0",
+                      usersnet_friend_getlabel(2) => "0",
+                      usersnet_friend_getlabel(3) => "0",
+                      usersnet_friend_getlabel(4) => "0",
+                      usersnet_friend_getlabel(5) => "0"));
     }
 
     function usersnet_widefriend($owner, $target)
index cb14c6e..1447d41 100644 (file)
@@ -1,25 +1,36 @@
+function __fieldify_findfirst(objarr, name)
+{
+    for (var i = 0, obj = objarr[i] ; i < objarr.length ; i++) {
+        var item = obj.getElementsByClassName(name + '_id');
+        if (item.length > 0) {
+            return (item);
+        }
+    }
+    return false;
+}
 
 // fieldsdescr = { name: { type: 'typename' }, ... }
-function Fieldify(ancestor, fieldsdescr)
+function Fieldify(ancestors, fieldsdescr)
 {
-    this.ancestor = ancestor;
-
+    this.ancestors = ancestors;
     this.field = new Array();
     for (k in fieldsdescr) {
         this.field[k] = fieldsdescr[k];
         if (this.field[k].type == 'fields') {
-            this.field[k].obj = new Fieldify(this.ancestor.getElementsByClassName(k + '_id')[0],
-                                             this.field[k].fields);
+            var item = __fieldify_findfirst(this.ancestors, k);
+            if (item) {
+                this.field[k].obj = new Fieldify(item, this.field[k].fields);
+            }
         }
     }
 }
 
 Fieldify.prototype = {
-    ancestor: null,
+    ancestors: null,
     field: null,
 
     visible: function(is_visible) {
-        this.ancestor.style.visibility = (is_visible ? "visible" : "hidden" );
+        this.ancestors[0].style.visibility = (is_visible ? "visible" : "hidden" );
     },
 
     // { 'name': 'value' }
@@ -59,35 +70,44 @@ Fieldify.prototype = {
 
     fld_value_set: function(name, value)
     {
-        this.ancestor.getElementsByClassName(name + '_id')[0].innerHTML = value;
+        var item = __fieldify_findfirst(this.ancestors, name);
+        if (item) {
+            item[0].innerHTML = value;
+        }
     },
 
     fld_value_get: function(name)
     {
-        return this.ancestor.getElementsByClassName(name + '_id')[0].innerHTML;
+        var item = __fieldify_findfirst(this.ancestors, name);
+        if (item) {
+            return (item[0].innerHTML);
+        }
+        return false;
     },
 
     fld_radio_set: function(name, value)
     {
-        var arr = this.ancestor.getElementsByClassName(name + '_id');
-
-        for (k in arr) {
-            if (arr[k].value == value)
-                arr[k].checked = true;
-            else
-                arr[k].checked = false;
+        var arr = __fieldify_findfirst(this.ancestors, name);
+        if (arr) {
+            for (k in arr) {
+                if (arr[k].value == value)
+                    arr[k].checked = true;
+                else
+                    arr[k].checked = false;
+            }
         }
     },
 
     fld_radio_get: function(name)
     {
-        var arr = this.ancestor.getElementsByClassName(name + '_id');
-        ret = null;
-
-        for (k in arr) {
-            if (arr[k].checked == true) {
-                ret = arr[k].value;
-                break;
+        var ret = null;
+        var arr = __fieldify_findfirst(this.ancestors, name);
+        if (arr) {
+            for (k in arr) {
+                if (arr[k].checked == true) {
+                    ret = arr[k].value;
+                    break;
+                }
             }
         }
         return ret;
index 12972e9..1e1b09d 100644 (file)
@@ -1392,7 +1392,7 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi
 <tr class="widefriend_id"><td class="le info-opt">Da evitare: <span class="black_id"></span></td>
 <td class="le info-opt">In prova: <span class="test_id"></span></td>
 <td class="le info-opt">Amico: <span class="friend_id"></span></td>
-<td class="le info-opt">Fidato: <span class="bff_id"></span></td><td></td></tr>
+<td class="le info-opt">Fidato: <span class="bff_id"></span></td></tr>
 
 <!-- <tr class="narrowfriendh_id"><td colspan="3"><b>Cosa ne pensano gli amici fidati:</b></td>
 <td class="le info-opt">Bravura: <span class="skill_id"></span></td></tr> -->
index 9cba917..499a7e1 100644 (file)
@@ -48,8 +48,7 @@ function info_fld(dobj)
                    skill: { type: 'radio' },
                    trust: { type: 'radio' }
                  };
-
-    return (new Fieldify(dobj, fields));
+    return (new Fieldify([dobj], fields));
  }
 
 function info_show(username)