Metoda PHP:
public function executeEditStickyComment(sfWebRequest $request) { $query = Doctrine_Query::create() ->update('StickyHasComments') ->set('comment', '?' , $_POST['comment']) ->where('id_sticky_has_comment=?', $_POST['id_sticky_has_comment']) ->execute(); exit; }
JS:
$('.edit_link').live('click', function(e){ var $this = $(this); var el_id = $this.attr('data-sticky-has-comment-id'); var el_val = $this.parent('.post').find('.post-content').addClass('active-edit').html(); var $el = $('.post-content.active-edit'); var $parent = $this.parent('.post'); var textarea_html = '<textarea class="edit_text_area" id="el_id-'+el_id+'">'+el_val+'</textarea>'; $el.fadeOut(200, function() { $('.btn, .statuses').addClass('hide'); $('.ui-dialog-buttonset button, #comment, .statuses').attr('disabled', true); $this.fadeOut(200, function() { if ( $('#el_id-'+el_id).length == 0) { $parent.append(textarea_html); } else { $('.edit_text_area').removeClass('active'); $('#el_id-'+el_id).removeClass('hide').addClass('active').fadeIn(); } if ( $('#save_comment'+el_id).hasClass('hide') ) { $('#save_comment'+el_id).removeClass('hide'); } if ($('#save_comment'+el_id)) { $('#save_comment'+el_id).live('click',function(e) { var comment = $('#el_id-'+el_id).val(); $.ajax({ url: "/sticky/EditStickyComment", data: { comment: comment, id_sticky_has_comment: el_id }, type: "POST", dataType : "json", success: function(res) { $('.post-content.active-edit').text(comment); $('#save_comment'+el_id).addClass('hide').fadeOut(200, function() { $this.fadeIn(200); }); $('#el_id-'+el_id).fadeOut(function() { $el.fadeIn(200); }); $('.btn, .statuses').removeClass('hide'); $('.ui-dialog-buttonset button, #comment').attr('disabled', false); $('.post-content.active-edit').removeClass('active-edit'); $('.ui-dialog-titlebar-close').live('click', function(){ $('.post-content.active-edit').removeClass('active-edit'); $('#edit_comment.active-edit').removeClass('active-edit'); }); } }); e.preventDefault(); }) } }); });
HTML:
<div class="post-container" style="height: 60%; width:100%; overflow-y: scroll; padding-top: 15px;"><div class="post" style="border-bottom: 1px solid black;margin-bottom: 10px; padding-bottom: 10px;"><span style="width: 100px;" class="post-date">2014-11-24 22:10:20</span> <a class="btn hide" style="color: blue;" id="delete_comment" href="#" data-sticky-has-comment-id="208">usun</a> <a style="color: blue;" class="" id="save_comment208" href="#" data-sticky-has-comment-id="208">zapisz</a> <a style="color: blue; display: inline;" id="edit_comment" href="#" data-sticky-has-comment-id="208" data-username="Administrator" data-user-id="1" data-datetime="2014-11-24 22:10:20" data-comment="159" class="edit_link btn hide">edytuj</a> <i id="fa-check" class="fa fa-check statuses hide" disabled="disabled" style="color: rgb(0, 0, 0);"></i> <i id="fa-exclamation" class="fa fa-exclamation statuses hide" disabled="disabled"></i> <i id="fa-times-circle-o" class="fa fa-times-circle-o statuses hide" disabled="disabled"></i> <p class="post-name">Administrator</p><p class="post-content active-edit" data-sticky-has-comment-id="208" style="display: none;">159adfas123</p><textarea class="edit_text_area active" id="el_id-208" style="display: inline-block;">159</textarea></div></div>
Jest cos wedlug was co moze powodowac po jednym kliknieciu wywolanie 2 wywolan ajaxowych i za kazdym razem zwieksza sie o 2 po zmienie pola i kliknieciu zapisz hmmmm