Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 320 lines (244 sloc) 10.641 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>
35 <script>function user(data) { window.user = data; $('#welcome').val(data); }</script>
36 <script src="https://data.fm/user.js"></script>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
37
1412a78 @melvincarvalho add github link
melvincarvalho authored
38 <header>
39 <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>
40 </header>
41
2cbb865 @melvincarvalho first commit
melvincarvalho authored
42 <div class="container">
43
44 <div class="sixteen columns">
4afbb26 @melvincarvalho Opentabs -> Opentabs
melvincarvalho authored
45 <h1 class="remove-bottom" style="margin-top: 40px">Opentabs</h1>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
46
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
47 <h5 id="welcome"></h5>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
48 <hr />
49 </div>
50 <div class="one-third column">
51
52 <ul class="tabs">
53 <!-- Give href an ID value of corresponding "tabs-content" <li>'s -->
54 <li><a class="active" href="#simple">My Tabs</a></li>
55
56 <li><a href="#lightweight">Send</a></li>
57 <li><a href="#mobileFriendly">Advanced</a></li>
58 </ul>
59
60 <ul class="tabs-content">
61 <li id="simple" class="active">
62 <div id="opentabs">
63
64 </div>
65 </li>
66
67 <li id="lightweight">
68 <form>
69 <input size="20" type="text" id="payee" name="payee" value="testdummy@opentabs.net" />
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">
31366c9 @melvincarvalho better login icons
melvincarvalho authored
82 &nbsp;(WebID) <a href="https://data.fm/login?next=http://opentabs.data.fm/index.html"><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>
578bcee @melvincarvalho redirect to app
melvincarvalho authored
84 <a href="https://data.fm/login?provider=Gmail&next=http://opentabs.data.fm/index.html"><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/index.html"><img src="http://www.textually.org/textually/archives/archives/images/set2/yahologo.gif" /></a>
31366c9 @melvincarvalho better login icons
melvincarvalho authored
86
0772965 @melvincarvalho WebID login
melvincarvalho authored
87
2cbb865 @melvincarvalho first commit
melvincarvalho authored
88 </li>
89 </ul>
90
91 </div>
92
93 </div>
94
95 <script src="javascripts/tabs.js"></script>
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
96 <script src="javascripts/sha1.js"></script>
2cbb865 @melvincarvalho first commit
melvincarvalho authored
97 <script src="opentabs.js"></script>
98 <script>
99
100 (function($) {
101
102 var IOU = function() { this.load() };
103 IOU.prototype = {
104
105 IOUs: [],
106
107 load: function() {
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
108 //this.IOUs = JSON.parse(window.localStorage.getItem('IOUs')) || [];
109 this.loadRemote();
2cbb865 @melvincarvalho first commit
melvincarvalho authored
110 this.render();
111 },
112
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
113 saveLocal: function() {
2cbb865 @melvincarvalho first commit
melvincarvalho authored
114 if( !this.confirm() ) {
115 alert('Operation Cancelled');
116 return;
117 }
118
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
119 if (!this.IOUs) this.IOUs = [];
120
94313f7 @melvincarvalho bugfix add mailto:
melvincarvalho authored
121 this.IOUs.push(this.createIOU(window.user, this.makeURI($('#payee').val()), $('#quantity').val(), $('#currency').val()));
2cbb865 @melvincarvalho first commit
melvincarvalho authored
122
123 window.localStorage.setItem('IOUs', JSON.stringify(this.IOUs));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
124 this.saveRemote();
125 this.syncRemote();
126
2cbb865 @melvincarvalho first commit
melvincarvalho authored
127
128 //this.load();
129 },
130
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
131 saveRemote: function() {
132 // get user
133 var user = window.user;
134
135 // DELETE
5fcba28 @melvincarvalho refactor delete file
melvincarvalho authored
136 this.deleteFile('http://opentabs.data.fm/d/' + hex_sha1(user));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
137
138 // PUT
139 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
140 this.putFile('http://opentabs.data.fm/d/' + hex_sha1(user), body);
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
141 //alert('http://opentabs.data.fm/d/' + hex_sha1(user) );
142
143 },
144
145 syncRemote: function() {
146 // get user
94313f7 @melvincarvalho bugfix add mailto:
melvincarvalho authored
147 var user = this.makeURI($('#payee').val());
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
148 var that = this;
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
149
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
150 try {
151 $.getJSON('http://opentabs.data.fm/d/'+ hex_sha1(user) +'.json' , function(data){
152 //alert(data);
153 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']));
154 if (!IOUs) IOUs = [];
155 IOUs.push(that.createIOU($('#payee').val(), window.user, -1.0*$('#quantity').val(), $('#currency').val()));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
156
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
157 // DELETE
158 that.deleteFile('http://opentabs.data.fm/d/' + hex_sha1(user));
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
159
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
160 // PUT
161 var body = '@prefix rdf: <http://www.w3.org/1999/02/22/rdf-syntax-ns#>.\n\n<> <#IOUs> "'+ escape(JSON.stringify(IOUs)) +'" .';
162 that.putFile('http://opentabs.data.fm/d/' + hex_sha1(user), body);
ba0d20d @melvincarvalho cleanup sync
melvincarvalho authored
163
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
164
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
165 window.location.reload();
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
166
eac8913 @melvincarvalho catch 404 errors
melvincarvalho authored
167 }).error(function () {
168 var IOUs = [];
169 IOUs.push(that.createIOU($('#payee').val(), window.user, -1.0*$('#quantity').val(), $('#currency').val()));
170
171 // PUT
172 var body = '@prefix rdf: <http://www.w3.org/1999/02/22/rdf-syntax-ns#>.\n\n<> <#IOUs> "'+ escape(JSON.stringify(IOUs)) +'" .';
173 that.putFile('http://opentabs.data.fm/d/' + hex_sha1(user), body);
174
175 window.location.reload();
176
177 });
178 } catch (err) {
179 alert('could not sync');
180 }
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
181
182
183
184 },
185
186 loadRemote: function() {
187 // get user
188 var user = window.user;
189 that = this;
190
191
192 $.getJSON('http://opentabs.data.fm/d/'+ hex_sha1(user) +'.json' , function(data){
193 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']));
194 //alert(JSON.stringify(IOUs));
195 that.IOUs = IOUs;
196 that.render();
197 });
198
199 $('#welcome').html(window.user);
200
201 },
202
203
2cbb865 @melvincarvalho first commit
melvincarvalho authored
204 confirm: function() {
205 var IOU = 'You are about to send:\n\n'+ $('#payee').val()
206 IOU += '\n\nan IOU for ' + $('#quantity').val() + ' ' + $("#currency").val();
207 IOU += '\n\nAre you sure?';
208 return confirm(IOU);
209 },
210
211 render: function() {
212 $('#opentabs').empty();
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
213 if(!this.IOUs || !this.IOUs.length) {
2cbb865 @melvincarvalho first commit
melvincarvalho authored
214 $('#opentabs').append( $('<p>').text('You don\'t currently have any open tabs.') );
215 return;
216 }
217
218 var line = '<tr>'
219 line += '<td>IOU&nbsp;</td>';
220 line += '<td class="gold">Amount&nbsp;</td>';
221 line += '<td>Currency</td>';
222 line += '</tr>';
223 $('#opentabs').append( $('<table>').append(line) );
224
225 this.IOUs.forEach(function(item) {
226 if (item && item.IOU) {
227 var line = '<tr>'
041e59b @melvincarvalho add global namespaces to data model
melvincarvalho authored
228 line += '<td>' + item.IOU['com:destination'] + '</td>';
229 line += '<td class="gold"> ' + (-1 * item.IOU['com:amount']) + '</td>';
230 line += '<td>' + item.IOU['com:currency'] + '</td>';
2cbb865 @melvincarvalho first commit
melvincarvalho authored
231 line += '</tr>';
041e59b @melvincarvalho add global namespaces to data model
melvincarvalho authored
232 if ( $('td:contains("'+ item.IOU['com:destination'] +'")').length > 0 ) {
233 var prev = $('td:contains("'+ item.IOU['com:destination'] +'")').next().html();
234 $('td:contains("'+ item.IOU['com:destination'] +'")').next().html(1.0*prev + (-1 * item.IOU['com:amount']));
2cbb865 @melvincarvalho first commit
melvincarvalho authored
235 } else {
236 $('#opentabs table tr:last').after(line);
237   }
238 }
239 });
97e53fa @melvincarvalho beautify cells
melvincarvalho authored
240
241 // beautify cells
242 $('td').each(function() {
243 var html = $(this).html();
244 if ( html.substring(0,7) == 'mailto:' ) {
245 $(this).html(html.substring(7));
246 }
247 }
248 );
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
249
250 $('#welcome').html(window.user);
2cbb865 @melvincarvalho first commit
melvincarvalho authored
251
252 },
253
254 clear: function() {
255 this.IOUs = window.localStorage.IOUs = null;
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
256 this.saveRemote();
2cbb865 @melvincarvalho first commit
melvincarvalho authored
257 this.load();
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
258 },
259
5fcba28 @melvincarvalho refactor delete file
melvincarvalho authored
260 deleteFile: function(file) {
261 var body = '';
262 xhr = new XMLHttpRequest();
263 xhr.open('DELETE', file, false);
264 xhr.setRequestHeader('Content-Type', 'text/turtle; charset=UTF-8');
265 xhr.send(body);
266 },
267
f8ab86b @melvincarvalho refactor put file
melvincarvalho authored
268 putFile: function(file, data) {
269 xhr = new XMLHttpRequest();
270 xhr.open('PUT', file, false);
271 xhr.setRequestHeader('Content-Type', 'text/turtle; charset=UTF-8');
272 xhr.send(data);
273 },
274
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
275 createIOU: function(source, destination, amount, currency) {
7b350fa @melvincarvalho add mailto
melvincarvalho authored
276
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
277 var IOU = {
278 id: '',
279 IOU: {
f4cf349 @melvincarvalho improve data model
melvincarvalho authored
280 "@context": "http://purl.org/opentabs",
281 "@type": "com:Transfer",
7b350fa @melvincarvalho add mailto
melvincarvalho authored
282 "com:source": this.makeURI(source),
283 "com:destination": this.makeURI(destination),
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
284 "com:amount": amount,
285 "com:currency": currency,
286 "dc:created": new Date(),
287 "rdfs:comment": 'a test IOU',
f4cf349 @melvincarvalho improve data model
melvincarvalho authored
288 "ot:state": 0
0a23ea0 @melvincarvalho refactor create IOU
melvincarvalho authored
289 }
290 }
291 return IOU;
7b350fa @melvincarvalho add mailto
melvincarvalho authored
292 },
293
294 makeURI: function(id) {
295 if ( id.substring(0,7) == 'mailto:' ) {
296 return id;
297 } else if ( id.indexOf(':') != -1 ) {
298 return id;
299 } else {
300 return 'mailto:' + id;
301 }
2cbb865 @melvincarvalho first commit
melvincarvalho authored
302 }
303
304 };
305
306 $(document).ready(function() {
307 document.IOU = new IOU;
308 $('#clearall').click(function() { document.IOU.clear() });
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
309 $('#save').click(function() { document.IOU.saveLocal() });
2cbb865 @melvincarvalho first commit
melvincarvalho authored
310 });
311
312 })(jQuery);
313
afd2d5e @melvincarvalho remote save first release
melvincarvalho authored
314
315
2cbb865 @melvincarvalho first commit
melvincarvalho authored
316 </script>
317
318 </body>
636e47d @melvincarvalho remove base
melvincarvalho authored
319 </html>
Something went wrong with that request. Please try again.