diff --git a/app/assets/javascripts/lib/contenteditable.js.erb b/app/assets/javascripts/lib/contenteditable.js.erb new file mode 100644 index 00000000..28dc9137 --- /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 3457c4de..347b9e88 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/views/admin/ad_banners/_ad_banner_tab.html.erb b/app/views/admin/ad_banners/_ad_banner_tab.html.erb index 56fd09a1..ca98e42e 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 4a3f2db4..cbc4de8e 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 60f1d261..dbd013df 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 c0e02ecc..3e3b4689 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 86970e6a..a53135da 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 3ad7ee1b..24af77b1 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -84,8 +84,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: 顯示中 @@ -118,6 +119,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 ef2c46e2..6faccb27 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,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