1 function ends_with(s, suffix)
3 if (s.indexOf(suffix, s.length - suffix.length) !== -1) {
9 function __ffa_nav(obj, ret, name)
13 arr = obj.className.split(" ");
14 if (arr.indexOf(name + "_id") != -1) {
19 // check if the current element is a leaf or a node
20 // if it is then return
21 for (var i = 0 ; i < arr.length ; i++) {
22 if (ends_with(arr[i], "_id")) {
27 for (var i = 0 ; i < obj.children.length ; i++) {
28 __ffa_nav(obj.children[i], ret, name);
33 function fieldify_get_dom_element(objarr, name)
37 for (var i = 0 ; i < objarr.length ; i++) {
39 for (var e = 0 ; e < obj.children.length ; e++) {
40 __ffa_nav(obj.children[e], ret, name);
50 // fieldsdescr = { name: { type: 'typename' }, ... }
51 function Fieldify(dom_elements, fieldsdescr)
55 this.dom_elements = dom_elements;
56 this.field = new Array();
57 for (k in fieldsdescr) {
58 this.field[k] = fieldsdescr[k];
59 if (this.field[k].type == 'fields') {
60 if (item = fieldify_get_dom_element(this.dom_elements, k)) {
61 this.field[k].obj = new Fieldify(item, this.field[k].fields);
67 Fieldify.prototype = {
71 visible: function(is_visible) {
72 this.dom_elements[0].style.visibility = (is_visible ? "visible" : "hidden" );
75 // { 'name': 'value' }
76 json2dom: function(field_values)
78 for (k in this.field) {
79 if (this.field[k].type == 'value') {
80 this.fld_value_set(k, field_values[k]);
82 else if (this.field[k].type == 'radio') {
83 this.fld_radio_set(k, field_values[k]);
85 else if (this.field[k].type == 'fields') {
86 this.field[k].obj.json2dom(field_values[k]);
94 for (k in this.field) {
95 if (this.field[k].perms == 'ro')
97 if (this.field[k].type == 'value') {
98 ret[k] = this.fld_value_get(k);
100 else if (this.field[k].type == 'radio') {
101 ret[k] = this.fld_radio_get(k);
103 else if (this.field[k].type == 'fields') {
104 ret[k] = this.field[k].obj.dom2json();
110 fld_value_set: function(name, value)
112 var item = fieldify_get_dom_element(this.dom_elements, name);
114 item[0].innerHTML = value;
118 fld_value_get: function(name)
120 var item = fieldify_get_dom_element(this.dom_elements, name);
122 return (item[0].innerHTML);
127 fld_radio_set: function(name, value)
129 var arr = fieldify_get_dom_element(this.dom_elements, name);
132 if (arr[k].value == value)
133 arr[k].checked = true;
135 arr[k].checked = false;
140 fld_radio_get: function(name)
143 var arr = fieldify_get_dom_element(this.dom_elements, name);
146 if (arr[k].checked == true) {