Pages

Monday, February 28, 2011

how to repeat triggering a javascript function automatically

The setInterval function in javascript helps the browser to execute a javascript function repeatedly over a time period and its syntax is as follows

setInterval( myFunction, noOfSeconds*1000) , where

setInterval is the name of the native javascript function
myFunction is the name of your custom function that needs to be triggered repeatedly
noOfSeconds is the time gap in number of seconds after which your custom function needs to be executed again

Once the setInterval is invoked, the stop the same the clearInterval command should be invoked.The syntax of the same is as follows,

clearInterval(myFunction)

Wednesday, February 23, 2011

Issue : dojo.xhrGet fails in Safari

It was one trouble some situation when I found that my dojo.xhrGet failed in Safari. I felt like I was hanging in a cliff 500 feet deep. with no way back :( untill I stumbled upon the following forum discussion,

http://www.devcomments.com/cross-site-ajax-using-dojo-xhrGet-doesn-t-work-as-expected-but-at200443.htm

An amazing one. The first few posts are not visible for some reason but the vital ones that resolved the issue where visible.

The abstract of what I understood from issue that I faced and the discussion in this forum are as follows,

1. When using dojo.xhrGet, a preflight request get triggered from safari. And that means an Ajax request is triggered to the server before server authentication could occur. And this posed a severe security threat as Anonymous access to my Lotus Notes Database has to be enabled for dojo.xhrGet to work on Safari.

2. The trick was to use dojo.xhr instead of dojo.xhrGet . The documentation on  dojo.xhr can be found in the following location -http://dojotoolkit.org/api/dojo.xhr

3. The context that we need to understand here is that dojo.xhrGet({arguments}) is same as dojo.xhr("GET",{arguments}). And this is one of the vital points that resolved the issue

In addition to the above, to tackle the preflight request issue, it is better, if one can check on the play around with the "sync" flag. It is not that playing around with this will definitely resolve the issue but there are paucity of chances that it might help.

Hope this helps :)

Thursday, February 10, 2011

An elegant way to get the current time (say a time stamp) in Lotus Script

The following lotusscript command gives a very good way of obtaining a the current time alone.

Format(Now, "Long Time")


hope this helps :)

Wednesday, February 9, 2011

agent.runWithDocumentContext(NotesDocument) not working in XPages

If you attempt to execute a Lotus Script agent from the server side script in the XPages and get the following error,

There are few issues that you may have to look into,

1. Sign the agent, XPage and the associated elements. Better sign the database with the server id.
2. Ensure that you have sufficient access to execute agents
3. Ensure the "Run as Web User" and "Allow Restricted Operation" are selected on the agent
4. Ensure that the type of the agent is "Agent List Selection" with target "None"

Hope this helps :)

Friday, February 4, 2011

How to capture orientation change event using Sencha Touch

One of the classy/awesome feature of an iPad, is the way the screen changes resolution/orientation as and when you rotate the iPad physically. The pages that you see on the screen switches between landscape to portrait mode just like that in a nice smooth continuous fashion.

Hence it becomes important for a iPad application developer to ensure that the page we develop for the iPads, looks good in all orientations and hence we definitely have to know where and when to change the application's styles.

For a simple panel created using using Sencha Touch, add the following property to capture the orientation changing event and you are set to go. Hope this is applicable to all components in sencha touch.


listeners: {
orientationchange : yourCustomFunction
}


Hope this helps :)

How to get the current node/leaf selected in a NestedList - Sencha Touch Framework

The following code fragment will help you alert the text that is present in the leaf/node of  a nested list which is being clicked. The nested list one which is created using sencha framework

activeListItem = yourNestedList .getActiveItem(),
associatedRecord = activeListItem t.getSelectedRecords()[0];
alert( record.get('text'))

Hope this helps :)

OnClick event for list items in NestedList - Sencha Touch Framework

Following is a fragment of code that builds a plugin to listen to the click events on the leaf/list items in a NestedList created using the Sencha Touch Framework. This is already present in the Kitchen Sink example provided in the Sencha Touch's Site

---------------------------Block A---------------------------
/**
* @class Ext.LeafSelectedPlugin
* @extends Object
*
* A simple plugin for a NestedList which adds a "leafselected"
* event which accounts for cardswitching and selectionchange.
*
* This is useful when you want to enable editing of all leaf items.
*/
Ext.LeafSelectedPlugin = Ext.extend(Object, {
init: function(nestedList) {
this.nestedList = nestedList;
nestedList.addEvents('leafselected');
nestedList.on('cardswitch', this.onCardSwitch, this);
nestedList.on('selectionchange', this.onSelectionChange, this);
},

onCardSwitch: function(ct, newCard, oldCard, newIndex, animated) {
var nestedList = this.nestedList;
if (newCard.getSelectedRecords) {
var record = newCard.getSelectedRecords()[0];
if (record) {
nestedList.fireEvent('leafselected', record.node.isLeaf());
} else {
nestedList.fireEvent('leafselected', false);
}
} else {
nestedList.fireEvent('leafselected', false);
}
},

onSelectionChange: function(selModel, records) {
var nestedList = this.nestedList,
subList = selModel.view;

if (nestedList.getActiveItem() === subList) {
if (records[0]) {
nestedList.fireEvent('leafselected', records[0].node.isLeaf());
} else {
nestedList.fireEvent('leafselected', false);
}
}
}
});



---------------------------Block A---------------------------
Add the above mentioned code to a script library

Include your script library into the XPage or your HTML file and do the following
---------------------------Block B---------------------------
var yourNestedList =new Ext.NestedList({
  plugins: [new Ext.LeafSelectedPlugin()],
  //your other parameters
});
---------------------------End of Block B---------------------------


Now call the following function to trigger the onclick or onselected event of the leaf/item of the nestedList
---------------------------Block C---------------------------
  yourNestedList .on('leafselected', function(enabled) {
alert('I am on the onclick event of the leaf/item of your nested list');
});
---------------------------End of Block C---------------------------

iPad Detection Using JavaScript

Following fragment of code helps in detecting whether an application is being previewed in a iPad or a normal web client.

// For use within normal web clients 
var isiPad = navigator.userAgent.match(/iPad/i) != null;

// For use within iPad developer UIWebView
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua)

For more info take a look at http://davidwalsh.name/detect-ipad

Hope this helps :)