# $Id$

# TODO: JEP-0004


namespace eval data {}


proc data::fill_fields {g items} {
    variable data
    global font

    set row 0
    set data(varlist,$g) {}
    
    grid columnconfig $g 1 -weight 1 -minsize 0

    foreach item $items {
	jlib::wrapper:splitxml $item tag vars isempty chdata children

	switch -- $tag {
	    instructions {
		message $g.instructions$row -text $chdata -width 10c
		grid $g.instructions$row -row $row -column 0 -columnspan 2 \
		    -sticky w
		incr row
	    }
	    x {}
	    default {
		lappend data(varlist,$g) $tag

		label $g.l$tag -text $tag
		entry $g.$tag \
		    -textvariable [namespace current]::data(var,$g,$tag) \
		    -font $font

		if {$chdata != {}} {
		    set data(var,$g,$tag) $chdata
		}

		grid $g.l$tag -row $row -column 0 -sticky e
		grid $g.$tag  -row $row -column 1 -sticky we

		incr row
	    }
	}
    }
}


proc data::get_tags {g} {
    variable data

    set restags {}

    foreach var $data(varlist,$g) {
	lappend restags [jlib::wrapper:createtag $var \
			     -chdata $data(var,$g,$var)]

    }

    return $restags
}

proc data::get_reported_fields {g} {
    variable data

    return $data(varlist,$g)
}

