Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 416 lines (329 sloc) 13.84 kb
2cbb865 @melvincarvalho first commit
melvincarvalho authored
1 <!DOCTYPE html>
2 <!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
3 <!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
4 <!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
5 <!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
6 <head>
7 <meta charset="utf-8">
4afbb26 @melvincarvalho Opentabs -> Opentabs
melvincarvalho authored
8 <title>Opentabs</title>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
9 <meta name="description" content="">
10 <meta name="author" content="">
11
12 <!--[if lt IE 9]>
13 <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
14 <![endif]-->
15 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
16
17 <link rel="stylesheet" href="stylesheets/base.css">
18 <link rel="stylesheet" href="stylesheets/skeleton.css">
19 <link rel="stylesheet" href="stylesheets/layout.css">
20
21 <link rel="shortcut icon" href="images/favicon.ico">
22 <link rel="apple-touch-icon" href="images/apple-touch-icon.png">
23 <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
24
25 <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
26
27 <style>
28 .gold { background-color: #FFFF99 }
29 </style>
30
31 </head>
32 <body>
33
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
34 <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
35
1412a78 @melvincarvalho add github link
melvincarvalho authored
36 <header>
37 <a href="https://github.com/melvincarvalho/OpenTabs" rel="doap:homepage"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://d3nwyuy0nl342s.cloudfront.net/img/71eeaab9d563c2b3c590319b398dd35683265e85/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub"></a>
38 </header>
39
2cbb865 @melvincarvalho first commit
melvincarvalho authored
40 <div class="container">
41
42 <div class="sixteen columns">
4afbb26 @melvincarvalho Opentabs -> Opentabs
melvincarvalho authored
43 <h1 class="remove-bottom" style="margin-top: 40px">Opentabs</h1>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
44
48715f4 @melvincarvalho Add loading text
melvincarvalho authored
45 <h5 id="welcome">Loading...</h5>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
46 <hr />
47 </div>
48 <div class="one-third column">
49
50 <ul class="tabs">
51 <!-- Give href an ID value of corresponding "tabs-content" <li>'s -->
52 <li><a class="active" href="#simple">My Tabs</a></li>
53
54 <li><a href="#lightweight">Send</a></li>
55 <li><a href="#mobileFriendly">Advanced</a></li>
56 </ul>
57
58 <ul class="tabs-content">
59 <li id="simple" class="active">
60 <div id="opentabs">
61
62 </div>
63 </li>
64
65 <li id="lightweight">
66 <form>
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
67 <select name="payee" id="payee">
68 <option value="testdummy@opentabs.net">Test Dummy</option>
69 </select>
597f91b @melvincarvalho set default size to 5
melvincarvalho authored
70 <input type="text" size="5" id="quantity" name="amount" value="5" />
2e3d379 @melvincarvalho currency readonly for now
melvincarvalho authored
71 <input readonly="true" size="5" type="text" id="currency" name="currency" value="EUR" />
2cbb865 @melvincarvalho first commit
melvincarvalho authored
72 <input type="button" value="Send" id="save" />
73 </form>
74 </li>
75 <li id="mobileFriendly">Advanced Settings coming soon.
76 <br/>
77
78 <form>
79 <button id="clearall">Clear All IOUs</button>
80 </form>
e6ba2dc @melvincarvalho test gmail login
melvincarvalho authored
81 <form action="https://data.fm/rp_auth">
0f00905 @melvincarvalho redirect to root rather than index.html
melvincarvalho authored
82 &nbsp;(WebID) <a href="https://data.fm/login?next=http://opentabs.data.fm/"><img style="float: left" src="http://data.fm/common/images/loginWebID.png" /></a><br/><br/><br/>
e6ba2dc @melvincarvalho test gmail login
melvincarvalho authored
83 </form>
0f00905 @melvincarvalho redirect to root rather than index.html
melvincarvalho authored
84 <a href="https://data.fm/login?provider=Gmail&next=http://opentabs.data.fm/"><img src="http://ealltd.com/images/gmail%20logo.jpg" /></a><br/><br/>
85 <a href="https://data.fm/login?provider=Yahoo&next=http://opentabs.data.fm/"><img src="http://www.textually.org/textually/archives/archives/images/set2/yahologo.gif" /></a>
31366c9 @melvincarvalho better login icons
melvincarvalho authored
86
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
87 <br/><br/><a href="javascript:document.IOU.FBLogin()"><img src="http://www.getfitwatford.co.uk/images/stories/images/facebook_40.gif" /></a><br/><br/>
0772965 @melvincarvalho WebID login
melvincarvalho authored
88
2cbb865 @melvincarvalho first commit
melvincarvalho authored
89 </li>
90 </ul>
91
92 </div>
93
94 </div>
95
96 <script src="javascripts/tabs.js"></script>
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
97 <script src="javascripts/sha1.js"></script>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
98 <script src="opentabs.js"></script>
99 <script>
100
101 (function($) {
102
103 var IOU = function() { this.load() };
104 IOU.prototype = {
105
106 IOUs: [],
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
107 friends: [],
2cbb865 @melvincarvalho first commit
melvincarvalho authored
108
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
109 loadUser: function() {
110 //alert('load user');
111 if (window.location.hash.length == 0) {
112 var script = document.createElement('script');
113 script.src = 'https://data.fm/user.js?callback=document.IOU.displayUser';
114 document.body.appendChild(script);
115 } else {
116 var accessToken = window.location.hash.substring(1);
117 var path = "https://graph.facebook.com/me?";
118 var queryParams = [accessToken, 'callback=document.IOU.displayUser'];
119 var query = queryParams.join('&');
120 var url = path + query;
121
122 // use jsonp to call the graph
123 var script = document.createElement('script');
124 script.src = url;
125 document.body.appendChild(script);
126 }
127 },
128
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
129 loadFriends: function() {
130 var accessToken = window.location.hash.substring(1);
131 var path = "https://graph.facebook.com/me/friends?";
132 var queryParams = [accessToken, 'callback=document.IOU.displayFriends'];
133 var query = queryParams.join('&');
134 var url = path + query;
135
136 // use jsonp to call the graph
137 var script = document.createElement('script');
138 script.src = url;
139 document.body.appendChild(script);
140 },
141
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
142 displayUser: function(user) {
143 var userName = document.getElementById('welcome');
144 if ( user.name ) {
145 var greetingText = document.createTextNode('Greetings, ' + user.name + '.');
146 window.user = 'https://graph.facebook.com/' + user.id;
dcd8233 @melvincarvalho facebook cleanup
melvincarvalho authored
147 userName.innerHTML = 'Greetings, ' + user.name;
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
148 this.loadFriends();
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
149 } else {
150 window.user = user;
151 var userName = document.getElementById('welcome');
152 userName.innerHTML = 'User: ' + window.user;
153 }
154 this.loadRemote();
155 },
156
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
157 displayFriends: function(data) {
158 var str;
159 for (i=0; i<data['data'].length; i++) {
160 var uri = 'https://graph.facebook.com/' + data['data'][i].id;
161 var n = data['data'][i].name;
162 this.friends.push( { 'uri' : uri , 'name' : n } );
163 $("#payee").append("<option value="+ uri +">"+ n +"</option>");
164 }
165 this.beautify();
166 },
167
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
168 FBLogin: function() {
169 var appID = "119467988130777";
170 if (window.location.hash.length == 0) {
171 var path = 'https://www.facebook.com/dialog/oauth?';
172 var queryParams = ['client_id=' + appID,
173 'redirect_uri=' + window.location,
174 'response_type=token'];
175 var query = queryParams.join('&');
176 var url = path + query;
177 window.location = url;
178 } else {
179 }
180 },
181
182
183
2cbb865 @melvincarvalho first commit
melvincarvalho authored
184 load: function() {
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
185 //this.IOUs = JSON.parse(window.localStorage.getItem('IOUs')) || [];
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
186 this.loadUser();
187 //this.loadRemote();
188 //this.render();
2cbb865 @melvincarvalho first commit
melvincarvalho authored
189 },
190
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
191 saveLocal: function() {
2cbb865 @melvincarvalho first commit
melvincarvalho authored
192 if( !this.confirm() ) {
193 alert('Operation Cancelled');
194 return;
195 }
196
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
197 if (!this.IOUs) this.IOUs = [];
198
94313f7 @melvincarvalho bugfix add mailto:
melvincarvalho authored
199 this.IOUs.push(this.createIOU(window.user, this.makeURI($('#payee').val()), $('#quantity').val(), $('#currency').val()));
2cbb865 @melvincarvalho first commit
melvincarvalho authored
200
201 window.localStorage.setItem('IOUs', JSON.stringify(this.IOUs));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
202 this.saveRemote();
203 this.syncRemote();
204
2cbb865 @melvincarvalho first commit
melvincarvalho authored
205
206 //this.load();
207 },
208
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
209 saveRemote: function() {
210 // get user
211 var user = window.user;
212
213 // DELETE
5fcba28 @melvincarvalho refactor delete file
melvincarvalho authored
214 this.deleteFile('http://opentabs.data.fm/d/' + hex_sha1(user));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
215
216 // PUT
217 var body = '@prefix rdf: <http://www.w3.org/1999/02/22/rdf-syntax-ns#>.\n\n<> <#IOUs> "'+ escape(JSON.stringify(this.IOUs)) +'" .';
f8ab86b @melvincarvalho refactor put file
melvincarvalho authored
218 this.putFile('http://opentabs.data.fm/d/' + hex_sha1(user), body);
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
219 //alert('http://opentabs.data.fm/d/' + hex_sha1(user) );
220
221 },
222
223 syncRemote: function() {
224 // get user
94313f7 @melvincarvalho bugfix add mailto:
melvincarvalho authored
225 var user = this.makeURI($('#payee').val());
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
226 var that = this;
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
227
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
228 try {
229 $.getJSON('http://opentabs.data.fm/d/'+ hex_sha1(user) +'.json' , function(data){
230 //alert(data);
231 var IOUs = JSON.parse(unescape(data['http://opentabs.data.fm/d/'+hex_sha1(user)]['http://opentabs.data.fm/d/'+hex_sha1(user)+'#IOUs'][0]['value']));
232 if (!IOUs) IOUs = [];
233 IOUs.push(that.createIOU($('#payee').val(), window.user, -1.0*$('#quantity').val(), $('#currency').val()));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
234
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
235 // DELETE
236 that.deleteFile('http://opentabs.data.fm/d/' + hex_sha1(user));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
237
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
238 // PUT
239 var body = '@prefix rdf: <http://www.w3.org/1999/02/22/rdf-syntax-ns#>.\n\n<> <#IOUs> "'+ escape(JSON.stringify(IOUs)) +'" .';
240 that.putFile('http://opentabs.data.fm/d/' + hex_sha1(user), body);
ba0d20d @melvincarvalho cleanup sync
melvincarvalho authored
241
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
242
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
243 window.location.reload();
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
244
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
245 }).error(function () {
246 var IOUs = [];
247 IOUs.push(that.createIOU($('#payee').val(), window.user, -1.0*$('#quantity').val(), $('#currency').val()));
248
249 // PUT
250 var body = '@prefix rdf: <http://www.w3.org/1999/02/22/rdf-syntax-ns#>.\n\n<> <#IOUs> "'+ escape(JSON.stringify(IOUs)) +'" .';
251 that.putFile('http://opentabs.data.fm/d/' + hex_sha1(user), body);
252
253 window.location.reload();
254
255 });
256 } catch (err) {
257 alert('could not sync');
258 }
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
259
260
261
262 },
263
264 loadRemote: function() {
265 // get user
266 var user = window.user;
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
267 if (!user) return;
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
268 that = this;
269
270
271 $.getJSON('http://opentabs.data.fm/d/'+ hex_sha1(user) +'.json' , function(data){
272 var IOUs = JSON.parse(unescape(data['http://opentabs.data.fm/d/'+hex_sha1(user)]['http://opentabs.data.fm/d/'+hex_sha1(user)+'#IOUs'][0]['value']));
273 //alert(JSON.stringify(IOUs));
274 that.IOUs = IOUs;
275 that.render();
276 });
277
dcd8233 @melvincarvalho facebook cleanup
melvincarvalho authored
278 //$('#welcome').html(window.user);
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
279
280 },
281
282
2cbb865 @melvincarvalho first commit
melvincarvalho authored
283 confirm: function() {
284 var IOU = 'You are about to send:\n\n'+ $('#payee').val()
285 IOU += '\n\nan IOU for ' + $('#quantity').val() + ' ' + $("#currency").val();
286 IOU += '\n\nAre you sure?';
287 return confirm(IOU);
288 },
289
290 render: function() {
291 $('#opentabs').empty();
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
292 if(!this.IOUs || !this.IOUs.length) {
2cbb865 @melvincarvalho first commit
melvincarvalho authored
293 $('#opentabs').append( $('<p>').text('You don\'t currently have any open tabs.') );
294 return;
295 }
296
297 var line = '<tr>'
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
298 line += '<td>IOU</td>';
299 line += '<td class="gold">Amount</td>';
2cbb865 @melvincarvalho first commit
melvincarvalho authored
300 line += '<td>Currency</td>';
301 line += '</tr>';
302 $('#opentabs').append( $('<table>').append(line) );
303
304 this.IOUs.forEach(function(item) {
305 if (item && item.IOU) {
306 var line = '<tr>'
041e59b @melvincarvalho add global namespaces to data model
melvincarvalho authored
307 line += '<td>' + item.IOU['com:destination'] + '</td>';
308 line += '<td class="gold"> ' + (-1 * item.IOU['com:amount']) + '</td>';
309 line += '<td>' + item.IOU['com:currency'] + '</td>';
2cbb865 @melvincarvalho first commit
melvincarvalho authored
310 line += '</tr>';
041e59b @melvincarvalho add global namespaces to data model
melvincarvalho authored
311 if ( $('td:contains("'+ item.IOU['com:destination'] +'")').length > 0 ) {
312 var prev = $('td:contains("'+ item.IOU['com:destination'] +'")').next().html();
313 $('td:contains("'+ item.IOU['com:destination'] +'")').next().html(1.0*prev + (-1 * item.IOU['com:amount']));
2cbb865 @melvincarvalho first commit
melvincarvalho authored
314 } else {
315 $('#opentabs table tr:last').after(line);
316   }
317 }
318 });
97e53fa @melvincarvalho beautify cells
melvincarvalho authored
319
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
320 this.beautify();
321
322 },
323
324 beautify: function() {
97e53fa @melvincarvalho beautify cells
melvincarvalho authored
325 // beautify cells
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
326 //alert('changing cells');
327 if ( !this.friends ) this.friends = [];
328 that = this;
97e53fa @melvincarvalho beautify cells
melvincarvalho authored
329 $('td').each(function() {
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
330 var html = $(this).html();
331 var n;
332 //alert(JSON.stringify(that.friends));
333 for (i=0; i<that.friends.length; i++) {
334 if ( that.friends[i].uri == html) {
335 n = that.friends[i].name;
336 //alert(n);
97e53fa @melvincarvalho beautify cells
melvincarvalho authored
337 }
00a7ec2 @melvincarvalho add facebook friends
melvincarvalho authored
338 }
339
340 if ( n ) {
341 $(this).html(n);
342 } else if ( html.substring(0,7) == 'mailto:' ) {
343 $(this).html(html.substring(7));
344 }
345 });
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
346
dcd8233 @melvincarvalho facebook cleanup
melvincarvalho authored
347 //$('#welcome').html(window.user);
2cbb865 @melvincarvalho first commit
melvincarvalho authored
348 },
349
350 clear: function() {
351 this.IOUs = window.localStorage.IOUs = null;
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
352 this.saveRemote();
2cbb865 @melvincarvalho first commit
melvincarvalho authored
353 this.load();
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
354 },
355
5fcba28 @melvincarvalho refactor delete file
melvincarvalho authored
356 deleteFile: function(file) {
357 var body = '';
358 xhr = new XMLHttpRequest();
359 xhr.open('DELETE', file, false);
360 xhr.setRequestHeader('Content-Type', 'text/turtle; charset=UTF-8');
361 xhr.send(body);
362 },
363
f8ab86b @melvincarvalho refactor put file
melvincarvalho authored
364 putFile: function(file, data) {
365 xhr = new XMLHttpRequest();
366 xhr.open('PUT', file, false);
367 xhr.setRequestHeader('Content-Type', 'text/turtle; charset=UTF-8');
368 xhr.send(data);
369 },
370
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
371 createIOU: function(source, destination, amount, currency) {
7b350fa @melvincarvalho add mailto
melvincarvalho authored
372
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
373 var IOU = {
374 id: '',
375 IOU: {
f4cf349 @melvincarvalho improve data model
melvincarvalho authored
376 "@context": "http://purl.org/opentabs",
377 "@type": "com:Transfer",
7b350fa @melvincarvalho add mailto
melvincarvalho authored
378 "com:source": this.makeURI(source),
379 "com:destination": this.makeURI(destination),
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
380 "com:amount": amount,
381 "com:currency": currency,
382 "dc:created": new Date(),
383 "rdfs:comment": 'a test IOU',
f4cf349 @melvincarvalho improve data model
melvincarvalho authored
384 "ot:state": 0
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
385 }
386 }
387 return IOU;
7b350fa @melvincarvalho add mailto
melvincarvalho authored
388 },
389
390 makeURI: function(id) {
391 if ( id.substring(0,7) == 'mailto:' ) {
392 return id;
393 } else if ( id.indexOf(':') != -1 ) {
394 return id;
395 } else {
396 return 'mailto:' + id;
397 }
2cbb865 @melvincarvalho first commit
melvincarvalho authored
398 }
399
400 };
401
402 $(document).ready(function() {
a527198 @melvincarvalho facebook cleanup
melvincarvalho authored
403 document.IOU = new IOU;
2cbb865 @melvincarvalho first commit
melvincarvalho authored
404 $('#clearall').click(function() { document.IOU.clear() });
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
405 $('#save').click(function() { document.IOU.saveLocal() });
2cbb865 @melvincarvalho first commit
melvincarvalho authored
406 });
407
408 })(jQuery);
409
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
410
411
2cbb865 @melvincarvalho first commit
melvincarvalho authored
412 </script>
413
414 </body>
636e47d @melvincarvalho remove base
melvincarvalho authored
415 </html>
Something went wrong with that request. Please try again.