Class: NotificationSelector

NotificationSelector

new NotificationSelector(args)

Select details for various levels of notification

User notes should always be updated with the contents of a notification action, but sometimes we want to do that in a separate action. When 'note_title_variable' and 'note_bbcode_variable' are not passed, the action will always succeed. You are expected to write a later action that checks 'notification result' and returns appropriately.
Name Type Description
args Object notification arguments
Example
var notification = new NotificationSelector({

    // default values (can be changed with val()):
    level               : 'none', // or 'post' or 'PM' or 'warning' or 'infraction'
    namespace           : 'variables namespace', // namespace to retrieve variables from
    violation           : 'default violation', // string, numeric ID or object
    keys                : {...}, // keys to use when resolving variables
          title_variable: 'Title variable', // variable to use for post/PM title or infraction reason
            ban_variable: 'Ban reason variable', // variable to use for reason to ban an account
         bbcode_variable: 'BBCode variable', // variable to use for BBCode
     note_title_variable: 'User note title variable', // variable to use for user note title
    note_bbcode_variable: 'User note BBCode variable', // variable to use for user note BBCode
    // these two usually aren't used:
    // title : 'initial text for post/PM title',
    // bbcode: 'initial text for BBCode',
    show_violations     : false, // show the "violation" dropdown (default: true)

    // other data needed for the selector to function:
    user            : { username: ..., user_id: ... }, // user to apply action to
    v               : variables, // Variables object
    bb              : bb, // BulletinBoard object
    violation_groups: [{ name: '...', violations: [v1,v2,...]},...], // list of violations to display
    thread_id       : 12345, // post goes here, variables and previews will be calculated as if rendered in this thread
    thread_desc     : 'name of thread (passed to Action)',
    loading_html    : 'Loading, please wait...', // shown while the preview is updated
    callback        : function(keys) { ... }, // called with the current data
    container       : notification_appended_to_this,
    key_prefix      : 'string appended to all keys returned from the action', // default: 'notification '
    known_keys      : [ 'key name', ... ], // keys that should not trigger the 'curly brackets detected' warning

});

Extends

Methods

Action built by this selector

Returns:
Type Description
Action

add known keys that will be inserted immediately before the notification is sent

Name Type Description
keys Object keys to insert

element where you can put "extra" actions

Sometimes it's useful to place another widget inside this one (e.g. an extra action to fire at the same time). This element is a place to put such widgets
Returns:
Type Description
jQuery

Get/set the box's current notification mode

Name Type Description
mode string optional 'edit' or 'preview'
Returns:
Type Description
string (new) mode

Mode-switching button

this bit of sugar provides a "mode switch" button for the widget
Returns:
Type Description
jQuery

inherited reset_value(current_value, name){string}

Update the "reset" data and get a stored value

this should be called by a "reset" button, to reset the contents of an input to a recent value
Name Type Description
current_value string current value as entered by the user (which we can reset to)
name string variable name
Returns:
Type Description
string new value

inherited resolve_value(name, name_suffix, keys, parser, value)

Resolve one of the values defined in the constructor

Name Type Description
name string variable name
name_suffix string array appended to variable name during resolution
keys Object optional keys to use when resolving
parser string optional how to parse the variable
value string | null (if defined) or null (otherwise)

inherited set_value(current_value, name, name_suffix, keys, parser, new)

Update the "reset" data and get a new value (if changed)

Name Type Description
current_value string current value as entered by the user (which we can reset to)
name string variable name
name_suffix string array appended to variable name during resolution
keys Object optional keys to use when resolving
parser string optional how to parse the variable
new string optional value (if defined and in need of an update)

inherited update_previous_values()

Specify new values for reset_value()

records values from this.val(), will return them on reset

Get/set widget's values

Note: In the return object, 'violation' will be set to the current violation object (not the default string), and 'title' and 'bbcode' will be set to the current strings. Values remain unchanged if they aren't passed (no need to pass 'namespace' each time)
Name Type Description
value Object new value
Returns:
Type Description
Object (new) value
Example
ns.val({
    level          : 'none', // or 'post' || 'PM' or 'warning' or 'infraction'
    namespace      : 'variables namespace', // namespace to retrieve variables from
    bbcode_variable: 'BBCode variable', // variable to use for BBCode
    ban_variable   : 'Ban reason variable', // variable to use for reason to ban an account
    title_variable : 'Title variable', // variable to use for post/PM title
    keys           : {...}, // keys to use when resolving variables
    violation      : 'default violation', // string, numeric ID or object
    // these two usually aren't used:
    // title  : 'initial text for post/PM title',
    // bbcode : 'initial text for BBCode',
    data           : ..., arbitrary data used by the calling code
});