-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgadget-org.xml
161 lines (151 loc) · 6.28 KB
/
gadget-org.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="IATI DFATD Data" scrolling="true" width="200" height="250" author="Sheng Huang" author_email="shenghuang.cida@google.com">
<Locale lang="all">
<msg name="iati_dfatd">IATI DFATD Data</msg>
<msg name="iati_field">IATI Field</msg>
<msg name="iati_keyword">Search Keyword</msg>
<msg name="language">en</msg>
</Locale>
<Locale lang="en">
<msg name="iati_dfatd">IATI DFATD Data</msg>
<msg name="iati_field">IATI Field</msg>
<msg name="iati_keyword">Search Keyword</msg>
<msg name="language">en</msg>
</Locale>
<Locale lang="fr">
<msg name="iati_dfatd">Data de IATI MAECD</msg>
<msg name="iati_field">IATI champ</msg>
<msg name="iati_keyword">Recherche par mot clé</msg>
<msg name="language">fr</msg>
</Locale>
<Locale lang="fr-ca">
<msg name="iati_dfatd">Data de IATI MAECD</msg>
<msg name="iati_field">IATI champ</msg>
<msg name="iati_keyword">Recherche par mot clé</msg>
<msg name="language">fr</msg>
</Locale>
</ModulePrefs>
<UserPref
name="myfield"
display_name="__MSG_iati_field__"
default_value="" />
<UserPref
name="mykeyword"
display_name="__MSG_iati_keyword__"
default_value=""
required="true" />
<Content type="html">
<![CDATA[
<div id="content_div"></div>
<script type="text/javascript">
// get prefs
var prefs = new gadgets.Prefs();
// Field set by user
var myField = prefs.getString("myfield");
// Keyword set by user
var myKeyword = prefs.getString("mykeyword");
function makeDOMRequest() {
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
var url = "http://www.acdi-cida.gc.ca/iita-iati/dfatd-maecd_activites-activities.xml";
gadgets.io.makeRequest(url, response, params, 3000);
};
function response(obj) {
// Start building HTML string that will be displayed in <div>.
// Set the style for the <div>.
var html = "<div style='padding: 5px;background-color: #ccf;font-family:Arial, Helvetica;"
+ "text-align:left;font-size:90%'>";
// Set style for title.
html +="<div style='text-align:center; font-size: 120%; color: yellow; "
+ "font-weight: 700;'>";
// obj.data contains a Document DOM element corresponding to the
// page that was requested
var domdata = obj.data;
// Display menu title. Use getElementsByTagName() to retrieve the <menu> element.
// Since there is only one menu element in the file,
// you can get to it by accessing the item at index "0".
// You can then use getAttribute to get the text associated with the
// menu "title" attribute.
var title = prefs.getMsg("iati_dfatd") + domdata.getElementsByTagName("iati-activities").item(0).getAttribute("version");
html += title + "</div><br>";
// Get a list of the <food> element nodes in the file
var itemList = domdata.getElementsByTagName("iati-activity");
// Loop through all <iati-activity> nodes (allow two level recursive search for grandchildrens)
for (var i = 0; i < itemList.length ; i++) {
// For each <iati-activity> node, get child nodes.
var found = false;
var activityNode = itemList.item(i);
var nodeList = itemList.item(i).childNodes;
// Loop through child nodes. Extract data from the text nodes that are
// the children of the associated text and schema field element nodes.
for (var j = 0; j < nodeList.length ; j++) {
var node = nodeList.item(j);
var nodeName = node.nodeName;
var nodeValue = "";
if (node.firstChild != null) {
nodeValue = node.firstChild.nodeValue;
}
if (nodeName == "iati-identifier") {
var identifier = nodeValue;
}
if (nodeName == "title") {
if (node.getAttribute("xml:lang") == prefs.getMsg("language")) {
var title = nodeValue;
}
}
if (nodeName == "description") {
if (node.getAttribute("xml:lang") == prefs.getMsg("language")) {
var description = nodeValue;
}
}
if (myField == "" && myKeyword == "") {
found = true;
} else if (myField != "" && myKeyword != "") {
if (nodeValue != null) {
if ((nodeName == myField && nodeValue.indexOf(myKeyword) != -1) || (myField == "iati-identifier" && identifier == myKeyword)) {
found = true;
}
} else {
var childNodeList = node.childNodes;
if (childNodeList.length > 1) {
for (var k = 0; k < childNodeList.length ; k++) {
var childNode = childNodeList.item(k);
var childNodeName = childNode.nodeName;
var childNodeValue = "";
if (childNode.firstChild != null) {
childNodeValue = childNode.firstChild.nodeValue;
}
if (childNodeName == myField && childNodeValue.indexOf(myKeyword) != -1) {
found = true;
}
}
}
}
}
}
if (found) {
// Append extracted data to the HTML string.
if(typeof(title) == 'undefined' || title == null) {
title = "";
}
if(typeof(description) == 'undefined' || description == null) {
description = "";
}
html += "<i><b>";
html += "<a href=\"http://www.acdi-cida.gc.ca/cidaweb/cpo.nsf/vWebProjByNumEn?OpenView&id="+identifier+"\" target=\"_blank\">"+identifier + "</a> - " + title;
html += "</b></i><br>";
html += " ";
html += description;
html += "<br>";
}
}
// Close up div
html += "</div>";
document.getElementById('content_div').innerHTML = html;
};
gadgets.util.registerOnLoadHandler(makeDOMRequest);
</script>
]]>
</Content>
</Module>