aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/refinery/banners/admin/banners_controller.rb12
-rw-r--r--app/controllers/refinery/banners/banners_controller.rb34
-rw-r--r--app/models/refinery/banners/banner.rb27
-rw-r--r--app/views/refinery/banners/admin/banners/_actions.html.erb25
-rw-r--r--app/views/refinery/banners/admin/banners/_banner.html.erb20
-rw-r--r--app/views/refinery/banners/admin/banners/_banners.html.erb2
-rw-r--r--app/views/refinery/banners/admin/banners/_form.html.erb74
-rw-r--r--app/views/refinery/banners/admin/banners/_records.html.erb18
-rw-r--r--app/views/refinery/banners/admin/banners/_sortable_list.html.erb5
-rw-r--r--app/views/refinery/banners/admin/banners/edit.html.erb1
-rw-r--r--app/views/refinery/banners/admin/banners/index.html.erb7
-rw-r--r--app/views/refinery/banners/admin/banners/new.html.erb1
-rw-r--r--app/views/refinery/banners/shared/_banner_image.html.erb1
-rw-r--r--app/views/refinery/banners/shared/_banners.html.erb9
14 files changed, 236 insertions, 0 deletions
diff --git a/app/controllers/refinery/banners/admin/banners_controller.rb b/app/controllers/refinery/banners/admin/banners_controller.rb
new file mode 100644
index 0000000..1992bcf
--- /dev/null
+++ b/app/controllers/refinery/banners/admin/banners_controller.rb
@@ -0,0 +1,12 @@
+module Refinery
+ module Banners
+ module Admin
+ class BannersController < ::Refinery::AdminController
+
+ crudify :'refinery/banners/banner',
+ :title_attribute => 'name', :xhr_paging => true
+
+ end
+ end
+ end
+end
diff --git a/app/controllers/refinery/banners/banners_controller.rb b/app/controllers/refinery/banners/banners_controller.rb
new file mode 100644
index 0000000..5ada5e0
--- /dev/null
+++ b/app/controllers/refinery/banners/banners_controller.rb
@@ -0,0 +1,34 @@
+module Refinery
+ module Banners
+ class BannersController < ::ApplicationController
+
+ before_filter :find_all_banners
+ before_filter :find_page
+
+ def index
+ # you can use meta fields from your model instead (e.g. browser_title)
+ # by swapping @page for @banner in the line below:
+ present(@page)
+ end
+
+ def show
+ @banner = Banner.find(params[:id])
+
+ # you can use meta fields from your model instead (e.g. browser_title)
+ # by swapping @page for @banner in the line below:
+ present(@page)
+ end
+
+ protected
+
+ def find_all_banners
+ @banners = Banner.order('position ASC')
+ end
+
+ def find_page
+ @page = ::Refinery::Page.where(:link_url => "/banners").first
+ end
+
+ end
+ end
+end
diff --git a/app/models/refinery/banners/banner.rb b/app/models/refinery/banners/banner.rb
new file mode 100644
index 0000000..eaa1713
--- /dev/null
+++ b/app/models/refinery/banners/banner.rb
@@ -0,0 +1,27 @@
+module Refinery
+ module Banners
+ class Banner < Refinery::Core::BaseModel
+ self.table_name = 'refinery_banners'
+
+ acts_as_indexed :fields => [:name, :url, :title, :description]
+
+ validates :name, :presence => true
+ validates_presence_of :start_date
+ validates_length_of :title, :in => 0..255, :allow_nil => true
+ validates_length_of :description, :in => 0..255, :allow_nil => true
+
+ belongs_to :image, :class_name => '::Refinery::Image'
+ has_and_belongs_to_many :pages, :class_name => '::Refinery::Page', :join_table => 'refinery_banners_pages'
+
+ scope :not_expired, lambda {
+ banners = Arel::Table.new(::Refinery::Banners::Banner.table_name)
+ where(banners[:expiry_date].eq(nil).or(banners[:expiry_date].gt(Time.now)))
+ }
+ scope :active, where(:is_active => true)
+ scope :published, lambda {
+ not_expired.active.where("start_date <= ?", Time.now).order(:position)
+ }
+
+ end
+ end
+end \ No newline at end of file
diff --git a/app/views/refinery/banners/admin/banners/_actions.html.erb b/app/views/refinery/banners/admin/banners/_actions.html.erb
new file mode 100644
index 0000000..f2a1681
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/_actions.html.erb
@@ -0,0 +1,25 @@
+<ul>
+ <% if ::Refinery::Banners::Admin::BannersController.searchable? %>
+ <li>
+ <%= render '/refinery/admin/search', :url => refinery.banners_admin_banners_path %>
+ </li>
+ <% end %>
+ <li>
+ <%= link_to t('.create_new'), refinery.new_banners_admin_banner_path,
+ :class => "add_icon" %>
+ </li>
+<% if !searching? && ::Refinery::Banners::Admin::BannersController.sortable? && ::Refinery::Banners::Banner.any? %>
+ <li>
+ <%= link_to t('.reorder', :what => "Banners"),
+ refinery.banners_admin_banners_path,
+ :id => "reorder_action",
+ :class => "reorder_icon" %>
+
+ <%= link_to t('.reorder_done', :what => "Banners"),
+ refinery.banners_admin_banners_path,
+ :id => "reorder_action_done",
+ :style => "display: none;",
+ :class => "reorder_icon" %>
+ </li>
+<% end %>
+</ul>
diff --git a/app/views/refinery/banners/admin/banners/_banner.html.erb b/app/views/refinery/banners/admin/banners/_banner.html.erb
new file mode 100644
index 0000000..9a362a2
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/_banner.html.erb
@@ -0,0 +1,20 @@
+<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(banner) -%>">
+ <span class='title'>
+ <%= banner.name %>
+
+ </span>
+ <span class='actions'>
+
+ <%= link_to refinery_icon_tag("application_go.png"), refinery.banners_banner_path(banner),
+ :title => t('.view_live_html'),
+ :target => "_blank" %>
+
+ <%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_banners_admin_banner_path(banner),
+ :title => t('.edit') %>
+ <%= link_to refinery_icon_tag("delete.png"), refinery.banners_admin_banner_path(banner),
+ :class => "cancel confirm-delete",
+ :title => t('.delete'),
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => banner.name),
+ :method => :delete %>
+ </span>
+</li>
diff --git a/app/views/refinery/banners/admin/banners/_banners.html.erb b/app/views/refinery/banners/admin/banners/_banners.html.erb
new file mode 100644
index 0000000..0027493
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/_banners.html.erb
@@ -0,0 +1,2 @@
+<%= will_paginate @banners if Refinery::Banners::Admin::BannersController.pageable? %>
+<%= render 'sortable_list' %>
diff --git a/app/views/refinery/banners/admin/banners/_form.html.erb b/app/views/refinery/banners/admin/banners/_form.html.erb
new file mode 100644
index 0000000..2cd827f
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/_form.html.erb
@@ -0,0 +1,74 @@
+<%= form_for [refinery, :banners_admin, @banner] do |f| -%>
+ <%= render '/refinery/admin/error_messages',
+ :object => @banner,
+ :include_object_name => true %>
+
+ <%= hidden_field_tag 'banner[page_ids][]' %>
+
+ <div class='field'>
+ <%= f.label :name -%>
+ <%= f.text_field :name, :class => 'larger widest' -%>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :title -%>
+ <%= f.text_field :title -%>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :description -%>
+ <%= f.text_field :description -%>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :image -%>
+ <%= render '/refinery/admin/image_picker',
+ :f => f,
+ :field => :image_id,
+ :image => @banner.image,
+ :toggle_image_display => false %>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :url -%>
+ <%= f.text_field :url -%>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :is_active -%>
+ <%= f.check_box :is_active, :checked => @banner[:is_active] -%>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :start_date -%>
+ <%= f.date_select :start_date -%>
+
+ </div>
+
+ <div class='field'>
+ <%= f.label :expiry_date -%>
+ <%= f.date_select :expiry_date -%>
+
+ </div>
+
+ <div class="field">
+ <%= f.label :pages %>
+ <% Refinery::Page.all.each do |page| %>
+ <div>
+ <%= check_box_tag "banner[page_ids][]", page.id, @banner.pages.include?(page) %>
+ <%= page.title %>
+ </div>
+ <% end %>
+ </div>
+
+ <%= render '/refinery/admin/form_actions', :f => f,
+ :continue_editing => false,
+ :delete_title => t('delete', :scope => 'refinery.banners.admin.banners.banner'),
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @banner.name) %>
+<% end -%>
diff --git a/app/views/refinery/banners/admin/banners/_records.html.erb b/app/views/refinery/banners/admin/banners/_records.html.erb
new file mode 100644
index 0000000..109fb04
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/_records.html.erb
@@ -0,0 +1,18 @@
+<% if searching? %>
+ <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
+<% end %>
+<div class='pagination_container'>
+ <% if @banners.any? %>
+ <%= render 'banners' %>
+ <% else %>
+ <p>
+ <% unless searching? %>
+ <strong>
+ <%= t('.no_items_yet') %>
+ </strong>
+ <% else %>
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
+ <% end %>
+ </p>
+ <% end %>
+</div>
diff --git a/app/views/refinery/banners/admin/banners/_sortable_list.html.erb b/app/views/refinery/banners/admin/banners/_sortable_list.html.erb
new file mode 100644
index 0000000..0a0aac1
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/_sortable_list.html.erb
@@ -0,0 +1,5 @@
+<ul id='sortable_list'>
+ <%= render :partial => 'banner', :collection => @banners %>
+</ul>
+<%= render '/refinery/admin/sortable_list',
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
diff --git a/app/views/refinery/banners/admin/banners/edit.html.erb b/app/views/refinery/banners/admin/banners/edit.html.erb
new file mode 100644
index 0000000..2d34363
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/edit.html.erb
@@ -0,0 +1 @@
+<%= render 'form' %>
diff --git a/app/views/refinery/banners/admin/banners/index.html.erb b/app/views/refinery/banners/admin/banners/index.html.erb
new file mode 100644
index 0000000..5413e3c
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/index.html.erb
@@ -0,0 +1,7 @@
+<section id='records'>
+ <%= render 'records' %>
+</section>
+<aside id='actions'>
+ <%= render 'actions' %>
+</aside>
+<%= render '/refinery/admin/make_sortable', :tree => false if !searching? and ::Refinery::Banners::Admin::BannersController.sortable? and ::Refinery::Banners::Banner.count > 1 %>
diff --git a/app/views/refinery/banners/admin/banners/new.html.erb b/app/views/refinery/banners/admin/banners/new.html.erb
new file mode 100644
index 0000000..2d34363
--- /dev/null
+++ b/app/views/refinery/banners/admin/banners/new.html.erb
@@ -0,0 +1 @@
+<%= render 'form' %>
diff --git a/app/views/refinery/banners/shared/_banner_image.html.erb b/app/views/refinery/banners/shared/_banner_image.html.erb
new file mode 100644
index 0000000..74eebb4
--- /dev/null
+++ b/app/views/refinery/banners/shared/_banner_image.html.erb
@@ -0,0 +1 @@
+<%= image_fu(banner_image.image, '960x310#c') %> \ No newline at end of file
diff --git a/app/views/refinery/banners/shared/_banners.html.erb b/app/views/refinery/banners/shared/_banners.html.erb
new file mode 100644
index 0000000..d436cc7
--- /dev/null
+++ b/app/views/refinery/banners/shared/_banners.html.erb
@@ -0,0 +1,9 @@
+<div id="slider">
+ <% if @page.present? and @page.banners.published.present? %>
+ <%= render :partial => 'refinery/banners/shared/banner_image', :collection => @page.banners.published %>
+ <% elsif @banners.present? then %>
+ <%= render :partial => 'refinery/banners/shared/banner_image', :collection => @banners %>
+ <% else %>
+ <!--todo: insert static images here-->
+ <% end %>
+</div> \ No newline at end of file