<% set page = new AjaxedPage page.title = "my first ajaxed page" page.draw() sub main() .'the execution starts here end sub % >
<% sub pagePart_one() % > .some bold text <% end sub sub main() % > . .load page part one <% end sub % >
<% sub callback(action) .if action = "add" then page.return(2 + 3) end sub % >
<% sub main() .id = page.QS("id") ' = request.queryString("id") .name = page.RF("name") ' = request.form("name") .save = page.RFHas("save") 'checks if "save" is not empty .'automatically try to parse a querystring value into an integer. .id = str.parse(page.QS("id"), 0) end sub % >
<% page.headerFooter = array("pageHeader", "pageFooter") % >
ajaxed.callback('profile', 'userProfile')
ajaxed.callback('info', updateInfo, {id: 1})
ajaxed.callback('getSales', gotSales, {year: <%= year(date()) % >, month: <%= year(date()) % >})
<% if page.isPostback() then .str.write(page.RFA("test")(0)) 'writes 1 .str.write(page.RFA("test")(1)) 'writes 2,3 end if % >
>
<% 'ensures that a posted value ID always is an integer ID = page.RFP("id", 0) if ID <= 0 then lib.error("wrong ID") 'now we can use it e.g. within the database set RS = lib.getRS("SELECT * FROM table WHERE id = {0}", ID) % >
set RS = db.getRecordset("SELECT * FROM user")
set RS = lib.getRS("SELECT * FROM users WHERE name = '{0}'", "john")
set val = db.getScalar("SELECT sales FROM table", 0)
set RS = db.getUnlockedRecordset("SELECT * FROM user")
<% sql = "SELECT * FROM user WHERE login = " & db.SQLSafe(username) % >
<% 'updates the firstname of all records of the table "person" 'to the value "leila" updated = db.update("person", array("firstname", "leila"), empty) str.writef("Updated {0} records", updated) % >
<% 'container with an array as datasource set dc = (new DataContainer)(array(1, 2, 3)) 'container with a dictionary as datasource set dc = (new DataContainer)(lib.newDict(1, 2, 3)) 'container for a recordset set dc = (new DataContainer)(lib.getRS("SELECT * FROM table")) % >
<% set dc = (new DataContainer)(array(1, 2, 3)) 'check if a given value exists in the container dc.contains(2) 'its even possible in one line ((new DataContainer)(array(1, 2, 3))).contains(2) % >
<% 'first we get the current page from querystring and parse it so its always a number currentPage = str.parse(page.QS("page"), 0) pages = ((new DataContainer)(data)).paginate(10, currentPage, 3) 'results in an array which contains the following values '... 4 5 6 ... % >
<% link = "{1}" str.write(str.format(link, array(1, "<<"))) str.write(str.format(link, array(currentPage - 1, "< prev"))) for each p in pages .p = str.parse(p, 0) .display = lib.iif(currentPage = p, "" & p & "", p) .str.write(lib.iif(p > 0), str.format(link, array(p, display)), "...") next str.write(str.format(link, array(currentPage + 1, "next >"))) str.write(str.format(link, array(empty, ">>"))) % >
There are only 3 pages [1, 2, 3] There are pages before the 3rd page and pages after the 5th ["...", 3, 4, 5, "..."] There are only page before or only after ["...", 3, 4, 5] [1, 2, 3, "..."] only one page [1]
<% set d = (new DataContainer)(array(1, 2, 3)) '=> 1 - 2 - 3 str.write(d.toString(" - ")) set d = (new DataContainer)(lib.newDict(empty)) d.data.add 1, "foo" d.data.add 2, "some" '=> 1 foo, 2 some str.write(d.toString(", ")) '=> 1 -> foo, 2 -> some str.write(d.toString(array(", ", " -> "))) % >
<% set dt = new Datatable set page = new AjaxedPage page.draw() sub init() .dt.sql = "SELECT * FROM user" .dt.sort = "firstname" end sub sub callback(a) .dr.draw() end sub sub main() .dt.draw() end sub % >
<% dt.newColumn("firstname", "Firstname")% >
<% dt.customControls = "dtCustomControls" sub dtCustomControls(callerDT) % > .Please click the button to print: .print <% end sub % >
<% dt.onRowCreated = "onRow" sub onRow(callerDT) .callerDT.row.disabled = callerDT.data("deleted") = 1 .if callerDT.data("deleted") = 1 then callerDT.row.class = "deleted" end sub % >
<% set c = dt.newColumn("firstname", "Firstname") c.cssClass = "colFirstname" % >
th.colID { .font-weight:bold; } td.colID { .color:#0f0; }
<% function onFirstname(dt) .color = lib.iif(dt.data("deleted") = 1, "#f00", "#000") .onFirstname = "" & dt.col & "" end function % >
<% dt.selection = "multiple" dt.onRowCreated = "onRow" sub onRow(callerDT) .callerDT.row.selected = callerDT.row.number <= 10 end sub % >
<% (new Dropdown)("SELECT * FROM table", "name", "selected").toString() % >
<% (new Dropdown)(lib.range(1, 12, 1), "month", month(date())).toString() % >
<% 'simple number output = (new JSON)("myNum", 2, false) 'generates {"myNum": 2} 'array with different datatypes output = (new JSON)("anArray", array(2, "x", null), true) 'generates "anArray": [2, "x", null] '(note: the last parameter was true, thus no surrounding brackets in the result) % >
<% 'by default we disable the logging AJAXED_LOGLEVEL = 0 sub envDEV() .'but we enable it on the dev environment .AJAXED_LOGLEVEL = 1 end sub % >
<% 'the same as array("x") arr = lib.arrayize("x") 'the same as array("x", "y") arr = lib.arrayize(array("x", "y")) 'or use the shortcut alias arr = ["O"](array(1, 2, 3)) % >
<% set f = getFunction("test") : f % >
<% cssClass = lib.iif(i mod 2 = 0, "even", "odd") % >
<% 'a function which accepts options function doSomething(options) .lib.options array("a", "b"), options, 0 .'or you can also use the alias .["O"] array("a", "b"), options, 0 .'now the variable options has been transformed into an optionshash... .str.write(options("a")) .str.write(options("b")) end function 'now calling the function in various ways.. doSomething(array("a", 1, "b", 2)) 'prints: 12 doSomething(array("b", "cool")) 'prints: cool doSomething(empty) 'prints: 00 % >
<% 'valid options array("option1", "value1", "option2", "value2") array("option1", empty) array() 'invalid options array("option1", "value1", "option2") % >
<% countryCode = local.locateClient(2, empty) if isEmpty(countryCode) then str.writeEnd("Service unavailable") if countryCode = "XX" then str.writeEnd("Location unknown") 'if location was found then the country is available for sure str.writef("You are located in '{0}', arent you?", countryCode) % >
<% lib.logger.debug("some debug message") lib.logger.warn("a warning like e.g. use method A instead of B") lib.logger.info("user logged in") lib.logger.error("some error happend") % >
<% set r = new RSS r.url = "http://somehost.com/somefeed.xml" r.load() if r.failed then lib.error("could not read feed. could be down or wrong format") for each it in r.items .str.write(r.title & "") next % >
<% set r = new RSS r.title = "My new ajaxed feed" r.description = "important stuff" r.language = "en" r.link = "http://mysite.com" set RS = db.getRS("SELECT * FROM news ORDER BY published_on DESC LIMIT 10", empty) while not RS.eof .if isEmpty(pubDate) then pubDate = cDate(RS("published_on")) .set it = new RSSItem .it.author = RS("author") .it.description = RS("excerpt") .it.link = "http://mysite.com/news/?" & RS("id") .it.guid = it.link .it.title = RS("title") .it.publishedDate = cDate(RS("published_on")) .r.addItem(it) .RS.movenext() wend if isEmpty(pubDate) then pubDate = now() r.publishedDate = pubDate set xml = r.generate("RSS2.0", empty) xml.save(response) % >
<% set output = new StringBuilder output("some text") output("some other text") % > <%= output.toString() % >
<% str.arrayToString(array(1, 2, 3), ",") '=> 1,2,3 % >
<% str.change("somestring", array(1, 2), array(3)) % >
'gets the ID value from querystring and ensures its an integer. 'if it cannot be parsed then always 0 is returned id = str.parse(page.QS("id"), 0) 'the same with a form value id = str.parse(page.RF("id"), 0) 'parsing to a float number nr = str.parse("212.22", 0.0)
<% 'e.g. US str.parse("12.3", 0.0) ' => 12.3 str.parse("12,3", 0.0) ' => 123 'e.g. Germany str.parse("12.3", 0.0) ' => 123 str.parse("12,3", 0.0) ' => 12.3 % >
<% str.rReplace("i am 20 and he is 10", "(\d)", "($1)", true) % >
<%= str.shorten("some value", 10, "...") % >
<% sql = "SELECT * FROM user WHERE login = " & str.SQLSafe(username) % >
<% set tf = new TestFixture tf.run() sub test_1() .tf.assert 1 = 1, "1 is not equal 2" .'Lets test if our home page works .tf.assertResponse "/default.asp", empty, "Welcome", "Welcome page seems not to work" end sub % >
<% 'this will fail assertResponse 1, 2, "values are not equal" 'array equality (will pass) assertResponse array(1, 2), array(1, 2), "arrays are not equal" 'array equality (both will fail) assertResponse array(1, 2), array(1, 3), "arrays are not equal" assertResponse array(1, 2), array(1), "arrays are not equal" % >
<% 'these will pass assertInDelta 10, 11, 1, "Something is wrong" assertInDelta 5.4, 5.4, 0.1, "Something is wrong" assertInDelta 5.4, 5.3, 0.1, "Something is wrong" 'those will fail assertInDelta 4.4, 4.5, 0.1, "Something is wrong" assertInDelta 33, 12, 10, "Something is wrong" % >
<% 'checks if the default.asp contains a tag assertResponse "/default.asp", empty, ".*", "Default.asp seem not to work" 'checks if the login.asp contains a tag with a css class "error" when being posted assertResponse array("POST", "/login.asp"), empty, "", "Using login without any credentials should return an error" % > byVal url byVal params pattern [string]regex pattern which will be checked against after url has been fetched msg
<% set t = new TextTemplate t.filename = "/sometemplatefile.txt" t.add "name", "John Doe" email.subject = t.getFirstLine() email.body = t.getAllButFirstLine() % >
<<< BLOCK DETAILS >>> Name: <<< NAME >>> <<< BLOCKEND DETAILS >>>
<% vars = array(var1, value1, var2, value2, ...) % >
<% set v = new Validator if lastname = "" then v.add "lastname", "Lastname cannot be empty" if str.parse(age, 0) <= 0 then v.add "age", "Age must be a number and greater than 0" if v then .save() else .str.write(v.getErrorSummary("", "", "", "")) end if % >
<% sub callback(a) .set v = new Validator .if str.parse(age, 0) <= 0 then v.add "age", "Age is invalid" .page.return v end sub % >
function validated(val) { .if (val.valid) $('someList').update(val.summary); }