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 -%>