From a9c241658ae8dc923c96efac560aa9fa752a0640 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Wed, 9 May 2012 15:22:15 +0800 Subject: [PATCH] Repeat code for news module --- ...ws_bulletin_category_setting_controller.rb | 63 +++++++++++++++++++ .../news_bulletin_categorys_helper.rb | 13 ++-- .../_modal_list.html.erb | 44 +++++++++++++ .../_privilege_user.html.erb | 26 ++++++++ .../setting.html.erb | 56 +++++++++++++++++ .../setting.js.erb | 2 + .../update_setting.js.erb | 1 + .../user_list.js.erb | 2 + .../_news_bulletin_category.html.erb | 2 +- vendor/built_in_modules/news/config/routes.rb | 6 +- 10 files changed, 208 insertions(+), 7 deletions(-) create mode 100644 vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_category_setting_controller.rb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/_modal_list.html.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/_privilege_user.html.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/setting.html.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/setting.js.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/update_setting.js.erb create mode 100644 vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/user_list.js.erb diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_category_setting_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_category_setting_controller.rb new file mode 100644 index 00000000..6b92195f --- /dev/null +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletin_category_setting_controller.rb @@ -0,0 +1,63 @@ +class Panel::News::BackEnd::NewsBulletinCategorySettingController < OrbitBackendController + before_filter :authenticate_user! + before_filter :for_app_manager + include AdminHelper + # layout 'admin' + # def preview_and_approve + # @bulletin = Bulletin.find params[:bulletin_id] + # end + + # def approve + # + # end + + def setting + @bulletin_categorys = [] + @bulletin_categorys << NewsBulletinCategory.find(params[:news_bulletin_category_id]) + @options_from_collection_for_select_bulletin_categorys = @bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] } + if params.has_key? :category + @bulletin_category = NewsBulletinCategory.find params[:category][:id] + else + @bulletin_category = @bulletin_categorys.first + end + preload_object_auth = @bulletin_category.object_auths.where(title: 'submit').empty?? (@bulletin_category.object_auths.create! :title=> 'submit') : @bulletin_category.object_auths.where(title: 'submit') + @users_array = preload_object_auth.first.privilege_users rescue [] + respond_to do |format| + format.html + format.js + end + end + + def update_setting + object_auth = update_setting_by_params + if object_auth.save! + flash[:notice] = "Update Done" + else + flash[:notice] = "Update Failed" + end + end + + def user_list + @bulletin_category = NewsBulletinCategory.find params[:category][:id] + end + + protected + def update_setting_by_params + category = NewsBulletinCategory.find params[:category][:id] + privilege_users = params[:users].collect{|key,value| User.find key } rescue [] + object_auth_ary = category.object_auths.where(title: 'submit') || (category.object_auths.create :title=> 'submit') + object_auth = object_auth_ary.first + object_auth.privilege_users = privilege_users + object_auth + end + + def get_categorys(id = nil) + @bulletin_categorys = [] + if(is_manager? || is_admin?) + @bulletin_categorys = (id ? NewsBulletinCategory.find(id).to_a : NewsBulletinCategory.excludes('disabled' => true)) + elsif is_sub_manager? + @bulletin_categorys = NewsBulletinCategory.authed_for_user(current_user,'submit_new') + end + end + +end diff --git a/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletin_categorys_helper.rb b/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletin_categorys_helper.rb index 8ad75108..51cbadcf 100644 --- a/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletin_categorys_helper.rb +++ b/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletin_categorys_helper.rb @@ -2,13 +2,16 @@ module Panel::News::BackEnd::NewsBulletinCategorysHelper include ActionView::Helpers::UrlHelper - def show_submit_permission_link(news_bulletin_category) - oa = news_bulletin_category.get_object_auth_by_title('submit') + def show_permission_link(news_bulletin_category) + type = 'submit' + oa = news_bulletin_category.get_object_auth_by_title(type) if oa.nil? - news_bulletin_category.object_auths.new(title: 'submit' ).save - oa = news_bulletin_category.get_object_auth_by_title('submit') + news_bulletin_category.object_auths.new(title: type ).save + oa = news_bulletin_category.get_object_auth_by_title(type) end - link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa) +# link_to t('announcement.bulletin.cate_auth'), edit_admin_object_auth_path(oa) +link_to t('announcement.bulletin.cate_auth'),panel_news_back_end_news_bulletin_category_setting_path(news_bulletin_category) + end end \ No newline at end of file diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/_modal_list.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/_modal_list.html.erb new file mode 100644 index 00000000..a73fdab2 --- /dev/null +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletin_category_setting/_modal_list.html.erb @@ -0,0 +1,44 @@ +<% if bulletin_category -%> + +