ajaxed 1.0 released

By | April 15, 2008

the new major release of asp ajaxed is here. I have jumped with counting to version 1.0 because it has been such a big update and the library reached its maturity level. Curious whats new in the box? A lot of improvements and new stuff – i got a lot of inspiration from ruby on rails as well and the biggest goodie is an own developer console with unit tests, documentation creator…

ajaxed1.gifajaxed2.gif

For all who cannot wait go directly to the download and update to the new version.

Ok, so whats new in 1.0? I have aggregated all the comments and tried to implement all your requests. As I am developing with Ruby on Rails, I have added some rubyism to the whole library as well. Do I have to change my running system completely now? No! no need to panick. There are only two small things you need to prepare before upgrading to 1.0 (mentioned at the end of the article). Ok, let’s move to the updates…

ajaxed console
Probably the most fancy update is the new ajaxed console which supports you while you develop your applications. its immediately available through /ajaxed/console/ on your server. You’ll find there a lot of useful stuff like a test runner, current configuration, documentation creator, regular expression evaluator, etc. Check a demo of the console here

New ajaxed config
The ajaxed config (config.asp) has been moved to an own folder which is located in the webroot /ajaxedConfig/config.asp. Seperating the configuration from the library makes the update process easier now. You can overwrite the ajaxed library without any thoughts…

html, head and body tags integration (header & footer)
People used to have problems of integrating the html, head and body tags into their pages. This has been solved now and you can find a header.asp and footer.asp in your ajaxedConfig folder. Those files are automatically loaded within your pages. This change brought some additional features as well

  • ajaxedPage.defaultStructure property lets you load your page with a default header and footer (provided by the library itself). This is useful if you quickly need a standard structure and don’t really care about the details
  • ajaxedPage.title gives you the possibility to assign a title to your page which may be used in the header
  • ajaxedPage.plain property allows to render a page completely plain which means it renders only those things which are defined in the page itself. (no header and footer). You will need this for your XHR
  • lib.exec lets you call any function only if it exists. This is used within the header to allow page specific head elements. Whenever you want anything to appear in your header just add a header() sub to your page and place the stuff there. e.g. especially javascripts, styles
  1. <% sub header() %>
  2.     <style>
  3.         /* some styles */
  4.     </style>
  5.     <% page.loadJSFile "someJSFile.js" %>
  6. <% end sub %>

Best thing is you take a look into the predefined header.asp in your config to see whats going on there. And don’t forget it’s up to you what you bung in there. You can add as many lib.exec calls as you want.

Environment support
ajaxed supports two environments now: LIVE (production) and DEV (development). The config variable AJAXED_ENVIRONMENT sets the current environment. This enhancement allows us …

  • creating conditions dependent on the environment. lib.env, lib.DEV and lib.LIVE are helpers to check which environment is running.
  • setting ajaxedPage.onlyDev to true in order to prevent calling it on the LIVE environment. E.g. whole ajaxed console and tests are only available on DEV env yet.

(The default environment is always development)

Unit tests
TestFixture class lets you create unit tests for your own applications. It comes with a lot of different asserts (as commonly known in other unit testing frameworks) and is very quickly to set up. After you have written your tests you can run them directly from the ajaxed console. Tests for the library itself are located there as well. Here is an example of how you write a simple test (test file must start with test_):

  1. <!--#include virtual="/ajaxed/class_testFixture/testFixture.asp"-->
  2. <%
  3. set tf = new TestFixture
  4. tf.run()
  5.  
  6. 'create test methods starting with test_
  7. 'followed by an increasing number
  8. sub test_1()
  9.     tf.assertEqual "x", "x", "x should be x"
  10.     tf.assert 1 = 1, "one should be definitely one"
  11.     tf.assertInstanceOf "testFixture", tf, "this test should be a TestFixture"
  12.     tf.assertInDelta 1, 1.1, 0.1, "equality with a delta"
  13.     tf.assertHas array(1, 2, 3), 2, "the array should contain 2"
  14. end sub
  15. %>

Documentation generator (Documentor)
Some of you have long waited for the day to come :) Finally its here! Automatically create a documentation of your ASP code. The tool is called Documentor and can be found within your ajaxed console. It is also used for the generation of the actual ajaxed documentation which got a small face lift as well. Read How to document to know more about documenting your code (This manual can be found in your ajaxed console). Example of a method documentation:

  1. '' @DESCRIPTION: gets all users for a given country
  2. '' @PARAM: country [string]: specified country. e.g. AT
  3. '' @RETURN: [recordset]
  4. function getUsersBy(country)
  5. end function

Automatic version check
The ajaxed console checks automatically for a new version of ajaxed and reminds you if there is a new version available. Never miss an update.

MD5 hash class
We have a hash on board of the library now. Hash your passwords, etc. easily with:

  1. hash = (new MD5).hash("mypassword")

Database methods
There are some new useful database methods which makes your code more readable and easier to debug.

  1. 'get the number of records of a table
  2. numberOfRecords = db.count("tablename", empty)
  3.  
  4. 'get number of records with condition
  5. numberOfRecords = db.count("tablename", "active = 1")
  6.  
  7. 'insert a record into a table (returns the ID)
  8. ID = db.insert("tablename", array("firstname", "jack", "lastname", "johnson"))
  9.  
  10. 'updating a record
  11. db.update "tablename", array("firstname", "Johnny"), ID
  12.  
  13. 'works as well with condition
  14. db.update "tablename", array("firstname", "Johnny"), "firstname = 'Jack'"
  15.  
  16. 'delete a record with a condition
  17. db.delete "tablename", "active = 0"
  18.  
  19. 'delete with an ID
  20. db.delete "tablename", 10
  21.  
  22. 'toggle the value of bit fields.
  23. db.toggle "tablename", "active", "country = 'AT'"
  24.  
  25. 'or with ID
  26. db.toggle "tablename", "active", 10

Most of them support a condition parameter which can be either a number (its used automatically as ID) or a string (which is a condition for the WHERE clause).
Those are handy for common CRUD operations. If you need more sophisticated stuff you should still use db.getRecordset().

RSS reader and writer
If you ever want to generate an RSS feed in your application or read another one – it’s no problem anymore. ajaxed has the right component inside. There is a full detailed article about this component here.

  1. 'example of reading some feed
  2. set r = new RSS
  3. r.url = "http://domain.com/feed"
  4. r.load()

Template class
ajaxed 1.0 includes a template class called TextTemplate. Very useful if you send emails within your applications. Create an template for the content of your email and parse it using TextTemplate. The ajaxed console provides a simple management of templates. For more details about TextTemplate read the article Template component for classic ASP or check the ajaxed documentation. Simple example

  1. set t = new TextTemplate
  2. t.filename = "mytemplate.template"
  3. t.add "name", "jack johnson"
  4.  
  5. 'your email object
  6. 'i use the first line of the template as the subject of my emails
  7. mail.subject = t.getFirstLine()
  8. mail.body = t.getAllButFirstLine()

Cache component
Caching data, rss feeds, etc. globally for all visitors can be achieved now with the Cache class. This class has been around for while as well and a details article is available here

Discussion group launched
Google GroupsI have created an own google asp ajaxed discussion group for better support and communication with all ajaxed users.

Minor changes/improvements

  • init() must not exist necessarily anymore. If it exists it will be called. if not then not ;) Thanks to the new lib.exec() and lib.getFunction(). Check the reference for more details.
  • str.matching checks a string against a given regular expression pattern. Is much more readable then creating the regex object over and over again.
  • An error will be raised if there is no main() in your page. Makes it easier to know whats going on…
  • lib.contains is a useful function which lets us check if a given value exists in a given data structure. Currently supported data structures are array and dictionary. Usage is easy: lib.contains(array("yes", "no"), "maybe")
  • script.aculo.us is now part of the library as well. I decided to do this as it plays very nicely with prototype and both are being used in ruby on rails successfully for a long time.
  • some more minor improvements and bug fixed which you bette look up in the changes.txt or directly in the SVN

That was it. Hope you enjoy working with the new version and I am looking forward for your feedback .. which already made the library what it is! Here are some things i am working on already…

  • generic email class
  • automatically notify admin about ANY errors
  • plugin infrastructure
  • asserts for request and response
  • logging possibilities
  • validator for business objects
  • dropdown control and calendar control

If you UPGRADE from 0.3 then the only thing you need to do is to move your config.asp into the new /ajaxedConfig/ folder. Last but not least create a header.asp and footer.asp in that folder. Put all your html, head and body tags there. You can use the existing ones and adopt them to your needs. Last but not least change AJAXED_ENVIRONMENT to your needed environment.

Download ajaxed 1.0

If you want to live on the edge then grab the latest version from SVN.

15 comments on “ajaxed 1.0 released

  1. thank you for tutarial.nice ..

  2. Hey man, Congrats, looks great.

    I like the documentor! :-)

  3. this is amazing! great job Michal!

  4. rolphes on said:

    Cool, thanks for all the work!

    One remark concerning the escape function in the JSON class:

    I’ve observed that the escape function can be pretty slow when a lot of data is passed to this function (amongst other things I use ajaxed to sort tables with 400+ rows – then the escape function takes up to 5 seconds).

    To accelerate this process I have written my own escape function which replaces only the slashes and the double quote by their unicode representation:

    public function escape(val)
    val = replace(val,”",”u005c”)
    val = replace(val,”/”,”u002F”)
    val = replace(val,”"”",”u0022″)
    escape = val
    end function

    So for my purpose the function is now much faster and works without any problems (also for special french or german characters). But I’ve no idea if this solution is usful in all cases.

  5. rolphes you are right that could be very time consuming if there is a lot of data … i have some idea of optimizing it but i am not sure if it will work.
    btw: if you get a lot of data you should rather consider making an own page which will be called with Ajax.Updater from prototype .. this is a much quicker way…

  6. This is fantastic work, well done indeed!

    I have a suggestion. How about having a separate demo page (similar to the one on Scriptaculous) that has a bunch of demos on it?

    I also have a question about Autocompleter. Is it supported? Is there a database version of it?

  7. Qwaider , i want to provide more samples .. you can find some in the “ajaxed” category already …
    what do you mean by the autocompleter support? you can use it as scriptaculous is included … but there are no specific asp wrappers.

  8. rolphes on said:

    Thanks for your answer. I will try the Ajax.Updater function …

  9. Dave on said:

    I want to create cascading classic asp comboboxes on one page.
    I need to do this with some kind of Ajax so the classic ASP page does not refresh.

    something like this:

    Step 1: you select a value on ComboBox1, this fires Javascricpt fcn QueryDb

    Step2: Use ajax to query database based on selected value from ComboBox1

    Step3: Populate ComboBox2 based on values returned from the database

    The biggest puzzle for me is step 2 but I also need to bind the returned data to ComboBox2 without a page refresh.

    Can I do this with your ajaxed 1.0 and if yes is there a code snippet to help me? Thanks for your time.

    Dave

  10. keran on said:

    Finally something for ASP :D

    Looks cool, had to test it….

    Little suggestion…. try to create Dreamweaver extension, there are many people which use ASP in Dreamweaver, but dont have any AJAX option. Im having real trouble with ASP and Mootols but somehow im managing all to work. There is new Adobe’s Spry, but those are only fancy effects

    Cheers mate

  11. can we have more than one sub main?

  12. vb you can only have one .. what do you need more for?

  13. Graeme on said:

    Michal,

    Just started a new job doing web dev and everyone is using ASP and doing stuff in a non Ajax way. Found your framework and everyone is loving it.

    Only minor suggestion I’d make is allow the user to specifiy the column to return as ID on DB insert. We had to change the code to make this work with our code etc.

    Thanks for the great work

    Graeme

  14. graeme good to hear u guys like it.. i dont fully understand what u mean allowing the user to specify to return the id.
    changes u do are okay but i would fully recommend u not doing it as you wont be compatible with the future versions.. the version 2.0 is coming soon with a lot cool stuff. just fyi

  15. Graeme on said:

    If we use db.insert (some SQL) etc then the code (as far as I understand) expects their to be a column called ID in the table. The code then returns this as the result of the insert function.

    If there is no ID column an error is thrown. We don’t want to label all our ID columns in our database ID (they are named for the table e.g. personid, addressid, etc). Therefore we have to change the code or it throws an error as we have no column called ID.

    Can’t wait to see version 2.0

    Thanks

Leave a Reply

*

* Copy This Password *

* Type Or Paste Password Here *

49,813 Spam Comments Blocked so far by Spam Free Wordpress