diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 30a8a3ac..fcb1052a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,8 +3,8 @@ class ApplicationController < ActionController::Base include ParserFrontEnd, ParserBackEnd, ApplicationHelper include OrbitApp::ErrorHandlers::PageErrorHandler - include OrbitApp::ErrorHandlers::ObjectAuthErrorHandler - include OrbitApp::ErrorHandlers::ModuleAppErrorHandler + include OrbitApp::ErrorHandlers::ObjectAuthErrorHandler + include OrbitApp::ErrorHandlers::ModuleAppErrorHandler rescue_from ObjectAuthError, :with => :render_object_auth_error rescue_from ModuleAppError, :with => :render_module_app_error @@ -34,11 +34,11 @@ class ApplicationController < ActionController::Base def front_end_available(module_app_title='') app_controller = ModuleApp.first(conditions: {:key => module_app_title} ) - unless app_controller.enable_frontend? + unless app_controller.enable_frontend? render :nothing => true end end - + def get_all_app_engines ary = ["vender/plugins/new_blog"] app_engines = ary.collect{|t| @@ -51,23 +51,23 @@ class ApplicationController < ActionController::Base def flaten_controller ary=[] - Find.find(File.join(Rails.root , 'vendor/plugins/')) { |name| + Find.find(File.join(Rails.root , 'vendor/plugins/')) { |name| require_dependency(name) if /_controller\.rb$/ =~ name ary << name } ary end - + # Find the parent for the given item def find_parent_item @parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil end - + def auth_failed_in_backend - #redirect_to admin_dashboards_url + #redirect_to admin_dashboards_url redirect_to root_path end - + def for_admin_only if is_admin? true @@ -76,7 +76,7 @@ class ApplicationController < ActionController::Base auth_failed_in_backend end end - + def for_app_manager if is_manager? true @@ -85,7 +85,7 @@ class ApplicationController < ActionController::Base auth_failed_in_backend end end - + def for_app_sub_manager if (@module_app.sub_managing_users.include?(current_or_guest_user) || is_manager?) true @@ -108,7 +108,7 @@ class ApplicationController < ActionController::Base flash[:error] = t("access.denied.object") auth_failed_in_backend unless (obj.get_object_auth_by_title(title).auth_users.include?(current_or_guest_user) || is_manager? || is_admin? ) end - + # Render the page def render_page(args={}) if @item @@ -132,9 +132,9 @@ class ApplicationController < ActionController::Base @orig_url = "http://#{request.host_with_port}/#{@item.path}?id=#{@object.id}" render 'shared/render_share', :layout => false end - + protected - + # Set I18n.locale def set_locale # update session if passed @@ -148,11 +148,11 @@ class ApplicationController < ActionController::Base else browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil condition = @site_in_use_locales.include?(browser_locale) - end + end session[:locale] = condition ? (browser_locale || session[:locale]) : I18n.default_locale.to_s I18n.locale = session[:locale].to_sym end - + # Set the site variables def set_site # set site if exist or create site @@ -161,11 +161,11 @@ class ApplicationController < ActionController::Base @site_in_use_locales = site_locales_default_head(@site.in_use_locales) @site_valid_locales = site_locales_default_head(@site.valid_locales) end - + def set_current_item session[:current_page] = params[:id] || @item.id rescue nil end - + def decrypt_data(encrypted_data, encrypted_key, encrypted_iv) site = Site.find(session[:site]) if encrypted_data @@ -181,7 +181,7 @@ class ApplicationController < ActionController::Base '' end end - + def get_homepage Page.root end @@ -229,6 +229,174 @@ class ApplicationController < ActionController::Base redirect_to ret end + def get_sorted_and_filtered(object_class, query = nil, objects = nil) + objects ||= get_objects(object_class, query) + object_class = object_class.classify.constantize + if !params[:sort].blank? + options = params[:sort_options] + options = [options] if !options.class.eql?(Array) + options.each do |option| + if object_class.fields.include?(option) + if object_class.fields[option].type.to_s.eql?('Object') && !object_class.relations[option].nil? + objects = get_objects_from_referenced_objects(object_class.fields[option].options[:class_name].constantize, objects, option) + else + (objects = objects.order_by(option, params[:direction])) rescue nil + end + elsif object_class.relations.include?(option) + case object_class.relations[option].macro + when :references_one + a = Array.new + objects.each { |object| a << [get_string_value_from_object(object), object] } + sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse! + objects = sorted.collect {|x| x[1] } + when :references_many, :references_and_referenced_in_many + objects = get_objects_from_self(object_class, objects, option) + when :referenced_in + objects = get_objects_from_referenced_objects(object_class.relations[option].class_name.constantize, objects, "#{option}_id") + end + elsif option.eql?('tags') + tag_array = @module_app.tags.inject([]){ |result, value| + result << [value.name, value] + } + params[:direction].eql?('asc') ? tag_array.sort : tag_array.sort.reverse! + sorted_objects = Array.new + tag_array.each do |x| + taggings = x[1].taggings + taggings.each {|tagging| sorted_objects << tagging.taggable } + end + # debugger + sorted_objects.flatten! + sorted_objects.uniq! + objects = get_with_nil(objects, option, sorted_objects) + end + end + end + if @filter + @filter.each do |key, value| + case key + when 'status' + a = Array.new + objects.each do |object| + value.each do |v| + a << object if object[v] + end + end + objects = a.uniq + when 'categories' + a = Array.new + objects.each do |object| + a << object if (value.include?(object.send("#{object.class.to_s.underscore}_category").id.to_s) rescue nil) + end + objects = a.uniq + when 'tags' + a = Array.new + objects.each do |object| + object.tags.each do |tag| + a << object if value.include?(tag.id.to_s) + end + end + objects = a.uniq + end if value.size > 0 + end + end + Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10) + end + + def get_viewable(object_class, query=nil) + objects = get_objects(object_class,query).order_by(:created_at, :desc) + Kaminari.paginate_array(objects).page(params[:page]).per(10) + end + + def get_objects(object_class, query=nil) + object_class = object_class.classify.constantize + # debugger + # a=1 + if query + if object_class.include?(Mongoid::Sortable) + objects = object_class.default_sort(params[:sort]).where(query) + else + objects = object_class.where(query) + end + else + if object_class.include?(Mongoid::Sortable) + objects = object_class.default_sort(params[:sort]).all + else + objects = object_class.all + end + end + objects + end + + def get_objects_from_referenced_objects(object_class, objects, option) + referer_ids = objects.distinct(option) + referenced_objects = object_class.find(referer_ids) rescue nil + if referenced_objects + a = Array.new + referenced_objects.to_a.each { |referer| a << [get_string_value_from_object(referer), referer.id] } + sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse! + sorted_objects = sorted.collect {|x| objects.where(option => x[1]).entries } + sorted_objects.flatten! + sorted_objects.uniq! + get_with_nil(objects, option, sorted_objects) + else + objects + end + end + + def get_objects_from_self(object_class, objects, option) + referenced_class = object_class.relations[option].class_name.constantize + referenced_objects = referenced_class.all rescue nil + if referenced_objects + reverse_relation = nil + referenced_class.relations.each { |relation| reverse_relation = relation[1].name.to_s if relation[1].class_name.eql?(object_class.to_s) } + a = Array.new + referenced_objects.each { |referenced_object| a << [get_string_value_from_object(referenced_object), referenced_object] } + a.compact! + sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse! + sorted_objects = Array.new + sorted.each {|x| sorted_objects << x[1].send(reverse_relation) } + sorted_objects.flatten! + sorted_objects.uniq! + get_with_nil(objects, option, sorted_objects) + else + objects + end + end + + def get_string_value_from_object(object) + s = object.name_translations[I18n.locale.to_s] unless s rescue nil + s = object.title_translations[I18n.locale.to_s] unless s rescue nil + s = object.name unless s rescue nil + s = object.title unless s rescue nil + s.downcase rescue '' + end + + def get_with_nil(objects, option, sorted_objects) + tmp = Array.new + objects.each { |object| tmp << [get_string_value_from_object(object), object] if (object.send(option).blank? || (object.send(option).size == 0 rescue nil)) } + sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse! + sorted_tmp = sorted.collect {|a| a[1] } + a = params[:direction].eql?('asc') ? (sorted_tmp + sorted_objects) : (sorted_objects + sorted_tmp) + a.flatten + end + + + def filter_authorized_objects(objects) + if(!is_admin? || !is_manager?) + objects.delete_if{ |object| + if object.is_pending == true + if check_permission(:manager) + object.create_user_id != current_user.id + else + !object.send("#{object.class.to_s.underscore}_category").authed_users('fact_check').include?(current_user) rescue false + end + else + false + end + } + end + objects + end private diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index a92d54e7..cbf963df 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -4,9 +4,9 @@ class OrbitBackendController < ApplicationController include OrbitTag::Tagging include AdminHelper include ApplicationHelper - + layout 'new_admin' - + def setup_vars @app_title ||= controller_path.split('/')[1].singularize @module_app ||= ModuleApp.first(conditions: {:key => @app_title} ) @@ -24,177 +24,15 @@ class OrbitBackendController < ApplicationController def force_order_for_user setup_vars - set_current_user + set_current_user authenticate_user! check_user_can_use end - def check_user_can_use + def check_user_can_use unless check_permission #redirect_to polymorphic_path(['panel',@app_title,'back_end','public']) redirect_to root_url end end - - def get_sorted_and_filtered(object_class, query=nil) - objects = get_objects(object_class, query) - object_class = object_class.classify.constantize - if !params[:sort].blank? - options = params[:sort_options] - options = [options] if !options.class.eql?(Array) - options.each do |option| - if object_class.fields.include?(option) - if object_class.fields[option].type.to_s.eql?('Object') && !object_class.relations[option].nil? - objects = get_objects_from_referenced_objects(object_class.fields[option].options[:class_name].constantize, objects, option) - else - (objects = objects.order_by(option, params[:direction])) rescue nil - end - elsif object_class.relations.include?(option) - case object_class.relations[option].macro - when :references_one - a = Array.new - objects.each { |object| a << [get_string_value_from_object(object), object] } - sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse! - objects = sorted.collect {|x| x[1] } - when :references_many, :references_and_referenced_in_many - objects = get_objects_from_self(object_class, objects, option) - when :referenced_in - objects = get_objects_from_referenced_objects(object_class.relations[option].class_name.constantize, objects, "#{option}_id") - end - elsif option.eql?('tags') - tag_array = @module_app.tags.inject([]){ |result, value| - result << [value.name, value] - } - params[:direction].eql?('asc') ? tag_array.sort : tag_array.sort.reverse! - sorted_objects = Array.new - tag_array.each do |x| - taggings = x[1].taggings - taggings.each {|tagging| sorted_objects << tagging.taggable } - end - # debugger - sorted_objects.flatten! - sorted_objects.uniq! - objects = get_with_nil(objects, option, sorted_objects) - end - end - end - if @filter - @filter.each do |key, value| - case key - when 'status' - a = Array.new - objects.each do |object| - value.each do |v| - a << object if object[v] - end - end - objects = a.uniq - when 'categories' - a = Array.new - objects.each do |object| - a << object if (value.include?(object.send("#{object.class.to_s.underscore}_category").id.to_s) rescue nil) - end - objects = a.uniq - when 'tags' - a = Array.new - objects.each do |object| - object.tags.each do |tag| - a << object if value.include?(tag.id.to_s) - end - end - objects = a.uniq - end if value.size > 0 - end - end - Kaminari.paginate_array(filter_authorized_objects(objects)).page(params[:page]).per(10) - end - - def get_string_value_from_object(object) - s = object.name_translations[I18n.locale.to_s] unless s rescue nil - s = object.title_translations[I18n.locale.to_s] unless s rescue nil - s = object.name unless s rescue nil - s = object.title unless s rescue nil - s.downcase rescue '' - end - - def get_objects_from_referenced_objects(object_class, objects, option) - referer_ids = objects.distinct(option) - referenced_objects = object_class.find(referer_ids) rescue nil - if referenced_objects - a = Array.new - referenced_objects.to_a.each { |referer| a << [get_string_value_from_object(referer), referer.id] } - sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse! - sorted_objects = sorted.collect {|x| objects.where(option => x[1]).entries } - sorted_objects.flatten! - sorted_objects.uniq! - get_with_nil(objects, option, sorted_objects) - else - objects - end - end - - def get_objects_from_self(object_class, objects, option) - referenced_class = object_class.relations[option].class_name.constantize - referenced_objects = referenced_class.all rescue nil - if referenced_objects - reverse_relation = nil - referenced_class.relations.each { |relation| reverse_relation = relation[1].name.to_s if relation[1].class_name.eql?(object_class.to_s) } - a = Array.new - referenced_objects.each { |referenced_object| a << [get_string_value_from_object(referenced_object), referenced_object] } - a.compact! - sorted = params[:direction].eql?('asc') ? a.sort : a.sort.reverse! - sorted_objects = Array.new - sorted.each {|x| sorted_objects << x[1].send(reverse_relation) } - sorted_objects.flatten! - sorted_objects.uniq! - get_with_nil(objects, option, sorted_objects) - else - objects - end - end - - def get_with_nil(objects, option, sorted_objects) - tmp = Array.new - objects.each { |object| tmp << [get_string_value_from_object(object), object] if (object.send(option).blank? || (object.send(option).size == 0 rescue nil)) } - sorted = params[:direction].eql?('asc') ? tmp.sort : tmp.sort.reverse! - sorted_tmp = sorted.collect {|a| a[1] } - a = params[:direction].eql?('asc') ? (sorted_tmp + sorted_objects) : (sorted_objects + sorted_tmp) - a.flatten - end - - - def get_viewable(object_class, query=nil) - objects = get_objects(object_class,query).order_by(:created_at, :desc) - Kaminari.paginate_array(objects).page(params[:page]).per(10) - end - - def get_objects(object_class, query=nil) - object_class = object_class.classify.constantize - # debugger - # a=1 - if query - objects = object_class.where(query) - else - objects = object_class.all - end - objects - end - - def filter_authorized_objects(objects) - if(!is_admin? || !is_manager?) - objects.delete_if{ |object| - if object.is_pending == true - if check_permission(:manager) - object.create_user_id != current_user.id - else - !object.send("#{object.class.to_s.underscore}_category").authed_users('fact_check').include?(current_user) rescue false - end - else - false - end - } - end - objects - end - -end \ No newline at end of file +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index afd43d63..2c538cd4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,7 +14,7 @@ module ApplicationHelper def check_user_role_enable(attribute_fields) @user.attribute_values.collect{|t| attribute_fields.include?(t.attribute_field) }.include?(true) rescue false end - + def show_attribute_value(value) if value.kind_of? Hash result = [] @@ -29,7 +29,7 @@ module ApplicationHelper u = nil User.without_callback(:create, :before, :initialize_desktop) do u = User.create(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(99)}@example.com") - end + end u.admin = false u.save(:validate => false) u @@ -57,24 +57,24 @@ module ApplicationHelper def flash_messages return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)} - formatted_messages = messages.map do |type| + formatted_messages = messages.map do |type| content_tag :div, :class => type.to_s do message_for_item(flash[type], flash["#{type}_item".to_sym]) end end raw(formatted_messages.join) end - + def link_back(custom_class=nil) case custom_class when nil - link_to t('back'), get_go_back, :class => 'nav' + link_to t('back'), get_go_back, :class => 'nav' else - link_to t('back'), get_go_back, :class => custom_class + link_to t('back'), get_go_back, :class => custom_class end - + end - + # Clean the link back def get_go_back begin @@ -115,28 +115,28 @@ module ApplicationHelper message % item end end - + def add_attribute(partial, f, attribute) new_object = f.object.send(attribute).build fields = f.fields_for(attribute, new_object, :child_index => "new_#{attribute}") do |f| render :partial => partial, :object => new_object, :locals => {:f => f} end end - + def active_for_ob_auths_object(object_class,field = :object_auth_id) unless active_for_action("object_auths_new_interface","setting").nil? ob_auth = ObjectAuth.find params[field] ob_auth.obj_authable_type == object_class.to_s ? 'active' : nil end end - + def active_for_ob_auth(ob_auth_title,field = :object_auth_id) unless active_for_action("module_apps_new_interface","setting").nil? oa_auth = ObjectAuth.find params[field] oa_auth.title == ob_auth_title ? 'active' : nil end end - + def active_for_app_auth(app_title ='', opt={:controller_name => 'module_apps_new_interface',:action_name=>'setting',:field => :module_app_id}) unless active_for_action(opt[:controller_name],opt[:action_name]).nil? app = ModuleApp.find params[opt[:field]] @@ -145,7 +145,7 @@ module ApplicationHelper nil end end - + def active_for_controllers(*controller_names) (controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? 'active' : nil end @@ -153,11 +153,11 @@ module ApplicationHelper def visible_for_controllers(*controller_names) (controller_names.include?(controller.controller_name) || controller_names.include?(request.fullpath)) ? '' : 'hide' end - + def active_for_action(controller_name, action_name) ((controller.controller_name.eql?(controller_name) || request.fullpath.eql?(controller_name)) && controller.action_name.eql?(action_name)) ? 'active' : nil end - + def page_metas(page) tmp_meta = {} metas = '' @@ -186,11 +186,11 @@ module ApplicationHelper res << page_title end res << "\n" - end + end def page_stylesheets(page, edit=nil) stylesheets = '' - unless edit + unless edit stylesheets << "\n" stylesheets << "\n" stylesheets << "\n" @@ -199,9 +199,9 @@ module ApplicationHelper stylesheets << "\n" stylesheets << "\n" stylesheets << "\n" - stylesheets << "\n" - stylesheets << "\n" - stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" + stylesheets << "\n" stylesheets << "\n" if page.design.css_default theme = page.design.themes.detect{ |d| d.id == page.theme_id } stylesheets << "\n" if theme @@ -235,9 +235,9 @@ module ApplicationHelper end def at_least_module_manager - is_manager? || is_admin? + is_manager? || is_admin? end - + def dislpay_view_count(object) "#{t(:view_count)}: #{object.view_count}" end @@ -303,4 +303,12 @@ module ApplicationHelper "http://#{request.host}:2#{site_number}00" end + def sortable(column, title = nil, options = {}) + options[:remote] ||= true + title ||= column.titleize + css_class = column.to_s == params[:sort] ? "current #{params[:direction]}" : 'asc' + direction = column.to_s == params[:sort] && params[:direction] == 'asc' ? 'desc' : 'asc' + link_to title, params.merge({direction: direction, sort: column, sort_options: column}), {:class => "#{css_class} sortable", :remote => options[:remote]} + end + end diff --git a/app/models/mongoid/sortable.rb b/app/models/mongoid/sortable.rb new file mode 100644 index 00000000..1e7302b8 --- /dev/null +++ b/app/models/mongoid/sortable.rb @@ -0,0 +1,34 @@ +module Mongoid + module Sortable + extend ActiveSupport::Concern + + included do + field :sort_number, type: Integer + + after_initialize :set_sort_number + end + + module ClassMethods + def default_sort(sorted = true) + if !sorted + asc(:sort_number) + else + asc + end + end + end + + private + + def set_sort_number + if self.sort_number.nil? + last_record = self.class.desc(:sort_number).first + if last_record + self.sort_number = (last_record.sort_number + 10) / 10 * 10 + else + self.sort_number = 10 + end + end + end + end +end diff --git a/config/locales/mobile.zh_tw.yml b/config/locales/mobile.zh_tw.yml index 76f96140..84c32558 100644 --- a/config/locales/mobile.zh_tw.yml +++ b/config/locales/mobile.zh_tw.yml @@ -10,4 +10,4 @@ zh_tw: language: 語言 location: 地理位置 location_description: '

本大學

302新竹縣竹北市嘉豐南路二段101號' - page: 頁面 \ No newline at end of file + page: 頁面 diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 7dd3d89f..17ba9402 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -133,7 +133,7 @@ zh_tw: date: calendar: 紀年法 format: 格式 - minguo_calendar: + minguo_calendar: after: 民國 before: 民前 first_year: 民國元年 @@ -200,7 +200,7 @@ zh_tw: errors: at_least_one: 至少擁有一個值 field: 欄位 - file: + file: size: 檔案大小 type: 檔案類型 upload: F上傳檔案 @@ -344,7 +344,7 @@ zh_tw: registered: 已註冊 rejected: 拒絕 rejected_reason: 拒絕原因:' - rejected_reason_empty: "拒絕核准, 沒有參考資訊" + rejected_reason_empty: "拒絕核准, 沒有參考資訊" related_links: 相關連結 role: 身份 role_field: 身份欄位 @@ -484,7 +484,7 @@ zh_tw: female: 女性 unknown: 未知 last_name: 姓氏 - office_tel: 辦公室電話 + office_tel: 辦公室電話 office_tel_note: 將公開於網頁 sid: 編號 sid_note: 教職員工編號或學生學號 @@ -503,3 +503,4 @@ zh_tw: visitors_this_year: 今年造訪人次 visitors_today: 今日造訪人次 yes_: "是" + sort_number: 排序數 diff --git a/vendor/built_in_modules/archive/app/controllers/panel/archive/widget/archive_files_controller.rb b/vendor/built_in_modules/archive/app/controllers/panel/archive/widget/archive_files_controller.rb index 0379a371..abfa7d93 100644 --- a/vendor/built_in_modules/archive/app/controllers/panel/archive/widget/archive_files_controller.rb +++ b/vendor/built_in_modules/archive/app/controllers/panel/archive/widget/archive_files_controller.rb @@ -1,47 +1,52 @@ class Panel::Archive::Widget::ArchiveFilesController < OrbitWidgetController + include AdminHelper def initialize super @app_title = 'archive_files' end - + def index @part = PagePart.find(params[:part_id]) - + if @part.widget_data_count @page_num = @part.widget_data_count else @page_num = 4 end - + if @part.widget_field @widget_fields = @part.widget_field else @widget_fields = [] end - + @widget_style = @part.widget_style - + @category_id = @part.category date_now = Time.now if !params[:category_id].blank? - @archive_files = ArchiveFile.all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num) + @archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:archive_file_category_id => params[:category_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num) @archive_file_categorys = ArchiveFileCategory.any_in(:_id => params[:category_id]).excludes('disable' => true) elsif !params[:tag_id].blank? - @archive_files = ArchiveFile.all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num) + @archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.any_in(:tagged_ids => params[:tag_id]).merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top ).page( params[:page_main] ).per(@page_num) get_categorys else - @archive_files = ArchiveFile.all.can_display.merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top, :created_at ).page( params[:page_main] ).per(@page_num) + @archive_files = ArchiveFile.default_sort(params[:sort]).all.can_display.merge(ArchiveFileCategory.excludes('disable' => true)).desc( :is_top).page( params[:page_main] ).per(@page_num) get_categorys end + if params[:sort] + @archive_files = get_sorted_and_filtered('archive_file', nil, @archive_files) + end + end - + def get_categorys @archive_file_categorys = ArchiveFileCategory.excludes('disable' => true) end - + end diff --git a/vendor/built_in_modules/archive/app/models/archive_file.rb b/vendor/built_in_modules/archive/app/models/archive_file.rb index 0b857757..780944d6 100644 --- a/vendor/built_in_modules/archive/app/models/archive_file.rb +++ b/vendor/built_in_modules/archive/app/models/archive_file.rb @@ -4,7 +4,8 @@ class ArchiveFile include Mongoid::Document include Mongoid::Timestamps include Mongoid::MultiParameterAttributes - + include Mongoid::Sortable + BelongsToCategory = :archive_file_category include OrbitCoreLib::BelongsToCategoryMayDisable @@ -14,26 +15,26 @@ class ArchiveFile taggable field :title, localize: true - + # has_and_belongs_to_many :tags, :class_name => "ArchiveTag" - + field :create_user_id field :update_user_id - - field :is_top, :type => Boolean, :default => false - field :is_hot, :type => Boolean, :default => false - field :is_hidden, :type => Boolean, :default => false - + + field :is_top, :type => Boolean, :default => false + field :is_hot, :type => Boolean, :default => false + field :is_hidden, :type => Boolean, :default => false + scope :can_display,where(is_hidden: false) - + # belongs_to :archive_file_category has_many :archive_file_multiples, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true - + validates :title, :at_least_one => true - + after_save :save_archive_file_multiples # searchable do @@ -47,17 +48,17 @@ class ArchiveFile # end def self.search( category_id = nil ) - + if category_id.to_s.size > 0 find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :title ) else - + find(:all).desc( :is_top, :title) - + end - + end @@ -75,7 +76,7 @@ class ArchiveFile def get_file_icon( file_data ) file_icon = "#{file_data.split('.')[-1]}".html_safe end - + def save_archive_file_multiples self.archive_file_multiples.each do |t| if t.should_destroy @@ -83,5 +84,5 @@ class ArchiveFile end end end - -end \ No newline at end of file + +end diff --git a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_archive_file.html.erb b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_archive_file.html.erb index a746d595..358f8f94 100644 --- a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_archive_file.html.erb +++ b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_archive_file.html.erb @@ -4,6 +4,9 @@ <%= check_box_tag 'to_delete[]', archive_file.id, false, :class => "checkbox_in_list" %> <% end -%> + + <%= archive_file.sort_number %> +
diff --git a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_form.html.erb b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_form.html.erb index 5f8058f9..01bd76e0 100644 --- a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_form.html.erb +++ b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_form.html.erb @@ -3,9 +3,9 @@ <%= f.error_messages %> - +
- +
@@ -31,51 +31,54 @@ <%= tag.name %> <% end %>
-
- +
+
- - + +
- + <%= f.label :category %> <%= f.select :archive_file_category_id, @archive_file_categorys.collect {|t| [ t.title, t.id ]} %> - + + <%= f.label :sort_number %> + <%= f.text_field :sort_number %> + - +
- + <% @site_valid_locales.each_with_index do |locale, i| %> - +
">
<%= f.label :title %> <%= f.fields_for :title_translations do |f| %> <%= I18nVariable.from_locale(locale) %> <%= f.text_field locale, :class=>'post-title', :value => (@archive_file.title_translations[locale] rescue nil) %> - <% end %> + <% end %>
- +
<% end %> - +
- - + +
- +
- + @@ -94,38 +97,38 @@ - + - + <% @archive_file.archive_file_multiples.asc(:_id).each_with_index do |archive_file_multiple, i| %> <%= f.fields_for :archive_file_multiples, archive_file_multiple do |f| %> <%= render :partial => 'form_file', :object => archive_file_multiple, :locals => {:f => f, :i => i} %> <% end %> - <% end %> + <% end %>
- +
- +
- - + +
- + - - + +
<%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %> <%= hidden_field_tag 'filter', params[:filter] %> <%= f.submit t('submit'), :class=>'btn btn-primary' %> - <%= link_to t('cancel'), get_go_back, :class=>"btn" %> + <%= link_to t('cancel'), get_go_back, :class=>"btn" %>
- +
- - + + <% content_for :page_specific_javascript do %> <%= javascript_include_tag "archive_form" %> @@ -136,7 +139,7 @@ $(this).prev().attr('value', parseInt(new_id) + 1); $(this).parents('table').append(("<%= escape_javascript(add_attribute 'form_file', f, :archive_file_multiples) %>").replace(old_id, new_id)); }); - + $('.archive_file_multiples_block a.delete').live('click', function(){ $(this).parents('.list_item').remove(); }); @@ -148,4 +151,4 @@ <% end %> - \ No newline at end of file + diff --git a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_sort_headers.html.erb b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_sort_headers.html.erb index b02c74ea..34552e76 100644 --- a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_sort_headers.html.erb +++ b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/_sort_headers.html.erb @@ -1,5 +1,6 @@ <%= render_sort_bar(true, delete_panel_archive_back_end_archive_files_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), + ['sort_number', 'sort_number', 'span1', :sort_number], ['status', ['is_top', 'is_hot', 'is_hidden'], 'span1', :status], ['category', 'archive_file_category', 'span2', :category], ['title', 'title','span3', :title], - ['tags', 'tags', 'span2', :tags]).html_safe %> \ No newline at end of file + ['tags', 'tags', 'span2', :tags]).html_safe %> diff --git a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/index.html.erb b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/index.html.erb index ac5bae6c..684a7962 100644 --- a/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/index.html.erb +++ b/vendor/built_in_modules/archive/app/views/panel/archive/back_end/archive_files/index.html.erb @@ -3,6 +3,7 @@ + @@ -20,4 +21,4 @@
<%= paginate @archive_files, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>
- \ No newline at end of file + diff --git a/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/_index.html.erb b/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/_index.html.erb index 2af42aa0..9f752f1e 100644 --- a/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/_index.html.erb +++ b/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/_index.html.erb @@ -8,13 +8,12 @@
- + - + - <% @archive_files.each_with_index do |post,i| %> class="even" <% end %>> @@ -22,7 +21,7 @@
<% if !post.archive_file_multiples.blank? %>
    - <% post.archive_file_multiples.asc(:_id).each do | afile | %> + <% post.archive_file_multiples.asc(:_id).each do | afile | %> <% if afile.file.file and afile.choose_lang_display(I18n.locale.to_s) %>
  1. <%= link_to afile.file_title, afile.file.url, {:target => '_blank', :title => afile.file_title, :class => "o-archives-file"} %> @@ -43,7 +42,7 @@
<%= t("archive.Title")%><%= sortable(:title, t("archive.Title"))%> <%= t("archive.Files")%><%= t("archive.Category")%><%= sortable(:archive_file_category, t("archive.Category"))%>
<%= post.title %>
-
+
<% if !params[:category_id].blank? %> <%= link_to t(:more_plus), panel_archive_front_end_archive_files_path(:category_id => @part.category) %> <% else %> @@ -72,7 +71,7 @@ <% if !post.archive_file_multiples.blank? %>
    - <% post.archive_file_multiples.asc(:_id).each do | afile | %> + <% post.archive_file_multiples.asc(:_id).each do | afile | %> <% if afile.file.file and afile.choose_lang_display(I18n.locale.to_s) %>
  1. <%= link_to afile.file_title, afile.file.url, {:target => '_blank', :title => afile.file_title, :class => "o-archives-file"} %> @@ -95,5 +94,5 @@
- + <% end %> diff --git a/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/index.js.erb b/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/index.js.erb index e1be79eb..a0afb16f 100644 --- a/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/index.js.erb +++ b/vendor/built_in_modules/archive/app/views/panel/archive/widget/archive_files/index.js.erb @@ -1 +1 @@ -$('#bulletin_widget').html("<%= j render 'index' %>") \ No newline at end of file +$('#archive_file_widget').html("<%= j render 'index' %>") diff --git a/vendor/built_in_modules/archive/config/locales/zh_tw.yml b/vendor/built_in_modules/archive/config/locales/zh_tw.yml index af2232e4..eeb190b5 100644 --- a/vendor/built_in_modules/archive/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/archive/config/locales/zh_tw.yml @@ -8,4 +8,8 @@ zh_tw: frontend: archive: 檔案室前台 widget: - index: 檔案室Widget \ No newline at end of file + index: 檔案室Widget + mongoid: + attributes: + archive_file: + sort_number: 排序數