]> git.decadent.org.uk Git - maypole.git/blobdiff - ex/fancy_example/templates/custom/display_inputs
tested and it seems to work
[maypole.git] / ex / fancy_example / templates / custom / display_inputs
index 201227ccf9803716ef4474de034cf151e92e398e..6baf703c7acb546588fba45696575704c3075bc2 100644 (file)
@@ -32,18 +32,25 @@ values on errors
    FOR c IN request.config.$tbl.required_cols;
         required.$c = 1;
    END;
+
 %]     
 
-[% FOR col = classmetadata.columns;  
+[% 
+SET heading_shown = 0; 
+FOR col = classmetadata.columns;  
        NEXT IF !classmetadata.cgi.$col;
        NEXT IF col == "id" OR col == classmetadata.table _ "_id";
-
        # Display foreign inputs last 
        IF (mykeys = classmetadata.cgi.$col.keys); 
                        foreign.push(col);
                        names.push(classmetadata.colnames.$col);
                        NEXT;
        END;
+    IF ! heading_shown; 
+       heading = classmetadata.moniker | ucfirst; 
+               "<h4> $heading </h4>";
+       SET heading_shown = 1; 
+    END;
 %]
 
 [%  # Base case starts here 
@@ -84,9 +91,19 @@ values on errors
 
 [%     USE this = Class(classmetadata.name); 
        FOR col IN foreign; 
-               fclass = this.related_class(request, col); 
+               # has_many mapping throws a stick in our spokes because related_class returns the mapped 
+               # class. Sometimes we just want the has_many class. 
+
+        # In case of Pub Handpumps maps to Beer and we want to add Handpump to Pub, we dont 
+               # want the mapped data .
+        # In case of "Create New Handpump" -- we want the mapped data probably so we get
+        # Beer inputs and Pub select box.
+
+               fclass_rel_meta = this.related_meta(request, col);
+        fclass = fclass_rel_meta.foreign_class; # ignor args.mapping
                fclass_meta = this.get_classmetadata(fclass);
-               fclass_meta.cgi = classmetadata.cgi.$col; 
+               fclass_meta.cgi = classmetadata.cgi.$col;
+ #       USE Dumper; Dumper.dump(fclass_meta);
                INCLUDE display_inputs
                        col_prefix = col _ "__AF__" _ col_prefix
                        errors = errors.$col