2013-08-01 10:33:49 +08:00
|
|
|
class BidsController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :find_bid, :only => [:show, :show_project, :create, :destroy, :more, :back, :add]
|
|
|
|
|
|
|
|
helper :watchers
|
|
|
|
def index
|
|
|
|
if params[:bid_title]
|
|
|
|
Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description])
|
|
|
|
end
|
|
|
|
# @requirement_title = "4"
|
|
|
|
@offset = 0
|
|
|
|
@limit = 20
|
|
|
|
@bids = Bid.offset(@offset).limit(@limit).all
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@state = false
|
|
|
|
@user = @bid.author
|
|
|
|
@jour = @bid.journals_for_messages
|
|
|
|
@jour.each_with_index {|j,i| j.indice = i+1}
|
|
|
|
#
|
|
|
|
# @journals = @bid.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
|
|
|
|
#@journals.each_with_index {|j,i| j.indice = i+1}
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
}
|
|
|
|
format.api
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_project
|
2013-08-01 20:47:00 +08:00
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
@option = []
|
|
|
|
@membership.each do |membership|
|
|
|
|
@option << membership.project
|
|
|
|
end
|
|
|
|
# a = [1]
|
|
|
|
# @project = Project.where("id in []", a)
|
2013-08-01 10:33:49 +08:00
|
|
|
@user = @bid.author
|
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
}
|
|
|
|
format.api
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add
|
2013-08-01 20:47:00 +08:00
|
|
|
project = Project.where('name = ?', params[:bid]).first
|
2013-08-01 10:33:49 +08:00
|
|
|
bid_message = params[:bid_for_save][:bid_message]
|
2013-08-01 20:47:00 +08:00
|
|
|
BidingProject.cerate_bidding(@bid.id, project.id, bid_message)
|
2013-08-01 10:33:49 +08:00
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
respond_to do |format|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
if params[:user_message].size>0
|
2013-08-01 20:47:00 +08:00
|
|
|
message = params[:user_message][:message]
|
2013-08-01 10:33:49 +08:00
|
|
|
@bid.add_jour(User.current, message)
|
|
|
|
# if a_message.size > 5
|
|
|
|
# @message = a_message[-5, 5]
|
|
|
|
# else
|
|
|
|
# @message = a_message
|
|
|
|
# end
|
|
|
|
# @message_count = a_message.count
|
|
|
|
end
|
|
|
|
@jour = @bid.journals_for_messages
|
|
|
|
@jour.each_with_index {|j,i| j.indice = i+1}
|
|
|
|
@bid.set_commit(@jour.count)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
JournalsForMessage.delete_message(params[:object_id])
|
|
|
|
@jour = @bid.journals_for_messages
|
|
|
|
@jour.each_with_index {|j,i| j.indice = i+1}
|
|
|
|
@bid.set_commit(@jour.count)
|
|
|
|
# if a_message.size > 5
|
|
|
|
# @message = a_message[-5, 5]
|
|
|
|
# else
|
|
|
|
# @message = a_message
|
|
|
|
# end
|
|
|
|
# @message_count = a_message.count
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
format.js
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
|
|
|
if @jour
|
|
|
|
user = @jour.user
|
|
|
|
text = @jour.notes
|
|
|
|
else
|
|
|
|
user = @bid.author
|
|
|
|
text = @bid.description
|
|
|
|
end
|
|
|
|
# Replaces pre blocks with [...]
|
|
|
|
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
|
|
|
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
|
|
|
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2013-08-02 08:53:07 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def new_bid
|
2013-08-02 08:53:07 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def more
|
|
|
|
@jour = @bid.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 = @bid.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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_bid
|
|
|
|
if params[:bid_id]
|
|
|
|
@bid = Bid.find(params[:bid_id])
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|