329 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Blogs | Search | myPL | About 
 
Latest 7 Posts
Lotus 1-2-3, SmartSuite and Organizer officially retired
Fri, May 17th 2013 210
Ender’s Game – First Movie Footage
Fri, May 3rd 2013 111
My recipes – All in one place
Mon, Apr 29th 2013 189
Useful utility to rename files in bulk
Tue, Apr 23rd 2013 139
The Enemy’s Gate is Down
Tue, Apr 16th 2013 242
How to set doctype on Notes forms
Thu, Apr 11th 2013 243
New LEGO Lord of The Rings sets this summer
Fri, Apr 5th 2013 294
Top 10
Review: Samsung Galaxy S3
Sun, Jun 24th 2012 2652
Code: Expanded Class for File Functions
Fri, Dec 21st 2012 783
Create and update Calendar reminders from Notes document
Thu, Aug 11th 2011 766
Code: Simple class for parsing file names
Thu, Dec 20th 2012 764
Creating PDF files from Notes documents
Thu, Nov 11th 2010 720
IBM Notes and Domino 9.0 Social Edition
Tue, Nov 13th 2012 674
Free Tool: Analyze ACL in Notes Application/Database
Tue, Nov 15th 2011 654
Export from Notes to Excel – 3 different ways
Wed, Nov 14th 2012 637
IBM Notes & Domino 9.0 Social Edition – Public beta now available!
Thu, Dec 13th 2012 611
How to write better code in Domino Designer – Part 1
Wed, Feb 20th 2013 580


YUI3: Poweful Javascript Framework
Karl-Henry Martinsson    

Last week I came up with a small side project. It was basically a simple web chat, working pretty much like the comments on a blog. I decided to build this as a classic Domino application, not using Xpages. I started development Wednesday mid-afternoon, and the application needed be done Thursday evening, and I of course had my regular job to do. So I could not justify spending the time I needed to learn doing it in Xpages, and then try to write CSS to get it to look like I wanted it. So there you have the reason for why I did not use Xpages.

I decided to take a look at YUI, the framework developed by Yahoo. The latest version is version 3, and it is really nice and powerful. I looked into in, and realized that I could do things very quickly, getting the same functionality as using Xpages (partial refresh  or page, etc) in just a few lines of code.

So what did I need for my application? I started with a blank Notes database. I created a page, which is where all the action would take place. On the page I created a header section (logo), a content section (where the messages/chat would be displayed) and a form section where I put a few fields for the users to fill out. The fields were name/handle, email, (optional) website and lastly the message to send. I also put two images there, one to use as a submit button, and one to refresh the chat content without having to submit a text.

I then added some javascript at the top, loading YUI3 (hosted by Yahoo, I did not even have to download anything) and then some code to do whatever I wanted to do. YUI works by binding functions to events on elements on the page. I wanted to bind function functions to the onClick event of the two buttons, "submit" and "refresh". To avoid this blog entry to be too long, I will just show the code behind the refresh button:

 Y.one('#refresh').on('click', function(e) {
        e.preventDefault();
        var contentcell = Y.one("#contentCell");
        if (contentcell) {
            var currentTime = new Date();
            Y.one('#refresh').set('src','webchat.nsf/ajax-loader-150.gif');
            contentcell.load("webchat.nsf/SendText?OpenAgent&refresh=true&datetime=" + currentTime.getTime(),"", function()  {
                Y.one('#refresh').set('src','webchat.nsf/refresh.png');
            } );
        }
    });

This code gets a reference to the first element with the id "refresh" using Y.one(), then bind a function to the "click" event. The function is defined right there, and it will do a couple of things. First it get a reference to the element (in this case a DIV) with the id  "contentCall". I check if it was found, and if so I get the current time (get a unique number). I then change the image of the refresh element to a spinning "loading" icon.

The next line is the coolest one. In one line of code I perform an Ajax call to an agent on the Domino server, and put the returned data into the contentcell element. Finally, after the server returns teh data, another function is called, which restored the refresh button to the original image.

The agent is written in Lotusscript, and it just read the existing chat entries from a database and output it using the print statement as HTML. I add the times in seconds as a second argument, just to get each call to be unique. Otherwise the returned data might be cached on the server and the user would not get the latest data.

The submit action is similar, the difference is that it read the values from the different fields on the form and submit them to the same agent as name-value pairs. The agent will detect that data is being passed to it, and will store the values in a new Notes document, then return HTML for all entries just like the refresh.

As you can see, a complete Ajax call (calling the server, waiting for data, gettingthe data back, replacing the content of an element on a page to perform a partial refresh and triggering additional code when the data has been returned) is just one line of code. Could not be much easier!

The actual application got more functionality, I check for certain required fields already in the web client, using javascript, I load up the content when the page is first opened (so the user does not have to press refresh to see anything), etc. The webchat is also just open specific times, when it is closed a message is displayed about when it will be open next, etc. The open/close is set by a Notes configuration document. Note: Do not use profile documents to store items for a web application, they get cached on the server and you will probably not get the latest data...

 



---------------------
http://www.bleedyellow.com/blogs/texasswede/entry/yui3framework
May 15, 2012
148 hits



Recent Blog Posts
210


Lotus 1-2-3, SmartSuite and Organizer officially retired
Fri, May 17th 2013 6:50a   Karl-Henry Martinsson
Earlier this week, IBM announced the withdrawal of marketing [sic!] of Lotus 1-2-3, together with Lotus SmartSuite and Lotus Organizer, effective 06/11/2013. Support ends on 09/30/2014. Lotus 1-2-3 version 3.0 for MS/DOS I personally never worked with 1-2-3 myself. When I started with computers in school, we used CP/M-86 as the operating system, and had a spreadsheet program developed specifically for use in the Swedish schools. My first job after high school was with Microsoft in 1988, so my fi [read] Keywords: formula language ibm lotus notes microsoft office properties
111


Ender’s Game – First Movie Footage
Fri, May 3rd 2013 1:45p   Karl-Henry Martinsson
Preview for the teaser trailer, to be released on May 7. You get to see about 10 seconds of movie footage here, and I have to say it looks pretty good to me. [read] Keywords:
189


My recipes – All in one place
Mon, Apr 29th 2013 11:06a   Karl-Henry Martinsson
For many years, I have enjoyed cooking and baking. One reason could be because I like good food. But it is also logical, similar to programming. You have instructions you follow, but you can still modify them, as long as you know how different ingredients react with each other and with heat, liquids, etc. Cooking is a combination of programming, chemistry and physics. Perfect for a geek! I often get questions about how I made a particular dish. Many of the recipes have been published on my blog, [read] Keywords:
139


Useful utility to rename files in bulk
Tue, Apr 23rd 2013 3:20p   Karl-Henry Martinsson
Earlier today I had to rename about 400 image files, and I was looking for a convenient tool that would help me out. I had to remove part of the filename, in the middle of the filename, which was a bit tricky. I found a very useful tool, called Bulk Rename Utility. It does not have the most user-friendly interface, but it is very powerful. And the best thing is that it is free. You can download it here. This is the somewhat messy but very powerful user interface… [read] Keywords: interface
242


The Enemy’s Gate is Down
Tue, Apr 16th 2013 5:04p   Karl-Henry Martinsson
Teaser poster for the upcoming movie adaptation of Orson Scott Card’s book Ender’s Game. I really enjoyed the book (as well as the parallel story in Ender’s Shadow), and hope the movie will stay at least somewhat close to the story in the books. According to the author, the movie will use elements from both books. If you haven’t read the books, I can highly recommend them. [read] Keywords: wiki
243


How to set doctype on Notes forms
Thu, Apr 11th 2013 1:29p   Karl-Henry Martinsson
Who redesigning my website to use Bootstrap, I ran into a problem. The navbar (meny) did not render correctly in Internet Explorer 9, despite looking perfect in Firefox and Internet Explorer 10. There are several discussions about this problem on StackOverflow and other forums, and the solution is simply to add on the first line of the HTML code. However, IBM Domino automatically adds a different doctype string, and there is no database or form property to change/set the correct value. But ther [read] Keywords: domino ibm lotusnotes notes database development firefox javascript twitter




294


New LEGO Lord of The Rings sets this summer
Fri, Apr 5th 2013 1:51p   Karl-Henry Martinsson
As the regular reader of this blog may have noticed, I am a huge Lord of the Rings fan, and I also enjoy building LEGO. There are four new LEGO sets in the Lord of The Rings series to be released this summer (in June, according to TheBrickBlogger.com). They are: 79005 – The Wizard Battle, 113 pieces, $12.99 79006 – The Council of Elrond, 243 pieces, $29.99 79007 – Battle at the Black Gate , 656 pieces, $59.99 79008 – Pirate Ship Ambush, 756 pieces, $99.99 Pictures below from The [read] Keywords:
573


Export Notes view to Excel – with multi-value fields
Fri, Apr 5th 2013 9:26a   Karl-Henry Martinsson
A few days ago, a question was asked on StackOverflow about how to export the content of a Notes view to Excel. The caveat was that some columns contained multiple values, but not on all documents. To solve this, I wrote a Lotusscript class that will export view data as either CSV or as an HTML table, both can then be saved to a file and opened in Excel. I am posting the code below. Enjoy! %REM Agent View Export Created Mar 27, 2013 by Karl-Henry Martinsson Description: Code to export a [read] Keywords: agent lotus lotusscript notes database server
491


Should everyone be a programmer?
Tue, Apr 2nd 2013 2:47p   Karl-Henry Martinsson
For years, there has been a debate if anyone can (or should) learn programming or not. While reading the Notes and Javascript groups on LinkedIn, as well as the Notes forums on IBM developerWorks, I have read more than one post where someone wants to learn Javascript or Notes programming, but don’t have any programming experience/knowledge. Can anyone learn to program? No. I would say half the population could learn at least the basics and mechanics of programming.  So should everyon [read] Keywords: atlas domino formula language ibm lotus lotusscript notes ajax community css facebook java javascript linkedin wiki xml
230


And I am up and running!
Thu, Mar 21st 2013 12:45p   Karl-Henry Martinsson
Downloaded the Notes client with Domino Designer and Administrator, installed it on top of the public beta from December in a viritual machine (with 1GB memory). Install went without any problems, and the client starts up fine. All settings and bookmarks were preserved from the beta. My workspace in IBM Notes 9.0 Social Edition It just works. [read] Keywords: domino ibm lotusnotes notes notes client workspace




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - Mobile Edition