diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 01578eab3..8dc5d80a0 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -26,6 +26,13 @@ class HomeworkAttachController < ApplicationController #删除留言 def destroy @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) + @homework = HomeworkAttach.find(params[:id]) + @jours = @homework.journals_for_messages.order("created_on DESC") + @limit = 10 + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] respond_to do |format| format.js end @@ -57,5 +64,27 @@ class HomeworkAttachController < ApplicationController #result = percent * 1.0 / stars_reates_count #result end + + #添加回复 + def add_jour_reply + parent_id = params[:reference_id] + author_id = User.current.id + reply_user_id = params[:reference_user_id] + reply_id = params[:reference_message_id] # 暂时不实现 + content = params[:user_notes] + options = {:user_id => author_id, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + @jfm = JournalsForMessage.new(options) + @jfm.save + respond_to do |format| + format.js{ + @save_succ = true if @jfm.errors.empty? + } + end + end end diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index c83c123fc..bfc1eacb4 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -193,7 +193,9 @@ class WordsController < ApplicationController elsif ( referer.match(/contests/) || referer.match(/contests/) ) #new added obj = Contest.find_by_id(obj_id) elsif ( referer.match(/softapplications/) || referer.match(/softapplications/) ) #new added - obj = Softapplication.find_by_id(obj_id) + obj = Softapplication.find_by_id(obj_id) + elsif ( referer.match(/homework_attach/) || referer.match(/homework_attach/) ) #new added + obj = HomeworkAttach.find_by_id(obj_id) else raise 'create reply obj unknow type.' end @@ -211,7 +213,9 @@ class WordsController < ApplicationController elsif obj.kind_of? Contest obj.add_jour(nil, nil, obj.id, options) #new added elsif obj.kind_of? Softapplication - obj.add_jour(nil, nil, obj.id, options) #new added + obj.add_jour(nil, nil, obj.id, options) #new added + elsif obj.kind_of? HomeworkAttach + obj.add_jour(nil, nil, obj.id, options) #new added else raise 'create reply obj unknow type.' end diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index d112ead50..4bac58449 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -24,4 +24,10 @@ class HomeworkAttach < ActiveRecord::Base result = percent * 1.0 / stars_reates.count result end + + def add_jours options + jfm = self.journals_for_messages.build(options) + jfm.save + jfm + end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 575737401..7356b7373 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -74,7 +74,8 @@ class JournalsForMessage < ActiveRecord::Base def self.reference_message(user_id) @user = User.find(user_id) - message = JournalsForMessage.find_by_sql("select * from journals_for_messages where reply_id = #{@user.id} or (jour_type = 'Bid' and jour_id in (select id from bids where author_id = #{@user.id}))") + message = JournalsForMessage.find_by_sql("select * from journals_for_messages where reply_id = #{@user.id} + or (jour_type = 'Bid' and jour_id in (select id from bids where author_id = #{@user.id}))") message end diff --git a/app/views/homework_attach/_add_jour_reply.html.erb b/app/views/homework_attach/_add_jour_reply.html.erb new file mode 100644 index 000000000..1e202e6a4 --- /dev/null +++ b/app/views/homework_attach/_add_jour_reply.html.erb @@ -0,0 +1,14 @@ + +<%= form_tag({:controller => 'homework_attach', :action => 'add_jour_reply'}, :remote => true) do %> +<%= text_area_tag 'user_notes', "", :class => 'noline', + :style => "resize: none;", :rows => 4, + :placeholder => l(:label_projects_feedback_respond_content), + :maxlength => 250 %> + +<%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %> +<%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %> +<%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => m_reply_id.id %> +<%= submit_tag l(:button_projects_feedback_respond), + :name => nil , :class => "enterprise", :style => "float: right; margin-top: 1px; margin-right: 4px;"%> + +<% end %> \ No newline at end of file diff --git a/app/views/homework_attach/_jour_reply.html.erb b/app/views/homework_attach/_jour_reply.html.erb new file mode 100644 index 000000000..0dd56f442 --- /dev/null +++ b/app/views/homework_attach/_jour_reply.html.erb @@ -0,0 +1,6 @@ +<% id = "journal_reply_ul_" + journal.id.to_s%> + \ No newline at end of file diff --git a/app/views/homework_attach/_journal_reply_items.html.erb b/app/views/homework_attach/_journal_reply_items.html.erb new file mode 100644 index 000000000..85f7fa304 --- /dev/null +++ b/app/views/homework_attach/_journal_reply_items.html.erb @@ -0,0 +1,34 @@ +<% reply_allow = JournalsForMessage.create_by_user? User.current %> +<% ids_r = 'reply_respond_form_'+ reply.id.to_s %> +
  • + + <%= image_tag url_to_avatar(reply.user), :class => "avatar-3" %> + +
    + <% id = 'project_respond_form_'+ reply.id.to_s %> +

    + <%= link_to reply.user.name, user_path(reply.user) %>:  + <%= reply.notes %> +

    +

    + <%= format_time reply.created_on %> + +

    +
    +
    + <% if reply_allow %> + <%= render :partial => "add_jour_reply", :locals => {:journal => journal, :m_reply_id => m_reply_id} %> + <% end %> +
    +
    +
  • \ No newline at end of file diff --git a/app/views/homework_attach/_showjour.html.erb b/app/views/homework_attach/_showjour.html.erb index f810082c9..dbd7f2547 100644 --- a/app/views/homework_attach/_showjour.html.erb +++ b/app/views/homework_attach/_showjour.html.erb @@ -40,24 +40,33 @@ <% for journal in jour%>
  • <%= image_tag(url_to_avatar(journal.user), :class => "avatar") %> - - <%= link_to journal.user, user_path(journal.user)%> - <% label = l(:label_contest_requirement) %> -
    <%= textilizable journal.notes%>
    - <%= l(:label_bids_published) %> -  <%= time_tag(journal.created_on).html_safe %>  - <%= l(:label_bids_published_ago) %> + + <%= link_to journal.user, user_path(journal.user)%> + <% label = l(:label_contest_requirement) %> +
    <%= textilizable journal.notes%>
    + <%= l(:label_bids_published) %> +  <%= time_tag(journal.created_on).html_safe %>  + <%= l(:label_bids_published_ago) %> + + <% ids = 'project_respond_form_'+ journal.id.to_s%> + + <%= link_to l(:label_projects_feedback_respond),'', + {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.name}: '); $('##{ids} textarea') ;return false;"} + %> + <% if journal.user==User.current|| User.current.admin? %> + <%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy', :object_id => journal, :user_id => journal.user}, + :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) %> + <% end %> +
    - <% ids = 'project_respond_form_'+ journal.id.to_s%> - - - <% if journal.user==User.current|| User.current.admin? %> - <%= link_to(l(:label_bid_respond_delete), {:controller => 'homework_attach', :action => 'destroy', :object_id => journal, :user_id => journal.user}, - :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) %> - <% end %> - -
    +
    + <%= render :partial => 'add_jour_reply', :locals => {:journal => journal, :m_reply_id => journal} %> +
    +
    +
    + <%= render :partial => "jour_reply", :locals => {:journal => journal } %> +
  • <% end %> diff --git a/app/views/homework_attach/add_jour_reply.js.erb b/app/views/homework_attach/add_jour_reply.js.erb new file mode 100644 index 000000000..564229d81 --- /dev/null +++ b/app/views/homework_attach/add_jour_reply.js.erb @@ -0,0 +1,14 @@ +<% if @save_succ %> +var pre_append = $('<%= j( + render :partial => "journal_reply_items", + :locals => {:reply => @jfm, :journal => @jfm.parent, :m_reply_id => @jfm} + ) %>').hide(); +$('#journal_reply_ul_<%=@jfm.m_parent_id%>').append(pre_append); +pre_append.fadeIn(600); +var textarea = $('#project_respond_form_<%=@jfm.m_reply_id.to_s%> textarea'); +textarea.val(''); +$('#project_respond_form_<%=@jfm.m_reply_id.to_s%>').hide(); +setMaxLengthItem(pre_append.find('textarea')[0]); +<% else %> +alert("<%= l(:label_feedback_fail) %>"); +<% end %> \ No newline at end of file diff --git a/app/views/homework_attach/destroy.js.erb b/app/views/homework_attach/destroy.js.erb index f3d9a7bef..9691a6aee 100644 --- a/app/views/homework_attach/destroy.js.erb +++ b/app/views/homework_attach/destroy.js.erb @@ -6,6 +6,7 @@ destroyedItem.remove(); }); <% else %> - $('#message').html('<%= escape_javascript(render(:partial => 'showjour', :locals => {:jour => @jour, :state => false})) %>'); + + $('#message').html('<%= escape_javascript(render(:partial => 'showjour', :locals => {:jour => @jours, :state => false})) %>'); $('#new_form_reference_user_id').val(""); <% end %> diff --git a/config/routes.rb b/config/routes.rb index b5defb117..ea1b70e35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,8 @@ RedmineApp::Application.routes.draw do resources :homework_attach match 'homework_attach/addjours', :controller => 'homework_attach', :action => 'addjours', :via => [:get,:post] + match 'homework_attach/add_jour_reply', :controller => 'homework_attach', :action => 'add_jour_reply', :via => [:get,:post] + resources :open_source_projects do collection do match 'search', via: [:get, :post]