<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:tal="http://xml.zope.org/namespaces/tal"
    xmlns:metal="http://xml.zope.org/namespaces/metal"
    xmlns:i18n="http://xml.zope.org/namespaces/i18n"
    i18n:domain="senaite.health">

<head>
    <title>CasePatientCondition Widget</title>
</head>
<body>
    <metal:view_macro define-macro="view">
        <fieldset tal:attributes="id string:${fieldName};
                                  name string:${fieldName};"
                  tal:define="i18n_domain field/widget/i18n_domain|context/i18n_domain|string:plone;
                              data python:widget.getPatientCondition();">

            <!-- Height -->
            <div class="fieldline" tal:define="units python:widget.getHeightUnits()">
                <div class="fieldline-label">
                    <span i18n:translate="">Height</span>
                </div>
                <div class="fieldline-content">
                    <tal:heights tal:repeat="idx python:range(len(units))">
                        <span tal:content="python:widget.getConditionValue('Height', units[idx]) or '-'"></span>&nbsp;
                        <span tal:content="python:units[idx]"></span>&nbsp;&nbsp;
                    </tal:heights>
                </div>
                <div class="clear-both"></div>
            </div>

            <!-- Weight -->
            <div class="fieldline" 
                 tal:define="units python:widget.getWeightUnits();
                             baseidx python:len(widget.getWeightUnits());">
                <div class="fieldline-label">
                    <span i18n:translate="">Weight</span>
                </div>
                <div class="fieldline-content">
                    <tal:heights tal:repeat="idx python:range(len(units))">
                        <span tal:content="python:widget.getConditionValue('Weight', units[idx]) or '-'"></span>&nbsp;
                        <span tal:content="python:units[idx]"></span>&nbsp;&nbsp;
                    </tal:heights>
                </div>
                <div class="clear-both"></div>
            </div>
            
            <!-- Waist -->
            <div class="fieldline" 
                 tal:define="units python:widget.getWaistUnits();
                                baseidx python:len(widget.getHeightUnits())+len(widget.getWeightUnits());">
                <div class="fieldline-label">
                    <span i18n:translate="">Waist</span>
                </div>
                <div class="fieldline-content">
                    <tal:heights tal:repeat="idx python:range(len(units))">
                        <span tal:content="python:widget.getConditionValue('Waist', units[idx]) or '-'"></span>&nbsp;
                        <span tal:content="python:units[idx]"></span>&nbsp;&nbsp;
                    </tal:heights>
                </div>
                <div class="clear-both"></div>
            </div>
        </fieldset>
    </metal:view_macro>
    <metal:edit_macro define-macro="edit">
    <metal:use use-macro="here/widgets/field/macros/edit">
    <tal:block metal:fill-slot="widget_body">
        <span tal:replace="structure context/@@authenticator/authenticator"/>                
        
        <fieldset tal:attributes="id string:${fieldName};
                                  name string:${fieldName};"                
             tal:define="values python:field.getEditAccessor(here)();
                         session_values python:here.session_restore_value(fieldName, values);
                         cached_values python:request.get(fieldName,session_values);
                         values python:cached_values or values;
                         i18n_domain field/widget/i18n_domain|context/i18n_domain|string:plone;
                         data python:widget.getPatientCondition();
                         mainidx python:0;">
        
            <!-- Height -->
            <div class="fieldline">
                <div class="fieldline-label">
                    <label tal:attributes="for string:${fieldName}.Height:records;"
                       i18n:translate="">Height</label>
                </div>
                <div class="fieldline-content"                                  
                     tal:define="units python:widget.getHeightUnits()">                                    
                    <tal:heights tal:repeat="idx python:range(len(units))">
                    
                        <input type="text"
                            tal:attributes="name string:${fieldName}.Value:records;
                                            id string:${fieldName}-Value-${repeat/idx/index};
                                            maxlength string:4;
                                            class string:numeric;
                                            value python:widget.getConditionValue('Height', units[idx]);
                                            size string:4;"/>
                        &nbsp;<span tal:content="python:units[idx]"/>&nbsp;&nbsp;
                        <input type="hidden"
                            tal:attributes="name string:${fieldName}.Condition:records;
                                            id string:${fieldName}-Condition-${repeat/idx/index};
                                            value string:Height"/>
                        <input type="hidden"
                            tal:attributes="name string:${fieldName}.Unit:records;
                                            id string:${fieldName}-Unit-${repeat/idx/index};
                                            value python:units[idx];"/>
                            
                    </tal:heights> 
                </div>
                <div class="clear-both"></div>
            </div>
            
            <!-- Weight -->
            <div class="fieldline">
                <div class="fieldline-label">
                    <label tal:attributes="for string:${fieldName}.Weight:records;"
                       i18n:translate="">Weight</label>
                </div>
                <div class="fieldline-content"
                    tal:define="units python:widget.getWeightUnits();
                                baseidx python:len(widget.getWeightUnits());">                                    
                    <tal:weights tal:repeat="idx python:range(len(units))">
                    
                        <input type="text"
                            tal:attributes="name string:${fieldName}.Value:records;
                                            id python:'%s-Value-%s' % (fieldName, baseidx+idx);
                                            maxlength string:4;
                                            class string:numeric;
                                            value python:widget.getConditionValue('Weight', units[idx]);
                                            size string:4;"/>
                        &nbsp;<span tal:content="python:units[idx]"/>&nbsp;&nbsp;
                        <input type="hidden"
                            tal:attributes="name string:${fieldName}.Condition:records;
                                            id python:'%s-Condition-%s' % (fieldName, baseidx+idx);
                                            value string:Weight"/>
                        <input type="hidden"
                            tal:attributes="name string:${fieldName}.Unit:records;
                                            id python:'%s-Unit-%s' % (fieldName, baseidx+idx);
                                            value python:units[idx];"/>
                            
                    </tal:weights> 
                </div>
                <div class="clear-both"></div>
            </div>
            
            <!-- Waist -->
            <div class="fieldline">
                <div class="fieldline-label">
                    <label tal:attributes="for string:${fieldName}.Waist:records;"
                       i18n:translate="">Waist</label>
                </div>
                <div class="fieldline-content"
                    tal:define="units python:widget.getWaistUnits();
                                baseidx python:len(widget.getHeightUnits())+len(widget.getWeightUnits());">                                    
                    <tal:waists tal:repeat="idx python:range(len(units))">
                    
                        <input type="text"
                            tal:attributes="name string:${fieldName}.Value:records;
                                            id python:'%s-Value-%s' % (fieldName, baseidx+idx);
                                            maxlength string:4;
                                            class string:numeric;
                                            value python:widget.getConditionValue('Waist', units[idx]);
                                            size string:4;"/>
                        &nbsp;<span tal:content="python:units[idx]"/>&nbsp;&nbsp;
                        <input type="hidden"
                            tal:attributes="name string:${fieldName}.Condition:records;
                                            id python:'%s-Condition-%s' % (fieldName, baseidx+idx);
                                            value string:Waist"/>
                        <input type="hidden"
                            tal:attributes="name string:${fieldName}.Unit:records;
                                            id python:'%s-Unit-%s' % (fieldName, baseidx+idx);
                                            value python:units[idx];"/>
                            
                    </tal:waists> 
                </div>
                <div class="clear-both"></div>
            </div>
                        
        </fieldset>
    </tal:block> 
    </metal:use>
    </metal:edit_macro>
</body>
</html>