complete preview for both new and announcement
This commit is contained in:
		
							parent
							
								
									8bd5481b3f
								
							
						
					
					
						commit
						6044857fea
					
				|  | @ -3,25 +3,53 @@ | |||
| // <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%>
 | ||||
| 
 | ||||
| $(document).ready(function() { | ||||
| 	$("a.post_preview").click(function(e){ | ||||
| 		$("#main-wrap").after("<span id='show_preview'></span>"); | ||||
| 		e.preventDefault(); | ||||
| 		var form = $(this).parents("form").first() | ||||
|         	//var cont = form["content"].value;
 | ||||
|         	$.ajax({ | ||||
|         		type: 'POST', | ||||
|         		url: $(this).attr("href")+'?preview=true', | ||||
|         		data: form.serialize(), | ||||
|         		dataType: "script", | ||||
|         		success: function (msg) { | ||||
| 					$("#"+start_modal_with_id).modal('show'); }, | ||||
| 			error: function(){ | ||||
| 				alert("ERROR"); | ||||
| 				} | ||||
|         	}); | ||||
|         	 | ||||
| 		return false | ||||
| 	}); | ||||
| 	// $(".post_preview").click(function(e){
 | ||||
| 	// 	$("#main-wrap").after("<span id='show_preview'></span>");
 | ||||
| 	// 	e.preventDefault();
 | ||||
| 	// 	var form = $(this).parents("form").first()
 | ||||
|  //        	//var cont = form["content"].value;
 | ||||
|  //   //      	$.ajax({
 | ||||
|  //   //      		type: 'POST',
 | ||||
|  //   //      		url: $(this).attr("href")+'?preview=true',
 | ||||
|  //   //      		data: form.serialize(),
 | ||||
|  //   //      		dataType: "script",
 | ||||
|  //   //      		success: function (msg) {
 | ||||
| 	// 		// 		$("#"+start_modal_with_id).modal('show'); },
 | ||||
| 	// 		// error: function(){
 | ||||
| 	// 		// 	alert("ERROR");
 | ||||
| 	// 		// 	}
 | ||||
|  //   //      	});
 | ||||
| 	// 		url = "/panel/news/back_end/news_bulletins/preview?preview=true"
 | ||||
| 	// 		// alert(url)
 | ||||
| 	// 		form.attr("action",url);
 | ||||
|  //        	form.submit();
 | ||||
| 	// 	//return false;
 | ||||
| 	// });
 | ||||
| 	var clicked_what = null; | ||||
| 	$("button.post_preview").click(function(){ | ||||
| 		clicked_what = $(this); | ||||
| 		$("form.nccu_ajax_form").ajaxSubmit({ | ||||
| 			beforeSubmit: function(a,f,o){ | ||||
| 				$("#main-wrap").after("<span id='show_preview'></span>"); | ||||
| 				o.dataType = 'script'; | ||||
| 				o.url = clicked_what.attr("url"); | ||||
| 			} | ||||
| 		}); | ||||
| 	}) | ||||
| 	// $("form.nccu_ajax_form").ajaxForm({
 | ||||
|  //        beforeSubmit: function(a,f,o) {
 | ||||
|  //        	// if(clicked_what.hasClass("post_preview")){
 | ||||
|  //         //          $("#main-wrap").after("<span id='show_preview'></span>");
 | ||||
|  //         //          o.dataType = 'script';
 | ||||
|  //         //          o.url = clicked_what.attr("url");
 | ||||
|  //         //    }
 | ||||
|  //        },
 | ||||
|  //        success: function(data) {
 | ||||
|  //             // if(!clicked_what.hasClass("post_preview")){
 | ||||
|  //             //    window.location = data.redirect_url;
 | ||||
|  //             // }
 | ||||
|  //          }
 | ||||
|  //    })
 | ||||
| 
 | ||||
| 	$("a.preview_trigger").click(function(){ | ||||
| 		$("#main-wrap").after("<span id='show_preview'></span>"); | ||||
|  |  | |||
|  | @ -0,0 +1,23 @@ | |||
| module Admin::WebComponentHelper | ||||
|   include ActionView::Helpers::TagHelper | ||||
| 
 | ||||
|   def alert_block_tag(title="",context="",*args) | ||||
|     content_tag(:div,:class=>"alert alert-block alert-error fade in") do | ||||
|       a = ActiveSupport::SafeBuffer.new | ||||
|       a << button_tag( 'x',:class=>"close",:data=>{:dismiss=>"alert"}) if (args.first[:close] rescue false) | ||||
|       a << content_tag(:h4,:class=>"alert-heading") do | ||||
|         title | ||||
|       end | ||||
|       a << content_tag(:p) do | ||||
|         context | ||||
|       end | ||||
|       # TODO : 可以提供更多功能 | ||||
|       # a << content_tag(:p) do | ||||
|       #   b = link_to("Take this action","",:class=>"btn btn-danger")  | ||||
|       #   b << link_to("Or do this","",:class=>"btn")  | ||||
|       #   b | ||||
|       # end | ||||
|     end | ||||
| 
 | ||||
|   end | ||||
|   end | ||||
|  | @ -2,12 +2,81 @@ class Preview | |||
|   include Mongoid::Document | ||||
|   include Mongoid::Timestamps | ||||
| 
 | ||||
|   field :object, :type => Hash | ||||
|   # field :object_f, :type => Hash | ||||
|   field :object, :type=> Hash | ||||
|   field :preview_at_link | ||||
|   field :expired_at , :type => DateTime | ||||
|   field :link_args, :type => Array | ||||
|   field :object_class_type | ||||
|    | ||||
|   has_many :preview_files, :autosave => true, :dependent => :destroy | ||||
| 
 | ||||
|   # def object=(params) | ||||
|   #   save_upload_temp_link(params,"news_bulletin_files_attributes") #unless params[] | ||||
|   #   self.object_f = params | ||||
|   # end | ||||
| 
 | ||||
|   # def object | ||||
|   #   return object_f | ||||
|   # end | ||||
| 
 | ||||
|   # def save_upload_temp_link(params,field_name = "bulletin_files_attributes") | ||||
|   #   image = preview_files.build(:file=>params[:image]) | ||||
|   #   params[:image] = image.id | ||||
| 
 | ||||
|   #   params[field_name].each_with_index do |item,index| | ||||
|   #     bfa = preview_files.build(:file=>params[field_name][index.to_s][:file]) | ||||
|   #     params[field_name][index.to_s] = bfa.id | ||||
|   #   end unless  params[field_name].nil? | ||||
|   # end | ||||
| 
 | ||||
|   # def dig_in_hash(hash,paths_ary) | ||||
|   #    hash.each_pair do |key,in_hash| | ||||
|   #       if in_hash.kind_of? Array  | ||||
|   #         dig_in_array(hash,paths_ary) | ||||
|   #       elsif in_hash.kind_of? Hash | ||||
|   #         dig_in_hash(hash,paths_ary) | ||||
|   #       else | ||||
|   #         puts("\n End Node: \t #{paths_ary.join } #{in_hash.class} : #{key}##{in_hash}") | ||||
|   #       end | ||||
|   #    end | ||||
|   # end | ||||
| 
 | ||||
|   # def dig_in_array(array,paths_ary) | ||||
|   #   array.each do |item| | ||||
|   #       if item.kind_of? Array  | ||||
|   #         dig_in_array(hash,paths_ary) | ||||
|   #       elsif item.kind_of? Hash | ||||
|   #         dig_in_hash(hash,paths_ary) | ||||
|   #       else | ||||
|   #         puts("\n End Node: \t #{paths_ary.join } #{item.class} : {item}") | ||||
|   #       end | ||||
|   #    end | ||||
|   # end | ||||
| 
 | ||||
| 
 | ||||
|   # def dig_in_hash_old(hash,paths_ary) | ||||
|   #   hash.each_pair do |k,in_hash| | ||||
|   #     if (!in_hash.kind_of? Array and !in_hash.kind_of? Hash) | ||||
|   #       #p "UploadedFile : #{in_hash.is_a? ActionDispatch::Http::UploadedFile}" | ||||
|   #       #in_hash = "no file" if in_hash.is_a? ActionDispatch::Http::UploadedFile | ||||
|   #       #in_hash.select{|key,hash| hash.is_a? ActionDispatch::Http::UploadedFile} | ||||
|   #       puts("\n End Node:# \n") | ||||
|   #       p "#{paths_ary.join } #{in_hash.class} : #{in_hash}" | ||||
|   #       #p "UploadedFile(#{in_hash}) : #{in_hash.is_a? ActionDispatch::Http::UploadedFile}" | ||||
|   #     else | ||||
|   #       if (!in_hash.first.kind_of? Array and !in_hash.first.kind_of? Hash) | ||||
|   #         paths_ary << "[#{in_hash.first}]"  | ||||
|   #       end | ||||
|   #       puts("\n Go Down [#{in_hash.first}]\n") | ||||
|   #       dig_in_hash(in_hash,paths_ary) | ||||
|   #       puts("\n Go Out \n") | ||||
|   #     end | ||||
|   #       puts "This is last" | ||||
|   #       paths_ary.pop   | ||||
|   #   end | ||||
|   # end | ||||
| 
 | ||||
|   def get_arg_hash | ||||
|     object.slice(*link_args).inject({}){|la,(k,v)| la[k.to_sym] = v; la} | ||||
|   end | ||||
|  | @ -19,7 +88,15 @@ class Preview | |||
|   end | ||||
| 
 | ||||
|   def get_virtual_object | ||||
|     eval(self.object_class_type).new object | ||||
|     virtual_object = eval(self.object_class_type).new object | ||||
|     preview_files.each do |file| | ||||
|       if file.file_in_array | ||||
|           eval("virtual_object.#{file.field_name_for_rebuild}.build  :file=>file.file")  | ||||
|         else | ||||
|           eval("virtual_object.#{file.field_name_for_rebuild} = file.file")      | ||||
|       end | ||||
|     end | ||||
|     virtual_object | ||||
|   end | ||||
| 
 | ||||
| end | ||||
|  |  | |||
|  | @ -0,0 +1,19 @@ | |||
| class PreviewFile | ||||
| 
 | ||||
|   include Mongoid::Document | ||||
|   include Mongoid::Timestamps | ||||
| 
 | ||||
|   mount_uploader :file, AssetUploader | ||||
|    | ||||
|   field :title, localize: true | ||||
|   field :description, localize: true | ||||
|   field :field_name_for_rebuild | ||||
|   field :file_in_array , :type => Boolean,default: false | ||||
| 
 | ||||
|   # field :to_save, :type => Boolean | ||||
|   field :should_destroy, :type => Boolean | ||||
|    | ||||
|   belongs_to :preview | ||||
|   # embedded_in :news_bulletin | ||||
| 
 | ||||
| end | ||||
|  | @ -4,7 +4,7 @@ | |||
|     <h3><%= t("modal.preview") %></h3> | ||||
|   </div> | ||||
|   <div class="modal-body"> | ||||
|     <p class="news_bulletin_slideshow"> | ||||
|     <p class=""> | ||||
|       <iframe src=<%= @preview_obj.get_preview_link %> style="width:1024px;height:300px" > | ||||
| 
 | ||||
|         </iframe> | ||||
|  | @ -0,0 +1 @@ | |||
| window.location = "<%= @info[:redirect_url]%>"; | ||||
|  | @ -0,0 +1,12 @@ | |||
| <% if !request.xhr? %> | ||||
| <textarea> | ||||
| <% end %> | ||||
| $('#show_preview').html('<%=escape_javascript(render :partial=>"/shared/preview/modal_preview") %>'); | ||||
| var start_modal_with_id = "<%= @preview_obj.id %>";  | ||||
| $("#"+start_modal_with_id).css("width","1050px"); | ||||
| $("#"+start_modal_with_id).css("height","768px"); | ||||
| $("#"+start_modal_with_id).css("margin","-270px 0 0 -550px"); | ||||
| $("#"+start_modal_with_id).modal(); | ||||
| <% if !request.xhr? %> | ||||
| </textarea> | ||||
| <% end %> | ||||
|  | @ -1,5 +1,6 @@ | |||
| $('#show_preview').html('<%=escape_javascript(render :partial=>"modal_preview") %>'); | ||||
| $('#show_preview').html('<%=escape_javascript(render :partial=>"/shared/preview/modal_preview") %>'); | ||||
| var start_modal_with_id = "<%= @preview_obj.id %>";  | ||||
| $("#"+start_modal_with_id).css("width","1050px"); | ||||
| $("#"+start_modal_with_id).css("height","768px"); | ||||
| $("#"+start_modal_with_id).css("margin","-270px 0 0 -550px"); | ||||
| $("#"+start_modal_with_id).css("margin","-270px 0 0 -550px"); | ||||
| $("#"+start_modal_with_id).modal(); | ||||
|  | @ -14,6 +14,7 @@ en: | |||
|   cant_empty_star: Cannot be empty (*) | ||||
|   create_fail: Creation failed | ||||
|   create: Create | ||||
|   continued: continued | ||||
|   delete: Delete | ||||
|   desktop: Desktop | ||||
|   disable: Disable | ||||
|  | @ -43,6 +44,7 @@ en: | |||
|   search_nccu: Search NCCU | ||||
|   show: Show | ||||
|   submit: Submit | ||||
|   preview: Preview | ||||
|   sure?: Are you sure? | ||||
|   update: Update | ||||
|   update_failed: Update failed | ||||
|  |  | |||
|  | @ -1,5 +1,22 @@ | |||
| zh_tw: | ||||
|    | ||||
|   mongoid: | ||||
|     models: | ||||
|       news_bulletin: 新聞 | ||||
|       bulletin: 公告 | ||||
|       ad_banner: 廣告輪播 | ||||
|       web_link: 連結管理 | ||||
|     attributes: | ||||
|       news_bulletin: | ||||
|         title: 新聞標題 | ||||
|       bulletin: | ||||
|         title: 公告標題 | ||||
|       ad_banner: | ||||
|         title: 標題 | ||||
|       web_link: | ||||
|         title: 名稱 | ||||
|         url: 路徑 | ||||
| 
 | ||||
| 
 | ||||
|   _locale: 中文 | ||||
|    | ||||
|   me: 我 | ||||
|  | @ -9,6 +26,7 @@ zh_tw: | |||
|   browse: 選擇檔案 | ||||
|   cancel: 取消 | ||||
|   cant_empty_star: 不能為空 (*) | ||||
|   continued: 詳讀全文 | ||||
|   create: 新增 | ||||
|   create_fail: 創建失敗 | ||||
|   delete: 刪除 | ||||
|  | @ -40,6 +58,7 @@ zh_tw: | |||
|   search_nccu: 搜尋政大 | ||||
|   show: 顯示 | ||||
|   submit: 送出 | ||||
|   preview: 預覽 | ||||
|   sure?: 您肯定嗎? | ||||
|   update: 更新 | ||||
|   update_failed: 更新失敗 | ||||
|  | @ -489,6 +508,7 @@ zh_tw: | |||
|         body: "以下欄位發生問題:" | ||||
| 
 | ||||
|   errors: | ||||
|     at_least_one: 至少要有一個 | ||||
|     format: "%{attribute} %{message}" | ||||
|     messages: | ||||
|       inclusion: "沒有包含在列表中" | ||||
|  |  | |||
|  | @ -1,14 +1,14 @@ | |||
| module  OrbitCoreLib | ||||
|   module Preview | ||||
|     def self.included(base) | ||||
|       base.instance_eval("field :is_preview,type: Boolean,:default => false") | ||||
|       base.instance_eval("scope :not_preview,where(:is_preview=>false)") | ||||
|       base.define_singleton_method :new_preview do |*args| | ||||
|         temp_obj = self.new(args.first) | ||||
|         temp_obj.is_preview = true | ||||
|         temp_obj.save(:validate => false) rescue | ||||
|         temp_obj | ||||
|       end | ||||
| 
 | ||||
|       # base.instance_eval("field :is_preview,type: Boolean,:default => false") | ||||
|       # base.instance_eval("scope :not_preview,where(:is_preview=>false)") | ||||
|       base.class_eval (" | ||||
|         def to_preview | ||||
|           raise 'Developer,please override to_preview method'   | ||||
|         end | ||||
|       ") | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,10 +13,11 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController | |||
|   before_filter :for_app_sub_manager,:except => [:index,:show,:get_sorted_and_filtered_bulletins] | ||||
| 
 | ||||
|   def preview | ||||
|     debugger | ||||
|     a=1 | ||||
| 
 | ||||
|     @bulletin = Bulletin.new_preview(params[:bulletin]) | ||||
|     #@preview_obj = Preview.create(:object=>params[:news_bulletin],:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_news_front_end_news_bulletin_path",:object_class_type=>"NewsBulletin") | ||||
|     bulletin = Bulletin.new params | ||||
|     @preview_obj = bulletin.to_preview | ||||
|     @preview_obj.save | ||||
|     render '/shared/preview/preview.js.erb' | ||||
|   end | ||||
| 
 | ||||
|   def index | ||||
|  | @ -75,8 +76,13 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController | |||
|   # GET /bulletins/new | ||||
|   # GET /bulletins/new.xml | ||||
|   def new | ||||
|     @bulletin = Bulletin.new(:postdate => DateTime.now) | ||||
| 	 | ||||
|     if(session[:in_validate_object].blank?) | ||||
|       @bulletin = Bulletin.new(:postdate => DateTime.now) | ||||
|     else | ||||
|       @bulletin = session[:in_validate_object] | ||||
|       session[:in_validate_object] = {} | ||||
|     end | ||||
|      | ||||
|     @link_url = panel_announcement_back_end_bulletins_path | ||||
|     get_tags | ||||
|     respond_to do |format| | ||||
|  | @ -139,10 +145,20 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController | |||
|                    | ||||
| 			format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.create_bulletin_success')) } | ||||
| 			format.xml  { render :xml => @bulletin, :status => :created, :location => @bulletin } | ||||
| 			format.js | ||||
| 			# format.js | ||||
|                   format.js {  | ||||
|                     @info = {"success"=>"true","redirect_url"=>panel_announcement_back_end_bulletins_url} | ||||
|                     flash[:notice] = t('bulletin.create_bulletin_success') | ||||
|                     render "/shared/preview/after_create.js.erb" | ||||
|                   } | ||||
| 		  else | ||||
| 			format.html { render :action => "new" } | ||||
| 			format.xml  { render :xml => @bulletin.errors, :status => :unprocessable_entity } | ||||
|                   format.js {  | ||||
|                     @info = {"success"=>"false","redirect_url"=>new_panel_announcement_back_end_bulletin_url(:bulletin => @bulletin)} | ||||
|                     session[:in_validate_object] = @bulletin | ||||
|                     render "/shared/preview/after_create.js.erb" | ||||
|                   } | ||||
| 		  end | ||||
| 		end | ||||
| 		 | ||||
|  | @ -344,7 +360,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController | |||
|    | ||||
|   def get_tags | ||||
|   	module_app = ModuleApp.first(:conditions => {:key => 'announcement'}) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) rescue [] | ||||
|   end | ||||
|    | ||||
| end | ||||
|  |  | |||
|  | @ -69,7 +69,8 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController | |||
|   end | ||||
|    | ||||
|   def preview_content | ||||
|     @bulletin = Bulletin.find params[:id] | ||||
|     @bulletin = Bulletin.find params[:id] rescue nil | ||||
|     @bulletin = Preview.find(params[:id]).get_virtual_object if @bulletin.nil? | ||||
|     get_categorys | ||||
|   end | ||||
|    | ||||
|  |  | |||
|  | @ -197,6 +197,18 @@ class Bulletin | |||
|     tags.order_by(I18n.locale, :asc) | ||||
|   end | ||||
|    | ||||
| 
 | ||||
|   def to_preview | ||||
|     preview_object = Preview.new(:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_announcement_front_end_bulletin_path",:object_class_type=>"Bulletin") | ||||
| 
 | ||||
|     self.bulletin["bulletin_files_attributes"].each_with_index do |atr,idx|  | ||||
|       preview_object.preview_files.build(:file=>self.bulletin["bulletin_files_attributes"][idx.to_s],:field_name_for_rebuild=>'bulletin_files',:file_in_array=>true) | ||||
|     end unless self.bulletin["bulletin_files_attributes"].nil? | ||||
|     preview_object.object = self.bulletin.except("bulletin_files_attributes") | ||||
|     preview_object | ||||
|   end | ||||
| 
 | ||||
| 
 | ||||
|   protected | ||||
|    | ||||
|   def check_deadline | ||||
|  | @ -223,4 +235,5 @@ class Bulletin | |||
|     self.tag_ids.delete('') | ||||
|   end | ||||
| 
 | ||||
| 
 | ||||
| end | ||||
|  |  | |||
|  | @ -1,5 +1,7 @@ | |||
| <% # encoding: utf-8 %> | ||||
| 
 | ||||
| <% content_for :page_specific_javascript do -%> | ||||
| 	<%= javascript_include_tag "inc/modal-preview" %> | ||||
| <% end -%> | ||||
| 	<!--Widget start--> | ||||
| 	<%= f.error_messages %> | ||||
| 	 | ||||
|  | @ -238,8 +240,8 @@ | |||
| 	</div> | ||||
| 
 | ||||
| 	  <div class="form-actions"> | ||||
| 		<%= link_to t('preview'),panel_announcement_back_end_bulletin_preview_path, :class=>"btn" %>  | ||||
| 		<%= f.submit t('submit'), :class=>'btn btn-primary' %> | ||||
| 	  	<%= button_tag t("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> | ||||
|    | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| <div id="poststuff"> | ||||
| <%= form_for @bulletin, :url => panel_announcement_back_end_bulletins_path do |f| %> | ||||
| <%= form_for @bulletin, :url => panel_announcement_back_end_bulletins_path,:html=>{ :class=>"nccu_ajax_form"} do |f| %> | ||||
| 	<%= render :partial => 'form', :locals => {:f => f} %> | ||||
| <% end %> | ||||
| </div> | ||||
|  |  | |||
|  | @ -11,7 +11,11 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController | |||
|   end | ||||
| 
 | ||||
|   def preview | ||||
|     @preview_obj = Preview.create(:object=>params[:news_bulletin],:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_news_front_end_news_bulletin_path",:object_class_type=>"NewsBulletin") | ||||
|     #@preview_obj = Preview.create(:object=>params[:news_bulletin],:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_news_front_end_news_bulletin_path",:object_class_type=>"NewsBulletin") | ||||
|     news_bulletin = NewsBulletin.new params | ||||
|     @preview_obj = news_bulletin.to_preview | ||||
|     @preview_obj.save | ||||
|     render '/shared/preview/preview.html.erb', :layout=>false | ||||
|   end | ||||
| 
 | ||||
|   def index | ||||
|  | @ -88,9 +92,12 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController | |||
|   # GET /news_bulletins/new | ||||
|   # GET /news_bulletins/new.xml | ||||
|   def new | ||||
|      | ||||
|     @news_bulletin = NewsBulletin.new | ||||
| 	 | ||||
|     if(session[:in_validate_object].blank?) | ||||
|       @news_bulletin = NewsBulletin.new | ||||
|     else | ||||
|       @news_bulletin = session[:in_validate_object] | ||||
|       session[:in_validate_object] = {} | ||||
|     end | ||||
|     @link_url = panel_news_back_end_news_bulletins_path | ||||
|      | ||||
| 	# @news_bulletin.news_bulletin_files.build | ||||
|  | @ -120,7 +127,6 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController | |||
|   # POST /news_bulletins | ||||
|   # POST /news_bulletins.xml | ||||
|   def create | ||||
|     binding.pry | ||||
|     get_tags | ||||
| 
 | ||||
| 	if params[:news_bulletin_link] | ||||
|  | @ -161,7 +167,8 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController | |||
|                   expire_page(:controller=>'panel/news/widget/news_bulletins' , :action=>'home_banner') | ||||
| 			format.html { redirect_to(panel_news_back_end_news_bulletins_url, :notice => t('news_bulletin.create_news_bulletin_success')) } | ||||
| 			format.xml  { render :xml => @news_bulletin, :status => :created, :location => @news_bulletin } | ||||
| 			format.js | ||||
|                   format.js  | ||||
|                    #format.json {render :json => {"success"=>"true","redirect_url"=>panel_news_back_end_news_bulletins_url,"notice" => t('news_bulletin.create_news_bulletin_success')}} | ||||
| 		  else | ||||
| 			format.html { render :action => "new" } | ||||
| 			format.xml  { render :xml => @news_bulletin.errors, :status => :unprocessable_entity } | ||||
|  | @ -379,7 +386,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController | |||
|    | ||||
|   def get_tags | ||||
|   	module_app = ModuleApp.first(:conditions => {:key => 'news'}) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) rescue [] | ||||
|   end | ||||
| 
 | ||||
| end | ||||
|  |  | |||
|  | @ -237,6 +237,18 @@ class NewsBulletin | |||
|   def sorted_tags | ||||
|     tags.order_by(I18n.locale, :asc) | ||||
|   end | ||||
| 
 | ||||
|   def to_preview | ||||
|     preview_object = Preview.new(:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_news_front_end_news_bulletin_path",:object_class_type=>"NewsBulletin") | ||||
|     preview_object.preview_files.build(:file=>self.news_bulletin["image"],:field_name_for_rebuild=>'image') | ||||
| 
 | ||||
| 
 | ||||
|     self.news_bulletin["news_bulletin_files_attributes"].each_with_index do |atr,idx|  | ||||
|       preview_object.preview_files.build(:file=>self.news_bulletin["news_bulletin_files_attributes"][idx.to_s],:field_name_for_rebuild=>'news_bulletin_files',:file_in_array=>true) | ||||
|     end unless self.news_bulletin["news_bulletin_files_attributes"].nil? | ||||
|     preview_object.object = self.news_bulletin.except("news_bulletin_files_attributes","image") | ||||
|     preview_object | ||||
|   end | ||||
|    | ||||
|   protected | ||||
|    | ||||
|  | @ -260,4 +272,6 @@ class NewsBulletin | |||
|     self.tag_ids.delete('') | ||||
|   end | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| end | ||||
|  |  | |||
|  | @ -4,7 +4,6 @@ | |||
| <% end -%> | ||||
| 	<!--Widget start--> | ||||
| 	<%= f.error_messages %> | ||||
| 	 | ||||
| 	<div id="sub-wiget"> | ||||
| 		<div id="widget-picture" class="widget-box"> | ||||
| 			<div class="widget-action clear"> | ||||
|  | @ -15,7 +14,6 @@ | |||
| 				<div class="control-group"> | ||||
|            <!-- <img class="pull-left upload-picture" src="/assets/default-img.png" /> --> | ||||
| 					<div  class="upload-picture"> | ||||
|               <!--請程式務必將圖片尺寸加入到行內裡--> | ||||
|               <% if @news_bulletin.image %> | ||||
|               	<%= image_tag @news_bulletin.image rescue ''%> | ||||
|               <% else %> | ||||
|  | @ -132,7 +130,7 @@ | |||
| 
 | ||||
| 	<div id="post-body"> | ||||
| 		<div id="post-body-content" class="clear"> | ||||
| 
 | ||||
| 			<%= alert_block_tag(t("activerecord.errors.template.body"),session[:in_validate_object].errors.messages) unless session[:in_validate_object].blank? %> | ||||
| 			<%= f.label :unit_list_for_anc,t('news.news_bulletin.unit_name')%> | ||||
| 			<%= f.select :unit_list_for_anc_id,@unit_list_for_anc.collect{|t| [ t.title, t.id ]}, {:prompt => t("news.news_bulletin.ut_prompt")}, :class => "input-medium" %>		 | ||||
| 
 | ||||
|  | @ -279,10 +277,10 @@ | |||
| 		</div> | ||||
| 	<!--Post End--> | ||||
| 	</div> | ||||
| 
 | ||||
| 		 | ||||
| 	  <div class="form-actions"> | ||||
| 	  	<%= link_to t('preview'),preview_panel_news_back_end_news_bulletins_path, :class=>"btn post_preview",:method=>:post , :remote => true%>  | ||||
| 		<%= f.submit t('submit'), :class=>'btn btn-primary' %> | ||||
| 	  	<%= button_tag t("preview"), :name=>"commit", :class=>'btn post_preview two_btn',:type=>:button, :url=>preview_panel_news_back_end_news_bulletins_path %> | ||||
| 		<%= f.submit t('submit'), :class=>'btn btn-primary two_btn' %> | ||||
| 		<%= link_to t('cancel'), get_go_back, :class=>"btn" %>  | ||||
| 	  </div> | ||||
|    | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| <div id="poststuff"> | ||||
| <%= form_for @news_bulletin, :url => panel_news_back_end_news_bulletins_path do |f| %> | ||||
| <%= form_for @news_bulletin, :url => panel_news_back_end_news_bulletins_path,:html=>{ :class=>"nccu_ajax_form"} do |f| %> | ||||
| 	<%= render :partial => 'form', :locals => {:f => f} %> | ||||
| <% end %> | ||||
| </div> | ||||
|  |  | |||
|  | @ -2,8 +2,8 @@ | |||
| <h1 class="h1"><%= @news_bulletin.title %></h1> | ||||
| <div class="info"> | ||||
| 	<div class="info1"> | ||||
| 		<span class="pull-right"><%= dislpay_view_count(@news_bulletin) %></span> | ||||
| 		<span class="date"><%= display_date(@news_bulletin.postdate) %></span> | ||||
| 		<span class="pull-right"><%= dislpay_view_count(@news_bulletin)  rescue ""%></span> | ||||
| 		<span class="date"><%= display_date(@news_bulletin.postdate)  rescue "" %></span> | ||||
| 		<% unit = @news_bulletin.unit_list_for_anc.title rescue nil %> | ||||
| 		<%= " | " if unit %> | ||||
| 		<%= link_to unit, panel_news_front_end_index_news_bulletins_by_unit_path(:name=>@news_bulletin.unit_list_for_anc_id) unless unit.blank?%> | ||||
|  |  | |||
|  | @ -21,7 +21,7 @@ | |||
| 		<li> | ||||
| 			<div class="news_img"><%= link_to image_tag(post.image.url, :size => "290x130"), panel_news_front_end_news_bulletin_path(post, :category_id => post.news_bulletin_category_id) %></div> | ||||
| 			<h3 class="h3 news_title"><%= link_to post.title, panel_news_front_end_news_bulletin_path(post, :category_id => post.news_bulletin_category_id) %></h3> | ||||
| 			<p class="news_wrap"><%= post.subtitle.html_safe rescue '' %></p> | ||||
| 			<p class="news_wrap"><%= truncate((post.subtitle rescue '') ,:length => 200).html_safe %></p> | ||||
| 		</li> | ||||
| 		<% end %> | ||||
| 	</ul> | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController | |||
|   before_filter :authenticate_user! | ||||
|   # before_filter :for_app_manager,:except => [:index,:show]  | ||||
|   before_filter :for_app_sub_manager,:except => [:index] | ||||
|   before_filter :only => [ :new,:edit,:update] do |controller| | ||||
|   before_filter :only => [ :new,:edit,:update,:create] do |controller| | ||||
|     controller.get_categorys('WebLinkCategory') | ||||
|   end | ||||
| 
 | ||||
|  | @ -74,7 +74,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController | |||
|   # POST /web_links.xml | ||||
|   def create | ||||
|     @web_link = WebLink.new(params[:web_link]) | ||||
| 	 | ||||
| 	get_tags | ||||
|     @web_link.create_user_id = current_user.id | ||||
|     @web_link.update_user_id = current_user.id | ||||
| 
 | ||||
|  | @ -159,7 +159,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController | |||
|    | ||||
|   def get_tags | ||||
|   	module_app = ModuleApp.first(:conditions => {:key => 'web_resource'}) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}) rescue [] | ||||
|   end | ||||
|    | ||||
| end | ||||
|  |  | |||
|  | @ -52,7 +52,7 @@ class Panel::WebResource::Widget::WebLinksController < OrbitWidgetController | |||
|    | ||||
|   def get_tags | ||||
|   	module_app = ModuleApp.first(:conditions => {:key => 'web_resource'}) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}) | ||||
|   	@tags = Tag.all(:conditions => {:module_app_id => module_app.id}) rescue [] | ||||
|   end | ||||
|    | ||||
| end | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue