JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Source: bop/js/api/operation/Pagination.js

define([], function() {

    'use strict';

    /**
     * An API object allowing client to describe what exact type of pagination is his {@link bop/js/spi/BOP BOP} able to handle.
     *
     * <p>
     * Currently it's possible to only disable/enable pagination but in the future, Application Builder will introduce more complex mechanisms to define various combinations of
     * pagination.
     * </p>
     *
     * @AbcsExtension stable
     * @version 17.1.1
     * @exports bop/js/api/operation/Pagination
     *
     * @constructor
     * @private
     *
     * @param {Object} params - Object literal with all possible parameters.
     * @param {Boolean} params.paginates - flag that shows whether this <code>Pagination</code> instance even paginates or not.
     * @param {Boolean} params.totalResults - flag that shows whether this <code>Pagination</code> supports total result feature or not.
     */
    var Pagination = function(params) {
        this._paginates = params.paginates;
        this._totalResults = params.totalResults;
    };

    Pagination.prototype.isSupported = function() {
        return this !== Pagination.NONE;
    };

    /**
     * Checks whether this <code>Pagination</code> instance supports total result feature or not.
     *
     * @returns {Boolean}
     */
    Pagination.prototype.isTotalResultSupported = function() {
        return this._totalResults === true;
    };

    /**
     * Represents unsupported pagination.
     *
     * <p>
     * Either use this option in {@link bop/js/api/operation/OperationBuilder#paginates OperationBuilder.paginates(..)} method or don’t call the {@link bop/js/api/operation/OperationBuilder#paginates OperationBuilder.paginates(..)}
     * method at all in case your {@link operation/js/api/Operation Operation} doesn't provide any kind of pagination support.
     * </p>
     *
     * @AbcsExtension stable
     * @type bop/js/api/operation/Pagination
     * @version 17.1.1
     */
    Pagination.NONE = new Pagination({
        paginates: false
    });

    /**
     * Represents standard type of pagination that supports:
     *
     * <ul>
     *  <li>
     *      Previous/Next page buttons.
     *  </li>
     *  <li>
     *      First/Last page buttons.
     *  </li>
     *  <li>
     *      Jumping between pages using page navigation.
     *  </li>
     *  <li>
     *      Direct navigation to few pages before and after the current page.
     *  </li>
     * </ul>
     *
     * @AbcsExtension stable
     * @type bop/js/api/operation/Pagination
     * @version 17.1.1
     */
    Pagination.STANDARD = new Pagination({
        paginates: true
    });

    /**
     * Expand the described functionality of this <code>Pagination</code> instance with an ability to return also Total Results together with the paginated data.
     *
     * @returns {bop/js/api/operation/Pagination} a reference to this object to allow method chaining
     */
    Pagination.prototype.totalResults = function() {
        // In order not to change the original constant, we need to make a clone and set the additional value separately
        // Although this isn't cleanest at the moment, it in fact improves the coding experience as client don't need to
        // make an explicit build(..) call
        return new Pagination({
            paginates: this._paginates,
            totalResults: true
        });
    };

    return Pagination;

});