From befd3bcdec06a28ea51439b9297349c0cbd62764 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 16:42:43 +0800 Subject: [PATCH] AdBanner reopen new banner and delete. Rename title with content editable tag. --- .../javascripts/lib/contenteditable.js.erb | 41 +++++++++++++++++++ .../admin/ad_banners_controller.rb | 5 +++ app/helpers/application_helper.rb | 7 ++-- .../admin/ad_banners/_ad_banner_tab.html.erb | 2 + .../ad_banners/_modal_ad_banner_form.html.erb | 1 + .../admin/ad_banners/create_error_msg.js.erb | 2 +- app/views/admin/ad_banners/index.html.erb | 10 +++-- .../admin/ad_banners/new_created_node.js.erb | 8 +++- config/locales/zh_tw.yml | 6 ++- config/routes.rb | 2 + 10 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/lib/contenteditable.js.erb diff --git a/app/assets/javascripts/lib/contenteditable.js.erb b/app/assets/javascripts/lib/contenteditable.js.erb new file mode 100644 index 000000000..28dc91375 --- /dev/null +++ b/app/assets/javascripts/lib/contenteditable.js.erb @@ -0,0 +1,41 @@ +<%#= encoding: utf-8 %> +$(function() { + var content_holder, content; + var selector = 'li[contenteditable="true"]'; + // prevent clicks inside editable area to fire + // a click event on the body + // and therefor saving our content before we even edit it + $(selector).click(function(e) { + e.stopPropagation(); + }); + + // initialize the "save" function + $(selector).focus(function(e) { + content_holder = $(this); + content = content_holder.html(); + + // one click outside the editable area saves the content + $('body').one('click', function(e) { + // but not if the content didn't change + if ($(e.target).is(selector) || content == content_holder.html()) { + return; + } + + $.ajax({ + url: content_holder.data('edit-url'), + type: 'POST', + dataType: 'json', + data: { body: content_holder.html() }, + success: function(json) { + alert("<%= I18n.t("admin.contenteditable.update_done") %>"); + //content_holder.effect('highlight', {'color': '#0f0'}, 3000); + }, + error: function() { + alert("<%= I18n.t("admin.contenteditable.update_failed") %>"); + //content_holder.effect('highlight', {'color': '#f00'}, 3000); + content_holder.html(content); + } + }); + }); + }); +}); \ No newline at end of file diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 3457c4dec..347b9e889 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -4,6 +4,11 @@ class Admin::AdBannersController < OrbitBackendController before_filter :for_app_manager,:except => [:index,:show] before_filter :for_app_sub_manager + def rename + @ad_banner = AdBanner.find(params[:id]) + @ad_banner.title = Nokogiri::HTML.fragment(params["body"]).at("a").children().to_s + render :json => {:success =>@ad_banner.save!} + end def destroy @ad_banner = AdBanner.find(params[:id]) @ad_banner.destroy diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 64a6bf1df..59b45c270 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -172,11 +172,10 @@ module ApplicationHelper locale.to_sym == I18n.locale ? 'active in': '' end -<<<<<<< HEAD - def at_least_module_manager + def at_least_module_manager is_manager? || is_admin? - end -======= + end + def dislpay_view_count(object) "#{t(:view_count)}: #{object.view_count}" end diff --git a/app/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index 56fd09a1e..ca98e42e8 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -26,7 +26,9 @@ <% if at_least_module_manager %> <%= show_ad_banner_permission_link ad_banner_tab%> + <%= link_to t('admin.ad.delete_banner'),admin_ad_banner_path(ad_banner_tab),:class => 'btn',:method => :delete,:confirm => t('sure?') %> <% end -%> + <%#= render :partial => 'new_add_banner_file', :object => ad_banner_tab.ad_images.build, :locals => { :field_name => "new_ad_images[]", :f => f, :classes => "r_destroy" } %> <%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %> diff --git a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb index 4a3f2db44..cbc4de8e8 100644 --- a/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb +++ b/app/views/admin/ad_banners/_modal_ad_banner_form.html.erb @@ -30,6 +30,7 @@ diff --git a/app/views/admin/ad_banners/create_error_msg.js.erb b/app/views/admin/ad_banners/create_error_msg.js.erb index 60f1d261e..dbd013dfd 100644 --- a/app/views/admin/ad_banners/create_error_msg.js.erb +++ b/app/views/admin/ad_banners/create_error_msg.js.erb @@ -1 +1 @@ -alert("Error occures:<%= @ad_banner.errors.full_messages%>"); \ No newline at end of file +$("#ad_banner-modal-info").append("<%= @ad_banner.errors.full_messages.join(',')%>"); \ 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 c0e02ecc8..3e3b46895 100644 --- a/app/views/admin/ad_banners/index.html.erb +++ b/app/views/admin/ad_banners/index.html.erb @@ -4,21 +4,23 @@ <% content_for :page_specific_javascript do -%> <%= javascript_include_tag "/static/jquery.cycle.all.latest.js" %> <%= javascript_include_tag "inc/modal-preview" %> + <%= javascript_include_tag "lib/contenteditable" %> + <% end -%>
-
+
<%= render :partial => 'ad_banner_tab',:collection => @ad_banners %>
- <%#= render :partial => "modal_ad_banner_form"%> + <%= render :partial => "modal_ad_banner_form"%>
diff --git a/app/views/admin/ad_banners/new_created_node.js.erb b/app/views/admin/ad_banners/new_created_node.js.erb index 86970e6a3..a53135da6 100644 --- a/app/views/admin/ad_banners/new_created_node.js.erb +++ b/app/views/admin/ad_banners/new_created_node.js.erb @@ -1,8 +1,14 @@ $('<%= escape_javascript(content_tag(:li,link_to(@ad_banner.title,"##{@ad_banner.title}",:data=>{:toggle=>"tab"}))) %>').insertBefore("#new_ad_banner_tab_but"); -$('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertBefore($("#new-a-banner")); +$('<%= escape_javascript(render(:partial => "ad_banner_tab",:locals => {:ad_banner_tab => @ad_banner})) %>').insertAfter($("#ad_banner-tab-content").children(".tab-pane").last()); $('.modal').modal('hide'); +$("#ad_banner-modal-info").empty(); +$("#new-a-banner form").each(function(){this.reset();}); + $('#new-a-banner').unbind(); $('#post-body-content').find(".nav.nav-tabs").children('li.active').removeClass("active"); +$("#ad_banner-tab-content").children(".tab-pane").removeClass("active"); $('#post-body-content').find(".nav.nav-tabs").children('li[id!="new_ad_banner_tab_but"]').last().addClass("active"); +$("#ad_banner-tab-content").children(".tab-pane").last().addClass("active"); + diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 916631d97..01d06e0b5 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -82,8 +82,9 @@ zh_tw: sec_place_holder: 3秒請輸入3 ab_fx: 轉場特效 all_banners: 輪播清單 - cate_auth: 分類授權 banner_best_size: Banner 尺寸 + cate_auth: 分類授權 + delete_banner: 刪除整組輪播 new_banner: 新增輪播 new_image: 新增橫幅 showing: 顯示中 @@ -115,6 +116,9 @@ zh_tw: choose_file: 請選擇一個文件... class: 階級 content: 內容 + contenteditable: + update_done: 更新完成 + update_failed: 更新失敗 create_error_link: 新增連接時出錯。 create_error_page: 新增頁面時出錯。 create_success_home: 首頁已成功新增。 diff --git a/config/routes.rb b/config/routes.rb index 248623614..e1a6a1c75 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,8 @@ Orbit::Application.routes.draw do match 'ad_banners/:id/preview' => 'ad_banners#realtime_preview',:as => :realtime_preview_ad_banner,:via => :put + match 'ad_banners/:id/rename' => 'ad_banners#rename',:as => :rename_ad_banner,:via => :post + resources :ad_banners do collection do match 'new_ad_image' => 'ad_images#new',:as => :new_ad_image,:via => :get