<% # encoding: utf-8 %>
<% content_for :page_specific_css do %>
  <%= stylesheet_link_tag "lib/main-forms" %>
  <%= stylesheet_link_tag "lib/fileupload" %>
  <%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<% content_for :page_specific_javascript do %>
  <%= javascript_include_tag "lib/bootstrap-fileupload" %> 
  <%= javascript_include_tag "lib/file-type" %>
  <%= javascript_include_tag "lib/module-area" %>
<% end %>

  <%= f.error_messages %>

<!-- 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></li>
    <li class="active">
      <a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
    </li>
    <% if show_form_status_field(@writing_journal) %>
      <li>
        <a href="#status" data-toggle="tab"><%= t(:status) %></a>
      </li>
    <% end %>
    <li>
      <a href="#tag" data-toggle="tab"><%= t(:tags) %></a>
    </li>
  </ul>

  <!-- Module -->
  <div class="tab-content module-area">

    <!-- Basic Module -->
    <div class="tab-pane fade in active" id="basic">

      <% if !params[:user_id].blank? %>
      
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_plugins.author") %></label>
        <div class="controls">
          <%= User.from_id(params[:user_id]).name rescue ''%>
        </div>
      </div> 

      <% end %> 

      <!-- year -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.year") %></label>
        <div class="controls">
			<%= select_year((@writing_journal.year ? @writing_journal.year.to_i : DateTime.now.year), {:start_year => DateTime.now.year, :end_year => 1930}, {:name => 'writing_journal[year]', :class => "span1"} ) %>
        </div>
      </div> 

      <!-- language -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.language") %></label>
        <div class="controls">
			<%= f.select :language, WritingJournal::LANGUAGE_TYPES, :prompt => 'Select', :class => "span3" %>
        </div>
      </div> 

      <!-- level_type -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.level_type") %></label>
        <div class="controls">
			<% @level_types.each do |level_type| %>
				<%= content_tag :label,:class => "checkbox inline" do -%>
					<%= check_box_tag 'writing_journal[journal_level_type_ids][]', level_type.id, @writing_journal.journal_level_type_ids.include?(level_type.id)%>
					<%= level_type.title %>
	   			    <%= hidden_field_tag 'writing_journal[journal_level_type_ids][]', '' %>
				<% end %>
			<% end %>
        </div>
      </div> 

      <!-- paper_type -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.paper_type") %></label>
        <div class="controls">
			<%= f.select :journal_paper_type_id, @paper_types.collect {|t| [ t.title, t.id ]}, :class => "span3" %>
        </div>
      </div>

      <!-- author_type -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.author_type") %></label>
        <div class="controls">
			<% @author_types.each do |author_type| %>
				<%= content_tag :label,:class => "checkbox inline" do -%>
					<%= check_box_tag 'writing_journal[journal_author_type_ids][]', author_type.id, @writing_journal.journal_author_type_ids.include?(author_type.id)%>
					<%= author_type.title %>
	   			    <%= hidden_field_tag 'writing_journal[journal_author_type_ids][]', '' %>
				<% end %>
			<% end %>
        </div>
      </div> 

      <!-- vol_no -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.vol_no") %></label>
        <div class="controls">
			<%= f.text_field :vol_no %>
        </div>
      </div> 

      <!-- issue_no -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.issue_no") %></label>
        <div class="controls">
			<%= f.text_field :issue_no %>
        </div>
      </div> 

      <!-- form_to -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.form_to") %></label>
        <div class="controls">
			<%= f.text_field :form_to_start, :class=>'span1' %> ~ <%= f.text_field :form_to_end, :class=>'span1' %>
        </div>
      </div> 

      <!-- total_pages -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.total_pages") %></label>
        <div class="controls">
			<%= f.text_field :total_pages %>
        </div>
      </div> 

      <!-- isbn -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.isbn") %></label>
        <div class="controls">
			<%= f.text_field :isbn %>
        </div>
      </div> 

      <!-- keywords -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.keywords") %></label>
        <div class="controls">
			<%= f.text_field :keywords %>
        </div>
      </div> 

      <!-- publication_date -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.publication_date") %></label>
        <div class="controls">
			<%= f.date_select :publication_date, {:use_month_numbers => true, :start_year => Time.now.year, :end_year => 1930, :order => [:year, :month, :day] }, {:class => 'span1'} %>
        </div>
      </div> 

      <!-- url -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.url") %></label>
        <div class="controls">
			<%= f.text_field :url , :class => "span6" %>
        </div>
      </div> 

      <!-- abstract -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.abstract") %></label>
        <div class="controls">
          <%= f.text_area :abstract, rows: 2, class: "input-block-level" %>
        </div>
      </div> 

      <!-- note -->
      <div class="control-group">
        <label class="control-label muted"><%= t("personal_journal.note") %></label>
        <div class="controls">
          <%= f.text_area :note, rows: 2, class: "input-block-level" %>
        </div>
      </div> 

    </div>

    <!-- Status Module -->
    <% if show_form_status_field(@writing_journal) %>
      <div class="tab-pane fade" id="status">

        <!-- Status -->
        <div class="control-group">
          <label class="control-label muted"><%= t(:status) %></label>
          <div class="controls" data-toggle="buttons-checkbox">
            <label class="checkbox inline btn <%= 'active' if @writing_journal.is_hidden? %>">
              <%= f.check_box :is_hidden %> <%= t(:hide) %>
            </label>
          </div>
        </div>

      </div>
    <% end %>

    <!-- Tag Module -->
    <div class="tab-pane fade" id="tag">

      <!-- Tag -->
      <div class="control-group">
        <label class="control-label muted"><%= t(:tags) %></label>
        <div class="controls" data-toggle="buttons-checkbox">
          <% @tags.each do |tag| %>
            <label class="checkbox inline btn <%= 'active' if @writing_journal.tag_ids.include?(tag.id) %>">
              <%= check_box_tag 'writing_journal[tag_ids][]', tag.id, @writing_journal.tag_ids.include?(tag.id) %> <%= tag.name %>
              <%= hidden_field_tag 'writing_journal[tag_ids][]', '' %>
            </label>
          <% end %>
        </div>
      </div>

    </div>

  </div>

  <!-- Language Tabs -->
  <div class="nav-name"><strong><%= t(:language) %></strong></div>
  <ul class="nav nav-pills language-nav">
    <% @site_in_use_locales.each_with_index do |locale, i| %>
      <li class="<%= 'active' if i == 0 %>">
        <a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a>
      </li>
    <% end %>
  </ul>

  <!-- Language -->
  <div class="tab-content language-area">

    <% @site_in_use_locales.each_with_index do |locale, i| %>
    
      <div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">

        <!-- paper_title-->
        <div class="control-group input-title">
          <label class="control-label muted"><%= t("personal_journal.paper_title") %></label>
          <div class="controls">          	
            <%= f.fields_for :paper_title_translations do |f| %>
              <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_journal.paper_title"), value: (@writing_journal.paper_title_translations[locale] rescue nil) %>
            <% end %>
          </div>
        </div>

        <!-- journal_title-->
        <div class="control-group input-title">
          <label class="control-label muted"><%= t("personal_journal.journal_title") %></label>
          <div class="controls">          	
            <%= f.fields_for :journal_title_translations do |f| %>
              <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_journal.journal_title"), value: (@writing_journal.journal_title_translations[locale] rescue nil) %>
            <% end %>
          </div>
        </div>

        <!-- authors-->
        <div class="control-group input-title">
          <label class="control-label muted"><%= t("personal_journal.authors") %></label>
          <div class="controls">          	
            <%= f.fields_for :authors_translations do |f| %>
              <%= f.text_field locale, class: "input-block-level", placeholder: t("personal_journal.authors"), value: (@writing_journal.authors_translations[locale] rescue nil) %>
            <% end %>
          </div>
        </div>

      </div>

    <% end %>

    <!-- File -->
    <div class="control-group">
      <label class="control-label muted"><%= t(:file_) %></label>
      <div class="controls">

        <!-- Exist -->
        <% if @writing_journal && !@writing_journal.writing_journal_files.blank? %>
          <div class="exist">
            <% @writing_journal.writing_journal_files.each_with_index do |writing_journal_file, i| %>
              <%= f.fields_for :writing_journal_files, writing_journal_file do |f| %>
                <%= render :partial => 'form_file', :object => writing_journal_file, :locals => {:f => f, :i => i} %>
              <% end %>
            <% end %> 
            <hr>
          </div>
        <% end %>

        <!-- Add -->
        <div class="add-target">
        </div>
        <p class="add-btn">
          <%= hidden_field_tag 'plugin_file_field_count', @writing_journal.writing_journal_files.count %>
          <a id="add_file" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
        </p>

      </div>
    </div>




   </div>



</div>

<!-- Form Actions -->
<div class="form-actions">
  <%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %>
  <%= f.submit t('submit'), class: 'btn btn-primary' %>
  <%= link_to t('cancel'), get_go_back, :class=>"btn" %>  
</div>

<% content_for :page_specific_javascript do %>
  <script>
    $(document).ready(function() {
    	$('.main-forms .add-on').tooltip();
      $(document).on('click', '#add_file', function(){
        var new_id = $(this).prev().attr('value');
        var old_id = new RegExp("new_writing_journal_files", "g");
        var on = $('.language-nav li.active').index();
        var le = $(this).parent('.add-btn').prev('.add-target').children('.start-line').length;
        $(this).prev().attr('value', parseInt(new_id) + 1);
        $(this).parent().siblings('.add-target').append(("<%= escape_javascript(add_attribute 'form_file', f, :writing_journal_files) %>").replace(old_id, new_id));
        $(this).parent('.add-btn').prev('.add-target').children('.start-line').eq(le).children('.input-append').find('.tab-content').each(function() {
          $(this).children('.tab-pane').eq(on).addClass('in active').siblings().removeClass('in active');
        });
        formTip();
      }); 
      $(document).on('click', '.delete_file', function(){
        $(this).parents('.input-prepend').remove();
      });
      $(document).on('click', '.remove_existing_record', function(){
        if(confirm("<%= I18n.t(:sure?)%>")){
          $(this).children('.should_destroy').attr('value', 1);
          $(this).parents('.start-line').hide();
        }
      });
    });
  </script>
<% end %>