Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 31a2bb94

Přidáno uživatelem Ondřej Anděl před téměř 4 roky(ů)

Feature #8509 Ovládání pro stránkování výsledků

Zobrazit rozdíly:

application/view/searchContent.php
1 1
<script>
2
    let pageIndex = 0;
3
    let itemPerPage = 50;
4
    let itemCount = 0;
5
    let pageCount = 0;
6

  
7

  
8
    //what to do when page renders
2 9
    window.onload = function() {
3 10
        let sourceSelect = new vanillaSelectBox("#source");
4 11
        filtersChange();
5 12
        fetchData(false);
13

  
14
        //page-label listener
15
        document.getElementById('page-label').addEventListener('keyup',function(e){
16
            if (e.key === 'Enter' || e.keyCode === 13) {
17
                this.blur();
18
            }
19
        });
6 20
    };
7 21
</script>
8 22

  
......
393 407
        </div>
394 408

  
395 409
        <!-- send button-->
396
        <button class="ml-auto btn" onclick="fetchData(true)">
410
        <button class="ml-auto btn" onclick="callFilter()">
397 411
            Filtrovat
398 412
        </button>
399 413
    </div>
......
413 427
        <tbody id="search-table">
414 428
            <script>
415 429
                let data;
430
                function callFilter() {
431
                    pageIndex = 0;
432
                    fetchData(true)
433
                }
434

  
416 435
                function filterData (formData) {
417 436
                    //regular
418 437
                    formData.append("lemma", document.getElementById("lemma").value);
......
454 473
                function fetchData (filter = true) {
455 474
                    // (A1) GET SEARCH TERM
456 475
                    const formData = new FormData();
457
                    formData.append("page", "0");//TODO PAGING
458
                    formData.append("items_per_page", "50");//TODO PAGING
476
                    formData.append("page", ""+pageIndex);
477
                    formData.append("items_per_page", ""+itemPerPage);
459 478
                    formData.append("finished", "true");//TODO ADMIN
460 479

  
461 480
                    if(filter){
......
470 489
                        let parsedJSON = JSON.parse(search);
471 490
                        if(parsedJSON.count === 0){
472 491
                            document.getElementById("no-data-label").style.display = "";
492
                            document.getElementById("paging-control").style.display = "none";
473 493
                        } else {
474 494
                            document.getElementById("no-data-label").style.display = "none";
495
                            document.getElementById("paging-control").style.display = "";
475 496
                        }
497
                        itemCount = parsedJSON.count;
498
                        pageCount = Math.ceil(itemCount / itemPerPage);
499
                        document.getElementById("page-label").value = (pageIndex + 1) + " / " + pageCount;
476 500
                        data = parsedJSON.data;
477 501
                        renderData(parsedJSON.data);
478 502
                    };
......
534 558
    </table>
535 559

  
536 560
    <h3 id="no-data-label" class="mx-auto text-center font-italic">Žádná data nebyla nalezena</h3>
561

  
562
    <script>
563
        function moveToFirst(){
564
            pageIndex = 0;
565
            fetchData(true);
566
        }
567

  
568
        function moveToPrevious(){
569
            pageIndex = (pageIndex - 1 > 0) ? (pageIndex - 1) : (0);
570
            fetchData(true);
571
        }
572

  
573
        function moveToNext(){
574
            pageIndex = (pageIndex + 1 < pageCount) ? (pageIndex + 1) : (pageCount - 1);
575
            fetchData(true);
576
        }
577

  
578
        function moveToLast(){
579
            pageIndex = pageCount - 1;
580
            fetchData(true);
581
        }
582

  
583
        function onManualPageStart(element){
584
            element.value = '';
585
        }
586

  
587
        function onManualPageEnd(element) {
588
            const value = Number(element.value) - 1;
589
            if(Number.isInteger(value) && value >= 0 && value < pageCount){
590
                pageIndex = value;
591
                fetchData(true);
592
            } else {
593
                element.value = (pageIndex + 1) + " / " + pageCount;
594
            }
595

  
596
        }
597
    </script>
598
    <div id="paging-control" class="mx-auto text-center" style="display: none">
599
        <button class="border-0 shadow-none bg-transparent" onclick="moveToFirst()"><b><<</b></button>
600
        <button class="border-0 shadow-none bg-transparent"  onclick="moveToPrevious()"><b><</b></button>
601
        <input class="border-0 shadow-none bg-transparent text-center font-weight-bold"
602
               id="page-label"
603
               onfocus="onManualPageStart(this)"
604
               onblur="onManualPageEnd(this)"
605
        />
606
        <button class="border-0 shadow-none bg-transparent"  onclick="moveToNext()"><b>></b></button>
607
        <button  class="border-0 shadow-none bg-transparent" onclick="moveToLast()"><b>>></b></button>
608
    </div>
537 609
</div>
538 610

  
539 611

  

Také k dispozici: Unified diff