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

Class: components.dt/js/spi/creators/PopupCreator

Interface describing a lightweight Popup Creator raising a popup window right after a view is created and added to a page, intended to modify the view's properties before the create process finishes.

Interface for creators that show a popup for entering basic component properties (data binding, type, field name, label) when new component is to be created.

The infrastructure first calls createView to create a view with default state and properties. When the view is created and added to the page getDropPopupController is called to obtain a DropPopupController instance. The infrastructure finally raises a popup with data provided by the returned DropPopupController. It's up to the implementor to ensure the view is properly updated with any modifications done inside the popup.

Even though ABCS by default raises a popup to customize the created view, the creator may be called through the Creator API by other creators to include the view into their own composed view hierarchy in which case the popup will not be opened and the creator (createView) is obliged to return a full working view based on the passed createContext containing the default properties. See the example below for demonstation.

You are obliged to implement:

Version:
  • 16.3.5
Source:
Examples

HTML markup for the popup

<div>
  <label for="componentdropCustomizer-label">Text</label>
  <input id="componentdropCustomizer-label" type="text"
      placeholder="Enter Text" data-bind="ojComponent: {
          component: 'ojInputText',
          value: text
  }">
</div>
<div>
  <button data-bind="ojComponent: {
      component: 'ojButton',
      label: 'Finish'
  }, click: finish">
  </button>
  <button data-bind="ojComponent: {
      component: 'ojButton',
      label: 'Cancel'
  }, click: cancel">
  </button>
</div>

How to use popup creators

define([
    'components.dt/js/spi/creators/CreatorType'
    'components.dt/js/spi/creators/DropPopupController',
    'text!mycomponent/templates/popup.html
], function (CreatorType, DropPopupController, popupMarkup) {

    'use strict';

    var MyCreator = function () {
        // constructor init
    };

    MyCreator.prototype.getType = function () {
        return CreatorType.POPUP;
    };

    MyCreator.prototype.createView = function (activePage, container, createContext) {
        // the method creates a default view with default properties.
        var componentFactory = ComponentFactory.create(activePage);
        // set the default view's property value
        var properties = {
            text: 'Default Text'
        };

        // the method should take createContext into account and fill as
        // many properties as possible to make the view complete because
        // when called through the Component Creator API the popup will
        // not be raised.
        if (createContext && createContext.text) {
            properties.text = createContext.text;
        }

        var view = componentFactory.createView({
            type: 'org.my.myComponent',
            properties: properties,
            displayName: 'My Component'
        });
        return view;
    };

    MyCreator.prototype.getDropPopupController = function (view) {
        // right after the view is created the infrastructure calls this method
        // to get an instance of DropPopupController providing the html markup,
        // view model and the callback implementation for the popup.
        var myPopupViewModel = this._createModel();
        var customizer = new MyCreator.MyDropCustomizer(view, myPopupViewModel);

        // create an instance of DropPopupController with required popup model and markup.
        var controller = new DropPopupController(myPopupViewModel, popupMarkup, customizer);

        // attach a finish handler to your model and dismiss the popup
        // when the model says so using an API finish method.
        myPopupViewModel.finishHandler = function (result) {
            controller.finish(result);
        };
        return controller;
    };

    MyCreator.prototype._createModel = function () {
        var model = {
            text: ko.observable(),
            finishHandler: undefined,
            finish: function () {
                this.finishHandler(true);
            },
            cancel: function () {
                this.finishHandler(false);
            }
        };
        return model;
    };

    MyCreator.prototype.getOptions = function () {
        return {
            // the creator is expected to create only one type of view: org.my.myComponent
            possibleGeneratedViewTypes: ['org.my.myComponent'],
            // min width of the component will be 2 columns
            minWidth: 2
        };
    };

    var MyDropCustomizer = function (view, model) {
        this._view = view;
        this._model = model;
    };

    MyDropCustomizer.prototype.opened = function () {
        // you can do something useful here
    };

    MyDropCustomizer.prototype.closed = function (accepted) {
        if (accepted) {
            // popup was accepted and closed, let's update view properties
            this._view.getProperties().setValue('text', this._model.text());
        }
        // do not forget to return a promise resolving to the view instance
        return Promise.resolve(this._view);
    };

    MyCreator.MyDropCustomizer = MyDropCustomizer;

    return MyCreator;

});

Extends

Methods

createView(activePage, container, createContext) → {pages.dt/js/api/View}

stable API

Creates a specific View for the component.

MUST be implemented.

The main purpose of this method is to create a full working instance of a View representing the top of your component hieararchy. You do not call its constructor directly but rather call the ComponentFactory.createView factory method taking care of lots of things for you.

See Creator for an example on how to implement this method.

Parameters:
Name Type Description
activePage pages.dt/js/api/Page

the current page the view is created for.

container pages.dt/js/api/View | undefined

parent container the view is about to be added into. May be undefined, when a standalone view is created, so do not heavily depend on it.

createContext Object

object with set of default properties used to create specific view instance with default properties or possibly even reconstruct an old view from a serialized context.

Version:
  • 16.3.5
Inherited From:
Source:
See:
Returns:

created View.

Type
pages.dt/js/api/View

getDropPopupController(view) → {components.dt/js/spi/creators/DropPopupController}

stable API

Creates and returns a DropPopupController instance for the PopupCreator implementation. DropPopupController is a class controlling the behavior of the opened popup modyfying the created view's properties during the view create process. See PopupCreator for an example on how to implement this method.

Must be overridden and implemented in descendants.

Parameters:
Name Type Description
view pages.dt/js/api/View

created view to be customized.

Version:
  • 16.3.5
Source:
Returns:

DropPopupController instance

Type
components.dt/js/spi/creators/DropPopupController

getOptions() → {components.dt/js/spi/creators/Creator.CreatorOptions}

stable API

Get the options which will be used by designer infrastructure.

Version:
  • 16.3.5
Inherited From:
Source:
Returns:
Type
components.dt/js/spi/creators/Creator.CreatorOptions

getType() → {components.dt/js/spi/creators/CreatorType}

stable API

Specifies the type of the creator.

Popup creators must return CreatorType.POPUP type.

Version:
  • 16.3.5
Overrides:
Source:
Returns:

creator type

Type
components.dt/js/spi/creators/CreatorType