-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPubExportTool.xml
341 lines (260 loc) · 13.4 KB
/
PubExportTool.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Publications Export">
<Require feature="opensocial-0.9" />
<Require feature="views" />
<Require feature="dynamic-height" />
<Require feature="pubsub" />
<Require feature="osapi" />
</ModulePrefs>
<!-- ==================== START COMBINED VIEWS ==================== -->
<Content type="html" view="canvas, small"><![CDATA[<!--HTML-->
<!DOCTYPE html>
<!-- #includes -->
<link rel="stylesheet" href="css/gadget.css" type="text/css" media="screen, projection" >
<script type="text/javascript" src="js/os.js" ></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<style>
.tool_title { font-family:Verdana, Arial; font-size:14px;}
.tool_title_orange { font-family:Verdana, Arial; font-size:14px; color:#FF9900; }
.tool_body { font-family:Arial; font-size:12px;}
.tool_credit { font-family:Arial; font-size:10px;}
.tool_table_cell { font-family:Arial; font-size:12px; padding:0px 20px 10px 0px; }
.tool_table_cell_small { font-family:Arial; font-size:11px;}
.tool_toggle_button { height:26px; width:70px; font-size:12px; font-weight:bold; }
</style>
<script type="text/javascript">
var g_arrOldIDs = [];
// ==============================================================
function gadgetEventTrack(action, label, value) {
var message = {'action' : action};
if (label) {message.label = label;}
if (value) {message.value = value;}
gadgets.pubsub.publish("analytics", message);
}
// ==============================================================
function showHelp() {
var pop = window.open('Publications Export Help','','top=200,left=200,width=450,height=275,scrollbars=0,status=0,menubar=0,location=0,resizable=0');
pop.document.write("<html><head></head><body><div style='margin:10px; font-family:Arial; font-size:12px;'>");
pop.document.write("The Publications Export tool lets you export data about the publications from a profile."
+ "<ul><li>Find a profile for which you want to capture the publications.</li>"
+ "<li>Click the <b>Export</b> button to export data about all the publications.</li>"
+ "<li>Profiles takes you to the export pane, where you can select what data to export.</li>"
+ "<li>If you decide not to export the data, click the Back link or back button in your browser to return to the profile.</li></ul>");
pop.document.write("<br><br><center>"
+ "<input type = 'button' value = 'Close' onclick = 'window.close();'>"
+ "</center>");
pop.document.write("</body></html>");
}
// ==============================================================
function saveData(sender, message) {
// test data
// var arrUnChunked = ["10516321","8929434","8738377"];
// var arrUnChunked = ["10516321","8929434"];
// convert incoming pubsub IMIDs to an array
var arrUnChunked = gadgets.json.parse(message).pubIds;
// initialize object
var chunkedDataObject = {}; // a map of data, keyed by pIds + chunk num
var chunkNum = 0;
while(arrUnChunked.length) {
var chunkName = 'pIDs' + chunkNum++;
chunkedDataObject[chunkName] = gadgets.json.stringify(arrUnChunked.splice(0, 400)); // chunked data as string as required by osapi.udpate call
}
chunkedDataObject["num_chunks"] = "" + chunkNum; // number of chunks as string as required by osapi.udpate call
// at this point we should have a nice chunkedDataObject that we can convert to JSON and store as
// appdata in one call
osapi.appdata.update({'userId': '@viewer', 'appId':'@app', 'data': gadgets.json.stringify(chunkedDataObject)}).execute(gadgets.views.requestNavigateTo('canvas'));
}
// ==============================================================
function readData(callback) {
// get the number of chunks
osapi.appdata.get({'userId':'@viewer', 'appId':'@app', 'fields':['num_chunks']} )
.execute(function(result){
var viewer = os.osapi.getViewerFromResult(result);
var num_chunks = viewer.num_chunks;
// build the fields to read the chunks
var fields = [];
for (var i = 0; i < num_chunks; i++) {
fields[i] = 'pIDs' + i;
}
osapi.appdata.get({'userId':'@viewer', 'appId':'@app', 'fields': fields} )
.execute(function(result){
g_arrOldIDs = [];
var viewer = os.osapi.getViewerFromResult(result);
for (var i = 0; i < fields.length; i++) {
var chunk = gadgets.json.parse(viewer[fields[i]]);
g_arrOldIDs = g_arrOldIDs.concat(chunk);
}
// now that all the data is loaded, execute the callback
callback();
}); /* end osapi.appdata.get INNER */
}); /* end osapi.appdata.get OUTER */
}
// ==============================================================
function buildPubList() {
// test data
// var g_arrOldIDs = ["10516321","8929434","8738377"];
for (idNum in g_arrOldIDs) {
$.ajax({
type: "GET",
url: "http://profiles.ucsf.edu/CustomAPI/v1/PubXML.aspx?PMID=" + g_arrOldIDs[idNum],
dataType: "xml",
success: function(xml){
table_authors = "";
last_names = [];
initials = [];
$(xml).find("MedlineCitation").each(function(){
iso = $(this).find("ISOAbbreviation").text();
table_title = $(this).find("ArticleTitle").text();
table_pubdate = $(this).find("PubDate").text();
table_pmid = $(this).find("PMID").text();
// match the div name in the target data display table
var pmid_first_eight = table_pmid;
pmid_first_eight = pmid_first_eight.substring(0,8);
$(xml).find("LastName").each(function(){
last_names.push($(this).text());
});
$(xml).find("Initials").each(function(){
initials.push($(this).text());
});
for (i in last_names) {
table_authors += last_names[i] + " ";
table_authors += initials[i] + ". ";
}
table_title = table_title + " " + table_authors + table_pubdate;
export_all_string = table_title + " " + table_authors + iso + " " + table_pubdate;
hash_title = "#title" + pmid_first_eight;
hash_pmid = "#pmid" + pmid_first_eight;
$(hash_title).html(table_title);
$(hash_pmid).html(pmid_first_eight);
// add to the id export text area
document.getElementById("canvas_id_list_textarea").value += pmid_first_eight + ",";
// add to the full export text area
document.getElementById("canvas_full_list_textarea").value += export_all_string + "\n\n";
}); /* end find call */
} /* end success function */
}); /* end ajax call */
} /* end for loop */
}
// ==============================================================
function buildPubListTable() {
// start the table
var strTable="<table cellspacing='0' cellpadding='0' width='600'>";
// build the table header row
strTable=strTable + "<td width='75%' align='left' valign='top' class='tool_table_cell'>" + "<u><b>Title</b></u></td>";
strTable=strTable + "<td width='25%' align='left' valign='top' class='tool_table_cell'>" + "<u><b>PubMed ID</b></u></td>";
strTable=strTable + "</tr>";
// build the data rows
for (j in g_arrOldIDs) {
// some PMIDs returned in the XML stream are very long
var pmid_first_eight = g_arrOldIDs[j] + "";
pmid_first_eight = pmid_first_eight.substring(0,8);
strTable = strTable + "<tr><td align='left' valign='top' class='tool_table_cell'><div id='title" + pmid_first_eight + "'>No Title data available</div></td>";
strTable = strTable + "<td align='left' valign='top' class='tool_table_cell'><div id='pmid" + pmid_first_eight + "'></div></td></tr>";
}
// end the table
strTable = strTable + "</table>";
// initialize the export divs
document.getElementById("canvas_id_list_textarea").value = "";
document.getElementById("canvas_full_list_textarea").value = "";
// hide the progress guide
// document.getElementById("progress").style.display="none";
// dispay the table in canvas view
document.getElementById("canvas_pubs_list").innerHTML = strTable;
// fetch the PMID data and populate the table
buildPubList();
} /* end buildPubListTable */
// ==============================================================
function copyIdDivToClipboard() {
document.getElementById("canvas_id_list").style.display = "block";
document.getElementById("canvas_id_list_text").style.display = "block";
document.getElementById("canvas_full_list").style.display = "none";
document.getElementById("canvas_full_list_text").style.display = "none";
document.getElementById("canvas_pubs_list").style.display = "none";
}
// ==============================================================
function copyFullDivToClipboard() {
document.getElementById("canvas_full_list").style.display = "block";
document.getElementById("canvas_full_list_text").style.display = "block";
document.getElementById("canvas_id_list").style.display = "none";
document.getElementById("canvas_id_list_text").style.display = "none";
document.getElementById("canvas_pubs_list").style.display = "none";
}
// ==============================================================
</script>
]]>
</Content>
<!-- ==================== END COMBINED VIEWS ==================== -->
<!-- ==================== START SMALL VIEW ==================== -->
<Content type="html" view="small"><![CDATA[<!--HTML-->
<!DOCTYPE html>
<div style="float:right; margin:10px 4px 0 0">
<table cellpadding="0" cellspacing="0">
<tr>
<td><input id="export_button" type="button" class="tool_toggle_button" value="Export" onClick="gadgetEventTrack('view_list');gadgets.pubsub.subscribe('JSONPubMedIds', saveData);"> </td>
<td><img src="images/hovertiptarget.png" border="0" onClick="gadgetEventTrack('help');showHelp()"></td>
</tr>
</table>
</div>
<script type="text/javascript">
gadgets.util.registerOnLoadHandler(gadgets.window.adjustHeight(40));
</script>
]]>
</Content>
<!-- ==================== END SMALL VIEW ==================== -->
<!-- ==================== START CANVAS VIEW ==================== -->
<Content type="html" view="canvas"><![CDATA[<!--HTML-->
<!DOCTYPE html>
<!-- top menu links -->
<div>
<p id="number_selected" class="tool_title_orange" style="margin-left:20px;">
Selected Publications<p>
<p class="tool_body" style="margin-left:20px; margin-bottom:10px;">
<a href="javascript:gadgetEventTrack('export_pub_ids');copyFullDivToClipboard();">Export all data</a>
|
<a href="javascript:gadgetEventTrack('export_all_data');copyIdDivToClipboard();">Export IDs</a>
</p>
<!--
<p id="progress" style="margin-left:20px;">
<br><br>
<img src="images/waiting.gif">
<br><br>
<b>Processing data. This may take a minute or two, based on the size of your selected PubMed ID list.</b>
</p>
-->
</div>
<div id="canvas_id_list" style="display:none; background:#FFF; width:664px; height:44px; margin-left:12px;">
Copy and paste the information below into a .txt file or another program.
<input type="button" style="height:22px; font-size:10; margin-left:84px;" value="Close" onClick="document.getElementById('canvas_id_list').style.display='none';document.getElementById('canvas_id_list_text').style.display='none';document.getElementById('canvas_pubs_list').style.display='block';"></button>
<br />
<a href="http://www.ncbi.nlm.nih.gov/sites/pmctopmid/" target="_blank">Convert copied PMIDs to PMCIDs</a>
<br />
</div>
<!-- holds the title and ID list to be copied to the clipboard -->
<div id="canvas_id_list_text" style="display:none; width:658px; height:450px; color:#000; margin:0px 5px 0px 5px;">
<textarea id="canvas_id_list_textarea" rows="27" cols="78" style="border:1px solid #000; margin: 0px 8px 0px 8px;">
</textarea>
</div>
<div id="canvas_full_list" style="display:none; background:#FFF; width:664px; height:26px; margin-left: 12px;">
Copy and paste the information below into a .txt file or another program.
<input type="button" style="height:22px; font-size:10; margin-left:84px;" value="Close" onClick="document.getElementById('canvas_full_list').style.display='none';document.getElementById('canvas_full_list_text').style.display='none';document.getElementById('canvas_pubs_list').style.display='block';"></button>
</div>
<!-- holds the full pubs list to be copied to the clipboard -->
<div id="canvas_full_list_text" style="display:none; width:658px; height:450px; color:#000; margin:0px 5px 0px 5px;">
<textarea id="canvas_full_list_textarea" rows="27" cols="78" style="border:1px solid #000; margin: 0px 8px 0px 8px;">
</textarea>
</div>
<!-- holds the visible pub details list -->
<div id="canvas_pubs_list" style="display:block; margin:20px 0px 0px 20px; height:525px; overflow:auto;"></div>
<script type="text/javascript">
function init() {
gadgets.window.adjustHeight(600);
readData(buildPubListTable);
document.getElementById("canvas_pubs_list").style.display="block";
}
gadgets.util.registerOnLoadHandler(init);
</script>
]]>
</Content>
<!-- ==================== END CANVAS VIEW ==================== -->
</Module>