jquery.bsonbuilder

1.0.0 • Public • Published

BSON builder

This library helps to integrate a BSON builder using jQuery.

You can see this plugin in action: online demo.

Get started

You can download plugin files from the source repository: js/ sub-directory.

This plugin is also available as a NPM package: npm install jquery.bsonbuilder

Setup

$("selector").bsonBuilder(options)

Following options are available to setup BSON builder.

onLoad (function): Callback function which is given the container element and BSON document when BSON builder is loaded (e.g. {element: ..., bson: {}}).

supportsWildcard (boolean): Supports wildcard as BSON value.

containerDecorator (function): Decorator function, is called each time an .editor element is appended to either a document or array view. The given .editor allows user to update document properties or array items, and it's created with an input.child-name (optional, if editing document, to type the property name), a select.child-type (to choose the type of BSON value to be added) and a button (to validate the creation of new BSON value). These prepared child elements must not be .removed (use .detach instead if needed). The decorator function must return the decorated .editor element.

childDecorator (function): Decorator function, is called each time a .bson value element is added. The given .bson contains 3 button elements: .move-up (possibly disabled if already first), .move-down (possibly disabled if already last) or .remove. These prepared child elements must not be .removed (use .detach instead if needed). The decorator function must return the decorated .bson element.

showPropertyValueEditor (function): Configuration function which returns a callback function to be called with an .editor element (see containerDecorator option) and the type (string) of BSON value to edited. The returned function must itself return a form element to be used to edit the value; e.g. function(editor, typ){ return $('<input type="text" class="bson-value" />') } . The configuration function showPropertyValueEditor is called with the default callback (showPropertyValueEditor: function(defCall){ return defCall }).

hidePropertyValueEditor (function): Callback function called with an .editor element, to hide when necessary the value editor added by function returned by showPropertyValueEditor; e.g. function(editor){ $(".bson-value", editor).css({'display':"none"}) } .

Following types are those supported by editors of BSON values: document, array, boolean, datetime, double, float, integer, long, objectid, string.

Event

Each time the managed BSON is updated, a bson.change event is fired with following properties.

action: Either add, remove, move-up or move-down.

bson: The BSON root document, of following form.

{
  doc1:{
    _type:"document",
    val:{
      bool2:{
        _type:"boolean",
        val:false
      },
      double2:{
        _type:"double",
        val:1
      }
    }
  },
  arr1:{
    _type:"array",
    val:[
      {
        _type:"datetime",
        val:null
      },
      {
        _type:"integer",
        val:123
      },
      { _type:"wildcard" }
    ]
  },
   bool1:{
    _type:"boolean",
     val:true
  },
  date1:{
    _type:"datetime",
    val:(new Date(1420156800000))
  },
  double1:{
    _type:"double",
    val:1.23
  },
  float1:{
    _type:"float",
    val:2.34
  },
  long1:{
    _type:"long",
    val:12345
  },
  oid1:{
    _type:"objectid",
    val:4321
  },
  str1:{
    _type:"string",
    val:"a_value"
  }
}

change: Data updated in the BSON: {'bson': changedPart, 'parent': changeParent, 'element': changeElement}. The bson sub-property is of form {_type:..., val:...} (see the formats of BSON values in previous example of root document).

Readme

Keywords

Package Sidebar

Install

npm i jquery.bsonbuilder

Weekly Downloads

2

Version

1.0.0

License

GPL-3.0

Last publish

Collaborators

  • cchantep