From 30137b50b41b67195dedb1cc316f9fb73defc5a7 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 16 May 2012 15:33:54 +0800 Subject: [PATCH 01/13] popup fix.. --- app/assets/javascripts/ajax_form.js | 11 ++- app/assets/javascripts/new_admin.js | 2 +- app/assets/javascripts/tiny_mce_popup.js | 5 ++ app/assets/javascripts/tinymce_orbit.js.erb | 93 +++++++++++++++++++++ app/controllers/admin/assets_controller.rb | 2 +- app/views/admin/assets/new.html.erb | 2 +- 6 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/tiny_mce_popup.js create mode 100644 app/assets/javascripts/tinymce_orbit.js.erb diff --git a/app/assets/javascripts/ajax_form.js b/app/assets/javascripts/ajax_form.js index d9b5abfe..b683f43d 100644 --- a/app/assets/javascripts/ajax_form.js +++ b/app/assets/javascripts/ajax_form.js @@ -4,4 +4,13 @@ $(document).on('click', '#ajax_form_submit', function(){ o.dataType = 'script'; } }); -}); \ No newline at end of file +}); +$(document).ready(function(){ + var win = parent.OWindow; + var thatwindow = win.thiswindow; + alert(self.id); + $("div.button_bar input[type=submit]").click(function(){ + thatwindow.document.getElementById(win.input).value = "Soemthing"; + return false; + }) +}) diff --git a/app/assets/javascripts/new_admin.js b/app/assets/javascripts/new_admin.js index 70bc22bd..f5fed368 100644 --- a/app/assets/javascripts/new_admin.js +++ b/app/assets/javascripts/new_admin.js @@ -16,4 +16,4 @@ //= require orbit-bar-search //= require side_bar_history //= require rss -//= require ajax_form \ No newline at end of file +//= require ajax_form diff --git a/app/assets/javascripts/tiny_mce_popup.js b/app/assets/javascripts/tiny_mce_popup.js new file mode 100644 index 00000000..f859d24e --- /dev/null +++ b/app/assets/javascripts/tiny_mce_popup.js @@ -0,0 +1,5 @@ + +// Uncomment and change this document.domain value if you are loading the script cross subdomains +// document.domain = 'moxiecode.com'; + +var tinymce=null,tinyMCEPopup,tinyMCE;tinyMCEPopup={init:function(){var b=this,a,c;a=b.getWin();tinymce=a.tinymce;tinyMCE=a.tinyMCE;b.editor=tinymce.EditorManager.activeEditor;b.params=b.editor.windowManager.params;b.features=b.editor.windowManager.features;b.dom=b.editor.windowManager.createInstance("tinymce.dom.DOMUtils",document);if(b.features.popup_css!==false){b.dom.loadCSS(b.features.popup_css||b.editor.settings.popup_css)}b.listeners=[];b.onInit={add:function(e,d){b.listeners.push({func:e,scope:d})}};b.isWindow=!b.getWindowArg("mce_inline");b.id=b.getWindowArg("mce_window_id");b.editor.windowManager.onOpen.dispatch(b.editor.windowManager,window)},getWin:function(){return(!window.frameElement&&window.dialogArguments)||opener||parent||top},getWindowArg:function(c,b){var a=this.params[c];return tinymce.is(a)?a:b},getParam:function(b,a){return this.editor.getParam(b,a)},getLang:function(b,a){return this.editor.getLang(b,a)},execCommand:function(d,c,e,b){b=b||{};b.skip_focus=1;this.restoreSelection();return this.editor.execCommand(d,c,e,b)},resizeToInnerSize:function(){var a=this;setTimeout(function(){var b=a.dom.getViewPort(window);a.editor.windowManager.resizeBy(a.getWindowArg("mce_width")-b.w,a.getWindowArg("mce_height")-b.h,a.id||window)},10)},executeOnLoad:function(s){this.onInit.add(function(){eval(s)})},storeSelection:function(){this.editor.windowManager.bookmark=tinyMCEPopup.editor.selection.getBookmark(1)},restoreSelection:function(){var a=tinyMCEPopup;if(!a.isWindow&&tinymce.isIE){a.editor.selection.moveToBookmark(a.editor.windowManager.bookmark)}},requireLangPack:function(){var b=this,a=b.getWindowArg("plugin_url")||b.getWindowArg("theme_url");if(a&&b.editor.settings.language&&b.features.translate_i18n!==false&&b.editor.settings.language_load!==false){a+="/langs/"+b.editor.settings.language+"_dlg.js";if(!tinymce.ScriptLoader.isDone(a)){document.write(' +<% end %> \ No newline at end of file diff --git a/app/views/admin/page_parts/edit.js.erb b/app/views/admin/page_parts/edit.js.erb index 5dd8351c..3e50360c 100644 --- a/app/views/admin/page_parts/edit.js.erb +++ b/app/views/admin/page_parts/edit.js.erb @@ -1 +1,44 @@ -$('#back_main').html("<%= j render(:partial => 'edit') %>"); \ No newline at end of file +$('#back_main').html("<%= j render(:partial => 'edit') %>"); +tinymce.init({ + // General options + mode: 'textareas', + theme: 'advanced', + file_browser_callback : 'myFileBrowser', + plugins : "autolink,lists,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave", + + // Theme options + theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect", + theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,forecolor,backcolor", + theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,fullscreen", + theme_advanced_toolbar_location : "top", + theme_advanced_toolbar_align : "left", + theme_advanced_statusbar_location : "bottom", + theme_advanced_resizing : true, + + // Skin options + skin : "o2k7", + skin_variant : "silver", + + // Drop lists for link/image/media/template dialogs + template_external_list_url : "js/template_list.js", + // external_link_list_url : "js/link_list.js", + // external_image_list_url : "js/image_list.js", + // media_external_list_url : "js/media_list.js" + + // Style formats + style_formats : [ + {title : 'Bold text', inline : 'b'}, + {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}}, + {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}}, + {title : 'Example 1', inline : 'span', classes : 'example1'}, + {title : 'Example 2', inline : 'span', classes : 'example2'}, + {title : 'Table styles'}, + {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'} + ], + + // Replace values for the template plugin + template_replace_values : { + username : "Some User", + staffid : "991234" + } +}); \ No newline at end of file From be7ce0bf45a1e18a618fdbc05ddee6f7e055db5f Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 17 May 2012 06:25:38 +0800 Subject: [PATCH 06/13] Redmine change's --- .../panel/announcement/back_end/bulletins/_form.html.erb | 4 ++-- .../views/panel/news/front_end/news_bulletins/show.html.erb | 2 +- .../panel/page_content/front_end/page_contexts/index.html.erb | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb index 4ffea341..05247251 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_form.html.erb @@ -50,13 +50,13 @@
- <%= f.datetime_select :postdate, {:use_month_numbers => true, :order => [:day, :month, :year] }, {:class => 'input-small'} %> + <%= f.datetime_select :postdate, {:use_month_numbers => true, :order => [:day, :month, :year] }, {:class => 'span1'} %>
- <%= f.datetime_select :deadline, {:use_month_numbers => true, :prompt => { :month => 'Month', :day => 'Day', :year => 'Year'}, :order => [:day, :month, :year] }, {:class => 'input-small'} %> + <%= f.datetime_select :deadline, {:use_month_numbers => true, :prompt => { :month => 'Month', :day => 'Day', :year => 'Year'}, :order => [:day, :month, :year] }, {:class => 'span1'} %>
diff --git a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb index 8959c6ae..e1c07e3b 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/show.html.erb @@ -2,10 +2,10 @@

<%= @news_bulletin.title[I18n.locale] %>

+ <%= dislpay_view_count(@news_bulletin) %> <%= @news_bulletin.postdate %>  |  <%= @news_bulletin.unit_list_for_anc.title[I18n.locale] rescue '' %> - <%= dislpay_view_count(@news_bulletin) %>
diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb index a27a56e7..474ace53 100644 --- a/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/front_end/page_contexts/index.html.erb @@ -3,8 +3,9 @@

<%= flash_messages %>

+
<%= dislpay_view_count(@page_context) %>

<%= @page_context.page.i18n_variable[I18n.locale] rescue nil %>

<%= @page_context.context[I18n.locale].html_safe rescue nil %>
-
<%= dislpay_view_count(@page_context) %>
+ From 26292f0dcca8d87fcf3d8e44fe51c7b6e93415fd Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 17 May 2012 06:28:29 +0800 Subject: [PATCH 07/13] Asset upload --- app/assets/javascripts/tinymce_orbit.js.erb | 2 +- app/controllers/admin/assets_controller.rb | 41 +++++++++++-- app/models/asset.rb | 7 +++ app/views/admin/assets/_asset.html.erb | 21 ++++++- app/views/admin/assets/_edit.html.erb | 4 +- app/views/admin/assets/_form.html.erb | 57 ++++++++++++------- app/views/admin/assets/_new.html.erb | 4 +- app/views/admin/assets/_sort_headers.html.erb | 11 ++-- app/views/admin/assets/file_upload.html.erb | 56 ++++++++++++++++++ app/views/admin/assets/index.html.erb | 15 ++--- app/views/admin/assets/index.js.erb | 4 ++ app/views/layouts/_side_bar.html.erb | 1 - config/locales/en.yml | 5 ++ config/locales/zh_tw.yml | 5 ++ config/routes.rb | 1 + 15 files changed, 191 insertions(+), 43 deletions(-) create mode 100644 app/views/admin/assets/file_upload.html.erb create mode 100644 app/views/admin/assets/index.js.erb diff --git a/app/assets/javascripts/tinymce_orbit.js.erb b/app/assets/javascripts/tinymce_orbit.js.erb index 1a9d063d..51f86b6f 100644 --- a/app/assets/javascripts/tinymce_orbit.js.erb +++ b/app/assets/javascripts/tinymce_orbit.js.erb @@ -46,7 +46,7 @@ function load_tinymce() { function myFileBrowser(field_name, url, type, win) { var cmsURL = window.location.toString(); cmsURL = cmsURL.split("/"); - cmsURL = "<%= Rails.application.routes.url_helpers.new_admin_asset_path %>"; + cmsURL = "<%= Rails.application.routes.url_helpers.file_upload_admin_assets_path %>"; console.log(cmsURL); // script URL - use an absolute path! if (cmsURL.indexOf("?") < 0) { diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 89fd41b7..fb4865a2 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -11,6 +11,7 @@ class Admin::AssetsController < OrbitBackendController def new @asset = Asset.new @asset_categories = AssetCategory.all + @tags = AssetTag.all respond_to do |format| format.html {} format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/new'} } @@ -20,6 +21,7 @@ class Admin::AssetsController < OrbitBackendController def edit @asset = Asset.find(params[:id]) @asset_categories = AssetCategory.all + @tags = AssetTag.all respond_to do |format| format.html {} format.js { render 'js/show_pop_up', :locals => {:partial => 'admin/assets/edit'} } @@ -28,15 +30,29 @@ class Admin::AssetsController < OrbitBackendController def create @asset = Asset.new(params[:asset]) - if @asset.save + @asset.filename = @asset.i18n_variable[I18n.locale] rescue nil + if @asset.filename && @asset.save respond_to do |format| - format.html { render :text => @asset.data.url } - format.js {} + format.js { + if params[:uploader] + render 'create' + else + render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil} + end + } end else + flash[:error] = t(:create_fail) + @asset_categories = AssetCategory.all + @tags = AssetTag.all respond_to do |format| - format.html { render :action => :new } - format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}} } + format.js { + if params[:uploader] + render 'file_upload' + else + render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/new', :locals => {:is_html => false}} + end + } end end end @@ -49,6 +65,9 @@ class Admin::AssetsController < OrbitBackendController format.js { render 'js/remove_pop_up_and_reload_content', :locals => {:function => 'replaceWith', :id => "asset_#{@asset.id}", :value => @asset, :values => nil, :partial => 'admin/assets/asset', :locals => nil} } end else + flash[:error] = t(:update_fail) + @asset_categories = AssetCategory.all + @tags = AssetTag.all respond_to do |format| format.html { render :action => :edit } format.js { render 'js/reload_pop_up', :locals => {:value => @asset, :values => nil, :partial => 'admin/assets/edit', :locals => {:is_html => false}} } @@ -71,5 +90,17 @@ class Admin::AssetsController < OrbitBackendController end redirect_to assets_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end + + def file_upload + @asset = Asset.new + @asset_categories = AssetCategory.all + @tags = AssetTag.all + render :layout => false + end + + def file_select + @assets = Asset.all + render :layout => false + end end diff --git a/app/models/asset.rb b/app/models/asset.rb index 2bb02dfc..9819934f 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -8,9 +8,16 @@ class Asset field :filename field :description + has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + validates_presence_of :filename, :data belongs_to :asset_category belongs_to :assetable, polymorphic: true + has_and_belongs_to_many :tags, :class_name => "AssetTag" + + def sorted_tags + tags.order_by(I18n.locale, :asc) + end end diff --git a/app/views/admin/assets/_asset.html.erb b/app/views/admin/assets/_asset.html.erb index 99ac636e..9eb4e77a 100644 --- a/app/views/admin/assets/_asset.html.erb +++ b/app/views/admin/assets/_asset.html.erb @@ -1,7 +1,8 @@ <%= check_box_tag 'to_delete[]', asset.id, false, :class => "checkbox_in_list" %> + <%= asset.i18n_variable[I18n.locale] rescue nil %> -
<%= image_tag(asset.data.url) %>
+
- <%= asset.description %> <%= asset.data.file.content_type %> - <%= asset.data_identifier %> <%= number_to_human_size(asset.data.file.file_length) %> + <%= asset.category.i18n_variable[I18n.locale] rescue nil %> + +
+
+ <% asset.sorted_tags.each do |tag| %> + <%= tag[I18n.locale] %> + <% end %> +
+
+ + + \ No newline at end of file diff --git a/app/views/admin/assets/_edit.html.erb b/app/views/admin/assets/_edit.html.erb index a62524c0..0e592d19 100644 --- a/app/views/admin/assets/_edit.html.erb +++ b/app/views/admin/assets/_edit.html.erb @@ -1,6 +1,8 @@

<%= t('editing_asset') %>

+ <%= flash_messages %> + <%= form_for @asset, :url => admin_asset_path(@asset), :html => {:id => (is_html ? nil : 'ajaxForm'), :multipart => true } do |f| %> <%= f.error_messages %> <%= render :partial => "form", :locals => { :f => f } %> @@ -9,7 +11,7 @@ <%= link_back %> <%= f.submit t(:edit) %> <% else %> - <%= t(:update) %> + <%= t(:update) %> <% end %>
<% end %> diff --git a/app/views/admin/assets/_form.html.erb b/app/views/admin/assets/_form.html.erb index 6abb883e..4e1589f4 100644 --- a/app/views/admin/assets/_form.html.erb +++ b/app/views/admin/assets/_form.html.erb @@ -1,19 +1,38 @@ -

-<%= f.label :filename, t('admin.file_name') %> -<%= f.text_field :filename, :class => 'text' %> -

- -

-<%= f.label :description, t('admin.description') %> -<%= f.text_field :description, :class => 'text' %> -

- -

-<%= f.label :category %> -<%= f.select :asset_category_id, @asset_categories.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-medium" %> -

- -

-<%= f.label :data, t('admin.data'), :class => 'file' %> -<%= f.file_field :data %> -

\ No newline at end of file +
+ +
+ <%= f.fields_for :i18n_variable, (@asset.new_record? ? @asset.build_i18n_variable : @asset.i18n_variable) do |f| %> + <% @site_valid_locales.each do |locale| %> + <%= content_tag :label do -%> +
+ <%= I18nVariable.from_locale(locale) %> + <%= f.text_field locale, :class => "input-large" %> +
+ <% end %> + <% end %> + <% end %> +
+
+
+ +
+ <%= f.select :asset_category_id, @asset_categories.collect{|t| [ t.i18n_variable[I18n.locale], t.id ]}, {}, :class => "input-large" %> +
+
+
+ +
+ <% @tags.each do |tag| %> + <%= content_tag :label, :class => "checkbox inline" do -%> + <%= check_box_tag 'asset[tag_ids][]', tag.id, @asset.tag_ids.include?(tag.id) %> + <%= tag[I18n.locale] %> + <% end %> + <% end %> +
+
+
+ +
+ <%= f.file_field :data, :class => 'upload' %> +
+
\ No newline at end of file diff --git a/app/views/admin/assets/_new.html.erb b/app/views/admin/assets/_new.html.erb index 5d770a2e..d8838278 100644 --- a/app/views/admin/assets/_new.html.erb +++ b/app/views/admin/assets/_new.html.erb @@ -1,11 +1,13 @@

<%= t('admin.new_asset') %>

+ <%= flash_messages %> + <%= form_for :asset, :url => admin_assets_path, :html => {:id => 'ajaxForm', :multipart => true } do |f| %> <%= f.error_messages %> <%= render :partial => "form", :locals => { :f => f } %> <% end %>
diff --git a/app/views/admin/assets/_sort_headers.html.erb b/app/views/admin/assets/_sort_headers.html.erb index 2c8ca234..86e5f86a 100644 --- a/app/views/admin/assets/_sort_headers.html.erb +++ b/app/views/admin/assets/_sort_headers.html.erb @@ -1,5 +1,6 @@ -<%= render_sort_bar(true, ['title', 'title','span1-2', 'admin.title'], - ['description', 'description', 'span1-2', 'admin.description'], - ['intro', 'intro', 'span1-2', 'admin.intro'], - ['intro', 'intro', 'span1-2', 'admin.intro'], - ['intro', 'intro', 'span1-2', 'admin.file_length']).html_safe %> +<%= render_sort_bar(true, ['title', 'title','span4', 'admin.title'], + ['description', 'description', 'span1-2', 'admin.data'], + ['intro', 'intro', 'span1-2', 'admin.file_type'], + ['intro', 'intro', 'span1-2', 'admin.file_length'], + ['intro', 'intro', 'span1-2', 'admin.category'], + ['intro', 'intro', 'span1-2', 'admin.tags']).html_safe %> diff --git a/app/views/admin/assets/file_upload.html.erb b/app/views/admin/assets/file_upload.html.erb new file mode 100644 index 00000000..eeed414b --- /dev/null +++ b/app/views/admin/assets/file_upload.html.erb @@ -0,0 +1,56 @@ +<%= javascript_include_tag "new_admin" %> +<%= stylesheet_link_tag "new_admin" %> + +<%= flash_messages %> + +<%= form_for :asset, :url => admin_assets_path(:uploader => true), :html => {:id => 'ajaxForm', :multipart => true } do |f| %> + + +
+ +
+ +<% end %> \ No newline at end of file diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb index 7424eb6c..394e18e8 100644 --- a/app/views/admin/assets/index.html.erb +++ b/app/views/admin/assets/index.html.erb @@ -3,12 +3,13 @@ - - - - - - + + + + + + + @@ -20,7 +21,7 @@
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_admin_asset_path, :remote => true, :class => 'btn btn-primary pull-right' %>
- <%= paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]} %> + <%= paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]}, :remote => true %>
diff --git a/app/views/admin/assets/index.js.erb b/app/views/admin/assets/index.js.erb new file mode 100644 index 00000000..e2e87d36 --- /dev/null +++ b/app/views/admin/assets/index.js.erb @@ -0,0 +1,4 @@ +$("#delete_all").attr("action", "<%= delete_admin_assets_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]) %>"); +$("#sort_headers").html("<%= j render 'sort_headers' %>"); +$("#tbody_assets").html("<%= j render :partial => 'asset', :collection => @assets %>"); +$("#asset_pagination").html("<%= j paginate @assets, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>"); \ No newline at end of file diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 852bfd4c..c1c16879 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -72,7 +72,6 @@ <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.asset'), admin_assets_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('assets', '/admin/asset_tags', 'asset_categories')) do -%> <%= content_tag :li, link_to(t('admin.all_assets'), admin_assets_path), :class => active_for_action('assets', 'index') %> - <%= content_tag :li, link_to(t('admin.add_new'), new_admin_asset_path), :class => active_for_action('assets', 'new') %> <%= content_tag :li, link_to(t('admin.categories'), admin_asset_categories_path), :class => active_for_action('asset_categories', 'index') %> <%= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %> <% end -%> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3e2ffe8e..908023d0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,6 +11,7 @@ en: back: Back browse: Browse cancel: Cancel + create_fail: Creation failed create: Create delete: Delete desktop: Desktop @@ -41,6 +42,7 @@ en: submit: Submit sure?: Are you sure? update: Update + update_failed: Update failed view: View view_count: View count yes_: "Yes" @@ -117,6 +119,7 @@ en: calendar: Calendar cant_delete_self: You can not delete yourself. cant_revoke_self_admin: You can not revoke your admin role yourself. + category: Category choose_file: Choose a file... class: Class content: Content @@ -146,6 +149,7 @@ en: enabled_for: Enabled for file_name: Filename file_size: File size + file_upload: File upload format: Format home: Home id: ID @@ -231,6 +235,7 @@ en: site_title: Site title super_pages: Super pages structure: Structure + tags: Tags title: Title translation: Translation type: Type diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 9a1a9952..14625b96 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -9,6 +9,7 @@ zh_tw: browse: 選擇檔案 cancel: 取消 create: 新增 + create_fail: 創建失敗 delete: 刪除 desktop: 桌面 disable: 禁用 @@ -35,6 +36,7 @@ zh_tw: submit: 送出 sure?: 您肯定嗎? update: 更新 + update: 更新失敗 view: 檢視 view_count: 查看次數 yes_: "Yes" @@ -110,6 +112,7 @@ zh_tw: calendar: 行事曆 cant_delete_self: 您不可以刪除自己。 cant_revoke_self_admin: 您不可以撤銷自己的管理身份。 + category: 類別 choose_file: 請選擇一個文件... class: 階級 content: 內容 @@ -143,6 +146,7 @@ zh_tw: enabled_for: 啟用 file_name: 檔名 file_size: 檔案大小 + file_upload: 文件上載 format: 格式 home: 首頁 id: ID @@ -230,6 +234,7 @@ zh_tw: site_setting: 網站設定 super_pages: 可編頁面 structure: 網站結構 + tags: 標籤 title: 標題 translation: 翻譯 type: 類型 diff --git a/config/routes.rb b/config/routes.rb index 214f58b2..ef2c46e2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,6 +15,7 @@ Orbit::Application.routes.draw do mount Resque::Server.new, :at => "/resque" resources :assets do collection do + get 'file_upload' post 'delete' end end From f663985a40a6d7e0fec3a7ba73ccb83c8845a787 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 15 May 2012 09:57:05 +0800 Subject: [PATCH 08/13] starting ad_banner auth --- app/helpers/admin/ad_banner_helper.rb | 10 ++++++++++ app/views/admin/ad_banners/_ad_banner_tab.html.erb | 3 +++ config/locales/zh_tw.yml | 1 + .../panel/announcement/back_end/bulletins_helper.rb | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index eff12427..f21c5e73 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -12,5 +12,15 @@ module Admin::AdBannerHelper printable_ad_images.shuffle! 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) + end end \ No newline at end of file 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..7074717f 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -20,6 +20,9 @@
    <%= render :partial => "ad_image_update", :collection => ad_banner_tab.ad_images,:as => :ad_image,:locals=>{:ad_banner => ad_banner_tab} %>
+ <% if is_manager? || is_admin? %> + <%= show_ad_banner_permission_link ad_banner_tab%> + <% 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 -%> diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 14625b96..e5d2b4f0 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -84,6 +84,7 @@ zh_tw: sec_place_holder: 3秒請輸入3 ab_fx: 轉場特效 all_banners: 輪播清單 + cate_auth: 分類授權 banner_best_size: Banner 尺寸 new_banner: 新增輪播 new_image: 新增橫幅 diff --git a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb index 8e6b9bff..68286c3e 100644 --- a/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb +++ b/vendor/built_in_modules/announcement/app/helpers/panel/announcement/back_end/bulletins_helper.rb @@ -2,7 +2,7 @@ module Panel::Announcement::BackEnd::BulletinsHelper def show_approval_link(bulletin) by_bulletin = (!bulletin.is_expired? and !bulletin.is_checked?) - by_user = (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager?) + by_user = (bulletin.bulletin_category.authed_users('fact_check').include?(current_user) or is_manager? or is_admin?) by_bulletin and by_user end From 03387d3c0772d5055b164b6ede13194512842711 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 15 May 2012 16:39:23 +0800 Subject: [PATCH 09/13] Object auth for ad_banner --- .../admin/ad_banners_controller.rb | 3 ++- .../module_apps_new_interface_controller.rb | 3 ++- app/helpers/admin/ad_banner_helper.rb | 11 +++++++++-- app/models/object_auth.rb | 2 ++ .../admin/ad_banners/_ad_banner_tab.html.erb | 19 +++++++++++-------- .../ad_banners/_ad_image_update.html.erb | 10 ++++++---- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 47d3d355..3457c4de 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -1,7 +1,8 @@ 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 destroy @ad_banner = AdBanner.find(params[:id]) diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 52292588..83aa0d79 100644 --- a/app/controllers/admin/module_apps_new_interface_controller.rb +++ b/app/controllers/admin/module_apps_new_interface_controller.rb @@ -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/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index f21c5e73..bfebc1b9 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -11,7 +11,10 @@ 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) @@ -20,7 +23,11 @@ module Admin::AdBannerHelper 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) + link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa),:class => "btn btn-warning" end + def at_least_module_manager + is_manager? || is_admin? + end + end \ No newline at end of file diff --git a/app/models/object_auth.rb b/app/models/object_auth.rb index d1c1c673..0ac3de41 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -11,6 +11,8 @@ class ObjectAuth < PrototypeAuth end def check_user_has_app_auth +debugger + a=1 sub_managing_users = auth_obj.app_auth.sub_managing_users app_auth = auth_obj.app_auth self.auth_users.each do |auth_user| 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 7074717f..a9e07ec2 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,20 +11,23 @@ <%= 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 || sub_manager?(ad_banner_tab)%> + <%= 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 -%>
    <%= render :partial => "ad_image_update", :collection => ad_banner_tab.ad_images,:as => :ad_image,:locals=>{:ad_banner => ad_banner_tab} %>
- <% if is_manager? || is_admin? %> + <% if at_least_module_manager %> <%= show_ad_banner_permission_link ad_banner_tab%> <% 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/config/locales/en.yml b/config/locales/en.yml index 908023d0..3fabb3ca 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -95,6 +95,7 @@ en: new_image: New image showing: Showing not_showing: NotShowing + picture_list: Picture List title: Title transition_sec: Transition time trans_unit_sec: sec diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index e5d2b4f0..3ad7ee1b 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -90,6 +90,7 @@ zh_tw: new_image: 新增橫幅 showing: 顯示中 not_showing: 沒有顯示 + picture_list: 圖片列表 title: 標題 transition_sec: 轉場單位時間 trans_unit_sec: 秒 From 82d78acbadbe198dd8583daf5bca9317af76831c Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 15 May 2012 18:55:16 +0800 Subject: [PATCH 10/13] First version of app and object auth for web_resource module. Basic fund is ok. backend need to be secued --- app/controllers/orbit_backend_controller.rb | 2 ++ app/helpers/admin/ad_banner_helper.rb | 8 +++----- app/helpers/admin/web_link_helper.rb | 11 +++++++++++ app/helpers/application_helper.rb | 4 ++++ app/models/object_auth.rb | 4 +--- .../admin/ad_banners/_ad_banner_tab.html.erb | 2 +- app/views/layouts/_side_bar.html.erb | 7 ++++--- lib/orbit_core_lib.rb | 4 ++++ .../web_resource/back_end/web_links_controller.rb | 4 ++-- .../web_resource/app/models/web_link_category.rb | 11 ++++++++++- .../_web_link_category.html.erb | 15 +++++++++------ .../back_end/web_link_categorys/index.html.erb | 2 +- .../back_end/web_links/_web_link.html.erb | 2 ++ 13 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 app/helpers/admin/web_link_helper.rb diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index cfa46847..e27e5b00 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 diff --git a/app/helpers/admin/ad_banner_helper.rb b/app/helpers/admin/ad_banner_helper.rb index bfebc1b9..ecba9b3b 100644 --- a/app/helpers/admin/ad_banner_helper.rb +++ b/app/helpers/admin/ad_banner_helper.rb @@ -16,8 +16,8 @@ module Admin::AdBannerHelper end def show_ad_banner_permission_link(ad_banner) - type = 'edit' - oa = ad_banner.get_object_auth_by_title(type) + 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) @@ -26,8 +26,6 @@ module Admin::AdBannerHelper link_to t('admin.ad.cate_auth'),admin_object_auth_ob_auth_path(oa),:class => "btn btn-warning" end - def at_least_module_manager - is_manager? || is_admin? - 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..445a3a49 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -196,4 +196,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/object_auth.rb b/app/models/object_auth.rb index 0ac3de41..d5cc48de 100644 --- a/app/models/object_auth.rb +++ b/app/models/object_auth.rb @@ -11,9 +11,7 @@ class ObjectAuth < PrototypeAuth end def check_user_has_app_auth -debugger - a=1 - 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 a9e07ec2..56fd09a1 100644 --- a/app/views/admin/ad_banners/_ad_banner_tab.html.erb +++ b/app/views/admin/ad_banners/_ad_banner_tab.html.erb @@ -15,7 +15,7 @@ <% end -%>

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

- <%if at_least_module_manager || sub_manager?(ad_banner_tab)%> + <%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'%> diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index c1c16879..e2c3a9ed 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -54,17 +54,18 @@ <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "ad_banners"}))), :class => active_for_app_auth('ad_banners') if (is_admin? rescue nil) %> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "ad_banners"}))), :class => active_for_app_auth('ad_banners') if (is_admin? rescue nil) %> <% end -%> <% end %> -<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') do -%> +<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> <%= content_tag :li, link_to(t('admin.all_articles'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') %> <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %> <%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "web_resource"}))), :class => active_for_app_auth('web_resource') if (is_admin? rescue nil) %> <% end -%> <% end -%> @@ -75,4 +76,4 @@ <%= content_tag :li, link_to(t('admin.categories'), admin_asset_categories_path), :class => active_for_action('asset_categories', 'index') %> <%= content_tag :li, link_to(t('admin.tags'), admin_asset_tags_path), :class => active_for_action('/admin/asset_tags', 'index') %> <% end -%> -<% end -%> \ No newline at end of file +<% end -%> diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index a6c9917f..ad4f6756 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -19,6 +19,10 @@ module OrbitCoreLib end + def cur_user_is_sub_manager_of(title) + authed_users(title).include?(User.current) + end + def app_auth ModuleApp.first(conditions: {:title => self.class::APP_NAME} ) end diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb index 69aa8c1a..323b92fc 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb @@ -1,7 +1,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController - before_filter :authenticate_user! - before_filter :is_admin? + # before_filter :for_app_manager,:except => [:index,:show] + # before_filter :for_app_sub_manager def index diff --git a/vendor/built_in_modules/web_resource/app/models/web_link_category.rb b/vendor/built_in_modules/web_resource/app/models/web_link_category.rb index c2a95f4b..f9ef5989 100644 --- a/vendor/built_in_modules/web_resource/app/models/web_link_category.rb +++ b/vendor/built_in_modules/web_resource/app/models/web_link_category.rb @@ -3,12 +3,21 @@ class WebLinkCategory include Mongoid::Document include Mongoid::Timestamps + include OrbitCoreLib::ObjectAuthable + # include Mongoid::MultiParameterAttributes - + AfterObjectAuthUrl = '/panel/page_content/back_end/page_contexts' + APP_NAME = 'web_resource' + ObjectAuthTitlesOptions = %W{edit} + field :key has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_many :web_links + def pp_object + i18n_variable[I18n.locale] + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb index 9d43b94c..b17e634b 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/_web_link_category.html.erb @@ -3,12 +3,15 @@
<% @site_valid_locales.each do |locale| %> diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb index 87defb11..4a2e8c59 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_link_categorys/index.html.erb @@ -34,6 +34,6 @@
-
<%= render :partial => "form" %>
+
<%= render :partial => "form" if at_least_module_manager%>
diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb index 457a05a8..f7d70250 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_web_link.html.erb @@ -24,8 +24,10 @@ <%= link_to web_link.name[I18n.locale], panel_web_resource_back_end_web_link_path(web_link) %>
From 7f2564a81e0b30a8d17c02c849a802ef494193d1 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 12:10:16 +0800 Subject: [PATCH 11/13] Fix sidebar and hide some links by roles --- .../admin/module_apps_new_interface_controller.rb | 6 +++--- app/views/layouts/_side_bar.html.erb | 14 ++++++++------ .../back_end/web_link_categorys_controller.rb | 3 ++- .../web_resource/back_end/web_links_controller.rb | 9 ++++++++- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/module_apps_new_interface_controller.rb b/app/controllers/admin/module_apps_new_interface_controller.rb index 83aa0d79..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 diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index e2c3a9ed..53314765 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -36,18 +36,20 @@ <%#= link_to content_tag(:i, nil, :class => 'icons-member') + t('admin.member'), admin_users_path %> <%# end -%> -<%= content_tag :li, :class => active_for_controllers('page_contexts') do -%> +<%= content_tag :li, :class => active_for_controllers('page_contexts') || active_for_app_auth('page_content') || active_for_ob_auths_object("PageContext") do -%> <%= link_to content_tag(:i, nil, :class => 'icons-page') + t('admin.page'), panel_page_content_back_end_page_contexts_path %> - <%#= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('page_contexts')) do -%> + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('page_contexts')) do -%> <%#= content_tag :li, link_to(t('admin.all_articles'), panel_page_content_back_end_page_contexts_path), :class => active_for_action('page_context', 'index') %> - <%# end -%> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "page_content"}))), :class => active_for_app_auth('page_content') if (is_admin? rescue nil) %> + <% end -%> + <% end -%> <%= content_tag :li, :class => active_for_controllers('designs') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-window-block') + t('admin.design'), admin_designs_path %> <% end -%> -<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') || active_for_app_auth('ad_banners') do -%> +<%= content_tag :li, :class => active_for_controllers('ad_banners', 'ad_images') ||active_for_ob_auths_object("AdBanner") ||active_for_app_auth('ad_banners') do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.ad_banner'), admin_ad_banners_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('ad_banners', 'ad_images') ) do -%> @@ -58,12 +60,12 @@ <% end -%> <% end %> -<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') do -%> +<%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') || active_for_ob_auths_object("WebLinkCategory") do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> <%= content_tag :li, link_to(t('admin.all_articles'), panel_web_resource_back_end_web_links_path), :class => active_for_action('web_links', 'index') %> <%= content_tag :li, link_to(t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path), :class => active_for_action('web_links', 'new') %> - <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => active_for_action('web_link_categorys', 'index') %> + <%= content_tag :li, link_to(t('announcement.categories'), panel_web_resource_back_end_web_link_categorys_path), :class => (active_for_action('web_link_categorys', 'index') || active_for_ob_auths_object("WebLinkCategory")) %> <%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "web_resource"}))), :class => active_for_app_auth('web_resource') if (is_admin? rescue nil) %> <% end -%> diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb index 46e8933f..8c961cba 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_link_categorys_controller.rb @@ -1,5 +1,6 @@ class Panel::WebResource::BackEnd::WebLinkCategorysController < OrbitBackendController - + before_filter :for_app_manager,:except => [:index] + def index @web_link_categorys = WebLinkCategory.all @web_link_category = WebLinkCategory.new(:display => 'List') diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb index 323b92fc..af557bcb 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb @@ -1,7 +1,7 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController before_filter :authenticate_user! # before_filter :for_app_manager,:except => [:index,:show] - # before_filter :for_app_sub_manager + before_filter :for_app_sub_manager,:except => [:index] def index @@ -134,6 +134,13 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController def get_categorys(id = nil) @web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true)) + + @web_link_categorys = [] + if(is_manager? || is_admin?) + @web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true)) + elsif is_sub_manager? + @web_link_categorys = WebLinkCategory.authed_for_user(current_user,'edit') + end end def get_tags From a3acd865d76466f11cbb553b2fc0a9922fe5f780 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 16:42:43 +0800 Subject: [PATCH 12/13] AdBanner reopen new banner and delete. Rename title with content editable tag. --- .../javascripts/lib/contenteditable.js.erb | 41 +++++++++++++++++++ .../admin/ad_banners_controller.rb | 5 +++ .../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 + 9 files changed, 70 insertions(+), 7 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 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 From 0f354b8ccc482fe759941cd0192ef19663675cab Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 16 May 2012 17:16:48 +0800 Subject: [PATCH 13/13] fix ad_image size hints. fix orbit backend controller error when changing language. --- app/controllers/orbit_backend_controller.rb | 1 + app/models/ad_banner.rb | 1 + app/views/admin/ad_images/_form.html.erb | 2 +- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index e27e5b00..98882ec3 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -13,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/models/ad_banner.rb b/app/models/ad_banner.rb index 09aa79c8..27ce11e1 100644 --- a/app/models/ad_banner.rb +++ b/app/models/ad_banner.rb @@ -7,6 +7,7 @@ class AdBanner 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/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?%>