include("functions.php"); Start(); ?>
Create your own App
The xScript framework is made of four parts:
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.
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)
genUID()
returns a random unique ID
setParent(parent)assigns the parent of the xElement.
assigns the class of the xElement.
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.
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.
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)
Adds an xElement to the xMulti object.
Remove all its contained elements from the xMulti
getElement(index)Returns a specific element from the xMulti
Abstract class for an xElement that contains other xElements
Subclass of xElement
Constructor xMultiElement(clss)
Add element to the xMultiElement object
Remove element from the xMultiElement object
Remove all elements from the xMultiElement object
getElement(index)Get element at index
Creates a <div> node that contains a set of xElements
Subclass of xMultiElement
Constructor xSection(clss)
Remove all contents of the xSection object
Creates a text node
Subclass of xElement
Constructor xText(text)
Creates an empty <div> element of specified height
Subclass of xElement
Constructor xVerticalSpacer(height)
Creates an HTML element of defined type
Subclass of xElement
Constructor xHtml(type,innerHtml,clss)
append HTML to the xHtml element
Creates an HTML element of defined type which contains a set of xElement objects
Subclass of xMultiElement
Constructor xMultiHtml(type,clss)
Creates a <a> element
Subclass of xMultiElement
Constructor xLink(label,href,clss)
Bind a function to the "click" event of the <a> element
Sets or removes the disabled attribute to the <a> element
Abstract class basis for other Input elements
Subclass of xElement
Constructor xInput(clss,wclss)
Returns the current value of the xInput element
setType(type)Sets the type for the input element i.e. text, email, number, tel etc.
Sets the current value for the input element.
Sets the placeholder text for the input element.
Sets or removes the readonly attribute for the input element.
Adds a class to the wrapper element
Sets the name of the input element and its linked <label>
Creates an <input> element of type "text" with surrounding <div> wrapper and linked <label>
Subclass of xInput
Constructor xStringInput(label,name,clss,wclss)
Creates an <input> element of type "number" with surrounding <div> wrapper and linked <label>
Subclass of xStringInput
Constructor xNumberInput(label,name,clss,wclss)
Creates an <input> element of type "email" with surrounding <div> wrapper and linked <label>
Subclass of xStringInput
Constructor xEmailInput(label,name,clss,wclss)
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)
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)
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)
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)
Adds an <option> element to the <select> with label and value
Adds options to the <select> element
Sets the selected option
Creates a <button> element
Subclass of xMultiElement
Redefines bindFunction(f)
Constructor xButton(label,clss)
Sets the disabled attribute on the <button> element
Creates an <img> element
Subclass of xElement
Constructor xImage(src,alt,clss)
Creates a <div> element surrounding text
Subclass of xElement
Constructor xTextBox(text,clss)
Sets the text for the xTextBox
Appends text to the xTextBox
Clears the text from the xTextBox
Creates a <p> element with text or with elements added to the xPara object
Subclass of xMultiElement
Constructor xPara(text,clss)
Sets the text for the xPara
Appends text to the xPara
Clears the text from the xPara
Creates a <span> element with text or with elements added to the xSpan object
Subclass of xMultiElement
Constructor xSpan(text,clss)
Sets the text for the xSpan
Appends text to the xSpan
Clears the text from the xSpan
Abstract class that implements an xSection with an auxiliar sibling DOM node
Subclass of xSection
Redefines append(parentNode) removeNode() removeElement(element)
Constructor xTwoElementSection(clss)
Does nothing here, to be redefined in derived classes
Creates an <ul> element
Subclass of xMultiElement
Redefines addElement(element) removeElement(element)
Constructor xList(clss)
Creates <table> element for laying out other xElements in the UI
Subclass of xMultiElement
Redefines removeElement(element)
Constructor xLayout(rows,cols,widths,clss)
Adds an xElement in the specified row and column
Retrieves the xElement at the specified row and column
Retrieves the xElement at the specified row and column
Replaces the xElement at the specified row and column with the specified element
Creates <div> element as base for a UI Panel
Subclass of xSection
Constructor xPanel(clss)
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)
Sets the title of the xTitlePanel
Clears the contents of the body of the xTitlePanel
Creates a <table> element
Subclass of xElement
Constructor xTable(clss)
Adds headings to the xTable.
Adds a row to the xTable.
Creates a <table> element that contains xElements in its cells
Subclass of xElement
Constructor xElementsTable(clss)
Adds headings to the xElementsTable.
Adds a row to the xElementsTable.
Retrieves the xElement at the specified row and column.
Returns the current row count.
Creates Bootstrap link element.
Subclass of xLink
Constructor xbLink(label,href,clss)
Creates Bootstrap string input element
Subclass of xInput
Constructor xbStringInput(label,name,clss,wclss)
Set or remove the error state of the xbStringInput.
Creates Bootstrap number input element
Subclass of xStringInput
Constructor xbNumberInput(label,name,clss,wclss)
Creates Bootstrap email input element
Subclass of xStringInput
Constructor xbEmailInput(label,name,clss,wclss)
Creates Bootstrap telephone input element
Subclass of xStringInput
Constructor xbTelInput(label,name,clss,wclss)
Creates Bootstrap date input element
Subclass of xStringInput
Constructor xbDateInput(label,name,clss,wclss)
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)
Set or remove the error state of the xbTextAreaInput.
Creates Bootstrap checkbox input element
Subclass of xInput
Redefines getValue()
Constructor xbCheckBox(label,name,clss,wclss)
Set or remove the checked value of the xbCheckBox.
Sets or remove the error state of the xbCheckBox.
Creates Bootstrap checkbox input element
Subclass of xInput
Redefines getValue() setValue(value) setReadOnly(readonly) setName(name)
Constructor xbSelect(label,name,clss,wclss)
Adds an option to the xbSelect.
Adds options to the xbSelect
Sets the selected option of the xbSelect
Clears the selected option of the xbSelect
Sets or remove the error state of the xbSelect.
Creates Bootstrap form element
Subclass of xMultiElement
Constructor xbForm(clss)
Creates Bootstrap button element
Subclass of xButton
Constructor xbButton(label,clss)
Creates Bootstrap button element with a Glyphicon
Subclass of xButton
Constructor xbButtonIcon(label,icon,right,clss)
Creates Bootstrap button with popover
Subclass of xbButton
Constructor xbButtonPopOver(label,title,content,clss)
Creates Bootstrap button with dropdown menu
Subclass of xSection
Constructor xbButtonDropdown(label,clss)
Adds an item to the dropdown menu.
Creates object representing an option of the dropdown menu of an xbButtonDropdown
Subclass of xLink
Constructor xbButtonDropdownItem(label,f)
Creates a Bootstrap button group that will contain xbButton
Subclass of xSection
Constructor xbButtonGroup(clss)
Adds a button to the xbButtonGroup
Creates a Bootstrap vertical button group that will contain xbButton
Subclass of xbButtonGroup
Constructor xbButtonGroupVertical(clss)
Creates a Bootstrap image element
Subclass of xImage
Constructor xbImage(src,alt,clss)
Creates a Bootstrap Text Box
Subclass of xTextBox
Constructor xbTextBox(text, clss)
Creates a Bootstrap Paragraph
Subclass of xPara
Constructor xbPara(text, clss)
Creates a Bootstrap Alert element
Subclass of xSection
Constructor xbAlert(clss)
Creates a Bootstrap Jumbotron element
Subclass of xSection
Constructor xbJumbotron()
Creates a Layout
Subclass of xLayout
Constructor xbLayout(rows,cols,widths,clss)
Creates a Bootstrap panel
Subclass of xPanel
Constructor xbPanel(clss)
Creates a Bootstrap panel with title
Subclass of xTitlePanel
Constructor xbTitlePanel(title, clss)
Creates a Bootstrap table
Subclass of xTable
Constructor xbTable(clss)
Creates a Bootstrap table in which cells contain xElements
Subclass of xElementsTable
Constructor xbElementsTable(clss)
Creates a Bootstrap tabed navigation element.
Subclass of xTwoElementSection
Redefines removeAuxElement(element)
Constructor xbTabs(clss)
Adds a pane to the xbTab
Removes a pane from the xbTab
Activates a pane at the specified index.
Creates a Bootstrap pane element for inclusion in an xbTab.
Subclass of xSection
Constructor xbTabPane(clss)
Creates a Bootstrap Nav Bar element.
Subclass of xSection
Constructor xbNavBar(title,clss)
Adds a dropdown menu to the xbNavBar.
Adds an item to the xbNavBar.
Retrieves an item from the xbNavBar at the specified index.
Creates a Bootstrap Nav Bar dropdown element for inclusion in an xbNavBar.
Subclass of xList
Constructor xbNavBarDropdown(title,clss)
Adds an item to the xbNavBarDropdown at the specified index.
Adds a divider to the xbNavBarDropdown.
Adds a wrapper element for the xbNavBarDropdown title.
Sets or removes the disabled state of the xbNavDropdown.
Creates a Bootstrap Nav Bar item element for inclusion in an xbNavBar.
Subclass of xLink
Redefines bindFunction(f)
Constructor xbNavBarItem(label,clss)
Sets or removes the disabled state of the xbNavBarItem.
Creates a Bootstrap Modal Dialog.
Subclass of xSection
Redefines show() hide() remove()
Constructor xbModal(title,clss,dlg_clss)
Adds an element to the xbModal footer.
Adds an element to the xbModal body.
Adds a close xbButton to the xbModal.
Sets the autoremove mode, in which the xbModal is removed from the DOM when closed.
Creates a Bootstrap xbButton which opens a linked xbModal.
Subclass of xbButton
Constructor xbModalOpenButton(label,modal,clss)
Creates an xLink element which opens a linked xbModal.
Subclass of xLink
Constructor xbModalOpenLink(label,modal,clss)
Creates a Bootstrap list-group element.
Subclass of xLink
Constructor xbListGroup(clss)
Adds an item to the xbListGroup.
Creates a Bootstrap list-group item element.
Subclass of xSection
Constructor xbListGroupItem(label,clss)
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)
Selects a Bootstrap theme.
Abstract class for field validators.
Constructor xbValidator()
Validate value
Creates a not empty field validator.
Subclass of xbValidator
Redefines validate(value)
Constructor xbNotEmptyValidator()
Creates a validator for email fields.
Subclass of xbValidator
Redefines validate(value)
Constructor xbEmailValidator()
Creates a validator for telephone fields.
Subclass of xbValidator
Redefines validate(value)
Constructor xbTelValidator()
Creates a not zero validator.
Subclass of xbValidator
Redefines validate(value)
Constructor xbNotZeroValidator()
Basic CRUD field.
Constructor xbField(type,title,name,inList,inSearch)
Returns the title of the field.
Returns the name of the field.
Sets the readonly attribute of the field.
Formats the value according to the field type.
Sets the value of the field.
Clears the field.
Returns the xbInput object corresponding to the field.
Returns the current value of the field.
Adds a validator to the field.
Validate the field. Returns true if the value of the field is validated by all validators.
Text Area field.
Subclass of xbField
Redefines getInput()
Constructor xbTextAreaField(title,name,rows,inList,inSearch)
Checkbox field.
Subclass of xbField
Redefines getInput() getValue() setValue(value) format(value) clear()
Constructor xbCheckboxField(title,name,onval,offval,inl,ins)
List field.
Subclass of xbField
Redefines getInput() format(value) clear()
Constructor xbListField(type,title,name,inList,inSearch)
Add an option to the List Field with the specified label and value.
Add options to the List Field.
List field where options are obtained from a database table.
Subclass of xbListField
Constructor xbTableListField(database,title,name,table,field,inList,inSearch)
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)
Add a field to the xbTableMaint.
Clears the search restriction.
Generates the list view.
Generates the record view for the specified id.
Generates the search panel.
Generates a list view with a search result.
Generates an empty form panel for a new record.
Reads the values of all fields in a form panel.
Validates all fields and return the result.
Inserts a new record into the database and presents a record view of the inserted record.
Presents an edit view for the record with specified id.
Saves in the database the edited record with specified id.
Deletes (after user confirmation) from the database the record with specified id.
Sets the parameters for the xbTableMaint when functioning as a linked table.
Starts processing CRUD operations by presenting an initial list view.
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.
Redefinable method in inherited class, called before generating the insert query, data in this.record.
Redefinable method in inherited class, called after sql insert, id is new id assigned on insert.
Redefinable method in inherited class, called before generating update query, data in this.record.
Redefinable method in inherited class, called after sql update.
Redefinable method in inherited class, called before generating delete query.
Redefinable method in inherited class, called after sql delete.
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(){}}.
Abstract class, base for other Android Interface classes.
Constructor xInterface()
Performs an Ajax GET request with the specified query that returns JSON data.
Performs an Ajax GET request with the specified query that returns raw data.
Performs an Ajax POST request with the specified query and data that returns raw data.
Performs an Ajax POST request with the specified query and data that returns JSON data.
SQLite Interface object class.
Subclass of xInterface
Constructor xSQL()
Opens and creates if it does not exist a SQLite database.
Executes an SQL statement that is not a select or insert.
Execute an insert SQL query. Returns the rowid of the inserted row, -1 if en error occurred.
Execute a select SQL query. Returns the cursor handle. -1 if an error occurred.
Returns the number of rows selected after an sqlSelect call
Go to the last row of the current cursor.
Retrieves the next row in the cursor as a Javascript object, false if past the end of the cursor.
Retrieves the previous row in the cursor as a Javascript object, false if before the start of the cursor.
Closes the current cursor.
Closes the current Data Base.
Deletes a database.
File IO Interface object class.
Subclass of xInterface
Constructor xFile()
Opens a file.
Lists files, returns an array of objects with attributes: path, fname, directory, lastmodified, length. or false.
Creates a directory.
Gets the absolute path of External Storage in the Android system.
Closes the current file.
Delete the current file
Reads the contents of the current file and returs them as a string.
Writes to the current file.
File Export Interface object class.
Subclass of xInterface
Constructor xExportFile()
Creates a file to be exported.
Gets the created file for download.
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()
Gets data from a server at the specified url.
Gets data from a server at the specified url issuing a POST request.
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(); }