Вы находитесь на странице: 1из 10

Ring Documentation, Release 1.5.

Next
cValues = left(cValues,len(cValues)-1) # remove last comma
cColumns = ""
for x in aColumns
cColumns += x + ","
next
cColumns = left(cColumns,len(cColumns)-1)
query("insert into " + cTableName + "("+cColumns+") values (" +
cValues + ")" )

Func Update nID

cStr = ""
for x in aColumns
cStr += x + " = '" + EscapeString(aPageVars[x]) + "' , "
# the space after comma is necessary
Next
cStr = left(cStr,len(cStr)-2)
query("update " + cTableName + " set " + cStr + " where id = " + nID )

Func UpdateColumn cColumn,cValue


query("update " + cTableName + " set " + cColumn + " = '" +
EscapeString(cValue) + "' where id = " + self.ID )

Func Count cValue

query("SELECT count(*) FROM " + cTableName +


" where "+cSearchColumn+" like '" + EscapeString(cValue) + "%'")
return queryValue()

Func Read nStart,nRecordsPerPage

query("SELECT * FROM "+ cTableName+" limit " + EscapeString(nStart) + "," +


EscapeString(nRecordsPerPage) )
aQueryResult = queryResult()

Func Search cValue,nStart,nRecordsPerPage

query("SELECT * FROM "+ cTableName+" where "+cSearchColumn+" like '" +


EscapeString(cValue) + "%'" +
" limit " + EscapeString(nStart) + "," + EscapeString(nRecordsPerPage) )
aQueryResult = queryResult()

Func Find nID

query("select * from " + cTableName + " where id = " + EscapeString(nID) )


aResult = queryResult()[1]
# move the result from the array to the object attributes
ID = nID
cCode = ""
for x = 2 to len(aResult)
cCode += aColumns[x-1] + " = hex2str('" + str2hex(aResult[x]) + "')" + nl
next
eval(cCode)

Func FindWith cColumn,cValue

47.23. Database, ModelBase & ControllerBase classes 395


Ring Documentation, Release 1.5.1

query("select * from " + cTableName + " where "+cColumn+" = '" +


EscapeString(cValue) + "'" )
aResult = queryResult()
if len(aResult) > 0
aResult = aResult[1]
else
return 0
ok
# move the result from the array to the object attributes
ID = aResult[1]
cCode = ""
for x = 2 to len(aResult)
cCode += aColumns[x-1] + " = hex2str('" + str2hex(aResult[x]) + "')" + nl
next
eval(cCode)
return 1

Func Delete ID

query("delete from " + cTableName + " where id = " + EscapeString(ID) )

Func Clear

cCode = ""
for x in aColumns
cCode += x + ' = ""' + nl
next
eval(cCode)

Func LoadModel

# create the columns array


query("SELECT * FROM "+ cTableName + " limit 0,1")
aQueryResult = QueryResultWithColumns()[1]
for x = 2 to len(aQueryResult)
aColumns + lower(trim(aQueryResult[x]))
next

# create attribute for each column


for x in aColumns
addattribute(self,x)
next

Func Connect

Super.Connect()
if nLoadModel = 0
nLoadModel = 1
LoadModel()
ok

private

nLoadModel = 0

Class ControllerBase

47.23. Database, ModelBase & ControllerBase classes 396


Ring Documentation, Release 1.5.1

nRecordsPerPage = 5
nRecordsCount = 0
nPagesCount = 0
nActivePage = 0

# Dynamic creation of oView = new tablenameView and oModel = new tablename.Model


classname = lower(classname(self))
if right(classname,10) = :controller
tablename = left(classname,len(classname)-10)
cCode = "oView = new " + tablename+"View" + nl
cCode += "oModel = new " + tablename+"Model" + nl
eval(cCode)
oModel.connect()
ok

cSearchName = "searchname"
cPart = "part"
cPageError = "The page number is not correct"
cLast = "last"
cOperation = "operation"
cRecID = "recid"

aColumnsNames = ["id"]
for t in oModel.aColumns
aColumnsNames + t
next

cMainURL = website + "?"

func Routing

switch aPageVars[cOperation]
on NULL showtable()
on :add addrecord()
on :save saverecord()
on :delete deleterecord()
on :edit editrecord()
on :update updaterecord()
off

func ShowTable

nRecordsCount = oModel.Count( aPageVars[cSearchName] )

nPagesCount = ceil(nRecordsCount / nRecordsPerPage)

if aPageVars[cPart] = cLast
aPageVars[cPart] = string(nPagesCount)
ok

nActivePage = number(aPageVars[cPart])
if nActivePage = 0 nActivePage = 1 ok

if ( nActivePage > nPagesCount ) and nRecordsCount > 0


ErrorMsg(cPageError)
return
ok

47.23. Database, ModelBase & ControllerBase classes 397


Ring Documentation, Release 1.5.1

nStart = (nActivePage-1)*nRecordsPerPage

if aPageVars[cSearchName] = NULL
oModel.Read( nStart,nRecordsPerPage )
else
oModel.Search( aPageVars[cSearchName],nStart,nRecordsPerPage )
ok

oView.GridView(self)

func AddRecord

oModel.clear()
oView.FormViewAdd(Self,:save,false) # false mean don't include record id

func SaveRecord

oModel.Insert()
oView.SaveView(self)

func EditRecord

oModel.Find( aPageVars[cRecID] )
oView.FormViewEdit(Self,:update,true) # true mean include record id

func UpdateRecord

oModel.update( aPageVars[cRecID] )
oView.UpdateView(self)

func DeleteRecord

oModel.Delete( aPageVars[cRecID] )
oView.DeleteView()

func braceend

oModel.Disconnect()

47.24 WebLib API

In this section we will see the web library functions, classes and methods.
Function Parameters Description
LoadVars None Save the request parameters and cookies to aPageVars List
WebPage None Create new object from the WebPage Class
BootStrapWebPage None Create new object from the BootStrapWebPage Class
HTMLSpecialChars cString Encode Special characters to HTML equivalent
Template cFile,oObject Execute Ring Code in cFile after accessing oObject using {}
Alert cMessage Generate HTML Web Page that display cMessage using JavaScript Alert()
HTML2PDF cString Generate and Display PDF File from HTML String (cString)
The Package System.Web contains the next classes

47.24. WebLib API 398


Ring Documentation, Release 1.5.1

Class Name Description


Application Contains methods for Encoding, Decoding, Cookies & More.
Page Contains methods to generate HTML pages.
ScriptFunctions Contains methods to generate some JavaScript Functions.
StyleFunctions Contains methods to generate CSS.
PageBuffer Generate HTML Page in memory (dont print the output).
HTML2PDF Generate PDF File from HTML code.
BootStrapPage Using BootStrap Library.
WebPage Generate page using objects for each element.
HtmlPage Like WebPage but doesnt print the output to stdout.
BootStrapWebPage Generate page using objects, using BootStrap Library.
ObjsBase Parent Class for page objects.
NewObjectsFunctions Methods to create new objects in the page or element.
H1 Wraps HTML H1.
H2 Wraps HTML H2.
H3 Wraps HTML H3.
H4 Wraps HTML H4.
H5 Wraps HTML H5.
H6 Wraps HTML H6.
P Wraps HTML P.
Link Wraps HTML link.
NewLine Wraps HTML NewLine.
Div Wraps HTML Div.
Form Wraps HTML Form.
Input Wraps HTML Input.
TextArea Wraps HTML TextArea.
Select Wraps HTML Select.
Option Wraps HTML Option.
Image Wraps HTML Image.
UL Wraps HTML UL.
LI Wraps HTML LI.
Table Wraps HTML Table.
TR Wraps HTML TR.
TD Wraps HTML TD.
TH Wraps HTML TH.
Audio Wraps HTML Audio.
Video Wraps HTML Video.
Nav Wraps HTML Nav.
Span Wraps HTML Span.
Button Wraps HTML Button.

47.24. WebLib API 399


Ring Documentation, Release 1.5.1

47.25 Application Class

Method Parameters Description


DecodeString cString Decode request parameters
Decode cString Decode multipart/form-data
GetFileName aArray,cVar Get File Name in aArray using cVar
SetCookie name,value,expires,path,domain,secure Set Cookie
Cookie name,value Set Cookie using name and value only
GetCookies None Get Cookies
URLEncode cString URL Encode
ScriptLibs None Add JavaScript Libraries like BootStrap
Print None Print Page Content
Style cStyle Add cStyle to page CSS content
StartHTML None Add HTTP Header to page content
The method DecodeString is used to get HTTP request parameters.
The methods Decode and GetFileName are used for uploading files.
The methods SetCookie, Cookie & GetCookies are used for adding and reading cookies.
The methods StartHTML, ScriptsLibs, Style & Print are used for page structure and JS/CSS support.
The method URLEncode is used to encode a URL to be used in HTML pages.

47.26 Page Class

Method Parameters Description


text x add HTMLSpecialChars(x) to page content (accept strings and numbers)
html cString add html code to page content
h1 x add x to page content between <h1> and </h1>
h2 x add x to page content between <h2> and </h2>
h3 x add x to page content between <h3> and </h3>
h4 x add x to page content between <h4> and </h4>
h5 x add x to page content between <h5> and </h5>
h6 x add x to page content between <h6> and </h6>
p aPara HTML <p> </p>, uses aPara List as Hash to get attributes
NewLine None add <br /> to page content
AddAttributes aPara Convert aPara list as hash to HTML element attributes
Link aPara HTML <a href> and </a>, uses aPara List as Hash to get attributes
Image aPara HTML <img>, uses aPara List as Hash to get attributes
Button aPara HTML <input type=button>, uses aPara List as Hash to get attributes
ButtonLink aPara HTML <input type=button>, uses link attribute to navigate to link
Textbox aPara HTML <input type=text>, uses aPara List as Hash to get attributes
Editbox aPara HTML <textarea> and </textarea>, uses aPara to get attributes
Combobox aPara HTML <select>, uses items attribute as list for <option>
Listbox aPara HTML <select multiple=multiple>, uses items attribute for <option>
ulstart aPara HTML <ul>
ulend aPara HTML </ul>
listart aPara HTML <li>
liend aPara HTML </li>
Continued on next page

47.25. Application Class 400


Ring Documentation, Release 1.5.1

Table 47.2 continued from previous page


Method Parameters Description
List2UL aList Generate HTML <ul> including items from Ring List items
DivStart aPara HTML <div>, uses aPara List as Hash to get attributes
NavStart aPara HTML <nav>, uses aPara List as Hash to get attributes
SpanStart aPara HTML <span>, uses aPara List as Hash to get attributes
BoxStart None Generate Div with black background to be used as page header
DivEnd None HTML </div>
NavEnd None HTML </nav>
SpanEnd None HTML </span>
BoxEnd None HTML </div>, the same as divend()
FormStart cAction HTML <form>, with cAction as the action attribute or an empty value
FormPost cAction HTML <form method=post> , with cAction as the action attribute
FormEnd None HTML </form>
Submit aPara HTML <input type=submit>
Hidden cName,cValue HTML <input type=hidden>
FormUpload x HTML Form, method=post enctype=multipart/form-data and x = action
UploadFile x HTML <input type=file> and name = x
Video aPara HTML <video>
Audio aPara HTML <audio>
GetColor aPara Select Color
Radio aPara HTML <input type=radio>
Checkbox aPara HTML <input type=checkbox>
Spinner aPara HTML <input type=number>
Slider aPara HTML <input type=range>
TableStart aPara HTML <table>
TableEnd None HTML </table>
RowStart aPara HTML <tr>
RowEnd None HTML </tr>
CellStart aPara HTML <td>
CellEnd None HTML </td>
HeaderStart aPara HTML <th>
HeaderEnd None HTML </th>

aPara in the page methods is a list contains attributes and values. Using aPara we can set values for the next attributes
classname id name align style dir value onclick oncontextmenu ondblclick
onmousedown onmouseenter onmouseleave onmousemove onmouseover onmouseout
onmouseup onkeydown onkeypress onkeyup onabort onbeforeunload onerror
onhashchange onload onpageshow onpagehide onresize onscroll onunload
onblur onchange onfocus onfocusin onfocusout oninput oninvalid onreset
onsearch onselect onsubmit ondrag ondragend ondragenter ondragleave
ondragover ondragstart ondrop oncopy oncut onpaste onafterprint
onbeforeprint oncanplay oncanplaythrough ondurationchange onemptied
onended onloadeddata onloadedmetadata onloadstart onpause onplay
onplaying onprogress onratechange onseeked onseeking onstalled onsuspend
ontimeupdate onvolumechange onwaiting animationend animationiteration
animationstart transitionend onmessage onopen onmousewheel ononline
onoffline onpostate onshow onstorage ontoggle onwheel ontouchcancel
ontouchend ontouchmove ontouchstart color opacity background backgroundattachment
backgroundcolor backgroundimage backgroundposition backgroundrepeat backgroundclip
backgroundorigin backgroundsize border borderbottom borderbottomcolor
borderbottomleftradius borderbottomrightradius borderbottomstyle borderbottomwidth
bordercolor borderimage borderimageoutset borderimagerepeat borderimageslice

47.26. Page Class 401


Ring Documentation, Release 1.5.1

borderimagesource borderimagewidth borderleft borderleftcolor borderleftstyle


borderleftwidth borderradius borderright borderrightcolor borderrightstyle
borderrightwidth borderstyle bordertop bordertopcolor bordertopleftradius
bordertoprightradius bordertopstyle bordertopwidth borderwidth boxdecorationbreak
boxshadow bottom clear clip display float height left margin marginbottom marginleft
marginright margintop maxheight maxwidth minheight minwidth overflow overflowx
overflowy padding paddingbottom paddingleft paddingright paddingtop position
right top visibility width verticalalign zindex aligncontent alignitems alignself
flex flexbasis flexdirection flexflow flexgrow flexshrink flexwrap justifycontent
order hangingpunctuation hyphens letterspacing linebreak lineheight overflowwrap
tabsize textalign textalignlast textcombineupright textindent textjustify
texttransform whitespace wordbreak wordspacing wordwrap textdecoration
textdecorationcolor textdecorationline textdecorationstyle textshadow
textunderlineposition @fontface @fontfeaturevalues font fontfamily fontfeaturesettings
fontkerning fontlanguageoverride fontsize fontsizeadjust fontstretch fontstyle
fontsynthesis fontvariant fontvariantalternates fontvariantcaps fontvarianteastasian
fontvariantligatures fontvariantnumeric fontvariantposition fontweight direction
textorientation unicodebidi writingmode bordercollapse borderspacing captionside
emptycells tablelayout counterincrement counterreset liststyle liststyleimage
liststyleposition liststyletype @keyframes animation animationdelay animationdirection
animationduration animationfillmode animationiterationcount animationname
animationplaystate animationtimingfunction backfacevisibility perspective
perspectiveorigin transform transformorigin transformstyle transition
transitionproperty transitionduration transitiontimingfunction transitiondelay
boxsizing content cursor imemode navdown navindex navleft navright navup
outline outlinecolor outlineoffset outlinestyle outlinewidth resize textoverflow
breakafter breakbefore breakinside columncount columnfill columngap columnrule
columnrulecolor columnrulestyle columnrulewidth columnspan columnwidth columns
widows orphans pagebreakafter pagebreakbefore pagebreakinside marks quotes
filter imageorientation imagerendering imageresolution objectfit objectposition
mask masktype mark markafter markbefore phonemes rest restafter restbefore
voicebalance voiceduration voicepitch voicepitchrange voicerate voicestress
voicevolume marqueedirection marqueeplaycount marqueespeed marqueestyle datatoggle
dataride datatarget dataslideto dataslide datadismiss dataplacement datacontent
datatrigger dataspy dataoffset dataoffsettop

47.27 ScriptFunctions Class

This class contains methods for adding JavaScript code to the generated web page.
The class methods are merged to the Page class, so we can use the next methods with page objects directly.
Method Parameters Description
Script cCode Add cCode string between <script> and </script>
ScriptRedirec- cURL set window.location to cURL
tion
ScriptFunc cFuncName,cCode Define function cFuncName that contains cCode
ScriptFuncAlert cFuncName,cMsg Define function cFuncName that uses alert() to print
cMsg
ScriptFuncAjax cFuncName,cLink,cDiv Define function cFuncName that load cLink in cDiv
ScriptFuncClean cFuncName,cDiv Define function cFuncName that clear the cDiv
ScriptFuncSe- cF,aL,cD,cR,cGR,cFC,nTO,cL1,cL2 Used to Edit/Delete Grid Record
lect
ScriptScroll- cDiv,nSize Set cDiv as Fixed Div with Size = nSize
Fixed

47.27. ScriptFunctions Class 402


Ring Documentation, Release 1.5.1

47.28 StyleFunctions Class

This class contains methods for adding CSS to the generated web page.
Like ScriptFunctions Class, The StyleFunctions class methods are merged to the Page class, so we can use the next
methods with page objects directly.
Method Parameters Description
StyleFloatLeft None Return float: left ;
StyleFloatRight None Return float: right ;
StyleSizeFull None Return width: 100% ; height: 100% ;
Stylecolor x Return color: + x + ;
Stylebackcolor x Return background-color: + x + ;
StyleTextCenter None Return text-align: center ;
StyleTextRight None Return text-align: right ;
StyleTextLeft None Return text-align: left ;
StyleSize x,y Return width: + x + ; height: + y + ;
StyleWidth x Return width: + x + ;
StyleHeight x Return height: + x + ;
StyleTop x Return top: + x + ;
StyleLeft x Return Left: + x + ;
StylePos x,y Return top: + x + ; + Left: + y + ;
StyleHorizontalCenter None Return margin-right:auto ; margin-left:auto;
StyleMarginTop x Return margin-top: + x + ;
StyleMarginRight x Return margin-right: + x + ;
StyleMarginLeft x Return margin-left: + x + ;
StyleDivCenter nWidth,nHeight Create Div in the center of the page
StyleAbsolute None Return position:absolute ;
StyleFixed None Return position:fixed ;
StyleZIndex x Return z-index: + x + ;
StyleFontSize x Return font-size: + x + ;
StyleGradient x Generate Gradient (x values from 1 to 60)
StyleTable None Set table properties
StyleTableRows id Set different color to even and odd rows in the table
StyleTableNoBorder None Return border-style: none;

47.29 WebPage Class

We use braces to access the active WebPage object attributes


Each one of these attribute will return a new object to access again using braces.

47.28. StyleFunctions Class 403


Ring Documentation, Release 1.5.1

Attribute Description
H1 Wraps HTML H1.
H2 Wraps HTML H2.
H3 Wraps HTML H3.
H4 Wraps HTML H4.
H5 Wraps HTML H5.
H6 Wraps HTML H6.
P Wraps HTML P.
Link Wraps HTML link.
NewLine Wraps HTML NewLine.
Div Wraps HTML Div.
Form Wraps HTML Form.
Input Wraps HTML Input.
TextArea Wraps HTML TextArea.
Select Wraps HTML Select.
Option Wraps HTML Option.
Image Wraps HTML Image.
UL Wraps HTML UL.
LI Wraps HTML LI.
Table Wraps HTML Table.
TR Wraps HTML TR.
TD Wraps HTML TD.
TH Wraps HTML TH.
Audio Wraps HTML Audio.
Video Wraps HTML Video.
Nav Wraps HTML Nav.
Span Wraps HTML Span.
Button Wraps HTML Button.

47.30 HtmlPage Class

The same as the WebPage class with the next changes


1. No output to the stdout
2. Provide the Output Method to get the output
Syntax:
output() ---> The output as string

47.30. HtmlPage Class 404

Вам также может понравиться