nmodule/webEditors/rc/fe/feDialogs

Functions for showing field editors in modal dialogs. Useful for prompting
the user to enter values, edit individual slots, and fire actions.

Description:
  • Functions for showing field editors in modal dialogs. Useful for prompting
    the user to enter values, edit individual slots, and fire actions.

Source:

Methods

(static) action(params) → {Promise}

Description:
  • Invoke an action on a mounted component. If the action requires a
    parameter, a field editor dialog will be shown to retrieve that argument
    from the user.

Source:
Parameters:
Name Type Description
params Object
Properties
Name Type Attributes Description
component baja.Component

the component on which to invoke
the action. Must be mounted.

slot String | baja.Slot

the action slot to invoke. Must be
a valid Action slot.

actionArgument baja.Value <optional>

Starting in Niagara 4.10, this
action argument can be used instead of showing a dialog to obtain
the argument.

Returns:

promise to be resolved with the action return
value if the action was successfully invoked, resolved with null if
the user clicked Cancel, or rejected if the parameters were invalid or the
action could not be invoked.

Type
Promise

(static) error(err, paramsopt) → {Promise}

Description:
  • Show details about an error.

Source:
Parameters:
Name Type Attributes Description
err Error | *
params Object <optional>
Properties
Name Type Attributes Description
title String <optional>
command module:bajaux/commands/Command <optional>

An optional Command to help display information on which Command failed

messageSummary String <optional>

An optional messageSummary to prepend to the Error.

Returns:
Type
Promise

(static) props(props, paramsopt) → {Promise.<(object|null)>}

Description:
  • A simple mechanism for editing multiple properties at once.

Source:
Since:
  • Niagara 4.14
Examples

Edit a simple key->value map.

return feDialogs.props({ foo: 'bar' }); // resolves an object with user-edited "foo" property

Edit a nested key->value map.

return feDialogs.props({
  user: { value: { firstName: 'Moe', lastName: 'Howard' } }
}); // resolves an object with a "user" property containing user-editor "firstName" and "lastName"

Specify display name

return feDialogs.props({
  foo: { displayName: 'Your foo value', value: 'bar' }
}); // resolves an object with user-entered "foo" property, but user was shown customized display name

Use display name from lexicon

return feDialogs.props({
  overrideValue: { displayName: '%lexicon(control:override.value)%', value: 0 }
}); // resolves an object with user-entered "overrideValue" property but user was shown "Override Value" from lexicon

Specify flags

return feDialogs.props({
  hidden: { value: 'hiddenValue', hidden: true },
  readonly: { value: 'readonlyValue', readonly: true }
}); // resolves an object with "hidden" and "readonly" values. User did not see "hidden" and was not able to edit "readonly".

Specify properties

return feDialogs.props({
  percent: { value: 0, properties: { min: 0, max: 100 } }
}); // resolves an object with "percent" value. Editor was validated to be between 0 and 100.

Edit a Complex directly

const comp = baja.$('control:NumericWritable');
return feDialogs.props(comp); // please note that the input Complex will be *saved* when the user clicks OK

Specify title and summary

return feDialogs.props({ foo: 'bar' }, {
  title: 'Foo Dialog',
  summary: 'Please enter your foo value'
});
Parameters:
Name Type Attributes Description
props Object.<string, (baja.Value|object)> | baja.Complex

a JSON object representing the
properties to edit. May be nested. You can also simply pass a Complex to edit the slots of
that Complex. See examples.

params object <optional>
Properties
Name Type Attributes Description
ordBase baja.Component <optional>

if field editors may need to resolve ORDs themselves,
pass ordBase to allow them to successfully resolve ORDs even when offline.

title string <optional>

optional dialog title

summary string <optional>

optional summary details for dialog

validate function <optional>

optional validation function to ensure that the entered
value is valid. If the user enters an invalid value, the OK button will be disabled. This
function should throw an Error, return a rejected Promise, or return or resolve false to fail
validation. It will receive a JSON object or a Complex, depending on what was passed as the
props argument.

Returns:

the newly entered values, or null if user clicked Cancel

Type
Promise.<(object|null)>

(static) selfClosing(params) → {Promise}

Description:
  • Show an editor in a dialog, similar to showFor, but with the added
    expectation that the editor represents a one-time interaction, like a
    button click, after which the dialog can be immediately closed. In other
    words, the "click ok to close" functionality is embedded in the editor
    itself. Only a Cancel button will be shown in the dialog itself.

    In order for the dialog to close, the shown editor must trigger a
    feDialogs.VALUE_READY_EVENT, optionally with a read value. When this
    event is triggered, the dialog will be closed and the promise resolved
    with the value passed to the event trigger.

Source:
Example

Trigger a VALUE_READY_EVENT to cause the dialog to be closed.

// ...
MyEditor.prototype.doInitialize = function (dom) {
  dom.on('click', 'button', function () {
    dom.trigger(feDialogs.VALUE_READY_EVENT, [ 'my value' ]);
  });
};
//...

feDialogs.selfClosing({
  type: MyEditor
}}
  .then(function (value) {
    if (value === 'my value') {
      //success!
    }
  });
Parameters:
Name Type Description
params Object

params to be passed to fe.buildFor

Properties
Name Type Attributes Default Description
title String <optional>

title for the dialog

delay Number <optional>
200

delay in ms to wait before showing a
loading spinner. The spinner will disappear when the field editor has
finished initializing and loading.

progressCallback function <optional>

pass a progress callback to
receive notifications as the editor being shown goes through the stages
of its life cycle (created, initialized, loaded).

Returns:

promise to be resolved when the editor has
triggered its own value event. It will be resolved with any value passed
to the event trigger, or with null if Cancel was clicked.

Type
Promise

(static) showFor(params) → {Promise}

Description:
  • Shows a field editor in a dialog.

    When the user clicks OK, the editor will be saved, committing any changes.
    The value that the user entered will be read from the editor and used to
    resolve the promise.

Source:
Examples
feDialogs.showFor({
    value: 'enter a string here (max 50 chars)',
    properties: { max: 50 },
    progressCallback: function (msg, arg) {
      switch(msg) {
      case 'created':     return console.log('editor created', arg);
      case 'initialized': return console.log('editor initialized', arg.jq());
      case 'loaded':      return console.log('editor loaded', arg.value());
      case 'invalid':     return console.log('validation error', arg);
      case 'valid':       return console.log('value is valid', arg);
      }
    }
  })
  .then(function (str) {
    if (str === null) {
      console.log('you clicked cancel');
    } else {
      console.log('you entered: ' + str);
    }
  });

Specify custom button handlers. If the user clicks one of these custom buttons, the showFor promise will be resolved with the value resolved by its handler.

feDialogs.showFor({
  value: 'enter a string',
  buttons: [ {
    name: 'uppercase',
    displayName: 'Uppercase It',
    handler: (dialog, event, editor) {
      // the arguments to the button handler are: the Dialog instance, the click event,
      // and the editor being shown in the dialog.
      // call `dialog.keepOpen` if you are not ready for the dialog to close. the dialog will
      // stay open and the promise will not be resolved yet.

      dialog.keepOpen();
      return editor.read().then((string) => editor.load(string.toUpperCase());
    }
  }, {
    name: 'lowercase',
    displayName: 'Lowercase It',
    handler: (dialog, event, editor) {
      dialog.keepOpen();
      return editor.read().then((string) => editor.load(string.toLowerCase()));
    }
  }, {
    // default 'ok' behavior is to read the value and resolve the promise. you don't have to
    // specify a handler to do this.
    name: 'ok'
  } ]
});

The strings 'ok', 'cancel', 'yes', and 'no' are special - you can include them in the buttons parameter to get their default behavior.

// only show the OK button, and resolve the promise with the entered value. 'yes' works the same.
feDialogs.showFor({ value: 'enter a string', buttons: [ 'ok' ] });

// only show the Cancel button, and resolve the promise with null. 'no' works the same.
feDialogs.showFor({ value: 'your changes will not be used', buttons: [ 'cancel' ] });

The buttons parameter can be an object literal, where the values are button definitions or handler functions.

feDialogs.showFor({
  value: 'Value to Edit',
  buttons: {
    ok: () => 'my custom ok result', // the value can be just a handler function. the default display name will be used.
    cancel: {
      displayName: "Never Mind"
      // omit the handler, and default handler for "cancel" will resolve null.
    },
    yes: {}, // just an empty object will use the default display name and default handler.
    no: {
      handler: () => 'user clicked "no"' // include a handler to override the default handler.
    },
    delete: {
      // for anything other than 'ok', 'cancel', 'yes', or 'no', you'll need to provide a
      // display name - or else just the button name will be used.
      displayName: 'Delete Everything',
      handler: () => deleteEverything()
    },
    retry: shouldShowRetryButton() && { // falsy values will cause the button _not_ to be shown.
      displayName: 'Try Again',
      handler: () => letUserTryAgain()
    }
  }
});

Use the 'on' parameter to respond to any bajaux events that are triggered by the editor.

const { MODIFY_EVENT } = events;
feDialogs.showFor({
  value: 'edit me',
  properties: { max: 10 },
  on: {
    [MODIFY_EVENT]: (dialog, event, editor) {
      return editor.validate()
        .catch(() => alert('no more than 10 characters pls'));
    }
  }
});
Parameters:
Name Type Description
params Object

params to be passed to fe.buildFor().

Properties
Name Type Attributes Default Description
dom jQuery <optional>

if your widget type should be instantiated
into a specific kind of DOM element, it can be passed in as a parameter.
Note that the given element will be appended to the dialog element itself,
so do not pass in an element that is already parented. If omitted, a div
will be created and used.

title String <optional>

title for the dialog

summary String <optional>

(since Niagara 4.14) provide this to display a more detailed
textual description about this prompt, e.g.: a description of its purpose, instructions on how
to use the editor shown, any additional information the user may want.

delay Number <optional>
200

delay in ms to wait before showing a
loading spinner. The spinner will disappear when the field editor has
finished initializing and loading.

save boolean <optional>

set to false to specify that the dialog
should not be saved on clicking OK - only the current value will be read
from the editor and used to resolve the promise.

onSaveError function <optional>

when this function is set and save
is set to true, the error will be handed off to this method. Otherwise,
when save is true feDialogs will show whatever error caused by the save in
a different dialog. This may optionally return a promise.

progressCallback function <optional>

pass a progress callback to
receive notifications as the editor being shown goes through the stages
of its life cycle (created, initialized, loaded), as well as whenever
the editor is validated (invalid, valid).

buttons Array.<(module:dialogs~Button|string)> <optional>

as of Niagara 4.12,
custom buttons can be specified. See examples for details.

on Object.<string, function()> <optional>

as of Niagara 4.12, custom handlers for
bajaux events (and only bajaux events) can be specified. This is an object literal
where the keys are bajaux event names and the values are event handler functions.
See examples for details.

validate function <optional>

as of Niagara 4.14, specify a custom validate function
to ensure that the entered value is valid. If the user enters an invalid value, the OK button
will be disabled. This function should throw an Error, return a rejected Promise, or return or
resolve false to fail validation.

Returns:

promise to be resolved when the user has entered
a value into the field editor and clicked OK, or rejected if the field
could not be read. The promise will be resolved with the value that the
user entered (or null if Cancel was clicked).

Type
Promise