Browse Source

* comments:

* show error if ajax req failed
  * use .serialize() instead manual form packing
master
Alex 'AdUser' Z 9 years ago
parent
commit
493598ca7e
  1. 16
      public/theme/js/main.js
  2. 4
      templates/comments/list.html.ep
  3. 3
      templates/comments/new.html.ep

16
public/theme/js/main.js

@ -18,21 +18,15 @@ $(document).ready(function() {
$('a#cadd').click(function(e) { $('a#cadd').click(function(e) {
e.preventDefault(); e.preventDefault();
$(this).remove(); $(this).remove();
$('#comments').load('/comments/new', function() { $('div#cadd').load('/comments/new', function() {
// form submit with ajax // form submit with ajax
$('#comments form').submit(function(e) { $('#comments form').submit(function(e) {
e.preventDefault(); e.preventDefault();
var url = document.createElement('a'); $.post('/comments/add', $(this).serialize())
url.href = window.location; .done(function(data) { location.reload(); })
var text = $('#comments textarea').val(); .fail(function(data) { $('#comments #resp').val(data); });
$.post('/comments/add', {
'pageid': escape(url.pathname),
'text': text,
}, function() {
location.reload();
});
}); // form submit }); // form submit
}); // on form load }); // on form load
}); // #cadd click }); // #cadd click
}); // #comments }); // #comments load
}); // document ready }); // document ready

4
templates/comments/list.html.ep

@ -13,4 +13,6 @@
</div> </div>
</div> </div>
% } % }
<p><a href="#" id="cadd"><%= l('Add') %></a></p> <div id="cadd">
<a href="#" id="cadd"><%= l('Add') %></a>
</div>

3
templates/comments/new.html.ep

@ -1,8 +1,9 @@
% my $pageid = stash('pageid') || ''; % my $pageid = stash('pageid') || '';
<form method="POST" action="/comments/add" id="cadd"> <form method="POST" action="/comments/add" id="cadd">
<input type="hidden" value="<%= $pageid %>" name="pageid">
<hr/> <hr/>
<textarea></textarea> <textarea></textarea>
<br/> <br/>
<input type="submit" value="<%= l('Add') %>"> <input type="submit" value="<%= l('Add') %>">
<input type="hidden" value="<%= $pageid %>" name="pageid"> <span id="resp" style="color: red"></span>
</form> </form>

Loading…
Cancel
Save