<% # encoding: utf-8 %>
<% content_for :page_specific_javascript do -%>
	<%= javascript_include_tag "inc/modal-preview" %>
<% end -%>
	<!--Widget start-->
	<%= f.error_messages %>
	
	<div id="sub-wiget">

		<div id="widget-picture" class="widget-box">
			<div class="widget-action clear tip" title="Upload pictures">
				<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-pictures"></i><%= t('announcement.picture') %></h3>
			<div class="widget-content clear">
				<div class="control-group">
           <!-- <img class="pull-left upload-picture" src="/assets/default-img.png" /> -->
					<div  class="upload-picture">
              <% if @bulletin.image %>
              	<%= image_tag @bulletin.image rescue ''%>
              <% else %>
              	<img class="pull-left upload-picture" src="/assets/default-img.png" />
              <% end %>
          </div>
					<span class="alert widgetInfo"><%= t("ad.widget_info_for_ad_image_size", :best_size=> "290px x 150px") %></span>
					<div class="controls file-upload input-prepend">
						<%= t(:browse) %>
						<%= f.file_field :image, :id => "input-upload", :class => '', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %>
					<!-- <span id='fu' class="file-name"></span>
					<br>
					<input name='fu' class="input-medium" type="text">
					<br> -->
					<% if @bulletin.image.file %>
					  <%= f.check_box :remove_image %>
					  <%= t('delete.file') %>
					<% end %>
					</div>
				</div>
			</div>
		</div>

		<div id="widget-date" class="widget-box widget-size-300">
			<div class="widget-action clear tip" title="Set the announcement to start and end dates">
				<a href="#" class="action"><i class="icon-exclamation-sign icon-white"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-calendar"></i><%= t(:date_) %></h3>
				<div class="widget-content clear">
				<div class="control-group">
					<%= f.datetime_picker :postdate, :picker_type => 'separated', :label => t(:start) %>
				</div>
				<div class="control-group">
					<%= f.datetime_picker :deadline, :picker_type => 'separated', :label => t(:end) %>
				</div>
			</div>
		</div>

	<% if show_form_status_field(@bulletin)%>
		<div id="widget-status" class="widget-box widget-size-300">
			<div class="widget-action clear tip" title="Setting the announcement state">
				<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-star"></i><%= t(:status) %></h3>
			<div class="widget-content clear">
				<div class="controls">
				<%= content_tag :label,:class => "checkbox inline" do -%>
					<%= f.check_box :is_top %>
					<%= t('top') %>
				<% end -%>
				<%= content_tag :label,:class => "checkbox inline" do -%>
					<%= f.check_box :is_hot %>
					<%= t('hot') %>
				<% end -%>
				<%= content_tag :label,:class => "checkbox inline" do -%>
					<%= f.check_box :is_hidden %>
					<%= t('hide') %>
				<% end -%>
				</div>
			</div>
		</div>
	<% end %>
	<% if @bulletin.is_rejected %>
		<div id="widget-rejected" class="widget-box widget-size-300">
			<div class="widget-action clear tip" title="Rejected Report">
				<a class="action"><i class="icon-cog icon-white"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-tag"></i><%= t('approval.stat') %></h3>
				<div class="widget-content clear form-horizontal">
					<%= @bulletin.not_checked_reason rescue t("rejected_reason_empty") %>
				</div>
		</div>
	<% end %>
		<div id="widget-tags" class="widget-box widget-size-300">
			<div class="widget-action clear tip" title="Setting">
				<a class="action"><i class="icon-cog icon-white"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-tag"></i><%= t(:tags) %></h3>
				<div class="widget-content clear form-horizontal">
					<p>
						<% @tags.each do |tag| %>
							<%= content_tag :label,:class => "checkbox inline" do -%>
								<%= check_box_tag 'bulletin[tag_ids][]', tag.id, @bulletin.tag_ids.include?(tag.id) %>
								<%= tag.name %>
                <%= hidden_field_tag 'bulletin[tag_ids][]', '' %>
							<% end %>
						<% end %>
					</p>
				</div>
		</div> 
  	<% if params[:action] != 'new' %>
		<div id="widget-audit" class="widget-box">
			<div class="widget-action clear tip" title="A">
				<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
			</div>
			
		</div>
		<% elsif current_user.admin? %>
			<%= f.hidden_field :is_checked,:value => true%>
		<% end %>
	</div>
  

<!--Wiget End-->
<!--Post Start-->

	<div id="post-body">
		<div id="post-body-content" class="clear">

			<%#= f.label :unit_list_for_anc%>
			<%#= f.select :unit_list_for_anc_id,@unit_list_for_anc.collect{|t| [ t.title, t.id ]}, {}, :class => "input-medium" %>
		
			<%= f.label :category,t(:category)%> 
			<%= f.select :category_id, @bulletin_categories.collect{|t| [ t.title, t.id ]}, {}, :class => "input-medium" %>
			
			<ul class="nav nav-tabs">
				<%# @site_valid_locales.each_with_index do |locale, i| %>
				<% @site_in_use_locales.each_with_index do |locale, i| %>
			    <li <%= ( i == 0 ) ? " class=active" : '' %>><a data-toggle="tab" href=".<%= locale %>"><%= I18nVariable.from_locale(locale) %></a></li>
				<% end %>
			</ul>
			
			<div class="tab-content">
			
				<%# @site_valid_locales.each_with_index do |locale, i| %>
				<% @site_in_use_locales.each_with_index do |locale, i| %>
				
				<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">

					<div class="title">
						<%= f.label :title ,t(:title)%>
						<%= f.fields_for :title_translations do |f| %>
							<%= I18nVariable.from_locale(locale) %>
							<%= f.text_field locale, :class=>'post-title', :value => (@bulletin.title_translations[locale] rescue nil) %>
						<% end %>
					</div>			

					<div class="editor">
						<%= f.label :subtitle, t(:subtitle) %>
						<%= f.fields_for :subtitle_translations do |f| %>
							<%= I18nVariable.from_locale(locale) %>
							<%= f.text_area locale, :rows => 5, :style=>"width:100%", :value => (@bulletin.subtitle_translations[locale] rescue nil) %>
						<% end %>
					</div>  
					
					<div class="editor">
						<%= f.label :text ,t(:text)%>
						<%= f.fields_for :text_translations do |f| %>
							<%= I18nVariable.from_locale(locale) %>
							<%= f.text_area locale, :style=>"width:100%", :class => 'tinymce_textarea', :value => (@bulletin.text_translations[locale] rescue nil) %>
						<% end %>				
					</div>
				
				</div>
				
				<% end %>
				
			</div>
			
			<div class="main-wiget">
				<div id="widget-link" class="widget-box">
					<div class="widget-action clear tip" title="Add a reference link">
						<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
					</div>
					<h3 class="widget-title"><i class="icons-link"></i><%= t(:link) %></h3>
					<div class="widget-content">
					
					<div id='bulletin_links' class="bulletin_links_block">
					
					<table class="table table-condensed">
						<thead>
							<tr>
								<th><%= t('announcement.url') %></th>
								<th><%= t('announcement.link_name') %></th>
								<th class="span1"></th>
							</tr>
						</thead>
						<tfoot>
							<tr>
								<td style="text-align:center" colspan="4">
									<div id='add_bulletin_link' class="info_input bulletin_links_block">
										<%= hidden_field_tag 'bulletin_link_field_count', @bulletin.bulletin_links.count %>
										<a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i><%= t(:add) %></span></a>
									</div>
								</td>
							</tr>
						</tfoot>
						<tbody>
						
							<% @bulletin.bulletin_links.each_with_index do |bulletin_link, i| %>
								<%#= fields_for "bulletin[bulletin_links][]", bulletin_link do |f| %>
								<%= f.fields_for :bulletin_links, bulletin_link do |f| %>
									<%= render :partial => 'form_bulletin_link', :object => bulletin_link, :locals => {:f => f, :i => i} %>
								<% end %>
							<% end %>	
							
						</tbody>
					</table>
					
								
					</div>
							
					</div>
				</div>
				<div id="widget-file" class="widget-box">
					<div class="widget-action clear tip" title="Added to the file">
						<a class="action"><i class="icon-exclamation-sign icon-white"></i></a>
					</div>
					<h3 class="widget-title"><i class="icons-paperclip"></i><%= t('announcement.file') %></h3>
					<div class="widget-content">
						
					<div id='bulletin_files' class="bulletin_files_block">
							
					<table class="table table-condensed">
						<thead>
							<tr>
								<th><%= t('announcement.selected_file') %></th>
								<th><%= t('announcement.file_name') %></th>
								<th><%= t('announcement.file_description') %></th>
								<th class="span1"></th>
							</tr>
						</thead>
						<tfoot>
							<tr>
								<td style="text-align:center" colspan="4">
									<div id='add_bulletin_file' class="info_input bulletin_files_block">
										<%= hidden_field_tag 'bulletin_file_field_count', @bulletin.bulletin_files.count %>
										<a class="add"><span class="btn btn-primary btn-small"><i class="icon-plus icon-white"></i><%= t(:add) %></span></a>
										<p><%= t("sys.limit_of_upload_file_size",:best_size => '3MB') %></p>
										<p><%= t("sys.preview_only_for_img") %></p>
									</div>
								</td>
							</tr>
						</tfoot>
						<tbody>
								<% @bulletin.bulletin_files.each_with_index do |bulletin_file, i| %>
									<%#= fields_for "bulletin[bulletin_files][]", bulletin_file do |f| %>
									<%= f.fields_for :bulletin_files, bulletin_file do |f| %>
										<%= render :partial => 'form_bulletin_file', :object => bulletin_file, :locals => {:f => f, :i => i} %>
									<% end %>
								<% end %>	
							
						</tbody>
					</table>
								
					</div>
					
					</div>
				</div>
			</div>		
	
		</div>
	<!--Post End-->
	</div>

	  <div class="form-actions">
	  	<%= button_tag t("preview"), :id=>"button_for_preview", :name=>"commit",:class=>'btn post_preview two_btn',:type=>:button,:url=>preview_panel_announcement_back_end_bulletins_path %>
		<%= f.submit t('submit'), :class=>'btn btn-primary two_btn' %>
		<%= link_to t('cancel'), get_go_back, :class=>"btn" %> 
	  </div>
  
  </div>
  
  

<% content_for :page_specific_javascript do %>
	<%= javascript_include_tag "bulletin_form" %>
	<%= javascript_include_tag "inc/jquery.imagesloaded.js" %>
	<script>
	$(document).ready(function() {

		$('#add_bulletin_link a.add').live('click', function(){
			var new_id = $(this).prev().attr('value');
			var old_id = new RegExp("new_bulletin_links", "g");
			$(this).prev().attr('value', parseInt(new_id) + 1);
			$(this).parents('table').append(("<%= escape_javascript(add_attribute 'form_bulletin_link', f, :bulletin_links) %>").replace(old_id, new_id));
		});
		$('#add_bulletin_file a.add').live('click', function(){
			var new_id = $(this).prev().attr('value');
			var old_id = new RegExp("new_bulletin_files", "g");
			$(this).prev().attr('value', parseInt(new_id) + 1);
			$(this).parents('table').append(("<%= escape_javascript(add_attribute 'form_bulletin_file', f, :bulletin_files) %>").replace(old_id, new_id));
		});
		$('.for_preview').popover({ html : true });
	});
	</script>
<% end %>
