X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=ex%2Ffancy_example%2Ftemplates%2Fcustom%2Fdisplay_inputs.recursive;fp=ex%2Ffancy_example%2Ftemplates%2Fcustom%2Fdisplay_inputs.recursive;h=5c7d56559ac797f1112c62b4678b30b493f6137b;hb=7bb021648c28d2f70ec2853f0d01dd49c6437460;hp=0000000000000000000000000000000000000000;hpb=c3973978e1373a262d13da63c9e9ecfde4b72cc7;p=maypole.git
diff --git a/ex/fancy_example/templates/custom/display_inputs.recursive b/ex/fancy_example/templates/custom/display_inputs.recursive
new file mode 100644
index 0000000..5c7d565
--- /dev/null
+++ b/ex/fancy_example/templates/custom/display_inputs.recursive
@@ -0,0 +1,97 @@
+[%#
+
+=head1 display_inputs
+
+This *RECURSIVELY* displays inputs for a hash of html elements
+
+Vars it needs:
+ classmetadata-- the hash of bunch of data:
+ cgi -- inputs keyed on column names
+ table -- table inputs are for
+ columns -- list in order want displayed inputs
+ colnames -- hash of what to label inputs
+
+errors -- hash of errors keyed on columns
+
+
+TODO -- make it recognize a general submit button for redisplaying
+values on errors
+
+=cut
+
+#
+%]
+
+[% # some variables
+ foreign = [];
+ names = [];
+ # get hash of related classes keyed on accessor for Foreign Inputs
+ USE this = Class(classmetadata.name);
+ tbl = classmetadata.table;
+ required = { };
+ FOR c IN request.config.$tbl.required_cols;
+ required.$c = 1;
+ END;
+%]
+
+[% FOR col = classmetadata.columns;
+ NEXT IF !classmetadata.cgi.$col;
+ NEXT IF col == "id";
+
+ # Display foreign inputs last
+ IF (mykeys = classmetadata.cgi.$col.keys);
+ foreign.push(col);
+ names.push(classmetadata.colnames.$col);
+ NEXT;
+ END;
+%]
+
+[% # Base case starts here
+
+ SET elem = classmetadata.cgi.$col; #.clone; # not sure why clone
+ IF elem.type == 'hidden';
+ elem.as_XML;
+ NEXT;
+ ELSIF cgi_params;
+ param_col = col_prefix _ col;
+ IF elem.tag == "textarea";
+ elem = elem.push_content(cgi_params.$param_col);
+ ELSIF elem.tag == "select";
+ oldval = set_selected(elem, cgi_params.$col);
+ ELSE;
+ oldval = elem.attr("value", cgi_params.$param_col);
+ END;
+ END;
+%]
+
+
+
+ [% IF errors.$col %]
+ [% errors.$col | html %]
+ [% END %]
+[% END; %]
+
+
+
+[% USE this = Class(classmetadata.name);
+ FOR col IN foreign;
+ fclass = this.related_class(request, col);
+ fclass_meta = this.get_classmetadata(fclass);
+ fclass_meta.cgi = classmetadata.cgi.$col;
+ INCLUDE display_inputs
+ col_prefix = col _ "__AF__" _ col_prefix
+ errors = errors.$col
+ heading = names.shift
+ classmetadata = fclass_meta; # localize
+ END;
+%]
+