/**
 * Created on : 2014.08.24., 5:26:26
 * Author     : Lajos Molnar <lajax.m@gmail.com>
 * since 1.0
 */

var translate = (function () {

    /**
     * @type string
     */
    var _originalMessage;

    /**
     * @param {object} $this
     */
    function _translateLanguage($this) {
        var data = {
            id: $this.data('id'),
            language_id: $('#language_id').val(),
            translation: $.trim($this.closest('tr').find('.translation').val())
        };

        helpers.post($('#language_id').data('url'), data);
    }

    /**
     * @param {object} $this
     */
    function _copySourceToTranslation($this) {
        var $translation = $this.closest('tr').find('.translation'),
            isEmptyTranslation = $.trim($translation.val()).length === 0,
            sourceMessage = $.trim($this.val());

        if (!isEmptyTranslation) {
            return;
        }

        if (typeof tm_googleApiKey === 'undefined') {
            // default bahavior - copy original text to translation field
            $translation.val(sourceMessage);
            _translateLanguage($this);
        } else {
            // google translation is enabled - translate and copy translation
            helpers.googleTranslate($.trim($this.val()), $('#language_id').val(), function(result) {
                if (result.success) {
                    $translation.val(result.text);
                } else {
                    $translation.val(sourceMessage);
                    helpers.showMessages(lajax.t('Google translation failed, source text was used as translation!'));
                }

                _translateLanguage($this);
            });
        }
    }

    return {
        init: function () {
            $('#translates').on('click', '.source', function () {
                _copySourceToTranslation($(this));
            });
            $('#translates').on('click', 'button', function () {
                _translateLanguage($(this));
            });
            $('#translates').on('focus', '.translation', function () {
                _originalMessage = $.trim($(this).val());
            });
            $('#translates').on('blur', '.translation', function () {
                if ($.trim($(this).val()) !== _originalMessage) {
                    _translateLanguage($(this).closest('tr').find('button'));
                }
            });
            $('#translates').on('change', "#search-form select", function(){
                $(this).parents("form").submit();
            });
        }
    };
})();

$(document).ready(function () {
    translate.init();
});

@@ -274,32 +274,102 @@
 nguage($this) %7B%0A
+        var $translation = $this.closest('tr').find('.translation');%0A%0A
         var data
@@ -391,19 +391,26 @@
   id: $t
-his
+ranslation
 .data('i
@@ -501,34 +501,8 @@
 im($
-this.closest('tr').find('.
 tran
@@ -508,18 +508,16 @@
 nslation
-')
 .val())%0A

Fix empty ID posted on message copying