diff --git a/Gemfile.lock b/Gemfile.lock index 5089191c..6bd7e8b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -97,7 +97,6 @@ GEM railties (~> 3.0) thor (~> 0.14) json (1.6.5) - libv8 (3.3.10.4) linecache19 (0.5.12) ruby_core_source (>= 0.1.4) mail (2.3.3) @@ -211,8 +210,6 @@ GEM rack (~> 1.0) tilt (~> 1.1, != 1.3.0) subexec (0.2.1) - therubyracer (0.9.10) - libv8 (~> 3.3.10) thor (0.14.6) tilt (1.3.3) tinymce-rails (3.4.8) @@ -275,7 +272,6 @@ DEPENDENCIES sinatra spork sprockets - therubyracer tinymce-rails uglifier watchr diff --git a/app/assets/javascripts/inc/modal-preview.js b/app/assets/javascripts/inc/modal-preview.js new file mode 100644 index 00000000..2f915f6c --- /dev/null +++ b/app/assets/javascripts/inc/modal-preview.js @@ -0,0 +1,15 @@ +//Preview need a link in form as Ex and a corresponding PUT action in controller +//Ex preview trigger: +// <%= link_to "NewPreview", realtime_preview_admin_ad_banner_path(ad_banner_tab) , :class=>'preview_trigger'%> + +$(document).ready(function() { + $("a.preview_trigger").click(function(){ + $(this).after(""); + $.ajax({ + type:"put", + url:$(this).attr("href"), + data:$(this).parents("form").serialize() + }).done(function(){ $("#"+start_modal_with_id).modal('show');}); + return false;} + ); +}); \ No newline at end of file diff --git a/app/assets/stylesheets/widget.css b/app/assets/stylesheets/widget.css index 2a9f430d..df284d92 100644 --- a/app/assets/stylesheets/widget.css +++ b/app/assets/stylesheets/widget.css @@ -59,7 +59,7 @@ } .select-role { display:none; - padding: 10px 0; + overflow:hidden; } .file-upload { position:relative; diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 95ce7e7c..19983b66 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -22,9 +22,14 @@ class Admin::AdBannersController < ApplicationController def create @ad_banner = AdBanner.new(params[:ad_banner]) - @ad_banner.save - redirect_to admin_ad_banners_url - + if @ad_banner.save + @active = @ad_banner + respond_to do |format| + format.js {render 'new_created_node'} + end + else + render 'create_error_msg' + end end def edit @@ -39,13 +44,14 @@ class Admin::AdBannersController < ApplicationController redirect_to admin_ad_banners_url end - def destroy_ad_image - + def realtime_preview + @ad_banner = AdBanner.first(conditions: { title: params[:title] }).preview_clone + @ad_banner.update_attributes(params[:ad_banner]).update_attributes(params[:ad_images]) end def index @ad_banners = AdBanner.all - @active = @ad_banners.first + @active = @ad_banners.first end end \ No newline at end of file diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index 3e09280f..0147c3d2 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -9,11 +9,16 @@ class AdBanner before_save :save_or_destroy validates_uniqueness_of :title + validates :title , :length => { :minimum => 2 } has_many :ad_images , dependent: :delete FX_TYPES = ["blindX","blindY","blindZ","cover","curtainX","curtainY","fade","fadeZoom","growX","growY","scrollUp","scrollDown","scrollLeft","scrollRight","scrollHorz","scrollVert","shuffle","slideX","slideY","toss","turnUp","turnDown","turnLeft","turnRight","uncover","wipe","zoom"] - + def preview_clone + preview_banner = self.clone + preview_banner.ad_images = self.ad_images + preview_banner + end # def new_ad_images(*attrs) # debugger # a=1 diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index d9b1b902..530e45cb 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -1,19 +1,20 @@ - -
" id=<%= ad_banner_tab.title %>> -

尺寸:

+
" id=<%= ad_banner_tab.title %>> +

<%= t("admin.ad.banner_best_size") %>:

<%= form_for ad_banner_tab,:url=> admin_ad_banner_path(ad_banner_tab),:method => :put,:class=>"input-medium" do |f| -%> <%= f.label :ad_fx, t('admin.ad.ab_fx') %> <%= f.select :ad_fx ,AdBanner::FX_TYPES %> <%= f.label :transition_sec, t('admin.ad.transition_sec') %> <%= f.text_field :transition_sec,:placeholder=>"3秒請輸入3000",:class=> "span3" %> <%= t("admin.ad.trans_unit_sec") %> - <%= f.submit %> - <%= f.submit 'Cancel',:type=>'reset' %> + <%= f.submit t("admin.ad.update_banner") %> + <%= f.submit t("cancel"),:type=>'reset' %>
<%= render :partial => "ad_image_update", :collection => ad_banner_tab.ad_images,:as => :ad_image,:locals=>{:ad_banner => ad_banner_tab} %> <%#= render :partial => 'new_add_banner_file', :object => ad_banner_tab.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %> - <%= link_to 'Add AdImage',new_admin_ad_banner_ad_image_path(ad_banner_tab) %> + <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> + <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.title) , :class=>'preview_trigger btn btn-success'%> +
<% end -%> - <%= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %> + <%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %>
diff --git a/app/views/admin/ad_banners/_ad_image_update.html.erb b/app/views/admin/ad_banners/_ad_image_update.html.erb index 34723b7e..c51b5885 100644 --- a/app/views/admin/ad_banners/_ad_image_update.html.erb +++ b/app/views/admin/ad_banners/_ad_image_update.html.erb @@ -1,12 +1,12 @@
  • <%= image_tag ad_image.file rescue nil%>

    - <%= ad_image.display? ? '[Showing]' : '[NotShawing]' %> + <%= ad_image.display? ? "[#{t('admin.ad.showing')}]" : "[#{t('admin.ad.not_showing')}]" %> <%= "#{ad_image.post_date ||'NeedReset' }~#{ad_image.unpost_date || 'NeedReset'}" %>

    - <%= link_to 'Edit',edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> - <%= link_to 'Del',admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %> + <%= link_to t('edit'),edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> + <%= link_to t('delete'),admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %>

  • diff --git a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb index 8e8de1d9..235e7e15 100644 --- a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb +++ b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb @@ -4,7 +4,7 @@ <% end %>
    diff --git a/app/views/admin/ad_banners/_modal_preview.html.erb b/app/views/admin/ad_banners/_modal_preview.html.erb new file mode 100644 index 00000000..27222e57 --- /dev/null +++ b/app/views/admin/ad_banners/_modal_preview.html.erb @@ -0,0 +1,35 @@ +<% if ad_banner -%> + + + +<% end -%> + + + diff --git a/app/views/admin/ad_banners/_preview_block.html.erb b/app/views/admin/ad_banners/_preview_block.html.erb index c2185d04..f71b3cd3 100644 --- a/app/views/admin/ad_banners/_preview_block.html.erb +++ b/app/views/admin/ad_banners/_preview_block.html.erb @@ -23,7 +23,7 @@ diff --git a/app/views/admin/ad_banners/create_error_msg.js.erb b/app/views/admin/ad_banners/create_error_msg.js.erb new file mode 100644 index 00000000..60f1d261 --- /dev/null +++ b/app/views/admin/ad_banners/create_error_msg.js.erb @@ -0,0 +1 @@ +alert("Error occures:<%= @ad_banner.errors.full_messages%>"); \ No newline at end of file diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index e6ebfd5d..8307885a 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -1,11 +1,18 @@ -<%= stylesheet_link_tag "admin/ad_banner_preview" %> +<% content_for :page_specific_css do -%> + <%#= stylesheet_link_tag "admin/ad_banner_preview" %> +<% end -%> +<% content_for :page_specific_css do -%> + <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> + <%= javascript_include_tag "inc/modal-preview" %> +<% end -%> +
    diff --git a/app/views/admin/ad_banners/new_created_node.js.erb b/app/views/admin/ad_banners/new_created_node.js.erb new file mode 100644 index 00000000..86970e6a --- /dev/null +++ b/app/views/admin/ad_banners/new_created_node.js.erb @@ -0,0 +1,8 @@ +$('<%= escape_javascript(content_tag(:li,link_to(@ad_banner.title,"##{@ad_banner.title}",:data=>{:toggle=>"tab"}))) %>').insertBefore("#new_ad_banner_tab_but"); +$('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertBefore($("#new-a-banner")); + +$('.modal').modal('hide'); +$('#new-a-banner').unbind(); +$('#post-body-content').find(".nav.nav-tabs").children('li.active').removeClass("active"); +$('#post-body-content').find(".nav.nav-tabs").children('li[id!="new_ad_banner_tab_but"]').last().addClass("active"); + diff --git a/app/views/admin/ad_banners/realtime_preview.js.erb b/app/views/admin/ad_banners/realtime_preview.js.erb new file mode 100644 index 00000000..1ab728f2 --- /dev/null +++ b/app/views/admin/ad_banners/realtime_preview.js.erb @@ -0,0 +1,2 @@ +$('#show_preview').html("<%= escape_javascript(render(:partial => 'modal_preview',:locals => {:ad_banner => @ad_banner})) %>"); +var start_modal_with_id = "slideshow-<%=@ad_banner.title.dehumanize%>" \ No newline at end of file diff --git a/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index 8e7f18df..075f01b4 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -4,6 +4,9 @@ <% content_for :page_specific_javascript do %> <%= javascript_include_tag "lib/datepicker" %> <%= javascript_include_tag "lib/date.format" %> + <%= javascript_include_tag "inc/modal-preview" %> + <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> + <% end %> @@ -167,7 +170,7 @@
    <%= f.fields_for :context, @ad_image.context do |f| %> - <%= f.text_area locale,:style => "width:100%", :class => "asd_tinymce_textarea post-title" %> + <%= f.text_area locale,:style => "width:100%", :class => "tinymce_textarea post-title" %> <% end %>
    @@ -184,5 +187,10 @@
    +
    + <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(@ad_image.ad_banner.title) ,:class=>"preview_trigger btn btn-success" rescue nil%> + <%= f.submit t("submit"),:class=>"btn btn-primary" %> + <%= f.submit t("cancel"),:class=>"btn ",:type => 'reset' %> +
    \ No newline at end of file diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 38380984..84d89ac4 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -32,9 +32,9 @@ <%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.ad_banner'), admin_ad_banners_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('ad_banners', 'ad_images')) do -%> - <%= content_tag :li, link_to(t('admin.all_ad_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> - <%= content_tag :li, link_to(t('admin.new_ad_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> - <%= content_tag :li, link_to(t('admin.new_ad_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> + <%= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> + <%= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> + <%= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> <% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 5a52d42e..6877b6bd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -41,10 +41,22 @@ en: sure?: Are you sure? update: Update yes_: "Yes" - + admin: action: Action ad_banner: AD Banner + ad: + ab_fx: FX + all_banners: AdBanner list + banner_best_size: Banner Best Size + new_banner: New banner + new_image: New image + showing: Showing + not_showing: NotShowing + title: Title + transition_sec: Transition time + trans_unit_sec: sec + update_banner: Update Banner add: Add add_item: Add item add_language: Add language @@ -171,3 +183,8 @@ en: role: User role panel: + + modal: + close: Close + preview: Preview + diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index c7230c80..550f454e 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -45,11 +45,15 @@ zh_tw: ad: ab_fx: 轉場特效 all_banners: 輪播清單 + banner_best_size: Banner 尺寸 new_banner: 新增輪播 new_image: 新增橫幅 + showing: 顯示中 + not_showing: 沒有顯示 title: 標題 transition_sec: 轉場單位時間 trans_unit_sec: 秒 + update_banner: 更新輪播 add: 新增 add_item: 新增項目 add_language: 新增語言 @@ -392,3 +396,6 @@ zh_tw: create: "新增%{model}" update: "更新%{model}" submit: "儲存%{model}" + modal: + close: "關閉" + preview: "預覽" diff --git a/config/routes.rb b/config/routes.rb index a86f6118..d2294edf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,8 @@ Orbit::Application.routes.draw do end end - + + match 'ad_banner/:title/preivew' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put resources :ad_banners do collection do match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get