Input anchor and page/range

Provide input control of anchor and page/range along with dynamic call out of the currently selected values.

HTML

<script src="https://mobiledemo.jaspersoft.com/jasperserver-pro/client/visualize.js"></script>

<div style="font-size: 11pt">Enter page number or range or use predefined values to narrow down search in report.</div>
<div style="font-size: 9pt">Default bookmark: "Newton".</div>
<!--Find bookmark: <input type="text" id="anchor"/>-->
Find page/range: <input type="text" id="page"/>
<br><br>
<div style="font-size: 11pt">Or select from a predefined:</div>
<button id="range">View pages 20-30 with bookmark "Everett"</button>
<button id="showCurrentLocation">Show current location</button>
<br><br>
<div id="container"></div>

CSS

#container {
    height: 400px;
    overflow-y: scroll;
    width: 100%;
}

JavaScript

visualize({
    auth: {
        name: "joeuser",
        password: "joeuser",
        organization: "organization_1"
    }
}, function (v) {

    var report = v.report({
        resource: "/public/Samples/Reports/AllAccounts",
        container: "#container",
        pages: {
            anchor: "Newton"
        },
        events: {
            changePagesState: function(currentPage) {
                console.log("changeCurrentPage", currentPage);
            }
        },
        error: function(e) {
            alert(e);
        }
    });
    
    $("#showCurrentLocation").on("click", function() {
        alert(JSON.stringify(report.pages()));
    });
    
    $("#anchor").on("change", function() {
        report
            .pages({ anchor: $(this).val() })
            .run()
            .fail(function(e) { console.log(report.pages()); alert(e); });
    });
    
    $("#page").on("change", function() {
        report
            .pages({ pages: $(this).val() })
            .run()
            .fail(function(e) { console.log(report.pages()); alert(e); });
    });
    
    $("#range").on("click", function() {
        report.properties({
            pages: {
                pages: "20-30",
                anchor: "Everett"
            }
        }).run().fail(function(e) { console.log(report.pages());  alert(e); });
    });
});