From e2d1e08df1bfffaeda9487b60a0d13aafbedde57 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 10 Dec 2015 18:41:51 +0100 Subject: [PATCH] Fieldify: add multiple ancestor object to allow multi-tr fields --- web/Obj/dbase_pgsql.phh | 10 +++---- web/fieldify.js | 66 +++++++++++++++++++++++++++-------------- web/index.php | 2 +- web/info.js | 3 +- 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index 79924e4..520a4f0 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -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) diff --git a/web/fieldify.js b/web/fieldify.js index cb14c6e..1447d41 100644 --- a/web/fieldify.js +++ b/web/fieldify.js @@ -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; diff --git a/web/index.php b/web/index.php index 12972e9..1e1b09d 100644 --- a/web/index.php +++ b/web/index.php @@ -1392,7 +1392,7 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi Da evitare: In prova: Amico: -Fidato: +Fidato: diff --git a/web/info.js b/web/info.js index 9cba917..499a7e1 100644 --- a/web/info.js +++ b/web/info.js @@ -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) -- 2.17.1