first commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp */
|
||||
(function($){
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
|
||||
var section = $('#wpml-translation-feedback-options'),
|
||||
enableToggle = section.find('#wpml-tf-enable-translation-feedback'),
|
||||
displayMode = section.find('input[name="display_mode"]'),
|
||||
saveTriggers = section.find('.js-wpml-tf-trigger-save');
|
||||
|
||||
var saveSettings = function (node) {
|
||||
var spinner = node.closest('.js-wpml-tf-settings-block').find('.spinner'),
|
||||
message = node.closest('.js-wpml-tf-settings-block').find('.js-wpml-tf-request-status').empty(),
|
||||
settings = getSerializedSettings();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
wp.ajax.send({
|
||||
data: {
|
||||
action: section.data('action'),
|
||||
nonce: section.data('nonce'),
|
||||
settings: settings
|
||||
},
|
||||
success: function (data) {
|
||||
spinner.removeClass('is-active');
|
||||
message.html(data).fadeIn().delay(3000).fadeOut();
|
||||
},
|
||||
error: function (data) {
|
||||
spinner.removeClass('is-active');
|
||||
message.html(data).fadeIn().delay(3000).fadeOut();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var getSerializedSettings = function() {
|
||||
var form = section.find('form'),
|
||||
disabled = form.find(':input:disabled').prop('disabled', false),
|
||||
settings = form.find('input, select, textarea').serialize();
|
||||
|
||||
disabled.prop('disabled', true);
|
||||
|
||||
return settings;
|
||||
};
|
||||
|
||||
enableToggle.on('change', function() {
|
||||
section.find('.js-wpml-tf-full-options').slideToggle();
|
||||
});
|
||||
|
||||
displayMode.on('change', function() {
|
||||
var customDisplayMode = section.find('#wpml_tf_display_mode_custom');
|
||||
|
||||
if (customDisplayMode.is(':checked')) {
|
||||
customDisplayMode.closest('li').find('select').prop('disabled', false);
|
||||
} else {
|
||||
customDisplayMode.closest('li').find('select').prop('disabled', true);
|
||||
}
|
||||
});
|
||||
|
||||
saveTriggers.on('change', function() {
|
||||
saveSettings($(this));
|
||||
});
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,190 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp */
|
||||
(function($){
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
var table = $('.js-wpml-tf-feedback-list-table'),
|
||||
ajax_action = $('.wpml-tf-feedback-list-page input[name="ajax_action"]').val(),
|
||||
ajax_nonce = $('.wpml-tf-feedback-list-page input[name="ajax_nonce"]').val();
|
||||
|
||||
var openFeedbackDetails = function (feedbackId) {
|
||||
table.find('#wpml-tf-feedback-' + feedbackId).hide();
|
||||
table.find('#wpml-tf-feedback-details-' + feedbackId).show();
|
||||
};
|
||||
|
||||
var closeAllFeedbackDetails = function () {
|
||||
table.find('.js-wpml-tf-feedback-details').hide();
|
||||
table.find('.js-wpml-tf-feedback').show();
|
||||
};
|
||||
|
||||
var getFeedbackNode = function(el) {
|
||||
return $(el).closest('.js-wpml-tf-feedback-details, .js-wpml-tf-feedback');
|
||||
};
|
||||
|
||||
var getFeedbackId = function(el) {
|
||||
return getFeedbackNode(el).data('feedback-id');
|
||||
};
|
||||
|
||||
var getFeedbackContentUpdate = function(node) {
|
||||
var newContentNode = node.find('.js-wpml-tf-edit-feedback'),
|
||||
originalContent = node.find('.js-wpml-tf-readonly-feedback').text();
|
||||
|
||||
if ( newContentNode.length && originalContent !== newContentNode.val() ) {
|
||||
return newContentNode.val();
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var getFeedbackReviewerId = function(node) {
|
||||
var reviewerNode = node.find('.js-wpml-tf-reviewer');
|
||||
|
||||
if ( reviewerNode.length ) {
|
||||
return parseInt(reviewerNode.val());
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var getFeedbackMessage = function(node) {
|
||||
var newMessage = node.find('.js-wpml-tf-new-message').val();
|
||||
|
||||
if ( newMessage ) {
|
||||
return newMessage;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var submitActionOnFeedback = function(id, action) {
|
||||
var currentURL = WPML_core.sanitize( window.location.href ),
|
||||
params = {
|
||||
nonce: WPML_core.sanitize(table.closest('form').find('input[name="nonce"]').val()),
|
||||
bulk_action: action,
|
||||
bulk_action2: action,
|
||||
feedback_ids: [ id ],
|
||||
};
|
||||
|
||||
window.location = currentURL + '&' + $.param(params);
|
||||
};
|
||||
|
||||
var sendRequest = function(node, data, reload) {
|
||||
var spinner = node.find('.spinner'),
|
||||
error_notification = node.find('.js-wpml-tf-feedback-details-error').empty();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
data.action = ajax_action;
|
||||
data.nonce = ajax_nonce;
|
||||
data.feedback_id = getFeedbackId(node);
|
||||
|
||||
wp.ajax.send({
|
||||
data: data,
|
||||
success: function (response) {
|
||||
if (reload) {
|
||||
window.location.href = WPML_core.sanitize(window.location.pathname + window.location.search + window.location.hash);
|
||||
} else {
|
||||
spinner.removeClass('is-active');
|
||||
refreshFeedbackRows(data.feedback_id, response);
|
||||
}
|
||||
},
|
||||
error: function (error_message) {
|
||||
spinner.removeClass('is-active');
|
||||
error_notification.html(error_message).fadeIn();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var refreshFeedbackRows = function(feedbackId, data) {
|
||||
var summary = $.parseHTML(data.summary_row),
|
||||
details = $.parseHTML(data.details_row);
|
||||
|
||||
table.find('#wpml-tf-feedback-' + feedbackId).first().replaceWith(summary);
|
||||
table.find('#wpml-tf-feedback-details-' + feedbackId).first().replaceWith(details);
|
||||
};
|
||||
|
||||
var attachEvents = function() {
|
||||
table.on( 'click', '.js-wpml-tf-open-details', function(e) {
|
||||
e.preventDefault();
|
||||
closeAllFeedbackDetails();
|
||||
openFeedbackDetails(getFeedbackId(this));
|
||||
}).on( 'click', '.js-wpml-tf-cancel', function(e) {
|
||||
e.preventDefault();
|
||||
closeAllFeedbackDetails();
|
||||
}).on( 'click', '.js-wpml-tf-enable-translator-note', function(e) {
|
||||
e.preventDefault();
|
||||
var trigger = $(this);
|
||||
trigger.siblings('.js-wpml-tf-translator-note').show();
|
||||
trigger.remove();
|
||||
}).on( 'click', '.js-wpml-tf-enable-edit-feedback', function(e) {
|
||||
e.preventDefault();
|
||||
var trigger = $(this);
|
||||
trigger.siblings('.js-wpml-tf-readonly-feedback').hide();
|
||||
trigger.siblings('.js-wpml-tf-edit-feedback').show();
|
||||
trigger.remove();
|
||||
}).on( 'click', '.js-wpml-tf-send', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var node = getFeedbackNode(this),
|
||||
data = {
|
||||
edit_action: 'update_feedback'
|
||||
};
|
||||
|
||||
if (getFeedbackContentUpdate(node)) {
|
||||
data.feedback_content = getFeedbackContentUpdate(node);
|
||||
}
|
||||
|
||||
if (getFeedbackReviewerId(node)) {
|
||||
data.feedback_reviewer_id = getFeedbackReviewerId(node);
|
||||
}
|
||||
|
||||
if (getFeedbackMessage(node)) {
|
||||
data.message_content = getFeedbackMessage(node);
|
||||
}
|
||||
|
||||
data.feedback_status = $(this).val();
|
||||
|
||||
if (node.find('.js-wpml-tf-translation-fixed-checkbox:checked').length > 0) {
|
||||
data.feedback_status = 'fixed';
|
||||
}
|
||||
|
||||
sendRequest(node, data);
|
||||
}).on('click', '.js-wpml-tf-refresh-status', function(e) {
|
||||
e.preventDefault();
|
||||
var node = getFeedbackNode(this),
|
||||
data = {
|
||||
edit_action: 'update_feedback',
|
||||
feedback_status: 'sent_to_ts_api'
|
||||
};
|
||||
|
||||
sendRequest(node, data);
|
||||
}).on('click', '.js-wpml-tf-translation-fixed', function(e) {
|
||||
e.preventDefault();
|
||||
var node = getFeedbackNode(this),
|
||||
data = {
|
||||
edit_action: 'update_feedback',
|
||||
feedback_status: 'fixed'
|
||||
};
|
||||
|
||||
sendRequest(node, data);
|
||||
}).on('click', '.js-wpml-tf-error-details a', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).siblings('pre').show();
|
||||
$(this).remove();
|
||||
}).on('click', '.js-wpml-tf-trash', function(e) {
|
||||
e.preventDefault();
|
||||
submitActionOnFeedback(getFeedbackId(this), 'trash');
|
||||
}).on('click', '.js-wpml-tf-untrash', function(e) {
|
||||
e.preventDefault();
|
||||
submitActionOnFeedback(getFeedbackId(this), 'untrash');
|
||||
}).on('click', '.js-wpml-tf-delete', function(e) {
|
||||
e.preventDefault();
|
||||
submitActionOnFeedback(getFeedbackId(this), 'delete');
|
||||
});
|
||||
};
|
||||
|
||||
attachEvents();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,146 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, wp */
|
||||
(function($){
|
||||
"use strict";
|
||||
|
||||
$(function () {
|
||||
var form = $('.js-wpml-tf-feedback-form'),
|
||||
openIcon = $('.js-wpml-tf-feedback-icon'),
|
||||
ratingInput = form.find('input[name="wpml-tf-rating"]'),
|
||||
sendButton = form.find('.js-wpml-tf-comment-button'),
|
||||
documentId = form.find('input[name="document_id"]').val(),
|
||||
documentType = form.find('input[name="document_type"]').val(),
|
||||
action = form.find('input[name="action"]').val(),
|
||||
nonce = form.find('input[name="nonce"]').val(),
|
||||
noCommentThreshold = 4,
|
||||
dialogInitialized = false,
|
||||
feedbackId;
|
||||
|
||||
var disableRating = function() {
|
||||
ratingInput.prop('disabled', true);
|
||||
};
|
||||
|
||||
var enableRating = function() {
|
||||
if(feedbackId && !form.hasClass('wpml-tf-closing-rating')) {
|
||||
ratingInput.prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
var enableComment = function() {
|
||||
sendButton.prop('disabled', false);
|
||||
};
|
||||
|
||||
var displayClosingComment = function() {
|
||||
form.removeClass('wpml-tf-pending-comment').addClass('wpml-tf-closing-comment');
|
||||
window.setTimeout(destroyDialogAndButton, 3000);
|
||||
};
|
||||
|
||||
var displayPendingComment = function() {
|
||||
form.addClass('wpml-tf-pending-comment').removeClass('wpml-tf-closing-rating');
|
||||
enableRating();
|
||||
};
|
||||
|
||||
var displayClosingRating = function() {
|
||||
form.addClass('wpml-tf-closing-rating').removeClass('wpml-tf-pending-comment');
|
||||
disableRating();
|
||||
};
|
||||
|
||||
var displayPendingRating = function() {
|
||||
form.removeClass('wpml-tf-closing-rating').removeClass('wpml-tf-pending-comment');
|
||||
enableRating();
|
||||
};
|
||||
|
||||
var sendFeedback = function(data) {
|
||||
var options;
|
||||
|
||||
if ( ! itLooksLikeSpam() ) {
|
||||
disableRating();
|
||||
form.addClass('wpml-tf-pending-request');
|
||||
|
||||
data.nonce = nonce;
|
||||
data.document_id = documentId;
|
||||
data.document_type = documentType;
|
||||
|
||||
options = {
|
||||
data: data,
|
||||
success: function(data) {
|
||||
feedbackId = data.feedback_id;
|
||||
form.addClass('wpml-tf-has-feedback-id').removeClass('wpml-tf-pending-request');
|
||||
enableRating();
|
||||
enableComment();
|
||||
}
|
||||
};
|
||||
|
||||
wp.ajax.send(action, options);
|
||||
}
|
||||
};
|
||||
|
||||
var itLooksLikeSpam = function() {
|
||||
var more_comment = form.find('textarea[name="more_comment"]');
|
||||
return ! dialogInitialized || more_comment.val();
|
||||
};
|
||||
|
||||
var openForm = function() {
|
||||
form.dialog({
|
||||
dialogClass: 'wpml-tf-feedback-form-dialog otgs-ui-dialog',
|
||||
closeOnEscape: true,
|
||||
draggable: true,
|
||||
modal: false,
|
||||
title: form.data('dialog-title'),
|
||||
dragStop: function() {
|
||||
$(this).parent().height('auto');
|
||||
}
|
||||
});
|
||||
|
||||
dialogInitialized = true;
|
||||
|
||||
// Fix display glitch with bootstrap.js
|
||||
$('.wpml-tf-feedback-form-dialog').find('.ui-dialog-titlebar-close').addClass('ui-button');
|
||||
};
|
||||
|
||||
var destroyDialogAndButton = function() {
|
||||
form.dialog( 'destroy' );
|
||||
openIcon.remove();
|
||||
};
|
||||
|
||||
openIcon.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
openForm();
|
||||
});
|
||||
|
||||
ratingInput.on('click', function() {
|
||||
var data = {
|
||||
rating: $(this).val()
|
||||
};
|
||||
|
||||
if ( feedbackId ) {
|
||||
data.feedback_id = feedbackId;
|
||||
}
|
||||
|
||||
sendFeedback(data);
|
||||
|
||||
if(data.rating < noCommentThreshold) {
|
||||
displayPendingComment();
|
||||
} else {
|
||||
displayClosingRating();
|
||||
}
|
||||
});
|
||||
|
||||
form.on('click', '.js-wpml-tf-change-rating', function(e) {
|
||||
e.preventDefault();
|
||||
displayPendingRating();
|
||||
});
|
||||
|
||||
sendButton.on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
content: $('textarea[name="wpml-tf-comment"]').val(),
|
||||
feedback_id: feedbackId
|
||||
};
|
||||
|
||||
sendFeedback(data);
|
||||
displayClosingComment();
|
||||
});
|
||||
|
||||
});
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user