<% # encoding: utf-8 %>

	<!--Widget start-->
	<%= f.error_messages %>
	
	<div id="sub-wiget">
		<div id="widget-picture" class="widget-box">
			<div class="widget-action clear">
				<a class="action"><i title="Upload pictures" class="icon-exclamation-sign icon-white tip"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-picture icons-white"></i>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>
					<div class="controls file-upload input-prepend">
					<label class="control-label add-on btn" for="input-upload">
						<%= t(:browse) %>
						<%= f.file_field :image, :id => "input-upload", :class => 'upload', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %>
					</label>
					<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('announcement.刪除已上傳檔案') %>
					<% end %>
					</div>
				</div>
			</div>
		</div>



		<div id="widget-date" class="widget-box widget-size-300">
			<div class="widget-action clear">
				<a href="#" class="action"><i title="Set the announcement to start and end dates" class="icon-exclamation-sign icon-white tip"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-calendar icons-white"></i> Date</h3>
				<div class="widget-content clear">
				<div class="control-group">
					<label class="control-label">Start</label>
					<div class="controls">
						<%= f.datetime_select :postdate, {:use_month_numbers => true, :order => [:day, :month, :year] }, {:class => 'span1'} %>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">End</label>
					<div class="controls">
						<%= f.datetime_select :deadline, {:use_month_numbers => true, :prompt => { :month => 'Month', :day => 'Day', :year => 'Year'}, :order => [:day, :month, :year] }, {:class => 'span1'} %>
					</div>
				</div>
			</div>
		</div>
		  
		<div id="widget-status" class="widget-box widget-size-300">
			<div class="widget-action clear">
				<a class="action"><i title="Setting the announcement state" class="icon-exclamation-sign icon-white tip"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-star-thin icons-white"></i>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>

		<div id="widget-tags" class="widget-box widget-size-300">
			<div class="widget-action clear">
				<a class="action"><i title="Setting" class="icon-cog icon-white tip"></i></a>
			</div>
			<h3 class="widget-title"><i class="icons-tag icons-white"></i>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[I18n.locale] %>
							<% end %>
						<% end %>
					</p>
				</div>
		</div> 
  	<% if params[:action] != 'new' %>
		<div id="widget-audit" class="widget-box">
			<div class="widget-action clear">
				<a class="action"><i title="A" class="icon-exclamation-sign icon-white tip"></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[I18n.locale], t.id ]}, {}, :class => "input-medium" %>
		
			<%= f.label :category,t('announcement.bulletin.category')%> 
			<%= f.select :bulletin_category_id, @bulletin_categorys.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-medium" %>
			
			<ul class="nav nav-tabs">
				<%# @site_valid_locales.each_with_index do |locale, i| %>
				<% @site_valid_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_valid_locales.each_with_index do |locale, i| %>
				
				<div class="<%= locale %> fade tab-pane <%= ( i == 0 ) ? "in active" : '' %>">

					<div class="title">
						<%= f.label :title ,t('announcement.bulletin.title')%>
						<%= f.fields_for :title, (@bulletin.new_record? ? @bulletin.build_title : @bulletin.title ) do |f| %>
							<%= I18nVariable.from_locale(locale) %>
							<%= f.text_field locale, :class=>'post-title' %>
						<% end %>
					</div>

					
					<div class="editor">
						<%= f.label :text ,t('announcement.bulletin.text')%>
						<%= f.fields_for :text, (@bulletin.new_record? ? @bulletin.build_text : @bulletin.text ) do |f| %>
							<%= I18nVariable.from_locale(locale) %>
							<%= f.text_area locale, :style=>"width:100%", :class => 'tinymce_textarea' %>
						<% end %>				
					</div>
				
				</div>
				
				<% end %>
				
			</div>
			
			<div class="main-wiget">
				<div id="widget-link" class="widget-box">
					<div class="widget-action clear">
						<a class="action"><i title="Add a reference link" class="icon-exclamation-sign icon-white tip"></i></a>
					</div>
					<h3 class="widget-title"><i class="icons-link icons-white"></i>Link</h3>
					<div class="widget-content">
					
					<div id='bulletin_links' class="bulletin_links_block">
					
					<table class="table table-condensed">
						<thead>
							<tr>
								<th>URL</th>
								<th>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">
						<a class="action"><i title="Added to the file" class="icon-exclamation-sign icon-white tip"></i></a>
					</div>
					<h3 class="widget-title"><i class="icons-paperclip icons-white"></i>File</h3>
					<div class="widget-content">
						
					<div id='bulletin_files' class="bulletin_files_block">
							
					<table class="table table-condensed">
						<thead>
							<tr>
								<th>File</th>
								<th>Name</th>
								<th><%= t('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>
									</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">
		<%= f.submit t('submit'), :class=>'btn btn-primary' %>
		<%= link_to t('cancel'), get_go_back, :class=>"btn" %> 
	  </div>
  
  </div>
  
  

<% content_for :page_specific_javascript do %>
	<%= 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 %>
