From 99e3bbb762c9a9c851be69172440bc4e259791b2 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 28 Feb 2012 21:41:47 +0600 Subject: [PATCH] [refs #194] update issue content --- app/assets/javascripts/tracker.js | 24 ++++++++++++++++++++++++ app/controllers/issues_controller.rb | 8 ++++++-- app/views/issues/show.html.haml | 14 ++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/tracker.js b/app/assets/javascripts/tracker.js index 8e9d79940..c2ce9a81d 100644 --- a/app/assets/javascripts/tracker.js +++ b/app/assets/javascripts/tracker.js @@ -205,4 +205,28 @@ $(document).ready(function() { return false; }); + $('#edit_issue_content').live('click', function() { + $('.edit_form.issue').fadeIn('slow'); + $(this).fadeOut('slow'); + }); + + $('.edit_form.issue').live('submit', function() { + var form = $(this); + $.ajax({ + type: 'POST', + url: form.attr("action"), + data: form.serialize(), + success: function(data){ + form.fadeOut('slow'); + $('#edit_issue_content').fadeIn('slow'); + $('h3.issue_title').html(form.find('#issue_title').attr('value')); + $('.fulltext.view.issue_body').html(form.find('#issue_body').attr('value')); + }, + error: function(data){ + alert('error') // TODO remove + } + }); + return false; + }); + }); diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 15af3a55d..2d3f13cf5 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -65,9 +65,13 @@ class IssuesController < ApplicationController @issue.set_close(current_user) if status == 'closed' @issue.set_open if status == 'open' status = 200 if @issue.save + render action, :status => (status || 500), :layout => false + else + @issue.title = params[:issue][:title] + @issue.body = params[:issue][:body] + status = 200 if @issue.save + render :nothing => true, :status => (status || 500), :layout => false end - - render action, :status => (status || 500), :layout => false end def destroy diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml index fca926f2c..e8e508867 100644 --- a/app/views/issues/show.html.haml +++ b/app/views/issues/show.html.haml @@ -2,7 +2,7 @@ -render :partial => 'issues/create_sidebar' -content_for :right_nopadding do dummy -%h3=@issue.title +%h3.issue_title=@issue.title .activity .top .image @@ -13,8 +13,18 @@ %span.date=@issue.created_at.to_s(:long) %br/ .both - .fulltext.view=@issue.body + .fulltext.view.issue_body=@issue.body .both +%br +- if can? :write, @issue.project + =link_to t('layout.edit'), '#', :id => 'edit_issue_content', :class => 'button' + =form_for :issue, :url => [@project, @issue], :method => :put, :html => { :class => 'edit_form issue', :style => 'display:none;' } do |f| + .leftlist= t('activerecord.attributes.issue.title') + ':' + .rightlist= f.text_field :title + .leftlist= t('activerecord.attributes.issue.body') + ':' + .rightlist= f.text_area :body + .both + =f.submit t('layout.update'), :id => 'update_issue_content' .hr =render :partial => 'issues/status'