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

Source: components.dt/js/spi/deleters/Deleter.js

define([
    'components.dt/js/spi/deleters/DeleterType'
], function(
        DeleterType
        ) {

    'use strict';

    /**
     * A deleter is used to cleanup artifacts generated by {@link components.dt/js/spi/creators/Creator Creator}.
     * It is plugged-in into the Abcs system using the registration API
     * ({@link components.dt/js/api/ComponentProviderRegistry ComponentProviderRegistry}).
     *
     * <p>The deleter by default doesn't raise any UI dialog for confirming the component
     * deletion. In order to bring-up any confirmation you need to implement that into
     * the <code>cleanup</code> method and fullfil the Promise with the result of the
     * user decision then. See example below.
     *
     * <p><strong>Don’t care about the deletion of the view from its parent.</strong> That
     * is the responsibility of the Abcs infractructure itself and is done automatically.</p>
     *
     * <p>In order to add a deleter for a new component type create an object with methods
     * described by {@link components.dt/js/spi/deleters/Deleter Deleter}. The object must
     * implement {@link components.dt/js/spi/deleters/Deleter#cleanup Deleter.cleanup} method
     * to clean the page or confirm the deletion process and
     * {@link components.dt/js/spi/deleters/Deleter#getType Deleter.getType} to specify the
     * type of the deleter.</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     *
     * @private
     * @exports components.dt/js/spi/deleters/Deleter
     * @constructor
     * @see {@link components.dt/js/spi/deleters/Deleter#cleanup Deleter.cleanup}
     * @example
     * <caption>Example of a view's deleter with confirmation dialog</caption>
     * define([
     *     'components.dt/js/spi/deleters/DeleterType'
     * ], function (DeleterType) {
     *
     *     'use strict';
     *
     *     var MyDeleter = function () {
     *     };
     *
     *     MyDeleter.prototype.cleanup = function (view, page) {
     *         var self = this;
     *         return new Promise(function(fulfil) {
     *             var dialogClosedListener = ko.observable(false);
     *             var confirmation = MyDeleter.createConfirmationDialog(dialogClosedListener);
     *             dialogClosedListener.subscribe(function() {
     *                 var accepted = confirmation.isAccepted();
     *
     *                 if (accepted) {
     *                     // deletion is accepted, perform the cleanup
     *                     self._cleanArtefacts();
     *                 }
     *
     *                 fulfil(accepted);
     *             });
     *             confirmation.showDialog();
     *         });
     *     };
     *
     *     MyDeleter.prototype.getType = function () {
     *         return DeleterType.CLEANUP;
     *     };
     *
     *     MyDeleter.prototype._cleanArtefacts = function () {
     *         // do all clean-up work
     *     };
     *
     *     MyDeleter.createConfirmationDialog = function (dialogClosedListener) {
     *         return {
     *             isAccepted: function() {
     *                 // implement the method and return the user answer to deletion dialog
     *             },
     *             showDialog: function() {
     *                 // invoke the the confirmation dialog
     *                 // call "dialogClosedListener(true);" once the dialog is closed
     *             }
     *         }
     *     };
     *
     *     ...
     *
     *     return MyDeleter;
     *
     * });
     */
    var Deleter = function() {
        AbcsLib.checkThis(this);
    };

    /**
     * Cleans the {@link pages.dt/js/api/View View} and the {@link pages.dt/js/api/Page Page} of artefacts generated
     * originally by the component's {@link components.dt/js/spi/creators/Creator Creator}.
     *
     * @AbcsExtension stable
     * @version 16.3.5
     *
     * @param {pages.dt/js/api/View} view top view container to be deleted
     * @param {pages.dt/js/api/Page} page the page owning the view in its hierarchy
     * @returns {Promise<Boolean>} Promise which fulfills before the view deletion is called; if the Promise fulfills
     *                             with another value than <code>true</code>, the deletion process is interrupted and
     *                             the view remains. The same happens if the Promise is rejected (in that case the
     *                             reject's argument is printed as warning into the console).
     *
     * @see {@link components.dt/js/spi/deleters/Deleter Deleter} for an example on how to implement the method
     */
    Deleter.prototype.cleanup = function(/*view, page*/) {
        return Promise.resolve(true);
    };

    /**
     * Specifies the type of the deleter.
     * <p>Every deleter must specify its type. The only publicly supported
     * deleter is the <code>DeleterType.CLEANUP</code> now. Any custom deleter must return
     * {@link components.dt/js/spi/deleters/DeleterType.CLEANUP DeleterType.CLEANUP} type.</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     *
     * @returns {components.dt/js/spi/deleters/DeleterType} deleter type
     */
    Deleter.prototype.getType = function () {
        return DeleterType.CLEANUP;
    };

    return Deleter;

});