From 4259cad450fee703dc34ebe5322de994d06a5448 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 11 Dec 2012 15:07:27 -0800 Subject: Playing around with using x-editable, which isn't yet working. --- app/assets/javascripts/application.js | 3 +++ app/assets/stylesheets/application.scss | 2 ++ help/app/assets/javascripts/tickets.js.coffee | 6 ++++++ help/app/views/tickets/show.html.haml | 6 ++++++ ui_dependencies.rb | 1 + 5 files changed, 18 insertions(+) create mode 100644 help/app/assets/javascripts/tickets.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 23d7fef..57e6d62 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,6 +16,9 @@ //= require users //= require_tree . //= require bootstrap +//= require bootstrap-editable +//= require bootstrap-editable-rails +//= require bootstrap-editable-inline //= require jquery.pjax $(function() { diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 8dec07d..cb5fa1b 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -12,3 +12,5 @@ table.table-hover .btn { table.table-hover tr:hover .btn { opacity: 1; } + +@import "bootstrap-editable"; \ No newline at end of file diff --git a/help/app/assets/javascripts/tickets.js.coffee b/help/app/assets/javascripts/tickets.js.coffee new file mode 100644 index 0000000..039ce91 --- /dev/null +++ b/help/app/assets/javascripts/tickets.js.coffee @@ -0,0 +1,6 @@ +$("#title").editable({ + type: 'text', + pk: 1, + url: '/blah', + title: 'TEXT here' + }); \ No newline at end of file diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index d9f594b..3e4acb9 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -1,4 +1,10 @@ %h2= @ticket.title + += #%a#title.editable.editable-click{"data-name" => "title", "data-original-title" => "Enter username", "data-resource" => "post", "data-type" => "text", "data-url" => ticket_path(@ticket.id), "data-pk" => @ticket.id, :href => "#"} test + +%a#title.editable.editable-click{:href => "#"} test + +%p - if @ticket.email email: = @ticket.email diff --git a/ui_dependencies.rb b/ui_dependencies.rb index eed79a3..10eac67 100644 --- a/ui_dependencies.rb +++ b/ui_dependencies.rb @@ -6,6 +6,7 @@ gem "pjax_rails" gem 'client_side_validations' gem 'client_side_validations-simple_form' gem 'kaminari', "0.13.0" # for pagination. trying 0.13.0 as there seem to be issues with 0.14.0 when using couchrest +gem 'bootstrap-editable-rails' group :assets do gem "haml-rails", "~> 0.3.4" -- cgit v1.2.3 From 524bb47fa5782ca1e0aaf16a4a0836defadfbe48 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 11 Dec 2012 16:18:37 -0800 Subject: Start to using x-editable to have title editable. --- app/assets/javascripts/application.js | 1 + app/views/home/index.html.haml | 3 --- help/app/assets/javascripts/tickets.js | 6 ++++++ help/app/assets/javascripts/tickets.js.coffee | 6 ------ help/app/controllers/tickets_controller.rb | 21 +++++++++++++++++++-- help/app/views/tickets/show.html.haml | 5 ++--- 6 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 help/app/assets/javascripts/tickets.js delete mode 100644 help/app/assets/javascripts/tickets.js.coffee diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 57e6d62..3fd641c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -20,6 +20,7 @@ //= require bootstrap-editable-rails //= require bootstrap-editable-inline //= require jquery.pjax +//= require tickets $(function() { $('a:not([data-remote]):not([data-behavior]):not([data-skip-pjax])').pjax('[data-pjax-container]'); diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index dd7e5aa..c02dcad 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,6 +1,3 @@ -%h1 spacer for firefox -%h1 spacer for firefox - Try to fetch a = link_to "cert", cert_path diff --git a/help/app/assets/javascripts/tickets.js b/help/app/assets/javascripts/tickets.js new file mode 100644 index 0000000..524df6f --- /dev/null +++ b/help/app/assets/javascripts/tickets.js @@ -0,0 +1,6 @@ +$("#title").editable({ + }); + +$(document).ready(function () { + $('#title').editable(); +}); \ No newline at end of file diff --git a/help/app/assets/javascripts/tickets.js.coffee b/help/app/assets/javascripts/tickets.js.coffee deleted file mode 100644 index 039ce91..0000000 --- a/help/app/assets/javascripts/tickets.js.coffee +++ /dev/null @@ -1,6 +0,0 @@ -$("#title").editable({ - type: 'text', - pk: 1, - url: '/blah', - title: 'TEXT here' - }); \ No newline at end of file diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 3ff19b8..b79dc0f 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -1,6 +1,6 @@ class TicketsController < ApplicationController - respond_to :html #, :json + respond_to :html, :json #has_scope :open, :type => boolean before_filter :set_strings @@ -52,7 +52,24 @@ class TicketsController < ApplicationController @ticket = Ticket.find(params[:id]) if !ticket_access_denied? - if status = params[:change_status] #close or open button was pressed + + if params[:post][:title] #title was changed with x-editable form + + respond_to do |format| + if @ticket.update_attributes(params[:post]) + format.html { redirect_to @ticket, notice: 'Ticket was successfully updated.' } + format.json { head :no_content } # 204 No Content + else + format.html { render action: "show" } + format.json { render json: @ticket.errors, status: :unprocessable_entity } + end + return + end + # TODO: do we want to keep the history of title changes? one possibility was adding a comment that said something like 'user changed the title from a to b' + + # TODO: this is throwing a missing template error + return + elsif 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 diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index 3e4acb9..f09f525 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -1,8 +1,7 @@ %h2= @ticket.title -= #%a#title.editable.editable-click{"data-name" => "title", "data-original-title" => "Enter username", "data-resource" => "post", "data-type" => "text", "data-url" => ticket_path(@ticket.id), "data-pk" => @ticket.id, :href => "#"} test - -%a#title.editable.editable-click{:href => "#"} test +%a#title.editable.editable-click{"data-name" => "title", "data-original-title" => "Enter username", "data-resource" => "post", "data-type" => "text", "data-url" => ticket_path(@ticket.id), "data-pk" => @ticket.id, :href => "#"} + = @ticket.title %p - if @ticket.email -- cgit v1.2.3 From 49d0ffe5f689ecb651b65beb4050b3f38cbb226e Mon Sep 17 00:00:00 2001 From: jessib Date: Wed, 12 Dec 2012 13:15:07 -0800 Subject: Refactoring of ticket displaying/editing. --- help/app/assets/javascripts/tickets.js | 3 --- help/app/controllers/tickets_controller.rb | 29 +++++++-------------------- help/app/models/ticket.rb | 1 + help/app/views/tickets/_new_comment.html.haml | 3 +-- help/app/views/tickets/new.html.haml | 9 +-------- help/app/views/tickets/show.html.haml | 18 +++++------------ 6 files changed, 15 insertions(+), 48 deletions(-) diff --git a/help/app/assets/javascripts/tickets.js b/help/app/assets/javascripts/tickets.js index 524df6f..8f58e86 100644 --- a/help/app/assets/javascripts/tickets.js +++ b/help/app/assets/javascripts/tickets.js @@ -1,6 +1,3 @@ -$("#title").editable({ - }); - $(document).ready(function () { $('#title').editable(); }); \ No newline at end of file diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index b79dc0f..db9bc82 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -52,36 +52,21 @@ class TicketsController < ApplicationController @ticket = Ticket.find(params[:id]) if !ticket_access_denied? - - if params[:post][:title] #title was changed with x-editable form - - respond_to do |format| - if @ticket.update_attributes(params[:post]) - format.html { redirect_to @ticket, notice: 'Ticket was successfully updated.' } - format.json { head :no_content } # 204 No Content - else - format.html { render action: "show" } - format.json { render json: @ticket.errors, status: :unprocessable_entity } - end - return + if params[:post] #currently changes to title or is_open status + if @ticket.update_attributes(params[:post]) #this saves ticket, so @ticket.changed? will be false + tick_updated = true end # TODO: do we want to keep the history of title changes? one possibility was adding a comment that said something like 'user changed the title from a to b' - # TODO: this is throwing a missing template error - return - elsif 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. + tick_updated = true if @ticket.changed? and @ticket.save end - if @ticket.changed? and @ticket.save + if tick_updated flash[:notice] = 'Ticket was successfully updated.' if @ticket.is_open respond_with @ticket @@ -95,14 +80,14 @@ class TicketsController < ApplicationController #respond_with(@ticket) # why does this go to edit?? redirect??? end end + end def index - #TODO: we will need pagination @all_tickets = Ticket.for_user(current_user, params, admin?) #for tests, useful to have as separate variable #below works if @tickets is a CouchRest::Model::Designs::View, but not if it is an Array - @tickets = @all_tickets.page(params[:page]).per(10) #TEST + @tickets = @all_tickets.page(params[:page]).per(10) #respond_with(@tickets) end diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index cd4fcfb..781216e 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -216,6 +216,7 @@ class Ticket < CouchRest::Model::Base end #not saving with close and reopen, as we will save in update when they are called. + #TODO: not sure if we should bother with these: def close self.is_open = false #save diff --git a/help/app/views/tickets/_new_comment.html.haml b/help/app/views/tickets/_new_comment.html.haml index a924dfd..b216311 100644 --- a/help/app/views/tickets/_new_comment.html.haml +++ b/help/app/views/tickets/_new_comment.html.haml @@ -1,3 +1,2 @@ -= #do we want this partial? not using it now -= simple_fields_for :comment do |c| += f.simple_fields_for :comments, comment_object do |c| = c.input :body, :label => 'Comment', :as => :text diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml index 537b97f..0ee47ff 100644 --- a/help/app/views/tickets/new.html.haml +++ b/help/app/views/tickets/new.html.haml @@ -1,16 +1,9 @@ %h2=t :new_ticket = simple_form_for(@ticket, :html => {:novalidate => true}) do |f| #turn off html5 validations to test - = #@ticket.errors.messages = f.input :title - = #f.input :email #if there is no current_user = f.input :email if !current_user #hmm--might authenticated users want to submit an alternate email? - - = f.simple_fields_for :comments do |c| - = c.input :body, :label => 'Comment', :as => :text - - = #render :partial => 'new_comment' #what we were using + = render :partial => 'new_comment', :locals => {:f => f, :comment_object => nil} = # regarding_user if not logged in = # email if not logged in - = #f.button :submit, :value => t(:submit), :class => 'btn-primary' = f.button :submit = link_to t(:cancel), tickets_path, :class => :btn diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index f09f525..b9f2ce6 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -1,6 +1,6 @@ %h2= @ticket.title -%a#title.editable.editable-click{"data-name" => "title", "data-original-title" => "Enter username", "data-resource" => "post", "data-type" => "text", "data-url" => ticket_path(@ticket.id), "data-pk" => @ticket.id, :href => "#"} +%a#title.editable.editable-click{"data-name" => "title", "data-resource" => "post", "data-type" => "text", "data-url" => ticket_path(@ticket.id), "data-pk" => @ticket.id, :href => "#"} = @ticket.title %p @@ -17,26 +17,18 @@ = "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 + = button_to 'close', {:post => {:is_open => false}}, :method => :put - else = 'closed' - = button_to 'open', {:change_status => :open}, :method => :put + = button_to 'open', {:post => {:is_open => true}}, :method => :put = render(:partial => "comment", :collection => @ticket.comments) = #render @ticket.comments should work if view is in /app/views/comments/_comment = 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] #remove + = render :partial => 'new_comment', :locals => {:f => f, :comment_object => TicketComment.new} = f.button :submit, @post_reply_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 want to have button to close -= # TODO if admin, have button to delete += button_to 'destroy', ticket_path, :confirm => 'are you sure?', :method => :delete if admin? = link_to t(:cancel), tickets_path, :class => :btn -- cgit v1.2.3