diff options
Diffstat (limited to 'help/app')
| -rw-r--r-- | help/app/controllers/tickets_controller.rb | 25 | ||||
| -rw-r--r-- | help/app/models/ticket.rb | 5 | ||||
| -rw-r--r-- | help/app/views/tickets/show.html.haml | 28 | 
3 files changed, 39 insertions, 19 deletions
| diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index ced9569..d66647f 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -39,24 +39,31 @@ class TicketsController < ApplicationController    def show      @ticket = Ticket.find(params[:id]) -    redirect_to tickets_path, :alert => "No such ticket" if !@ticket +    if !@ticket +      redirect_to tickets_path, :alert => "No such ticket" +      return +    end      authorize_ticket_access      # @ticket.comments.build      # build ticket comments?    end    def update -      @ticket = Ticket.find(params[:id])      if ticket_access? -      params[:ticket][:comments_attributes] = nil if params[:ticket][:comments_attributes].values.first[:body].blank? #unset comments hash if no new comment was typed -      @ticket.attributes = params[:ticket] #this will call comments_attributes= -       -      @ticket.is_open = false if params[:commit] == @reply_close_str #this overrides is_open selection - -      # what if there is an update and no new comment? Confirm that there is a new comment to update posted_by: -      @ticket.comments.last.posted_by = (current_user ? current_user.id : nil) if @ticket.comments_changed? #protecting posted_by isn't working, so this should protect it. +      if status = params[:change_status] #close or open button was pressed +        @ticket.close if params[:change_status] == 'close' +        @ticket.reopen if params[:change_status] == 'open' +      else    +        params[:ticket][:comments_attributes] = nil if params[:ticket][:comments_attributes].values.first[:body].blank? #unset comments hash if no new comment was typed +        @ticket.attributes = params[:ticket] #this will call comments_attributes=        +        #@ticket.is_open = false if params[:commit] == @reply_close_str #this overrides is_open selection +        @ticket.close if params[:commit] == @reply_close_str #this overrides is_open selection +         +        # what if there is an update and no new comment? Confirm that there is a new comment to update posted_by: +        @ticket.comments.last.posted_by = (current_user ? current_user.id : nil) if @ticket.comments_changed? #protecting posted_by isn't working, so this should protect it. +      end        if @ticket.changed? and @ticket.save          flash[:notice] = 'Ticket was successfully updated.'          respond_with @ticket diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index cb8e397..dc2f51b 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -72,14 +72,15 @@ class Ticket < CouchRest::Model::Base      # in controller set to be current users email if that exists    end +  #not saving with close and reopen, as we will save in update when they are called.    def close      self.is_open = false -    save +    #save    end    def reopen      self.is_open = true -    save +    #save    end    def comments_attributes=(attributes) diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index eaa3356..6872f0b 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -8,21 +8,33 @@  - if @ticket.email    email:    = @ticket.email -- if User.find(@ticket.created_by) -  Created by -  = User.find(@ticket.created_by).login  -- else -  Unauthenticated ticket creator +%li +  - if User.find(@ticket.created_by) +    Created by +    = User.find(@ticket.created_by).login  +  - else +    Unauthenticated ticket creator +%li +  = "status:"  +  - if @ticket.is_open +    = 'open' +    = #link_to 'close', ticket_path, :method => :put +    = #button_to 'close', ticket_path, :method => :put +    = button_to 'close', {:change_status => :close}, :method => :put +  - else  +    = 'closed' +    = button_to 'open', {:change_status => :open}, :method => :put  = render(:partial => "comment", :collection => @ticket.comments)  = simple_form_for (@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test    = f.simple_fields_for :comments, TicketComment.new do |c|      = c.input :body, :label => 'Comment', :as => :text    = #render :partial => 'new_comment' -  = f.label :is_open -  = f.select :is_open, [true, false] +  = #f.label :is_open +  = #f.select :is_open, [true, false] #remove    = f.button :submit, @post_reply_str -  = f.button :submit, @reply_close_str +  - if @ticket.is_open +    = f.button :submit, @reply_close_str    = #link_to t(:destroy), ticket_path,  :confirm => 'are you sure?', :method => :delete, :class => :btn if admin? # for link_to to work with delete, need to figure out jquery interaction correctly. see  http://stackoverflow.com/questions/3774925/delete-link-sends-get-instead-of-delete-in-rails-3-view etc..    = button_to 'destroy', ticket_path, :confirm => 'are you sure?', :method => :delete  if admin? #TODO---confirmation not working    = # button_to("test destroy", {}, {:onclick => "return confirm('Are you sure?')", :method => :delete, :remote => true}) #this works but is ugly | 
