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') %> +

    + <%= 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') %>

    + +
    \ 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') %>

    + +
    +<% end -%> + +<%= flash_messages %> +
    +

    <%= t('admin.list_ad_banners') %>

    + + + + + + + + + + + + +<% @ad_banners.each do |ad_banner| %> + + + + + + + + + + +<% end %> +
    <%= 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_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' %> +
    +
    + +
    + <%= 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 %> +



    + + + + <%= render :partial => "admin/ad_banners/ad_image", :collection => @ad_banner.ad_images %> +