5 This *RECURSIVELY* displays inputs for a hash of html elements
8 classmetadata-- the hash of bunch of data:
9 cgi -- inputs keyed on column names
10 table -- table inputs are for
11 columns -- list in order want displayed inputs
12 colnames -- hash of what to label inputs
14 errors -- hash of errors keyed on columns
17 TODO -- make it recognize a general submit button for redisplaying
28 # get hash of related classes keyed on accessor for Foreign Inputs
29 USE this = Class(classmetadata.name);
30 tbl = classmetadata.table;
32 FOR c IN request.config.$tbl.required_cols;
39 SET heading_shown = 0;
40 FOR col = classmetadata.columns;
41 NEXT IF !classmetadata.cgi.$col;
42 NEXT IF col == "id" OR col == classmetadata.table _ "_id";
43 # Display foreign inputs last
44 IF (mykeys = classmetadata.cgi.$col.keys);
46 names.push(classmetadata.colnames.$col);
50 heading = classmetadata.moniker | ucfirst;
51 "<h4> $heading </h4>";
52 SET heading_shown = 1;
56 [% # Base case starts here
58 SET elem = classmetadata.cgi.$col; #.clone; # not sure why clone
59 IF elem.type == 'hidden';
63 param_col = col_prefix _ col;
64 IF elem.tag == "textarea";
65 elem = elem.push_content(cgi_params.$param_col);
66 ELSIF elem.tag == "select";
67 oldval = set_selected(elem, cgi_params.$col);
69 oldval = elem.attr("value", cgi_params.$param_col);
76 SET indicator = '*' IF (required.$col);
79 [% indicator _ classmetadata.colnames.$col ||
80 col | replace('_',' ') | ucfirst %]
86 <span class="error">[% errors.$col | html %]</span>
90 <!-- Display the differnt component inputs -->
92 [% USE this = Class(classmetadata.name);
94 # has_many mapping throws a stick in our spokes because related_class returns the mapped
95 # class. Sometimes we just want the has_many class.
97 # In case of Pub Handpumps maps to Beer and we want to add Handpump to Pub, we dont
98 # want the mapped data .
99 # In case of "Create New Handpump" -- we want the mapped data probably so we get
100 # Beer inputs and Pub select box.
102 fclass_rel_meta = this.related_meta(request, col);
103 fclass = fclass_rel_meta.foreign_class; # ignor args.mapping
104 fclass_meta = this.get_classmetadata(fclass);
105 fclass_meta.cgi = classmetadata.cgi.$col;
106 # USE Dumper; Dumper.dump(fclass_meta);
107 INCLUDE display_inputs
108 col_prefix = col _ "__AF__" _ col_prefix
110 heading = names.shift
111 classmetadata = fclass_meta; # localize