public
Description: A base class for HTTP based activities for the OLPC laptop
Homepage: https://www.socialtext.net/lukec/index.cgi?httpactivity
Clone URL: git://github.com/lukec/httpactivity.git
httpactivity / dev-guide.txt
100644 65 lines (46 sloc) 2.016 kb
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
HTTP based Socialcalc Interface TODO List
 
* Create HTTPActivity.py
* Create OnePageWikiActivity.py
 
 
Could Do List
* include jquery pdf in pyhttpjs - great docs
* have a special uid in each request
* server could support syncing several clients
* blog post about this process - dev tools, good/bad
 
----
 
Packaging - HTTPActivity
 
Desc: A base class for building simple web clients
 
Synopsis:
  import HTTPActivity
  
  class MyActivity(HTTPActivity):
    TODO - add more synopsis
 
Overview:
  Your web based application must be able, at a minimum, to launch and display
  itself, write state to the journal, and load back up from the journal.
 
  Starting up your application:
    A web server will be started on an internal port, and web/index.html will
    be loaded in the webserver
 
  Your application must define two javascript hooks that will be called to
  interact with the journal.
    
    document.XO_read_hook = function (content) {
        // Do something with the content
        // Eg: stick it in a textarea in the page
        jQuery('textarea').html(content)
    }
    document.XO_write_hook = function () {
        // Return the content to save to the journal
        // Eg: save the content of a textarea
        return jQuery('textarea').html()
    }
 
  In the background, the browser will make HTTP requests to the built-in HTTP
  server. Based on the response of the server, different hooks will be
  called.
 
  Pro-active saving:
    It may be possible to lose data (unconfirmed) if the activity is closed
    before the browser has time to write to the journal. So you may want to
    proactively save, if the browser is idle, or a big change has happened.
 
      XO.write_to_journal( save_content )
 
    This will tell the python activity to save this content the next chance it
    has.
 
  Technical Note: Currently the server immediately returns the requests, but
  a possible improvement is for the server to hold the request open until it
  times out or there is a response ready.