Basic function for AdBanner
This commit is contained in:
parent
3287b68354
commit
a980847eb3
|
@ -0,0 +1,18 @@
|
||||||
|
$("button.multi_files").live("click", function(){
|
||||||
|
$(this).parent().prev("ul").append("<li>" + $(this).val() +'Time:'+ $(this).siblings('.ad_time').val()+'Link:'+$(this).siblings('.ad_out_link').val()+ "</li>");
|
||||||
|
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;
|
||||||
|
});
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
||||||
|
module Admin::AdBannerHelper
|
||||||
|
end
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
||||||
|
<div id="basic_block" class="roles_block">
|
||||||
|
<%= 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 } %>
|
||||||
|
</div>
|
|
@ -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 %>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<%= fields_for "ad_banner[existing_ad_images][#{ad_image.id}]", ad_image do |f| %>
|
||||||
|
<p class="new_file">
|
||||||
|
Destroy?<%= f.check_box :to_destroy %>
|
||||||
|
<%= render :partial => "ad_image_form", :locals => { :f => f } %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -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 %>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :title, t('admin.title') %>
|
||||||
|
<%= f.text_field :title, :class => 'text' %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :picture_position, t('admin.picture_position') %>
|
||||||
|
<%= f.text_field :picture_position, :class => 'text' %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :post_date, t('admin.post_date') %>
|
||||||
|
<%= f.date_select :post_date, :order => [:year, :month, :day], :use_month_numbers => true %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= f.label :unpost_date, t('admin.unpost_date') %>
|
||||||
|
<%= f.date_select :unpost_date, :order => [:year, :month, :day], :use_month_numbers => true %>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :context, t('admin.context') %>
|
||||||
|
<%= f.text_field :context, :class => 'text' %>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :direct_to_after_click, t('admin.direct_to_after_click') %>
|
||||||
|
<%= f.check_box :direct_to_after_click %>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<%= f.label :ad_images, t('admin.ad_images') %>
|
||||||
|
<ul>
|
||||||
|
<% @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 %>
|
||||||
|
</ul>
|
||||||
|
<%= render :partial => 'new_add_banner_file', :object => @ad_banner.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
|
||||||
|
<%#= render :partial => 'new_design_file', :object => @design.themes.build, :locals => { :field_name => "themes", :f => f, :classes => "r_destroy" } %>
|
||||||
|
</p>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<%= f.fields_for field_name, new_add_banner_file do |f| %>
|
||||||
|
<p class="new_file">
|
||||||
|
<%= f.file_field :file %>
|
||||||
|
<%= render :partial => "ad_image_form", :locals => { :f => f } %>
|
||||||
|
<%= button_tag '+', :class => "multi_files"%>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<div id="search">
|
||||||
|
<input id="user_search" name="user[username]" size="30" type="text" />
|
||||||
|
</div>
|
||||||
|
<div class="member_setup <%= @class %>">
|
||||||
|
<h1><%= t('admin.setup_member') %></h1>
|
||||||
|
<ul class="list">
|
||||||
|
<li class="set_1"><%= link_to content_tag(:span, t('admin.list_users')), admin_users_path %></li>
|
||||||
|
<li class="set_2"><%= link_to content_tag(:span, t('admin.list_roles')), admin_roles_path %></li>
|
||||||
|
<li class="set_3"><%= link_to content_tag(:span, t('admin.list_infos')), admin_infos_path %></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<h1><%= t('admin.editing_ad_banner') %></h1>
|
||||||
|
|
||||||
|
<%= 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 } %>
|
||||||
|
<p>
|
||||||
|
<%= f.submit t('update') %> <%= link_back %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<br /><br/>
|
|
@ -0,0 +1,46 @@
|
||||||
|
<% content_for :secondary do %>
|
||||||
|
<div class="ad_banners_setup">
|
||||||
|
<h1><%= t('admin.setup_ad_banners') %></h1>
|
||||||
|
<ul class="list">
|
||||||
|
<li><%= link_to content_tag(:span, t('admin.new_ad_banner')), new_admin_ad_banner_path, :class => 'seclink1' %></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
|
<%= flash_messages %>
|
||||||
|
<div class="main2">
|
||||||
|
<h1><%= t('admin.list_ad_banners') %></h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td><%= t('admin.title') %></td>
|
||||||
|
<td><%= t('admin.picture_position') %></td>
|
||||||
|
<td><%= t('admin.post_date') %></td>
|
||||||
|
<td><%= t('admin.unpost_date') %></td>
|
||||||
|
<td><%= t('admin.context') %></td>
|
||||||
|
<td><%= t('admin.direct_to_after_click') %></td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<% @ad_banners.each do |ad_banner| %>
|
||||||
|
<tr class="have">
|
||||||
|
<td><%= ad_banner.title %></td>
|
||||||
|
<td><%= ad_banner.picture_position %></td>
|
||||||
|
<td><%= ad_banner.post_date %></td>
|
||||||
|
<td><%= ad_banner.unpost_date %></td>
|
||||||
|
<td><%= ad_banner.context %></td>
|
||||||
|
<td><%= ad_banner.direct_to_after_click %></td>
|
||||||
|
<td class="action">
|
||||||
|
<%= 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' %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr></tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button_bar">
|
||||||
|
<%= link_to t('admin.new_ad_banner'), new_admin_ad_banner_path, :class => 'new' %>
|
||||||
|
</div>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<div class="main2">
|
||||||
|
<h1><%= t('admin.new_ad_banner') %></h1>
|
||||||
|
|
||||||
|
<%= form_for :ad_banner, :url => admin_ad_banners_path, :html => {:multipart => true} do |f| %>
|
||||||
|
<%= f.error_messages %>
|
||||||
|
<%= render :partial => "form", :locals => { :f => f } %>
|
||||||
|
|
||||||
|
<div class="button_bar">
|
||||||
|
<%= link_back %>
|
||||||
|
<%= f.submit t('create') %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<% content_for :secondary do %>
|
||||||
|
<%= render 'side_bar' %>
|
||||||
|
<% end %>
|
||||||
|
<br /><br /><br /><br />
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><%=t('admin.ad_banner.title') %> <%= @ad_banner.title %></li>
|
||||||
|
<li><%=t('admin.ad_banner.picture_position') %> <%= @ad_banner.picture_position %></li>
|
||||||
|
<li><%=t('admin.ad_banner.post_date') %> <%= @ad_banner.post_date %></li>
|
||||||
|
<li><%=t('admin.ad_banner.unpost_date') %> <%= @ad_banner.unpost_date %></li>
|
||||||
|
<li><%=t('admin.ad_banner.context') %> <%= @ad_banner.context %></li>
|
||||||
|
<li><%=t('admin.ad_banner.direct_to_after_click') %> <%= @ad_banner.direct_to_after_click %></li>
|
||||||
|
<li><%=t('admin.ad_banner.ad_style') %> <%= @ad_banner.ad_style %></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<%= render :partial => "admin/ad_banners/ad_image", :collection => @ad_banner.ad_images %>
|
||||||
|
|
Reference in New Issue