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

Source: components.dt/js/spi/creators/DropPopupController.js

define([
    'core/js/api/Listenable'
], function (
        Listenable
        ) {

    'use strict';

    /**
     * Final drop popup controller class.
     *
     * Drop popup controller is a controller for the popup displayed when a {@link components.dt/js/spi/creators/PopupCreator PopupCreator}
     * constructs a view and adds it into the page. The PopupCreator uses the
     * popup to modify the default created view with user's input.
     * <p>It is up to the specific creator to provide an instance of DropPopupController
     * with a proper popup markup and model that updates the view's properties.</p>
     * <p>The infrastructure raises a popup with the content (HTML markup and view model)
     * passed as constructor arguments and informs about the popup state through
     * a callback instance passed as the third parameter.</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     * @exports components.dt/js/spi/creators/DropPopupController
     * @constructor
     * @param {Object} model view model part of the popup. Pass any object you use
     * as your view model.
     * @param {String} markup HTML markup part of the popup internals. The markup
     * should include accept and cancel buttons (popup footer) as these are not
     * added by the infrastructure.
     * @param {components.dt/js/spi/creators/DropPopupController.DropCustomizer} dropCustomizer object providing callback methods called when the
     * popup state changes.
     * @returns {components.dt/js/spi/creators/DropPopupController} DropPopupController instance
     * @see {@link components.dt/js/spi/creators/PopupCreator PopupCreator} for an example
     */
    var DropPopupController = function (model, markup, dropCustomizer) {
        AbcsLib.checkDefined(model, 'model');
        AbcsLib.checkDefined(markup, 'markup');
        if (!markup) {
            throw new Error('Variable "markup" must not be empty!');
        }
        AbcsLib.checkDefined(dropCustomizer, 'dropCustomizer');
        AbcsLib.checkThis(this);
        Listenable.call(this);
        this._viewModel = model;
        this._markup = markup;
        this._dropCustomizer = dropCustomizer;
    };

    AbcsLib.mixin(DropPopupController, Listenable);

    /**
     * Fired when the customizer is about to close.
     * @constant
     */
    DropPopupController.EVENT_CLOSE = 'close';

    /**
     * Called when the popup with the customizer is opened.
     */
    DropPopupController.prototype.open = function () {
        if (typeof this._dropCustomizer.opened === 'function') {
            this._dropCustomizer.opened();
        }
    };

    /**
     * Closes the popup from inside a drop customizer implementation. This
     * usually happens when user clicks on a cancel or finish button.
     *
     * <p>Popup creators will call this method on their own when their popup
     * is to be closed (canceled or finished).</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     * @param {Boolean} accepted flag indicating if the popup was accepted or
     * canceled and dismissed by user.
     */
    DropPopupController.prototype.finish = function (accepted) {
        AbcsLib.checkParameterCount(arguments, 1);
        AbcsLib.checkDefined(accepted, 'accepted');
        this.fireEvent(DropPopupController.EVENT_CLOSE, accepted);
    };

    /**
     * Called when the popup is closing.
     * @param {View} view
     * @param {Boolean} finished success/cancel flag
     */
    DropPopupController.prototype.close = function (view, finished) {
        var result = this._dropCustomizer.closed(finished);
        return result;
    };

    /**
     */
    DropPopupController.prototype.getViewModel = function () {
        return this._viewModel;
    };

    /**
     */
    DropPopupController.prototype.getMarkup = function () {
        return this._markup;
    };

    /**
     * An object providing methods called when a popup state changes,
     * when the popup is opened and painted or closed and dismissed.
     *
     * @AbcsExtension stable
     * @version 16.3.5
     * @memberof components.dt/js/spi/creators/DropPopupController
     * @see {@link components.dt/js/spi/creators/DropPopupController DropPopupController}
     * @objectLiteral
     */
    var DropCustomizer = function () {
    };

    /**
     * Called when the popup is opened and rendered.
     * <p>You may want to do some init logic here such as setting focus to
     * preferred input fields etc.</p>
     * @AbcsExtension stable
     * @version 16.3.5
     */
    DropCustomizer.prototype.opened = function () {
    };

    /**
     * Called when the popup is closed and dismissed.
     * <p><strong>Must be implemented in descendants.</strong></p>
     * <p>You may want to do some cleanup or update the view's properties
     * here depending on the <code>accepted</code> parameter.</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     * @param {Booolean} accepted flag indicating if the popup was accepted or
     * canceled by user.
     * @return {Promise} a promise resolved to the final {@link pages.dt/js/api/View view}.
     * Some drop customizers may completely exchange the previously created view
     * for a new one. When that happens resolve the promise with the new view
     * instance.
     */
    DropCustomizer.prototype.closed = function (/*accepted*/) {
    };

    return DropPopupController;
});