diff --git a/app/assets/javascripts/ad_banner/banner_preview.js b/app/assets/javascripts/ad_banner/banner_preview.js index ca3ff01..69075aa 100644 --- a/app/assets/javascripts/ad_banner/banner_preview.js +++ b/app/assets/javascripts/ad_banner/banner_preview.js @@ -60,7 +60,7 @@ $(function() { bannerSpeed = null, bannerW = null, bannerH = null, - $preview = $('#pageslide .preview'); + $preview = $('.main-forms .preview'); $(".ad_banner_ad_fx").change(function () { var suckIE = false; diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index d00343f..395f6a4 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -2,56 +2,62 @@ class Admin::AdBannersController < OrbitAdminController before_action ->(module_app = @app_title) { set_variables module_app } def index + @table_fields = ["ad_banner.banner", :title, :category] + @categories = @module_app.categories.enabled + @filter_fields = filter_fields(@categories, []) + @filter_fields.delete(:status) + @filter_fields.delete(:tags) @banners = Banner.all - @categories = @module_app.categories.enabled.collect{|c|[c.title, c.id]} + .order_by(sort) + .with_categories(filters("category")) + + @banners = search_data(@banners,[:title]).page(params[:page]).per(6) + if request.xhr? + render :partial => "index_table" + end end def show - @ad_banners = Banner.all - @active = Banner.find(params[:id]) - render :action => 'index' + @banner = Banner.find(params[:id]) + @images = @banner.ad_images.desc(:created_at).page(params[:page]).per(10) + @table_fields = [:banner, :title, "ad_banner.duration", :link] end def new + user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false @ad_banner = Banner.new - render layout: false + render_401 if !user_has_rights end def create - @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 + ad_banner = Banner.new(banner_params) + ad_banner.save + redirect_to admin_ad_banners_url end def edit + user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false @ad_banner = Banner.find(params[:id]) - render layout: false + render_401 if !user_has_rights 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 + ad_banner = Banner.find(params[:id]) + ad_banner.update_attributes(banner_params) + redirect_to params[:referer_url] end def destroy - @ad_banner = Banner.find(params[:id]) - @ad_banner.destroy - redirect_to admin_ad_banners_url + ad_banner = Banner.find(params[:id]) + ad_banner.destroy + redirect_to admin_ad_banners_path(:page => params[:page]) end private # Never trust parameters from the scary internet, only allow the white list through. def banner_params - params.require(:ad_banner).permit! + params.require(:banner).permit! end end diff --git a/app/controllers/admin/ad_images_controller.rb b/app/controllers/admin/ad_images_controller.rb index 4639b1a..b590eb4 100644 --- a/app/controllers/admin/ad_images_controller.rb +++ b/app/controllers/admin/ad_images_controller.rb @@ -11,7 +11,7 @@ class Admin::AdImagesController < Admin::AdBannersController def edit @ad_image = AdImage.find(params[:id]) - if can_edit_or_delete?(@ad_image) + if can_edit_or_delete?(@ad_image.banner) @ad_banner = @ad_image.banner else render_401 @@ -19,41 +19,33 @@ class Admin::AdImagesController < Admin::AdBannersController end def update - @ad_image = AdImage.find(params[:id]) - if @ad_image.update_attributes(ad_image_params) - redirect_to params['referer_url'] - else - @ad_banners = Banner.all - @tags = @module_app.tags || [] - render action: :edit - end + ad_image = AdImage.find(params[:id]) + ad_image.update_attributes(ad_image_params) + redirect_to params[:referer_url] end def new @ad_image = AdImage.new - @ad_banner = Banner.find(params[:banner]) - @tags = @module_app.tags || [] - - @ad_image.postdate = Date.today + @ad_banner = Banner.find(params[:banner_id]) + if can_edit_or_delete?(@ad_banner) + @tags = @module_app.tags || [] + @ad_image.postdate = Date.today + else + render_401 + end end def create @ad_image = AdImage.new(ad_image_params) - if @ad_image.save - redirect_to params['referer_url'] - else - @ad_banners = Banner.all - @tags = @module_app.tags || [] - @ad_image = AdImage.new(ad_image_params) - render action: :new - end + @ad_image.save + redirect_to params[:referer_url] end def destroy - @ad_image = AdImage.find params[:id] - if @ad_image.destroy - redirect_to admin_ad_banners_url - end + ad_image = AdImage.find params[:id] + banner = ad_image.banner + ad_image.destroy + redirect_to admin_ad_banner_path(banner.id, :page => params[:page]) end private diff --git a/app/views/admin/ad_banners/_form.html.erb b/app/views/admin/ad_banners/_form.html.erb index 3c6ab08..ced0b6e 100644 --- a/app/views/admin/ad_banners/_form.html.erb +++ b/app/views/admin/ad_banners/_form.html.erb @@ -1,29 +1,96 @@ -<%#= flash_messages %> -<%#= f.error_messages %> +<% 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" %> + <%= javascript_include_tag "validator" %> + <%= javascript_include_tag "cycle2" %> + <%= javascript_include_tag "ad_banner/banner_preview" %> +<% end %> -<%= f.label :title, t('ad_banner.banner_name') %> -<%= f.text_field :title, class: 'input-large', placeholder: t('ad_banner.banner_name'), id: 'name' %> -<%= t('ad_banner.name_only_english') %> + + +
+ + + +
-<%= 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' %> -<%= t('ad_banner.number_seconds') %> - -<%= 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' %> -<%= t('ad_banner.number_milliseconds') %> - -<%= f.label :size, t('ad_banner.size') %> - -<%= f.number_field :base_image, in: 1..1, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;", id: 'base_image' %> - -<%= f.label :category_id, t('ad_banner.categories') %> -<%= f.select :category_id, @categories, {} %> - -<%= f.label :ad_fx, t('ad_banner.effect') %> -<%= f.select :ad_fx, Banner::FX_TYPES, {}, {class: 'ad_banner_ad_fx', id: 'ad_fx'} %> -

<%= t('ad_banner.no_ie_10_effect_support') %>

-
- <%= image_tag "slideshow_preview_A.png", width: "100%", height: 80 %> - <%= image_tag "slideshow_preview_B.png", width: "100%", height: 80 %> + +
+ +
+ <%= f.label :title, t('ad_banner.banner_name'), :class => "control-label muted" %> +
+ <%= f.text_field :title, class: 'input-large', placeholder: t('ad_banner.banner_name') %> + <%= t('ad_banner.name_only_english') %> +
+
+ +
+ <%= f.label :timeout, t('ad_banner.transition_interval'), :class => "control-label muted" %> +
+ <%= f.number_field :timeout, in: 0..60, step: 1, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" %> + <%= t('ad_banner.number_seconds') %> +
+
+ +
+ <%= f.label :speed, t('ad_banner.transition_speed'), :class => "control-label muted" %> +
+ <%= f.number_field :speed, in: 0..1000, step: 100, class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" %> + <%= t('ad_banner.number_milliseconds') %> +
+
+ +
+ <%= f.label :size, t('ad_banner.size'), :class => "control-label muted" %> +
+ <%= f.number_field :base_image, in: 1..(@ad_banner.new_record? ? 1 : (@ad_banner.ad_images.count == 0 ? 1 : @ad_banner.ad_images.count)), class: 'input-mini', onkeypress: "if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" %> +
+
+ +
+ +
+ <%= select_category(f, @module_app) %> +
+
+ +
+ <%= f.label :size, t('ad_banner.size'), :class => "control-label muted" %> +
+ <%= f.select :ad_fx, Banner::FX_TYPES, {}, {class: 'ad_banner_ad_fx', id: 'ad_fx'} %> +

<%= t('ad_banner.no_ie_10_effect_support') %>

+
+ <%= image_tag "slideshow_preview_A.png", width: "400", height: 80 %> + <%= image_tag "slideshow_preview_B.png", width: "400", height: 80 %> +
+
+
+
+
+
+ +
+ <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), admin_ad_banners_path(:page => params[:page]), :class=>"btn" %>
+ diff --git a/app/views/admin/ad_banners/_index.html.erb b/app/views/admin/ad_banners/_index.html.erb index a1631ec..d402b03 100644 --- a/app/views/admin/ad_banners/_index.html.erb +++ b/app/views/admin/ad_banners/_index.html.erb @@ -232,7 +232,7 @@
- <% if can_edit_or_delete?(banner) && current_user.is_admin? or current_user.is_manager?(@module_app) or current_user.is_sub_manager?(@module_app) %> + <% if can_edit_or_delete?(banner) %>
" data-id="<%= banner.id.to_s %>" diff --git a/app/views/admin/ad_banners/_index_table.html.erb b/app/views/admin/ad_banners/_index_table.html.erb new file mode 100644 index 0000000..b6a05ff --- /dev/null +++ b/app/views/admin/ad_banners/_index_table.html.erb @@ -0,0 +1,67 @@ +<% content_for :page_specific_css do %> + +<% end %> + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false %> + <% @banners.each do |banner| %> + + + + + + <% end %> + +
+
+ <% if !banner.ad_images.can_display.blank? %> + <% banner.ad_images.can_display.desc(:created_at).each do |image| %> +
+ <% end %> + <% else %> +
+
+ <% end %> + +
+
+ <%= banner.title rescue "" %> +
+ +
+
+ <%= banner.category.title rescue "" %> +
+
+<% if user_has_rights %> + +<% end %> + <%= content_tag :div, paginate(@banners), class: "pagination pagination-centered" %> +
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 0000000..e8adef8 --- /dev/null +++ b/app/views/admin/ad_banners/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @ad_banner, url: admin_ad_banner_path(@ad_banner), html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/ad_banners/index.html.erb b/app/views/admin/ad_banners/index.html.erb index e38bfa4..e41330f 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -3,52 +3,12 @@ <%= javascript_include_tag "cycle2" %> <%= javascript_include_tag "ad_banner/banner_preview" %> <% end %> - - - -<% if current_user.is_admin? or current_user.is_manager?(@module_app) %> -
- - -
- -
-
- - - - -
-
-
-
- <%= form_for :ad_banner, url: nil, remote: true do |f| %> -
- <%= render :partial => "form", :locals => { :f => f } %> -
- <%= t(:cancel) %> - <%= f.submit t(:submit), class: 'btn btn-primary btn-small' %> -
-
- <% end %> -
-
-
-
- -<% end %> - <%= render 'layouts/delete_modal', delete_options: @delete_options %> - +<%= render_filter @filter_fields, "index_table" %> + + <%= render 'index_table'%> + \ 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 0000000..04550d4 --- /dev/null +++ b/app/views/admin/ad_banners/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @ad_banner, url: admin_ad_banners_path, html: {class: "form-horizontal main-forms"} do |f| %> +
+ <%= render partial: 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file 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 0000000..07504c0 --- /dev/null +++ b/app/views/admin/ad_banners/show.html.erb @@ -0,0 +1,63 @@ +<% content_for :page_specific_css do %> + +<% end %> +

<%= @banner.title %>

+ + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @images.each do |image| %> + + + + + + + <% end %> + +
+ <%= image_tag image.file.thumb, :class => "banner-image" %> + + <%= image.title rescue "" %> + <% if can_edit_or_delete?(@banner) %> + + <% end %> + + <% if !image.postdate.nil? %> + <%= image.postdate.strftime("%Y-%m-%d %H:%M") rescue "" %> + <% if !image.deadline.nil? %> + ~ <%= image.deadline.strftime("%Y-%m-%d %H:%M") rescue "" %> + <% if image.expired? %> + <%= t("ad_banner.expired") %> + <% end %> + <% end %> + <% end %> + + <%= image.out_link rescue "" %> +
+ + <% if can_edit_or_delete?(@banner) %> +
+ + <%= content_tag :div, paginate(@images), class: "pagination pagination-centered" %> +
+ <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index e035701..5189b75 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -26,5 +26,6 @@ en: all: All categories: Categories add: Add + duration: Duration setting: Settings expired: Expired \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 82ad0f3..d6530f9 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -24,4 +24,5 @@ zh_tw: transition_interval: 轉換間隔 transition_speed: 轉換速度 type: 開啟方式 - expired: 已下架 \ No newline at end of file + expired: 已下架 + duration: Duration \ No newline at end of file