mypackage_wrt/mercurial.js
author nithyar
Wed, 12 May 2010 17:17:10 +0100
changeset 52 3f1ce447f91e
parent 51 abeee2a2e01b
permissions -rwxr-xr-x
Updated S^4 Key Feature dates
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     1
var revisionview=null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     2
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     3
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     4
function PackageMercurialUrl () {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     5
	if (!Packageid) {return;}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     6
	MCLrepos = new Ajax();
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     7
	MCLrepos.onreadystatechange = PackageMercurialUrlCompleted;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     8
	MCLrepos.open('GET', nocache(mercurialUrl), true);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
     9
	debuglog.debug ("accessing mercurial url: "+ mercurialUrl);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    10
	MCLrepos.send(null);	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    11
		
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    12
}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    13
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    14
function PackageMercurialUrlCompleted () {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    15
	 
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    16
	 if (MCLrepos.readyState == 4) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    17
	 	var pagetext = MCLrepos.responseText;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    18
		
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    19
		var ind = pagetext.indexOf(Packageid +"/");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    20
		pagetext = pagetext.substr(1,ind+Packageid.length);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    21
		debuglog.debug("result of regexp search for url is " + ind +  " Package name is "+Packageid);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    22
		
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    23
		if (ind==-1){
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    24
			uiManager.showNotification(1000, "Warning", "Mercurial - Package Not Found");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    25
			debuglog.debug ("Error - Package not found in the FCL page");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    26
			return;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    27
		} 
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    28
		ind=pagetext.lastIndexOf("href");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    29
		
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    30
		mercurialPackageUrl = symbianOrgBaseUrl + pagetext.substr(ind+6,pagetext.length-ind-6) + mercurialrss;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    31
	 	debuglog.debug("mercurial FCL repo URL is:" + mercurialPackageUrl);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    32
		//save settings
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    33
		    if (window.widget) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    34
				widget.setPreferenceForKey(mercurialPackageUrl, "mercurialPackageUrl");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    35
			} else {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    36
				debuglog.debug("mercurial - widget not found");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    37
			}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    38
	 }
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    39
}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    40
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    41
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    42
function MercurialFeedPresenter(rssreader) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    43
	var myreader = rssreader;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    44
	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    45
	ButtonFeedPresenter.prototype.init.call(this, rssreader);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    46
}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    47
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    48
 MercurialFeedPresenter.prototype = new ButtonFeedPresenter(null);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    49
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    50
// Handle the button-press
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    51
 MercurialFeedPresenter.prototype.feedClicked = function(event){
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    52
	var clickedButton = event.source;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    53
	var id = clickedButton.id;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    54
	var myitem = this.items[id]
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    55
	revisionpresenter(myitem,this.rssreader);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    56
}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    57
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    58
function revisionpresenter(aItem, aParent) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    59
	revisionview = new ListView(null, createCaption(aItem.title));
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    60
	revisionview.previousView = aParent;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    61
	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    62
	var mytext = new ContentPanel(null, null, null, true);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    63
	mytext.setExpanded(true);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    64
	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    65
	revisionview.addControl(mytext);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    66
	 var mybuf = "<br><div class=\"FeedItemLink\">";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    67
	     mybuf += "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" + symbianOrgBaseUrl + aItem.url + "'); return false;\">";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    68
    	 mybuf += "Open in browser..";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    69
         mybuf += "</a>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    70
         mybuf += "</div><br>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    71
			   
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    72
	var description = "<table style="+bugzillaTableStyle+">";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    73
	description += "<tr><td>Author:" + "</td><td>" + aItem.author + "</td></tr>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    74
	description += "<tr><td>Date:" + "</td><td>" + aItem.date + "</td></tr>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    75
	description += "</table>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    76
	description += "<table style="+bugzillaTableStyle+"><tr><td>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    77
	description += mybuf;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    78
	description += "<div class=\"FeedItemDescription\">" 
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    79
	description += "<b>Description:</b><br>" +  aItem.description ;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    80
	description += "</div>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    81
	description += "</td></tr></table>";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    82
	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    83
	mytext.setContent(description);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    84
	revisionview.show();
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    85
	 
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    86
	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    87
}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    88
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    89
function parseRepoFeed (broker, responseStatus, xmlDoc) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    90
	
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    91
	if (responseStatus == 200 && xmlDoc != null) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    92
        // node ref for iterating
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    93
        var node;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    94
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    95
		// for compatibility with rss
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    96
		var lastModified = new Date();
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    97
		
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    98
        // init result items array
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
    99
        var items = [];
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   100
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   101
		var itemElements = xmlDoc.getElementsByTagName("item");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   102
		
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   103
		for (var i = 0; i < itemElements.length; i++) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   104
            // iterate through child nodes of this item and gather
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   105
            // all the data we need for a feed item
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   106
            var title = null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   107
            var date = null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   108
            var description = null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   109
            var url = null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   110
            var author = null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   111
			var changeset = null;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   112
            node = itemElements[i].firstChild;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   113
            while (node != null) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   114
                if (node.nodeType == Node.ELEMENT_NODE) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   115
                    if (node.nodeName == "title") {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   116
                        // item title
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   117
                        title = getTextOfNode(node);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   118
						if ( title.length > 48) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   119
							title = title.substring(0,45) + "...";
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   120
						}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   121
                    } else if (node.nodeName == "pubDate" ) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   122
                        // item publishing date
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   123
                        date = getTextOfNode(node);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   124
                    } else if (node.nodeName == "description" && !this.ignoreContent ) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   125
                        // item description
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   126
                        description = getTextOfNode(node);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   127
                    } else if (node.nodeName == "guid") {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   128
                        // link URL
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   129
                        url = getTextOfNode(node);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   130
						// extract bug revision
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   131
						ind=url.indexOf("rev/");
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   132
						rev = url.substr(ind,url.length-ind);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   133
						
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   134
                    } else if (node.nodeName == "author" ) {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   135
						author = getTextOfNode(node);
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   136
					}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   137
                }
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   138
                node = node.nextSibling;
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   139
            }
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   140
            items.push({ title: title, date: date, description: description, url: url, author: author, rev: rev });
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   141
		}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   142
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   143
        // update was completed successfully
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   144
        return { status: "ok", lastModified: lastModified, items: items };
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   145
    } else {
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   146
        // update failed
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   147
        return { status: "error" };
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   148
    }
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   149
}
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   150
abeee2a2e01b my package version 0.4a
victorp@symbian.org
parents:
diff changeset
   151