Changeset 637


Ignore:
Timestamp:
06/11/2011 02:34:58 AM (12 months ago)
Author:
ofer
Message:

Fix ticket #161, some work for #141

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/transposhedit.js

    r624 r637  
    151151            tr0: translation 
    152152        }; 
    153         // We are pre-accounting the progress bar here - which is not very nice 
    154         /*TODO think!!!! if (source > 0) { 
    155             done_p += $("*[token='" + token + "']").size(); 
    156         }*/ 
     153 
    157154        $.ajax({ 
    158155            type: "POST", 
    159156            url: t_jp.post_url, 
    160157            data: data, 
    161             success: function () { 
    162             // Success now only updates the save progress bar (green) 
    163             /* THINK if (t_jp.progress) { 
    164                     if (togo > 4 && source > 0) { 
    165                         $("#progress_bar2").progressbar('value', done_p / togo * 100); 
    166                     } 
    167  
    168                 }*/ 
    169             }, 
    170  
     158            // In the past we used this to make progress bar status, not really needed, but keeping for future reference 
     159            // success: function () {}, 
     160            // TODO: This probably needs a revision! 
    171161            error: function (req) { 
    172162                alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 
     
    185175    } 
    186176 
     177    // fetch translation from google translate... 
    187178    function getgt() 
    188179    { 
     
    208199    function getbt() 
    209200    { 
    210         ms_trans($(idprefix + "original").val(), function (translation) { 
    211             $(idprefix + "translation").val($("<div>" + $.trim(translation) + "</div>").text()) 
     201        ms_trans($(idprefix + "original").val(), function (result) { 
     202            $(idprefix + "translation").val($("<div>" + $.trim(result) + "</div>").text()) 
    212203            .keyup(); 
    213204        }); 
     
    308299    function history_dialog(segment_id){ 
    309300        var dialog = idprefix + "historydialog"; 
    310         /*if ($(dialog).length) { 
    311             $(dialog).dialog('open'); 
    312             return; 
    313         }*/ 
    314301 
    315302        $(dialog).remove(); 
    316         //$(idprefix+'historydialog').remove(); 
    317303 
    318304        $('<div id="' + prefix + 'historydialog" title="' + __('History') + '">'+__('Loading...')+'</div>').appendTo("body"); 
     
    321307            // dialogClass: 'ui-widget-shadow', 
    322308            show: 'slide'//, 
    323         //stack: true 
    324309        }); 
    325310        if ($("html").attr("dir") === 'rtl') { 
     
    414399 
    415400    } 
     401     
     402    // load data to translate dialog 
     403    function set_translate_dialog_values(segment_id) { 
     404        // the field values 
     405        $(idprefix + "original").val($(idprefix + segment_id).attr('data-orig')); 
     406        $(idprefix + "translation").val($(idprefix + segment_id).html()); 
     407 
     408        if ($(idprefix + segment_id).attr('data-trans')) { 
     409            $(idprefix + "translation").val($(idprefix + segment_id).attr('data-trans')); 
     410        } 
     411        // init data vars 
     412        $(idprefix + "translation").data("origval", $(idprefix + "translation").val()); 
     413 
     414        // need to set approve button to enabled by default 
     415        $(idprefix + 'approve').button("enable"); 
     416 
     417        // make sure the next and prev buttons are in order 
     418        $(idprefix + 'prev').button("enable"); 
     419        $(idprefix + 'next').button("enable"); 
     420        if (!$(idprefix + (Number(segment_id) - 1)).length) { 
     421            $(idprefix + 'prev').button("disable"); 
     422        } 
     423        if (!$(idprefix + (Number(segment_id) + 1)).length) { 
     424            $(idprefix + 'next').button("disable"); 
     425        } 
     426 
     427        // set the original language part 
     428        var segmentlang = $(idprefix + segment_id).attr('data-srclang'); 
     429        if (segmentlang === undefined ) { 
     430            segmentlang = t_jp.olang; 
     431        } 
     432        $(idprefix + "orglang").text(l[segmentlang]); 
     433        // old history is history 
     434        $(idprefix+'historydialog').remove(); 
     435        // This line makes sure that the approval button is correct on creation 
     436        // at the end of the chain, a keyup event will make sure everything is ok 
     437        $(idprefix + "translation").keyup(); 
     438      
     439 
     440    } 
     441     
    416442    //Open translation dialog 
    417443    function translate_dialog(segment_id) { 
     
    434460        $('<div id="' + prefix + 'dialog" title="' + __('Edit Translation') + '"/>').appendTo("body"); 
    435461 
    436         var segmentlang = $(idprefix + segment_id).attr('data-srclang'); 
    437         if (segmentlang === undefined ) { 
    438             segmentlang = t_jp.olang; 
    439         } 
    440  
    441462        $(dialog).css("padding", "1px").append( 
    442463            '<div style="width: 100%">' + 
    443             '<label for="original">' + __('Original text') +' (<a href="#" title="'+__('read alternate translations')+'" id="'+prefix+'orglang">'+l[segmentlang]+'</a>)'+ '</label>' + 
     464            '<label for="original">' + __('Original text') +' (<a href="#" title="'+__('read alternate translations')+'" id="'+prefix+'orglang"></a>)'+ '</label>' + 
    444465            '<textarea cols="80" row="3" name="original" id="' + prefix + 'original" readonly="y"/>' + 
    445466            '<span id="' + prefix + 'utlbar">' + 
     
    552573            text: false 
    553574        }); 
     575         
    554576        // prev button click 
    555         if ($(idprefix + (Number(segment_id) - 1)).length) { 
    556             $(idprefix + 'prev').click(function () { 
    557                 translate_dialog(Number(segment_id) - 1); 
    558             }); 
    559         } else { 
    560             $(idprefix + 'prev').button("disable"); 
    561         } 
     577        $(idprefix + 'prev').click(function () { 
     578            // save data if changed 
     579            if ($(idprefix + 'translation').data("changed")) { 
     580                var translation = $(idprefix + 'translation').val(), 
     581                token = $(idprefix + segment_id).attr('data-token'); 
     582                ajax_translate_human(token, translation); 
     583            } 
     584            // dec counter, reload fields 
     585            segment_id = Number(segment_id) - 1; 
     586            set_translate_dialog_values(segment_id); 
     587        }); 
     588        // next button click 
     589        $(idprefix + 'next').click(function () { 
     590            // save data if changed 
     591            if ($(idprefix + 'translation').data("changed")) { 
     592                var translation = $(idprefix + 'translation').val(), 
     593                token = $(idprefix + segment_id).attr('data-token'); 
     594                ajax_translate_human(token, translation); 
     595            } 
     596            // inc counterm reload fields 
     597            segment_id = Number(segment_id) + 1; 
     598            set_translate_dialog_values(segment_id); 
     599        }); 
     600 
    562601        // zoom button click 
    563602        $(idprefix + 'zoom').click(function () { 
     
    592631        }); 
    593632 
    594         // next button click 
    595         if ($(idprefix + (Number(segment_id) + 1)).length) { 
    596             $(idprefix + 'next').click(function () { 
    597                 translate_dialog(Number(segment_id) + 1); 
    598             }); 
    599         } else { 
    600             $(idprefix + 'next').button("disable"); 
    601         } 
    602  
    603633        $(idprefix + 'history').button({ 
    604634            icons: { 
     
    636666            $(this).button("disable"); 
    637667        }); 
     668         
    638669        $(idprefix + 'bing').button({ 
    639670            icons: { 
     
    646677            $(this).button("disable"); 
    647678        }); 
     679         
    648680        $(idprefix + 'apertium').button({ 
    649681            icons: { 
     
    656688            $(this).button("disable"); 
    657689        }); 
     690         
     691        // approval button 
    658692        $(idprefix + 'approve').button({ 
    659693            icons: { 
     
    670704            } 
    671705        }); 
    672  
    673         // setting textarea values 
    674         $(idprefix + "original").val($(idprefix + segment_id).attr('data-orig')); 
    675  
    676         $(idprefix + "translation").val($(idprefix + segment_id).html()); 
    677  
    678         if ($(idprefix + segment_id).attr('data-trans')) { 
    679             $(idprefix + "translation").val($(idprefix + segment_id).attr('data-trans')); 
    680         } 
    681         // init data vars 
    682         $(idprefix + "translation") 
    683         //.data("changed",false) 
    684         .data("origval", $(idprefix + "translation").val()); 
    685706 
    686707        $(idprefix + "translation").keyup(function (e) { 
     
    697718            } 
    698719        }); 
    699  
    700         // This line makes sure that the approval button is correct on creation 
    701         $(idprefix + "translation").keyup(); 
     720        // load field values 
     721        set_translate_dialog_values(segment_id); 
    702722 
    703723        // time to create the dialog 
    704724        $(dialog).dialog({ 
    705             //modal: true, 
    706             //width: 'auto', 
    707             //autoopen: false, 
    708725            resizable: false, 
    709726            width: 500//, 
    710         //   buttons: tButtons 
    711727        }); 
    712728 
     
    715731            fix_dialog_header_rtl(dialog); 
    716732            var uicorner = 'ui-corner-'; 
     733            // to remove with jqueryui-1.8.14 
    717734            $(idprefix + 'utlbar button:first').addClass(uicorner + left).removeClass(uicorner + right); 
    718735            $(idprefix + 'utlbar button:last').addClass(uicorner + right).removeClass(uicorner + left); 
     
    742759 
    743760    } 
    744  
    745761 
    746762    // lets add the images 
Note: See TracChangeset for help on using the changeset viewer.