<%
   defaultValue = (defined? property.defaultValue) ? property.defaultValue : nil
%>
<select name="<%= name -%>" id="<%= id -%>">
  <option value=""><%= !defaultValue.blank? ? message('default') : nil -%></option>
  <%
     metrics_per_domain={}
     metrics_filtered_by(property.options).each do |metric|
       domain=metric.domain || ''
       metrics_per_domain[domain]||=[]
       metrics_per_domain[domain]<<metric
     end

     metrics_per_domain.keys.sort.each do |domain|
  %>
    <optgroup label="<%= h domain -%>">
      <% metrics_per_domain[domain].each do |m|
        selected_attr = (m.key==value || m.id==value) ? " selected='selected'" : ''
      %>
        <option value="<%= m.key -%>" <%= selected_attr -%>><%= m.short_name -%></option>
      <% end -%>
    </optgroup>
  <% end -%>
</select>