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 47d3d355..347b9e88 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -1,8 +1,14 @@ class Admin::AdBannersController < OrbitBackendController layout "new_admin" before_filter :authenticate_user! - before_filter :for_app_manager + 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/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 52292588..404ac693 100644 --- a/app/controllers/admin/module_apps_new_interface_controller.rb +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -1,4 +1,4 @@ -class Admin::ModuleAppsNewInterfaceController < ApplicationController +class Admin::ModuleAppsNewInterfaceController < OrbitBackendController before_filter :authenticate_user! before_filter :is_admin? include AdminHelper @@ -25,9 +25,9 @@ class Admin::ModuleAppsNewInterfaceController < ApplicationController def update_setting module_app = update_setting_by_params if module_app.save! - flash[:notice] = "Update Done" + flash[:notice] = t("admin.object_auth.update_done") else - flash[:notice] = "Update Failed" + flash[:notice] = t("admin.object_auth.update_failed") end end @@ -37,8 +37,9 @@ class Admin::ModuleAppsNewInterfaceController < ApplicationController protected def update_setting_by_params + user_sat = [] ma = ModuleApp.find params[:module_app][:id] - user_sat = User.find params[:users].keys + user_sat = User.find params[:users].keys if params.has_key? :users users_to_new = user_sat - ma.managing_users users_to_remove = ma.managing_users - user_sat diff --git a/app/controllers/admin/object_auths_new_interface_controller.rb b/app/controllers/admin/object_auths_new_interface_controller.rb index 6018413b..bc546ac8 100644 --- a/app/controllers/admin/object_auths_new_interface_controller.rb +++ b/app/controllers/admin/object_auths_new_interface_controller.rb @@ -1,6 +1,5 @@ class Admin::ObjectAuthsNewInterfaceController < OrbitBackendController include OrbitCoreLib::PermissionUnility - before_filter :force_order diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index cfa46847..98882ec3 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -1,6 +1,8 @@ class OrbitBackendController< ApplicationController before_filter :force_order,:except => [:public] before_filter :setup_vars + before_filter :set_current_user + # before_filter {|c| c.front_end_available(@app_title)} # before_filter :check_user_can_use include OrbitCoreLib::PermissionUnility @@ -11,6 +13,7 @@ class OrbitBackendController< ApplicationController def setup_vars @app_title = request.fullpath.split('/')[2] @app_title = request.fullpath.split('/')[1] if(@app_title == "back_end") + @app_title.gsub!(/[?].*/,'') @module_app = ModuleApp.first(conditions: {:key => @app_title} ) end diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index eff12427..ecba9b3b 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -11,6 +11,21 @@ module Admin::AdBannerHelper printable_ad_images.shuffle! end - + def sub_manager?(ad_banner) + ad_banner.authed_users(:edit).include?(current_user) + end + + def show_ad_banner_permission_link(ad_banner) + type = 'edit' + oa = ad_banner.get_object_auth_by_title(type) + if oa.nil? + ad_banner.object_auths.new(title: type ).save + oa = ad_banner.get_object_auth_by_title(type) + end +# link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa) + link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa),:class => "btn btn-warning" + end + + end \ No newline at end of file diff --git a/app/helpers/admin/web_link_helper.rb b/app/helpers/admin/web_link_helper.rb new file mode 100644 index 00000000..813bc48c --- /dev/null +++ b/app/helpers/admin/web_link_helper.rb @@ -0,0 +1,11 @@ +module Admin::WebLinkHelper + def show_web_link_permission_link(web_link) + type = 'edit' + oa = web_link.get_object_auth_by_title(type) + if oa.nil? + web_link.object_auths.new(title: type ).save + oa = web_link.get_object_auth_by_title(type) + end + link_to t('admin.web_link.cate_auth'),admin_object_auth_ob_auth_path(oa) + end +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5f693965..fc93c29a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -172,6 +172,10 @@ module ApplicationHelper locale.to_sym == I18n.locale ? 'active in': '' end + def at_least_module_manager + is_manager? || is_admin? + end + def dislpay_view_count(object) "#{t(:view_count)}: #{object.view_count}" end @@ -196,4 +200,8 @@ module ApplicationHelper display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year}) end + def at_least_module_manager + is_manager? || is_admin? + end + end diff --git a/app/models/ad_banner.rb b/app/models/ad_banner.rb index 09aa79c8..18c6d448 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -3,10 +3,11 @@ class AdBanner include Mongoid::Timestamps include Mongoid::MultiParameterAttributes include OrbitCoreLib::ObjectAuthable - + field :title field :transition_msec,type: Integer field :ad_fx #TODO Design should explain + field :best_size,:default => '' before_save :save_or_destroy validates_uniqueness_of :title diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index d1c1c673..d5cc48de 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -11,7 +11,7 @@ class ObjectAuth < PrototypeAuth end def check_user_has_app_auth - sub_managing_users = auth_obj.app_auth.sub_managing_users + sub_managing_users = auth_obj.app_auth.sub_managing_users rescue [] app_auth = auth_obj.app_auth self.auth_users.each do |auth_user| if !sub_managing_users.include? auth_user && !auth_user.admin? 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 797624ff..ca98e42e 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -1,5 +1,5 @@
" id=<%= ad_banner_tab.title.dehumanize %>> - +<% if at_least_module_manager || sub_manager?(ad_banner_tab)%> <%= form_for ad_banner_tab,:url=> admin_ad_banner_path(ad_banner_tab),:method => :put,:class=>"input-medium" do |f| -%>
@@ -11,17 +11,25 @@ <%= f.submit t("admin.ad.update_banner"), :class => 'btn' %> <%= f.submit t("cancel"),:type=>'reset', :class => 'btn' %>
-

圖片列表

+ <% end -%> +<% end -%> +

<%= t("admin.ad.picture_list")%>

-
- <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> - <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.id) , :class=>'preview_trigger btn btn-success'%> -
+ <%if (at_least_module_manager || ad_banner_tab.cur_user_is_sub_manager_of(:edit) )%> + <%= content_tag :div ,:class=>'adbanner-action' do%> + <%= link_to t("admin.ad.new_image"),new_admin_ad_banner_ad_image_path(ad_banner_tab) ,:class => "btn btn-primary"%> + <%= link_to t("modal.preview"), admin_realtime_preview_ad_banner_path(ad_banner_tab.id) , :class=>'preview_trigger btn btn-success'%> + <% end -%> + <% end -%> + <% 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" } %>
- <% end -%> <%#= render :partial => 'preview_block',:locals=> {:ad_banner =>ad_banner_tab} %>
diff --git a/app/views/admin/ad_banners/_ad_image_update.html.erb b/app/views/admin/ad_banners/_ad_image_update.html.erb index c055a8c9..0b4277a0 100644 --- a/app/views/admin/ad_banners/_ad_image_update.html.erb +++ b/app/views/admin/ad_banners/_ad_image_update.html.erb @@ -4,8 +4,10 @@ <%= ad_image.display? ? "[#{t('admin.ad.showing')}]" : "[#{t('admin.ad.not_showing')}]" %> <%= "#{ad_image.post_date ||'NeedReset' }~#{ad_image.unpost_date || 'NeedReset'}" %>

-

- <%= link_to t('edit'),edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> - <%= link_to t('delete'),admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %> -

+ <%if at_least_module_manager || sub_manager?(ad_image.ad_banner) %> +

+ <%= link_to t('edit'),edit_admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn btn-primary' %> + <%= link_to t('delete'),admin_ad_banner_ad_image_path(ad_banner,ad_image),:class => 'btn',:method => :delete,:confirm => t('sure?') %> +

+ <% end -%> \ No newline at end of file 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/app/views/admin/ad_images/_form.html.erb b/app/views/admin/ad_images/_form.html.erb index be5f2b47..1513fa05 100644 --- a/app/views/admin/ad_images/_form.html.erb +++ b/app/views/admin/ad_images/_form.html.erb @@ -80,7 +80,7 @@ <%= image_tag @ad_image.file rescue ''%>
- 此區塊圖片尺寸請使用580px × 225px + <%= t("admin.ad.widget_info_for_ad_image_size",:best_size=> @ad_image.ad_banner.best_size) if !@ad_image.ad_banner.best_size.empty?%>