Merge branch 'master' into ldap

Conflicts:
	app/assets/stylesheets/new_admin.css.erb
This commit is contained in:
Christophe Vilayphiou 2012-04-23 14:13:37 +08:00
commit 2eeb530422
19 changed files with 148 additions and 44 deletions

View File

@ -97,7 +97,6 @@ GEM
railties (~> 3.0) railties (~> 3.0)
thor (~> 0.14) thor (~> 0.14)
json (1.6.5) json (1.6.5)
libv8 (3.3.10.4)
linecache19 (0.5.12) linecache19 (0.5.12)
ruby_core_source (>= 0.1.4) ruby_core_source (>= 0.1.4)
mail (2.3.3) mail (2.3.3)
@ -211,8 +210,6 @@ GEM
rack (~> 1.0) rack (~> 1.0)
tilt (~> 1.1, != 1.3.0) tilt (~> 1.1, != 1.3.0)
subexec (0.2.1) subexec (0.2.1)
therubyracer (0.9.10)
libv8 (~> 3.3.10)
thor (0.14.6) thor (0.14.6)
tilt (1.3.3) tilt (1.3.3)
tinymce-rails (3.4.8) tinymce-rails (3.4.8)
@ -275,7 +272,6 @@ DEPENDENCIES
sinatra sinatra
spork spork
sprockets sprockets
therubyracer
tinymce-rails tinymce-rails
uglifier uglifier
watchr watchr

View File

@ -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("<span id='show_preview'></span>");
$.ajax({
type:"put",
url:$(this).attr("href"),
data:$(this).parents("form").serialize()
}).done(function(){ $("#"+start_modal_with_id).modal('show');});
return false;}
);
});

View File

@ -59,7 +59,7 @@
} }
.select-role { .select-role {
display:none; display:none;
padding: 10px 0; overflow:hidden;
} }
.file-upload { .file-upload {
position:relative; position:relative;

View File

@ -22,9 +22,14 @@ class Admin::AdBannersController < ApplicationController
def create def create
@ad_banner = AdBanner.new(params[:ad_banner]) @ad_banner = AdBanner.new(params[:ad_banner])
@ad_banner.save if @ad_banner.save
redirect_to admin_ad_banners_url @active = @ad_banner
respond_to do |format|
format.js {render 'new_created_node'}
end
else
render 'create_error_msg'
end
end end
def edit def edit
@ -39,13 +44,14 @@ class Admin::AdBannersController < ApplicationController
redirect_to admin_ad_banners_url redirect_to admin_ad_banners_url
end 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 end
def index def index
@ad_banners = AdBanner.all @ad_banners = AdBanner.all
@active = @ad_banners.first @active = @ad_banners.first
end end
end end

View File

@ -9,11 +9,16 @@ class AdBanner
before_save :save_or_destroy before_save :save_or_destroy
validates_uniqueness_of :title validates_uniqueness_of :title
validates :title , :length => { :minimum => 2 }
has_many :ad_images , dependent: :delete 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"] 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) # def new_ad_images(*attrs)
# debugger # debugger
# a=1 # a=1

View File

@ -1,19 +1,20 @@
<script type="text/javascript" src="/static/jquery.cycle.all.latest.js"></script> <div class="tab-pane <%= "active" if ad_banner_tab==@active%>" id=<%= ad_banner_tab.title %>>
<div class="tab-pane <%= "active" if ad_banner_tab==@active %>" id=<%= ad_banner_tab.title %>> <p><%= t("admin.ad.banner_best_size") %></p>
<p>尺寸:</p>
<%= form_for ad_banner_tab,:url=> admin_ad_banner_path(ad_banner_tab),:method => :put,:class=>"input-medium" do |f| -%> <%= 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.label :ad_fx, t('admin.ad.ab_fx') %>
<%= f.select :ad_fx ,AdBanner::FX_TYPES %> <%= f.select :ad_fx ,AdBanner::FX_TYPES %>
<%= f.label :transition_sec, t('admin.ad.transition_sec') %> <%= 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.text_field :transition_sec,:placeholder=>"3秒請輸入3000",:class=> "span3" %> <%= t("admin.ad.trans_unit_sec") %>
<%= f.submit %> <%= f.submit t("admin.ad.update_banner") %>
<%= f.submit 'Cancel',:type=>'reset' %> <%= f.submit t("cancel"),:type=>'reset' %>
<div> <div>
<%= render :partial => "ad_image_update", :collection => ad_banner_tab.ad_images,:as => :ad_image,:locals=>{:ad_banner => ad_banner_tab} %> <%= 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" } %> <%#= 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'%>
</div> </div>
<% end -%> <% end -%>
<%= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %> <%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %>
</div> </div>

View File

@ -1,12 +1,12 @@
<li class="span3"> <li class="span3">
<%= image_tag ad_image.file rescue nil%> <%= image_tag ad_image.file rescue nil%>
<p> <p>
<%= 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'}" %> <%= "#{ad_image.post_date ||'NeedReset' }~#{ad_image.unpost_date || 'NeedReset'}" %>
</p> </p>
<p> <p>
<%= link_to 'Edit',edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> <%= link_to t('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('delete'),admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %>
</p> </p>
</li> </li>

View File

@ -4,7 +4,7 @@
<div class="modal-header"> <div class="modal-header">
<a class="close" data-dismiss="modal">×</a> <a class="close" data-dismiss="modal">×</a>
<h3>Add AdBanner</h3> <h3><%= t("admin.ad.new_banner") %></h3>
</div> </div>
<div class="modal-body form-horizontal"> <div class="modal-body form-horizontal">
@ -30,26 +30,21 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<%= f.submit t('submit'), :class=>'btn btn-primary' %> <%= f.submit t('submit'), :class=>'btn btn-primary',:remote=>true %>
<a class="btn" data-dismiss="modal"><%= t('cancel')%></a> <a class="btn" data-dismiss="modal"><%= t('cancel')%></a>
</div> </div>
<% end %> <% end %>
</div> </div>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
if(window.location.pathname == "/admin/ad_banners/new"){
$('#new-a-banner').modal({show: true});
}
$('#new_ad_banner_tab_but').on('shown', function (e) { $('#new_ad_banner_tab_but').on('shown', function (e) {
$('#new-a-banner').modal({show: true}); $('#new-a-banner').modal({show: true});
}) });
$('#new-a-banner').on('shown', function (e) {
alert('show!');
})
<% if params[:action] == "new" -%>
$('#new-a-banner').modal({show: true});
<% end -%>
$('#new-a-banner').on('hidden', function (e) { $('#new-a-banner').on('hidden', function (e) {
$(".nav.nav-tabs a[id!='new_ad_banner_tab_but']:last").tab('show'); $(".nav.nav-tabs a[id!='new_ad_banner_tab_but']:last").tab('show');
}) });
</script> </script>

View File

@ -0,0 +1,35 @@
<% if ad_banner -%>
<div class="modal hide fade in banner-preview" id='slideshow-<%=ad_banner.title.dehumanize%>'>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3><%= t("modal.preview") %></h3>
</div>
<div class="modal-body">
<p class="ad_banner_slideshow">
<% preview_block_ad_images_helper(ad_banner).each do |ad_image| -%>
<%= image_tag ad_image.file,:alt => (ad_image.title[locale] || ' '),:time_to_next => ad_banner.transition_sec,:link_open=> ad_image.link_open, :link_url =>((ad_image.out_link || ad_banner.context || ' ')) %>
<% end -%>
</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal"><%= t("modal.close") %></a>
</div>
</div>
<% end -%>
<script type='text/javascript' src='/static/kernel.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
$('#slideshow-<%=ad_banner.title.dehumanize%>').on('show', function () {
$('#slideshow-banner_1').find(".ad_banner_slideshow").cycle({delay: -1000, fx: '<%= ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx %>', timeoutFn: getTimeout });
});
$(".modal").on('hidden', function () {
$("#show_preview").remove();
});
//$('#slideshow-<%=ad_banner.title.dehumanize%>').show();
});
</script>

View File

@ -23,7 +23,7 @@
<script type='text/javascript' src='/static/kernel.js'></script> <script type='text/javascript' src='/static/kernel.js'></script>
<script type='text/javascript'> <script type='text/javascript'>
$('#slideshow-<%=ad_banner.title.dehumanize%>').on('show', function () { $('#slideshow-<%=ad_banner.title.dehumanize%>').on('show', function () {
$('#slideshow-banner_1').find(".ad_banner_slideshow").cycle({delay: -1000, fx: '<%= ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx %>', timeoutFn: getTimeout }); $('#slideshow-<%=ad_banner.title.dehumanize%>').find(".ad_banner_slideshow").cycle({delay: -1000, fx: '<%= ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx %>', timeoutFn: getTimeout });
}); });
</script> </script>

View File

@ -0,0 +1 @@
alert("Error occures:<%= @ad_banner.errors.full_messages%>");

View File

@ -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 -%>
<div id="post-body-content" class="clear"> <div id="post-body-content" class="clear">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<% @ad_banners.each do |ab| %> <% @ad_banners.each do |ab| %>
<%= content_tag :li,link_to(ab.title,"##{ab.title}",:data=>{:toggle=>"tab"}),:class => (ab == @active ? 'active' : nil ) %> <%= content_tag :li,link_to(ab.title,"##{ab.title}",:data=>{:toggle=>"tab"}),:class => (ab == @active ? 'active' : nil ) %>
<% end -%> <% end -%>
<%= content_tag :li,link_to('New',"#new-a-banner",:data=>{:toggle=>"tab"}),:id=>'new_ad_banner_tab_but',:class => (@active.nil? ? 'active' : nil ) %> <%= content_tag :li,link_to(t("admin.ad.new_banner"),"#new-a-banner",:data=>{:toggle=>"tab"}),:id=>'new_ad_banner_tab_but',:class => (@active.nil? ? 'active' : nil ) %>
</ul> </ul>

View File

@ -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");

View File

@ -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%>"

View File

@ -4,6 +4,9 @@
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/datepicker" %> <%= javascript_include_tag "lib/datepicker" %>
<%= javascript_include_tag "lib/date.format" %> <%= javascript_include_tag "lib/date.format" %>
<%= javascript_include_tag "inc/modal-preview" %>
<%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %>
<% end %> <% end %>
@ -167,7 +170,7 @@
<br/> <br/>
<div class="context editor"> <div class="context editor">
<%= f.fields_for :context, @ad_image.context do |f| %> <%= 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 %> <% end %>
</div> </div>
@ -184,5 +187,10 @@
</div> </div>
</div> </div>
<!--Post End--> <!--Post End-->
<div class="form-actions">
<%= 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' %>
</div>
</form> </form>
</div> </div>

View File

@ -32,9 +32,9 @@
<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') do -%> <%= 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 %> <%= 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 :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.ad.all_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.ad.new_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.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -41,10 +41,22 @@ en:
sure?: Are you sure? sure?: Are you sure?
update: Update update: Update
yes_: "Yes" yes_: "Yes"
admin: admin:
action: Action action: Action
ad_banner: AD Banner 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: Add
add_item: Add item add_item: Add item
add_language: Add language add_language: Add language
@ -171,3 +183,8 @@ en:
role: User role role: User role
panel: panel:
modal:
close: Close
preview: Preview

View File

@ -45,11 +45,15 @@ zh_tw:
ad: ad:
ab_fx: 轉場特效 ab_fx: 轉場特效
all_banners: 輪播清單 all_banners: 輪播清單
banner_best_size: Banner 尺寸
new_banner: 新增輪播 new_banner: 新增輪播
new_image: 新增橫幅 new_image: 新增橫幅
showing: 顯示中
not_showing: 沒有顯示
title: 標題 title: 標題
transition_sec: 轉場單位時間 transition_sec: 轉場單位時間
trans_unit_sec: trans_unit_sec:
update_banner: 更新輪播
add: 新增 add: 新增
add_item: 新增項目 add_item: 新增項目
add_language: 新增語言 add_language: 新增語言
@ -392,3 +396,6 @@ zh_tw:
create: "新增%{model}" create: "新增%{model}"
update: "更新%{model}" update: "更新%{model}"
submit: "儲存%{model}" submit: "儲存%{model}"
modal:
close: "關閉"
preview: "預覽"

View File

@ -24,7 +24,8 @@ Orbit::Application.routes.draw do
end end
end end
match 'ad_banner/:title/preivew' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put
resources :ad_banners do resources :ad_banners do
collection do collection do
match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get