From ec428f240c02cf268cc0a77ae1669e93c3c9b134 Mon Sep 17 00:00:00 2001
From: Matthew Fu
Date: Tue, 31 Jan 2012 18:23:32 +0800
Subject: [PATCH 1/2] Basic function for ad_banner
---
config/environments/development.rb | 30 ++++-----
config/routes.rb | 2 +-
.../back_end/bulletins/_file.html - 複製.erb | 34 ----------
.../bulletins/index.html - 有分類.erb | 64 -------------------
4 files changed, 16 insertions(+), 114 deletions(-)
delete mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_file.html - 複製.erb
delete mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - 有分類.erb
diff --git a/config/environments/development.rb b/config/environments/development.rb
index d1b671e5..549fc11e 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -24,21 +24,21 @@ PrototypeR4::Application.configure do
config.action_dispatch.best_standards_support = :builtin
- config.middleware.use ExceptionNotifier,
- :email_prefix => "[R4_error]",
- :sender_address => %{"notifier" },
- :exception_recipients => %w{chris@rulingcom.com}
-
- config.action_mailer.delivery_method = :smtp
- config.action_mailer.smtp_settings = {
- :tls => true,
- :enable_starttls_auto => true,
- :address => "smtp.gmail.com",
- :port => '587',
- :domain => "smtp.gmail.com",
- :authentication => "plain",
- :user_name => "redmine@rulingcom.com",
- :password => "rulingredmine" }
+ # config.middleware.use ExceptionNotifier,
+ # :email_prefix => "[R4_error]",
+ # :sender_address => %{"notifier" },
+ # :exception_recipients => %w{chris@rulingcom.com}
+ #
+ # config.action_mailer.delivery_method = :smtp
+ # config.action_mailer.smtp_settings = {
+ # :tls => true,
+ # :enable_starttls_auto => true,
+ # :address => "smtp.gmail.com",
+ # :port => '587',
+ # :domain => "smtp.gmail.com",
+ # :authentication => "plain",
+ # :user_name => "redmine@rulingcom.com",
+ # :password => "rulingredmine" }
end
diff --git a/config/routes.rb b/config/routes.rb
index 60f87467..3d483d08 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -13,7 +13,7 @@ PrototypeR4::Application.routes.draw do
namespace :admin do
resources :assets
resources :app_auths
-
+ resources :ad_banners
resources :designs do
collection do
get 'upload_package'
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_file.html - 複製.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_file.html - 複製.erb
deleted file mode 100644
index 009a602d..00000000
--- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_file.html - 複製.erb
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
- <% bulletin_files.each do | bulletin_file | %>
- <%= fields_for 'bulletin[bulletin_files][]', bulletin_file, :index => nil do |f| %>
-
- <%= f.label :file %>
- <%#= file_field_tag 'bulletin[file]' %>
- <%= f.file_field :file %>
-
- <%= f.label :file_title %>
- <%= f.text_field :filetitle %>
-
- <%= f.label :file_description %>
- <%= f.text_field :description %>
-
-
- <% if bulletin_file.new_record? %>
- <%= t(:delete) %>
- <% else %>
- <%= f.hidden_field :id %>
- <% if bulletin_file.is_built_in? %>
-
- <%= f.hidden_field :disabled, :value => bulletin_file.is_disabled? , :class => 'built_in_state' %>
- <% else %>
- <%= t(:delete) %>
- <%= f.hidden_field :_destroy, :value => nil, :class => 'should_destroy' %>
- <% end %>
- <% end %>
-
-
- <% end %>
- <% end %>
-
-
\ No newline at end of file
diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - 有分類.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - 有分類.erb
deleted file mode 100644
index 80dc0e7e..00000000
--- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html - 有分類.erb
+++ /dev/null
@@ -1,64 +0,0 @@
-<% content_for :secondary do %>
-
-
-
-
-
-
- <%= link_to t('bulletin.new_announcement'), new_panel_announcement_back_end_bulletin_path %>
- <%= link_to t('bulletin.new_announcement_class'), panel_announcement_back_end_bulletin_categorys_path %>
-
-<% end -%>
-
-<%= flash_messages %>
-
-<%= t('bulletin.list_announcement') %>
-
-
-
-
-
-
-<% @bulletin_categorys.each do |t| %>
-
- <%= link_to t.i18n_variable[I18n.locale], panel_announcement_back_end_bulletins_path(:bulletin_category_id => t.id ) %>
-
-
-
- <%= t('bulletin.category') %>
- <%= t('bulletin.title') %>
- <%= t('bulletin.image') %>
- <%= t('bulletin.file') %>
- <%= t('bulletin.text') %>
- <%= t('bulletin.postdate') %>
- <%= t('bulletin.deadline') %>
- <%= t('bulletin.action') %>
-
-
- <% t.bulletins.each do |post| %>
-
- <%= link_to post.bulletin_category.i18n_variable[I18n.locale], panel_announcement_front_end_bulletin_path(post) %>
- <%= post.title %>
- <%= link_to t('bulletin.image'), post.image.url, {:target => '_blank', :title => post.alt} if post.image.file %>
-
- <% post.bulletin_files.each do | bfile | %>
- <%= link_to bfile.filetitle, bfile.file.url, {:target => '_blank', :title => bfile.description} if bfile.file.file %>
- <% end %>
-
- <%= truncate(post.text,:length=>15) %>
- <%= post.postdate %>
- <%= post.deadline %>
-
- <%= link_to t('bulletin.edit'), edit_panel_announcement_back_end_bulletin_path(post) %> |
- <%= link_to t('bulletin.delete'), panel_announcement_back_end_bulletin_path(post), :confirm => t('announcement.sure?'), :method => :delete, :confirm => 'Are you sure?' %>
-
-
-
- <% end %>
-
-
-
-<% end %>
-
-
-
From dcecb78afb54e1f2287e7b3f1d9803f1e6936a66 Mon Sep 17 00:00:00 2001
From: Matthew Kaito Juyuan Fu
Date: Tue, 31 Jan 2012 18:31:31 +0800
Subject: [PATCH 2/2] Basic function for AdBanner
---
app/assets/javascripts/ad_banner.js | 18 +++++++
.../admin/ad_banners_controller.rb | 43 ++++++++++++++++
app/helpers/admin/ad_banner_helper.rb | 2 +
app/models/ad_banner.rb | 44 ++++++++++++++++
app/models/ad_image.rb | 16 ++++++
app/views/admin/ad_banners/_ad_image.html.erb | 7 +++
.../admin/ad_banners/_ad_image_form.html.erb | 3 ++
.../ad_banners/_ad_image_update.html.erb | 8 +++
app/views/admin/ad_banners/_form.html.erb | 51 +++++++++++++++++++
.../ad_banners/_new_add_banner_file.html.erb | 7 +++
app/views/admin/ad_banners/_side_bar.html.erb | 11 ++++
app/views/admin/ad_banners/edit.html.erb | 11 ++++
app/views/admin/ad_banners/index.html.erb | 46 +++++++++++++++++
app/views/admin/ad_banners/new.html.erb | 13 +++++
app/views/admin/ad_banners/show.html.erb | 18 +++++++
15 files changed, 298 insertions(+)
create mode 100644 app/assets/javascripts/ad_banner.js
create mode 100644 app/controllers/admin/ad_banners_controller.rb
create mode 100644 app/helpers/admin/ad_banner_helper.rb
create mode 100644 app/models/ad_banner.rb
create mode 100644 app/models/ad_image.rb
create mode 100644 app/views/admin/ad_banners/_ad_image.html.erb
create mode 100644 app/views/admin/ad_banners/_ad_image_form.html.erb
create mode 100644 app/views/admin/ad_banners/_ad_image_update.html.erb
create mode 100644 app/views/admin/ad_banners/_form.html.erb
create mode 100644 app/views/admin/ad_banners/_new_add_banner_file.html.erb
create mode 100644 app/views/admin/ad_banners/_side_bar.html.erb
create mode 100644 app/views/admin/ad_banners/edit.html.erb
create mode 100644 app/views/admin/ad_banners/index.html.erb
create mode 100644 app/views/admin/ad_banners/new.html.erb
create mode 100644 app/views/admin/ad_banners/show.html.erb
diff --git a/app/assets/javascripts/ad_banner.js b/app/assets/javascripts/ad_banner.js
new file mode 100644
index 00000000..57176a1c
--- /dev/null
+++ b/app/assets/javascripts/ad_banner.js
@@ -0,0 +1,18 @@
+$("button.multi_files").live("click", function(){
+ $(this).parent().prev("ul").append("" + $(this).val() +'Time:'+ $(this).siblings('.ad_time').val()+'Link:'+$(this).siblings('.ad_out_link').val()+ " ");
+ new_node = $(this).parent().clone();
+ $(this).parent().css("display","none");
+ new_node.children('input.multi_files').val("");
+ $(this).parent().before(new_node);
+ return false;
+
+});
+
+$('a.remove_mark').live("click",function(){
+ $(this).prev("input").val("true");
+ $(this).parent().css("text-decoration","line-through")
+ $(this).parent().removeClass("r_snapshot");
+ $(this).next().remove();
+ $(this).remove();
+ return false;
+});
\ No newline at end of file
diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb
new file mode 100644
index 00000000..19d81057
--- /dev/null
+++ b/app/controllers/admin/ad_banners_controller.rb
@@ -0,0 +1,43 @@
+class Admin::AdBannersController < ApplicationController
+ layout "admin"
+ before_filter :authenticate_user!
+ before_filter :is_admin?
+
+ def destroy
+ @ad_banner = AdBanner.find(params[:id])
+ @ad_banner.destroy
+ redirect_to admin_ad_banners_url
+ end
+
+ def show
+ @ad_banner = AdBanner.find(params[:id])
+ end
+
+ def new
+ @ad_banner = AdBanner.new
+ end
+
+ def create
+ @ad_banner = AdBanner.new(params[:ad_banner])
+ @ad_banner.save
+ redirect_to admin_ad_banners_url
+
+ end
+
+ def edit
+ @ad_banner = AdBanner.find(params[:id])
+
+ end
+
+ def update
+ @ad_banner = AdBanner.find(params[:id])
+ @ad_banner.update_attributes(params[:ad_banner])
+ @ad_banner.save
+ redirect_to admin_ad_banners_url
+ end
+
+ def index
+ @ad_banners = AdBanner.all
+ end
+
+end
\ No newline at end of file
diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb
new file mode 100644
index 00000000..0621df38
--- /dev/null
+++ b/app/helpers/admin/ad_banner_helper.rb
@@ -0,0 +1,2 @@
+module Admin::AdBannerHelper
+end
\ No newline at end of file
diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb
new file mode 100644
index 00000000..368c7081
--- /dev/null
+++ b/app/models/ad_banner.rb
@@ -0,0 +1,44 @@
+class AdBanner
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ include Mongoid::MultiParameterAttributes
+
+ field :title
+ field :picture_position
+ field :post_date,type: Date
+ field :unpost_date,type: Date
+ field :context
+ field :direct_to_after_click,type: Boolean
+ field :ad_style #TODO Design should explain
+
+
+ before_save :save_or_destroy
+
+ embeds_many :ad_images, :cascade_callbacks => true
+
+ def new_ad_images=(*attrs)
+ attrs[0].each do |attr| #Loop by JSs,Themes,Imgs
+ unless attr[:file].nil?
+ self.ad_images << AdImage.new(attr)
+ end
+ end
+ end
+
+ def existing_ad_images=(*attrs)
+ attrs[0].each do |attr| #Loop by JSs,Themes,Imgs
+ ad_image = self.ad_images.find attr[0]
+ ad_image.update_attributes(attr[1])
+ end
+ end
+
+ def save_or_destroy
+ self.ad_images.each do |ad_image|
+ if ad_image.to_save?
+ ad_image.save
+ end
+ if ad_image.to_destroy?
+ ad_image.destroy
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/ad_image.rb b/app/models/ad_image.rb
new file mode 100644
index 00000000..dc8eab8b
--- /dev/null
+++ b/app/models/ad_image.rb
@@ -0,0 +1,16 @@
+class AdImage
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ mount_uploader :file, ImageUploader
+
+ field :time_to_next #Weight
+ field :picture_intro
+ field :out_link
+
+ field :to_save, :type => Boolean
+ field :to_destroy, :type => Boolean
+
+ embedded_in :ad_banner
+
+end
diff --git a/app/views/admin/ad_banners/_ad_image.html.erb b/app/views/admin/ad_banners/_ad_image.html.erb
new file mode 100644
index 00000000..7ecdaa3b
--- /dev/null
+++ b/app/views/admin/ad_banners/_ad_image.html.erb
@@ -0,0 +1,7 @@
+
+ <%= image_tag ad_image.file %>
+ Time to next: <%= ad_image.time_to_next %>
+ Intro: <%= ad_image.picture_intro %>
+ Out Link <%= link_to ad_image.out_link %>
+ <%= render :partial => "ad_image_update", :locals => { :ad_image => ad_image } %>
+
diff --git a/app/views/admin/ad_banners/_ad_image_form.html.erb b/app/views/admin/ad_banners/_ad_image_form.html.erb
new file mode 100644
index 00000000..43d817a5
--- /dev/null
+++ b/app/views/admin/ad_banners/_ad_image_form.html.erb
@@ -0,0 +1,3 @@
+Time: <%= f.text_field :time_to_next ,:class=> 'ad_time'%>
+Link:<%= f.text_field :out_link ,:class=> 'ad_out_link'%>
+<%= f.hidden_field :to_save %>
\ No newline at end of file
diff --git a/app/views/admin/ad_banners/_ad_image_update.html.erb b/app/views/admin/ad_banners/_ad_image_update.html.erb
new file mode 100644
index 00000000..d2234ac5
--- /dev/null
+++ b/app/views/admin/ad_banners/_ad_image_update.html.erb
@@ -0,0 +1,8 @@
+<%= fields_for "ad_banner[existing_ad_images][#{ad_image.id}]", ad_image do |f| %>
+
+ Destroy?<%= f.check_box :to_destroy %>
+ <%= render :partial => "ad_image_form", :locals => { :f => f } %>
+
+<% end %>
+
+
diff --git a/app/views/admin/ad_banners/_form.html.erb b/app/views/admin/ad_banners/_form.html.erb
new file mode 100644
index 00000000..ff19e513
--- /dev/null
+++ b/app/views/admin/ad_banners/_form.html.erb
@@ -0,0 +1,51 @@
+<% content_for :page_specific_css do %>
+ <%= stylesheet_link_tag "ad_banner" %>
+<% end %>
+<% content_for :page_specific_javascript do %>
+ <%= javascript_include_tag "ad_banner" %>
+<% end %>
+
+
+
+ <%= f.label :title, t('admin.title') %>
+ <%= f.text_field :title, :class => 'text' %>
+
+
+ <%= f.label :picture_position, t('admin.picture_position') %>
+ <%= f.text_field :picture_position, :class => 'text' %>
+
+
+
+ <%= f.label :post_date, t('admin.post_date') %>
+ <%= f.date_select :post_date, :order => [:year, :month, :day], :use_month_numbers => true %>
+
+
+
+ <%= f.label :unpost_date, t('admin.unpost_date') %>
+ <%= f.date_select :unpost_date, :order => [:year, :month, :day], :use_month_numbers => true %>
+
+
+
+ <%= f.label :context, t('admin.context') %>
+ <%= f.text_field :context, :class => 'text' %>
+
+
+
+ <%= f.label :direct_to_after_click, t('admin.direct_to_after_click') %>
+ <%= f.check_box :direct_to_after_click %>
+
+
+ <%= f.label :ad_images, t('admin.ad_images') %>
+
+ <% @ad_banner.ad_images.each do |ad_image| %>
+ <%= render :partial => 'ad_image', :object => ad_image, :locals => { :field_name => "ad_images", :f => f, :classes => "r_destroy, r_edit" } %>
+ <% end %>
+
+ <%= render :partial => 'new_add_banner_file', :object => @ad_banner.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %>
+
+
+
+
+
+ <%#= render :partial => 'new_design_file', :object => @design.themes.build, :locals => { :field_name => "themes", :f => f, :classes => "r_destroy" } %>
+
diff --git a/app/views/admin/ad_banners/_new_add_banner_file.html.erb b/app/views/admin/ad_banners/_new_add_banner_file.html.erb
new file mode 100644
index 00000000..64733ca4
--- /dev/null
+++ b/app/views/admin/ad_banners/_new_add_banner_file.html.erb
@@ -0,0 +1,7 @@
+<%= f.fields_for field_name, new_add_banner_file do |f| %>
+
+ <%= f.file_field :file %>
+ <%= render :partial => "ad_image_form", :locals => { :f => f } %>
+ <%= button_tag '+', :class => "multi_files"%>
+
+<% end %>
\ No newline at end of file
diff --git a/app/views/admin/ad_banners/_side_bar.html.erb b/app/views/admin/ad_banners/_side_bar.html.erb
new file mode 100644
index 00000000..ce0e1296
--- /dev/null
+++ b/app/views/admin/ad_banners/_side_bar.html.erb
@@ -0,0 +1,11 @@
+
+
+
+
+
<%= t('admin.setup_member') %>
+
+ <%= link_to content_tag(:span, t('admin.list_users')), admin_users_path %>
+ <%= link_to content_tag(:span, t('admin.list_roles')), admin_roles_path %>
+ <%= link_to content_tag(:span, t('admin.list_infos')), admin_infos_path %>
+
+
\ No newline at end of file
diff --git a/app/views/admin/ad_banners/edit.html.erb b/app/views/admin/ad_banners/edit.html.erb
new file mode 100644
index 00000000..7ccb00d0
--- /dev/null
+++ b/app/views/admin/ad_banners/edit.html.erb
@@ -0,0 +1,11 @@
+<%= t('admin.editing_ad_banner') %>
+
+<%= form_for @ad_banner, :url => admin_ad_banner_path(@ad_banner),:html => {:multipart => true} do |f| %>
+ <%= f.error_messages %>
+ <%= render :partial => "form", :locals => { :f => f } %>
+
+ <%= f.submit t('update') %> <%= link_back %>
+
+<% end %>
+
+
diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb
new file mode 100644
index 00000000..54217140
--- /dev/null
+++ b/app/views/admin/ad_banners/index.html.erb
@@ -0,0 +1,46 @@
+<% content_for :secondary do %>
+
+
<%= t('admin.setup_ad_banners') %>
+
+ <%= link_to content_tag(:span, t('admin.new_ad_banner')), new_admin_ad_banner_path, :class => 'seclink1' %>
+
+
+<% end -%>
+
+<%= flash_messages %>
+
+
<%= t('admin.list_ad_banners') %>
+
+
+
+
+ <%= t('admin.title') %>
+ <%= t('admin.picture_position') %>
+ <%= t('admin.post_date') %>
+ <%= t('admin.unpost_date') %>
+ <%= t('admin.context') %>
+ <%= t('admin.direct_to_after_click') %>
+
+
+<% @ad_banners.each do |ad_banner| %>
+
+ <%= ad_banner.title %>
+ <%= ad_banner.picture_position %>
+ <%= ad_banner.post_date %>
+ <%= ad_banner.unpost_date %>
+ <%= ad_banner.context %>
+ <%= ad_banner.direct_to_after_click %>
+
+ <%= link_to t(:show), admin_ad_banner_path(ad_banner), :class => 'show' %>
+ <%= link_to t(:edit), edit_admin_ad_banner_path(ad_banner), :class => 'edit' %>
+ <%= link_to t(:delete), admin_ad_banner_path(ad_banner), :confirm => t('sure?'), :method => :delete, :class => 'delete' %>
+
+
+
+<% end %>
+
+
+
+
+ <%= link_to t('admin.new_ad_banner'), new_admin_ad_banner_path, :class => 'new' %>
+
\ No newline at end of file
diff --git a/app/views/admin/ad_banners/new.html.erb b/app/views/admin/ad_banners/new.html.erb
new file mode 100644
index 00000000..31d182b7
--- /dev/null
+++ b/app/views/admin/ad_banners/new.html.erb
@@ -0,0 +1,13 @@
+
+
<%= t('admin.new_ad_banner') %>
+
+ <%= form_for :ad_banner, :url => admin_ad_banners_path, :html => {:multipart => true} do |f| %>
+ <%= f.error_messages %>
+ <%= render :partial => "form", :locals => { :f => f } %>
+
+
+ <%= link_back %>
+ <%= f.submit t('create') %>
+
+ <% end %>
+
diff --git a/app/views/admin/ad_banners/show.html.erb b/app/views/admin/ad_banners/show.html.erb
new file mode 100644
index 00000000..35deffa2
--- /dev/null
+++ b/app/views/admin/ad_banners/show.html.erb
@@ -0,0 +1,18 @@
+<% content_for :secondary do %>
+ <%= render 'side_bar' %>
+<% end %>
+
+
+
+ <%=t('admin.ad_banner.title') %> <%= @ad_banner.title %>
+ <%=t('admin.ad_banner.picture_position') %> <%= @ad_banner.picture_position %>
+ <%=t('admin.ad_banner.post_date') %> <%= @ad_banner.post_date %>
+ <%=t('admin.ad_banner.unpost_date') %> <%= @ad_banner.unpost_date %>
+ <%=t('admin.ad_banner.context') %> <%= @ad_banner.context %>
+ <%=t('admin.ad_banner.direct_to_after_click') %> <%= @ad_banner.direct_to_after_click %>
+ <%=t('admin.ad_banner.ad_style') %> <%= @ad_banner.ad_style %>
+
+
+
+ <%= render :partial => "admin/ad_banners/ad_image", :collection => @ad_banner.ad_images %>
+