first commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
jQuery('#wpml_save_cloned_sites_report_type').click(function () {
|
||||
var reportType = jQuery('input[name*="ate_locked_option"]:checked').val();
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_save_cloned_sites_report_type',
|
||||
nonce: jQuery('#icl_doc_translation_method_cloned_nonce').val(),
|
||||
reportType: reportType
|
||||
},
|
||||
success: function () {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
jQuery(function () {
|
||||
var buttonId = '#wpml_tm_ate_source_id_migration_btn';
|
||||
|
||||
jQuery(buttonId).click(function () {
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery(this).after('<span class="wpml-fix-tp-id-spinner">' + icl_ajxloaderimg + '</span>');
|
||||
|
||||
jQuery.ajax({
|
||||
url : ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: jQuery(this).data('action'),
|
||||
nonce: jQuery(this).data('nonce'),
|
||||
},
|
||||
success: function () {
|
||||
jQuery(buttonId).prop('disabled', false);
|
||||
jQuery('.wpml-fix-tp-id-spinner').remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, wpml_clear_ts_strings */
|
||||
|
||||
/** @namespace wpml_clear_ts_strings.placeHolder */
|
||||
/** @namespace wpml_clear_ts_strings.action */
|
||||
/** @namespace wpml_clear_ts_strings.nonce */
|
||||
|
||||
var ClearPreferredTS = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.init = function () {
|
||||
var box = jQuery('#' + wpml_clear_ts_strings.placeHolder);
|
||||
var button = box.find('.button-primary');
|
||||
var spinner = box.find('.spinner');
|
||||
|
||||
button.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': wpml_clear_ts_strings.action,
|
||||
'nonce': wpml_clear_ts_strings.nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
document.location.reload(true);
|
||||
} else {
|
||||
alert(response.data);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
},
|
||||
complete: function () {
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
clearPreferredTS.init();
|
||||
});
|
||||
};
|
||||
|
||||
var clearPreferredTS = new ClearPreferredTS();
|
||||
@@ -0,0 +1,297 @@
|
||||
/*globals vkbeautify, jQuery, wp */
|
||||
|
||||
var WPML = WPML || {};
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
//Hack required for the core CodeMirror extensions to work
|
||||
var CodeMirror = wp.CodeMirror || CodeMirror;
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
//Make easier to deal with changing namespaces
|
||||
WPML.CodeMirror = WPML.CodeMirror || CodeMirror || null;
|
||||
|
||||
WPML_TM.Custom_XML_Editor = function (element) {
|
||||
this.container = element;
|
||||
this.content = this.container.getElementsByClassName('wpml-tm-custom-xml-content')[0];
|
||||
this.saveButton = this.container.getElementsByClassName('.button-primary')[0];
|
||||
this.editor = {};
|
||||
this.hightLightedLines = [];
|
||||
};
|
||||
|
||||
WPML_TM.Custom_XML_Editor.prototype = {
|
||||
init: function () {
|
||||
this.initCodeMirror();
|
||||
},
|
||||
initCodeMirror: function () {
|
||||
if (!WPML.CodeMirror) {
|
||||
return;
|
||||
}
|
||||
this.editor = WPML.CodeMirror.fromTextArea(this.content, {
|
||||
lineNumbers: true,
|
||||
mode: {
|
||||
name: 'xml',
|
||||
htmlMode: false
|
||||
},
|
||||
|
||||
matchBrackets: true,
|
||||
autoCloseBrackets: true,
|
||||
|
||||
matchTags: {bothTags: true},
|
||||
autoCloseTags: true,
|
||||
|
||||
indentUnit: 2,
|
||||
tabSize: 2,
|
||||
smartIndent: true,
|
||||
|
||||
extraKeys: this.getKeysMap(),
|
||||
|
||||
foldGutter: true,
|
||||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
|
||||
|
||||
hintOptions: {
|
||||
schemaInfo: this.getXMLSchema()
|
||||
}
|
||||
});
|
||||
|
||||
var toolbar = this.container.getElementsByClassName('wpml-tm-custom-xml-toolbar')[0];
|
||||
this.editor.addPanel(toolbar, {
|
||||
position: 'top',
|
||||
stable: true
|
||||
});
|
||||
|
||||
this.editor.setOption('theme', 'dracula');
|
||||
this.editor.setCursor(0, 0);
|
||||
},
|
||||
highlightErrors: function (errors) {
|
||||
for (var index in errors) {
|
||||
if (errors.hasOwnProperty(index)) {
|
||||
var errorsGroup = errors[index];
|
||||
|
||||
if (errorsGroup.constructor === Array) {
|
||||
for (var errorGroupIndex in errorsGroup) {
|
||||
if (errorsGroup.hasOwnProperty(errorGroupIndex)) {
|
||||
var error = errorsGroup[errorGroupIndex];
|
||||
if (error.hasOwnProperty('line')) {
|
||||
this.highlightLine(error.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
highlightLine: function (lineNumber) {
|
||||
if (lineNumber >= 1) {
|
||||
this.editor.addLineClass(lineNumber - 1, 'wrap', 'line-error');
|
||||
this.hightLightedLines.push(lineNumber - 1);
|
||||
}
|
||||
},
|
||||
resetHighlightedLines: function () {
|
||||
for (var index in this.hightLightedLines) {
|
||||
if (this.hightLightedLines.hasOwnProperty(index)) {
|
||||
this.editor.removeLineClass(this.hightLightedLines[index], 'wrap', 'line-error');
|
||||
}
|
||||
}
|
||||
this.hightLightedLines = [];
|
||||
},
|
||||
foldCode: function (cm) {
|
||||
cm.foldCode(cm.getCursor());
|
||||
},
|
||||
autoFormat: function (cm) {
|
||||
cm.save();
|
||||
cm.setValue(vkbeautify.xml(cm.getValue()));
|
||||
},
|
||||
prepareSave: function () {
|
||||
this.resetHighlightedLines();
|
||||
this.autoFormat(this.editor);
|
||||
this.editor.save();
|
||||
},
|
||||
onSaveRequest: function () {
|
||||
this.prepareSave();
|
||||
if ('undefined' !== this.onSave) {
|
||||
this.onSave();
|
||||
}
|
||||
},
|
||||
getXMLSchema: function () {
|
||||
var translateOptions = {
|
||||
attrs: {
|
||||
'translate': ['0', '1']
|
||||
}
|
||||
};
|
||||
|
||||
var translateActions = {
|
||||
attrs: {
|
||||
'action': ['copy', 'translate', 'ignore', 'copy-once'],
|
||||
'style': ['line', 'textarea', 'visual'],
|
||||
'translate_link_target': ['0', '1'],
|
||||
'convert_to_sticky': ['0', '1'],
|
||||
'label': null,
|
||||
'group': null
|
||||
}
|
||||
};
|
||||
|
||||
var genericKey = {
|
||||
attrs: {
|
||||
'name': null,
|
||||
children: ['key']
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
'!top': ['wpml-config'],
|
||||
'wpml-config': {
|
||||
children: [
|
||||
'language-switcher-settings',
|
||||
'custom-types',
|
||||
'taxonomies',
|
||||
'shortcodes',
|
||||
'custom-fields',
|
||||
'admin-texts',
|
||||
'elementor-widgets',
|
||||
'beaver-builder-widgets',
|
||||
'cornerstone-widgets'
|
||||
]
|
||||
},
|
||||
'language-switcher-settings': {
|
||||
children: ['key']
|
||||
},
|
||||
'custom-types': {
|
||||
children: ['custom-type']
|
||||
},
|
||||
'custom-type': translateOptions,
|
||||
'taxonomies': {
|
||||
children: ['taxonomy']
|
||||
},
|
||||
'taxonomy': translateOptions,
|
||||
'shortcodes': {
|
||||
children: ['shortcode']
|
||||
},
|
||||
'shortcode': {
|
||||
children: ['tag', 'attributes']
|
||||
},
|
||||
'tag': {
|
||||
attrs: {
|
||||
'encoding': null
|
||||
}
|
||||
},
|
||||
'attributes': {
|
||||
children: ['attribute']
|
||||
},
|
||||
'attribute': {},
|
||||
'custom-fields': {
|
||||
children: ['custom-field']
|
||||
},
|
||||
'custom-field': translateActions,
|
||||
'custom-term-field': {
|
||||
children: ['wpml-custom-term-field']
|
||||
},
|
||||
'wpml-custom-term-field': translateActions,
|
||||
'admin-texts': {
|
||||
children: ['key']
|
||||
},
|
||||
'key': genericKey,
|
||||
'elementor-widgets': {
|
||||
children: ['widget']
|
||||
},
|
||||
'beaver-builder-widgets': {
|
||||
children: ['widget']
|
||||
},
|
||||
'cornerstone-widgets': {
|
||||
children: ['widget']
|
||||
},
|
||||
'widget': {
|
||||
attrs: {
|
||||
name: null,
|
||||
},
|
||||
children: [
|
||||
'conditions',
|
||||
'fields',
|
||||
'fields-in-item',
|
||||
'integration-classes'
|
||||
]
|
||||
},
|
||||
'conditions': {
|
||||
children: ['condition']
|
||||
},
|
||||
'condition': {
|
||||
attrs: {
|
||||
key: null
|
||||
}
|
||||
},
|
||||
'fields': {
|
||||
children: ['field']
|
||||
},
|
||||
'fields-in-item': {
|
||||
children: ['field'],
|
||||
attrs: {
|
||||
items_of: null
|
||||
}
|
||||
},
|
||||
'field': {
|
||||
attrs: {
|
||||
type: null,
|
||||
editor_type: [
|
||||
'LINE',
|
||||
'AREA',
|
||||
'VISUAL',
|
||||
'LINK'
|
||||
],
|
||||
key_of: null,
|
||||
field_id: null
|
||||
}
|
||||
},
|
||||
'integration-classes': {
|
||||
children: ['integration-class']
|
||||
},
|
||||
'integration-class': {}
|
||||
};
|
||||
},
|
||||
getKeysMap: function () {
|
||||
var mac = WPML.CodeMirror.keyMap["default"] === WPML.CodeMirror.keyMap.macDefault;
|
||||
var ctrl = mac ? "Cmd-" : "Ctrl-";
|
||||
|
||||
var extraKeys = {
|
||||
"'<'": this.completeAfter.bind(this),
|
||||
"'/'": this.completeIfAfterLt.bind(this),
|
||||
"' '": this.completeIfInTag.bind(this),
|
||||
"'='": this.completeIfInTag.bind(this)
|
||||
};
|
||||
|
||||
extraKeys[ctrl + 'Space'] = 'autocomplete';
|
||||
extraKeys[ctrl + 'K'] = this.foldCode;
|
||||
extraKeys[ctrl + 'F'] = this.autoFormat;
|
||||
extraKeys[ctrl + 'S'] = this.onSaveRequest.bind(this);
|
||||
|
||||
return extraKeys;
|
||||
},
|
||||
completeAfter: function (cm, pred) {
|
||||
if (!pred || pred()) {
|
||||
setTimeout(function () {
|
||||
if (!cm.state.completionActive) {
|
||||
cm.showHint({completeSingle: false});
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
return WPML.CodeMirror.Pass;
|
||||
|
||||
},
|
||||
completeIfAfterLt: function (cm) {
|
||||
return this.completeAfter(cm, function () {
|
||||
var cur = cm.getCursor();
|
||||
return cm.getRange(WPML.CodeMirror.Pos(cur.line, cur.ch - 1), cur) === "<";
|
||||
});
|
||||
},
|
||||
completeIfInTag: function (cm) {
|
||||
return this.completeAfter(cm, function () {
|
||||
var tok = cm.getTokenAt(cm.getCursor());
|
||||
if (tok.type === "string" && (!/['"]/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length === 1)) {
|
||||
return false;
|
||||
}
|
||||
var inner = WPML.CodeMirror.innerMode(cm.getMode(), tok.state).state;
|
||||
return inner.tagName;
|
||||
});
|
||||
}
|
||||
};
|
||||
}());
|
||||
@@ -0,0 +1,173 @@
|
||||
/*globals jQuery, ajaxurl */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
WPML_TM.Custom_XML = function (element, codeMirror) {
|
||||
this.container = element;
|
||||
this.spinner = this.container.find('.spinner');
|
||||
this.content = this.container.find('.wpml-tm-custom-xml-content');
|
||||
this.messages = this.container.find('.js-wpml-tm-messages');
|
||||
this.action = this.content.data('action');
|
||||
this.nonceValidate = this.content.data('nonce-validate');
|
||||
this.nonceSave = this.content.data('nonce-save');
|
||||
this.saveButton = this.container.find('.button-primary');
|
||||
this.editor = codeMirror;
|
||||
};
|
||||
|
||||
WPML_TM.Custom_XML.prototype = {
|
||||
init: function () {
|
||||
this.saveButton.on('click', jQuery.proxy(this.onSave, this));
|
||||
if (this.editor) {
|
||||
this.editor.init();
|
||||
this.editor.onSave = jQuery.proxy(function () {this.saveButton.trigger('click');}, this);
|
||||
}
|
||||
},
|
||||
onSave: function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (this.editor) {
|
||||
this.editor.prepareSave();
|
||||
}
|
||||
|
||||
var content = this.content.val();
|
||||
|
||||
this.messages.empty();
|
||||
this.showSpinner();
|
||||
this.validate(content);
|
||||
},
|
||||
validate: function (content) {
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: this.action + '-validate',
|
||||
nonce: this.nonceValidate,
|
||||
content: content
|
||||
},
|
||||
context: this,
|
||||
success: jQuery.proxy(this.validated, this),
|
||||
error: jQuery.proxy(this.onError, this)
|
||||
});
|
||||
},
|
||||
validated: function (response) {
|
||||
this.addMessage(response);
|
||||
if (response.success) {
|
||||
this.save(this.content.val());
|
||||
} else {
|
||||
this.highlightErrors(response);
|
||||
this.hideSpinner();
|
||||
}
|
||||
},
|
||||
onError: function (response) {
|
||||
this.addMessage(response);
|
||||
this.highlightErrors(response);
|
||||
this.hideSpinner();
|
||||
},
|
||||
highlightErrors: function (response) {
|
||||
if (this.editor) {
|
||||
this.editor.highlightErrors(response.data);
|
||||
}
|
||||
},
|
||||
save: function (content) {
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: this.action + '-save',
|
||||
nonce: this.nonceSave,
|
||||
content: content
|
||||
},
|
||||
context: this,
|
||||
success: jQuery.proxy(this.saved, this),
|
||||
error: jQuery.proxy(this.onError, this),
|
||||
complete: jQuery.proxy(this.hideSpinner, this)
|
||||
});
|
||||
},
|
||||
saved: function (response) {
|
||||
this.addMessage(response);
|
||||
},
|
||||
addMessage: function (response) {
|
||||
var message = '';
|
||||
var type = '';
|
||||
if ('undefined' !== response) {
|
||||
message = 'error';
|
||||
type = 'error';
|
||||
if (response.hasOwnProperty('success') && response.success) {
|
||||
type = 'info';
|
||||
message = 'success';
|
||||
}
|
||||
if (response.hasOwnProperty('data') && response.data) {
|
||||
if (typeof(response.data) === 'string' || response.data instanceof String) {
|
||||
message = response.data;
|
||||
} else if (response.data.constructor === Array) {
|
||||
message = this.convertArrayToUL(response.data);
|
||||
} else if (typeof response.data === 'object') {
|
||||
message = this.convertObjectToTable(response.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
var messageContainer = jQuery('<p></p>');
|
||||
messageContainer.addClass(type);
|
||||
messageContainer.html(message);
|
||||
this.messages.append(messageContainer);
|
||||
},
|
||||
showSpinner: function () {
|
||||
this.spinner.addClass('is-active');
|
||||
},
|
||||
hideSpinner: function () {
|
||||
this.spinner.removeClass('is-active');
|
||||
},
|
||||
convertObjectToTable: function (data) {
|
||||
var html = '<table>';
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property)) {
|
||||
html += '<tr><th>' + property + '</th><td>' + data[property] + '</td></tr>';
|
||||
}
|
||||
}
|
||||
html += '</table>';
|
||||
return html;
|
||||
},
|
||||
convertArrayToUL: function (data) {
|
||||
var html = '<ul>';
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property)) {
|
||||
html += '<li>';
|
||||
if (typeof(data[property]) === 'string' || data[property] instanceof String) {
|
||||
html += data[property];
|
||||
} else if (data[property].constructor === Array) {
|
||||
html += this.convertArrayToUL(data[property]);
|
||||
} else if (typeof data[property] === 'object') {
|
||||
if (data[property].hasOwnProperty('message') && data[property].message) {
|
||||
html += data[property].message;
|
||||
} else if (data[property].hasOwnProperty('error') && data[property].error) {
|
||||
html += data[property].error;
|
||||
} else {
|
||||
html += this.convertObjectToTable(data[property]);
|
||||
}
|
||||
}
|
||||
html += '</li>';
|
||||
}
|
||||
}
|
||||
html += '</ul>';
|
||||
return html;
|
||||
}
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
var items = document.getElementsByClassName('js-wpml-tm-custom-xml');
|
||||
|
||||
var i;
|
||||
for (i = 0; i < items.length; i++) {
|
||||
var codeMirror;
|
||||
if (WPML_TM.Custom_XML_Editor) {
|
||||
codeMirror = new WPML_TM.Custom_XML_Editor(items[i]);
|
||||
}
|
||||
var customXML = new WPML_TM.Custom_XML(jQuery(items[i]), codeMirror);
|
||||
customXML.init();
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,19 @@
|
||||
jQuery(function () {
|
||||
jQuery('#wpml_fix_tp_id_btn').click(function () {
|
||||
jQuery(this).prop('disabled', true);
|
||||
jQuery(this).after('<span class="wpml-fix-tp-id-spinner">' + icl_ajxloaderimg + '</span>');
|
||||
jQuery.ajax({
|
||||
url : ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
job_ids: jQuery('#wpml_fix_tp_id_text').val(),
|
||||
action : 'wpml-fix-translation-jobs-tp-id',
|
||||
nonce : jQuery('#wpml-fix-tp-id-nonce').val(),
|
||||
},
|
||||
success: function () {
|
||||
jQuery('#wpml_fix_tp_id_btn').prop('disabled', false);
|
||||
jQuery('.wpml-fix-tp-id-spinner').remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
9
wp-content/plugins/wpml-translation-management/res/js/iframeResizer.min.js
vendored
Normal file
9
wp-content/plugins/wpml-translation-management/res/js/iframeResizer.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,77 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.translateLinkTargets = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function () {
|
||||
jQuery(function () {
|
||||
self.button = jQuery('#wpml-scan-link-targets');
|
||||
self.postCount = self.button.data('post-count');
|
||||
self.stringCount = self.button.data('string-count');
|
||||
self.button.on('click', function () {
|
||||
self.button.prop('disabled', true);
|
||||
self.button.parent().find('.spinner').css('visibility', 'visible');
|
||||
self.numberFixed = 0;
|
||||
showCompletePercent(self.postCount, 'post');
|
||||
wpmlScanLinkTargets(0, 10, true);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var wpmlScanLinkTargets = function ( start, count, isPosts ) {
|
||||
var message = self.button.data( isPosts ? 'post-message' : 'string-message' );
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'POST',
|
||||
data: {
|
||||
'last_processed': start,
|
||||
'number_to_process': count,
|
||||
'nonce': jQuery('[name=wpml-translate-link-targets]').val(),
|
||||
'action': isPosts ? 'WPML_Ajax_Update_Link_Targets_In_Posts' : 'WPML_Ajax_Update_Link_Targets_In_Strings'
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
self.numberFixed += response.data.links_fixed;
|
||||
if ( response.data.number_left > 0 ) {
|
||||
|
||||
showCompletePercent( response.data.number_left, isPosts ? 'post' : 'string' );
|
||||
wpmlScanLinkTargets( response.data.last_processed + 1, 10, isPosts );
|
||||
} else {
|
||||
showCompletePercent( self.stringCount, 'string' );
|
||||
if ( isPosts && self.stringCount ) {
|
||||
wpmlScanLinkTargets( 0, 10, false );
|
||||
} else {
|
||||
self.button.prop('disabled', false);
|
||||
self.button.parent().find('.spinner').css('visibility', 'hidden');
|
||||
self.button.parent().find( '.results' ).html( self.button.data( 'complete-message').replace( '%s', self.numberFixed ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var showCompletePercent = function( numberLeft, type ) {
|
||||
var total = type == 'post' ? self.postCount : self.stringCount,
|
||||
done = total - numberLeft,
|
||||
message = self.button.data( type + '-message' );
|
||||
|
||||
message = message.replace( '%1$s', done );
|
||||
message = message.replace( '%2$s', total );
|
||||
|
||||
self.button.parent().find( '.results' ).html( message );
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
};
|
||||
|
||||
var translateLinkTargets = new WPML_TM.translateLinkTargets();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
jQuery(function () {
|
||||
|
||||
var ajax_success_action = function (response, response_text) {
|
||||
if (response.success) {
|
||||
response_text.text(icl_ajx_saved);
|
||||
} else {
|
||||
response_text.text(icl_ajx_error);
|
||||
response_text.show();
|
||||
}
|
||||
setTimeout(function () {
|
||||
response_text.fadeOut('slow');
|
||||
}, 2500);
|
||||
};
|
||||
|
||||
jQuery( '#js-translated_document-options-btn' ).click(function(){
|
||||
|
||||
var document_status = jQuery( 'input[name*="icl_translated_document_status"]:checked' ).val(),
|
||||
page_url = jQuery( 'input[name*="icl_translated_document_page_url"]:checked' ).val(),
|
||||
response_text = jQuery( '#icl_ajx_response_tdo' ),
|
||||
spinner = '<span id="js-document-options-spinner" style="float: inherit; margin: 0" class="spinner is-active"></span>';
|
||||
|
||||
response_text.html( spinner );
|
||||
response_text.show();
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_translated_document_options',
|
||||
nonce: jQuery( '#wpml-translated-document-options-nonce' ).val(),
|
||||
document_status: document_status,
|
||||
page_url: page_url
|
||||
},
|
||||
success: function ( response ) {
|
||||
ajax_success_action( response, response_text );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
jQuery( '#translation-pickup-mode' ).click(function(){
|
||||
var pickup_mode = jQuery( 'input[name*="icl_translation_pickup_method"]:checked' ).val(),
|
||||
response_text = jQuery( '#icl_ajx_response_tpm' ),
|
||||
spinner = '<span id="js-document-options-spinner" style="float: inherit; margin: 0" class="spinner is-active"></span>';
|
||||
|
||||
response_text.html( spinner );
|
||||
response_text.show();
|
||||
|
||||
jQuery.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpml_save_translation_pickup_mode',
|
||||
nonce: jQuery( '#wpml_save_translation_pickup_mode' ).val(),
|
||||
pickup_mode: pickup_mode
|
||||
},
|
||||
success: function ( response ) {
|
||||
ajax_success_action( response, response_text );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
/* global jQuery, window */
|
||||
|
||||
(function($) {
|
||||
|
||||
$(function () {
|
||||
|
||||
var alert = $('.js-wpml-tm-post-edit-alert');
|
||||
|
||||
if (0 === alert.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
alert.dialog({
|
||||
dialogClass : 'otgs-ui-dialog',
|
||||
closeOnEscape: false,
|
||||
draggable: false,
|
||||
modal: true,
|
||||
minWidth: 520,
|
||||
open: function(e) {
|
||||
$(e.target).closest('.otgs-ui-dialog').find('.ui-widget-header').remove();
|
||||
}
|
||||
});
|
||||
|
||||
alert.on('click', '.js-wpml-tm-go-back', function(e) {
|
||||
e.preventDefault();
|
||||
dismiss_translation_editor_notice();
|
||||
window.history.go(-1);
|
||||
}).on('click', '.js-wpml-tm-continue', function(e) {
|
||||
e.preventDefault();
|
||||
dismiss_translation_editor_notice();
|
||||
alert.dialog('close');
|
||||
}).on( 'click', '.js-wpml-tm-open-in-te', function() {
|
||||
dismiss_translation_editor_notice();
|
||||
} );
|
||||
|
||||
function dismiss_translation_editor_notice() {
|
||||
|
||||
var show_again_checkbox = $( '.do-not-show-again' );
|
||||
|
||||
if ( show_again_checkbox.prop('checked') ) {
|
||||
|
||||
var action = show_again_checkbox.attr( 'data-action' );
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: action,
|
||||
nonce: $( '#'+action ).val()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,25 @@
|
||||
/*globals jQuery, ajaxurl*/
|
||||
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery('#wpml-tm-refresh-services').click(function () {
|
||||
var button = jQuery(this);
|
||||
|
||||
button.prop('disabled', true);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url : ajaxurl,
|
||||
data: {
|
||||
'nonce': jQuery(this).data('nonce'),
|
||||
'action': 'wpml_tm_refresh_services'
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function ( res ) {
|
||||
button.prop( 'disabled', true );
|
||||
jQuery( '.wpml-tm-refresh-services-msg' ).html( res.data.message );
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, wpml_reset_pro_trans_config_strings */
|
||||
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.placeHolder */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.confirmation */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.reset */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.action */
|
||||
/** @namespace wpml_reset_pro_trans_config_strings.nonce */
|
||||
|
||||
var ResetProTransConfig = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.init = function () {
|
||||
var checkBox = jQuery('#icl_reset_pro_check');
|
||||
var button = jQuery('#icl_reset_pro_but');
|
||||
checkBox.on('change', function () {
|
||||
if (checkBox.is(":checked")) {
|
||||
button.removeClass('button-primary-disabled');
|
||||
} else {
|
||||
button.addClass('button-primary-disabled');
|
||||
}
|
||||
});
|
||||
button.on('click', function (event) {
|
||||
var spinner;
|
||||
var canReset;
|
||||
var result = false;
|
||||
var checkBoxChecked;
|
||||
var userConfirms;
|
||||
var buttonDisabled;
|
||||
|
||||
event.preventDefault();
|
||||
buttonDisabled = button.hasClass('button-primary-disabled');
|
||||
checkBoxChecked = checkBox.is(":checked");
|
||||
canReset = !buttonDisabled && checkBoxChecked;
|
||||
if (canReset) {
|
||||
userConfirms = confirm(wpml_reset_pro_trans_config_strings.confirmation);
|
||||
result = userConfirms;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
spinner = jQuery('#' + wpml_reset_pro_trans_config_strings.placeHolder).find('.spinner');
|
||||
button.prop('disabled', true);
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': wpml_reset_pro_trans_config_strings.action,
|
||||
'nonce': wpml_reset_pro_trans_config_strings.nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success : function (response) {
|
||||
if (response.success) {
|
||||
alert(response.data);
|
||||
document.location.reload(true);
|
||||
} else {
|
||||
alert(response.data);
|
||||
}
|
||||
},
|
||||
error : function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
},
|
||||
complete: function () {
|
||||
button.prop('disabled', false);
|
||||
button.next().fadeOut();
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
resetProTransConfig.init();
|
||||
});
|
||||
};
|
||||
|
||||
var resetProTransConfig = new ResetProTransConfig();
|
||||
346
wp-content/plugins/wpml-translation-management/res/js/scripts.js
Normal file
346
wp-content/plugins/wpml-translation-management/res/js/scripts.js
Normal file
@@ -0,0 +1,346 @@
|
||||
/*global jQuery*/
|
||||
/*localization global: wpml_tm_strings*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
jQuery(function () {
|
||||
|
||||
|
||||
jQuery(document).on('change', '.icl_tj_select_translator select', icl_tm_assign_translator);
|
||||
|
||||
|
||||
jQuery('#icl_side_by_site').find('a[href="#cancel"]').click(function () {
|
||||
var anchor = jQuery(this);
|
||||
jQuery.ajax({
|
||||
type : "POST", url: ajaxurl, data: 'action=dismiss_icl_side_by_site',
|
||||
success: function () {
|
||||
anchor.parent().parent().fadeOut();
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// Translator notes - translation dashboard - start
|
||||
jQuery('.icl_tn_link').click(function () {
|
||||
jQuery('.icl_post_note:visible').slideUp();
|
||||
var anchor = jQuery(this);
|
||||
var spl = anchor.attr('id').split('_');
|
||||
var doc_id = spl[3];
|
||||
var icl_post_note_doc_id = jQuery('#icl_post_note_' + doc_id);
|
||||
if (icl_post_note_doc_id.css('display') !== 'none') {
|
||||
icl_post_note_doc_id.slideUp();
|
||||
} else {
|
||||
icl_post_note_doc_id.slideDown();
|
||||
var text_area = icl_post_note_doc_id.find('textarea');
|
||||
text_area.focus();
|
||||
text_area.data('original_value', text_area.val());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.icl_tn_cancel').click(function () {
|
||||
var note_div = jQuery(this).closest('.icl_post_note'),
|
||||
text_area = note_div.find('textarea');
|
||||
|
||||
text_area.val( text_area.data('original_value' ) );
|
||||
note_div.slideUp();
|
||||
});
|
||||
|
||||
jQuery('.icl_tn_save').click(function () {
|
||||
var anchor = jQuery(this);
|
||||
anchor.closest('table').find('input').prop('disabled', true);
|
||||
var tn_post_id = anchor.closest('table').find('.icl_tn_post_id').val();
|
||||
var note = jQuery('#post_note_' + tn_post_id).val();
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
data: "icl_ajx_action=save_translator_note¬e=" + note + '&post_id=' + tn_post_id + '&_icl_nonce=' + jQuery('#_icl_nonce_stn_').val(),
|
||||
success: function () {
|
||||
anchor.closest('table').find('input').prop('disabled', false);
|
||||
anchor.closest('table').parent().slideUp();
|
||||
var note_icon = jQuery('#icl_tn_link_' + tn_post_id).find('i');
|
||||
if (anchor.closest('table').prev().val()) {
|
||||
note_icon.removeClass('otgs-ico-note-add-o').addClass('otgs-ico-note-edit-o');
|
||||
} else {
|
||||
note_icon.removeClass('otgs-ico-note-edit-o').addClass('otgs-ico-note-add-o');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
// Translator notes - translation dashboard - end
|
||||
|
||||
// MC Setup
|
||||
jQuery('#icl_doc_translation_method').submit(iclSaveForm);
|
||||
jQuery('#icl_page_sync_options').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_custom_tax_sync_options"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_custom_posts_sync_options"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_cf_translation"]').submit(iclSaveForm);
|
||||
jQuery('form[name="icl_tcf_translation"]').submit(iclSaveForm);
|
||||
jQuery('form[name="wpml-old-jobs-editor"]').submit(iclSaveForm);
|
||||
|
||||
var icl_translation_jobs_basket = jQuery('#icl-translation-jobs-basket');
|
||||
icl_translation_jobs_basket.find('th :checkbox').change(iclTmSelectAllJobsBasket);
|
||||
icl_translation_jobs_basket.find('td :checkbox').change(iclTmUpdateJobsSelectionBasket);
|
||||
var icl_translation_jobs = jQuery('#icl-translation-jobs');
|
||||
icl_translation_jobs.find('td.js-check-all :checkbox').change(iclTmSelectAllJobsSelection);
|
||||
icl_translation_jobs.find('td :checkbox').change(update_translation_job_checkboxes);
|
||||
|
||||
jQuery('#icl_tm_jobs_dup_submit').click(function () {
|
||||
return confirm(jQuery(this).next().html());
|
||||
});
|
||||
|
||||
jQuery('#icl_hide_promo').click(function () {
|
||||
jQuery.ajax({type: "POST", url: ajaxurl, data: 'action=icl_tm_toggle_promo&value=1', success: function () {
|
||||
jQuery('.icl-translation-services').slideUp(function () {
|
||||
jQuery('#icl_show_promo').fadeIn();
|
||||
});
|
||||
}});
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('#icl_show_promo').click(function () {
|
||||
jQuery.ajax({type: "POST", url: ajaxurl, data: 'action=icl_tm_toggle_promo&value=0', success: function () {
|
||||
jQuery('#icl_show_promo').hide();
|
||||
jQuery('.icl-translation-services').slideDown();
|
||||
}});
|
||||
return false;
|
||||
});
|
||||
|
||||
// --- Start: XLIFF form handler ---
|
||||
var icl_xliff_options_form = jQuery('#icl_xliff_options_form');
|
||||
if (icl_xliff_options_form !== undefined) {
|
||||
jQuery("#icl_xliff_options_form").off();
|
||||
jQuery(document).on('submit', '#icl_xliff_options_form', icl_xliff_set_newlines);
|
||||
}
|
||||
|
||||
// --- End: XLIFF form handler ---
|
||||
|
||||
// Make the number in the translation basket tab flash.
|
||||
var translation_basket_flash = function (count) {
|
||||
|
||||
var basket_count = jQuery('#wpml-basket-items');
|
||||
var basket_tab = basket_count.parent();
|
||||
|
||||
if (basket_count.length && count) {
|
||||
count--;
|
||||
|
||||
var originalBackgroundColor = basket_tab.css('background-color');
|
||||
var originalColor = basket_tab.css('color');
|
||||
|
||||
flash_animate_element(basket_tab, '#0085ba', '#ffffff');
|
||||
if (count) {
|
||||
flash_animate_element(basket_tab, originalBackgroundColor, originalColor);
|
||||
}
|
||||
|
||||
translation_basket_flash(count);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
var flash_animate_element = function (element, backgroundColor, color) {
|
||||
element.animate({opacity: 1}, 500, function () {
|
||||
element.css({backgroundColor: backgroundColor, color: color});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (location.href.indexOf("main.php&sm=basket") == -1 ) {
|
||||
translation_basket_flash (3);
|
||||
}
|
||||
});
|
||||
|
||||
function icl_xliff_set_newlines(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var form = jQuery(this);
|
||||
var submitButton = form.find(':submit');
|
||||
|
||||
submitButton.prop('disabled', true);
|
||||
var ajaxLoader = jQuery(icl_ajxloaderimg).insertBefore(submitButton);
|
||||
var icl_xliff_newlines = jQuery("input[name=icl_xliff_newlines]:checked").val();
|
||||
var icl_xliff_version = jQuery("select[name=icl_xliff_version]").val();
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'set_xliff_options',
|
||||
security: wpml_xliff_ajax_nonce,
|
||||
icl_xliff_newlines: icl_xliff_newlines,
|
||||
icl_xliff_version: icl_xliff_version
|
||||
},
|
||||
success: function (msg) {
|
||||
if (!msg.error) {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_saved);
|
||||
}
|
||||
else {
|
||||
alert(msg.error);
|
||||
}
|
||||
},
|
||||
error: function (msg) {
|
||||
fadeInAjxResp('#icl_ajx_response', icl_ajx_error);
|
||||
},
|
||||
complete: function () {
|
||||
ajaxLoader.remove();
|
||||
submitButton.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_tm_assign_translator() {
|
||||
var this_translator = jQuery(this);
|
||||
var translator_id = this_translator.val();
|
||||
var icl_tj_select_translator = this_translator.closest('.icl_tj_select_translator');
|
||||
var translation_controls = icl_tj_select_translator.find('.icl_tj_select_translator_controls');
|
||||
var job_id = translation_controls.attr('id').replace(/^icl_tj_tc_/, '');
|
||||
translation_controls.show();
|
||||
translation_controls.find('.icl_tj_cancel').click(function () {
|
||||
this_translator.val(jQuery('#icl_tj_ov_' + job_id).val());
|
||||
translation_controls.hide();
|
||||
});
|
||||
var jobType = jQuery('#icl_tj_ty_' + job_id).val();
|
||||
translation_controls.find('.icl_tj_ok').off().click(function () {
|
||||
icl_tm_assign_translator_request(job_id, translator_id, this_translator, jobType);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function icl_tm_assign_translator_request(job_id, translator_id, select, jobType) {
|
||||
var translation_controls = select.closest('.icl_tj_select_translator').find('.icl_tj_select_translator_controls');
|
||||
select.prop('disabled', true);
|
||||
translation_controls.find('.icl_tj_cancel, .icl_tj_ok').prop('disabled', true);
|
||||
var td_wrapper = select.parent().parent();
|
||||
|
||||
var ajaxLoader = jQuery( icl_ajxloaderimg ).insertBefore( translation_controls.find( '.icl_tj_ok' ) );
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: 'icl_ajx_action=assign_translator&job_id=' + job_id + '&translator_id=' + translator_id + '&job_type=' + jobType + '&_icl_nonce=' + jQuery('#_icl_nonce_at').val(),
|
||||
success: function (msg) {
|
||||
if (!msg.error) {
|
||||
translation_controls.hide();
|
||||
/** @namespace msg.service */
|
||||
if (msg.service !== 'local') {
|
||||
td_wrapper.html(msg.message);
|
||||
}
|
||||
}
|
||||
select.prop('disabled', false);
|
||||
translation_controls.find('.icl_tj_cancel, .icl_tj_ok').prop('disabled', false);
|
||||
ajaxLoader.remove();
|
||||
translation_controls.hide();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function icl_tm_set_pickup_method(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var form = jQuery(this);
|
||||
var submitButton = form.find(':submit');
|
||||
|
||||
submitButton.prop('disabled', true);
|
||||
var ajaxLoader = jQuery(icl_ajxloaderimg).insertBefore(submitButton);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: icl_ajx_url,
|
||||
dataType: 'json',
|
||||
data: 'icl_ajx_action=set_pickup_mode&' + form.serialize(),
|
||||
success: function (msg) {
|
||||
if ( msg.success ) {
|
||||
icl_translations_pickup_box_populate();
|
||||
} else {
|
||||
fadeInAjxResp( '#icl_ajx_response_tpm', msg.data.message, true );
|
||||
}
|
||||
},
|
||||
complete: function () {
|
||||
ajaxLoader.remove();
|
||||
submitButton.prop('disabled', false);
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function iclTmSelectAllJobsBasket(caller) {
|
||||
jQuery('#icl-translation-jobs-basket').find(':checkbox').prop('checked', jQuery(caller).prop('checked'));
|
||||
jQuery('#icl-tm-jobs-cancel-but').prop('disabled', !jQuery(caller).prop('checked'));
|
||||
}
|
||||
|
||||
function updateTMSelectAllCheckbox(tableSelector) {
|
||||
jQuery(tableSelector).find('td.js-check-all :checkbox').prop(
|
||||
'checked',
|
||||
!jQuery(tableSelector).find('.js-wpml-job-row :checkbox:not(:checked)').length
|
||||
);
|
||||
}
|
||||
|
||||
function update_translation_job_checkboxes() {
|
||||
updateJobCheckboxes('#icl-translation-jobs');
|
||||
updateTMSelectAllCheckbox('#icl-translation-jobs');
|
||||
}
|
||||
function updateJobCheckboxes(table_selector) {
|
||||
var job_parent = jQuery(table_selector);
|
||||
|
||||
jQuery('#icl-tm-jobs-cancel-but').prop('disabled', job_parent.find(':checkbox:checked').length === 0);
|
||||
if (job_parent.find(':checkbox:checked').length > 0) {
|
||||
var checked_items = job_parent.find('th :checkbox');
|
||||
if (job_parent.find('td :checkbox:checked').length === job_parent.find('td :checkbox').length) {
|
||||
checked_items.prop('checked', true);
|
||||
} else {
|
||||
checked_items.prop('checked', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function iclTmUpdateJobsSelectionBasket() {
|
||||
iclTmSelectAllJobsBasket(this);
|
||||
updateJobCheckboxes('#icl-translation-jobs-basket');
|
||||
}
|
||||
|
||||
function iclTmSelectAllJobsSelection() {
|
||||
jQuery('#icl-translation-jobs').find(':checkbox').prop(
|
||||
'checked',
|
||||
jQuery('#icl-translation-jobs td.js-check-all :checkbox').prop('checked')
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof String.prototype.startsWith !== 'function') {
|
||||
// see below for better implementation!
|
||||
String.prototype.startsWith = function (str){
|
||||
return this.slice(0, str.length) === str;
|
||||
};
|
||||
}
|
||||
if (typeof String.prototype.endsWith !== 'function') {
|
||||
String.prototype.endsWith = function (str){
|
||||
return this.slice(-str.length) === str;
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
(function($) {
|
||||
$(function () {
|
||||
$('#translation-notifications').on('change', 'input', function (e) {
|
||||
var input = $(e.target);
|
||||
var child = $('[name="' + input.data('child') + '"]');
|
||||
|
||||
if (child.length) {
|
||||
child.prop('disabled', !input.is(":checked"));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,214 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, wpml_tm_service_activation_strings */
|
||||
|
||||
/** @namespace wpml_tm_service_activation_strings.alertTitle */
|
||||
/** @namespace wpml_tm_service_activation_strings.cancelledJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.openJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.keepLocalJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.errorCancellingJobs */
|
||||
/** @namespace wpml_tm_service_activation_strings.errorGeneric */
|
||||
/** @namespace wpml_tm_service_activation_strings.confirm */
|
||||
/** @namespace wpml_tm_service_activation_strings.yes */
|
||||
/** @namespace wpml_tm_service_activation_strings.no */
|
||||
/** @namespace data.opens */
|
||||
/** @namespace data.cancelled */
|
||||
|
||||
var ServiceActivation = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.initClickAction = function (item, ajaxAction) {
|
||||
var elementName;
|
||||
elementName = item.attr('name');
|
||||
jQuery.ajax(
|
||||
{
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': ajaxAction,
|
||||
'nonce': elementName + '_nonce'
|
||||
},
|
||||
success: function (response) {
|
||||
var callback = ajaxAction + '_success';
|
||||
self[callback](response);
|
||||
},
|
||||
error: function (xhr, ajaxOptions, thrownError) {
|
||||
var callback = ajaxAction + '_error';
|
||||
self[callback](xhr, ajaxOptions, thrownError);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
self.displayResponseDialog = function (message) {
|
||||
self.responseDialog.find('p').empty();
|
||||
self.responseDialog.find('p').append(message);
|
||||
|
||||
self.responseDialog.dialog('open');
|
||||
};
|
||||
|
||||
self.displayConfirmationDialog = function (callback) {
|
||||
var message = wpml_tm_service_activation_strings.confirm;
|
||||
self.confirmationDialog.find('p').empty();
|
||||
self.confirmationDialog.find('p').append(message);
|
||||
|
||||
self.confirmationDialog.dialog(
|
||||
'option', 'buttons', [
|
||||
{
|
||||
text: wpml_tm_service_activation_strings.yes,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
callback(true);
|
||||
}
|
||||
}, {
|
||||
text: wpml_tm_service_activation_strings.no,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
self.confirmationDialog.dialog('open');
|
||||
};
|
||||
|
||||
self.wpml_cancel_open_local_translators_jobs_error = function (xhr, ajaxOptions, thrownError) {
|
||||
var message = wpml_tm_service_activation_strings.errorCancellingJobs;
|
||||
alert(message);
|
||||
console.log(xhr);
|
||||
console.log(ajaxOptions);
|
||||
console.log(thrownError);
|
||||
};
|
||||
|
||||
self.wpml_keep_open_local_translators_jobs_error = function (xhr, ajaxOptions, thrownError) {
|
||||
var message = wpml_tm_service_activation_strings.errorGeneric;
|
||||
alert(message);
|
||||
console.log(xhr);
|
||||
console.log(ajaxOptions);
|
||||
console.log(thrownError);
|
||||
};
|
||||
|
||||
self.wpml_keep_open_local_translators_jobs_success = function (response) {
|
||||
var message;
|
||||
var success = response.success;
|
||||
if (success) {
|
||||
message = wpml_tm_service_activation_strings.keepLocalJobs;
|
||||
} else {
|
||||
message = wpml_tm_service_activation_strings.errorGeneric;
|
||||
}
|
||||
self.displayResponseDialog(message);
|
||||
};
|
||||
|
||||
self.wpml_cancel_open_local_translators_jobs_success = function (response) {
|
||||
var data = response.data;
|
||||
var success = response.success;
|
||||
|
||||
var message;
|
||||
if (success) {
|
||||
message = wpml_tm_service_activation_strings.cancelledJobs + ' ' + data.cancelled + '<br>';
|
||||
if (data.open) {
|
||||
message += wpml_tm_service_activation_strings.errorCancellingJobs + '<br>';
|
||||
message += wpml_tm_service_activation_strings.openJobs + ' ' + data.opens;
|
||||
}
|
||||
} else {
|
||||
message = wpml_tm_service_activation_strings.errorCancellingJobs;
|
||||
}
|
||||
self.displayResponseDialog(message);
|
||||
};
|
||||
|
||||
self.init = function () {
|
||||
var dialogHtml;
|
||||
|
||||
self.notice = jQuery('.wpml-service-activation-notice').first();
|
||||
self.actions = self.notice.find('.wpml-action');
|
||||
|
||||
dialogHtml = '<div title="' + wpml_tm_service_activation_strings.alertTitle + '">';
|
||||
dialogHtml += '<p></p>';
|
||||
dialogHtml += '</div>';
|
||||
|
||||
self.confirmationDialog = jQuery(dialogHtml);
|
||||
self.responseDialog = jQuery(dialogHtml);
|
||||
|
||||
self.confirmationDialog.dialog(
|
||||
{
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
modal: true,
|
||||
width: 'auto',
|
||||
closeOnEscape: false,
|
||||
buttons: [
|
||||
{
|
||||
text: wpml_tm_service_activation_strings.yes,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
}
|
||||
}, {
|
||||
text: wpml_tm_service_activation_strings.no,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
self.responseDialog.dialog(
|
||||
{
|
||||
autoOpen: false,
|
||||
resizable: false,
|
||||
modal: true,
|
||||
width: 'auto',
|
||||
closeText: wpml_tm_service_activation_strings.closeButton,
|
||||
closeOnEscape: true,
|
||||
buttons: [
|
||||
{
|
||||
text: wpml_tm_service_activation_strings.closeButton,
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
}
|
||||
}
|
||||
],
|
||||
close: function () {
|
||||
window.location.reload(true);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
self.initElements();
|
||||
};
|
||||
self.initClick = function (item) {
|
||||
var ajaxAction = item.data('action');
|
||||
if (ajaxAction) {
|
||||
item.on(
|
||||
'click', function (event) {
|
||||
var callback;
|
||||
event.preventDefault();
|
||||
callback = function (proceed) {
|
||||
if (true === proceed) {
|
||||
self.initClickAction(item, ajaxAction);
|
||||
}
|
||||
};
|
||||
self.displayConfirmationDialog(callback);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
self.initElements = function () {
|
||||
if (self.notice) {
|
||||
_.each(
|
||||
self.actions, function (value) {
|
||||
var element = jQuery(value);
|
||||
self.initClick(element);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
jQuery(
|
||||
function () {
|
||||
serviceActivation.init();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var serviceActivation = new ServiceActivation();
|
||||
@@ -0,0 +1,90 @@
|
||||
/*jshint devel:true */
|
||||
/*global ajaxurl, _ */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.setTranslationRole = function ( $, content, nonce, role, validStateCallback ) {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function () {
|
||||
if ( content ) {
|
||||
self.newUserInputs = content.find( '.js-first-name, .js-last-name, .js-email, .js-user-name' );
|
||||
self.wpRoleSelect = content.find( '.js-role' );
|
||||
|
||||
self.newUserInputs.on( 'input', inputChange );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var setTranslationRole = function ( data, success, error ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: _.extend( data, {
|
||||
action: 'wpml_add_translation_' + role,
|
||||
nonce: nonce
|
||||
} ),
|
||||
success: function ( response ) {
|
||||
if ( response.success ) {
|
||||
success( response.data );
|
||||
} else {
|
||||
error( response.data );
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
};
|
||||
|
||||
var inputChange = function( e ) {
|
||||
validStateCallback( self.isValid() );
|
||||
};
|
||||
|
||||
self.setExisting = function ( userId, success, error, extraData ) {
|
||||
setTranslationRole(
|
||||
_.extend( extraData, { user_id : userId } ),
|
||||
success,
|
||||
error
|
||||
);
|
||||
};
|
||||
|
||||
self.addNew = function ( success, error, extraData ) {
|
||||
setTranslationRole( _.extend( extraData, {
|
||||
first: $( self.newUserInputs[ 0 ] ).val(),
|
||||
last: $( self.newUserInputs[ 1 ] ).val(),
|
||||
email: $( self.newUserInputs[ 2 ] ).val(),
|
||||
user: $( self.newUserInputs[ 3 ] ).val(),
|
||||
role: self.wpRoleSelect.val()
|
||||
} ),
|
||||
success,
|
||||
error
|
||||
);
|
||||
};
|
||||
|
||||
self.isValid = function () {
|
||||
return self.getUserName() && self.isEmailValid( self.getEmail() );
|
||||
};
|
||||
|
||||
self.isEmailValid = function ( email ) {
|
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test( email );
|
||||
};
|
||||
|
||||
self.resetInputs = function() {
|
||||
self.newUserInputs.val( '' );
|
||||
};
|
||||
|
||||
self.getUserName = function() {
|
||||
return $( self.newUserInputs[ 3 ] ).val();
|
||||
};
|
||||
|
||||
self.getEmail = function() {
|
||||
return $( self.newUserInputs[ 2 ] ).val();
|
||||
};
|
||||
|
||||
init();
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
/*global wpml_tm_strings, jQuery, Backbone, icl_ajxloaderimg, ajaxurl, ProgressBar */
|
||||
/*jslint laxbreak: true */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
WPML_TM.Dashboard = Backbone.View.extend({
|
||||
events: {
|
||||
'click td[scope="row"] :checkbox': 'update_td',
|
||||
"click td.check-column :checkbox": 'icl_tm_select_all_documents',
|
||||
"change #icl_tm_languages :radio": 'change_radio',
|
||||
"change #parent-filter-control": 'populate_parent_list',
|
||||
"change #icl_language_selector": 'populate_parent_list',
|
||||
"click #duplicate-all": 'icl_tm_bulk_batch_selection',
|
||||
"click #translate-all": 'icl_tm_bulk_batch_selection',
|
||||
"click #update-none": 'icl_tm_bulk_batch_selection',
|
||||
"submit #icl_tm_dashboard_form": 'submit',
|
||||
"change #filter_type": 'show_hide_parent_controls'
|
||||
},
|
||||
counts: {
|
||||
all: 0,
|
||||
duplicate: 0,
|
||||
translate: 0
|
||||
},
|
||||
init: function ( $ ) {
|
||||
var self = this;
|
||||
self.$ = $;
|
||||
self.counts.all = self.setElement( '.icl_tm_wrap' );
|
||||
self.change_radio();
|
||||
self.show_hide_parent_controls();
|
||||
},
|
||||
submit: function (e) {
|
||||
var self = this;
|
||||
self.recount();
|
||||
if (self.counts.duplicate > 0) {
|
||||
e.preventDefault();
|
||||
var post_ids = [];
|
||||
var langs = [];
|
||||
var radios = jQuery('#icl_tm_languages').find('tbody').find(':radio:checked').filter('[value=2]');
|
||||
radios.each(function () {
|
||||
langs.push(jQuery(this).attr('name').replace('tr_action[', '').replace(']', ''));
|
||||
});
|
||||
|
||||
var languagesCount = langs.length;
|
||||
if (0 < languagesCount) {
|
||||
var post_id_boxes = self.$el.find('#icl-tm-translation-dashboard tbody td :checkbox:checked');
|
||||
var post_ids_count = post_id_boxes.length;
|
||||
|
||||
for (var p = 0; p < post_ids_count; p++) {
|
||||
for (var l = 0; l < languagesCount; l++) {
|
||||
post_ids.push({
|
||||
postId: jQuery(post_id_boxes[p]).val(),
|
||||
languageCode: langs[l]
|
||||
});
|
||||
}
|
||||
}
|
||||
var duplication_ui = new PostDuplication(post_ids, jQuery('#icl_dup_ovr_warn'));
|
||||
duplication_ui.sendBatch();
|
||||
}
|
||||
}
|
||||
},
|
||||
iclTmUpdateDashboardSelection: function () {
|
||||
var self = this;
|
||||
if (self.$el.find(':checkbox:checked').length > 0) {
|
||||
var checked_items = self.$el.find('td.check-column :checkbox');
|
||||
if (self.$el.find('td[scope="row"] :checkbox:checked').length === self.$el.find('td[scope="row"] :checkbox').length) {
|
||||
checked_items.prop('checked', true);
|
||||
} else {
|
||||
checked_items.prop('checked', false);
|
||||
}
|
||||
}
|
||||
},
|
||||
recount: function(){
|
||||
var self = this;
|
||||
var radios = jQuery('#icl_tm_languages').find('tbody').find(':radio:checked');
|
||||
self.counts.duplicate = radios.filter('[value=2]').length;
|
||||
self.counts.translate = radios.filter('[value=1]').length;
|
||||
self.counts.all = radios.length;
|
||||
|
||||
return self;
|
||||
},
|
||||
change_radio: function () {
|
||||
var bulk_select_radio, bulk_select_val, self;
|
||||
self = this;
|
||||
self.recount();
|
||||
self.icl_tm_enable_submit();
|
||||
self.icl_tm_dup_warn();
|
||||
bulk_select_val = self.counts.duplicate === self.counts.all ? "2" : false;
|
||||
bulk_select_val = self.counts.translate === self.counts.all ? "1" : bulk_select_val;
|
||||
bulk_select_val = self.counts.translate === 0 && self.counts.duplicate === 0 ? "0" : bulk_select_val;
|
||||
bulk_select_radio = bulk_select_val !== false
|
||||
? self.$el.find('[name="radio-action-all"]').filter('[value=' + bulk_select_val + ']')
|
||||
: self.$el.find('[name="radio-action-all"]');
|
||||
bulk_select_radio.prop('checked', !!bulk_select_val);
|
||||
},
|
||||
update_td: function () {
|
||||
var self = this;
|
||||
self.icl_tm_update_word_count_estimate();
|
||||
self.iclTmUpdateDashboardSelection();
|
||||
},
|
||||
icl_tm_select_all_documents: function (e) {
|
||||
var self = this;
|
||||
self.$el.find('#icl-tm-translation-dashboard').find(':checkbox').prop('checked', !!jQuery(e.target).prop('checked'));
|
||||
self.icl_tm_update_word_count_estimate();
|
||||
self.icl_tm_update_doc_count();
|
||||
self.icl_tm_enable_submit();
|
||||
},
|
||||
icl_tm_update_word_count_estimate: function () {
|
||||
var self = this;
|
||||
self.icl_tm_enable_submit();
|
||||
var element_rows = self.$el.find('tbody').find('tr');
|
||||
var current_overall_word_count = 0;
|
||||
var icl_tm_estimated_words_count = jQuery('#icl-tm-estimated-words-count');
|
||||
jQuery.each(element_rows, function () {
|
||||
var row = jQuery(this);
|
||||
if (row.find(':checkbox').prop('checked')) {
|
||||
var item_word_count = row.data('word_count');
|
||||
var val = parseInt(item_word_count);
|
||||
val = isNaN(val) ? 0 : val;
|
||||
current_overall_word_count += val;
|
||||
}
|
||||
});
|
||||
icl_tm_estimated_words_count.html(current_overall_word_count);
|
||||
self.icl_tm_update_doc_count();
|
||||
},
|
||||
|
||||
populate_parent_list: function () {
|
||||
var self = this,
|
||||
parent_select = self.$( '#parent-filter-control' ),
|
||||
parent_taxonomy_item_container = self.$( '[name="parent-taxonomy-item-container"]' ),
|
||||
val = parent_select.val();
|
||||
|
||||
if ( val ) {
|
||||
parent_taxonomy_item_container.hide();
|
||||
if ( val != 'any' ) {
|
||||
var ajax_loader = self.$( '<span class="spinner"></span>' );
|
||||
ajax_loader.insertBefore( parent_taxonomy_item_container ).css( {
|
||||
visibility: "visible",
|
||||
float: "none"
|
||||
} );
|
||||
self.$.ajax( {
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_tm_parent_filter',
|
||||
type: val,
|
||||
from_lang: self.$( 'select[name="filter[from_lang]"]' ).val(),
|
||||
parent_id: self.$( '[name="filter[parent_id]"]' ).val()
|
||||
},
|
||||
success: function ( response ) {
|
||||
parent_taxonomy_item_container.html( response.data.html );
|
||||
parent_taxonomy_item_container.show();
|
||||
ajax_loader.remove();
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
show_hide_parent_controls: function (e) {
|
||||
var self = this,
|
||||
selected_option = self.$( '#filter_type option:selected' ),
|
||||
parent_data = selected_option.data( 'parent' ),
|
||||
taxonomy_data = selected_option.data( 'taxonomy' );
|
||||
|
||||
if ( parent_data || taxonomy_data ) {
|
||||
self.$( '#parent-taxonomy-container' ).show();
|
||||
self.fill_parent_type_select( parent_data, taxonomy_data );
|
||||
self.populate_parent_list();
|
||||
} else {
|
||||
self.$( '#parent-taxonomy-container' ).hide();
|
||||
}
|
||||
},
|
||||
|
||||
fill_parent_type_select: function ( parent_data, taxonomy_data ) {
|
||||
var self = this,
|
||||
parent_select = self.$( '#parent-filter-control' );
|
||||
|
||||
parent_select.find( 'option' ).remove();
|
||||
|
||||
parent_select.append( '<option value="any">' + wpml_tm_strings.any + '</option>' );
|
||||
|
||||
if ( parent_data ) {
|
||||
parent_select.append( '<option value="page">' + wpml_tm_strings.post_parent + '</option>' );
|
||||
}
|
||||
if ( taxonomy_data ) {
|
||||
taxonomy_data = taxonomy_data.split( ',' );
|
||||
for ( var i = 0; i < taxonomy_data.length; i++ ) {
|
||||
var parts = taxonomy_data[i].split( '=' );
|
||||
parent_select.append( '<option value="' + parts[0] + '">' + parts[1] + '</option>' );
|
||||
}
|
||||
}
|
||||
parent_select.val( parent_select.data( 'original' ) );
|
||||
parent_select.data( 'original', '' );
|
||||
if ( ! parent_select.val() ) {
|
||||
parent_select.val( 'any' );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
icl_update_button_label: function (dupl_count, trans_count) {
|
||||
var button_label;
|
||||
if (dupl_count > 0 && trans_count === 0) {
|
||||
button_label = wpml_tm_strings.BB_duplicate_all;
|
||||
} else if (dupl_count > 0 && trans_count > 0) {
|
||||
button_label = wpml_tm_strings.BB_mixed_actions;
|
||||
} else if (dupl_count === 0 && trans_count > 0) {
|
||||
button_label = wpml_tm_strings.BB_default;
|
||||
} else {
|
||||
button_label = wpml_tm_strings.BB_no_actions;
|
||||
}
|
||||
|
||||
jQuery('#icl_tm_jobs_submit').html(button_label);
|
||||
},
|
||||
icl_update_button_class: function (dupl_count, trans_count) {
|
||||
var button= jQuery('#icl_tm_jobs_submit');
|
||||
var button_class= 'wpml-tm-button-basket';
|
||||
if (dupl_count > 0 && trans_count === 0) {
|
||||
button.removeClass(button_class);
|
||||
} else {
|
||||
button.addClass(button_class);
|
||||
}
|
||||
},
|
||||
icl_tm_dup_warn: function () {
|
||||
var self = this;
|
||||
if (self.counts.duplicate > 0 !== self.$el.find('[id="icl_dup_ovr_warn"]:visible').length > 0) {
|
||||
self.$el.find('#icl_dup_ovr_warn').fadeToggle(400);
|
||||
}
|
||||
self.icl_update_button_label(self.counts.duplicate, self.counts.translate);
|
||||
self.icl_update_button_class(self.counts.duplicate, self.counts.translate);
|
||||
},
|
||||
icl_tm_bulk_batch_selection: function (e) {
|
||||
var self = this;
|
||||
var element = jQuery(e.target);
|
||||
var value = element.val();
|
||||
element.prop('checked', true);
|
||||
self.$el.find('#icl_tm_languages').find('tbody input:radio[value=' + value + ']').prop('checked', true);
|
||||
self.change_radio();
|
||||
return self;
|
||||
},
|
||||
icl_tm_enable_submit: function () {
|
||||
var self = this;
|
||||
var hasSelection = (self.counts.duplicate > 0 || self.counts.translate > 0)
|
||||
&& jQuery('#icl-tm-translation-dashboard').find('td :checkbox:checked').length > 0;
|
||||
jQuery('#icl_tm_jobs_submit').prop('disabled', !hasSelection);
|
||||
},
|
||||
icl_tm_update_doc_count: function () {
|
||||
var self = this;
|
||||
var dox = self.$el.find('tbody td :checkbox:checked').length;
|
||||
jQuery('#icl-tm-sel-doc-count').html(dox);
|
||||
if (dox) {
|
||||
jQuery('#icl-tm-doc-wrap').fadeIn();
|
||||
} else {
|
||||
jQuery('#icl-tm-doc-wrap').fadeOut();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var PostDuplication = Backbone.View.extend({
|
||||
ui: {},
|
||||
posts: [],
|
||||
duplicatedIDs: [],
|
||||
langs: '',
|
||||
initialize: function (posts, element) {
|
||||
var self = this;
|
||||
self.posts = posts;
|
||||
self.ui = new ProgressBar();
|
||||
self.ui.overall_count = posts.length;
|
||||
self.ui.actionText = wpml_tm_strings.duplicating;
|
||||
element.replaceWith(self.ui.getDomElement());
|
||||
self.ui.start();
|
||||
},
|
||||
sendBatch: function () {
|
||||
var nonce;
|
||||
var p;
|
||||
var postsToSend;
|
||||
var languages;
|
||||
var self = this;
|
||||
var postsDataToSend = self.posts.splice(0, 5);
|
||||
var postsDataToSendCount = postsDataToSend.length;
|
||||
|
||||
if(0 < postsDataToSendCount) {
|
||||
postsToSend = [];
|
||||
languages = [];
|
||||
for (p = 0; p < postsDataToSendCount; p++) {
|
||||
if (-1 === jQuery.inArray(postsDataToSend[p].postId, postsToSend)) {
|
||||
postsToSend.push(postsDataToSend[p].postId);
|
||||
}
|
||||
if (-1 === jQuery.inArray(postsDataToSend[p].languageCode, languages)) {
|
||||
languages.push(postsDataToSend[p].languageCode);
|
||||
}
|
||||
}
|
||||
|
||||
if(0 < postsToSend.length && 0 < languages.length) {
|
||||
nonce = wpml_tm_strings.wpml_duplicate_dashboard_nonce;
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'wpml_duplicate_dashboard',
|
||||
duplicate_post_ids: postsToSend,
|
||||
duplicate_target_languages: languages,
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function () {
|
||||
self.ui.change(postsToSend.length);
|
||||
self.duplicatedIDs = self.duplicatedIDs.concat(postsToSend);
|
||||
if (0 < self.posts.length) {
|
||||
self.sendBatch();
|
||||
} else {
|
||||
self.ui.complete(wpml_tm_strings.duplication_complete, false);
|
||||
jQuery('#icl_tm_languages').find('tbody').find(':radio:checked').filter('[value=2]').prop('checked', false);
|
||||
self.setHierarchyNoticeAndSubmit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
setHierarchyNoticeAndSubmit: function () {
|
||||
var self = this;
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'wpml_need_sync_message',
|
||||
duplicated_post_ids: self.duplicatedIDs.join(','),
|
||||
_icl_nonce: wpml_tm_strings.wpml_need_sync_message_nonce
|
||||
|
||||
},
|
||||
success: function () {
|
||||
jQuery('#icl_tm_dashboard_form').submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(function () {
|
||||
var tmDashboard = new WPML_TM.Dashboard();
|
||||
tmDashboard.init(jQuery);
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function WpmlTpPollingPickupPopulateAction(jQuery, TranslationProxyPolling) {
|
||||
/*
|
||||
* Before doing anything here, check whether the box, to write
|
||||
* data about translations ready for pickup , even exists.
|
||||
*/
|
||||
var tmPickupBox = jQuery('#icl_tm_pickup_wrap');
|
||||
var icl_tm_pickup_wrap_button = jQuery("#icl_tm_get_translations");
|
||||
var pickup_nof_jobs = jQuery("#icl_pickup_nof_jobs");
|
||||
var pickup_last_pickup = jQuery("#icl_pickup_last_pickup");
|
||||
var nonce = jQuery("#_icl_nonce_populate_t").val();
|
||||
|
||||
return {
|
||||
run: function () {
|
||||
if (tmPickupBox.length === 0) {
|
||||
return;
|
||||
}
|
||||
icl_tm_pickup_wrap_button.val('...Fetching translation job data ...');
|
||||
icl_tm_pickup_wrap_button.prop('disabled', true);
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_populate_translations_pickup_box',
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function (response) {
|
||||
/** @namespace response.data.wait_text */
|
||||
/** @namespace response.data.polling_data */
|
||||
/** @namespace response.data.jobs_in_progress_text */
|
||||
/** @namespace response.data.last_pickup_text */
|
||||
if (response.success) {
|
||||
if (!response.data.wait_text) {
|
||||
icl_tm_pickup_wrap_button.prop('disabled', false);
|
||||
icl_tm_pickup_wrap_button.val(response.data.button_text);
|
||||
pickup_nof_jobs.html(response.data.jobs_in_progress_text);
|
||||
pickup_last_pickup.text(response.data.last_pickup_text);
|
||||
jQuery('#tp_polling_job').text(JSON.stringify(response.data.polling_data));
|
||||
TranslationProxyPolling.init(icl_tm_pickup_wrap_button, icl_ajxloaderimg);
|
||||
} else {
|
||||
pickup_nof_jobs.html(response.data.wait_text);
|
||||
icl_tm_pickup_wrap_button.hide();
|
||||
}
|
||||
} else {
|
||||
icl_tm_pickup_wrap_button.val(response.data.button_text);
|
||||
}
|
||||
},
|
||||
error: function (response) {
|
||||
if (response.data && response.data.error) {
|
||||
jQuery("#icl_pickup_nof_jobs").text(response.data.error);
|
||||
}
|
||||
icl_tm_pickup_wrap_button.hide();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
jQuery(function () {
|
||||
var boxPopulation = new WpmlTpPollingPickupPopulateAction(jQuery, TranslationProxyPolling);
|
||||
boxPopulation.run();
|
||||
});
|
||||
@@ -0,0 +1,142 @@
|
||||
/*global jQuery, ajaxurl, JSON */
|
||||
"use strict";
|
||||
|
||||
var TranslationProxyPolling = {
|
||||
init: function (button, icl_ajxloaderimg) {
|
||||
var self = this;
|
||||
var JSONtext = jQuery('#tp_polling_job').text();
|
||||
self.jobs = JSONtext ? JSON.parse(JSONtext) : [];
|
||||
jQuery(button).click(self.handleOne);
|
||||
self.button = jQuery(button);
|
||||
self.icl_ajxloaderimg = jQuery(icl_ajxloaderimg);
|
||||
self.icl_ajxloaderimg.hide();
|
||||
self.button.after(TranslationProxyPolling.icl_ajxloaderimg);
|
||||
},
|
||||
jobs: [],
|
||||
completed_count: 0,
|
||||
cancel_count: 0,
|
||||
error_data: [],
|
||||
showSpinner: function () {
|
||||
if (!TranslationProxyPolling.spinner) {
|
||||
TranslationProxyPolling.button.prop('disabled', true);
|
||||
TranslationProxyPolling.icl_ajxloaderimg.show();
|
||||
TranslationProxyPolling.spinner = true;
|
||||
}
|
||||
},
|
||||
hideSpinner: function () {
|
||||
TranslationProxyPolling.button.prop('disabled', false);
|
||||
TranslationProxyPolling.icl_ajxloaderimg.hide();
|
||||
TranslationProxyPolling.spinner = false;
|
||||
},
|
||||
handleOne: function () {
|
||||
var nonce = jQuery("#_icl_nonce_pickup_t").val();
|
||||
var currentJob = TranslationProxyPolling.jobs.length > 0 ? TranslationProxyPolling.jobs.pop() : false;
|
||||
if (currentJob) {
|
||||
TranslationProxyPolling.showSpinner();
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_pickup_translations',
|
||||
_icl_nonce: nonce,
|
||||
job_polled: currentJob,
|
||||
completed_jobs: TranslationProxyPolling.completed_count,
|
||||
cancelled_jobs: TranslationProxyPolling.cancel_count
|
||||
},
|
||||
success: function (response) {
|
||||
if (currentJob && !response.data.job_error) {
|
||||
TranslationProxyPolling.updateCounts(currentJob, response);
|
||||
}
|
||||
var icl_message_div;
|
||||
/** @namespace response.data.completed */
|
||||
if (response.data.completed) {
|
||||
icl_message_div = jQuery("#icl_tm_pickup_wrap_completed");
|
||||
icl_message_div.text(response.data.completed);
|
||||
icl_message_div.show();
|
||||
}
|
||||
/** @namespace response.data.cancelled */
|
||||
if (response.data.cancelled) {
|
||||
icl_message_div = jQuery("#icl_tm_pickup_wrap_cancelled");
|
||||
icl_message_div.text(response.data.cancelled);
|
||||
icl_message_div.show();
|
||||
}
|
||||
/** @namespace response.data.submitting */
|
||||
if (response.data.submitting) {
|
||||
icl_message_div = jQuery("#icl_tm_pickup_wrap_submitting");
|
||||
icl_message_div.text(response.data.submitting);
|
||||
icl_message_div.show();
|
||||
}
|
||||
if (TranslationProxyPolling.jobs.length > 0) {
|
||||
TranslationProxyPolling.handleOne();
|
||||
} else {
|
||||
TranslationProxyPolling.hideSpinner();
|
||||
TranslationProxyPolling.button.attr('disabled', 'disabled');
|
||||
TranslationProxyPolling.startReloading(10);
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'icl_pickup_translations_complete'
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
TranslationProxyPolling.hideSpinner();
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
TranslationProxyPolling.hideSpinner();
|
||||
}
|
||||
},
|
||||
updateCounts: function (currentJob, response) {
|
||||
if (currentJob.job_state === 'translation_ready' && response.data.completed) {
|
||||
TranslationProxyPolling.completed_count += 1;
|
||||
}
|
||||
if (currentJob.job_state === 'cancelled' && response.data.cancelled) {
|
||||
TranslationProxyPolling.completed_count += 1;
|
||||
}
|
||||
},
|
||||
startReloading: function (remaining) {
|
||||
if (0 >= remaining) {
|
||||
location.reload(true);
|
||||
} else {
|
||||
TranslationProxyPolling.updatePickupButtonTo('reloading', remaining);
|
||||
setTimeout(function () {
|
||||
TranslationProxyPolling.startReloading(remaining - 1);
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
updatePickupButtonTo: function (state, value) {
|
||||
var dataAttributePrefix, stateData, sanitizedValue;
|
||||
|
||||
dataAttributePrefix = state;
|
||||
if ('undefined' === typeof state) {
|
||||
dataAttributePrefix = 'default';
|
||||
}
|
||||
|
||||
sanitizedValue = value;
|
||||
if ('undefined' === typeof value) {
|
||||
sanitizedValue = '';
|
||||
}
|
||||
|
||||
stateData = TranslationProxyPolling.button.data(dataAttributePrefix + '-text');
|
||||
|
||||
if ('reloading' === dataAttributePrefix) {
|
||||
stateData = TranslationProxyPolling.button.data('reloading-text') + ' ' + sanitizedValue;
|
||||
}
|
||||
|
||||
if ('undefined' !== typeof stateData) {
|
||||
if (stateData) {
|
||||
TranslationProxyPolling.button.data('current-text', stateData);
|
||||
TranslationProxyPolling.button.val(stateData);
|
||||
} else {
|
||||
self.updatePickupButtonTo('default');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,754 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global jQuery, ajaxurl, icl_ajx_url, icl_ajxloaderimg, tm_basket_data */
|
||||
|
||||
(function ($) {
|
||||
"use strict";
|
||||
|
||||
jQuery(
|
||||
function () {
|
||||
|
||||
//Basket
|
||||
|
||||
/* enable button 'Remove from basket' in Translation management > Translate jobs */
|
||||
var translation_jobs_basket_form = jQuery('#translation-jobs-basket-form');
|
||||
var handle_basket_form_cb = function (cb_location) {
|
||||
jQuery('#icl-tm-basket-delete-but').prop('disabled', jQuery('#translation-jobs-basket-form').find(cb_location + ':checked').length);
|
||||
};
|
||||
|
||||
var cb_locations = ['td', 'tfoot th', 'thead th'];
|
||||
jQuery.each(cb_locations,function(cb_location){
|
||||
cb_location += ' :checkbox:checked';
|
||||
translation_jobs_basket_form.find(cb_location).click(
|
||||
function () {
|
||||
handle_basket_form_cb(cb_location);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
jQuery('.js-translation-jobs-basket-form').on(
|
||||
'submit', function (e) { // Display confirmation on form submit
|
||||
e.preventDefault();
|
||||
|
||||
var message = jQuery(this).data('message');
|
||||
var confirmation = confirm(message);
|
||||
|
||||
if (confirmation) {
|
||||
jQuery(this).off('submit');
|
||||
jQuery(this).trigger('submit');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
function Translation_Jobs() {
|
||||
var form = jQuery('#translation-jobs-translators-form');
|
||||
var form_send_button = form.find('.button-primary');
|
||||
var form_delete_button = jQuery('[name="clear-basket"]');
|
||||
var basket_name_element = form.find('#basket_name');
|
||||
var basket_extra_fields_list = form.find('#basket_extra_fields_list');
|
||||
var message_box;
|
||||
var message_box_content;
|
||||
var additional_data;
|
||||
var progress_bar_object = new ProgressBar();
|
||||
var progress_bar = progress_bar_object.getDomElement();
|
||||
var batch_basket_items = [];
|
||||
var batch_number = 0;
|
||||
var batch_size;
|
||||
var batch_deadline = form.find( '#basket-deadline' );
|
||||
|
||||
var init = function () {
|
||||
form.on('submit', submit_form);
|
||||
|
||||
// prevent sending basket by pressing Enter
|
||||
form.on("keypress", function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
basket_name_element.on('blur', basket_name_blur);
|
||||
|
||||
message_box = jQuery('<div class="message_box"><div class="wpml-tm-basket-message-icon"></div></div>');
|
||||
message_box_content = jQuery('<div class="wpml-tm-basket-message-content"></div>');
|
||||
message_box_content.appendTo(message_box);
|
||||
message_box.insertBefore(form_send_button).hide();
|
||||
|
||||
additional_data = jQuery('<div class="additional_data"></div>');
|
||||
|
||||
progress_bar.insertAfter(message_box_content);
|
||||
progress_bar.hide();
|
||||
|
||||
initDatePicker();
|
||||
$('#icl-translation-translators').on('change', '.js-wpml-translator-dropdown', refresh_deadline_date);
|
||||
};
|
||||
|
||||
var initDatePicker = function() {
|
||||
batch_deadline.datepicker({
|
||||
minDate: new Date( Date.now() ),
|
||||
dateFormat: "yy-mm-dd",
|
||||
dayNames: wpml_tm_translation_basket_and_options.day_names,
|
||||
dayNamesMin: wpml_tm_translation_basket_and_options.day_initials,
|
||||
monthNames: wpml_tm_translation_basket_and_options.month_names
|
||||
});
|
||||
|
||||
jQuery( 'body' ).addClass( 'wpml' );
|
||||
};
|
||||
|
||||
var refresh_deadline_date = function(e) {
|
||||
var translatorsTable = $(e.delegateTarget);
|
||||
var selectors = translatorsTable.find('.js-wpml-translator-dropdown');
|
||||
var spinner = batch_deadline.siblings('.spinner');
|
||||
var translators = {};
|
||||
|
||||
$.each(selectors, function(i, selector) {
|
||||
selector = $(selector);
|
||||
var lang_to = selector.data('lang-to');
|
||||
translators[ lang_to ] = selector.find(':selected').val();
|
||||
});
|
||||
|
||||
spinner.addClass('is-active');
|
||||
|
||||
$.post({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'wpml-tm-jobs-deadline-estimate-ajax-action',
|
||||
nonce: form.find('#_icl_nonce_refresh_deadline').val(),
|
||||
translators: translators
|
||||
},
|
||||
success: function(response) {
|
||||
form.find('#basket-deadline').val(response.data.deadline);
|
||||
spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var basket_name_blur = function (e) {
|
||||
if (e !== null && typeof e.preventDefault !== 'undefined') {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var spinner = jQuery('<span class="spinner" style="display: inline-block;"></span>');
|
||||
spinner.hide();
|
||||
|
||||
spinner.insertAfter(jQuery(this));
|
||||
spinner.css('float', 'none');
|
||||
spinner.show();
|
||||
|
||||
check_basket_name();
|
||||
|
||||
spinner.hide();
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var get_nonce = function (action) {
|
||||
var nonceField = jQuery('[id="_icl_nonce_' + action + '"]');
|
||||
|
||||
return nonceField ? nonceField.val() : '';
|
||||
};
|
||||
|
||||
var check_basket_name = function () {
|
||||
|
||||
var action = 'check_basket_name';
|
||||
var nonce = get_nonce(action);
|
||||
var check_result = false;
|
||||
var basket_name = get_basket_name();
|
||||
form_send_button.attr('disabled', 'disabled');
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
async: false,
|
||||
data: {
|
||||
action: 'check_basket_name',
|
||||
basket_name: basket_name,
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function (result) {
|
||||
result = result.data;
|
||||
/** @namespace result.new_value */
|
||||
form_send_button.prop('disabled', !result.valid)
|
||||
if (result.valid) {
|
||||
if (result.modified) {
|
||||
set_basket_name(result.new_value);
|
||||
}
|
||||
form_send_button.show();
|
||||
} else {
|
||||
alert(result.message);
|
||||
set_basket_name(result.new_value);
|
||||
check_basket_name();
|
||||
}
|
||||
|
||||
check_result = result.valid;
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
show_errors(jqXHR, textStatus);
|
||||
form_send_button.prop('disabled', true);
|
||||
check_result = false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return check_result;
|
||||
};
|
||||
|
||||
var get_basket_name = function () {
|
||||
if (typeof basket_name_element !== 'undefined' && basket_name_element.val().length === 0) {
|
||||
basket_name_element.val(basket_name_element.attr('placeholder'));
|
||||
}
|
||||
|
||||
return basket_name_element.val();
|
||||
};
|
||||
|
||||
var set_basket_name = function (value) {
|
||||
if (typeof basket_name_element !== 'undefined') {
|
||||
basket_name_element.val(value);
|
||||
}
|
||||
|
||||
return basket_name_element.val();
|
||||
};
|
||||
|
||||
// translator[it]
|
||||
// translator[en-US]
|
||||
var get_translators = function () {
|
||||
var extract_translator = function (translators, key, value) {
|
||||
if (typeof key !== 'undefined' && /^translator/.test(key)) {
|
||||
key = key.replace('translator[', '').replace(']', '');
|
||||
if (translators[key] !== undefined) {
|
||||
if (!translators[key].push) {
|
||||
translators[key] = [translators[key]];
|
||||
}
|
||||
translators[key].push(value || '');
|
||||
} else {
|
||||
translators[key] = value || '';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Todo: get only translators
|
||||
var translators = {};
|
||||
var a = form.serializeArray();
|
||||
jQuery.each(
|
||||
a, function () {
|
||||
var key = this.name;
|
||||
var value = this.value;
|
||||
extract_translator(translators, key, value);
|
||||
}
|
||||
);
|
||||
|
||||
return translators;
|
||||
};
|
||||
|
||||
var get_extra_fields = function () {
|
||||
var items = jQuery('#basket_extra_fields_list').find(':input').get();
|
||||
var string = '';
|
||||
var items_total = jQuery(items).length;
|
||||
|
||||
if (items_total > 0) {
|
||||
jQuery(items).each(function (index, elm) {
|
||||
string += elm.name +":"+ jQuery(elm).val();
|
||||
if (index !== items_total - 1) {
|
||||
string += "|";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return encodeURIComponent(string);
|
||||
};
|
||||
|
||||
var sending_only_to_professional_translation = function (translators) {
|
||||
var isProfessionalTranslator = function (translator) {
|
||||
return translator.match(/^ts-\d+$/);
|
||||
};
|
||||
|
||||
var translatorsArray = Object.values(translators);
|
||||
return translatorsArray.length === translatorsArray.filter(isProfessionalTranslator).length;
|
||||
};
|
||||
|
||||
var submit_form = function (e) {
|
||||
//Prevent submitting the form
|
||||
if (typeof e.preventDefault !== 'undefined') {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (!check_basket_name()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
additional_data.empty();
|
||||
message_box.hide();
|
||||
additional_data.appendTo(message_box_content);
|
||||
|
||||
var basket_name = get_basket_name();
|
||||
var translators = get_translators();
|
||||
translation_jobs_basket_form.find('.row-actions').hide();
|
||||
|
||||
form_send_button.attr('disabled', 'disabled').hide();
|
||||
form_delete_button.attr('disabled', 'disabled');
|
||||
|
||||
message_box.show();
|
||||
|
||||
var header = sending_only_to_professional_translation(translators) ?
|
||||
tm_basket_data.strings['sending_batch_to_ts'] :
|
||||
tm_basket_data.strings['sending_batch'];
|
||||
|
||||
update_message('<h4>' + header + '</h4>', true, 'sending', false);
|
||||
|
||||
|
||||
if (typeof translators === 'undefined' || translators.length === 0) {
|
||||
update_message(tm_basket_data.strings['error_no_translators'], true, 'error', false);
|
||||
end_process(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
progress_bar_object.start();
|
||||
var action = 'send_basket_items';
|
||||
var nonce = get_nonce(action);
|
||||
|
||||
//Retrieve basket items
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: action,
|
||||
basket_name: basket_name,
|
||||
_icl_nonce: nonce
|
||||
},
|
||||
success: function (result) {
|
||||
result = result.data;
|
||||
|
||||
update_message(result.message, false, 'sending', false);
|
||||
|
||||
batch_basket_items = [];
|
||||
var batch_basket_string_items = [];
|
||||
|
||||
//Loop through basket item group
|
||||
jQuery.each(result.basket, prepare_basket_items(result.allowed_item_types, batch_basket_string_items));
|
||||
|
||||
progress_bar_object.overall_count = batch_basket_items.length + batch_basket_string_items.length;
|
||||
batch_number = 0;
|
||||
|
||||
update_basket_badge_count(progress_bar_object.getRemainingCount());
|
||||
|
||||
if (batch_basket_string_items.length > 0) {
|
||||
batch_send_strings(basket_name, translators, batch_basket_string_items);
|
||||
} else {
|
||||
batch_send_basket_to_tp(basket_name, translators);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
show_errors(jqXHR, textStatus);
|
||||
show_rollback_message();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
//Prevent submitting the form (backward compatibility)
|
||||
return false;
|
||||
};
|
||||
|
||||
var prepare_basket_items = function (allowed_item_types, batch_basket_string_items) {
|
||||
return function (item_type, basket_group) {
|
||||
if (jQuery.inArray(item_type, allowed_item_types) >= 0) {
|
||||
jQuery.each(
|
||||
basket_group, function (post_id) {
|
||||
var batch_basket_item = {};
|
||||
batch_basket_item.type = item_type;
|
||||
batch_basket_item.post_id = post_id;
|
||||
|
||||
if (item_type === 'string') {
|
||||
batch_basket_string_items.push(batch_basket_item);
|
||||
} else {
|
||||
batch_basket_items.push(batch_basket_item);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var progressbar_finish_text = '100%';
|
||||
var progressbar_callback = function (progress_bar) {
|
||||
progress_bar.dom.remove();
|
||||
};
|
||||
|
||||
var update_basket_badge_count = function (count) {
|
||||
var badge = jQuery('#wpml-basket-items');
|
||||
count = parseInt(count, 10);
|
||||
|
||||
if (count > 0) {
|
||||
badge.find('#basket-item-count').text(count);
|
||||
} else {
|
||||
badge.hide();
|
||||
}
|
||||
};
|
||||
|
||||
var batch_send_strings = function (basket_name, translators, strings) {
|
||||
if (strings.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
batch_number++;
|
||||
var batch_number_label = jQuery('<p><strong>' + tm_basket_data.strings['batch'] + ' #' + batch_number + '</strong></p>');
|
||||
update_message(batch_number_label, true, 'sending', true);
|
||||
|
||||
batch_size = strings.length;
|
||||
|
||||
var success_callback = build_success_callback(function() {
|
||||
batch_send_basket_to_tp(basket_name, translators);
|
||||
});
|
||||
|
||||
send_basket_item_request(basket_name, translators, strings, success_callback);
|
||||
};
|
||||
|
||||
var batch_send_basket_to_tp = function (basket_name, translators, skip_items) {
|
||||
|
||||
if (typeof skip_items === 'undefined') {
|
||||
skip_items = 0;
|
||||
// We consider 2s per doc and per lang, and we don't want to exceed 20s per request
|
||||
var langs = Object.keys(translators);
|
||||
batch_size = Math.ceil(20 / langs.length); // 1 to 20
|
||||
batch_size = Math.min(5, batch_size); // 1 to 5
|
||||
}
|
||||
|
||||
batch_number++;
|
||||
|
||||
var batch_length = batch_basket_items.length;
|
||||
if ((batch_length - skip_items) <= 0) {
|
||||
end_process(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (batch_length > 1) {
|
||||
|
||||
var batch_number_label = jQuery('<p><strong>' + tm_basket_data.strings['batch'] + ' #' + batch_number + '</strong></p>');
|
||||
|
||||
update_message(batch_number_label, true, 'sending', true);
|
||||
}
|
||||
|
||||
var batch_data = batch_basket_items.slice(skip_items, skip_items + batch_size);
|
||||
|
||||
var success_callback = build_success_callback(function () {
|
||||
setTimeout(
|
||||
function () {
|
||||
batch_send_basket_to_tp(basket_name, translators, (skip_items + batch_size));
|
||||
}, 1000
|
||||
)
|
||||
});
|
||||
|
||||
send_basket_item_request(basket_name, translators, batch_data, success_callback);
|
||||
};
|
||||
|
||||
var build_success_callback = function(nextStepCallback) {
|
||||
return function (result) {
|
||||
var success = result.success;
|
||||
var data = result.data;
|
||||
|
||||
if (success) {
|
||||
progress_bar_object.change(batch_size);
|
||||
//Let's give some rest to the server
|
||||
nextStepCallback();
|
||||
} else {
|
||||
handle_ajax_error(data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var handle_ajax_error = function (data) {
|
||||
update_message(data.message, true, 'error', true);
|
||||
show_additional_messages(data);
|
||||
progress_bar_object.stop();
|
||||
end_process(false);
|
||||
};
|
||||
|
||||
var send_basket_item_request = function(basket_name, translators, batch_data, success_callback) {
|
||||
var action = 'send_basket_item';
|
||||
|
||||
var data = {
|
||||
action: action,
|
||||
_icl_nonce: get_nonce(action),
|
||||
basket_name: basket_name,
|
||||
batch: batch_data,
|
||||
translators: translators,
|
||||
extra_fields: get_extra_fields(),
|
||||
deadline_date: batch_deadline.val()
|
||||
};
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: success_callback,
|
||||
error: function (jqXHR, textStatus) {
|
||||
if (jqXHR.status >= 500) {
|
||||
request_rollback_for_batch(basket_name);
|
||||
}
|
||||
|
||||
show_errors(jqXHR, textStatus);
|
||||
show_rollback_message();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var show_additional_messages = function (result) {
|
||||
/** @namespace result.additional_messages */
|
||||
if (typeof result.additional_messages !== 'undefined' && result.additional_messages !== null && result.additional_messages.length > 0) {
|
||||
jQuery.each(
|
||||
result.additional_messages, function (i, additional_message) {
|
||||
update_message(additional_message.text, true, additional_message.type, true);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var show_errors = function (jqXHR, textStatus) {
|
||||
if (jqXHR.responseText === 'undefined') {
|
||||
update_message('<strong>'+tm_basket_data.strings['error_occurred']+'</strong><div>' + textStatus + '</div>', false, 'error', true);
|
||||
} else if (jqXHR.responseText === 'Invalid nonce') {
|
||||
update_message(tm_basket_data.strings['error_not_allowed'], false, 'error', true);
|
||||
} else {
|
||||
var error_content = jQuery(jqXHR.responseText.substring(1, jqXHR.responseText.length - 1));
|
||||
update_message(tm_basket_data.strings['error_occurred'], false, 'error', true);
|
||||
update_message(error_content, true, 'error', true);
|
||||
}
|
||||
};
|
||||
|
||||
var batch_send_basket_to_tp_commit = function () {
|
||||
update_message(tm_basket_data.strings['jobs_committing'], false, 'sending', false);
|
||||
|
||||
var action = 'send_basket_commit';
|
||||
var nonce = get_nonce(action);
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: action,
|
||||
_icl_nonce: nonce,
|
||||
translators: get_translators(),
|
||||
basket_name: get_basket_name()
|
||||
},
|
||||
success: function (result) {
|
||||
var success = result.success;
|
||||
result = result.data;
|
||||
if (success) {
|
||||
if(typeof result.result.is_local !== 'undefined' && result.result.is_local ) {
|
||||
var message = tm_basket_data.strings['jobs_sent_to_local_translator'];
|
||||
|
||||
if(typeof result.result.emails_did_not_sent !== 'undefined' && result.result.emails_did_not_sent ){
|
||||
message = message.replace(/<ul><li>[\s\S]*?<\/li>/, '<ul>' + tm_basket_data.strings['jobs_emails_local_did_not_sent'] );
|
||||
}
|
||||
}else{
|
||||
var message = tm_basket_data.strings['jobs_committed'];
|
||||
}
|
||||
if (typeof result.links !== 'undefined') {
|
||||
var links = jQuery('<ul></ul>');
|
||||
jQuery.each(
|
||||
result.links, function (i, link) {
|
||||
var link_item = jQuery('<li></li>');
|
||||
var link_anchor = jQuery('<a></a>');
|
||||
link_anchor.attr('href', link.url);
|
||||
link_anchor.text(link.text);
|
||||
|
||||
link_anchor.appendTo(link_item);
|
||||
link_item.appendTo(links);
|
||||
}
|
||||
);
|
||||
links.appendTo(message);
|
||||
}
|
||||
update_message(message, false, 'updated', false);
|
||||
var call_to_action = false;
|
||||
/** @namespace result.result.call_to_action */
|
||||
if(typeof result.result.call_to_action !== 'undefined') {
|
||||
call_to_action = jQuery('<p>' + result.result.call_to_action + '</p>');
|
||||
update_message(call_to_action, true, 'updated', true);
|
||||
}
|
||||
|
||||
batch_send_basket_to_tp_completed(result);
|
||||
|
||||
} else {
|
||||
handle_response(result);
|
||||
show_rollback_message();
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus) {
|
||||
show_errors(jqXHR, textStatus);
|
||||
show_rollback_message();
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var show_rollback_message = function () {
|
||||
update_message(tm_basket_data.strings['rollbacks'], false, 'error', false);
|
||||
update_message(tm_basket_data.strings['rolled'], false, 'error', true);
|
||||
progress_bar_object.complete(progressbar_finish_text, progressbar_callback);
|
||||
};
|
||||
|
||||
var request_rollback_for_batch = function(basket_name) {
|
||||
var action = 'rollback_basket';
|
||||
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: action,
|
||||
_icl_nonce: get_nonce(action),
|
||||
basket_name: basket_name
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var batch_send_basket_to_tp_completed = function (response) {
|
||||
progress_bar_object.complete(progressbar_finish_text, progressbar_callback);
|
||||
form_send_button.attr('disabled', 'disabled');
|
||||
form_delete_button.attr('disabled', 'disabled');
|
||||
basket_name_element.attr('disabled', 'disabled');
|
||||
basket_name_element.attr('readonly', 'readonly');
|
||||
batch_deadline.attr('disabled', 'disabled');
|
||||
batch_deadline.attr('readonly', 'readonly');
|
||||
form.attr('disabled', 'disabled');
|
||||
form.attr('readonly', 'readonly');
|
||||
form.trigger('wpml-tm-basket-submitted', response);
|
||||
|
||||
// hide the badge
|
||||
jQuery('#wpml-basket-items').hide();
|
||||
|
||||
};
|
||||
|
||||
var end_process = function (commit) {
|
||||
|
||||
if (commit) {
|
||||
batch_send_basket_to_tp_commit();
|
||||
} else {
|
||||
form_delete_button.prop('disabled', false);
|
||||
form_send_button.prop('disabled', false);
|
||||
form_send_button.show();
|
||||
show_rollback_message();
|
||||
}
|
||||
};
|
||||
|
||||
var handle_response = function (response) {
|
||||
var errors = [];
|
||||
if (typeof response.errors !== 'undefined') {
|
||||
errors = response.errors;
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
update_message(tm_basket_data.strings['errors'], false, 'error', true);
|
||||
jQuery.each(
|
||||
errors, function (i, error_message) {
|
||||
update_message(error_message, true, 'error', true);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var update_message = function (message, details, status, append) {
|
||||
var target;
|
||||
|
||||
if (typeof append !== 'undefined' && append !== false) {
|
||||
append = true;
|
||||
}
|
||||
|
||||
if (typeof status !== 'undefined') {
|
||||
message_box.removeClass();
|
||||
message_box.addClass('wpml-tm-basket-message wpml-tm-basket-message-' + status);
|
||||
}
|
||||
|
||||
if (typeof details !== 'undefined' && details !== false) {
|
||||
target = additional_data;
|
||||
if (!target.length) {
|
||||
target = message_box_content;
|
||||
}
|
||||
} else {
|
||||
target = message_box_content;
|
||||
}
|
||||
if (!append) {
|
||||
target.empty();
|
||||
if (target === message_box_content) {
|
||||
additional_data.appendTo(message_box_content);
|
||||
}
|
||||
}
|
||||
build_message(target, message);
|
||||
};
|
||||
|
||||
var build_message = function (container, message_element_or_string) {
|
||||
|
||||
if (message_element_or_string && typeof container !== 'undefined') {
|
||||
if (container.is(":hidden") || !container.is(':visible')) {
|
||||
container.show();
|
||||
}
|
||||
if (typeof message_element_or_string === 'string') {
|
||||
message_element_or_string = jQuery('<p>' + message_element_or_string + '</p>');
|
||||
}
|
||||
if (typeof message_element_or_string === 'object') {
|
||||
message_element_or_string.appendTo(container);
|
||||
}
|
||||
}
|
||||
|
||||
return message_element_or_string;
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
Translation_Jobs();
|
||||
|
||||
var basket_extra_fields_refresh = jQuery('#basket_extra_fields_refresh');
|
||||
basket_extra_fields_refresh.click(function(event) {
|
||||
event.preventDefault();
|
||||
var basket_extra_fields_list = jQuery('#basket_extra_fields_list');
|
||||
var ajax_spinner = jQuery('<span class="spinner"></span>');
|
||||
ajax_spinner.show();
|
||||
ajax_spinner.css('visibility', 'visible');
|
||||
basket_extra_fields_list.html(ajax_spinner);
|
||||
var ajax_data = {
|
||||
'action': 'basket_extra_fields_refresh'
|
||||
};
|
||||
|
||||
jQuery.post(ajaxurl, ajax_data, function(response) {
|
||||
basket_extra_fields_list.html(response);
|
||||
});
|
||||
});
|
||||
|
||||
var duplicated = document.getElementById('icl_duplicate_post_in_basket'),
|
||||
button = $('.button-primary'),
|
||||
nonce = document.getElementById('icl_disconnect_nonce');
|
||||
if (duplicated !== null) {
|
||||
$('<div />', {
|
||||
id: 'icl_disconnect_message',
|
||||
text: tm_basket_data.tmi_message,
|
||||
class: 'icl-admin-message-warning'
|
||||
}).insertBefore('.button-primary');
|
||||
button.on('click', function () {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'icl_disconnect_posts',
|
||||
nonce: nonce.value,
|
||||
posts: duplicated.value
|
||||
}
|
||||
}).success(function (resp) {
|
||||
if (resp.success !== true) {
|
||||
alert(resp.data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}(jQuery));
|
||||
@@ -0,0 +1,79 @@
|
||||
jQuery(function ($) {
|
||||
"use strict";
|
||||
|
||||
var dialog = $('.js-wpml-translation-basket-dialog');
|
||||
|
||||
var openDialog = function (result) {
|
||||
/** @namespace result.call_to_action */
|
||||
/** @namespace result.ts_batch_link */
|
||||
|
||||
var hasAdditionalContent = typeof result.call_to_action !== 'undefined' || typeof result.ts_batch_link !== 'undefined';
|
||||
|
||||
var options = {
|
||||
dialogClass: 'wpml-dialog otgs-ui-dialog',
|
||||
width: 600,
|
||||
title: dialog.data('title'),
|
||||
modal: true,
|
||||
closeOnEscape: false,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
open: function () {
|
||||
var dialogContent = dialog.find('.js-dialog-content');
|
||||
|
||||
var callToAction = dialogContent.find('.js-call-to-action');
|
||||
|
||||
var batchLink = dialogContent.find('.js-batch-link');
|
||||
var batchLinkAnchor = batchLink.find('a');
|
||||
|
||||
if (callToAction && typeof result.call_to_action !== 'undefined') {
|
||||
callToAction.text(result.call_to_action);
|
||||
hasAdditionalContent = true;
|
||||
}
|
||||
if (batchLinkAnchor && typeof result.ts_batch_link !== 'undefined') {
|
||||
batchLinkAnchor.attr('href', result.ts_batch_link.href);
|
||||
batchLinkAnchor.text(result.ts_batch_link.text);
|
||||
$(batchLinkAnchor).on('click', function () {
|
||||
dialog.dialog('close');
|
||||
});
|
||||
|
||||
batchLink.show();
|
||||
hasAdditionalContent = true;
|
||||
}
|
||||
dialog.show();
|
||||
repositionDialog();
|
||||
}
|
||||
};
|
||||
|
||||
if (hasAdditionalContent) {
|
||||
dialog.dialog(options);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var repositionDialog = function() {
|
||||
if (dialog.hasClass("ui-dialog-content") && dialog.dialog('isOpen')) {
|
||||
var winH = $(window).height() - 180;
|
||||
$(".otgs-ui-dialog .ui-dialog-content").css({
|
||||
"max-height": winH
|
||||
});
|
||||
$(".otgs-ui-dialog").css({
|
||||
"max-width": "95%"
|
||||
});
|
||||
dialog.dialog("option", "position", {
|
||||
my: "center",
|
||||
at: "center",
|
||||
of: window
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(window).resize(repositionDialog);
|
||||
|
||||
var form = $('#translation-jobs-translators-form');
|
||||
|
||||
form.on('wpml-tm-basket-submitted', function(event, response) {
|
||||
if (response.result) {
|
||||
openDialog(response.result);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
var dialog = jQuery('.wpml-tm-invalid-fields-dialog');
|
||||
|
||||
jQuery('.wpml-tm-invalid-fields-open-dialog').click(function () {
|
||||
var fields = jQuery(this).data('fields');
|
||||
dialog.dialog({
|
||||
dialogClass: 'wpml-dialog otgs-ui-dialog',
|
||||
width : 'auto',
|
||||
title : jQuery(this).data('page-title'),
|
||||
modal: true,
|
||||
open: function () {
|
||||
dialog.html('');
|
||||
dialog.append('<ul>');
|
||||
jQuery.each(fields, function(index, value){
|
||||
var field = JSON.parse(value);
|
||||
dialog.append('<li><strong>' + field.title + '</strong>: ' + field.content + '</li>');
|
||||
});
|
||||
dialog.append( '</ul>' );
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,293 @@
|
||||
this["WPML_TM"] = this["WPML_TM"] || {};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/footer.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<div class="wpml-translation-action-buttons-abort">\n\t<button class="cancel wpml-dialog-close-button js-dialog-cancel">' +
|
||||
((__t = (cancel)) == null ? '' : __t) +
|
||||
'</button>\n\t<button class="button-secondary wpml-resign-button js-resign">' +
|
||||
((__t = (resign)) == null ? '' : __t) +
|
||||
'</button>\n</div>\n<div class="wpml-translation-action-buttons-status">\n\t<div class="progress-bar js-progress-bar"><div class="progress-bar-text"></div></div>\n\t<label><input class="js-translation-complete" name="complete" type="checkbox"/>' +
|
||||
((__t = (translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n\n\n\t<div class="otgs-toggle-group">\n\t\t<input type="checkbox" class="js-toggle-translated otgs-switcher-input" id="wpml_tm_toggle_translated">\n\t\t<label for="wpml_tm_toggle_translated" class="otgs-switcher" data-on="ON" data-off="OFF">' +
|
||||
((__t = (hide_translated)) == null ? '' : __t) +
|
||||
'</label>\n\t</div>\n</div>\n<div class = "wpml-translation-action-buttons-apply">\n\t<span class = "js-saving-message" style = "display:none"><img src="' +
|
||||
((__t = (loading_url)) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = (saving)) == null ? '' : __t) +
|
||||
'" height="16" width="16"/>' +
|
||||
((__t = (saving)) == null ? '' : __t) +
|
||||
'</span>\n\t<button class = "button button-primary button-large wpml-dialog-close-button js-save-and-close">' +
|
||||
((__t = (save_and_close)) == null ? '' : __t) +
|
||||
'</button>\n\t<button class = "button button-primary button-large wpml-dialog-close-button js-save">' +
|
||||
((__t = (save)) == null ? '' : __t) +
|
||||
'</button>\n</div>\n\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/group.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
|
||||
if ( title ) { ;
|
||||
__p +=
|
||||
((__t = ( title )) == null ? '' : __t);
|
||||
} ;
|
||||
__p += '\n<div class="inside">\n</div>\n\n';
|
||||
if ( divider ) { ;
|
||||
__p += '\n<hr />\n';
|
||||
} ;
|
||||
__p += '\n<button class="button-copy button-secondary js-button-copy-group">\n\t<i class="otgs-ico-copy"></i>\n</button>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/header.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p +=
|
||||
((__t = ( title )) == null ? '' : __t) +
|
||||
'\n<a href="' +
|
||||
((__t = ( link_url )) == null ? '' : __t) +
|
||||
'" class="view" target="_blank">' +
|
||||
((__t = ( link_text )) == null ? '' : __t) +
|
||||
'</a>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/image.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '\t<div class="inside">\n\t\t<img src="' +
|
||||
((__t = ( image_src )) == null ? '' : __t) +
|
||||
'">\n\t</div>\n\n\n';
|
||||
if ( divider ) { ;
|
||||
__p += '\n<hr />\n';
|
||||
} ;
|
||||
__p += '\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/languages.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '\t<input type="hidden" name="source_lang" value="' +
|
||||
((__t = ( language.source )) == null ? '' : __t) +
|
||||
'" />\n\t<input type="hidden" name="target_lang" value="' +
|
||||
((__t = ( language.target )) == null ? '' : __t) +
|
||||
'" />\n\t<h3 class="wpml-header-original">' +
|
||||
((__t = ( labels.source_lang )) == null ? '' : __t) +
|
||||
':\n\t\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( language.img.source_url )) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = ( language.source_lang )) == null ? '' : __t) +
|
||||
'"/></span>\n\t\t<strong>' +
|
||||
((__t = ( language.source_lang )) == null ? '' : __t) +
|
||||
'</strong>\n\t</h3>\n\n\t<h3 class="wpml-header-translation">' +
|
||||
((__t = ( labels.target_lang )) == null ? '' : __t) +
|
||||
':\n\t\t<span class="wpml-title-flag"><img src="' +
|
||||
((__t = ( language.img.target_url )) == null ? '' : __t) +
|
||||
'" alt="' +
|
||||
((__t = ( language.target_lang )) == null ? '' : __t) +
|
||||
'"/></span>\n\t\t<strong>' +
|
||||
((__t = ( language.target_lang )) == null ? '' : __t) +
|
||||
'</strong>\n\t</h3>\n\n\t<div class="wpml-copy-container">\n\t\t<button class="button-secondary button-copy-all js-button-copy-all" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'">\n\t\t\t<i class="otgs-ico-copy"></i> ' +
|
||||
((__t = ( labels.copy_all )) == null ? '' : __t) +
|
||||
'\n\t\t</button>\n\t</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/note.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape;
|
||||
with (obj) {
|
||||
__p += '<p>' +
|
||||
((__t = ( note )) == null ? '' : __t) +
|
||||
'</p>\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/section.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<div class="handlediv button-link"><br></div>\n<h3 class="hndle">\n\t<span>' +
|
||||
((__t = ( section.title )) == null ? '' : __t) +
|
||||
' ';
|
||||
if ( section.empty ) { ;
|
||||
__p += ' <i>' +
|
||||
((__t = ( section.empty_message )) == null ? '' : __t);
|
||||
} ;
|
||||
__p += '</span>\n\t';
|
||||
if ( section.sub_title ) { ;
|
||||
__p += '\n\t<span class="subtitle"><i class="otgs-ico-warning"></i>' +
|
||||
((__t = ( section.sub_title )) == null ? '' : __t) +
|
||||
'</span>\n\t';
|
||||
} ;
|
||||
__p += '\n</h3>\n\n<div class="inside">\n</div>\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/single-line.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label>' +
|
||||
((__t = (field.title)) == null ? '' : __t) +
|
||||
'</label>\n<input readonly class="original_value js-original-value" value="' +
|
||||
__e( field.field_data ) +
|
||||
'" type="text" ' +
|
||||
((__t = (field.original_direction)) == null ? '' : __t) +
|
||||
'/>\n<button class="button-copy button-secondary js-button-copy icl_tm_copy_link otgs-ico-copy" id="icl_tm_copy_link_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'" ></button>\n<input class="translated_value js-translated-value" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][data]" value="' +
|
||||
__e( field.field_data_translated ) +
|
||||
'" type="text" ' +
|
||||
((__t = (field.translation_direction)) == null ? '' : __t) +
|
||||
'/>\n\n<div class="field_translation_complete">\n\t<label><input class="icl_tm_finished js-field-translation-complete" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][finished]" type="checkbox" ';
|
||||
if (field.field_finished) { ;
|
||||
__p += ' checked="checked" ';
|
||||
} ;
|
||||
__p += ' />' +
|
||||
((__t = (labels.translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n</div>\n\n';
|
||||
if (field.diff) { ;
|
||||
__p += '\n<a class="js-toggle-diff toggle-diff">' +
|
||||
((__t = (labels.show_diff)) == null ? '' : __t) +
|
||||
'</a>\n' +
|
||||
((__t = (field.diff)) == null ? '' : __t) +
|
||||
'\n';
|
||||
} ;
|
||||
__p += '\n\n\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][tid]" value="' +
|
||||
((__t = (field.tid)) == null ? '' : __t) +
|
||||
'">\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][format]" value="base64">\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/textarea.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label>' +
|
||||
((__t = (field.title)) == null ? '' : __t) +
|
||||
'</label>\n<textarea class="original_value js-original-value" readonly cols="22" rows="10" ' +
|
||||
((__t = (field.original_direction)) == null ? '' : __t) +
|
||||
'>' +
|
||||
((__t = ( field.field_data )) == null ? '' : __t) +
|
||||
'</textarea>\n<button class="button-copy button-secondary js-button-copy icl_tm_copy_link otgs-ico-copy" id="icl_tm_copy_link_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'"></button>\n<textarea class="translated_value js-translated-value cols="22" rows="10" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][data]" ' +
|
||||
((__t = (field.translation_direction)) == null ? '' : __t) +
|
||||
'>' +
|
||||
((__t = ( field.field_data_translated )) == null ? '' : __t) +
|
||||
'</textarea>\n\n<div class="field_translation_complete">\n\t<label><input class="icl_tm_finished js-field-translation-complete" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][finished]" type="checkbox" ';
|
||||
if (field.field_finished) { ;
|
||||
__p += ' checked="checked" ';
|
||||
} ;
|
||||
__p += ' />' +
|
||||
((__t = (labels.translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n</div>\n\n';
|
||||
if (field.diff) { ;
|
||||
__p += '\n<a class="js-toggle-diff toggle-diff">' +
|
||||
((__t = (labels.show_diff)) == null ? '' : __t) +
|
||||
'</a>\n' +
|
||||
((__t = (field.diff)) == null ? '' : __t) +
|
||||
'\n';
|
||||
} ;
|
||||
__p += '\n\n\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][tid]" value="' +
|
||||
((__t = (field.tid)) == null ? '' : __t) +
|
||||
'">\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][format]" value="base64">\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
|
||||
this["WPML_TM"]["templates/translation-editor/wysiwyg.html"] = function(obj) {
|
||||
obj || (obj = {});
|
||||
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
|
||||
function print() { __p += __j.call(arguments, '') }
|
||||
with (obj) {
|
||||
__p += '<label>' +
|
||||
((__t = (field.title)) == null ? '' : __t) +
|
||||
'</label>\n<div id="original_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'_placeholder"></div>\n<button class="button-copy button-secondary js-button-copy icl_tm_copy_link otgs-ico-copy" id="icl_tm_copy_link_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'" title="' +
|
||||
((__t = ( labels.copy_from_original )) == null ? '' : __t) +
|
||||
'"></button>\n<div id="translated_' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'_placeholder"></div>\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][tid]" value="' +
|
||||
((__t = (field.tid)) == null ? '' : __t) +
|
||||
'">\n<input type="hidden" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][format]" value="base64">\n\n<div class="field_translation_complete">\n <label><input class="icl_tm_finished js-field-translation-complete" name="fields[' +
|
||||
((__t = (field.field_type)) == null ? '' : __t) +
|
||||
'][finished]" type="checkbox" ';
|
||||
if (field.field_finished) { ;
|
||||
__p += ' checked="checked" ';
|
||||
} ;
|
||||
__p += ' />' +
|
||||
((__t = (labels.translation_complete)) == null ? '' : __t) +
|
||||
'</label>\n</div>\n\n';
|
||||
if (field.diff) { ;
|
||||
__p += '\n<a class="js-toggle-diff toggle-diff">' +
|
||||
((__t = (labels.show_diff)) == null ? '' : __t) +
|
||||
'</a>\n' +
|
||||
((__t = (field.diff)) == null ? '' : __t) +
|
||||
'\n';
|
||||
} ;
|
||||
__p += '\n\n\n';
|
||||
|
||||
}
|
||||
return __p
|
||||
};
|
||||
@@ -0,0 +1,211 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*global _, jQuery, ajaxurl, icl_ajx_url, icl_ajxloaderimg, wpActiveEditor, tinyMCE,
|
||||
tinymce, iclSaveForm,
|
||||
tmEditorStrings, WPML_TM.editorFooterView, WPML_TM.editorHeaderView,
|
||||
WpmlTmEditorMainView,
|
||||
WpmlTranslationEditorTemplates, WpmlTemplateCompiler */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
"use strict";
|
||||
var tmEditor = {
|
||||
dontShowAgain: false,
|
||||
copyLinks: {},
|
||||
copyLinkViews: [],
|
||||
footerView: {},
|
||||
model: {},
|
||||
view: {},
|
||||
update_copy_link_visibility: function () {
|
||||
var self = tmEditor;
|
||||
self.copyLinks.each(function () {
|
||||
var type = this.id.replace(/^icl_tm_copy_link_/, '');
|
||||
var content = self.get_content_for_copy_field(type);
|
||||
if (content && content.trim() !== "") {
|
||||
jQuery(this).closest('span').hide();
|
||||
} else {
|
||||
jQuery(this).closest('span').show();
|
||||
}
|
||||
});
|
||||
if (self.copyLinks.filter(':visible').length === 1) {
|
||||
self.copyLinks.closest('span').hide();
|
||||
} else {
|
||||
self.copyLinks.find('#icl_tm_copy_link_icl_all_fields').closest('span').show();
|
||||
}
|
||||
},
|
||||
findInputFieldForCheckBox: function (cbName) {
|
||||
var fieldName = cbName.replace(/finished/, 'data');
|
||||
var inputField = jQuery('[name="' + fieldName + '"]');
|
||||
if (inputField.length === 0) {
|
||||
inputField = false;
|
||||
}
|
||||
|
||||
return inputField;
|
||||
},
|
||||
find_custom_editor: function (field_type) {
|
||||
var custom_editor = false;
|
||||
var editors;
|
||||
if (typeof tinyMCE !== 'undefined' && (editors = tinyMCE.editors) !== undefined) {
|
||||
jQuery.each(
|
||||
editors, function () {
|
||||
var item = this;
|
||||
if (("field-wpcf-" + field_type).toLowerCase() === item.id.toLowerCase()
|
||||
|| field_type.toLowerCase() === item.id.toLowerCase()) {
|
||||
custom_editor = item;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return custom_editor;
|
||||
},
|
||||
get_content_for_copy_field: function (field_type) {
|
||||
var editor = this.find_custom_editor(field_type);
|
||||
|
||||
return editor !== false ? editor.getContent() : jQuery('#' + field_type).val();
|
||||
},
|
||||
icl_populate_field: function (field_type, content) {
|
||||
var custom_editor = tmEditor.find_custom_editor(field_type);
|
||||
|
||||
if (custom_editor !== false && !custom_editor.isHidden() && custom_editor.getContent().trim() === "") {
|
||||
custom_editor.insertContent(content);
|
||||
} else {
|
||||
custom_editor = jQuery('#' + field_type);
|
||||
if ('undefined' !== typeof custom_editor && 'undefined' !== typeof custom_editor.val()) {
|
||||
custom_editor.val(custom_editor.val().trim() !== "" ? custom_editor.val() : content);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
var wpml_diff_toggle = jQuery('.wpml_diff_toggle');
|
||||
wpml_diff_toggle.closest('.wpml_diff_wrapper').find('.wpml_diff').hide();
|
||||
wpml_diff_toggle.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
jQuery(this).closest('.wpml_diff_wrapper').find('.wpml_diff').slideToggle();
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.tm-learn-more').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var popUpHtml = '<div id="tm-editor-learn-more" title="' + tmEditorStrings.title + '">' + tmEditorStrings.learnMore + '</div>';
|
||||
jQuery(popUpHtml).dialog();
|
||||
});
|
||||
|
||||
var icl_tm_editor = jQuery('#icl_tm_editor');
|
||||
icl_tm_editor.find('.handlediv').click(function () {
|
||||
if (jQuery(this).parent().hasClass('closed')) {
|
||||
jQuery(this).parent().removeClass('closed');
|
||||
} else {
|
||||
jQuery(this).parent().addClass('closed');
|
||||
}
|
||||
});
|
||||
|
||||
jQuery('.icl_tm_finished').change(function () {
|
||||
jQuery(this).parent().parent().find('.icl_tm_error').hide();
|
||||
|
||||
var field = jQuery(this).attr('name').replace(/finished/, 'data');
|
||||
|
||||
var data;
|
||||
var datatemp = '';
|
||||
if (field === 'fields[body][data]') {
|
||||
try {
|
||||
datatemp = tinyMCE.get('body').getContent();
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
data = jQuery('*[name="' + field + '"]').val() + datatemp;
|
||||
} else if (jQuery(this).hasClass('icl_tmf_multiple')) {
|
||||
data = 1;
|
||||
jQuery('[name*="' + field + '"]').each(function () {
|
||||
data = data * jQuery(this).val().length;
|
||||
});
|
||||
} else {
|
||||
|
||||
try {
|
||||
datatemp = tinyMCE.get(field.replace('fields[', '').replace('][data]', '')).getContent();
|
||||
}
|
||||
catch (err) {
|
||||
}
|
||||
|
||||
data = jQuery('[name="' + field + '"]*').val() + datatemp;
|
||||
data = jQuery('[name="' + field.toLowerCase() + '"]*').val() + datatemp;
|
||||
}
|
||||
|
||||
if (jQuery(this).prop('checked') && !data) {
|
||||
jQuery(this).closest('.icl_tm_error').show();
|
||||
jQuery(this).prop('checked', false);
|
||||
}
|
||||
});
|
||||
|
||||
jQuery('.icl_tmf_term').on('click', function (e) {
|
||||
var box = jQuery(this);
|
||||
var inputField = tmEditor.findInputFieldForCheckBox(box.attr('name'));
|
||||
if (box.prop('checked')) {
|
||||
box.prop('checked', true);
|
||||
} else {
|
||||
if (tmEditor.dontShowAgain === true) {
|
||||
inputField.attr('disabled', false);
|
||||
} else {
|
||||
var popUpHtml = ['<div id="tm-editor-learn-more"><span>',
|
||||
tmEditorStrings.warning,
|
||||
'</span><p><input type="checkbox" class="tm-editor-not-show-again"/>',
|
||||
tmEditorStrings.dontShowAgain,
|
||||
'</p></div>'].join('');
|
||||
jQuery(popUpHtml).dialog(
|
||||
{
|
||||
width: 'auto',
|
||||
buttons: [
|
||||
{
|
||||
text: "Ok",
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
if (inputField) {
|
||||
inputField.attr('disabled', false);
|
||||
box.prop('checked', false);
|
||||
if (jQuery(this).find('.tm-editor-not-show-again').prop('checked')) {
|
||||
jQuery(this).dialog("destroy");
|
||||
tmEditor.dontShowAgain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
text: "Cancel",
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
box.prop('checked', true);
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var job_id = jQuery('[name="job_id"]').val();
|
||||
|
||||
tmEditor.model = new WPML_TM.editorJob(
|
||||
{
|
||||
job_id: job_id,
|
||||
nonce: tmEditorStrings.contentNonce,
|
||||
is_dirty: false
|
||||
}
|
||||
);
|
||||
tmEditor.copyLinks = jQuery('.icl_tm_copy_link');
|
||||
tmEditor.view = new WPML_TM.editorMainView({
|
||||
el: jQuery('.icl-translation-editor'),
|
||||
model: tmEditor.model
|
||||
});
|
||||
tmEditor.view.render();
|
||||
|
||||
|
||||
icl_tm_editor.submit(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
tmEditor.update_copy_link_visibility();
|
||||
|
||||
jQuery(window).trigger('customEvent');
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.editorCopyAll = function (mainView) {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function (mainView) {
|
||||
self.mainView = mainView;
|
||||
};
|
||||
|
||||
self.copy = function () {
|
||||
var hasTranslations = self.mainView.hasTranslations();
|
||||
if (!hasTranslations) {
|
||||
self.mainView.copyOriginalOverwrite();
|
||||
} else {
|
||||
self.copyAllDialog = new WPML_TM.editorCopyAllDialog(this);
|
||||
}
|
||||
};
|
||||
|
||||
self.copyAllNotTranslated = function () {
|
||||
self.mainView.copyOriginalDontOverwrite();
|
||||
};
|
||||
|
||||
self.copyAllOverwrite = function () {
|
||||
self.mainView.copyOriginalOverwrite();
|
||||
};
|
||||
|
||||
|
||||
init(mainView);
|
||||
|
||||
};
|
||||
|
||||
WPML_TM.editorCopyAllDialog = function (editor) {
|
||||
"use strict";
|
||||
|
||||
var dialog;
|
||||
|
||||
var init = function (editor) {
|
||||
dialog = jQuery("#wpml-translation-editor-copy-all-dialog");
|
||||
dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: 500,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog'
|
||||
});
|
||||
|
||||
jQuery(dialog).find('.js-copy-cancel').off('click');
|
||||
jQuery(dialog).find('.js-copy-cancel').on('click', dialogCancel);
|
||||
|
||||
jQuery(dialog).find('.js-copy-not-translated').off('click');
|
||||
jQuery(dialog).find('.js-copy-not-translated').on('click', function () {
|
||||
editor.copyAllNotTranslated();
|
||||
dialog.dialog('close');
|
||||
});
|
||||
jQuery(dialog).find('.js-copy-overwrite').off('click');
|
||||
jQuery(dialog).find('.js-copy-overwrite').on('click', function () {
|
||||
editor.copyAllOverwrite();
|
||||
dialog.dialog('close');
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
var dialogCancel = function () {
|
||||
dialog.dialog('close');
|
||||
};
|
||||
|
||||
init(editor);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.editorEditIndependentlyDialog = function (editor) {
|
||||
"use strict";
|
||||
|
||||
var dialog;
|
||||
var endingDuplicate;
|
||||
|
||||
var init = function (editor) {
|
||||
endingDuplicate = false;
|
||||
|
||||
dialog = jQuery("#wpml-translation-editor-edit-independently-dialog");
|
||||
dialog.dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
minWidth: 500,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
dialogClass: 'dialog-fixed otgs-ui-dialog',
|
||||
beforeClose: function (event, ui) {
|
||||
if (!endingDuplicate) {
|
||||
dialogCancel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(dialog).find('.js-edit-independently-cancel').off('click');
|
||||
jQuery(dialog).find('.js-edit-independently-cancel').on('click', dialogCancel);
|
||||
|
||||
jQuery(dialog).find('.js-edit-independently').off('click');
|
||||
jQuery(dialog).find('.js-edit-independently').on('click', function () {
|
||||
editor.editIndependently();
|
||||
endingDuplicate = true;
|
||||
dialog.dialog('close');
|
||||
});
|
||||
};
|
||||
|
||||
var dialogCancel = function () {
|
||||
editor.cancel();
|
||||
};
|
||||
|
||||
init(editor);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.FIELD_STYLE_SINGLE_LINE = '0';
|
||||
WPML_TM.FIELD_STYLE_TEXT_AREA = '1';
|
||||
WPML_TM.FIELD_STYLE_WYSIWYG = '2';
|
||||
|
||||
WPML_TM.fieldViewFactory = {
|
||||
create: function (field, args) {
|
||||
var view = null;
|
||||
if (field.field_style === WPML_TM.FIELD_STYLE_SINGLE_LINE) {
|
||||
view = new WPML_TM.editorSingleLineFieldView(args);
|
||||
} else if (field.field_style === WPML_TM.FIELD_STYLE_TEXT_AREA) {
|
||||
view = new WPML_TM.editorTextareaFieldView(args);
|
||||
} else if (field.field_style === WPML_TM.FIELD_STYLE_WYSIWYG) {
|
||||
view = new WPML_TM.editorWysiwygFieldView(args);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*global jQuery, ajaxurl, Backbone, WpmlTmEditorModel, window, tmEditorStrings, _ */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorFooterView = Backbone.View.extend({
|
||||
tagName: 'footer',
|
||||
className: 'wpml-translation-action-buttons',
|
||||
|
||||
events: {
|
||||
'click .js-save': 'save',
|
||||
'click .js-resign': 'resign',
|
||||
'click .js-dialog-cancel': 'cancel',
|
||||
'click .js-save-and-close': 'save_and_close',
|
||||
'change .js-toggle-translated': 'toggleTranslated'
|
||||
},
|
||||
initialize: function (options) {
|
||||
var self = this;
|
||||
self.mainView = options.mainView;
|
||||
self.listenTo(self.model, 'translationUpdated', self.setDirty);
|
||||
},
|
||||
save: function () {
|
||||
var self = this;
|
||||
self.doSave();
|
||||
},
|
||||
editIndependently: function () {
|
||||
WpmlTmEditorModel.is_duplicate = false;
|
||||
},
|
||||
doSave: function () {
|
||||
var self = this;
|
||||
var saveMessage = jQuery('.js-saving-message');
|
||||
saveMessage.show();
|
||||
self.disableButtons(true);
|
||||
self.listenToOnce(self.model, 'saveJobSuccess', function () {
|
||||
saveMessage.hide();
|
||||
self.disableButtons(false);
|
||||
});
|
||||
self.model.save(jQuery('#icl_tm_editor').serialize());
|
||||
|
||||
self.setDirty(false);
|
||||
return self;
|
||||
},
|
||||
resign: function () {
|
||||
if (window.confirm(tmEditorStrings.resign_translation)) {
|
||||
window.location.href = tmEditorStrings.resign_url;
|
||||
}
|
||||
},
|
||||
cancel: function () {
|
||||
this.redirect_to_return_url('wpml_tm_cancel=1');
|
||||
},
|
||||
save_and_close: function () {
|
||||
var self = this;
|
||||
self.listenToOnce(self.model, 'saveJobSuccess', function () {
|
||||
self.setDirty(false);
|
||||
this.redirect_to_return_url('wpml_tm_saved=1');
|
||||
});
|
||||
|
||||
self.save();
|
||||
},
|
||||
redirect_to_return_url: function (param_string) {
|
||||
var url = WpmlTmEditorModel.return_url;
|
||||
if (url.indexOf('?') < 0) {
|
||||
url += '?' + param_string;
|
||||
} else {
|
||||
url += '&' + param_string;
|
||||
}
|
||||
window.location = url;
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/footer.html'](tmEditorStrings));
|
||||
self.progressBar = self.$el.find('.js-progress-bar');
|
||||
self.translationComplete = self.$el.find(':checkbox[name=complete]');
|
||||
self.showProgressBar();
|
||||
self.maybeShowTranslationComplete();
|
||||
self.maybeHideHideCompletedSwitcher();
|
||||
|
||||
window.onbeforeunload = function (e) {
|
||||
if (self.isDirty()) {
|
||||
return tmEditorStrings.confirmNavigate;
|
||||
}
|
||||
};
|
||||
_.defer(_.bind(self.maybeShowDuplicateDialog, self));
|
||||
},
|
||||
maybeShowDuplicateDialog: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.is_duplicate) {
|
||||
self.dialog = new WPML_TM.editorEditIndependentlyDialog(self);
|
||||
}
|
||||
},
|
||||
showProgressBar: function () {
|
||||
|
||||
var self = this;
|
||||
self.progressBar.css('display', WpmlTmEditorModel.requires_translation_complete_for_each_field ? 'inline-block' : 'none');
|
||||
self.progressBar.find('.ui-progressbar-value').height(self.progressBar.find('.progress-bar-text').height());
|
||||
self.progressBar.progressbar({});
|
||||
var value = parseInt(self.model.progressPercentage(), 10);
|
||||
self.progressBar.find('.progress-bar-text').html(value + '% Complete');
|
||||
self.progressBar.find('.ui-progressbar-value').attr('data-progressbar-text', value + '% Complete');
|
||||
self.progressBar.progressbar({value: value});
|
||||
self.progressBar.find('.ui-progressbar-value').height(self.progressBar.find('.progress-bar-text').height());
|
||||
|
||||
return self;
|
||||
},
|
||||
setCompleteCheckBox: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.requires_translation_complete_for_each_field) {
|
||||
self.translationComplete.prop('checked', self.model.progressPercentage() === 100);
|
||||
}
|
||||
return self;
|
||||
},
|
||||
maybeShowTranslationComplete: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.requires_translation_complete_for_each_field) {
|
||||
self.translationComplete.parent().hide();
|
||||
} else {
|
||||
self.translationComplete.prop('checked', WpmlTmEditorModel.translation_is_complete);
|
||||
}
|
||||
},
|
||||
maybeHideHideCompletedSwitcher: function () {
|
||||
var self = this;
|
||||
if (!WpmlTmEditorModel.display_hide_completed_switcher) {
|
||||
self.$el.find('#wpml_tm_toggle_translated').parent().hide();
|
||||
}
|
||||
},
|
||||
progressBar: function () {
|
||||
return this.$el.find('.js-progress-bar');
|
||||
},
|
||||
setDirty: function (value) {
|
||||
this.model.set('is_dirty', value);
|
||||
},
|
||||
isDirty: function () {
|
||||
return this.model.get('is_dirty');
|
||||
},
|
||||
disableButtons: function (state) {
|
||||
this.$el.find('.js-save, .js-resign, .js-dialog-cancel, .js-save-and-close').prop('disabled', state);
|
||||
},
|
||||
disableSaveButtons: function (state) {
|
||||
this.$el.find('.js-save, .js-save-and-close').prop('disabled', state);
|
||||
},
|
||||
hideResignButton: function (state) {
|
||||
if (state) {
|
||||
this.$el.find('.js-resign').hide();
|
||||
} else {
|
||||
this.$el.find('.js-resign').show();
|
||||
}
|
||||
},
|
||||
toggleTranslated: function() {
|
||||
var toggle = this.$el.find('.js-toggle-translated');
|
||||
this.mainView.hideTranslated(toggle.is(':checked'));
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*global Backbone, jQuery*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorGroupView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-form-row wpml-field-group',
|
||||
events: {
|
||||
'click .js-button-copy-group': 'onCopy',
|
||||
'update_button_state .js-button-copy-group': 'setCopyButtonState'
|
||||
},
|
||||
render: function (group) {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/group.html'](group));
|
||||
},
|
||||
setup: function () {
|
||||
this.$el.find('.js-button-copy').css({visibility: 'hidden'});
|
||||
this.initializeGroupCopyButtons();
|
||||
this.setCopyButtonState();
|
||||
},
|
||||
initializeGroupCopyButtons: function () {
|
||||
|
||||
var self = this;
|
||||
|
||||
// Poistion the copy button so it's between the original and translation
|
||||
|
||||
self.$el.find('.js-button-copy:first').each(function () {
|
||||
|
||||
// center the button in group
|
||||
var groupCopyButton = self.$el.find('.js-button-copy-group');
|
||||
var firstButton = jQuery(this);
|
||||
var lastButton = self.$el.find('.js-button-copy:last');
|
||||
if (lastButton.length) {
|
||||
var groupHeight = lastButton.position().top + lastButton.height() - firstButton.position().top;
|
||||
var newTop = groupHeight / 2 - groupCopyButton.height() / 2;
|
||||
groupCopyButton.css({
|
||||
'position': 'relative',
|
||||
'top': newTop
|
||||
});
|
||||
}
|
||||
|
||||
groupCopyButton.insertAfter(firstButton);
|
||||
|
||||
// hide the original copy button
|
||||
firstButton.hide();
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
onCopy: function () {
|
||||
this.$el.find('.js-button-copy').trigger('click');
|
||||
},
|
||||
setCopyButtonState: function () {
|
||||
this.$el.find('.js-button-copy-group').prop('disabled', this.$el.find('.js-button-copy:disabled').length > 0);
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*global Backbone, jQuery*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorHeaderView = Backbone.View.extend({
|
||||
tagName: 'span',
|
||||
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/header.html'](self.model));
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*global Backbone, jQuery*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorImageView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-field-image',
|
||||
render: function (image) {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/image.html'](image));
|
||||
},
|
||||
setup: function () {
|
||||
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,37 @@
|
||||
/*global Backbone, jQuery, _, tmEditor */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorBasicFieldView = WPML_TM.editorJobFieldView.extend({
|
||||
events: _.extend({
|
||||
'input .js-translated-value': 'onChange'
|
||||
}, WPML_TM.editorJobFieldView.prototype.events),
|
||||
|
||||
onChange: function () {
|
||||
tmEditor.model.trigger('translationUpdated', true);
|
||||
this.updateUI();
|
||||
},
|
||||
|
||||
getOriginal: function () {
|
||||
return this.$el.find('.js-original-value').val();
|
||||
},
|
||||
|
||||
getTranslation: function () {
|
||||
return this.$el.find('.js-translated-value').val();
|
||||
},
|
||||
|
||||
setTranslation: function (value) {
|
||||
this.$el.find('.js-translated-value').val(value);
|
||||
this.updateUI();
|
||||
},
|
||||
|
||||
setTranslatedColor: function(css) {
|
||||
this.$el.find('.js-translated-value').css(css);
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*global Backbone, WpmlTmEditorModel, document, jQuery, _ */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorJobFieldView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-form-row',
|
||||
events: {
|
||||
'click .icl_tm_copy_link': 'copyField',
|
||||
'click .js-toggle-diff': 'toggleDiff',
|
||||
'change .js-field-translation-complete' : 'setInputStatus'
|
||||
},
|
||||
toggleDiff: function(e) {
|
||||
e.preventDefault();
|
||||
var diff = this.$el.find('.diff');
|
||||
if(diff.is(':visible')) {
|
||||
diff.fadeOut();
|
||||
} else {
|
||||
diff.fadeIn();
|
||||
}
|
||||
this.updateUI();
|
||||
},
|
||||
copyField: function () {
|
||||
var self = this;
|
||||
self.setTranslation(self.getOriginal());
|
||||
return false;
|
||||
},
|
||||
updateUI: function () {
|
||||
var self = this;
|
||||
if (self.$el.is(':visible')) {
|
||||
try {
|
||||
var original = self.getOriginal();
|
||||
var translation = self.getTranslation();
|
||||
|
||||
self.$el.find('.icl_tm_copy_link').prop('disabled', translation !== '' || original === '');
|
||||
self.translationCompleteCheckbox.prop('disabled', translation === '');
|
||||
if ('' === translation) {
|
||||
self.translationCompleteCheckbox.prop('checked', false);
|
||||
self.translationCompleteCheckbox.trigger('change');
|
||||
}
|
||||
self.sendMessageToGroupView();
|
||||
jQuery(document).trigger('WPML_TM.editor.field_update_ui', self);
|
||||
}
|
||||
catch(err) {
|
||||
// this try - catch block is needed because this is sometimes called before tiny MCE editor is completely initialized
|
||||
}
|
||||
}
|
||||
},
|
||||
escapeHTML: function (string) {
|
||||
return string.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
||||
},
|
||||
render: function (field, labels) {
|
||||
var self = this;
|
||||
self.field = field;
|
||||
if (typeof self.field.title === 'undefined' || '' === self.field.title) {
|
||||
self.$el.removeClass('wpml-form-row').addClass('wpml-form-row-nolabel');
|
||||
}
|
||||
if (field.field_style !== WPML_TM.FIELD_STYLE_SINGLE_LINE) {
|
||||
self.field.field_data = self.escapeHTML(self.field.field_data);
|
||||
}
|
||||
self.$el.html(WPML_TM[self.getTemplate()]({
|
||||
field: self.field,
|
||||
labels: labels
|
||||
}));
|
||||
self.translationCompleteCheckbox = self.$el.find('.js-field-translation-complete');
|
||||
_.defer(_.bind(self.updateUI, self));
|
||||
if (WpmlTmEditorModel.hide_empty_fields && field.field_data === '') {
|
||||
self.$el.hide().addClass('hidden');
|
||||
self.translationCompleteCheckbox.prop('checked', true);
|
||||
self.translationCompleteCheckbox.prop('disabled', false);
|
||||
}
|
||||
if (!WpmlTmEditorModel.requires_translation_complete_for_each_field) {
|
||||
self.translationCompleteCheckbox.hide();
|
||||
self.translationCompleteCheckbox.parent().hide();
|
||||
}
|
||||
self.$el.find('.field-diff').find('.diff').hide();
|
||||
|
||||
self.setTranslatedColor( self.getStatusColors() );
|
||||
|
||||
jQuery(document).trigger('WPML_TM.editor.field_view_ready', self);
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
},
|
||||
|
||||
sendMessageToGroupView: function () {
|
||||
var group = this.$el.closest('.wpml-field-group');
|
||||
if (group.length) {
|
||||
group.find('.js-button-copy-group').trigger('update_button_state');
|
||||
}
|
||||
},
|
||||
|
||||
getFieldType: function () {
|
||||
return this.field.field_type;
|
||||
},
|
||||
|
||||
setInputStatus: function() {
|
||||
var self = this;
|
||||
self.setTranslatedColor( self.getStatusColors() );
|
||||
_.delay( function () {
|
||||
jQuery( '.js-toggle-translated' ).trigger( 'change' );
|
||||
}, 1000 );
|
||||
},
|
||||
|
||||
getStatusColors: function () {
|
||||
var self = this;
|
||||
if (self.translationCompleteCheckbox.is(':checked')) {
|
||||
return {
|
||||
background: '#e8f7e3',
|
||||
borderColor: '#d0e9c6'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
background: '',
|
||||
borderColor: ''
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
hideTranslated: function ( state ) {
|
||||
var self = this;
|
||||
if ( self.translationCompleteCheckbox.is( ':checked' ) && state ) {
|
||||
self.$el.hide();
|
||||
} else {
|
||||
if ( !self.$el.hasClass( 'hidden' ) ) {
|
||||
self.$el.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,15 @@
|
||||
/*global */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorSingleLineFieldView = WPML_TM.editorBasicFieldView.extend({
|
||||
|
||||
getTemplate: function () {
|
||||
return 'templates/translation-editor/single-line.html';
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,15 @@
|
||||
/*global */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorTextareaFieldView = WPML_TM.editorBasicFieldView.extend({
|
||||
|
||||
getTemplate: function () {
|
||||
return 'templates/translation-editor/textarea.html';
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,151 @@
|
||||
/*global jQuery, tinymce, tinyMCE, _, quicktags, tmEditor, WpmlTmEditorModel*/
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorWysiwygFieldView = WPML_TM.editorJobFieldView.extend({
|
||||
getTemplate: function () {
|
||||
return 'templates/translation-editor/wysiwyg.html';
|
||||
},
|
||||
|
||||
getOriginal: function () {
|
||||
return this.$el.find('textarea.original_value').text();
|
||||
},
|
||||
|
||||
getTranslation: function () {
|
||||
var self = this;
|
||||
var editor = tinymce.get(self.field.field_type);
|
||||
if (editor && editor instanceof tinyMCE.Editor && !editor.isHidden()) {
|
||||
return editor.getContent();
|
||||
} else {
|
||||
return self.getTextAreaElement().val();
|
||||
}
|
||||
},
|
||||
|
||||
setTranslation: function (value) {
|
||||
var self = this;
|
||||
|
||||
var editor = tinymce.get(self.field.field_type);
|
||||
var shouldToggle = editor && editor instanceof tinyMCE.Editor && !editor.isHidden();
|
||||
|
||||
if (shouldToggle) {
|
||||
tinymce.execCommand('mceToggleEditor', false, self.field.field_type);
|
||||
}
|
||||
|
||||
self.getTextAreaElement().val(value);
|
||||
|
||||
if (shouldToggle) {
|
||||
tinymce.execCommand('mceToggleEditor', false, self.field.field_type);
|
||||
}
|
||||
|
||||
this.updateUI();
|
||||
},
|
||||
|
||||
setup: function () {
|
||||
var self = this;
|
||||
self.replacePlaceHolder('original');
|
||||
self.replacePlaceHolder('translated');
|
||||
|
||||
self.$el.find('textarea.original_value').prop('readonly', true);
|
||||
self.getTextAreaElement().on('input', _.bind(self.updateUI, self));
|
||||
self.getTextAreaElement().on('input', function () {
|
||||
tmEditor.model.trigger('translationUpdated', true);
|
||||
});
|
||||
|
||||
if (!WpmlTmEditorModel.show_media_button) {
|
||||
self.$el.find('.wp-media-buttons').hide();
|
||||
}
|
||||
|
||||
_.delay(_.bind(self.waitForEditorAndThenInstallHooks, self, self.translationCompleteCheckbox.is( ':checked' )), 1000);
|
||||
|
||||
_.delay(_.bind(self.setInputStatus, self, 1000 ) );
|
||||
|
||||
},
|
||||
|
||||
getTextAreaElement: function () {
|
||||
return this.$el.find('textarea#' + this.field.field_type);
|
||||
},
|
||||
|
||||
waitForEditorAndThenInstallHooks: function (checked) {
|
||||
var self = this;
|
||||
var editor = tinymce.get(self.field.field_type);
|
||||
if (editor && editor instanceof tinyMCE.Editor) {
|
||||
editor.on('nodechange keyup', function (e) {
|
||||
var lazyOnChange = _.debounce(_.bind(self.updateUI, self), 1000);
|
||||
lazyOnChange(editor);
|
||||
editor.save();
|
||||
});
|
||||
|
||||
editor.on('change', function (e) {
|
||||
tmEditor.model.trigger('translationUpdated', true);
|
||||
});
|
||||
_.delay(function () {
|
||||
self.$el.find('.mce_editor_origin .mce-toolbar-grp').height(self.$el.find('.mce_editor .mce-toolbar-grp').height());
|
||||
}, 1000);
|
||||
self.setRtlAttributes(editor);
|
||||
self.setOriginalBackgroundGray( editor );
|
||||
|
||||
if( checked ) {
|
||||
self.translationCompleteCheckbox.prop('checked', true);
|
||||
self.translationCompleteCheckbox.prop('disabled', false);
|
||||
self.translationCompleteCheckbox.trigger('change');
|
||||
}
|
||||
} else {
|
||||
_.delay(_.bind(self.waitForEditorAndThenInstallHooks, self), 1000);
|
||||
}
|
||||
},
|
||||
|
||||
replacePlaceHolder: function (type) {
|
||||
var self = this;
|
||||
var $placeholder = self.$el.find('#' + type + '_' + self.field.field_type + '_placeholder');
|
||||
jQuery('#' + self.field.field_type + '_' + type + '_editor').detach().insertAfter($placeholder);
|
||||
$placeholder.remove();
|
||||
},
|
||||
setRtlAttributes: function (editor) {
|
||||
var self = this, dir, body, html;
|
||||
|
||||
dir = WpmlTmEditorModel.rtl_translation ? 'rtl' : 'ltr';
|
||||
html = jQuery(editor.iframeElement).contents().find('html');
|
||||
html.attr('dir', dir);
|
||||
body = html.find('body');
|
||||
if (body.length) {
|
||||
body.attr('dir', dir);
|
||||
}
|
||||
self.getTextAreaElement().attr('dir', dir);
|
||||
|
||||
dir = WpmlTmEditorModel.rtl_original ? 'rtl' : 'ltr';
|
||||
html = self.$el.find('.mce_editor_origin').find('iframe').contents().find('html');
|
||||
html.attr('dir', dir);
|
||||
body = html.find('body');
|
||||
if (body.length) {
|
||||
body.attr('dir', dir);
|
||||
}
|
||||
self.$el.find('textarea.original_value').attr('dir', dir);
|
||||
},
|
||||
setOriginalBackgroundGray: function ( editor ) {
|
||||
var self = this,
|
||||
html = self.$el.find( '.mce_editor_origin' ).find( 'iframe' ).contents().find( 'html' ),
|
||||
body = html.find('body'),
|
||||
sizer = self.$el.find( '.mce_editor_origin' ).find( '.mce-statusbar' ).find( '.mce-flow-layout' );
|
||||
|
||||
body.css( 'background-color', '#eee' );
|
||||
sizer.css( 'background-color', '#eee' );
|
||||
},
|
||||
setTranslatedColor: function ( css ) {
|
||||
var input = this.$el.find( '.translated_value' ),
|
||||
html = input.find( 'iframe' ).contents().find( 'html' ),
|
||||
body = html.find( 'body' ),
|
||||
sizer = input.find( '.mce-statusbar' ).find( '.mce-flow-layout' ),
|
||||
textArea = input.find( '.translated_value' );
|
||||
|
||||
body.css( 'background-color', css.background );
|
||||
sizer.css( 'background-color', css.background );
|
||||
textArea.css( 'background-color', css.background );
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,56 @@
|
||||
/*global _, Backbone, jQuery, WpmlTmEditorModel, ajaxurl */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorJob = Backbone.Model.extend({
|
||||
fetch: function (successCallback) {
|
||||
var self = this;
|
||||
|
||||
_.each(WpmlTmEditorModel.fields, function (field) {
|
||||
field.field_finished = parseInt(field.field_finished, 10);
|
||||
self.set(field.field_type, field.field_data);
|
||||
self.set(field.field_type + '_raw', field);
|
||||
});
|
||||
self.set('layout', WpmlTmEditorModel.layout);
|
||||
successCallback();
|
||||
},
|
||||
save: function (data) {
|
||||
var self = this;
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: self.url(),
|
||||
dataType: 'json',
|
||||
data: {
|
||||
data: data,
|
||||
action: 'wpml_save_job_ajax',
|
||||
_icl_nonce: self.get('nonce')
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
self.trigger('saveJobSuccess');
|
||||
} else {
|
||||
self.trigger('saveJobFailed');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
progressPercentage: function () {
|
||||
|
||||
return jQuery('.icl_tm_finished:checked:visible').length / jQuery('.icl_tm_finished:visible').length * 100;
|
||||
},
|
||||
/**
|
||||
* Overrides the BackBone url method to use the WordPress ajax endpoint
|
||||
*
|
||||
* @returns {String}
|
||||
*/
|
||||
url: function () {
|
||||
|
||||
return ajaxurl;
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*global Backbone */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorLanguagesView = Backbone.View.extend({
|
||||
tagName: 'header',
|
||||
className: 'wpml-translation-header',
|
||||
events: {
|
||||
'click .js-button-copy-all': 'copyAll'
|
||||
},
|
||||
initialize: function (options) {
|
||||
this.mainView = options.mainView;
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/languages.html'](self.model));
|
||||
},
|
||||
copyAll: function () {
|
||||
var copyAllTask = new WPML_TM.editorCopyAll(this.mainView);
|
||||
copyAllTask.copy();
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,210 @@
|
||||
/*global _, Backbone, WpmlTmEditorModel, tmEditorStrings, jQuery, tmEditor, document */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorMainView = Backbone.View.extend({
|
||||
events: {
|
||||
'change .icl_tm_finished': 'updateState'
|
||||
},
|
||||
updateState: function () {
|
||||
var self = this;
|
||||
self.footerView.showProgressBar().setCompleteCheckBox();
|
||||
},
|
||||
render: function () {
|
||||
var self = this;
|
||||
var job_type = jQuery('input[name="job_post_type"]').val();
|
||||
self.fieldViews = [];
|
||||
|
||||
self.translationMemory = null;
|
||||
|
||||
if (
|
||||
WpmlTmEditorModel.translation_memory
|
||||
&& tmEditorStrings.translationMemoryNonce
|
||||
&& tmEditorStrings.translationMemoryEndpoint
|
||||
) {
|
||||
self.translationMemory = new WPML_TM.translationMemory( WpmlTmEditorModel.languages );
|
||||
}
|
||||
|
||||
jQuery('#screen-meta-links').hide();
|
||||
|
||||
jQuery(document).trigger('WPML_TM.editor.before_render', [job_type] );
|
||||
|
||||
self.addHeaderView();
|
||||
self.addNoteView();
|
||||
self.addLanguagesView();
|
||||
|
||||
self.model.fetch(function () {
|
||||
self.addFields(self.model.get('layout'), self.$el.find('#wpml-translation-editor-wrapper'));
|
||||
self.addFooterView();
|
||||
|
||||
jQuery(document).trigger('WPML_TM.editor.ready', [job_type, self.fieldViews, self.footerView]);
|
||||
});
|
||||
self.updateState();
|
||||
|
||||
if ( self.translationMemory ) {
|
||||
self.translationMemory.fetch();
|
||||
}
|
||||
|
||||
return self;
|
||||
},
|
||||
addFields: function (fields, $location) {
|
||||
var self = this;
|
||||
_.each(fields, function (field) {
|
||||
if (typeof field == 'string') {
|
||||
self.fieldViews.push(self.createFieldView(field, $location));
|
||||
} else if (field.field_type == 'tm-section') {
|
||||
self.createSection(field, $location);
|
||||
} else if (field.field_type == 'tm-group') {
|
||||
self.createGroup(field, $location);
|
||||
} else if (field.field_type == 'wcml-image') {
|
||||
self.createImage(field, $location);
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
createFieldView: function (field, $location) {
|
||||
var self = this;
|
||||
field = self.model.get(field + '_raw');
|
||||
var view = WPML_TM.fieldViewFactory.create(field, {
|
||||
id: 'job_field_' + field.field_type,
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(self.model.get(field.field_type + '_raw'), tmEditorStrings);
|
||||
$location.last().append(view.$el);
|
||||
view.setup();
|
||||
|
||||
if ( self.translationMemory ) {
|
||||
self.translationMemory.addField( field, view );
|
||||
}
|
||||
|
||||
return view;
|
||||
},
|
||||
createSection: function (field, $location) {
|
||||
var self = this;
|
||||
var view = new WPML_TM.editorSectionView({
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(field);
|
||||
$location.last().append(view.$el);
|
||||
self.addFields(field.fields, view.$el.find('.inside'));
|
||||
},
|
||||
createGroup: function (field, $location) {
|
||||
var self = this;
|
||||
var view = new WPML_TM.editorGroupView({
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(field);
|
||||
$location.last().append(view.$el);
|
||||
self.addFields(field.fields, view.$el.find('.inside'));
|
||||
view.setup();
|
||||
},
|
||||
createImage: function (field, $location) {
|
||||
var self = this;
|
||||
var view = new WPML_TM.editorImageView({
|
||||
job_id: self.model.get('job_id')
|
||||
});
|
||||
view.render(field);
|
||||
$location.last().append(view.$el);
|
||||
self.addFields(field.fields, view.$el.find('.inside'));
|
||||
view.setup();
|
||||
},
|
||||
addHeaderView: function () {
|
||||
var self = this;
|
||||
var headerView = new WPML_TM.editorHeaderView({
|
||||
model: WpmlTmEditorModel.header
|
||||
});
|
||||
headerView.render();
|
||||
self.appendToDom(headerView);
|
||||
},
|
||||
addNoteView: function () {
|
||||
var self = this;
|
||||
if (WpmlTmEditorModel.note) {
|
||||
var noteView = new WPML_TM.editorNoteView({
|
||||
model: WpmlTmEditorModel
|
||||
});
|
||||
noteView.render();
|
||||
self.appendToDom(noteView);
|
||||
}
|
||||
},
|
||||
addLanguagesView: function () {
|
||||
var self = this;
|
||||
self.languagesView = new WPML_TM.editorLanguagesView({
|
||||
model: {
|
||||
language: WpmlTmEditorModel.languages,
|
||||
labels: tmEditorStrings
|
||||
},
|
||||
mainView: self
|
||||
});
|
||||
self.languagesView.render();
|
||||
self.appendToDom(self.languagesView);
|
||||
},
|
||||
addFooterView: function () {
|
||||
var self = this;
|
||||
self.footerView = new WPML_TM.editorFooterView({
|
||||
model: tmEditor.model,
|
||||
mainView: self
|
||||
});
|
||||
self.footerView.render();
|
||||
self.appendToDom(self.footerView);
|
||||
},
|
||||
appendToDom: function (view) {
|
||||
var self = this;
|
||||
if (view instanceof WPML_TM.editorHeaderView) {
|
||||
self.$el.find('#wpml-translation-editor-header').last().append(view.$el);
|
||||
} else {
|
||||
self.$el.find('#wpml-translation-editor-wrapper').last().append(view.$el);
|
||||
}
|
||||
},
|
||||
hasTranslations: function () {
|
||||
var self = this;
|
||||
var hasTranslation = false;
|
||||
_.each( self.fieldViews, function ( view ) {
|
||||
if ( ! hasTranslation) {
|
||||
if ( view.getTranslation() !== '' && view.getTranslation() !== view.getOriginal() ) {
|
||||
hasTranslation = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return hasTranslation;
|
||||
},
|
||||
copyOriginalOverwrite: function () {
|
||||
var self = this;
|
||||
_.each(self.fieldViews, function (view) {
|
||||
view.copyField();
|
||||
});
|
||||
},
|
||||
copyOriginalDontOverwrite: function () {
|
||||
var self = this;
|
||||
_.each(self.fieldViews, function (view) {
|
||||
if (view.getTranslation() === '') {
|
||||
view.copyField();
|
||||
}
|
||||
});
|
||||
},
|
||||
hideTranslated: function (state) {
|
||||
var self = this;
|
||||
_.each(self.fieldViews, function (view) {
|
||||
view.hideTranslated(state);
|
||||
});
|
||||
self.hideEmptyGroups();
|
||||
},
|
||||
hideEmptyGroups: function () {
|
||||
jQuery('.postbox').each( function () {
|
||||
var elements = jQuery('[class*="wpml-form-row"]', jQuery(this));
|
||||
var hiddenElements = elements.filter( function () {
|
||||
return jQuery(this).css('display') === 'none';
|
||||
} );
|
||||
if ( elements.length === hiddenElements.length ) {
|
||||
jQuery(this).hide();
|
||||
} else {
|
||||
jQuery(this).show();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*global Backbone */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorNoteView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'wpml-form-row wpml-note',
|
||||
|
||||
render: function () {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/note.html'](self.model));
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -0,0 +1,28 @@
|
||||
/*global Backbone, tmEditorStrings */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
WPML_TM.editorSectionView = Backbone.View.extend({
|
||||
tagName: 'div',
|
||||
className: 'postbox',
|
||||
events: {
|
||||
'click .handlediv': 'showHideSection',
|
||||
'click .hndle': 'showHideSection'
|
||||
},
|
||||
|
||||
render: function (field) {
|
||||
var self = this;
|
||||
self.$el.html(WPML_TM['templates/translation-editor/section.html']({
|
||||
section: field,
|
||||
labels: tmEditorStrings
|
||||
}));
|
||||
},
|
||||
showHideSection: function () {
|
||||
this.$el.toggleClass('closed');
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,78 @@
|
||||
/*jshint devel:true */
|
||||
/*global jQuery, ajaxurl, tmEditorStrings */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.translationMemory = function ( languages ) {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
var init = function ( languages ) {
|
||||
self.strings = {};
|
||||
self.languages = languages;
|
||||
};
|
||||
|
||||
var hasTranslation = function ( field ) {
|
||||
return '' === field.field_data || '' !== field.field_data_translated || 0 !== field.field_finished;
|
||||
};
|
||||
|
||||
var updateViewWithTranslation = function ( data ) {
|
||||
if ( data.original in self.strings ) {
|
||||
for ( var i = 0; i < self.strings[ data.original ].length; i++ ) {
|
||||
var view = self.strings[ data.original ][ i ];
|
||||
if ( view.getTranslation() === '' ) {
|
||||
view.setTranslation( data.translation );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.addField = function ( field, view ) {
|
||||
if ( !hasTranslation( field ) ) {
|
||||
|
||||
var string = field.field_data;
|
||||
if ( !(string in self.strings) ) {
|
||||
self.strings[ string ] = [];
|
||||
}
|
||||
self.strings[ string ].push( view );
|
||||
}
|
||||
};
|
||||
|
||||
self.fetch = function () {
|
||||
var strings = [];
|
||||
|
||||
for ( var key in self.strings ) {
|
||||
if ( self.strings.hasOwnProperty( key ) ) {
|
||||
strings.push( {string: key, source: self.languages['source'], target: self.languages['target']} );
|
||||
}
|
||||
}
|
||||
if ( strings.length > 0 ) {
|
||||
jQuery.ajax(
|
||||
{
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
data: JSON.stringify({ batch: true, strings: strings }),
|
||||
action: 'wpml_action',
|
||||
nonce: tmEditorStrings.translationMemoryNonce,
|
||||
endpoint: tmEditorStrings.translationMemoryEndpoint
|
||||
},
|
||||
success: function ( response ) {
|
||||
if ( response.success ) {
|
||||
var data = response.data;
|
||||
for ( var i = 0; i < data.length; i++ ) {
|
||||
if ( data[i].length > 0 ) {
|
||||
updateViewWithTranslation( data[i][0] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
init( languages );
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
jQuery(function () {
|
||||
jQuery('*[data-tp-enabled="0"]').hide();
|
||||
jQuery('.wpml_tp_custom_dismiss_able').click(icl_dismiss_custom_text);
|
||||
});
|
||||
|
||||
function icl_dismiss_custom_text() {
|
||||
var item = jQuery(this);
|
||||
item.parentNode.parentNode.removeChild(item.parentNode);
|
||||
jQuery.ajax({
|
||||
type:'POST',
|
||||
url : item.href,
|
||||
success: function(msg){
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*jshint devel:true */
|
||||
/*global ajaxurl, jQuery */
|
||||
|
||||
var WPML_TM = WPML_TM || {};
|
||||
|
||||
WPML_TM.translationRolesSelect2 = function ( elementSelector, nonce, role, onChange ) {
|
||||
"use strict";
|
||||
|
||||
var formatResult = function ( user ) {
|
||||
/** @namespace user.full_name */
|
||||
var result = user.full_name;
|
||||
|
||||
if (!result) {
|
||||
result += user.display_name;
|
||||
}
|
||||
|
||||
result += ' - ' + user.user_login;
|
||||
|
||||
if (user.user_email) {
|
||||
result += ' (' + user.user_email + ')';
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fix select2 on ui dialogs
|
||||
* https://github.com/select2/select2/issues/1246#issuecomment-71710835
|
||||
*/
|
||||
|
||||
var otgs_access_fix_select2_in_dialog = function () {
|
||||
//Enable select2 dropdown fix
|
||||
if ( jQuery.ui && jQuery.ui.dialog && jQuery.ui.dialog.prototype._allowInteraction ) {
|
||||
var ui_dialog_interaction = jQuery.ui.dialog.prototype._allowInteraction;
|
||||
jQuery.ui.dialog.prototype._allowInteraction = function ( e ) {
|
||||
if ( jQuery( e.target ).closest( '.wpml_select2-dropdown' ).length ) return true;
|
||||
return ui_dialog_interaction.apply( this, arguments );
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
elementSelector.wpml_select2( {
|
||||
width: '250px',
|
||||
minimumInputLength: 2,
|
||||
ajax: {
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
datatype: 'json',
|
||||
delay: 250,
|
||||
data: function ( params ) {
|
||||
return {
|
||||
action: 'wpml_search_translation_' + role,
|
||||
nonce: nonce,
|
||||
search: params
|
||||
};
|
||||
},
|
||||
results: function ( data ) {
|
||||
return {
|
||||
results: data.data
|
||||
};
|
||||
}
|
||||
},
|
||||
formatResult: formatResult,
|
||||
formatSelection: formatResult,
|
||||
id: function ( user ) {
|
||||
return user.ID;
|
||||
}
|
||||
} ).on( 'change', onChange );
|
||||
|
||||
otgs_access_fix_select2_in_dialog();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,390 @@
|
||||
/*jshint browser:true, devel:true */
|
||||
/*globals jQuery, ajaxurl*/
|
||||
var WPMLTranslationServicesDialog = function () {
|
||||
"use strict";
|
||||
|
||||
var self = this;
|
||||
|
||||
self.INVALIDATION_ACTION = 'translation_service_invalidation';
|
||||
self.AUTHENTICATION_ACTION = 'translation_service_authentication';
|
||||
self.UPDATE_CREDENTIALS_ACTION = 'translation_service_update_credentials';
|
||||
|
||||
self.preventEventDefault = function (event) {
|
||||
if ('undefined' !== event && 'undefined' !== typeof(event.preventDefault)) {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
};
|
||||
|
||||
self.enterKey = 13;
|
||||
self.ajaxSpinner = jQuery('<span class="spinner"></span>');
|
||||
self.activeServiceWrapper = jQuery( '.js-wpml-active-service-wrapper' );
|
||||
|
||||
self.init = function () {
|
||||
var flushWebsiteDetailsCacheLink;
|
||||
var header;
|
||||
var tip;
|
||||
|
||||
header = self.activeServiceWrapper.find( '.active-service-header' ).val();
|
||||
tip = self.activeServiceWrapper.find( '.active-service-tip' ).val();
|
||||
|
||||
self.serviceDialog = jQuery('<div id="service_dialog"><h4>' + header + '</h4><div class="custom_fields_wrapper"></div><p class="ts-api-tip">' + tip + '</p><div class="tp_response_message icl_ajx_response"></div>');
|
||||
self.ajaxSpinner.addClass('is-active');
|
||||
|
||||
flushWebsiteDetailsCacheLink = jQuery('.js-flush-website-details-cache');
|
||||
|
||||
|
||||
jQuery('#wpml-tp-services').on('click', '.js-activate-service-id', function (event) {
|
||||
self.preventEventDefault(event);
|
||||
|
||||
var button = jQuery(this);
|
||||
var serviceId = jQuery(this).data('id');
|
||||
self.toggleService(serviceId, button, 1);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('body').delegate('.js-deactivate-service', 'click', function (event) {
|
||||
var serviceId;
|
||||
var button;
|
||||
self.preventEventDefault(event);
|
||||
|
||||
button = jQuery(this);
|
||||
serviceId = jQuery(this).data('id');
|
||||
self.toggleService(serviceId, button, 0);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
self.activeServiceWrapper.on('click', '.js-invalidate-service', function (event) {
|
||||
var serviceId;
|
||||
var button;
|
||||
self.preventEventDefault(event);
|
||||
|
||||
button = jQuery(this);
|
||||
serviceId = jQuery(this).data('id');
|
||||
self.translationServiceAuthentication(serviceId, button, self.INVALIDATION_ACTION, 1);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
flushWebsiteDetailsCacheLink.on('click', function (event) {
|
||||
var anchor = jQuery(this);
|
||||
self.preventEventDefault(event);
|
||||
|
||||
self.flushWebsiteDetailsCache(anchor);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
var credentialSettingHandler = function (event, action) {
|
||||
var customFields;
|
||||
var serviceId;
|
||||
self.preventEventDefault(event);
|
||||
|
||||
serviceId = jQuery(this).data('id');
|
||||
customFields = jQuery(this).data('custom-fields');
|
||||
|
||||
self.serviceAuthenticationDialog(customFields, serviceId, action);
|
||||
|
||||
return false;
|
||||
};
|
||||
self.activeServiceWrapper.on('click', '.js-authenticate-service', function (event) {
|
||||
return credentialSettingHandler.bind(this)(event, self.AUTHENTICATION_ACTION);
|
||||
});
|
||||
|
||||
self.activeServiceWrapper.on('click', '.js-update-service-credentials', function (event) {
|
||||
return credentialSettingHandler.bind(this)(event, self.UPDATE_CREDENTIALS_ACTION );
|
||||
});
|
||||
|
||||
self.refreshTSInfo();
|
||||
};
|
||||
|
||||
self.refreshTSInfo = function() {
|
||||
var activeServiceBlock = jQuery('.js-wpml-active-service-wrapper');
|
||||
|
||||
if ( ! activeServiceBlock.length || ! activeServiceBlock.find('.js-needs-info-refresh').val() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var activeTsButtons = activeServiceBlock.find('input, button').prop('disabled', true);
|
||||
var nonce = activeServiceBlock.find('.js-ts-refresh-nonce').val();
|
||||
var refreshMsg = activeServiceBlock.find('.js-ts-refreshing-message').fadeIn();
|
||||
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'refresh_ts_info',
|
||||
'nonce': nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.success && response.data) {
|
||||
var content = jQuery.parseHTML(response.data.active_service_block);
|
||||
activeServiceBlock.fadeOut(400, function() {
|
||||
activeServiceBlock.html(content).fadeIn(content);
|
||||
});
|
||||
} else {
|
||||
refreshMsg.fadeOut(400, function() {
|
||||
refreshMsg.html("<p>" + response.data.message + "</p>").addClass('notice notice-error inline').fadeIn(content);
|
||||
activeTsButtons.prop('disabled', false);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.toggleService = function (serviceId, button, enableService, successCallback) {
|
||||
var ajaxData;
|
||||
var enable = enableService;
|
||||
var nonce = jQuery( '.translation_service_toggle' ).val();
|
||||
if ('undefined' === typeof enableService) {
|
||||
enable = 0;
|
||||
}
|
||||
|
||||
self.disableButton(button);
|
||||
|
||||
ajaxData = {
|
||||
'action': 'translation_service_toggle',
|
||||
'nonce': nonce,
|
||||
'service_id': serviceId,
|
||||
'enable': enable ? 1 : 0
|
||||
};
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: ajaxData,
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
self.enableButton(button)
|
||||
if ( typeof successCallback === 'function' ) {
|
||||
successCallback( response.data );
|
||||
} else {
|
||||
var data = response.data;
|
||||
|
||||
if ( data.reload ) {
|
||||
location.reload( true );
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.disableButton = function (button) {
|
||||
if (button) {
|
||||
button.attr( 'disabled', 'disabled' );
|
||||
button.after( self.ajaxSpinner.clone().addClass('is-active') );
|
||||
}
|
||||
}
|
||||
|
||||
self.enableButton = function (button) {
|
||||
if (button) {
|
||||
button.prop( 'disabled', false );
|
||||
button.next().fadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
self.serviceAuthenticationDialog = function (customFields, serviceId, action) {
|
||||
self.serviceDialog.dialog({
|
||||
dialogClass: 'wpml-dialog otgs-ui-dialog',
|
||||
width: 'auto',
|
||||
title: self.activeServiceWrapper.find( '.active-service-title' ).val(),
|
||||
modal: true,
|
||||
open: function () {
|
||||
|
||||
var customFieldsWrapper = self.serviceDialog.find('.custom_fields_wrapper');
|
||||
self.buildCustomFieldsUI( customFields, customFieldsWrapper );
|
||||
|
||||
jQuery(':input', this).keyup(function (event) {
|
||||
if (self.enterKey === event.keyCode) {
|
||||
jQuery(this).closest('.ui-dialog').find('.ui-dialog-buttonpane').find('button.js-submit:first').click();
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: "Cancel",
|
||||
click: function () {
|
||||
jQuery(this).dialog("close");
|
||||
},
|
||||
'class': 'button-secondary alignleft'
|
||||
}, {
|
||||
text: "Submit",
|
||||
click: function () {
|
||||
self.hideButtons();
|
||||
self.translationServiceAuthentication(serviceId, false, action, 0);
|
||||
},
|
||||
'class': 'button-primary js-submit'
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
self.buildCustomFieldsUI = function (customFields, customFieldsWrapper) {
|
||||
var firstInput = false;
|
||||
|
||||
customFieldsWrapper.empty();
|
||||
|
||||
jQuery.each(customFields, function (i, item) {
|
||||
var itemLabel, itemInput;
|
||||
var itemId;
|
||||
var customFieldsListItem = jQuery('<div class="wpml-form-row"></div>');
|
||||
customFieldsListItem.appendTo(customFieldsWrapper);
|
||||
|
||||
itemId = 'custom_field_' + item.name;
|
||||
|
||||
if (item.type.trim().toLowerCase() !== 'hidden') {
|
||||
itemLabel = jQuery('<label for="' + itemId + '">' + item.label + ':</label>');
|
||||
itemLabel.appendTo(customFieldsListItem);
|
||||
}
|
||||
itemInput = jQuery('<input type="' + item.type + '" id="' + itemId + '" class="custom_fields" name="' + item.name + '" />');
|
||||
|
||||
itemInput.appendTo(customFieldsListItem);
|
||||
if (!firstInput) {
|
||||
itemInput.focus();
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
self.getSerializedCustomFields = function() {
|
||||
var customFieldsDataStringify;
|
||||
var customFieldsData;
|
||||
var customFieldsInput;
|
||||
|
||||
customFieldsInput = jQuery('.custom_fields');
|
||||
customFieldsData = {};
|
||||
jQuery.each(customFieldsInput, function (i, item) {
|
||||
customFieldsData[jQuery(item).attr('name')] = jQuery(item).val();
|
||||
});
|
||||
return JSON.stringify(customFieldsData, null, ' ');
|
||||
};
|
||||
|
||||
self.hideButtons = function () {
|
||||
self.ajaxSpinner.appendTo(self.serviceDialog);
|
||||
self.serviceDialog.parent().find('.ui-dialog-buttonpane').fadeOut();
|
||||
};
|
||||
|
||||
self.showButtons = function () {
|
||||
if ( self.serviceDialog ) {
|
||||
self.serviceDialog.find( self.ajaxSpinner ).remove();
|
||||
self.serviceDialog.parent().find( '.ui-dialog-buttonpane' ).fadeIn();
|
||||
}
|
||||
};
|
||||
|
||||
self.translationServiceAuthentication = function (serviceId, button, action, successCallback) {
|
||||
var nonce = jQuery( '.translation_service_authentication' ).val();
|
||||
|
||||
self.disableButton(button);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': action,
|
||||
'nonce': nonce,
|
||||
'service_id': serviceId,
|
||||
'custom_fields': self.getSerializedCustomFields()
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
self.enableButton(button);
|
||||
if ( typeof successCallback === 'function' ) {
|
||||
successCallback( response.data );
|
||||
} else {
|
||||
var response_message = jQuery( '.tp_response_message' );
|
||||
response = response.data;
|
||||
if ( 0 === response.errors ) {
|
||||
if ( response.reload ) {
|
||||
location.reload( true );
|
||||
}
|
||||
}
|
||||
|
||||
response_message.html( response.message );
|
||||
response_message.show();
|
||||
|
||||
setInterval( function () {
|
||||
response_message.fadeOut();
|
||||
}, 5000 );
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, status, error) {
|
||||
var parsedResponse = jqXHR.statusText || status || error;
|
||||
alert(parsedResponse);
|
||||
},
|
||||
complete: function() {
|
||||
self.showButtons();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.flushWebsiteDetailsCache = function (anchor) {
|
||||
var nonce = anchor.data('nonce');
|
||||
|
||||
self.ajaxSpinner.appendTo(anchor);
|
||||
self.ajaxSpinner.addClass('is-active');
|
||||
|
||||
if (nonce) {
|
||||
jQuery.ajax({
|
||||
type: "POST",
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'wpml-flush-website-details-cache',
|
||||
'nonce': nonce
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (response) {
|
||||
self.ajaxSpinner.removeClass('is-active');
|
||||
if (response.success) {
|
||||
/** @namespace response.redirectTo */
|
||||
location.reload(response.data.redirectTo);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
var wpmlTranslationServicesDialog = new WPMLTranslationServicesDialog();
|
||||
var current_url = location.href;
|
||||
var search_section = jQuery('.ts-admin-section-search');
|
||||
|
||||
wpmlTranslationServicesDialog.init();
|
||||
|
||||
search_section.find('.search').click(function () {
|
||||
var param = {
|
||||
s: search_section.find('.search-string' ).val()
|
||||
};
|
||||
|
||||
window.location.href = current_url + '&' + jQuery.param( param );
|
||||
});
|
||||
|
||||
search_section.find( '.search-string' ).keypress(function (e) {
|
||||
if ( e.which === 13 ) {
|
||||
search_section.find( '.search' ).click();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery( '.ts-admin-section-inactive-services #current-page-selector-top' ).keypress(function (e) {
|
||||
if ( e.which === 13 ) {
|
||||
var param = {
|
||||
paged: jQuery( this ).val()
|
||||
};
|
||||
|
||||
window.location.href = current_url + '&' + jQuery.param( param );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* global icl_ajxloaderimg */
|
||||
|
||||
var ProgressBar = Backbone.View.extend({
|
||||
dom: false,
|
||||
overall_count: 0,
|
||||
done_count: 0,
|
||||
ajax_loader_img: false,
|
||||
progress_label_value: false,
|
||||
progress_label: false,
|
||||
actionText : '',
|
||||
initialize: function () {
|
||||
var self = this;
|
||||
self.ajax_loader_img = jQuery(icl_ajxloaderimg);
|
||||
self.dom = jQuery('<div class="progressbar"><div class="progress-label"><span class="value"></span></div></div>');
|
||||
self.progress_label = self.dom.find(".progress-label");
|
||||
self.progress_label_value = self.dom.find(".value");
|
||||
|
||||
return self;
|
||||
},
|
||||
start: function () {
|
||||
var self = this;
|
||||
self.ajax_loader_img.appendTo(self.progress_label);
|
||||
self.getDomElement().progressbar({value: false, max: 100});
|
||||
self.getDomElement().fadeIn();
|
||||
self.progress_label_value.text('');
|
||||
|
||||
return self;
|
||||
},
|
||||
change: function (change) {
|
||||
var self = this;
|
||||
self.done_count += change;
|
||||
var value = Math.min(Math.round(self.done_count / self.overall_count * 100), 100);
|
||||
self.progress_label_value.text(self.actionText + " " + value + "%");
|
||||
self.getDomElement().progressbar('value', value);
|
||||
},
|
||||
complete: function (text, callback) {
|
||||
var self = this;
|
||||
self.ajax_loader_img.remove();
|
||||
self.progress_label_value.text(text);
|
||||
if (typeof callback === 'function') {
|
||||
callback(self);
|
||||
}
|
||||
},
|
||||
getRemainingCount: function () {
|
||||
var self = this;
|
||||
|
||||
return self.overall_count - self.done_count;
|
||||
},
|
||||
getDomElement: function () {
|
||||
var self = this;
|
||||
|
||||
return self.dom;
|
||||
},
|
||||
stop: function () {
|
||||
var self = this;
|
||||
self.getDomElement().hide();
|
||||
|
||||
return self;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
/*global jQuery, ajaxurl, wp, icl_ajx_response */
|
||||
var WPML_TP_API = WPML_TP_API || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
WPML_TP_API.refreshLanguagePairs = function () {
|
||||
|
||||
var refreshLanguagePairs = function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var self = this;
|
||||
var spinner = jQuery( '.refresh-language-pairs-section .spinner' );
|
||||
|
||||
spinner.addClass( 'is-active' );
|
||||
|
||||
wp.ajax.send({
|
||||
data: {
|
||||
action: 'wpml-tp-refresh-language-pairs',
|
||||
nonce: jQuery(self).data('nonce')
|
||||
},
|
||||
success : function (response) {
|
||||
var response_text = jQuery( '.refresh-language-pairs-section .wpml_ajax_response' );
|
||||
|
||||
response_text.html( response.msg );
|
||||
response_text.css( 'display', 'inline-block' );
|
||||
spinner.removeClass( 'is-active' );
|
||||
|
||||
setTimeout(function() {
|
||||
response_text.fadeOut( 'slow' );
|
||||
}, 3000);
|
||||
},
|
||||
complete: function () {
|
||||
spinner.remove();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
jQuery('.js-refresh-language-pairs').on('click', refreshLanguagePairs);
|
||||
|
||||
};
|
||||
|
||||
jQuery(function () {
|
||||
WPML_TP_API.refreshLanguagePairs();
|
||||
});
|
||||
}());
|
||||
Reference in New Issue
Block a user