This repository has been archived by the owner on Apr 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
116 lines (100 loc) · 3.79 KB
/
index.html
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
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>XML Viewer</title>
<!-- jQuery to help make some magic happen -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!-- Twitter Bootstrap to make it pretty -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- Small UI tweaks -->
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<script type="text/javascript">
function handleFileSelect(evt) {
var file = evt.target.files[0];
fr = new FileReader();
fr.onload = receivedText;
fr.readAsText(file);
}
function receivedText() {
var docContents = new Array();
var text = fr.result.replace('', '\&\#5');
$xml = $( $.parseXML( text ) );
$xml.find("sms").each(function(){
var var_name = $(this).attr("contact_name");
if(!var_name || var_name == "(Unknown)") var_name = $(this).attr("address").replace('+1', '');
var temp = $.grep(docContents, function (e) {
return e.name == var_name;
});
if( temp.length ) {
temp[0].texts.push({ readable_date: $(this).attr("readable_date"),
address: $(this).attr("address"),
body: $(this).attr("body"),
date: $(this).attr("date"),
type: parseInt($(this).attr("type"))
});
}
else {
docContents.push(
{
name: var_name,
texts: [{
readable_date: $(this).attr("readable_date"),
address: $(this).attr("address"),
body: $(this).attr("body"),
date: $(this).attr("date"),
type: parseInt($(this).attr("type"))
}]
}
);
}
});
// Sort
docContents.sort(function(a, b) {
return parseFloat(b.texts[b.texts.length - 1].date) - parseFloat(a.texts[a.texts.length - 1].date);
});
// Form the group
var html = '<h3>Text Messages</h3><div class="panel-group" id="accordion">';
$.each(docContents, function(personIndex, personObject){
// Start the group member, label with the name
html += '<div class="panel panel-default"><div class="panel-heading">' +
'<h4 class="panel-title"><a data-target="#collapse' + personIndex +
'" data-toggle="collapse" data-parent="#accordion">' +
personObject.name + ' - ' + personObject.texts.length + '</a></h4></div><div id="collapse' +
personIndex + '" class="panel-collapse collapse"><div class="panel-body">' +
'<table class="table table-bordered table-condensed table-striped" >' +
'<tr><th>Date</th><th>Status</th><th>Message</th></tr>';
//Populate the texts
$.each(personObject.texts, function(textIndex, textObject) {
var status;
if (textObject.type == 1) status = "Received";
else if (textObject.type == 2) status = "Sent";
else status = "Other";
html += '<tr><td class="messageDateCell">' + textObject.readable_date +
'</td><td>' + status + '</td><td>' + textObject.body + '</td></tr>';
});
//Finish the group member
html += '<tr><td colspan="3"><a data-target="#collapse' + personIndex + '" data-toggle="collapse" data-parent="#accordion">' +
'Close</a></td></tr></table></div></div></div>';
});
// Finish the group
html += '</div>';
$("#content").html(html);
}
$(document).ready(function(){
$("#xml-file").change(handleFileSelect);
$( "#accordion" ).accordion({ collapsible: true });
});
</script>
<input type="file" id="xml-file" name="files" />
<div id="content">
</div>
</body>
</html>