Skip to content

Commit 0d7c579

Browse files
author
Paul Bersch
committed
Hooray! Ajax posting now correctly updates the post on the page without reloading.
1 parent 9e68b39 commit 0d7c579

File tree

5 files changed

+31
-84
lines changed

5 files changed

+31
-84
lines changed

js/functions.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ function fill_form_and_escape(postID) {
3535
ajax.open('POST', 'edit', true);
3636
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
3737
ajax.send(data);
38-
$('.hidden').ajaxSuccess(updatePost(postID));
38+
ajax.onreadystatechange = function() {
39+
if(ajax.readyState == 4){
40+
updatePost(postID);
41+
}
42+
};
3943
}
4044

4145
function setClickable() {
@@ -82,25 +86,11 @@ function newPostSetClickable() {
8286

8387
function updatePost(postID) {
8488
$('#editTextarea').remove();
85-
//var newElement = document.createElement('div');
86-
//newElement.setAttribute('class', 'post');
87-
//newElement.setAttribute('id', postID);
88-
//$('.hidden').after(newElement);
89-
//$('.hidden').remove();
9089

9190
$('.hidden').load("ajaxget", {"id": postID});
9291
$('.hidden').show("fast");
9392
$('.hidden').removeClass("hidden");
9493

95-
// var newElement = document.createElement('div');
96-
// newElement.setAttribute('class', 'post newelement');
97-
// newElement.setAttribute('style', 'display: none');
98-
// $('.hidden').after(newelement);
99-
// $('.hidden').replaceWith(newElement);
100-
// $('.hidden').load("ajaxget", {"id": postID});
101-
// $('.hidden').show("fast");
102-
// $('.hidden').removeClass("hidden");
103-
10494
}
10595

10696
function cancelEditing() {

post.py

Lines changed: 15 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import re, os
55

66
# update config file to current working directory
7-
regex = re.compile('current_directory')
7+
def updateConfig(self):
8+
regex = re.compile('current_directory')
89

9-
f = open('post.config.base', 'r')
10-
contents = f.read()
11-
contents = regex.sub(os.getcwd(), contents)
12-
f.close()
10+
# open base file
11+
f = open('post.config.base', 'r')
12+
contents = f.read()
13+
contents = regex.sub(os.getcwd(), contents)
14+
f.close()
1315

14-
f = open('post.config', 'w')
15-
f.write(contents)
16-
f.close()
16+
# write new config file
17+
f = open('post.config', 'w')
18+
f.write(contents)
19+
f.close()
1720

1821
class Post(object):
1922
def __init__(self, date = datetime.today().strftime('%Y%m%d%H%M%S'), title = "", body = ""):
@@ -88,10 +91,10 @@ def index(self):
8891
header = open('theme/header.php', 'r')
8992
page.append(header.read())
9093
header.close()
91-
94+
9295
for post in self.posts:
9396
page.append(post.createPost())
94-
97+
9598
footer = open('theme/footer.php', 'r')
9699
page.append(footer.read())
97100
footer.close()
@@ -118,68 +121,14 @@ def ajaxget(self, id):
118121
return post.createPost(False)
119122
ajaxget.exposed = True
120123

121-
124+
122125

123126
cherrypy.tree.mount(Blog(), config='post.config')
124127

125128
if __name__ == '__main__':
126129
import os.path
127130
cherrypy.config.update(os.path.join(os.path.dirname(__file__), 'tutorial.conf'))
128-
131+
129132
cherrypy.server.quickstart()
130133
cherrypy.engine.start()
131134

132-
133-
"""
134-
[/]
135-
tools.staticdir.root = os.path.normcase('C:/Documents and Settings/pnbersch/Desktop/play/ponies/')
136-
[/js/jquery-1.2.1.js]
137-
tools.staticfile.on = True
138-
tools.staticfile.filename = os.path.normcase("C:/Documents and Settings/pnbersch/Desktop/play/ponies/js/jquery-1.2.1.js")
139-
140-
[/js/functions.js]
141-
tools.staticfile.on = True
142-
tools.staticfile.filename = os.path.normcase("C:/Documents and Settings/pnbersch/Desktop/play/ponies/js/functions.js")
143-
144-
[/theme/main.css]
145-
tools.staticfile.on = True
146-
tools.staticfile.filename = os.path.normcase("C:\Documents and Settings\pnbersch\Desktop\play\ponies/theme/main.css")
147-
148-
149-
150-
151-
"""
152-
153-
154-
# myblog = Blog()
155-
156-
# print myblog.makePage()
157-
158-
#for post in myblog.posts:
159-
# print post.title
160-
# print post.date
161-
# print post.markedupbody
162-
163-
164-
#print myblog.posts[0].title
165-
#print myblog.posts[0].date
166-
#print myblog.posts[0].body
167-
168-
# datetime.today().strftime('%Y%m%d%H%M%S')
169-
170-
#thepost = Post()
171-
172-
#thepost.title = 'Fear!'
173-
#thepost.body = 'I find that you should fear all _ponies_.'
174-
175-
#thepost.markupbody()
176-
177-
#print thepost.title
178-
179-
#print thepost.date.strftime('%Y%m%d%H%M%S')
180-
181-
#print thepost.body
182-
183-
#print thepost.markedupbody
184-
185-

posts/20080204020312

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ Changed.
44

55
Many times. Many.
66

7-
Lalala. asfdasdfj jaykay
7+
Lalala. asfdasdfj jaykay
8+
9+
A change. Changechangechange.
10+
11+
And when it updates, you know!

posts/20080406020312

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ Changes are afloat.
44

55
Twice are there changes.
66

7-
And thrice.
7+
And thrice. Thrice truly.
8+
9+
Wahhhh changeeee.

posts/20081028174152

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
This is the title
22
And this is the body. The body of cheese.
33

4-
Lalala.
4+
Lalala. LAAAAAAAAAA.
5+
6+
Change!

0 commit comments

Comments
 (0)