import-process.php
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$this->registerJs("
");
?>
<script type="text/javascript">
    jQuery(document).ready(function () {
        var in_process=false;
        var count=1;
        in_process=true;
        doImport();
        function doImport(from) {
            from = typeof(from) != 'undefined' ? from : 0;
            console.log('go', from);
            $.ajax({
                url: "<?= Yii::$app->request->baseUrl .'/product/manage/'. $method?>",
                data: {from:from},
                dataType: 'json',
                success: function(data){
                    for(var key in data.items)
                    {
                        $('ul#process-result').prepend('<li>'+ data.items[key] +'</li>');
                        count++;
                    }
                    var per = Math.round(100*data.from/data.totalsize)+'%';
                    $('#progressbar div').css({width: per});
                    if(data != false && !data.end)
                    {
                        doImport(data.from);
                    }
                    else
                    {
                        $('ul#process-result').prepend('<li>Импорт цен успешно завершен!</li>');
                        progressbar.hide('fast');
                        in_process = false;
                    }
                },
                error: function(xhr, status, errorThrown) {
                    alert(errorThrown+'\n'+xhr.responseText);
                }
            });
        }
    });
</script>
<div class="product-import-process-form">
    <h1>Импорт <?= $method == 'prices' ? 'цен' : 'данных'?> товаров</h1>
    <?= \yii\jui\ProgressBar::widget([
        'clientOptions' => [
            'value' => 100,
            'label' => ''
        ],
        'options' => [
            'id' => 'progressbar'
        ],
    ]);?>
    <ul id="process-result"></ul>
</div>