diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index e6fbd2e0e..0a0f25419 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -14,7 +14,13 @@ class SoftapplicationsController < ApplicationController # GET /softapplications/1.json def show @softapplication = Softapplication.find(params[:id]) - + @jours = @softapplication.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] + @state = false respond_to do |format| format.html # show.html.erb format.json { render json: @softapplication } @@ -41,6 +47,7 @@ class SoftapplicationsController < ApplicationController # POST /softapplications.json def create @softapplication = Softapplication.new(params[:softapplication]) + @softapplication.user = User.current @softapplication.save_attachments(params[:attachments]) respond_to do |format| if @softapplication.save @@ -86,4 +93,94 @@ class SoftapplicationsController < ApplicationController format.json { head :no_content } end end + #应用评价涉及到的方法 + def new_message + @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id] + if @jour + user = @jour.user + text = @jour.notes + else + user = @softapplication.user + text = @softapplication.description + end + text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') + @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> " + @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" + @id = user.id + rescue ActiveRecord::RecordNotFound + render_404 + end + #新建评价 + def create_message + + if params[:softapplication_message][:message].size>0 + if params[:reference_content] + message = params[:softapplication_message][:message] + "\n" + params[:reference_content] + else + message = params[:softapplication_message][:message] + end + refer_user_id = params[:softapplication_message][:reference_user_id].to_i + @softapplication = Softapplication.find(params[:id]) + @softapplication.add_jour(User.current, message, refer_user_id) + + end + + @user = @softapplication.user + @jours = @softapplication.journals_for_messages.where('m_parent_id IS NULL').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] + #@softapplication.set_commit(@feedback_count) + + respond_to do |format| + format.js + end + + end + + ##删除评价 + def destroy_message + @user = @softapplication.user + if User.current.admin? || User.current.id == @user.id + JournalsForMessage.delete_message(params[:object_id]) + end + @jours = @softapplication.journals_for_messages.reverse + @limit = 10 + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + + @softapplication.set_commit(@feedback_count) + respond_to do |format| + format.js + end + end + # + def more + @jour = @softapplication.journals_for_messages + @jour.each_with_index {|j,i| j.indice = i+1} + @state = true + + respond_to do |format| + format.html { redirect_to :back } + format.js + #format.api { render_api_ok } + end + end + # + def back + @jour = @softapplication.journals_for_messages + @jour.each_with_index {|j,i| j.indice = i+1} + @state = false + + respond_to do |format| + format.html { redirect_to :back } + format.js + #format.api { render_api_ok } + end + end end diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 416b40db0..c83c123fc 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -192,6 +192,8 @@ class WordsController < ApplicationController obj = Bid.find_by_id(obj_id) 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) else raise 'create reply obj unknow type.' end @@ -208,6 +210,8 @@ class WordsController < ApplicationController obj.add_jour(nil, nil, nil, options) 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 else raise 'create reply obj unknow type.' end diff --git a/app/models/softapplication.rb b/app/models/softapplication.rb index f661ea74b..70983a489 100644 --- a/app/models/softapplication.rb +++ b/app/models/softapplication.rb @@ -1,4 +1,21 @@ class Softapplication < ActiveRecord::Base attr_accessible :android_min_version_available, :app_type_id, :app_type_name, :description, :name, :user_id acts_as_attachable + has_many :journals_for_messages, :as => :jour, :dependent => :destroy + belongs_to :user + + def add_jour(user, notes, reference_user_id = 0, options = {}) + if options.count == 0 + self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + else + jfm = self.journals_for_messages.build(options) + jfm.save + jfm + end + end + def set_commit(commit) + self.update_attribute(:commit, commit) + end + + end diff --git a/app/models/user.rb b/app/models/user.rb index 8c867512e..1aa1e0382 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -79,12 +79,14 @@ class User < Principal ## added by xianbo for delete has_many :biding_projects, :dependent => :destroy has_many :contesting_projects, :dependent => :destroy + belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy ##ended by xianbo #####fq has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy has_many :bids, :foreign_key => 'author_id', :dependent => :destroy has_many :contests, :foreign_key => 'author_id', :dependent => :destroy + has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" has_many :journal_replies, :dependent => :destroy diff --git a/app/views/softapplications/new.html.erb b/app/views/softapplications/new.html.erb index 820165819..cd46c7572 100644 --- a/app/views/softapplications/new.html.erb +++ b/app/views/softapplications/new.html.erb @@ -1,9 +1,9 @@ -

<%= l(:label_release_softapplication)%>

-
+
<%= form_for Softapplication.new, :url => {:controller => 'softapplications', :action => 'create'}, :update => "bidding_project_list", :complete => '$("#put-bid-form").hide();', :html => {:multipart => true, :id => 'add_homework_form'} do |f| %>
@@ -14,7 +14,7 @@ * : <%= f.text_field :name, :required => true, :size => 60, :style => "width:400px;" %> <%= l(:label_softapplication_name_condition)%> -
+

@@ -41,12 +41,18 @@

- <%= render_flash_messages %> -

- <%= render :partial => 'attachments/form' %> -

-
- <%= submit_tag l(:button_create), :onclick => "return true" %> + +
+ 上传应用软件包或应用截图 + <%= render_flash_messages %> +

+ <%= render :partial => 'attachments/form' %> +

+

(<%=l(:label_upload_softapplication_photo_condition)%>)

+ +
+
+
<%= submit_tag l(:button_create), :onclick => "return true" %>