Javascript-форум (https://javascript.ru/forum/)
-   Prototype & script.aculo.us (https://javascript.ru/forum/prototype-script-aculo-us/)
-   -   Помогите переписать этот код на Prototype (https://javascript.ru/forum/prototype-script-aculo-us/65824-pomogite-perepisat-ehtot-kod-na-prototype.html)

Mitrandir 09.11.2016 18:21

Помогите переписать этот код на Prototype
 
Добрый вечер!
Вопрос по сабжу, нужно срочно переписать код для того чтобы было легко его интегрировать в остальной код Prototype.
Пока пойду читать документацию самостоятельно, но вдруг тут кто-то согласится помочь быстрее :)
Собственно код
function send() {
        var paySystem = getPaySelectedAttr();

        document.getElementById('payparts-period-success').innerHTML = document.getElementById('month-sel').value;
        var url = "<?php echo $this->getUrl('payparts/payment/notify/', array('_secure' => false)); ?>";
        new Ajax.Request( url, {
            method: 'post',
            parameters: 'parts='+document.getElementById('month-sel').value+'&system='+ paySystem['system'],
            onSuccess: successFunc,
            onFailure:  failureFunc
        });

    }
    function successFunc(response){
        console.log(response);
        document.getElementById("payparts-select-block").style.display = "none";
        document.getElementById("payparts-success").style.display = "block";
        document.getElementById("payment-buttons-container").style.display = "block";
        return true;
    }
    function failureFunc(response){
        document.getElementById("send-parts-error").style.display = "block";
        return false;
    }

    function getPaySelectedAttr(){
        var result = {};
        var e = document.getElementById("system-sel");
        result['value'] = e.options[e.selectedIndex].value;
        result['system'] = e.options[e.selectedIndex].getAttribute('pp-name');
        result['name'] = e.options[e.selectedIndex].getAttribute('name');
        return result;
    }
    
    function periodChange(){
        var selectData = getPaySelectedAttr();
        var result = '<option disabled>Срок,мес.</option><option selected value="2">2</option>';
        console.log(selectData);

        for ($i=0;$i < selectData['value']; $i++){
            if($i > 2){
                result += '<option value='+$i+'>'+$i+'</option>';
            }
        }
        document.getElementById('month-sel').innerHTML = result;
        document.getElementById('system-name').innerHTML = selectData['name'];

    }
    function radioLisener(){
        var radios = document.forms["co-payment-form"].elements["payment[method]"];
        for(var i = 0, max = radios.length; i < max; i++) {
            radios[i].onchange = function() {
                if(document.getElementById('p_method_payparts_redirect').checked){
                    document.getElementById("payment-buttons-container").style.display = "none";   
                } else{
                    document.getElementById("payment-buttons-container").style.display = "block";
                }
            }
        }
    }
    radioLisener();
    document.getElementById("send-parts-error").style.display = "none";
    document.getElementById('send-period').onclick = send;
    document.getElementById('system-sel').onchange = periodChange;

Coriolan161 10.11.2016 11:12

Mitrandir,
Гендальф, бросай это гиблое дело!

Mitrandir 10.11.2016 16:03

Да я тоже так подумал, просто надеялся, что есть тут люди поумнее меня (они то есть), но толку вижу мало... :(

Coriolan161 10.11.2016 17:30

Mitrandir,
Просто надо лезть, ковырять, вспоминать Prototype который уже давно позабыт)


Часовой пояс GMT +3, время: 21:05.