aCelery

Create your own App

xScript

xScript

The xScript framework is made of four parts:

  1. Base classes and plain UI object classes that do not use Bootstrap.
  2. UI classes that implement Bootstrap UI elements.
  3. CRUD framework.
  4. Android interface classes.

All object methods that do not return some other value return a reference to the same object (this). Allowing a shorter chained style of writing. Example:

var section = new xSection()
                  .addElement(new xbButton("button1"))
                  .addElement(new xbButton("button2"))
                  .addElement(new xbStringInput("Label","name"));

UI objects are divided in two: simple objects, and objects that can contain other UI objects. You build your app's user interface by adding objects to containing objects, and these in turn to other containing objects until you reach the top level. By this method you, for example, can create a panel, to which you add some input fields, and a button group, to which you then add some buttons.

Please note that for the sake of completness all classes and methods are documented, however most are the "internal piping" and you will probably never need to use them unless you want to derive your own classes from them.


xScript Classes Reference

Base Classes

xElement

Abstract class, base for all other UI classes. all xElement objects will be assigned on construction a unique random ID which can be used to identify the object in the document's DOM.

Constructor xElement(clss)

clss Class to assign to the element, if none given the default "x_element" class will be used.

genUID()

returns a random unique ID

setParent(parent)

assigns the parent of the xElement.

parent The parent element to assign.

setClass(clss)

assigns the class of the xElement.

clss Class to assign

getId()

returns the ID of the xElement.

getHashId()

returns the ID of the xElement with a preceding # this is useful if you want to manipulate the xElement with jquery i.e $(myElement.getHashId())

getNode()

returns the DOM node for the xElement.

remove()

removes itself from its parent.

removeNode()

remove the xElement's node from its DOM parent

removeElement()

Does nothing here, redefinable by other subclasses

setToTop()

Appends the xElement to the top level document.body

append(parentNode)

Appends the xElement's DOM node to it's parent element's DOM node.

parentNode node to which the xElement's node will be appended.

hide()

Hides the xElement

show()

Shows the xElement

bindToEvent(type, function)

binds the element to an event of type with the call back function. A typical use would be to bind the "click" event to function, which would call function when the xElement is cliked.

  • type Event type.
  • function Function to calle when Event is triggered.


xMulti

Class that contains a collection of xElements without a parent node. Added xElements to xMulti are appended to the xMulti's parent.

Subclass of xElement

Redefines getNode() remove() removeNode() removeElement(element) setToTop() append(parentNode) hide() show() bindToEvent()

Constructor xMulti(clss)

  • clss class to assign to the element, if none given the default "x_multielement" class is used.

addElement(element)

Adds an xElement to the xMulti object.

  • element xElement to be added.

removeAllElements()

Remove all its contained elements from the xMulti

getElement(index)

Returns a specific element from the xMulti

  • index index of element to retrieve.


xMultiElement

Abstract class for an xElement that contains other xElements

Subclass of xElement

Constructor xMultiElement(clss)

  • clss class to assign to the element, if non given the default "x_multielement" class is used.

addElement(element)

Add element to the xMultiElement object

  • element xElement to be added

removeElement(element)

Remove element from the xMultiElement object

  • element xElement to be removed

removeAllElements()

Remove all elements from the xMultiElement object

getElement(index)

Get element at index

  • index index of element to retrieve.


xSection

Creates a <div> node that contains a set of xElements

Subclass of xMultiElement

Constructor xSection(clss)

  • clss Class assigned to the created <div> element

clear()

Remove all contents of the xSection object


xText

Creates a text node

Subclass of xElement

Constructor xText(text)

  • text Text for the text node


xVerticalSpacer

Creates an empty <div> element of specified height

Subclass of xElement

Constructor xVerticalSpacer(height)

  • height height in pixels of the xVerticalSpacer element


xHtml

Creates an HTML element of defined type

Subclass of xElement

Constructor xHtml(type,innerHtml,clss)

  • type HTML node type.
  • innerHtml HTML to append to the xHtml element.
  • clss Class assigned to the xHtml element.

addHtml(html)

append HTML to the xHtml element

  • html HTML to append


xMultiHtml

Creates an HTML element of defined type which contains a set of xElement objects

Subclass of xMultiElement

Constructor xMultiHtml(type,clss)

  • type HTML node type
  • clss Class assigned to the xMultiHtml element


xLink

Creates a <a> element

Subclass of xMultiElement

Constructor xLink(label,href,clss)

  • label Label for the <a> element.
  • href target of the <a> element
  • clss Class assigned to the <a> element, if none given the default "x_link" will be used

bindFunction(f)

Bind a function to the "click" event of the <a> element

  • f Function to bind

disabled(d)

Sets or removes the disabled attribute to the <a> element

  • d Boolean, true sets the <a> element as disabled


xInput

Abstract class basis for other Input elements

Subclass of xElement

Constructor xInput(clss,wclss)

  • clss Class assigned to the xInput element, if none given the "x_input" default class is used.
  • wclss Class assigned to the wrapper element, if none given the "x_inputwrapper" default class is used.

getValue()

Returns the current value of the xInput element

setType(type)

Sets the type for the input element i.e. text, email, number, tel etc.

  • type Type for the input element.

setValue(value)

Sets the current value for the input element.

  • value Value to set.

setPlaceholder(placeholder)

Sets the placeholder text for the input element.

  • placeholder Text to use as placeholder.

setReadOnly(readonly)

Sets or removes the readonly attribute for the input element.

  • readonly Boolean value, true sets the readonly attribute.

addWrapperClass(clss)

Adds a class to the wrapper element

  • clss Class to add to the wrapper element.

setName(name)

Sets the name of the input element and its linked <label>

  • name Name for the Input element and its linked <label>.


xStringInput

Creates an <input> element of type "text" with surrounding <div> wrapper and linked <label>

Subclass of xInput

Constructor xStringInput(label,name,clss,wclss)

  • label Label for the <input> element
  • name Name for the <input> element
  • clss Class for the <input> element
  • wclss Class for the <div> wrapper


xNumberInput

Creates an <input> element of type "number" with surrounding <div> wrapper and linked <label>

Subclass of xStringInput

Constructor xNumberInput(label,name,clss,wclss)

  • label Label for the <input> element
  • name Name for the <input> element
  • clss Class for the <input> element
  • wclss Class for the <div> wrapper


xEmailInput

Creates an <input> element of type "email" with surrounding <div> wrapper and linked <label>

Subclass of xStringInput

Constructor xEmailInput(label,name,clss,wclss)

  • label Label for the <input> element
  • name Name for the <input> element
  • clss Class for the <input> element
  • wclss Class for the <div> wrapper


xDateInput

Creates an <input> element of type "date" with surrounding <div> wrapper and linked <label>

Subclass of xDateInput(label,name,clss,wclss)

Constructor xEmailInput(label,name,clss,wclss)

  • label Label for the <input> element
  • name Name for the <input> element
  • clss Class for the <input> element
  • wclss Class for the <div> wrapper


xTextAreaInput

Creates an <textarea> element with surrounding <div> wrapper and linked <label>

Subclass of xStringInput

Redefines getValue() setValue(value) setPlaceHolder(placeholder) setReadOnly(readonly) setName(name)

Constructor xTextAreaInput(label,name,rows,cols,clss,wclss)

  • label Label for the <textarea> element
  • name Name for the <textarea> element
  • rows Rows for the <textarea> element
  • cols Columns for the <textarea> element
  • clss Class for the <textarea> element
  • wclss Class for the <div> wrapper


xCheckBox

Creates an <input> element of type "checkbox" with surrounding <div> wrapper and linked <label>

Subclass of xInput

Redefines getValue()

Constructor xCheckBox(label,name,clss,wclss)

  • label Label for the <input> element
  • name Name for the <input> element
  • clss Class for the <input> element
  • wclss Class for the <input> wrapper


xSelect

Create <select> element with surrounding <div> wrapper and linked <label>

Subclass of xInput

Redefines getValue() setReadOnly(readonly) setName(name)

Constructor xSelect(label,name,clss,wclss)

  • label Label for the <select> element
  • name Name for the <select> element
  • clss Class for the <select> element
  • wclss Class for the <select> wrapper

addOption(label,value)

Adds an <option> element to the <select> with label and value

  • label Label for the <option>
  • value Value for the <option>

addOptions(options)

Adds options to the <select> element

  • options array of objects {label: "Label", value: "Value"}

setSelected(selected)

Sets the selected option

  • selected value of the selected option


xButton

Creates a <button> element

Subclass of xMultiElement

Redefines bindFunction(f)

Constructor xButton(label,clss)

  • label Label for the <button> element
  • clss Class for the <button> element

disabled(disabled)

Sets the disabled attribute on the <button> element

  • disabled Boolean value, true sets the disabled attribute for the <button> element


xImage

Creates an <img> element

Subclass of xElement

Constructor xImage(src,alt,clss)

  • src url of the image
  • alt Alternate text for the image
  • clss Class for the <img> element, if none given the "x_image" default class is used


xTextBox

Creates a <div> element surrounding text

Subclass of xElement

Constructor xTextBox(text,clss)

  • text Text for the xTextBox
  • clss Class assigned to the <div> element, if none given the "x_textbox" default class is used

setText(text)

Sets the text for the xTextBox

  • text Text to set

addText(text)

Appends text to the xTextBox

  • text Text to append

clear()

Clears the text from the xTextBox


xPara

Creates a <p> element with text or with elements added to the xPara object

Subclass of xMultiElement

Constructor xPara(text,clss)

  • text Text for the xPara
  • clss Class assigned to the <p> element, if none given the "x_para" default class is used

setText(text)

Sets the text for the xPara

  • text Text to set

addText(text)

Appends text to the xPara

  • text Text to append

clear()

Clears the text from the xPara


xSpan

Creates a <span> element with text or with elements added to the xSpan object

Subclass of xMultiElement

Constructor xSpan(text,clss)

  • text Text for the xSpan
  • clss Class assigned to the <span> element, if none given the "x_span" default class is used

setText(text)

Sets the text for the xSpan

  • text Text to set

addText(text)

Appends text to the xSpan

  • text Text to append

clear()

Clears the text from the xSpan


xTwoElementSection

Abstract class that implements an xSection with an auxiliar sibling DOM node

Subclass of xSection

Redefines append(parentNode) removeNode() removeElement(element)

Constructor xTwoElementSection(clss)

  • clss Class assigned to the <div> element, if none given the "x_twoelementsection" default class is used

removeAuxElement(element)

Does nothing here, to be redefined in derived classes

  • element element to be removed


xList

Creates an <ul> element

Subclass of xMultiElement

Redefines addElement(element) removeElement(element)

Constructor xList(clss)

  • clss Class assigned to the <ul> element, if none given the "x_list" default class is used


xLayout

Creates <table> element for laying out other xElements in the UI

Subclass of xMultiElement

Redefines removeElement(element)

Constructor xLayout(rows,cols,widths,clss)

  • rows Number of rows in the xLayout
  • cols Number of colums in the xLayout
  • widths Array of percentage or pixel width of each column: i.e. ["80%","20%"] If none given columns will be of equal width.
  • clss Class assigned to the <table> element, if none given the "x_layout" default class is used

addElement(element,row,col)

Adds an xElement in the specified row and column

  • element xElement to be added
  • row Row of the cell where the xElement will be added
  • col Column of the cell where the xElement will be added

getElement(row,col)

Retrieves the xElement at the specified row and column

  • row Row of the cell where the xElement will be retrieved.
  • col Row of the cell where the xElement will be retrieved.

setWidths(widths)

Retrieves the xElement at the specified row and column

  • widths Array of percentage or pixel width of each column: i.e. ["80%","20%"]

replaceElement(element,row,col)

Replaces the xElement at the specified row and column with the specified element

  • row Row of the cell where the xElement will be replaced
  • col Column of the cell where the xElement will be replaced
  • element xElement to replace


xPanel

Creates <div> element as base for a UI Panel

Subclass of xSection

Constructor xPanel(clss)

  • clss Class assigned to the <div> element, if none given the "x_panel" default class is used


xTitlePanel

Creates a set of <div> element as base for a UI Panel with Title and Body

Subclass of xPanel

Redefines addElement(element)

Constructor xTitlePanel(title, bodyclss, titleclss, clss)

  • title Title of the xTitlePanel.
  • bodyclss Class assigned to the body <div> element.
  • titleclss Class assigned to the title <div> element.
  • clss Class assigned to the containing <div> element, if none given the "x_titlepanel" default class is used

setTitle(title)

Sets the title of the xTitlePanel

  • title Text to use as title.

clear()

Clears the contents of the body of the xTitlePanel


xTable

Creates a <table> element

Subclass of xElement

Constructor xTable(clss)

  • clss Class assigned to the <table> element, if none given the "x_table" default class is used

addHeadings(headings)

Adds headings to the xTable.

  • headings Array of strings to be used as headings.

addRow(row,clss)

Adds a row to the xTable.

  • row Array of strings to be inserted as a row.
  • clss Class assigned to the row.


xElementsTable

Creates a <table> element that contains xElements in its cells

Subclass of xElement

Constructor xElementsTable(clss)

  • clss Class assigned to the <table> element, if none given the "x_elementstable" default class is used

addHeadings(headings)

Adds headings to the xElementsTable.

  • headings Array of xElements to be used as headings.

addRow(row,clss)

Adds a row to the xElementsTable.

  • row Array of xElements to be inserted in the row.
  • clss Class assigned to the row.

getElement(row,col)

Retrieves the xElement at the specified row and column.

  • row Row of the xElement to be retrieved.
  • col Column of the xElement to be retrieved.

getRowCount()

Returns the current row count.


Bootstrap Element Encapsulating Classes

xbLink

Creates Bootstrap link element.

Subclass of xLink

Constructor xbLink(label,href,clss)

  • label Label for the xbLink.
  • href Target for the xbLink.
  • clss Class to append to the xbLink.


xbStringInput

Creates Bootstrap string input element

Subclass of xInput

Constructor xbStringInput(label,name,clss,wclss)

  • label Label for the xbStringInput.
  • name Name for the xbStringInput.
  • clss Class for the xbStringInput if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbStringInput.

setError(error)

Set or remove the error state of the xbStringInput.

  • error Boolean value, if true the xStringInput set to the error state.


xbNumberInput

Creates Bootstrap number input element

Subclass of xStringInput

Constructor xbNumberInput(label,name,clss,wclss)

  • label Label for the xbNumberInput.
  • name Name for the xbNumberInput.
  • clss Class for the xbNumberInput if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbNumberInput.


xbEmailInput

Creates Bootstrap email input element

Subclass of xStringInput

Constructor xbEmailInput(label,name,clss,wclss)

  • label Label for the xbEmailInput.
  • name Name for the xbEmailInput.
  • clss Class for the xbEmailInput if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbEmailInput.


xbTelInput

Creates Bootstrap telephone input element

Subclass of xStringInput

Constructor xbTelInput(label,name,clss,wclss)

  • label Label for the xbTelInput.
  • name Name for the xbTelInput.
  • clss Class for the xbTelInput if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbTelInput.


xbDateInput

Creates Bootstrap date input element

Subclass of xStringInput

Constructor xbDateInput(label,name,clss,wclss)

  • label Label for the xbDateInput.
  • name Name for the xbDateInput.
  • clss Class for the xbDateInput if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbDateInput.


xbTextAreaInput

Creates Bootstrap textarea input element

Subclass of xInput

Redefines setValue(value) getValue() setPlaceholder(placeholder) setReadOnly(readonly) setName(name)

Constructor xbTextAreaInput(label,name,rows,clss,wclss)

  • label Label for the xbTextAreaInput.
  • name Name for the xbTextAreaInput.
  • rows Number of rows for the xbTextAreaInput.
  • clss Class for the xbTextAreaInput if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbTextAreaInput.

setError(error)

Set or remove the error state of the xbTextAreaInput.

  • error Boolean value, if true the xbTextAreaInput set to the error state.


xbCheckBox

Creates Bootstrap checkbox input element

Subclass of xInput

Redefines getValue()

Constructor xbCheckBox(label,name,clss,wclss)

  • label Label for the xbCheckBox.
  • name Name for the xbCheckBox.
  • clss Class for the xbCheckBox if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbCheckBox.

setChecked(checked)

Set or remove the checked value of the xbCheckBox.

  • checked Boolean value, if true the xbCheckBox is checked.

setError(error)

Sets or remove the error state of the xbCheckBox.

  • error Boolean value, if true the xbCheckBox is set to the error state.


xbSelect

Creates Bootstrap checkbox input element

Subclass of xInput

Redefines getValue() setValue(value) setReadOnly(readonly) setName(name)

Constructor xbSelect(label,name,clss,wclss)

  • label Label for the xbSelect.
  • name Name for the xbSelect.
  • clss Class for the xbSelect if none given the "form-control" class is used.
  • wclss Class to append to the "form-group" wrapper class of the xbSelect.

addOption(label,value)

Adds an option to the xbSelect.

  • label Label of the option.
  • value Value of the option.

addOptions(options)

Adds options to the xbSelect

  • options Array of objects {label: "label", value: "value"} to be used as options of the xbSelect.

setSelected(selected)

Sets the selected option of the xbSelect

  • selected Value of the selected option.

clear()

Clears the selected option of the xbSelect

setError(error)

Sets or remove the error state of the xbSelect.

  • error Boolean value, if true the xbSelect is set to the error state.


xbForm

Creates Bootstrap form element

Subclass of xMultiElement

Constructor xbForm(clss)

  • clss Class for the xbForm.


xbButton

Creates Bootstrap button element

Subclass of xButton

Constructor xbButton(label,clss)

  • label Label for the xbButton.
  • clss Additional class for the xbButton.


xbButtonIcon

Creates Bootstrap button element with a Glyphicon

Subclass of xButton

Constructor xbButtonIcon(label,icon,right,clss)

  • label Label for the xbButtonIcon.
  • icon Glyphicon for the xbButtonIcon.
  • right If true places icon to the right of the label.
  • clss Additional class for the xbButtonIcon.


xbButtonPopOver

Creates Bootstrap button with popover

Subclass of xbButton

Constructor xbButtonPopOver(label,title,content,clss)

  • label Label for the xbButtonPopOver.
  • title Title of the popover.
  • content content of the popover.
  • clss Additional class for the xbButtonPopOver.


xbButtonDropdown

Creates Bootstrap button with dropdown menu

Subclass of xSection

Constructor xbButtonDropdown(label,clss)

  • label Label for the xbButtonDropdown.
  • clss Additional class for the xbButtonDropdown.

addItem(item)

Adds an item to the dropdown menu.

  • item xbButtonDropdownItem object representing an option in the dropdown menu.


xbButtonDropdownItem

Creates object representing an option of the dropdown menu of an xbButtonDropdown

Subclass of xLink

Constructor xbButtonDropdownItem(label,f)

  • label Label for the option.
  • f Function to bind to this option.


xbButtonGroup

Creates a Bootstrap button group that will contain xbButton

Subclass of xSection

Constructor xbButtonGroup(clss)

  • clss Additional class for the xbButtonGroup.

addButton(btn)

Adds a button to the xbButtonGroup

  • btn xbButton object.


xbButtonGroupVertical

Creates a Bootstrap vertical button group that will contain xbButton

Subclass of xbButtonGroup

Constructor xbButtonGroupVertical(clss)

  • clss Additional class for the xbButtonGroupVertical.


xbImage

Creates a Bootstrap image element

Subclass of xImage

Constructor xbImage(src,alt,clss)

  • src URL of the image.
  • alt Alternate text for the image.
  • clss Class for the xbImage.


xbTextBox

Creates a Bootstrap Text Box

Subclass of xTextBox

Constructor xbTextBox(text, clss)

  • text Text for the xbTextBox.
  • clss Class for the xbTextBox.


xbPara

Creates a Bootstrap Paragraph

Subclass of xPara

Constructor xbPara(text, clss)

  • text Text for the xbPara.
  • clss Class for the xbPara.


xbAlert

Creates a Bootstrap Alert element

Subclass of xSection

Constructor xbAlert(clss)

  • clss Additional class for the xbAlert.


xbJumbotron

Creates a Bootstrap Jumbotron element

Subclass of xSection

Constructor xbJumbotron()


xbLayout

Creates a Layout

Subclass of xLayout

Constructor xbLayout(rows,cols,widths,clss)

  • rows Number of rows in the xbLayout
  • cols Number of colums in the xbLayout
  • widths Array of percentage or pixel width of each column: i.e. ["80%","20%"] If none given columns will be of equal width.
  • clss Class assigned to the xbLayout element.


xbPanel

Creates a Bootstrap panel

Subclass of xPanel

Constructor xbPanel(clss)

  • clss Class assigned to the xbPanel element, if none given the "panel" default class is used


xbTitlePanel

Creates a Bootstrap panel with title

Subclass of xTitlePanel

Constructor xbTitlePanel(title, clss)

  • title Title for the xbTitlePanel.
  • clss Additional class added to the xbTitlePanel element.


xbTable

Creates a Bootstrap table

Subclass of xTable

Constructor xbTable(clss)

  • clss Additional class added to the xbTable element.


xbElementsTable

Creates a Bootstrap table in which cells contain xElements

Subclass of xElementsTable

Constructor xbElementsTable(clss)

  • clss Additional class added to the xbElementsTable element.


xbTabs

Creates a Bootstrap tabed navigation element.

Subclass of xTwoElementSection

Redefines removeAuxElement(element)

Constructor xbTabs(clss)

  • clss Additional class added to the xbTabs element.

addPane(title,pane)

Adds a pane to the xbTab

  • title Title for the pane.
  • pane xbTabPane object.

removePane(index)

Removes a pane from the xbTab

  • index Index of the pane to remove.

activatePane(index)

Activates a pane at the specified index.

  • index Index of the pane to activate.


xbTabPane

Creates a Bootstrap pane element for inclusion in an xbTab.

Subclass of xSection

Constructor xbTabPane(clss)

  • clss Additional class added to the xbTabPane element.


xbNavBar

Creates a Bootstrap Nav Bar element.

Subclass of xSection

Constructor xbNavBar(title,clss)

  • title Title of the xbNavBar.
  • clss Additional class added to the xbNavBar element.

addDropdown(dropdown)

Adds a dropdown menu to the xbNavBar.

  • dropdown xbNavBarDropdown object.

addItem(item)

Adds an item to the xbNavBar.

  • item xbNavBarItem object.

getNavItem(index)

Retrieves an item from the xbNavBar at the specified index.

  • index Index of the item to retrieve.


xbNavBarDropdown

Creates a Bootstrap Nav Bar dropdown element for inclusion in an xbNavBar.

Subclass of xList

Constructor xbNavBarDropdown(title,clss)

  • title Title of the xbNavBarDropdown.
  • clss Additional class added to the xbNavBarDropdown element.

addItem(item)

Adds an item to the xbNavBarDropdown at the specified index.

  • item xbNavBarItem object.

addDivider()

Adds a divider to the xbNavBarDropdown.

addTitleWrapper(wrapper)

Adds a wrapper element for the xbNavBarDropdown title.

  • wrapper HTML element to use as title wrapper i.e <h3>.

disabled(d)

Sets or removes the disabled state of the xbNavDropdown.

  • d Boolean, if true the xbNavDropdown is disabled.


xbNavBarItem

Creates a Bootstrap Nav Bar item element for inclusion in an xbNavBar.

Subclass of xLink

Redefines bindFunction(f)

Constructor xbNavBarItem(label,clss)

  • title Title of the xbNavBarItem.
  • clss Additional class added to the xbNavBarItem element.

disabled(d)

Sets or removes the disabled state of the xbNavBarItem.

  • d Boolean, if true the xbNavBarItem is disabled.


xbModal

Creates a Bootstrap Modal Dialog.

Subclass of xSection

Redefines show() hide() remove()

Constructor xbModal(title,clss,dlg_clss)

  • title Title of the xbModal.
  • clss Additional class added to the xbModal wrapper element.
  • dlg_clss Additional class added to the xbModal Dialog element.

addToFooter(element)

Adds an element to the xbModal footer.

  • element xElement object.

addToBody(element)

Adds an element to the xbModal body.

  • element xElement object.

addCloseButton(label,clss)

Adds a close xbButton to the xbModal.

  • label Label for the button.
  • clss Additional class for the xbButton.

setAutoRemove(autoremove)

Sets the autoremove mode, in which the xbModal is removed from the DOM when closed.

  • autoremove Boolean, if true the xbModal is set to autoremove on close.


xbModalOpenButton

Creates a Bootstrap xbButton which opens a linked xbModal.

Subclass of xbButton

Constructor xbModalOpenButton(label,modal,clss)

  • label Label of the xbModalOpenButton.
  • modal xbModal object to link to the xbModalOpenButton.
  • clss Additional class added to the xbModalOpenButton element.


xbModalOpenLink

Creates an xLink element which opens a linked xbModal.

Subclass of xLink

Constructor xbModalOpenLink(label,modal,clss)

  • label Label of the xbModalOpenLink.
  • modal xbModal object to link to the xbModalOpenLink.
  • clss Additional class added to the xbModalOpenLink element.


xbListGroup

Creates a Bootstrap list-group element.

Subclass of xLink

Constructor xbListGroup(clss)

  • clss Additional class added to the xbListGroup element.

addItem(item)

Adds an item to the xbListGroup.

  • item xbListGroupItem object.


xbListGroup

Creates a Bootstrap list-group item element.

Subclass of xSection

Constructor xbListGroupItem(label,clss)

  • label Label for the xbListGroupItem element.
  • clss Additional class added to the xbListGroupItem element.


xbTheme

Creates a xbSelect with options for Bootstrap themes. The theme of the app is changed on selection. If not inserted as an UI element it can also be used to change the theme programmatically.

Subclass of xbSelect

Constructor xbTheme(label,currentTheme)

  • label Label for the xbTheme element.
  • currentTheme Initial theme to select. If none given the default "acelery" is used.

setTheme(theme)

Selects a Bootstrap theme.

  • theme name of the theme to select: aCelery, Cerulean, Cosmo, Cyborg, Darkly, Default, Flatly, Journal, Lumen, Paper, Readable, Sandstone, Simplex, Slate, Spacelab, Superhero, United, Yeti.


CRUD (Create, Read, Update, Delete) Classes

xbValidator

Abstract class for field validators.

Constructor xbValidator()

validate(value)

Validate value

  • value Value to validate.


xbNotEmptyValidator

Creates a not empty field validator.

Subclass of xbValidator

Redefines validate(value)

Constructor xbNotEmptyValidator()


xbEmailValidator

Creates a validator for email fields.

Subclass of xbValidator

Redefines validate(value)

Constructor xbEmailValidator()


xbTelValidator

Creates a validator for telephone fields.

Subclass of xbValidator

Redefines validate(value)

Constructor xbTelValidator()


xbNotZeroValidator

Creates a not zero validator.

Subclass of xbValidator

Redefines validate(value)

Constructor xbNotZeroValidator()


xbField

Basic CRUD field.

Constructor xbField(type,title,name,inList,inSearch)

  • type Field type (string, number, money, date, email, tel).
  • title Field title.
  • name Name in the database table.
  • inList Boolean, if true the field will be presented in the list view.
  • inSearch Boolean, if true the field will be presented in the search view.

getTitle()

Returns the title of the field.

getName()

Returns the name of the field.

setReadOnly(readonly)

Sets the readonly attribute of the field.

  • readonly Boolean, if true the field is set to read only.

format(value)

Formats the value according to the field type.

  • value Value to format.

setValue(value)

Sets the value of the field.

  • value Value to set.

clear()

Clears the field.

getInput()

Returns the xbInput object corresponding to the field.

getValue()

Returns the current value of the field.

addValidator(validator)

Adds a validator to the field.

  • validator xbValidator object.

validate()

Validate the field. Returns true if the value of the field is validated by all validators.


xbTextAreaField

Text Area field.

Subclass of xbField

Redefines getInput()

Constructor xbTextAreaField(title,name,rows,inList,inSearch)

  • title Field title
  • name Name in the database table.
  • rows Number of rows for the Text Area.
  • inList Boolean, if true the field will be presented in the list view.
  • inSearch Boolean, if true the field will be presented in the search view.


xbCheckboxField

Checkbox field.

Subclass of xbField

Redefines getInput() getValue() setValue(value) format(value) clear()

Constructor xbCheckboxField(title,name,onval,offval,inl,ins)

  • title Field title
  • name Name in the database table.
  • onval Value of the field when checked.
  • offval Value of the field when not checked.
  • inList Boolean, if true the field will be presented in the list view.
  • inSearch Boolean, if true the field will be presented in the search view.


xbListField

List field.

Subclass of xbField

Redefines getInput() format(value) clear()

Constructor xbListField(type,title,name,inList,inSearch)

  • type Type of the field in the database table.
  • title Field title.
  • name Name in the database table.
  • inList Boolean, if true the field will be presented in the list view.
  • inSearch Boolean, if true the field will be presented in the search view.

addOption(label,value)

Add an option to the List Field with the specified label and value.

  • label Label for the option.
  • value Value for the option.

addOptions(options)

Add options to the List Field.

  • options Array of objects {label: "label", value: "value"}.


xbTableListField

List field where options are obtained from a database table.

Subclass of xbListField

Constructor xbTableListField(database,title,name,table,field,inList,inSearch)

  • database xSQL object.
  • title Field title.
  • name Name in the database table.
  • table Table from where the options will be obtained.
  • field Field to use for the label of the options.
  • inList Boolean, if true the field will be presented in the list view.
  • inSearch Boolean, if true the field will be presented in the search view.


xbTableMaint

Object that performs all CRUD operations on a single table or on a main table and other linked tables.

Subclass of xbTitlePanel

Constructor xbTableMaint(database,title,table)

  • database xSQL object.
  • title xbTableMaint title.
  • table Table to use for CRUD operations.

addField(field)

Add a field to the xbTableMaint.

  • field xbField object.

clearRestrict()

Clears the search restriction.

list(firstid,lastid)

Generates the list view.

  • firstid First ID value passed for pagin purposes.
  • lastid Last ID value passed for pagin purposes.

show(id)

Generates the record view for the specified id.

  • id ID of the record to show.

find()

Generates the search panel.

findResult()

Generates a list view with a search result.

empty()

Generates an empty form panel for a new record.

readForm()

Reads the values of all fields in a form panel.

validateFields()

Validates all fields and return the result.

insert()

Inserts a new record into the database and presents a record view of the inserted record.

edit(id)

Presents an edit view for the record with specified id.

  • id ID of the record to edit.

save(id)

Saves in the database the edited record with specified id.

  • id ID of the record to save.

del(id)

Deletes (after user confirmation) from the database the record with specified id.

  • id ID of the record to delete.

setSlaveParams(linkField,linkId)

Sets the parameters for the xbTableMaint when functioning as a linked table.

  • linkField Field in the database to use as link.
  • linkId Current value of the link field.

run()

Starts processing CRUD operations by presenting an initial list view.

validateForm()

Redefinable method in inherited class, called to validate the form, must return a true or false value. Current values to use for validation are accessible in this.record.

preNew()

Redefinable method in inherited class, called before generating the insert query, data in this.record.

postNew(id)

Redefinable method in inherited class, called after sql insert, id is new id assigned on insert.

  • id ID assigned on insert.

preEdit(id)

Redefinable method in inherited class, called before generating update query, data in this.record.

  • id ID of record to update.

postEdit(id)

Redefinable method in inherited class, called after sql update.

  • id ID of updated record.

preDelete(id)

Redefinable method in inherited class, called before generating delete query.

  • id ID of record to delete.

postDelete(id)

Redefinable method in inherited class, called after sql delete.

  • id ID of deleted record.

specialActionsMenu(id)

Redefinable method in inherited class, used to present the user with a menu of special actions in the record view. Must return an array of objects {label: "mylabel", bind: function(){}}.

  • id ID of current record.


Android Interface Classes

xInterface

Abstract class, base for other Android Interface classes.

Constructor xInterface()

getRemoteInterface(query)

Performs an Ajax GET request with the specified query that returns JSON data.

  • query query component of the URL.

rawRemoteInterface(query)

Performs an Ajax GET request with the specified query that returns raw data.

  • query query component of the URL.

rawPostRemoteInterface(query,data)

Performs an Ajax POST request with the specified query and data that returns raw data.

  • query query component of the URL.
  • data data to be posted.

postRemoteInterface(query,data)

Performs an Ajax POST request with the specified query and data that returns JSON data.

  • query query component of the URL.
  • data data to be posted.


xSQL

SQLite Interface object class.

Subclass of xInterface

Constructor xSQL()

openDB(path, basePath)

Opens and creates if it does not exist a SQLite database.

  • path path of the database file (usually just the file name).
  • basePath path of the database location, if none given the default {external_storage}/aCelery/db/ is used

sqlExec(query)

Executes an SQL statement that is not a select or insert.

  • query SQL query.

sqlInsert(query)

Execute an insert SQL query. Returns the rowid of the inserted row, -1 if en error occurred.

  • query SQL insert query.

sqlSelect(query)

Execute a select SQL query. Returns the cursor handle. -1 if an error occurred.

  • query SQL select query.

getRowCount()

Returns the number of rows selected after an sqlSelect call

gotoLastRow()

Go to the last row of the current cursor.

getNextRow()

Retrieves the next row in the cursor as a Javascript object, false if past the end of the cursor.

getPrevRow()

Retrieves the previous row in the cursor as a Javascript object, false if before the start of the cursor.

closeCursor()

Closes the current cursor.

closeDB()

Closes the current Data Base.

deleteDB(path, basePath)

Deletes a database.

  • path Path of the database to delete.
  • basePath path of the database location, if none given the default {external_storage}/aCelery/db/ is used


xFile

File IO Interface object class.

Subclass of xInterface

Constructor xFile()

open(path, basePath)

Opens a file.

  • path Path of the file.
  • basePath path of the file location, if none given the default {external_storage}/aCelery/files/ is used

listFiles(path, basePath)

Lists files, returns an array of objects with attributes: path, fname, directory, lastmodified, length. or false.

  • path Path of the directory.
  • basePath path of the directory location, if none given the default {external_storage}/aCelery/files/ is used

mkDir(path, basePath)

Creates a directory.

  • path Path of the directory.
  • basePath path of the directory location, if none given the default {external_storage}/aCelery/files/ is used

getExtStoragePath()

Gets the absolute path of External Storage in the Android system.

close()

Closes the current file.

deleteFile()

Delete the current file

read()

Reads the contents of the current file and returs them as a string.

write(data,append)

Writes to the current file.

  • data Data to write.
  • append Boolean, if true appends data to the file, otherwise it overwrites.


xExportFile

File Export Interface object class.

Subclass of xInterface

Constructor xExportFile()

set(mime,fname,data)

Creates a file to be exported.

  • mime Mime type of the file.
  • fname File name.
  • data Data for the file.

get()

Gets the created file for download.


xHTTP

HTTP interface object class. This interface allows us to circumvent the same origin policy which prevents us form getting data from an arbitrary server using regular javascript Ajax calls.

Subclass of xInterface

Constructor xHTTP()

get(url)

Gets data from a server at the specified url.

  • url URL or the required resource.

post(url,data)

Gets data from a server at the specified url issuing a POST request.

  • url URL or the required resource.
  • data Javascript object with the data to post.


Example App

var db, topLayout, myModal;

function initDB(){
   // Initialize SQLite database

   db = new xSQL();
   db.openDB("xtest.db");
   db.sqlExec("create table if not exists person (mname string, email string, grp string)");
   db.sqlExec("create table if not exists person_tel (person integer, tel string, type string)");

}

function tabsTest(){
   // Example tabs with 3 panes

   var myTabs = new xbTabs();
   var pane1 = new xbTabPane();
   var pane2 = new xbTabPane();
   var pane3 = new xbTabPane();
   
   myTabs.addPane("Pane 1", pane1)
         .addPane("Pane 2", pane2)
         .addPane("Pane 3", pane3)
         .activatePane(1);
         
   pane1.addElement(new xbPara("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et erat et metus auctor cursus. Ut congue facilisis velit sit amet dapibus"));
   pane2.addElement(new xbPara("Nam pellentesque porta odio, eu auctor felis viverra eget. Aenean tortor ligula, ornare quis tristique in, fermentum nec elit. Lorem ipsum dolor sit amet"));
   pane3.addElement(new xbPara("Nullam et orci consequat, feugiat nisi in, consectetur mauris. Aenean nec imperdiet augue. Etiam placerat neque lectus, vel volutpat justo dapibus sed"));

   // Remove previous element from the layout and add myTabs 

   if (e = topLayout.getElement(1,0))
      e.remove();
   topLayout.addElement(myTabs,1,0);
}

function widgetTest(){
   // Test various Bootstrap widgets

   var panel = new xbTitlePanel("Widgets");
   
   var btnGroup = new xbButtonGroup()
                      .addElement(new xbButton("Button","btn-primary"))
                      .addElement(new xbButtonIcon("Icon","glyphicon-asterisk"))
                      .addElement(new xbButtonDropdown("Dropdown")
                                      .addItem(new xbButtonDropdownItem("Item 1",null))
                                      .addItem(new xbButtonDropdownItem("Item 2",null))
                                      .addItem(new xbButtonDropdownItem("Item 3",null)));
   panel.addElement(new xbImage("/user/Example/Redtwitter_icon_48x48.png","Red Twitter"))
        .addElement(new xbTheme("Select Theme"))
        .addElement(new xbStringInput("Input","inp"))
        .addElement(new xbSelect("Select","sel")
                        .addOption("Option 1","1")
                        .addOption("Option 2","2")
                        .addOption("Option 3","3"))
        .addElement(btnGroup);                
                        
   if (e = topLayout.getElement(1,0))
      e.remove();
   topLayout.addElement(panel,1,0);
}

function jsonNews(){
   // Get a news feed with the HTTP interface and present in an xbListGroup
   
   var jsonfeed = new xHTTP().get("http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=8&q=http%3A%2F%2Fnews.google.com%2Fnews%3Foutput%3Drss");
   var list = new xbListGroup();
   var data = JSON.parse(jsonfeed);
   for (var i = 0; ((i < data.responseData.feed.entries.length) && (i < 10)); i++){
      var ent = data.responseData.feed.entries[i];
      var item = new xbListGroupItem()
                     .addElement(new xMultiHtml("h3")
                                    .addElement(new xbPara(ent.title,"text-info")))
                     .addElement(new xPara(ent.contentSnippet));
      list.addElement(item);
   }
   if (e = topLayout.getElement(1,0))
      e.remove();
   topLayout.addElement(list,1,0);
}

function dirExport(){
   // Export the Directory database with the File Export Interface
   
   var resObj;
   var data = "";
   var myEf = new xExportFile();
   
   db.sqlSelect("select a.rowid, a.*, b.rowid, b.* from person as a, person_tel as b where b.person = a.rowid order by a.mname");
   while (resObj = db.getNextRow()){
      var first = true;
      for(fld in resObj){
         if (!first)
            data += ',';
         first = false;
         data += '"' + resObj[fld] + '"';
      }
      data += '\r\n';
   }
   
   // This is the file export trick: First send to the server and then get it back!
   
   myEf.set("text/csv","directory.csv",data);
   myEf.get();
}

function showModal(){
   // Show a Modal Dialog
   
   myModal = new xbModal("aCelery Modal");
   myModal.addCloseButton("Close","btn-primary");
   myModal.addToBody(new xbPara("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin et erat et metus auctor cursus. Ut congue facilisis velit sit amet dapibus"));
   myModal.show();
}

function dirMaint(dbl){
   // Use the CRUD framework in single table and linked table modes
   
   var person = new xbTableMaint(db,"Directory","person")
                 .addField(new xbField("string","Name","mname",true,true)
                               .addValidator(new xbNotEmptyValidator()))
                 .addField(new xbField("email","Email","email",false,true)
                               .addValidator(new xbEmailValidator()))
                 .addField(new xbListField("string","Group","grp",false,true)
                               .addOption("Work","w")
                               .addOption("Friends","f")
                               .addOption("Family","m"));

   if (dbl == "2"){
      var person_tel = new xbTableMaint(db,"Telephones","person_tel")
                           .addField(new xbField("number","Person","person",false,false))
                           .addField(new xbField("tel","Telephone","tel",true,false)
                                         .addValidator(new xbTelValidator()))
                           .addField(new xbListField("string","Type","type",true,false)
                                         .addOption("Work","w")
                                         .addOption("Home","h")
                                         .addOption("Mobile","m"));

      // Link the person_tel table to the person table                              

      person.addLinkedTable(person_tel,"person");
   }
   if (e = topLayout.getElement(1,0))
      e.remove();
   topLayout.addElement(person,1,0);
   
   // Start the xbTableMaint object
   
   person.run();
}

function exit(){
   // Close the app
   db.closeDB();
   xCloseApp();
}

function showMenu(){
   // Create and show a Bootstrap NavBar with the main menu
   
   var nav, dir;
   
   nav = new xbNavBar("aCelery","acelery_navbar");
   dir = new xbNavBarDropdown("Directory");
   dir.addItem(new xbNavBarItem("CRUD Single")
                    .bindFunction(function(){dirMaint("1")}));
   dir.addItem(new xbNavBarItem("CRUD Linked")
                    .bindFunction(function(){dirMaint("2")}));
   dir.addItem(new xbNavBarItem("Export")
                    .bindFunction(dirExport));
   nav.addDropdown(dir);
   nav.addItem(new xbNavBarItem("Tabs")
                   .bindFunction(tabsTest));
   nav.addItem(new xbNavBarItem("Widgets")
                   .bindFunction(widgetTest));
   nav.addItem(new xbNavBarItem("News")
                   .bindFunction(jsonNews));
   nav.addItem(new xbNavBarItem("Modal")
                   .bindFunction(showModal));
   nav.addItem(new xbNavBarItem("Exit")
                   .bindFunction(exit));

   // Create a layout for the App with 2 rows and 1 column
   // Add the NavBar and set as the Top Element.
   
   topLayout = new xbLayout(2,1)
                  .addElement(nav,0,0)
                  .setToTop();
}

function main(){
   // App entry point
   
   initDB();
   showMenu();
}