From 66aa72d210ccddacc46aaebf427d079e69710e2b Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Thu, 23 Oct 2014 18:49:14 +0800 Subject: [PATCH 01/33] Signed-off-by: alan <547533434@qq.com> --- app/controllers/my_controller.rb | 564 ++++++++-------- app/views/activities/index.html.erb | 202 +++--- app/views/contestnotifications/index.html.erb | 300 ++++----- app/views/contests/index.html.erb | 106 +-- .../courses/_join_private_course.html.erb | 150 ++--- app/views/settings/_projects.html.erb | 52 +- app/views/welcome/contest.html.erb | 602 +++++++++--------- app/views/welcome/index.html.erb | 384 +++++------ app/views/wiki/diff.html.erb | 66 +- app/views/wiki/edit.html.erb | 124 ++-- .../lib/acts_as_attachable.rb | 340 +++++----- public/javascripts/attachments.js | 466 +++++++------- 12 files changed, 1678 insertions(+), 1678 deletions(-) diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 69dda5be0..fa2784f22 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -1,282 +1,282 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -#+ -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -class MyController < ApplicationController - layout "users_base" - before_filter :require_login - - helper :issues - helper :users - helper :custom_fields - - BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, - 'issuesreportedbyme' => :label_reported_issues, - 'issueswatched' => :label_watched_issues, - 'news' => :label_news_latest, - 'calendar' => :label_calendar, - 'documents' => :label_document_plural, - 'timelog' => :label_spent_time - }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze - - DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'], - 'right' => ['issuesreportedbyme'] - }.freeze - - def index - - page - render :action => 'page' - end - - # Show user's page - def page - @user = User.current - @Issues= Issue.visible.open. - where(:assigned_to_id => ([User.current.id] + User.current.group_ids)) - @limit = 10 - @feedback_count = @Issues.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @curse_attachments = @Issues[@offset, @limit] - - @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT - end - - def page2 - @limit = 10 - @user = User.current - @Issues= Issue.visible.open. - where(:assigned_to_id => ([User.current.id] + User.current.group_ids)) - @feedback_count = @Issues.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @curse_attachments = @Issues[@offset, @limit] - @state = false - @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT - respond_to do |format| - format.js - end - end - - # Edit user's account - def account - @user = User.current - lg=@user.login - @pref = @user.pref - diskfile = disk_filename('User', @user.id) - diskfile1 = diskfile + 'temp' - if request.post? - @user.safe_attributes = params[:user] - @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - @user.login = params[:login] - unless @user.user_extensions.nil? - if @user.user_extensions.identity == 2 - @user.firstname = params[:enterprise_name] - end - end - - @se = @user.extensions - @se.school_id = params[:occupation] if params[:occupation] - @se.gender = params[:gender] - @se.location = params[:province] if params[:province] - @se.location_city = params[:city] if params[:city] - @se.identity = params[:identity].to_i if params[:identity] - @se.technical_title = params[:technical_title] if params[:technical_title] - @se.student_id = params[:no] if params[:no] - - if @user.save && @se.save - # 头像保存 - if File.exist?(diskfile1) - if File.exist?(diskfile) - File.delete(diskfile) - end - File.open(diskfile1, "rb") do |f| - buffer = f.read(10) - if buffer != "DELETE" - File.open(diskfile1, "rb") do |f1| - File.open(diskfile, "wb") do |f| - buffer = "" - while (buffer = f1.read(8192)) - f.write(buffer) - end - end - end - - # File.rename(diskfile + 'temp',diskfile); - end - end - end - - # 确保文件被删除 - if File.exist?(diskfile1) - File.delete(diskfile1) - end - - @user.pref.save - @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) - set_language_if_valid @user.language - flash[:notice] = l(:notice_account_updated) - redirect_to user_url(@user) - return - else - # 确保文件被删除 - if File.exist?(diskfile1) - File.delete(diskfile1) - end - @user.login = lg - end - else - # 确保文件被删除 - if File.exist?(diskfile1) - File.delete(diskfile1) - end - end - end - - # Destroys user's account - def destroy - @user = User.current - unless @user.own_account_deletable? - redirect_to my_account_url - return - end - - if request.post? && params[:confirm] - @user.destroy - if @user.destroyed? - logout_user - flash.now[:notice] = l(:notice_account_deleted) - end - redirect_to home_url - end - end - - # Manage user's password - def password - @user = User.current - unless @user.change_password_allowed? - flash.now[:error] = l(:notice_can_t_change_password) - redirect_to my_account_url - return - end - if request.post? - if @user.check_password?(params[:password]) - @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] - - if @user.save - flash.now[:notice] = l(:notice_account_password_updated) - redirect_to my_account_url - end - else - flash.now[:error] = l(:notice_account_wrong_password) - end - end - end - - # Create a new feeds key - def reset_rss_key - if request.post? - if User.current.rss_token - User.current.rss_token.destroy - User.current.reload - end - User.current.rss_key - flash[:notice] = l(:notice_feeds_access_key_reseted) - end - redirect_to my_account_url - end - - # Create a new API key - def reset_api_key - if request.post? - if User.current.api_token - User.current.api_token.destroy - User.current.reload - end - User.current.api_key - flash[:notice] = l(:notice_api_access_key_reseted) - end - redirect_to my_account_url - end - - # User's page layout configuration - def page_layout - @user = User.current - @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup - @block_options = [] - BLOCKS.each do |k, v| - unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)} - @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] - end - end - end - - # Add a block to user's page - # The block is added on top of the page - # params[:block] : id of the block to add - def add_block - block = params[:block].to_s.underscore - if block.present? && BLOCKS.key?(block) - @user = User.current - layout = @user.pref[:my_page_layout] || {} - # remove if already present in a group - %w(top left right).each {|f| (layout[f] ||= []).delete block } - # add it on top - layout['top'].unshift block - @user.pref[:my_page_layout] = layout - @user.pref.save - end - redirect_to my_page_layout_url - end - - # Remove a block to user's page - # params[:block] : id of the block to remove - def remove_block - block = params[:block].to_s.underscore - @user = User.current - # remove block in all groups - layout = @user.pref[:my_page_layout] || {} - %w(top left right).each {|f| (layout[f] ||= []).delete block } - @user.pref[:my_page_layout] = layout - @user.pref.save - redirect_to my_page_layout_url - end - - # Change blocks order on user's page - # params[:group] : group to order (top, left or right) - # params[:list-(top|left|right)] : array of block ids of the group - def order_blocks - group = params[:group] - @user = User.current - if group.is_a?(String) - group_items = (params["blocks"] || []).collect(&:underscore) - group_items.each {|s| s.sub!(/^block_/, '')} - if group_items and group_items.is_a? Array - layout = @user.pref[:my_page_layout] || {} - # remove group blocks if they are presents in other groups - %w(top left right).each {|f| - layout[f] = (layout[f] || []) - group_items - } - layout[group] = group_items - @user.pref[:my_page_layout] = layout - @user.pref.save - end - end - render :nothing => true - end -end +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +#+ +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class MyController < ApplicationController + layout "users_base" + before_filter :require_login + + helper :issues + helper :users + helper :custom_fields + + BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, + 'issuesreportedbyme' => :label_reported_issues, + 'issueswatched' => :label_watched_issues, + 'news' => :label_news_latest, + 'calendar' => :label_calendar, + 'documents' => :label_document_plural, + 'timelog' => :label_spent_time + }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze + + DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'], + 'right' => ['issuesreportedbyme'] + }.freeze + + def index + + page + render :action => 'page' + end + + # Show user's page + def page + @user = User.current + @Issues= Issue.visible.open. + where(:assigned_to_id => ([User.current.id] + User.current.group_ids)) + @limit = 10 + @feedback_count = @Issues.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @curse_attachments = @Issues[@offset, @limit] + + @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT + end + + def page2 + @limit = 10 + @user = User.current + @Issues= Issue.visible.open. + where(:assigned_to_id => ([User.current.id] + User.current.group_ids)) + @feedback_count = @Issues.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @curse_attachments = @Issues[@offset, @limit] + @state = false + @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT + respond_to do |format| + format.js + end + end + + # Edit user's account + def account + @user = User.current + lg=@user.login + @pref = @user.pref + diskfile = disk_filename('User', @user.id) + diskfile1 = diskfile + 'temp' + if request.post? + @user.safe_attributes = params[:user] + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + @user.login = params[:login] + unless @user.user_extensions.nil? + if @user.user_extensions.identity == 2 + @user.firstname = params[:enterprise_name] + end + end + + @se = @user.extensions + @se.school_id = params[:occupation] if params[:occupation] + @se.gender = params[:gender] + @se.location = params[:province] if params[:province] + @se.location_city = params[:city] if params[:city] + @se.identity = params[:identity].to_i if params[:identity] + @se.technical_title = params[:technical_title] if params[:technical_title] + @se.student_id = params[:no] if params[:no] + + if @user.save && @se.save + # 头像保存 + if File.exist?(diskfile1) + if File.exist?(diskfile) + File.delete(diskfile) + end + File.open(diskfile1, "rb") do |f| + buffer = f.read(10) + if buffer != "DELETE" + File.open(diskfile1, "rb") do |f1| + File.open(diskfile, "wb") do |f| + buffer = "" + while (buffer = f1.read(8192)) + f.write(buffer) + end + end + end + + # File.rename(diskfile + 'temp',diskfile); + end + end + end + + # 确保文件被删除 + if File.exist?(diskfile1) + File.delete(diskfile1) + end + + @user.pref.save + @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) + set_language_if_valid @user.language + flash[:notice] = l(:notice_account_updated) + redirect_to user_url(@user) + return + else + # 确保文件被删除 + if File.exist?(diskfile1) + File.delete(diskfile1) + end + @user.login = lg + end + else + # 确保文件被删除 + if File.exist?(diskfile1) + File.delete(diskfile1) + end + end + end + + # Destroys user's account + def destroy + @user = User.current + unless @user.own_account_deletable? + redirect_to my_account_url + return + end + + if request.post? && params[:confirm] + @user.destroy + if @user.destroyed? + logout_user + flash.now[:notice] = l(:notice_account_deleted) + end + redirect_to home_url + end + end + + # Manage user's password + def password + @user = User.current + unless @user.change_password_allowed? + flash.now[:error] = l(:notice_can_t_change_password) + redirect_to my_account_url + return + end + if request.post? + if @user.check_password?(params[:password]) + @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] + + if @user.save + flash.now[:notice] = l(:notice_account_password_updated) + redirect_to my_account_url + end + else + flash.now[:error] = l(:notice_account_wrong_password) + end + end + end + + # Create a new feeds key + def reset_rss_key + if request.post? + if User.current.rss_token + User.current.rss_token.destroy + User.current.reload + end + User.current.rss_key + flash[:notice] = l(:notice_feeds_access_key_reseted) + end + redirect_to my_account_url + end + + # Create a new API key + def reset_api_key + if request.post? + if User.current.api_token + User.current.api_token.destroy + User.current.reload + end + User.current.api_key + flash[:notice] = l(:notice_api_access_key_reseted) + end + redirect_to my_account_url + end + + # User's page layout configuration + def page_layout + @user = User.current + @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup + @block_options = [] + BLOCKS.each do |k, v| + unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)} + @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] + end + end + end + + # Add a block to user's page + # The block is added on top of the page + # params[:block] : id of the block to add + def add_block + block = params[:block].to_s.underscore + if block.present? && BLOCKS.key?(block) + @user = User.current + layout = @user.pref[:my_page_layout] || {} + # remove if already present in a group + %w(top left right).each {|f| (layout[f] ||= []).delete block } + # add it on top + layout['top'].unshift block + @user.pref[:my_page_layout] = layout + @user.pref.save + end + redirect_to my_page_layout_url + end + + # Remove a block to user's page + # params[:block] : id of the block to remove + def remove_block + block = params[:block].to_s.underscore + @user = User.current + # remove block in all groups + layout = @user.pref[:my_page_layout] || {} + %w(top left right).each {|f| (layout[f] ||= []).delete block } + @user.pref[:my_page_layout] = layout + @user.pref.save + redirect_to my_page_layout_url + end + + # Change blocks order on user's page + # params[:group] : group to order (top, left or right) + # params[:list-(top|left|right)] : array of block ids of the group + def order_blocks + group = params[:group] + @user = User.current + if group.is_a?(String) + group_items = (params["blocks"] || []).collect(&:underscore) + group_items.each {|s| s.sub!(/^block_/, '')} + if group_items and group_items.is_a? Array + layout = @user.pref[:my_page_layout] || {} + # remove group blocks if they are presents in other groups + %w(top left right).each {|f| + layout[f] = (layout[f] || []) - group_items + } + layout[group] = group_items + @user.pref[:my_page_layout] = layout + @user.pref.save + end + end + render :nothing => true + end +end diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb index ef52a164d..694af0a14 100644 --- a/app/views/activities/index.html.erb +++ b/app/views/activities/index.html.erb @@ -1,101 +1,101 @@ -
- <%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %> -
-- - <%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %> - | -
-
|
-
- <% @activity.event_types.each do |t| %>
- <%= check_box_tag "show_#{t}", 1, @activity.scope.include?(t) %>
-
-
- <% end %>
-
- -
-<% end %> -<%= hidden_field_tag('user_id', params[:user_id]) unless params[:user_id].blank? %> -- <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> -
-<% end %> -<% end %> - -<% html_title(l(:label_activity), @author) -%> ++ <%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %> +
++ + <%= image_tag(url_to_avatar(e.event_author), :class => "avatar") %> + | +
+
|
+
+ <% @activity.event_types.each do |t| %>
+ <%= check_box_tag "show_#{t}", 1, @activity.scope.include?(t) %>
+
+
+ <% end %>
+
+ +
+<% end %> +<%= hidden_field_tag('user_id', params[:user_id]) unless params[:user_id].blank? %> ++ <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> +
+<% end %> +<% end %> + +<% html_title(l(:label_activity), @author) -%> diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb index a4dacd523..cf7ebe508 100644 --- a/app/views/contestnotifications/index.html.erb +++ b/app/views/contestnotifications/index.html.erb @@ -1,151 +1,151 @@ - - - - <%= l(:label_notification) %> - -<% if User.current.logged? && (User.current.admin? ||User.current == @contest.author) %> - <%= link_to(l(:bale_news_notice), - new_contest_contestnotification_path(@contest), - :class => 'icon icon-add', - :onclick => 'showAndScrollTo("add-contestnotifications", "contestnotifications_title"); return false;') %> -<% end %> -<% if @contest %> - -- - <%= l(:label_bids_reward_method) %> - - <%= @contest.budget%> - - -
-- <%= link_to image_tag(url_to_avatar(contestnotifications.author), :class => "avatar"), user_path(contestnotifications.author) %> - | -
-
|
-
+ + <%= l(:label_bids_reward_method) %> + + <%= @contest.budget%> + + +
++ <%= link_to image_tag(url_to_avatar(contestnotifications.author), :class => "avatar"), user_path(contestnotifications.author) %> + | +
+
|
+
<%= l(:label_contest_innovate) %> | -<%= l(:label_user_location) %> : | -- <% if User.current.logged? %> - <% unless User.current.user_extensions.identity == 1 %> - <%= link_to(l(:label_newtype_contest), new_contest_contests_path, :class => 'icon icon-add', :target => "_blank") %> - - <% end %> - <% end %> - | -
-
- <%= text_field_tag 'name', params[:name], :size => 30 %>
- <%= hidden_field_tag 'project_type', params[:project_type] %>
- <%= submit_tag l(:label_search), :class => "enterprise", :name => "contests_search" %>
-
- |
-
- - <%= link_to request.host()+"/contests", contests_path %> - - - | -- <%=link_to l(:field_homepage), home_path %> > - <%=link_to l(:label_contest_innovate), :controller => 'contests', :action => 'index' %> - - | -
<%= l(:label_contest_innovate) %> | +<%= l(:label_user_location) %> : | ++ <% if User.current.logged? %> + <% unless User.current.user_extensions.identity == 1 %> + <%= link_to(l(:label_newtype_contest), new_contest_contests_path, :class => 'icon icon-add', :target => "_blank") %> + + <% end %> + <% end %> + | +
+
+ <%= text_field_tag 'name', params[:name], :size => 30 %>
+ <%= hidden_field_tag 'project_type', params[:project_type] %>
+ <%= submit_tag l(:label_search), :class => "enterprise", :name => "contests_search" %>
+
+ |
+
+ + <%= link_to request.host()+"/contests", contests_path %> + + + | ++ <%=link_to l(:field_homepage), home_path %> > + <%=link_to l(:label_contest_innovate), :controller => 'contests', :action => 'index' %> + + | +
只要持有课程ID和密码,就可快速加入所在课程。课程页面搜索不到的私有课程只能从此通道进入哦!
-只要持有课程ID和密码,就可快速加入所在课程。课程页面搜索不到的私有课程只能从此通道进入哦!
+- <%= setting_check_box :default_projects_public %> -
- -- <%= setting_multiselect(:default_projects_modules, - Redmine::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, :prefix => "project_module_"), m.to_s]}) %> -
- -- <%= setting_multiselect(:default_projects_tracker_ids, Tracker.sorted.all.collect {|t| [t.name, t.id.to_s]}) %> -
- -- <%= setting_check_box :sequential_project_identifiers %> -
- - -+ <%= setting_check_box :default_projects_public %> +
+ ++ <%= setting_multiselect(:default_projects_modules, + Redmine::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, :prefix => "project_module_"), m.to_s]}) %> +
+ ++ <%= setting_multiselect(:default_projects_tracker_ids, Tracker.sorted.all.collect {|t| [t.name, t.id.to_s]}) %> +
+ ++ <%= setting_check_box :sequential_project_identifiers %> +
+ + +<%= l(:label_no_ftapplication) %>
- - <% end %> -<%= l(:label_no_ftapplication) %>
+ + <% end %> +- <%= l(:label_version) %> - <%= link_to @diff.content_from.version, :action => 'show', :id => @page.title, :project_id => @page.project, :version => @diff.content_from.version %> - - (<%= @diff.content_from.author ? @diff.content_from.author.name : l(:label_user_anonymous)%>, - <%= format_time(@diff.content_from.updated_on) %>) - -→ - <%= l(:label_version) %> - <%= link_to @diff.content_to.version, :action => 'show', - :id => @page.title, :project_id => @page.project, - :version => @diff.content_to.version %> - / - <%= @page.content.version %> - - (<%= @diff.content_to.author ? link_to_user(@diff.content_to.author.name) : l(:label_user_anonymous)%>, - <%= format_time(@diff.content_to.updated_on) %>) - -
- -+ <%= l(:label_version) %> + <%= link_to @diff.content_from.version, :action => 'show', :id => @page.title, :project_id => @page.project, :version => @diff.content_from.version %> + + (<%= @diff.content_from.author ? @diff.content_from.author.name : l(:label_user_anonymous)%>, + <%= format_time(@diff.content_from.updated_on) %>) + +→ + <%= l(:label_version) %> + <%= link_to @diff.content_to.version, :action => 'show', + :id => @page.title, :project_id => @page.project, + :version => @diff.content_to.version %> + / + <%= @page.content.version %> + + (<%= @diff.content_to.author ? link_to_user(@diff.content_to.author.name) : l(:label_user_anonymous)%>, + <%= format_time(@diff.content_to.updated_on) %>) + +
+ +- <%=text_area_tag 'content[text]', @text, :required => true, :id => 'editor02', :cols => 100, :rows => 25 %> -
- -- - <%= fp.select :parent_id,content_tag('option', '', :value => '') + wiki_page_options_for_select(@wiki.pages.all(:include => :parent) - @page.self_and_descendants, @page.parent) %> -
- <% end %> - <% end %> - -- - <%= f.text_field :comments, :style => "width:75%;" %> -
-- - <%= render :partial => 'attachments/form' %> -
-- <%= submit_tag l(:button_save) %> -
- <%= wikitoolbar_for 'content_text' %> -<% end %> - -<% content_for :header_tags do %> - <%= robot_exclusion_tag %> -<% end %> -<% html_title @page.pretty_title %> +<%= wiki_page_breadcrumb(@page) %> + + ++ <%=text_area_tag 'content[text]', @text, :required => true, :id => 'editor02', :cols => 100, :rows => 25 %> +
+ ++ + <%= fp.select :parent_id,content_tag('option', '', :value => '') + wiki_page_options_for_select(@wiki.pages.all(:include => :parent) - @page.self_and_descendants, @page.parent) %> +
+ <% end %> + <% end %> + ++ + <%= f.text_field :comments, :style => "width:75%;" %> +
++ + <%= render :partial => 'attachments/form' %> +
++ <%= submit_tag l(:button_save) %> +
+ <%= wikitoolbar_for 'content_text' %> +<% end %> + +<% content_for :header_tags do %> + <%= robot_exclusion_tag %> +<% end %> +<% html_title @page.pretty_title %> diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index f0f06ee26..609b35415 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -1,170 +1,170 @@ -# Redmine - project management software -# Copyright (C) 2006-2013 Jean-Philippe Lang -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -module Redmine - module Acts - module Attachable - def self.included(base) - base.extend ClassMethods - end - - module ClassMethods - def acts_as_attachable(options = {}) - cattr_accessor :attachable_options - self.attachable_options = {} - attachable_options[:view_permission] = options.delete(:view_permission) || "view_#{self.name.pluralize.underscore}".to_sym - attachable_options[:delete_permission] = options.delete(:delete_permission) || "edit_#{self.name.pluralize.underscore}".to_sym - - has_many :attachments, options.merge(:as => :container, - :order => "#{Attachment.table_name}.created_on ASC, #{Attachment.table_name}.id ASC", - :dependent => :destroy) - send :include, Redmine::Acts::Attachable::InstanceMethods - before_save :attach_saved_attachments - end - end - - module InstanceMethods - def self.included(base) - base.extend ClassMethods - end - - def attachments_visible?(user=User.current) - if self.respond_to?(:project) - (respond_to?(:visible?) ? visible?(user) : true) && - user.allowed_to?(self.class.attachable_options[:view_permission], self.project) - else - return true - end - - end - - def attachments_deletable?(user=User.current) - if (self.has_attribute?(:course) ||self.has_attribute?(:course_id)) && self.course - #默认给予删除自己上传的附件的权限 - (respond_to?(:visible?) ? visible?(user) : true) && - (user.allowed_to?(self.class.attachable_options[:delete_permission], self.course) || (self.has_attribute?(:author_id) && self.author == user)) - else - #默认给予删除自己上传的附件的权限 - (respond_to?(:visible?) ? visible?(user) : true) && - (user.allowed_to?(self.class.attachable_options[:delete_permission], self.project) || (self.has_attribute?(:author_id) && self.author == user)) - end - end - - def saved_attachments - @saved_attachments ||= [] - end - - def unsaved_attachments - @unsaved_attachments ||= [] - end - - # 设置资源文件的公开属性 - # add by nwb - def set_attachment_public(res) - # 公开的资源判断他的父级的公开属性 - if res.is_public - if( (self.class.to_s=="Project" && self.is_public == false) || - (self.has_attribute?(:project) && self.project && self.project.is_public == false) || - (self.has_attribute?(:board) && self.board.project && self.board.project.is_public == false) || - (self.class.to_s=="HomeworkAttach" && self.bid.reward_type == 3) || - (self.class.to_s=="Course" && self.is_public == false) || - (self.has_attribute?(:course) && self.course && self.course.is_public == false) || - (self.has_attribute?(:board) && self.board.course && self.board.course.is_public == false) - ) - res.is_public = false - end - end - end - - def save_attachmentsex(attachments, author=User.current,attachment_type) - @curattachment_type = attachment_type - result = save_attachments(attachments,author) - result - end - - def save_attachments(attachments, author=User.current) - # 清除临时文件 - if attachments - tempAttach = attachments[:dummy] - if tempAttach && tempAttach[:file] - attachments.delete(:dummy) - end - end - - if attachments.is_a?(Hash) - attachments = attachments.stringify_keys - attachments = attachments.to_a.sort {|a, b| - if a.first.to_i > 0 && b.first.to_i > 0 - a.first.to_i <=> b.first.to_i - elsif a.first.to_i > 0 - 1 - elsif b.first.to_i > 0 - -1 - else - a.first <=> b.first - end - } - attachments = attachments.map(&:last) - end - if attachments.is_a?(Array) - attachments.each do |attachment| - if attachment.is_a?(Hash) - a = nil - file = attachment['file'] - token = attachment['token'] - t = file && file.size > 0 - if file && file.size > 0 - a = Attachment.create(:file => file, :author => author) - elsif token - a = Attachment.find_by_token_only(token) - if a - a.filename = attachment['filename'] unless attachment['filename'].blank? - a.content_type = attachment['content_type'] - end - end - end - if a && !attachment['is_public_checkbox'] - a.is_public = false - elsif a && attachment['is_public_checkbox'] - a.is_public = true - end - set_attachment_public(a) if a - next unless a - a.description = attachment['description'].to_s.strip - a.attachtype = @curattachment_type - if a.new_record? - unsaved_attachments << a - else - saved_attachments << a - end - end - end - {:files => saved_attachments, :unsaved => unsaved_attachments} - end - - def attach_saved_attachments - saved_attachments.each do |attachment| - self.attachments << attachment - end - end - - module ClassMethods - end - end - end - end -end +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module Redmine + module Acts + module Attachable + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + def acts_as_attachable(options = {}) + cattr_accessor :attachable_options + self.attachable_options = {} + attachable_options[:view_permission] = options.delete(:view_permission) || "view_#{self.name.pluralize.underscore}".to_sym + attachable_options[:delete_permission] = options.delete(:delete_permission) || "edit_#{self.name.pluralize.underscore}".to_sym + + has_many :attachments, options.merge(:as => :container, + :order => "#{Attachment.table_name}.created_on ASC, #{Attachment.table_name}.id ASC", + :dependent => :destroy) + send :include, Redmine::Acts::Attachable::InstanceMethods + before_save :attach_saved_attachments + end + end + + module InstanceMethods + def self.included(base) + base.extend ClassMethods + end + + def attachments_visible?(user=User.current) + if self.respond_to?(:project) + (respond_to?(:visible?) ? visible?(user) : true) && + user.allowed_to?(self.class.attachable_options[:view_permission], self.project) + else + return true + end + + end + + def attachments_deletable?(user=User.current) + if (self.has_attribute?(:course) ||self.has_attribute?(:course_id)) && self.course + #默认给予删除自己上传的附件的权限 + (respond_to?(:visible?) ? visible?(user) : true) && + (user.allowed_to?(self.class.attachable_options[:delete_permission], self.course) || (self.has_attribute?(:author_id) && self.author == user)) + else + #默认给予删除自己上传的附件的权限 + (respond_to?(:visible?) ? visible?(user) : true) && + (user.allowed_to?(self.class.attachable_options[:delete_permission], self.project) || (self.has_attribute?(:author_id) && self.author == user)) + end + end + + def saved_attachments + @saved_attachments ||= [] + end + + def unsaved_attachments + @unsaved_attachments ||= [] + end + + # 设置资源文件的公开属性 + # add by nwb + def set_attachment_public(res) + # 公开的资源判断他的父级的公开属性 + if res.is_public + if( (self.class.to_s=="Project" && self.is_public == false) || + (self.has_attribute?(:project) && self.project && self.project.is_public == false) || + (self.has_attribute?(:board) && self.board.project && self.board.project.is_public == false) || + (self.class.to_s=="HomeworkAttach" && self.bid.reward_type == 3) || + (self.class.to_s=="Course" && self.is_public == false) || + (self.has_attribute?(:course) && self.course && self.course.is_public == false) || + (self.has_attribute?(:board) && self.board.course && self.board.course.is_public == false) + ) + res.is_public = false + end + end + end + + def save_attachmentsex(attachments, author=User.current,attachment_type) + @curattachment_type = attachment_type + result = save_attachments(attachments,author) + result + end + + def save_attachments(attachments, author=User.current) + # 清除临时文件 + if attachments + tempAttach = attachments[:dummy] + if tempAttach && tempAttach[:file] + attachments.delete(:dummy) + end + end + + if attachments.is_a?(Hash) + attachments = attachments.stringify_keys + attachments = attachments.to_a.sort {|a, b| + if a.first.to_i > 0 && b.first.to_i > 0 + a.first.to_i <=> b.first.to_i + elsif a.first.to_i > 0 + 1 + elsif b.first.to_i > 0 + -1 + else + a.first <=> b.first + end + } + attachments = attachments.map(&:last) + end + if attachments.is_a?(Array) + attachments.each do |attachment| + if attachment.is_a?(Hash) + a = nil + file = attachment['file'] + token = attachment['token'] + t = file && file.size > 0 + if file && file.size > 0 + a = Attachment.create(:file => file, :author => author) + elsif token + a = Attachment.find_by_token_only(token) + if a + a.filename = attachment['filename'] unless attachment['filename'].blank? + a.content_type = attachment['content_type'] + end + end + end + if a && !attachment['is_public_checkbox'] + a.is_public = false + elsif a && attachment['is_public_checkbox'] + a.is_public = true + end + set_attachment_public(a) if a + next unless a + a.description = attachment['description'].to_s.strip + a.attachtype = @curattachment_type + if a.new_record? + unsaved_attachments << a + else + saved_attachments << a + end + end + end + {:files => saved_attachments, :unsaved => unsaved_attachments} + end + + def attach_saved_attachments + saved_attachments.each do |attachment| + self.attachments << attachment + end + end + + module ClassMethods + end + end + end + end +end diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 1504019d7..8ea71909b 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -1,233 +1,233 @@ -/* Redmine - project management software - Copyright (C) 2006-2013 Jean-Philippe Lang */ - -function postUpMsg(attachmentId) -{ - $.ajax({ - url: '/attachments/renderTag', - type: "GET", - data: { - attachmentId: attachmentId - } - - }) -} -function addFile(inputEl, file, eagerUpload) { - - if ($('#attachments_fields').children().length < 10) { - - var attachmentId = addFile.nextAttachmentId++; - - var fileSpan = $('', { 'id': 'attachments_' + attachmentId, 'class':'attachment' }); - - fileSpan.append( - $('', { 'type': 'text', 'class': 'filename readonly', 'name': 'attachments[' + attachmentId + '][filename]', 'readonly': 'readonly'} ).val(file.name), - $('', { 'type': 'text', 'class': 'description', 'name': 'attachments[' + attachmentId + '][description]', 'maxlength': 254, 'placeholder': $(inputEl).data('description-placeholder') } ).toggle(!eagerUpload), - $('公开:').attr({ 'class': 'ispublic-label' }) , - $('', { 'type': 'checkbox', 'class': 'is_public_checkbox','value':1, 'name': 'attachments[' + attachmentId + '][is_public_checkbox]', checked:'checked' } ).toggle(!eagerUpload), - $(' ').attr({ 'href': "#", 'class': 'remove-upload', 'data-confirm' : "您确定要删除吗?" }).click(removeFile).toggle(!eagerUpload), - $('<%= content_tag('span', "#{l(:label_institution_name)}:", :class => "course-font")%> From 986f48f012e9d210c3d3af917f094816a8abb3ae Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sat, 25 Oct 2014 17:02:58 +0800 Subject: [PATCH 04/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/my/account.html.erb | 61 +++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 57eaa93d1..6776340ac 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -35,7 +35,9 @@ <%= call_hook(:view_my_account_contextual, :user => @user) %>