<script type="text/javascript">
var localDomains = "";
$(document).ready(function() {
  $.validationEngineLanguage.newLang(localDomains);
  $("#content_item").validationEngine();
});
</script>

<%= form_with(model: @content_item, url: {action: :register_item},
  id: 'content_item', html: {name: "content_item", multipart: true }) do |f| %>
  <%= f.hidden_field :master_frame, {value: @content_item.master_frame} %>
  <%= f.hidden_field :category, {value: @content_item.category} %>
  <% if @edit_type == "update" -%><%= f.hidden_field :id, {value: @content_item.id} %><%- end -%>
  <% case @content_item.category when 1 -%>
  <fieldset>
    <h2><%= $content_item_category[@content_item.category - 1][0] %></h2>
    <div class="table-sys-a1">
      <div class="item-body">
        <div class="item-tr">
          <div class="item-mid">タイトル</div>
          <div class="input-mid">
            <%= f.text_field :string1, 
                  {value: @content_item.string1, class: 'validate[required, maxSize[50]]'} %>
          </div>
        </div>
      </div>
    </div>
  </fieldset>
  <% when 2 -%>
  <fieldset>
    <h2><%= $content_item_category[@content_item.category - 1][0] %></h2>
    <div class="table-sys-a1">
      <div class="item-body">
        <div class="item-tr">
          <div class="table-sys-a2">
            <div class="item-body">
              <div class="item-tr">
                <div class="item-mid" style="padding: 0px;">
                  <%= f.text_area :text1, cols: '60', rows: '10', value: @content_item.text1, 
                    class: 'validate[required, maxSize[3000]]', style: 'width:522px;margin:5px;' %>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="item-tr">
          <div class="table-sys-a2">
            <div class="item-body">
              <div class="item-tr">
                <div class="item-mid">自動的にbrタグを挿入</div>
                <div class="input-mid">
                  <%= f.check_box :flg %>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </fieldset>
  <% when 3 -%>
  <fieldset>
    <h2><%= $content_item_category[@content_item.category - 1][0] %></h2>
    <div class="table-sys-a1">
      <div class="item-body">
        <div class="item-tr">
          <div class="item-mid">画像ファイル</div>
          <div class="input-mid">
            <input id="image" size= "30" type="file" name="image" class="validate[required, funcCall[fileType[jpg|jpeg|JPG]], funcCall[fileMaxSize[12]]]" accept=".jpg,.jpeg,.JPG,.JPEG">
          </div>
        </div>
      </div>
    </div>
  </fieldset>
  <% when 4 -%>
  <fieldset>
    <h2><%= $content_item_category[@content_item.category - 1][0] %></h2>
    <div class="table-sys-a1">
      <div class="item-body">
        <div class="item-tr">
          <div class="item-mid">表示文字</div>
          <div class="input-mid">
            <%= f.text_field :string1, {value: @content_item.string1, class: 'validate[required, maxSize[40]]'} %>
          </div>
        </div>
        <div class="item-tr">
          <div class="item-mid">リンク先ＵＲＬ</div>
          <div class="input-mid">
            <%= f.text_field :url, {value: @content_item.url, class: 'validate[required, maxSize[255], custom[url]]'} %><br>(例：http://oooo.oo.jp)
          </div>
        </div>
        <div class="item-tr">
          <div class="item-mid">新しくウィンドウを開く</div>
          <div class="input-mid">
            <%= f.check_box :flg %>
          </div>
        </div>
      </div>
    </div>
  </fieldset>
  <% when 5 -%>
  <fieldset>
    <h2><%= $content_item_category[@content_item.category - 1][0] %></h2>
    <div class="table-sys-a1">
      <div class="item-body">
        <div class="item-tr">
          <div class="item-mid">リンク用画像ファイル</div>
          <div class="input-mid">
            <input id="image" size= "30" type="file" name="image" class="validate[required, funcCall[fileType[jpg|jpeg|JPG]], funcCall[fileMaxSize[12]]]" accept=".jpg,.jpeg,.JPG,.JPEG">
          </div>
        </div>
        <div class="item-tr">
          <div class="item-mid">リンク先ＵＲＬ</div>
          <div class="input-mid">
            <%= f.text_field :url, {value: @content_item.url, class: 'validate[required, maxSize[255], custom[url]]'} %><br>(例：http://oooo.oo.jp)
          </div>
        </div>
        <div class="item-tr">
          <div class="item-mid">新しくウィンドウを開く</div>
          <div class="input-mid">
            <%= f.check_box :flg %>
          </div>
        </div>
      </div>
    </div>
  </fieldset>
  <% end -%>
  <br>
  <%= f.submit "　登録　" %>
<% end %>

<br>
<br>

<% if session[:target_for_back_id] -%>
<%= link_to "戻る", {action: session[:target_for_back], id: session[:target_for_back_id]} %><br />
<% else -%>
<%= link_to "戻る", {action: session[:target_for_back]} %><br />
<% end -%>
