1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- function commentFormSubmit(e) {
- e.preventDefault();
- var nick = $('#comment-nick').val();
- var email = $('#comment-email').val();
- var content = $('#comment-content').val();
- var commentType = $('#comment-type').val();
- var commentId = $('#comment-id').val();
- if (!nick) {
- alert('Nie podano autora komentarza!');
- return;
- }
- if (!content) {
- alert('Nie można wysłać pustego komentarza!');
- return;
- }
- var formData = {
- 'comment-nick': nick,
- 'comment-email': email,
- 'comment-content': content,
- 'comment-type': commentType,
- 'comment-id': commentId,
- 'mode': 'json'
- };
-
- $.ajax({
- dataType: 'json',
- type: 'POST',
- data: formData,
- url: scriptUrlPrefix+'sendcomment.php',
- success: commentSubmitDone,
- error: commentSubmitFailed,
- });
- }
- function commentSubmitFailed(data) {
- alert('Nie udało się przesłać komentarza do serwera.');
- }
- function commentSubmitDone(data) {
- if (data.result == 'OK') {
- alert('Dodano komentarz');
- refreshComments();
- } else {
- alert('Nie udało się dodać komentarza! Komunikat od serwera: ' + data.error);
- }
- }
- function refreshComments() {
- var commentType = $('#comment-type').val();
- var commentId = $('#comment-id').val();
- $('#comments').text('Wczytywanie komentarzy...');
- var formData = {
- 'type': commentType,
- 'id': commentId,
- };
-
- $.ajax({
- dataType: 'html',
- type: 'GET',
- data: formData,
- url: scriptUrlPrefix+'getcomments.php',
- success: function(data) {
- $('#comments').html(data);
- addCommentFormSubmitAction();
- },
- });
- }
- function commentsImageReplace(image) {
- $('#comment-id').val(image.id);
- }
- function addCommentFormSubmitAction() {
- $('#comment-form').on('submit', commentFormSubmit);
- }
- $(document).ready(function() {
- addCommentFormSubmitAction();
- });
|