See09/session.js
author ivanl
Tue, 09 Mar 2010 10:34:58 +0000
changeset 20 918767a9c8d3
parent 19 f3521a11d878
permissions -rw-r--r--
Adding Wikipedia Widget 1.0rc5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     1
// ////////////////////////////////////////////////////////////////////////////
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     2
// Symbian Foundation Example Code
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     3
//
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     4
// This software is in the public domain. No copyright is claimed, and you 
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     5
// may use it for any purpose without license from the Symbian Foundation.
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     6
// No warranty for any purpose is expressed or implied by the authors or
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     7
// the Symbian Foundation. 
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     8
// ////////////////////////////////////////////////////////////////////////////
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
     9
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    10
// Session class is used to encapsulate all session data
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    11
function Session(){
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    12
	this.date = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    13
	this.location = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    14
	this.startTime = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    15
	this.endTime = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    16
	this.topic = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    17
	this.chair = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    18
	this.speakers = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    19
	this.title = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    20
	this.description = null;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    21
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    22
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    23
Session.prototype.GetContentHTML = function () {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    24
	var buf = "<small><i>" + this.startTime + " - " + this.endTime;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    25
	if ( this.location ) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    26
		buf += ", " + this.location;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    27
	}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    28
	buf += "</i>";
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    29
	var haschair = false;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    30
	if ( this.chair && this.chair != null && this.chair.length > 0 ) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    31
		var ch = this.chair.replace(/<br>/g, ", ");
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    32
		buf += "<br><b>Chair: " + ch + "</b>";
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    33
		haschair = true;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    34
	}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    35
	if (this.speakers && this.speakers != null && this.speakers.length > 0) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    36
		buf += "<b>, "
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    37
		if ( haschair ) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    38
			buf += "Speakers: ";
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    39
		}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    40
		// remove nasty newlines
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    41
		var spk = this.speakers.replace(/<br>/g, ", ");
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    42
		buf += spk + "</b>";
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    43
	}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    44
	buf += "<br>" + this.description + "</small>";
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    45
	return buf;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    46
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    47
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    48
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    49
// Used when parsing to assign a value by ordinal
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    50
Session.prototype.SetFieldByOrdinal = function(ordinal, val) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    51
	switch(ordinal) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    52
		case 0: this.date = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    53
		case 1: this.location = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    54
		case 2: this.startTime = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    55
		case 3: this.endTime = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    56
		case 4: this.topic = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    57
		case 5: this.chair = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    58
		case 6: this.speakers = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    59
		case 7: this.title = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    60
		case 8: this.description = val; break;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    61
	}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    62
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    63
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    64
Session.prototype.GetNumberOfFields = function () {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    65
	return 9;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    66
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    67
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    68
Session.prototype.GetStartUtc = function(){
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    69
	return this.GetUtcTime(this.date, this.startTime);
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    70
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    71
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    72
Session.prototype.GetEndUtc = function(){
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    73
	return this.GetUtcTime(this.date, this.endTime);
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    74
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    75
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    76
Session.prototype.GetUtcTime = function(dateString, timeString){
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    77
	// make a date, then we'll mod it
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    78
	var d = new Date();
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    79
	// dateString is in the format DD-mmm-YY
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    80
	var parts = dateString.split("-");
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    81
	d.setFullYear(parseInt(parts[2]) + 2000);
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    82
	d.setDate(parseInt(parts[0]));
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    83
	d.setMonth(indexOfMonth(parts[1]));
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    84
	// time is in the format HH:MM
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    85
	parts = timeString.split(":");
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    86
	d.setHours(parseInt(parts[0]));
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    87
	d.setMinutes(parseInt(parts[1]));
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    88
	// convert to msec since Jan 1 1970
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    89
	var localTime = d.getTime();
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    90
	// obtain local UTC offset and convert to msec
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    91
	var localOffset = d.getTimezoneOffset() * 60000;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    92
	// obtain UTC time in msec
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    93
	return localTime + localOffset;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    94
}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    95
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    96
function indexOfMonth(m){
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    97
	switch(m.toLowerCase()) {
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    98
		case "jan": return 1;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
    99
		case "feb": return 2;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   100
		case "mar": return 3;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   101
		case "apr": return 4;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   102
		case "may": return 5;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   103
		case "jun": return 6;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   104
		case "jul": return 7;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   105
		case "aug": return 8;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   106
		case "sep": return 9;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   107
		case "oct": return 10;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   108
		case "nov": return 11;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   109
		case "dec": return 12;
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   110
	}
f3521a11d878 See 09 widget, version 1.0rc3
ivanl
parents:
diff changeset
   111
}