<% sub_domains = field.sub_domains.order("priority") %>
<% if sub_domains %>
    <% sub_domains.each do |subdomain| %>
        <ul class="orgSubList">
          <li class="orgSubTree"></li>
          <li class="orgSubNum ml5 mr5">
            <div id="show_domain_priority_<%= subdomain.id %>" ondblclick="edit_priority('#show_domain_priority_<%= subdomain.id %>','#edit_domain_priority_<%= subdomain.id %>');"  class="subNumBlock" title="双击可编辑">
              <%= subdomain.priority %>
            </div>
            <div id="edit_domain_priority_<%= subdomain.id %>" style="display:none; width:30px;">
              <input type="text" onblur="domain_update_priority('#show_domain_priority_<%= subdomain.id %>','#edit_domain_priority_<%= subdomain.id %>','<%= subdomain.org_subfield.id %>','<%= subdomain.id %>',$(this).val());" style="width:20px;" value="<%= subdomain.priority %>"/>
            </div>
          </li>
          <li class="orgSubColumn">
            <div id="subsubdomain_show_<%= subdomain.id %>" class="subColumnControl" title="<%= subdomain.name %>"><%= subdomain.name %></div>
            <div id="subsubdomain_edit_<%= subdomain.id %>" style="display:none;">
              <input type="text" name="name" onblur="update_subfield_subdomain('#subsubdomain_show_<%= subdomain.id %>','#subsubdomain_edit_<%= subdomain.id %>','<%= subdomain.org_subfield.id %>','<%= subdomain.id %>',$(this).val());" value="<%= subdomain.name %>" style="width:70px;"/>
            </div>
          </li>
          <li class="orgSubStatus">新增</li>
          <li class="orgSubOrder">
            默认
          </li>
          <li class="orgSubType"><%= subdomain.field_type == "Post" ? "帖子" : "资源" %></li>
          <li class="orgListCatalog hidden"> -- </li>
          <%#= link_to "隐藏", hide_org_subsubdomain_organizations_path(subdomain), :method => 'post', :remote => true, :id => "hide_#{subdomain.id}", :class => "linkBlue fr mr5" %>
          <li class="orgSubOperation">
            <a href="javascript:void(0);" class="linkGrey fr ml5 mr10" onclick="hide_domain($(this),'<%= subdomain.org_subfield.id %>','<%= subdomain.id %>');" id="hide_<%= subdomain.id %>"><%= subdomain.hide==0?"隐藏":"可见" %></a>
            <span class="fr">|</span>
            <%= link_to "删除", org_subfield_sub_domain_path(subdomain, :org_subfield_id => subdomain.org_subfield.id), :method => 'delete', :remote => true, :confirm => "您确定删除吗？", :class => "linkGrey fr ml5 mr5" %>
            <span class="fr">|</span>
            <a href="javascript:void(0);" class="linkGrey fr ml5 mr5" onclick="edit('#subsubdomain_show_<%= subdomain.id %>','#subsubdomain_edit_<%= subdomain.id %>');">编辑</a>
          </li>
          <div class="cl"></div>
        </ul>
    <% end %>
<% end %>

<script>
    function update_subfield_subdomain(show_id, edit_id, field_id, domain_id, input_value) {
        if ($(show_id).html().trim() != input_value.trim()) {
            if (confirm('确定修改为' + input_value + "?"))
                $.ajax({
                    url: "/org_subfields/" + field_id + "/sub_domains/"  + domain_id + "?name=" + input_value,
                    type: 'put'
                });
            else{
                $(edit_id).children("input").val($(show_id).html().trim());
            }
        }
        $(show_id).show();
        $(edit_id).hide();
//       $(edit_id).focus();
    }


    function domain_update_priority(show_id, edit_id, field_id, domain_id, input_value){
        var re = /^[0-9]*[1-9]*[0-9]$/
        if(re.test(input_value) && $(show_id).html().trim() != input_value.trim() && input_value.trim() != ''){
            $.ajax({
                url: "/org_subfields/" + field_id + "/sub_domains/"  + domain_id + "/domain_update_priority?priority=" + input_value,
                type: 'put'
            });
        }
        else{
            $(edit_id).children("input").val($(show_id).html().trim());
        }
        $(show_id).show();
        $(edit_id).hide();
    }

    function hide_domain(content, field_id, domain_id){
        if (content.text() == '隐藏')
            $.ajax({
                url: "/org_subfields/" + field_id + "/sub_domains/"  + domain_id + "/hide_sub_domain",
                type: "post"
            });
        else
            $.ajax({
                url: "/org_subfields/" + field_id + "/sub_domains/"  + domain_id + "/show_sub_domain",
                type: "post"
            });
    }
</script>
