From fe92b050264633898d1bed919821f6e361d3e443 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Tue, 12 May 2015 17:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=8C=BA=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=99=84=E4=BB=B6=20Signed-off-by:=20alan=20?= =?UTF-8?q?<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- app/controllers/messages_controller.rb | 14 +--- app/views/attachments/_form_course.html.erb | 8 +-- app/views/attachments/_form_project.html.erb | 8 +-- app/views/boards/_edit.html.erb | 2 +- app/views/boards/_form_project.html.erb | 2 +- public/javascripts/attachments.js | 75 +++++++++++++++++++- public/stylesheets/courses.css | 21 +++++- public/stylesheets/project.css | 18 ++++- 9 files changed, 121 insertions(+), 29 deletions(-) diff --git a/Gemfile b/Gemfile index 810190a6a..0aa77ae99 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'acts-as-taggable-on', '2.4.1' gem 'spreadsheet' gem 'ruby-ole' gem 'rails_kindeditor',path:'lib/rails_kindeditor' -#gem "rmagick", ">= 2.0.0" +gem "rmagick", ">= 2.0.0" group :development do gem 'grape-swagger' diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 1e4f19acb..6e2da4bb0 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -172,18 +172,10 @@ class MessagesController < ApplicationController # Edit a message def edit @isReply = false - if params[:is_board] - if @project - (redirect_to project_boards_path(@project); return false) - elsif @course - (redirect_to course_boards_path(@course); return false) - end + if @project + (render_403; return false) unless @message.editable_by?(User.current) else - if @project - (render_403; return false) unless @message.editable_by?(User.current) - else - (render_403; return false) unless @message.course_editable_by?(User.current) - end + (render_403; return false) unless @message.course_editable_by?(User.current) end @message.safe_attributes = params[:message] diff --git a/app/views/attachments/_form_course.html.erb b/app/views/attachments/_form_course.html.erb index 1e81aaf65..7b07426aa 100644 --- a/app/views/attachments/_form_course.html.erb +++ b/app/views/attachments/_form_course.html.erb @@ -1,4 +1,4 @@ - + <% if defined?(container) && container && container.saved_attachments %> <% if isReply %> <% container.saved_attachments.each_with_index do |attachment, i| %> @@ -38,12 +38,12 @@ <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> -<%= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"_file.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> +<%= button_tag "#{l(:button_browse)}", :type=>"button", :onclick=>"file#{container.id}.click()",:class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> <%= file_field_tag 'attachments[dummy][file]', - :id => '_file', + :id => "file#{container.id}", :class => 'file_selector', :multiple => true, - :onchange => 'addInputFiles(this);', + :onchange => "addInputFiles_board(this, '#{container.id}');", :style => 'display:none', :data => { :max_file_size => Setting.attachment_max_size.to_i.kilobytes, diff --git a/app/views/attachments/_form_project.html.erb b/app/views/attachments/_form_project.html.erb index 9778d3242..66d9a0e80 100644 --- a/app/views/attachments/_form_project.html.erb +++ b/app/views/attachments/_form_project.html.erb @@ -1,4 +1,4 @@ - + <% if defined?(container) && container && container.saved_attachments %> <% if isReply %> <% container.saved_attachments.each_with_index do |attachment, i| %> @@ -38,12 +38,12 @@ <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> - <%= button_tag "文件浏览", :type=>"button", :onclick=>"_file.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> + <%= button_tag "文件浏览", :type=>"button", :onclick=>"file#{container.id}.click()", :class =>"sub_btn",:style => ie8? ? 'display:none' : '' %> <%= file_field_tag 'attachments[dummy][file]', - :id => '_file', + :id => "file#{container.id}", :class => 'file_selector', :multiple => true, - :onchange => 'addInputFiles(this);', + :onchange => "addInputFiles_board(this, '#{container.id}');", :style => 'display:none', :data => { :max_file_size => Setting.attachment_max_size.to_i.kilobytes, diff --git a/app/views/boards/_edit.html.erb b/app/views/boards/_edit.html.erb index a4b2aff73..15358c03a 100644 --- a/app/views/boards/_edit.html.erb +++ b/app/views/boards/_edit.html.erb @@ -12,7 +12,7 @@ } do |f| %> <%= render :partial => 'form_project', :locals => {:f => f, :replying => !topic.parent.nil?, :topic => topic} %> - <%= l(:button_submit)%> + <%= l(:button_submit)%> <%= l(:button_cancel) %> <%#= link_to l(:button_cancel), board_message_url(topic.board, topic.root, :r => (topic.parent_id && topic.id)), :class => "blue_btn grey_btn fl c_white" %> diff --git a/app/views/boards/_form_project.html.erb b/app/views/boards/_form_project.html.erb index b42cabbeb..3ecffa3e2 100644 --- a/app/views/boards/_form_project.html.erb +++ b/app/views/boards/_form_project.html.erb @@ -51,7 +51,7 @@
  • <% unless replying %>
    - <%= render :partial => 'attachments/form_project', :locals => {:container => @message,:isReply => @isReply} %> + <%= render :partial => 'attachments/form_project', :locals => {:container => topic,:isReply => @isReply} %>
    <% end %>
  • diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 2c10d28e4..6eb73182d 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -23,9 +23,10 @@ function reload(fileSpan) { } -function addFile(inputEl, file, eagerUpload) { +function addFile_board(inputEl, file, eagerUpload, id) { - if ($('#attachments_fields').children().length < 30) { + var attachments_frame = '#attachments_fields' + id; + if ($(attachments_frame).children().length < 30) { deleteallfiles = $(inputEl).data('deleteAllFiles'); var attachmentId = addFile.nextAttachmentId++; @@ -48,7 +49,7 @@ function addFile(inputEl, file, eagerUpload) { }).toggle(!eagerUpload), $('
    ', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) - ).appendTo('#attachments_fields'); + ).appendTo(attachments_frame); if(eagerUpload) { ajaxUpload(file, attachmentId, fileSpan, inputEl); @@ -58,7 +59,42 @@ function addFile(inputEl, file, eagerUpload) { } return null; } +function addFile(inputEl, file, eagerUpload) { + + var attachments_frame = '#attachments_fields'; + if ($(attachments_frame).children().length < 30) { + deleteallfiles = $(inputEl).data('deleteAllFiles'); + 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('descriptionPlaceholder') } ).toggle(!eagerUpload), + $(''+$(inputEl).data('fieldIsPublic')+':').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' }).click(function(){ + if(confirm($(inputEl).data('areYouSure'))){ + removeFile(); + if(!eagerUpload){ + (function(e){ + reload(e); + })(fileSpan); + } + } + }).toggle(!eagerUpload), + $('
    ', { 'class': 'div_attachments', 'name': 'div_'+'attachments_' + attachmentId} ) + ).appendTo('#attachments_fields'); + + if(eagerUpload) { + ajaxUpload(file, attachmentId, fileSpan, inputEl); + + } + return attachmentId; + } + return null; +} addFile.nextAttachmentId = 1; function ajaxUpload(file, attachmentId, fileSpan, inputEl) { @@ -202,7 +238,26 @@ function addInputFiles(inputEl) { //clearedFileInput.insertAfter('#attachments_fields'); } +function addInputFiles_board(inputEl, id) { + // var clearedFileInput = $(inputEl).clone().val(''); + + if (inputEl.files) { + // upload files using ajax + uploadAndAttachFiles_board(inputEl.files, inputEl, id); + // $(inputEl).remove(); + } else { + // browser not supporting the file API, upload on form submission + var attachmentId; + var aFilename = inputEl.value.split(/\/|\\/); + attachmentId = addFile_board(inputEl, { name: aFilename[ aFilename.length - 1 ] }, false, id); + if (attachmentId) { + $(inputEl).attr({ name: 'attachments[' + attachmentId + '][file]'}).hide(); + $('#upload_file_count').html(""+count+""+$(inputEl).data('fileCount')); + } + } + //clearedFileInput.insertAfter('#attachments_fields'); +} function uploadAndAttachFiles(files, inputEl) { var maxFileSize = $(inputEl).data('max-file-size'); @@ -218,7 +273,21 @@ function uploadAndAttachFiles(files, inputEl) { $.each(files, function() {addFile(inputEl, this, true);}); } } +function uploadAndAttachFiles_board(files, inputEl, id) { + var maxFileSize = $(inputEl).data('max-file-size'); + var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); + + var sizeExceeded = false; + $.each(files, function() { + if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;} + }); + if (sizeExceeded) { + window.alert(maxFileSizeExceeded); + } else { + $.each(files, function() {addFile_board(inputEl, this, true, id);}); + } +} function handleFileDropEvent(e) { $(this).removeClass('fileover'); diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index f49ef22f1..132cddadc 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -83,8 +83,8 @@ a:hover.talk_edit{ color:#ff5722;} .talkpage_text{ border:1px solid #64bdd9; width:600px; color:#7d7d7d; padding:5px; margin:10px 0 10px 50px; background:#fff;} /****新建讨论***/ .talk_new{ color:#4c4c4c;} -.talk_input{ border:1px solid #64bdd9; height:16px; width:585px; background:#fff; margin-bottom:10px; padding:5px;} -.talk_text{ border:1px solid #64bdd9; height:100px;width:585px; background:#fff; margin-left:5px; padding:5px; margin-bottom:10px;} +.talk_input{ border:1px solid #64bdd9; height:16px; width:550px; background:#fff; margin-bottom:10px; padding:5px;} +.talk_text{ border:1px solid #64bdd9; height:100px;width:550px; background:#fff; margin-left:5px; padding:5px; margin-bottom:10px;} .talk_new ul li{ } .sb{width:70px; height:26px; color:#606060; cursor:pointer;} a.blue_btn{ background:#64bdd9; display:block; font-size:14px;color:#fff; font-weight:normal; text-align:center; margin-left:10px; margin-bottom:10px; padding:2px 10px;} @@ -364,6 +364,23 @@ span.add_attachment {font-size: 80%;line-height: 2.5em;} .reply_btn:hover{ background:#999; color:#fff; } #attachments_fields div.ui-progressbar { width: 100px; height:14px; margin: 2px 0 -5px 8px; display: inline-block; } + +.attachments_fields input.description {margin-left:4px; width:100px; } +.attachments_fields span .boldSpan{display:block; white-space:nowrap; font-family:'微软雅黑';} +.attachments_fields div.ui-progressbar { width: 100px; height:14px; margin: 2px 0 -5px 8px; display: inline-block; } +a.remove-upload:hover {text-decoration:none !important;} +.attachments_fields input.is_public_checkbox {width:20px;} + + +.attachments_fields span.ispublic-label {display: inline-block;width: 30px;margin-left: 10px;} +a.remove-upload {background: url(../images/delete.png) no-repeat 1px 50%;width: 1px;display: inline-block;padding-left: 16px;} +.attachments_fields input.filename {border: 0;height: 1.8em;width: 150px;color: #555;background-color: inherit;background: url(../images/attachment.png) no-repeat 1px 50%;padding-left: 18px;padding-top: 2px;} +span.add_attachment {font-size: 80%;line-height: 2.5em;} +.attachments_fields span {display: block;white-space: nowrap;} +.file_selector{position: relative;opacity: 0;filter: alpha(opacity:0);} +.attachments_fields .ajax-waiting input.filename {background:url(../images/hourglass.png) no-repeat 0px 50%;} +.attachments_fields .ajax-loading input.filename {background:url(../images/loading.gif) no-repeat 0px 50%;} + .ui-widget { font-family: Verdana, sans-serif; font-size: 1.1em; diff --git a/public/stylesheets/project.css b/public/stylesheets/project.css index 98194b73c..14a7a9a34 100644 --- a/public/stylesheets/project.css +++ b/public/stylesheets/project.css @@ -123,8 +123,8 @@ a:hover.talk_edit{ color:#ff5722;} .recall_con{ float:left;color:#777777; width:520px; margin-left:10px; } /****新建讨论***/ .talk_new{ color:#4c4c4c;} -.talk_input{ border:1px solid #64bdd9; height:16px; width:585px; background:#fff; margin-bottom:10px; padding:5px;} -.talk_text{ border:1px solid #64bdd9; height:100px;width:585px; background:#fff; margin-left:5px; padding:5px; margin-bottom:10px;} +.talk_input{ border:1px solid #64bdd9; height:16px; width:550px; background:#fff; margin-bottom:10px; padding:5px;} +.talk_text{ border:1px solid #64bdd9; height:100px;width:550px; background:#fff; margin-left:5px; padding:5px; margin-bottom:10px;} .talk_new ul li{ } .sb{width:70px; height:26px; color:#606060; cursor:pointer;} /*a.blue_btn{ background:#64bdd9; display:block; font-size:14px;color:#fff; font-weight:normal; text-align:center; margin-left:10px; margin-bottom:10px; padding:2px 10px;}*/ @@ -254,7 +254,21 @@ span.add_attachment {font-size: 80%;line-height: 2.5em;} .reply_btn{ cursor:pointer; -moz-border-radius:3px; -webkit-border-radius:3px; border:1px solid #ccc; color:#999; border-radius:3px; padding:2px 10px; margin-bottom:10px;display: block;margin-left: 470px;} .reply_btn:hover{ background:#999; color:#fff; } +.attachments_fields input.description {margin-left:4px; width:100px; } +.attachments_fields span .boldSpan{display:block; white-space:nowrap; font-family:'微软雅黑';} +.attachments_fields div.ui-progressbar { width: 100px; height:14px; margin: 2px 0 -5px 8px; display: inline-block; } +a.remove-upload:hover {text-decoration:none !important;} +.attachments_fields input.is_public_checkbox {width:20px;} + +.attachments_fields span.ispublic-label {display: inline-block;width: 30px;margin-left: 10px;} +a.remove-upload {background: url(../images/delete.png) no-repeat 1px 50%;width: 1px;display: inline-block;padding-left: 16px;} +.attachments_fields input.filename {border: 0;height: 1.8em;width: 150px;color: #555;background-color: inherit;background: url(../images/attachment.png) no-repeat 1px 50%;padding-left: 18px;padding-top: 2px;} +span.add_attachment {font-size: 80%;line-height: 2.5em;} +.attachments_fields span {display: block;white-space: nowrap;} +.file_selector{position: relative;opacity: 0;filter: alpha(opacity:0);} +.attachments_fields .ajax-waiting input.filename {background:url(../images/hourglass.png) no-repeat 0px 50%;} +.attachments_fields .ajax-loading input.filename {background:url(../images/loading.gif) no-repeat 0px 50%;} .ui-widget { font-family: Verdana, sans-serif;