<tal:comment replace="nothing">View macro for a Date.</tal:comment>
<metal:view define-macro="view"><span tal:replace="value"/></metal:view>

<tal:comment replace="nothing">Edit macro for an Date.</tal:comment>
<metal:edit define-macro="edit"
            tal:define="years python: contextObj.getSelectableYears(widget['name'])">
  <tal:comment replace="nothing">Day</tal:comment>
  <select tal:define="days python:range(1,32)"
          tal:attributes="name string:${name}_day;
                          id   string:${name}_day;">
    <option value="">-</option>
    <tal:days repeat="day days">
      <option tal:define="zDay python: str(day).zfill(2)"
              tal:attributes="value zDay;
                              selected python:contextObj.dateValueSelected(name, 'day', day, rawValue)"
              tal:content="zDay"></option>
    </tal:days>
  </select>

  <tal:comment replace="nothing">Month</tal:comment>
  <select tal:define="months python:range(1,13)"
          tal:attributes="name string:${name}_month;
                          id   string:${name}_month;">
    <option value="">-</option>
    <tal:months repeat="month months">
      <option tal:define="zMonth python: str(month).zfill(2)"
              tal:attributes="value zMonth;
                              selected python:contextObj.dateValueSelected(name, 'month', month, rawValue)"
              tal:content="zMonth"></option>
    </tal:months>
  </select>

  <tal:comment replace="nothing">Year</tal:comment>
  <select tal:attributes="name string:${name}_year;
                          id   string:${name}_year;">
    <option value="">-</option>
    <option tal:repeat="year years"
            tal:attributes="value year;
                            selected python:contextObj.dateValueSelected(name, 'year', year, rawValue)"
            tal:content="year"></option>
  </select>
  <tal:comment replace="nothing">The icon for displaying the calendar popup</tal:comment>
  <input type="hidden" tal:attributes="id name; name name"/>
  <img tal:attributes="id string:${name}_img; src string: $appUrl/ui/calendar.gif"/>
  <script tal:content="python: contextObj.getCalendarInit(name, years)"></script>

  <tal:hour condition="python: widget['format'] == 0">
    <select tal:define="hours python:range(0,24);"
            tal:attributes="name string:${name}_hour;
                            id   string:${name}_hour;">
      <option value="">-</option>
      <tal:hours repeat="hour hours">
        <option tal:define="zHour python: str(hour).zfill(2)"
                tal:attributes="value zHour;
                                selected python:contextObj.dateValueSelected(name, 'hour', hour, rawValue)"
                tal:content="zHour"></option>
      </tal:hours>
    </select> :
    <select tal:define="minutes python:range(0,60,5);"
            tal:attributes="name string:${name}_minute;
                            id   string:${name}_minute;">
      <option value="">-</option>
      <tal:minutes repeat="minute minutes">
        <option tal:define="zMinute python: str(minute).zfill(2)"
                tal:attributes="value zMinute;
                                selected python:contextObj.dateValueSelected(name, 'minute', minute, rawValue)"
                tal:content="zMinute"></option>
      </tal:minutes>
    </select>
  </tal:hour>
</metal:edit>

<tal:comment replace="nothing">Cell macro for an Date.</tal:comment>
<metal:cell define-macro="cell">
  <metal:call use-macro="app/ui/widgets/date/macros/view"/>
</metal:cell>

<tal:comment replace="nothing">Search macro for an Date.</tal:comment>
<metal:search define-macro="search"
              tal:define="years python:range(widget['startYear'], widget['endYear']+1)">
  <label tal:content="python: _(widget['labelId'])"></label>
  <table>
    <tal:comment replace="nothing">From</tal:comment>
    <tr tal:define="fromName      python: '%s_from' % name;
                    dayFromName   python: '%s_from_day' % name;
                    monthFromName python: '%s_from_month' % name;
                    yearFromName  python: '%s*date' % widgetName">
      <td width="10px">&nbsp;</td>
      <td>
        <label tal:content="python: _('search_from')"></label>
      </td>
      <td>
        
        <select tal:attributes="id dayFromName; name dayFromName">
          <option value="">--</option>
          <option tal:repeat="value python: [str(v).zfill(2) for v in range(1, 32)]"
                  tal:content="value" tal:attributes="value value"></option>
        </select> /
        <select tal:attributes="id monthFromName; name monthFromName">
          <option value="">--</option>
          <option tal:repeat="value python: [str(v).zfill(2) for v in range(1, 13)]"
                  tal:content="value" tal:attributes="value value"></option>
        </select> /
        <select tal:attributes="id yearFromName; name yearFromName">
          <option value="">--</option>
          <option tal:repeat="value python:range(widget['startYear'], widget['endYear']+1)"
                  tal:content="value" tal:attributes="value value"></option>
        </select>
       <tal:comment replace="nothing">The icon for displaying the calendar popup</tal:comment>
       <input type="hidden" tal:attributes="id fromName; name fromName"/>
       <img tal:attributes="id string:${fromName}_img; src string: $appUrl/ui/calendar.gif"/>
       <script tal:content="python: tool.getCalendarInit(fromName, years)"></script>
      </td>
    </tr>
    <tal:comment replace="nothing">To</tal:comment>
    <tr tal:define="toName      python: '%s_to' % name;
                    dayToName   python: '%s_to_day' % name;
                    monthToName python: '%s_to_month' % name;
                    yearToName  python: '%s_to_year' % name">
      <td></td>
      <td>
        <label tal:content="python: _('search_to')"></label>&nbsp;&nbsp;&nbsp;&nbsp;
      </td>
      <td height="20px;">
        <select tal:attributes="id dayToName; name dayToName">
          <option value="">--</option>
          <option tal:repeat="value python: [str(v).zfill(2) for v in range(1, 32)]"
                  tal:content="value" tal:attributes="value value"></option>
        </select> /
        <select tal:attributes="id monthToName; name monthToName">
          <option value="">--</option>
          <option tal:repeat="value python: [str(v).zfill(2) for v in range(1, 13)]"
                  tal:content="value" tal:attributes="value value"></option>
        </select> /
        <select tal:attributes="id yearToName; name yearToName">
          <option value="">--</option>
          <option tal:repeat="value python:range(widget['startYear'], widget['endYear']+1)"
                 tal:content="value" tal:attributes="value value"></option>
        </select>
       <tal:comment replace="nothing">The icon for displaying the calendar popup</tal:comment>
       <input type="hidden" tal:attributes="id toName; name toName"/>
       <img tal:attributes="id string:${toName}_img; src string: $appUrl/ui/calendar.gif"/>
       <script tal:content="python: tool.getCalendarInit(toName, years)"></script>
      </td>
    </tr>
  </table>
</metal:search>
