<% content_for :page_specific_css do %>
  <%= stylesheet_link_tag "lib/main-forms" %>
<% end 
   delete_domain_button = button_tag("#{t('delete_')} domain", class: 'btn btn-danger', 
                                              :onclick=> "delete_domain(this)",
                                              :type => 'button')
%>
<script type="text/javascript">
  function add_domain(ele){
    var tp=$(ele);
    var tp2=tp.parents('.controls').eq(0).find('.group');
    var tp3=tp2.find('.domain_name').eq(0).clone();
    tp3.val('');
    tp2.append('<br>');
    tp2.append(tp3);
    tp2.append('<%= delete_domain_button %>')
  }
  function add_default_domain(ele){
    var tp=$(ele);
    var tp2=tp.parents('.controls').eq(0).find('.group');
    var tp3 = '<input class="domain_name" name="site_server[default_domain_names][]" type="text" placeholder="*.example.com (<%=t("client_management.domain_hint")%>)" title="*.example.com (<%=t("client_management.domain_hint")%>)">';
    tp2.append('<br>');
    tp2.append(tp3);
    tp2.append('<%= delete_domain_button %>')
  }
  function delete_domain(ele){
    $(ele).prev('input').remove()
    $(ele).prev('br').remove()
    $(ele).remove()
  }
</script>
<%= form_for @site_server ,:url=>{:action=>"edit_server_info",:type=>'update'},:method=>:post, :html => {:class=>"form-horizontal main-forms"} do |f|%>
  <fieldset>
    <input type='hidden' name='id' value='<%=@site_server.id.to_s%>'/>
    <!-- Input Area -->
    <div class="input-area">
      <!-- Module Tabs -->
      <div class="nav-name"><strong><%= t(:module) %></strong></div>
      <ul class="nav nav-pills module-nav">
          <li class="active">
            <a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
          </li>
      </ul>
      <!-- Module -->
      <div class="tab-content module-area">
        <!-- Basic Module -->
        <div class="tab-pane fade in active" id="basic">
          <!-- Category -->
          <div class="control-group">
            <label class="control-label muted"><%= t(:category) %></label>
            <div class="controls">
              <%= select_category(f, @module_app) %>
            </div>
          </div>
          <!-- Tag Module -->
          <div class="control-group">
            <label class="control-label muted"><%= t(:tags) %></label>
            <%= select_tags(f, @module_app) %>
          </div>
          <% unless @site_server.new_record? %>
          <div class="control-group">
            <label class="control-label muted" for="active_server"><%= t("client_management.active") %></label>
            <div class="controls">
              <%= f.check_box :active,:id=>"active_server",:title=>t("client_management.active") %>
            </div>
          </div>
          <% end %>
          <div class="control-group">
            <label class="control-label muted" for="server_name">Server name:</label>
            <div class="controls">
              <% if @site_server.new_record? %>
                <%= f.text_field :server_name,{:id=>'server_name'} %>
              <% else %>
                <span style=" display: inline-block; vertical-align: -webkit-baseline-middle; font-size: 1.5em;"><%= @site_server.server_name %></span>
                <% f.hidden_field :server_name,{:id=>'server_name'} %>
              <% end%>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="domain_name">Domain name:</label>
            <div class="controls">
              <div class="group">
              <% 
              tp = @site_server.domain_names
              tp << '' if tp.length == 0
              tp.each_with_index do |domain_name,i| %>
                <%= '<br>'.html_safe if i !=0 %>
                <%= text_field_tag "site_server[domain_names][]",domain_name,{:id=>nil,:class=>"domain_name"} %>
                <%= delete_domain_button if i !=0 %>
              <% end %>
              </div>
              <%= f.button "#{t('add')} domain", class: 'btn btn-info', 
                  :onclick=> "add_domain(this)",
                  :type => 'button'
              %>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="enable_redirect_default_domain"><%= t("client_management.redirect_to_default_domain_name") %></label>
            <div class="controls">
              <%= f.check_box :enable_redirect_default_domain,:id=>"enable_redirect_default_domain" %>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="default_domain_names"><%=t("client_management.default_domain_names")%>:</label>
            <div class="controls">
              <div class="group">
              <% 
              @site_server.default_domain_names.each_with_index do |domain_name,i| %>
                <%= '<br>'.html_safe if i !=0 %>
                <%= text_field_tag "site_server[default_domain_names][]",domain_name,{:id=>nil,:class=>"domain_name"} %>
                <%= delete_domain_button %>
              <% end %>
              </div>
              <%= f.button "#{t('add')} domain", class: 'btn btn-info', 
                  :onclick=> "add_default_domain(this)",
                  :type => 'button'
              %>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="ip">IP:</label>
            <div class="controls">
              <%= f.text_field :ip,{:id=>'ip'} %>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="port">Port:</label>
            <div class="controls">
              <%= f.text_field :port,{:id=>'port'} %>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="account">Account:</label>
            <div class="controls">
              <%= f.text_field :account,{:id=>'account'} %>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label muted" for="password">Password:</label>
            <div class="controls">
              <%= f.text_field :password,{:id=>'password'} %>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="form-actions">
      <%= f.submit t('submit'), class: 'btn btn-primary' %>
    </div>
  </fieldset>
<% end %>