ad banner backend working

Conflicts:
	app/controllers/admin/ad_banners_controller.rb
	app/controllers/admin/ad_images_controller.rb
	lib/ad_banner/engine.rb
This commit is contained in:
Harry Bomrah 2014-05-09 16:42:23 +08:00
parent e4cf9d3ba9
commit 01219aa756
27 changed files with 611 additions and 85 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,82 @@
function slideshow (element, bannerEffect, bannerTime, bannerSpeed) {
element.cycle('destroy');
element.children('img').removeAttr('class');;
element.cycle({
fx: bannerEffect,
timeout: bannerTime,
speed: bannerSpeed,
});
};
function setSlideshow(element, data) {
$("#pageslide .ad_banner_ad_fx").children('option:selected').each(function(index, el) {
$(this).val() == 'flipHorz' || $(this).val() == 'flipVert' ? $('.suckIE').show() : $('.suckIE').hide();
});
slideshow(element, data['fx'], 2000, 1000);
}
function preview() {
$('.open-modal').on('click', function() {
var _data = $(this).data();
bannerName = _data.name;
bannerEffect = _data.fx;
bannerTime = _data.time;
bannerSpeed = _data.speed;
bannerW = _data.w;
bannerH = _data.h;
$('#preview').modal('show');
});
$('#preview').on('shown', function() {
$(this).attr('aria-labelledby', bannerName.toString()).find('h3').text(bannerName.toString())
if(bannerW > 500) {
var resize = 500/bannerW
bannerW = Math.floor(bannerW*resize);
bannerH = Math.floor(bannerH*resize);
console.log(bannerW)
};
if(bannerH > 300) {
var resize = 300/bannerH
bannerW = Math.floor(bannerW*resize);
bannerH = Math.floor(bannerH*resize);
}
slideshow($(this).find('.preview'), bannerEffect, bannerTime, bannerSpeed);
$(this).find('.preview').css({
'width': bannerW,
'height': bannerH
});
$(this).find('.preview img').css({
'width': '100%',
'height': '100%'
});
});
$('#preview').on('hidden', function() {
$(this).attr('aria-labelledby', '').find('h3').text('')
$(this).find('.preview').cycle('destroy');
$(this).find('.preview img').removeAttr('style');
});
};
$(function() {
var bannerName = null,
bannerEffect = null,
bannerTime = null,
bannerSpeed = null,
bannerW = null,
bannerH = null,
$preview = $('#pageslide .preview');
$(".ad_banner_ad_fx").change(function () {
var suckIE = false;
// bannerTime = $("#pageslide #timeout").val()*1000;
// bannerSpeed = $("#pageslide #speed").val()*1000;
bannerTime = parseInt(bannerTime) || 300;
bannerSpeed = parseInt(bannerSpeed) || 300;
$(this).children('option:selected').each(function(index, el) {
$(this).val() == 'flipHorz' || $(this).val() == 'flipVert' ? $('.suckIE').show() : $('.suckIE').hide();
});
slideshow($preview, $(this).val(), 2000, 1000);
});
preview();
});

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +1,21 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
$(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$("tr").removeClass("active");
pageslide.find('.preview').cycle('destroy');
});
$.pageslide.loadComplete(function(pageslide, item) {
$("tr").removeClass("active");
item.closest('tr').addClass('active');
if(item.data('id') == 'new') {
resetForm();
pageslide.find('form').attr('action', '/admin/ad_banners/');
pageslide.find('form').attr('method', 'post');
}
else {
setForm(item.data('form'));
pageslide.find('form').attr('action', '/admin/ad_banners/' + item.data('id'));
pageslide.find('form').attr('method', 'put');
}
setSlideshow(pageslide.find('.preview'), item.data());
});
})

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -0,0 +1,4 @@
//= require cycle2/jquery.cycle2.min.js
//= require cycle2/transition/jquery.cycle2.flip.min.js
//= require cycle2/transition/jquery.cycle2.scrollVert.min.js
//= require cycle2/transition/jquery.cycle2.tile.min.js

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
/* Plugin for Cycle2; Copyright (c) 2012 M. Alsup; v20130909 */
(function(e){"use strict";function t(t){return{preInit:function(e){e.slides.css(n)},transition:function(i,n,s,o,r){var l=i,c=e(n),a=e(s),d=l.speed/2;t.call(a,-90),a.css({display:"block","background-position":"-90px",opacity:1}),c.css("background-position","0px"),c.animate({backgroundPosition:90},{step:t,duration:d,easing:l.easeOut||l.easing,complete:function(){i.API.updateView(!1,!0),a.animate({backgroundPosition:0},{step:t,duration:d,easing:l.easeIn||l.easing,complete:r})}})}}}function i(t){return function(i){var n=e(this);n.css({"-webkit-transform":"rotate"+t+"("+i+"deg)","-moz-transform":"rotate"+t+"("+i+"deg)","-ms-transform":"rotate"+t+"("+i+"deg)","-o-transform":"rotate"+t+"("+i+"deg)",transform:"rotate"+t+"("+i+"deg)"})}}var n,s=document.createElement("div").style,o=e.fn.cycle.transitions,r=void 0!==s.transform||void 0!==s.MozTransform||void 0!==s.webkitTransform||void 0!==s.oTransform||void 0!==s.msTransform;r&&void 0!==s.msTransform&&(s.msTransform="rotateY(0deg)",s.msTransform||(r=!1)),r?(o.flipHorz=t(i("Y")),o.flipVert=t(i("X")),n={"-webkit-backface-visibility":"hidden","-moz-backface-visibility":"hidden","-o-backface-visibility":"hidden","backface-visibility":"hidden"}):(o.flipHorz=o.scrollHorz,o.flipVert=o.scrollVert||o.scrollHorz)})(jQuery);

View File

@ -0,0 +1,2 @@
/*! Plugin for Cycle2; Copyright (c) 2012 M. Alsup; ver: 20121120 */
(function(a){function b(a,b,c){if(a&&c.style.filter){b._filter=c.style.filter;try{c.style.removeAttribute("filter")}catch(d){}}else!a&&b._filter&&(c.style.filter=b._filter)}"use strict",a.extend(a.fn.cycle.transitions,{fade:{before:function(c,d,e,f){var g=c.API.getSlideOpts(c.nextSlide).slideCss||{};c.API.stackSlides(d,e,f),c.cssBefore=a.extend(g,{opacity:0,display:"block"}),c.animIn={opacity:1},c.animOut={opacity:0},b(!0,c,e)},after:function(a,c,d){b(!1,a,d)}},fadeout:{before:function(c,d,e,f){var g=c.API.getSlideOpts(c.nextSlide).slideCss||{};c.API.stackSlides(d,e,f),c.cssBefore=a.extend(g,{opacity:1,display:"block"}),c.animOut={opacity:0},b(!0,c,e)},after:function(a,c,d){b(!1,a,d)}}})})(jQuery);

View File

@ -0,0 +1,2 @@
/*! Plugin for Cycle2; Copyright (c) 2012 M. Alsup; ver: 20121120 */
(function(a){"use strict",a.fn.cycle.transitions.scrollVert={before:function(a,b,c,d){a.API.stackSlides(a,b,c,d);var e=a.container.css("overflow","hidden").height();a.cssBefore={top:d?-e:e,left:0,opacity:1,display:"block"},a.animIn={top:0},a.animOut={top:d?e:-e}}}})(jQuery);

View File

@ -0,0 +1,2 @@
/* Plugin for Cycle2; Copyright (c) 2012 M. Alsup; v20130721 */
(function(e){"use strict";e.fn.cycle.transitions.tileSlide=e.fn.cycle.transitions.tileBlind={before:function(t,i,n,s){t.API.stackSlides(i,n,s),e(i).show(),t.container.css("overflow","hidden"),t.tileDelay=t.tileDelay||"tileSlide"==t.fx?100:125,t.tileCount=t.tileCount||7,t.tileVertical=t.tileVertical!==!1,t.container.data("cycleTileInitialized")||(t.container.on("cycle-destroyed",e.proxy(this.onDestroy,t.API)),t.container.data("cycleTileInitialized",!0))},transition:function(t,i,n,s,o){function r(e){p.eq(e).animate(I,{duration:t.speed,easing:t.easing,complete:function(){(s?v-1===e:0===e)&&t._tileAniCallback()}}),setTimeout(function(){(s?v-1!==e:0!==e)&&r(s?e+1:e-1)},t.tileDelay)}t.slides.not(i).not(n).hide();var c,l,a,d,u,p=e(),f=e(i),y=e(n),v=t.tileCount,h=t.tileVertical,g=t.container.height(),m=t.container.width();h?(l=Math.floor(m/v),d=m-l*(v-1),a=u=g):(l=d=m,a=Math.floor(g/v),u=g-a*(v-1)),t.container.find(".cycle-tiles-container").remove();var I,A={left:0,top:0,overflow:"hidden",position:"absolute",margin:0,padding:0};I=h?"tileSlide"==t.fx?{top:g}:{width:0}:"tileSlide"==t.fx?{left:m}:{height:0};var S=e('<div class="cycle-tiles-container"></div>');S.css({zIndex:f.css("z-index"),overflow:"visible",position:"absolute",top:0,left:0,direction:"ltr"}),S.insertBefore(n);for(var x=0;v>x;x++)c=e("<div></div>").css(A).css({width:v-1===x?d:l,height:v-1===x?u:a,marginLeft:h?x*l:0,marginTop:h?0:x*a}).append(f.clone().css({position:"relative",maxWidth:"none",width:f.width(),margin:0,padding:0,marginLeft:h?-(x*l):0,marginTop:h?0:-(x*a)})),p=p.add(c);S.append(p),f.hide(),y.show().css("opacity",1),r(s?0:v-1),t._tileAniCallback=function(){y.show(),f.hide(),S.remove(),o()}},stopTransition:function(e){e.container.find("*").stop(!0,!0),e._tileAniCallback&&e._tileAniCallback()},onDestroy:function(){var e=this.opts();e.container.find(".cycle-tiles-container").remove()}}})(jQuery);

View File

@ -1,35 +1,56 @@
class Admin::AdBannersController < OrbitAdminController
def initialize
super
@app_title = "ad_banner"
def index
@banners = Banner.all.page(params[:page]).per(10)
@table_fields = ["Banner Name","Effect","Transition Interval","Transition Speed","Size","Preview"]
end
def index
@ad_banners = Banner.all
end
def show
@ad_banners = Banner.all
@ad_banners = Banner.all
@active = Banner.find(params[:id])
render :action => 'index'
end
def new
@ad_banner = Banner.new
@ad_banner = Banner.new
render layout: false
end
def create
@ad_banner = Banner.new(banner_params)
@ad_banner.save
render "index"
@ad_banner = Banner.new(banner_params)
if @ad_banner.save
redirect_to admin_ad_banners_url
else
@ad_banner = Banner.new(params[:ad_banner])
render :new
end
end
def edit
@ad_banner = Banner.find(params[:id])
render layout: false
end
def update
@ad_banner = Banner.find(params[:id])
if @ad_banner.update_attributes(banner_params)
redirect_to admin_ad_banners_url, :status => 303
else
render :edit
end
end
def destroy
@ad_banner = Banner.find(params[:id])
@ad_banner.destroy
redirect_to admin_ad_banners_url
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def banner_params
params.require(:banner).permit(:ad_fx, :height, :speed, :title, :timeout, :width)
params.require(:ad_banner).permit!
end
end

View File

@ -1,23 +1,66 @@
class Admin::AdImagesController < Admin::AdBannersController
def initialize
super
@app_title = "ad_banner"
end
def index
@ad_images = AdImage.all
@ad_images = AdImage.all.page(params[:page]).per(10)
@table_fields = ["Preview","Banner","Title","Start Date","End Date", "Link"]
end
def new
@ad_image = AdImage.new
@ad_banners = Banner.all
def edit
@ad_image = AdImage.find(params[:id])
@ad_banners = Banner.all
@tags = @module_app.tags || []
end
def update
@ad_image = AdImage.find(params[:id])
if @ad_image.update_attributes(ad_image_params)
redirect_to admin_ad_images_url
else
@ad_banners = Banner.all
@tags = @module_app.tags || []
render action: :edit
end
end
def new
@ad_image = AdImage.new
@ad_banners = Banner.all
@tags = @module_app.tags || []
@ad_image.postdate = Date.today
@ad_image.deadline = Date.today + 30
end
def create
@ad_image = AdImage.new(ad_image_params)
@ad_image.save
redirect_to admin_ad_images_path
@ad_image = AdImage.new(ad_image_params)
if @ad_image.save
redirect_to admin_ad_images_url
else
@ad_banners = Banner.all
@tags = @module_app.tags || []
@ad_image = AdImage.new(ad_image_params)
render action: :new
end
end
def destroy
@ad_image = AdImage.find params[:id]
if @ad_image.destroy
redirect_to admin_ad_images_url
end
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def ad_image_params
params.require(:ad_image).permit(:weight, :out_link, :link_open, :file, :file_cache, :banner_id, title_translations: [:en, :zh_tw], context_translations: [:en, :zh_tw])
params.require(:ad_image).permit!
end
def setup_vars
@module_app = ModuleApp.where(:key => "ad_banner").first
end
end

View File

@ -11,6 +11,8 @@ class AdImage
field :weight, type: Integer, default: 1
field :out_link, type: String
field :link_open, type: String
field :postdate , :type => DateTime, :default => Time.now
field :deadline , :type => DateTime
LINK_OPEN_TYPES = ["local", "new_window"]
belongs_to :banner

View File

@ -25,4 +25,12 @@ class Banner
def timeout_millisecond
self.timeout*1000 rescue 0
end
def preview_link
"<a data-w='#{self.width}' data-time='#{self.timeout_millisecond}' data-speed='#{self.speed}' data-name='#{self.title}' data-h='#{self.height}' data-fx='#{self.ad_fx}' class='btn btn-success open-modal' href='#'>Preview</a>".html_safe
end
def data_attribute_hash
{'width'=> self.width,'height'=> self.height,'ad_fx'=> self.ad_fx,'name'=>self.title,'timeout'=>self.timeout,'speed'=>self.speed}.to_json
end
end

View File

@ -0,0 +1,28 @@
<%#= flash_messages %>
<%#= f.error_messages %>
<%= f.label :title, t('ad_banner.banner_name') %>
<%= f.text_field :title, class: 'input-large', placeholder: t('ad_banner.banner_name'), id: 'name' %>
<span class="help-block"><%= t('ad_banner.name_only_english') %></span>
<%= f.label :timeout, t('ad_banner.transition_interval') %>
<%= f.number_field :timeout, in: 0..60, step: 1, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'timeout' %>
<span class="help-block"><%= t('ad_banner.number_seconds') %></span>
<%= f.label :speed, t('ad_banner.transition_speed') %>
<%= f.number_field :speed, in: 0..1000, step: 100, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'speed' %>
<span class="help-block"><%= t('ad_banner.number_milliseconds') %></span>
<%= f.label :size, t('ad_banner.size') %>
<span class="banner_set">W</span>
<%= f.number_field :width, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'width' %>
<span class="banner_set">H</span>
<%= f.number_field :height, in: 10..1000, step: 10, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'height' %>
<%= f.label :ad_fx, t('ad_banner.effect') %>
<%= f.select :ad_fx, Banner::FX_TYPES, {}, {class: 'ad_banner_ad_fx', id: 'ad_fx'} %>
<p class="suckIE hide"><i class="icons-warning"></i> <%= t('ad_banner.no_ie_10_effect_support') %></p>
<div class="preview">
<%= image_tag "slideshow_preview_A.png", width: 200, height: 80 %>
<%= image_tag "slideshow_preview_B.png", width: 200, height: 80 %>
</div>

View File

@ -0,0 +1,33 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @banners.each do |banner| %>
<tr>
<td>
<%= banner.title %>
<div class="quick-edit">
<ul class="nav nav-pills">
<li>
<a data-title="Edit Banner" data-id="<%= banner.id.to_s %>" data-fx="<%= banner.ad_fx %>" data-form="<%= banner.data_attribute_hash.to_s %>" class="open-slide" href="#">Edit</a>
</li>
<li>
<a href="/admin/ad_banners/<%= banner.id.to_s %>" data-method="delete" data-confirm="Are you sure?" ><%= t(:delete_) %></a>
</li>
</ul>
</div>
</td>
<td><%= banner.ad_fx %></td>
<td><%= banner.timeout %></td>
<td><%= banner.speed %></td>
<td><%= banner.size %></td>
<td><%= banner.preview_link %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -1,8 +1,54 @@
<% @ad_banners.each do |a|%>
<%= a.title %>
<%= a.ad_fx %>
<%= a.height %>
<%= a.width %>
<%= a.speed %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "cycle2" %>
<%= javascript_include_tag "ad_banner/banner_preview" %>
<% end %>
<div id="banner_index">
<%= render 'index' %>
</div>
<div class="bottomnav clearfix" style="left: 81px;">
<div class="action pull-right">
<a data-title="New Banner" data-id="new" data-fx="fade" class="btn btn-primary open-slide" href="#">
<i class="icon-plus"></i> Add
</a>
</div>
<div class="pagination pagination-centered"></div>
</div>
<div id="preview" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="ModalLabel"><%= t(:preview) %></h3>
</div>
<div class="modal-body">
<div class="preview">
<%= image_tag "slideshow_preview_A.png", class: 'hide' %>
<%= image_tag "slideshow_preview_B.png", class: 'hide' %>
</div>
</div>
<div class="modal-footer">
</div>
</div>
<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :ad_banner, url: nil, remote: true do |f| %>
<fieldset>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small' %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,4 @@
$("#banner_index").html("<%= j render 'index' %>")
$.pageslide.close();
openSlide();
preview();

View File

@ -1,15 +0,0 @@
<%= form_for(@ad_banner, url: {action: "create"}) do |f| %>
Title <%= f.text_field :title %>
Timeout <%= f.text_field :timeout %>
Width <%= f.text_field :width %>
Height <%= f.text_field :height %>
Speed <%= f.text_field :speed %>
Ad Fx <%= f.text_field :ad_fx %>
<%= f.submit "Create Banner" %>
<% end %>

View File

@ -0,0 +1,216 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<%#= f.error_messages %>
<!-- Input Area -->
<div class="input-area">
<!-- Module Tabs -->
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li class="active">
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
</li>
<li>
<a href="#tag" data-toggle="tab"><%= t(:tags) %></a>
</li>
<li>
<a href="#type" data-toggle="tab"><%= t('ad_banner.type') %></a>
</li>
<li>
<a href="#frequency" data-toggle="tab"><%= t(:frequency) %></a>
</li>
<li>
<a href="#link" data-toggle="tab"><%= t(:link) %></a>
</li>
<li>
<a href="#imageupload" data-toggle="tab"><%= t(:image) %></a>
</li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<!-- Category -->
<div class="control-group">
<label class="control-label muted"><%= t('ad_banner.banner') %></label>
<div class="controls">
<%= f.select :banner_id, @ad_banners.collect{|t| [ t.title, t.id ]} %>
</div>
</div>
<!-- Date Time Picker -->
<div class="control-group">
<label class="control-label muted"><%= t(:start_date) %></label>
<div class="controls">
<%= f.datetime_picker :postdate, :no_label => true %>
</div>
</div>
<!-- Date Time Picker -->
<div class="control-group">
<label class="control-label muted"><%= t(:end_date) %></label>
<div class="controls">
<%= f.datetime_picker :deadline, :no_label => true %>
</div>
</div>
</div>
<!-- Tag Module -->
<div class="tab-pane fade" id="tag">
<!-- Tag -->
<div class="control-group">
<label class="control-label muted"><%= t(:tags) %></label>
<div class="controls" data-toggle="buttons-checkbox">
<% @tags.each do |tag| %>
<label class="checkbox inline btn <%= 'active' if @ad_image.tag_ids.include?(tag.id) %>">
<%= check_box_tag 'ad_image[tag_ids][]', tag.id, @ad_image.tag_ids.include?(tag.id) %> <%= tag.name %>
<%= hidden_field_tag 'ad_image[tag_ids][]', '' %>
</label>
<% end %>
</div>
</div>
</div>
<!-- Type Module -->
<div class="tab-pane fade" id="type">
<!-- Type -->
<div class="control-group">
<label class="control-label muted"><%= t('ad_banner.type') %></label>
<div class="controls">
<%= f.select :link_open, AdImage::LINK_OPEN_TYPES.map{|a| [t("ad_banner.#{a}"), a]} %>
</div>
</div>
</div>
<!-- Frequency Module -->
<div class="tab-pane fade" id="frequency">
<!-- Frequency -->
<div class="control-group">
<label class="control-label muted"><%= t(:frequency) %></label>
<div class="controls">
<%= f.number_field :weight, placeholder: t(:frequency), in: 1..99, maxlength: 2, onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" %>
<span class="help-block"><%= t('ad_banner.enter_number') %></span>
</div>
</div>
</div>
<!-- Link Module -->
<div class="tab-pane fade" id="link">
<!-- Link -->
<div class="control-group">
<label class="control-label muted"><%= t(:link) %></label>
<div class="controls">
<%= f.text_field :out_link, placeholder: t(:url) %>
<span class="help-block"><%= t('ad_banner.enter_url') %></span>
</div>
</div>
</div>
<!-- Images Module -->
<div class="tab-pane fade" id="imageupload">
<!-- Images Upload -->
<div class="control-group">
<label class="control-label muted"><%= t(:image) %></label>
<div class="controls">
<div class="fileupload fileupload-new clearfix <%= 'fileupload-edit' if @ad_image.file.file %>" data-provides="fileupload">
<div class="fileupload-new thumbnail pull-left">
<% if @ad_image.file.file %>
<%= image_tag @ad_image.file %>
<% else %>
<img src="http://www.placehold.it/50x50/EFEFEF/AAAAAA" />
<% end %>
</div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
<span class="btn btn-file">
<span class="fileupload-new"><%= t(:select_image) %></span>
<span class="fileupload-exists"><%= t(:change) %></span>
<%= f.file_field :file %>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
<div class="controls" data-toggle="buttons-checkbox">
<label class="checkbox inline btn btn-danger fileupload-remove">
<%= f.check_box :remove_file %><%= t(:remove) %>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Language Tabs -->
<div class="nav-name"><strong><%= t(:language) %></strong></div>
<ul class="nav nav-pills language-nav">
<% I18n.available_locales.each_with_index do |locale, i| %>
<li class="<%= 'active' if i == 0 %>">
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale.to_s) %></a>
</li>
<% end %>
</ul>
<!-- Language -->
<div class="tab-content language-area">
<% I18n.available_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<!-- Title-->
<div class="control-group input-title">
<label class="control-label muted"><%= t(:title) %></label>
<div class="controls">
<%= f.fields_for :title_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@ad_image.title_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
<!-- Content -->
<div class="control-group input-content">
<label class="control-label muted"><%= t(:content) %></label>
<div class="controls">
<div class="textarea">
<%= f.fields_for :context_translations do |f| %>
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@ad_image.context_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
</div>

View File

@ -0,0 +1,5 @@
<%= form_for @ad_image, url: admin_ad_image_path(@ad_image), html: {class: "form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render partial: 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -1,5 +1,33 @@
<% @ad_images.each do |a|%>
<%= a.title %>
<%= a.banner.title%>
<%=image_tag(a.file.url(:thumb))%>
<% end %>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @ad_images.each do |image| %>
<tr>
<td><img src="<%= image.file.thumb.url %>" /></td>
<td><%= image.banner.title %></td>
<td>
<%= image.title %>
<div class="quick-edit">
<ul class="nav nav-pills">
<li>
<a href="/<%= I18n.locale %>/admin/ad_images/<%= image.id.to_s %>/edit"><%= t(:edit) %></a>
</li>
<li>
<a class="text-error" href="/<%= I18n.locale %>/admin/ad_images/<%= image.id.to_s %>" data-method="delete" data-confirm="Are you sure?"><%= t(:delete_) %></a>
</li>
</ul>
</div>
</td>
<td><%= format_value image.postdate %></td>
<td><%= format_value image.deadline %></td>
<td><%= image.out_link rescue "&nbsp;" %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -1,24 +1,5 @@
<%= form_for(@ad_image, url: {action: "create"}) do |f| %>
<% I18n.available_locales.each do |locale| %>
Title <%= locale.to_s %>:
<%= f.fields_for :title_translations do |n| %>
<%= n.text_field locale %>
<% end %>
Context <%= locale.to_s %>:
<%= f.fields_for :context_translations do |n| %>
<%= n.text_area locale %>
<% end %>
<% end %>
<p>
<label>Image</label>
<%= image_tag(@ad_image.file_url) if @ad_image.file? %>
<%= f.file_field :file %>
<%= f.hidden_field :file_cache %>
</p>
<%= f.select :banner_id, @ad_banners.collect{|t| [ t.title, t.id ]} %>
<%= f.submit "Create Banner Image" %>
<%= form_for @ad_image, url: admin_ad_images_path, html: {class: "form-horizontal main-forms"} do |f| %>
<fieldset>
<%= render partial: 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -13,23 +13,23 @@ module AdBanner
side_bar do
head_label_i18n 'ad_banner.ad_banner', icon_class: "icons-landscape"
available_for [:admin,:manager,:sub_manager]
active_for_controllers ({:private=>['ad_banner']})
active_for_controllers (['admin/ad_banners','admin/ad_images'])
head_link_path "admin_ad_banners_path"
context_link 'ad_banner.all',
:link_path=>"admin_ad_images_path" ,
:priority=>1,
:active_for_action=>{'admin/ad_banners'=>:index}
:active_for_action=>{'admin/ad_images'=>"index"}
context_link 'ad_banner.add',
:link_path=>"new_admin_ad_image_path" ,
:priority=>1,
:active_for_action=>{'admin/ad_banners'=>:index}
:active_for_action=>{'admin/ad_images'=>"new"}
context_link 'ad_banner.banner',
:link_path=>"admin_ad_banners_path" ,
:priority=>3,
:active_for_action=>{'admin/ad_banners'=>:index}
:active_for_action=>{'admin/ad_banners'=>"index"}
end
end
end