Posts Tagged ‘js’

11 Apr 2013
5

Appcelerator Mobile Development – Season 1: Prologue

Hi everyone. I’m very excited about my next Blogging Project. Over the past year I’ve had some very decent exposure to Mobile Development, whether Phonegap, jQuery Mobile, Dojo Mobile, XPages Mobile Controls, Appcelerator Titanium, etc.

This is a Prologue to some upcoming Video Tutorials that I am grouping together as “Appcelerator Mobile DevelopmentSeason 1“, where I will be showing everyone how to get started with Appcelerator Titanium Development to build native iOS and Android Mobile Applications.

Season 1 will focus on some basic methods of getting up and running with Native Mobile Development. Our focus will be to create a Mobile Application that runs on iOS and Android which allows the capturing of data, some reports and a couple of other nifty features like SplitWindows for iPads, Pull to Refresh Actions for Views, etc.

We will also be integrating this Mobile App with a Basic Domino XPages Application. I’ll show you how to authenticate with Domino, make use of XAgents and REST Services to push and pull information to an from Domino, as well as triggering your business logic on the Domino side for your Workflow Processes.

Finally, I will be showing you what, at the moment, seem to be best practices for developing mobile Apps using frameworks like commonJS, underscore.js, etc. This will allow us to avoid memory leaks and poor performance by making use of a very basic form of MVC Architecture within our Mobile Application.

My next Blog Post will focus on getting you up and running with Appcelerator Titanium and installing the SDKs for iOS and Android.

I would love your comments, feedback and suggestions regarding this venture. Feel free to post comments against this Blog Post or catch me on Twitter.

Cheers for now
John.
20 Mar 2013
0

Tip: Understand how to compare values in JavaScript

Hi everyone. In this post I want to point out a not so common way to compare variables and their values in JavaScript.

For many out there, the common way to compare 2 values is to use the == or != operators. If we look at the example below however, you’ll notice an interesting result that is returned:

Example:

var boolFalse = false;

var boolTrue = true;

var myString = “”;

if(boolFalse == 0) //This returns True

if(boolTrue == 1) //This returns True

if(myString == 0) //This returns True

The reason why these values are returning true is because as a default, when using == or !=, JavaScript only compares the values and not their variable types.

If you wanted to perform a strict comparison between 2 variables using their Value as well as Type, then you will need to use === or !==.

Example:

if(boolFalse === 0) //This returns False

if(boolTrue === 1) //This returns False

if(boolTrue !== 1) //This returns True

if(myString === 0) //This returns False

 

I now use this as a Standard when coding in JavaScript. I hope this makes sense.

Happy coding :)

John.

17 Jan 2013
2

XPages Tip: Pass NotesDateTime to the Javascript Date Object

Hi all.

I spent this morning creating a massive SSJS Validation Rule that had to do with Date and Time values that were provided by the User online. I think Date Objects will forever remain my Everest, because I just can’t seem to get it right without wasting hours on it.

In SSJS, the problem with the NotesDateTime Object is that properties like “getDateOnly”, “getTimeOnly” and “getLocalTime” return the values as strings. If you want to compare values, you’re in for a tough time.

Now the Javascript Date Object offers you way more in terms of comparing values. Click here to check an awesome function you can use in your code.

I had a scenario where I was using NotesDateTime Objects to manipulate Date/Time Values, but I wanted to pass these Date/Time Values to the JavaScript Date Object to perform compares, etc. My first attempt failed when I tried to use the “getLocalTime” property of the NotesDateTimeObject:

Note: This example is not best practice, but allows me to show you a function available in SSJS

var date1:NotesDateTime = session.CreateDateTime(“2013/01/17 06:00:00″);

var date2:Date = new Date(date1.getLocalTime());

The above-mentioned will fail because date1.getLocalTime() is an illegal Date value according to the JavaScript Date Object. Having said that, there is an awesome NotesDateTime Method called .toJavaData() that converts the value to a JavaScript Date Object:

var date1:NotesDateTime = session.CreateDateTime(“2013/01/17 06:00:00″);

var date2:Date = new Date(date1.toJavaDate());

From here use you can use the Date Object for comparing Date and Time Values.

I trust this helps :)

John.

19 Dec 2012
5

XPages Query: Strange behavior between partialRefreshGet and Post

Hi all. I hit a very strange issue this morning with my Partial Refreshes. It’s the first time i’ve been faced with this problem. I’m happy to say that I managed to resolve the issue, but I’m a bit confused as to why it was an issue in the first place.

Ok, so I have a button that performs an SSJS Function. It also triggers a Partial Refresh of a Panel in my XPage. This Panel that gets refreshed excludes my Button Bar Panel and for very good reasons. My Button Bar Panel should only be refreshed after the initial Partial Refresh of my other Panel in the XPage.

I do this by adding some CSJS to the onComplete event of my Button that’s triggered. It uses a Remote Service to check a condition, then if that condition is True, it performs a Partial Refresh of the Button Bar Panel. I used a XSP.partialRefreshGet for the partial refresh of the Button Bar Panel.

Now, what I noticed, was that the Button Bar Panel in some cases, was been refreshed before the Primary Partial Refresh. This doesn’t happen in the first 2 times that the button is clicked, but only from the 3rd time onward. I couldn’t understand this because according to Firebug, the Partial Refreshes occur in the correct Sequence.

How I fixed the issue was quite simple: I changed the XSP.partialRefreshGet to a XSP.partialRefreshPost. This immediately resolved the issue and everything works perfectly.

In short, I am just a bit confused as to why a XSP.partialRefreshGet would run its actions out of sequence. Very strange behavior.

Would love some feedback or comments.

 

Cheers

John.

9 Nov 2012
-

Use Dojo or jQuery to manipulate Printing of Web Pages

Hi everyone. Here’s a second post that was published by Johan Meyer, Ukuvuma’s senior Microsoft Developer.

Enjoy

John.

 

From Johan Meyer at Ukuvuma Solutions

Okay, this is a nice short tutorial where I will show you the following:

  1. How to create a print button on a web page.
  2. Use Firebug (Firefox), Developer Tools(IE) or any other developer tools available to identify what controls needs to be hidden or showed before the page gets printed.
  3. Show you what code is needed for jQuery or Dojo.

 

1. How to create a print button on a web page.
First off you need to create a Print button. Now normally when I create an image as a button on a web page I will use CSS for the style and a <div> for the button.

So first add a <div></div> tag to your Page and give it a class name, for this example I will be using “printButton” as the class name.
In your HTML file add this div:

<body> <div class="printButton"> </div> </body> 

Now that you have your div you need to create the Stylesheet that will style our print button.  Add a CSS file to your project and add the following to it.  The dot before printButton means that this style is applicable to the printButton Class.  If the printButton had a # before it would look for the div’s ID.

.printButton {

background-image: url(“printButton.jpg”);

background-repeat: no-repeat;

cursor: pointer;

cursor: hand;

height: 20px;

width: 20px;

padding: 5px;

}

 

This style will change your div however you want it.  The first two lines will show your image without repeating it.  Then we use two cursors, the first one works for IE and the second for Firefox (this is the code that will show the little hand when you hover over the image).  Then we set the fixed width of the div and the padding to make it look a bit nicer.

 

 

 

 

 

The image above shows how the button should look by now.  To create an actual print button we need to add the Javascript print command.  Add the following to your printButton div.

<html>

<head>

<script type=”text/javascript” language=”javascript”> function printDocument() { window.print(); } </script>

</head>

<body>

<div onclick=”javascript:printDocument();”> </div>

</body>

</html>

 

The onclick event fires a javascript function called printDocument().  Inside this function we call a JavaScript function that calls the browsers print class.  This will print the document but not always as the user would want it to print.

 

2.  Use Firebug to enhanced the nor window.print JavaScript function

For now I’m not going to go into depth of how firebug works but I will post on how to use it and all about what I know of firebug in one of my future posts.

Use Firebug and look through the website that you want to print and identify what controls you want to hide before printing, or what controls you want to modify in size before printing.

If you have a layout that looks like this, it is likely that you only want the content part of this layout.  So identify the controls by ID or by class and write them down.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The sections that we will want to hide are: LeftSide, Header, Footer and RightSide.

 

3.  JQuery and Dojo code

Now that you know what controls you don’t want to show, you need to hide them before calling the printing function and show them again after printing.

In the printDocument function add the following code for jQuery:

<script type=”text/javascript” language=”javascript”>

function printDocument() {

jQuery(“.LeftSide”).hide();

jQuery(“.Header”).hide();

jQuery(“.Footer”).hide();

jQuery(“.RightSide”).hide();

window.print();

jQuery(“.LeftSide”).show();

jQuery(“.Header”).show();

jQuery(“.Footer”).show();

jQuery(“.RightSide”).show();

}

</script>

 

And this if you want to use Dojo:

<script type=”text/javascript” language=”javascript”>

function printDocument() {

dojo.query(“.LeftSide”).style(“display”, “none”);

dojo.query(“.Header”).style(“display”, “none”);

dojo.query(“.Footer”).style(“display”, “none”);

dojo.query(“.RightSide”).style(“display”, “none”);

window.print();

dojo.query(“.LeftSide”).style(“display”, “block”);

dojo.query(“.Header”).style(“display”, “block”);

dojo.query(“.Footer”).style(“display”, “block”);

dojo.query(“.RightSide”).style(“display”, “block”);

}

</script>

 

If you need to call some of the controls on the ID instead of Class, you can change the jQuery to “#Header” and the dojo you need to remover the string with the dot and add dojo.byId(“Header”) instead.

You can manipulate the page as you like, just return everything back to normal after the user has printed or redirect them to a new page.

Hope you enjoyed this tutorial.