AJAX-driven Calendar Widget

This commit is contained in:
Raoul Snyman 2010-02-28 23:25:48 +02:00
commit 85f1515f82
4 changed files with 36 additions and 16 deletions

View File

@ -47,10 +47,9 @@ def make_map():
map.connect('/archive/{year}/{month}', controller='blog', action='archive') map.connect('/archive/{year}/{month}', controller='blog', action='archive')
map.connect('/archive/{year}/{month}/{day}', controller='blog', action='archive') map.connect('/archive/{year}/{month}/{day}', controller='blog', action='archive')
map.connect('/archive/{year}/{month}/{day}/{url}', controller='blog', action='view') map.connect('/archive/{year}/{month}/{day}/{url}', controller='blog', action='view')
map.connect('/search', controller='blog', action='search') map.connect('/search', controller='blog', action='search')
map.connect('/tag/{id}', controller='blog', action='tag') map.connect('/tag/{id}', controller='blog', action='tag')
map.connect('/calendar/{year}/{month}', controller='blog', action='calendar')
map.connect('/{controller}/{action}') map.connect('/{controller}/{action}')
map.connect('/{controller}/{action}/{id}') map.connect('/{controller}/{action}/{id}')

View File

@ -167,3 +167,22 @@ class BlogController(BaseController):
c.page_title = u'Search' c.page_title = u'Search'
return render(u'/blog/search.mako') return render(u'/blog/search.mako')
def calendar(self, year, month):
#c.calendar = Calendar(6)
#c.today = datetime.today()
c.thismonth = datetime.now().replace(int(year), int(month))
c.prev_month = c.thismonth - monthdelta(1)
c.next_month = c.thismonth + monthdelta(1)
month_start = datetime(c.thismonth.year, c.thismonth.month, 1, 0, 0, 0, 0)
month_end = c.next_month.replace(day=1, hour=23, minute=59, second=59, microsecond=9999) - timedelta(seconds=1)
posts = Session.query(Post)\
.filter(Post.created >= month_start)\
.filter(Post.created <= month_end)\
.all()
c.month_posts = {}
for post in posts:
if post.created.day not in c.month_posts:
c.month_posts[post.created.day] = []
c.month_posts[post.created.day].append(post)
return render(u'/calendar.mako')

View File

@ -160,6 +160,18 @@ ScribeEngine.Namespace.create("ScribeEngine.General", {
{ {
$(".jshidden").hide(); $(".jshidden").hide();
}, },
/**
* Go to a particular month or year on the calendar.
*/
go_to_month: function (e)
{
var link = ScribeEngine.Events.getElement(e);
$("#calendar_wrap").load(link.attr("href"), function() {
ScribeEngine.Events.click("#next a", ScribeEngine.General.go_to_month);
ScribeEngine.Events.click("#prev a", ScribeEngine.General.go_to_month);
});
return false;
},
/** /**
* Do all the funny things required to toggle a fieldset * Do all the funny things required to toggle a fieldset
*/ */
@ -190,18 +202,6 @@ ScribeEngine.Namespace.create("ScribeEngine.General", {
$ScribeEngine.General.perform_toggle(fieldset); $ScribeEngine.General.perform_toggle(fieldset);
return false; return false;
}, },
/**
* Sets the active project
*/
set_project: function ()
{
$('#project-selector > div.content').hide();
$('#project-throbber').show();
project_id = $("#CurrentProject").val();
$.get('/dashboard/ajax_project/' + project_id, function () {
window.location.reload();
});
},
/** /**
* Initialises collapsible fieldsets * Initialises collapsible fieldsets
*/ */
@ -234,4 +234,6 @@ ScribeEngine.Namespace.create("ScribeEngine.General", {
* This function below will be executed on all page views. * This function below will be executed on all page views.
*/ */
ScribeEngine.Events.load(function () { ScribeEngine.Events.load(function () {
ScribeEngine.Events.click("#next a", ScribeEngine.General.go_to_month);
ScribeEngine.Events.click("#prev a", ScribeEngine.General.go_to_month);
}); });

View File

@ -15,9 +15,9 @@
</thead> </thead>
<tfoot> <tfoot>
<tr> <tr>
<td abbr="${c.prev_month.strftime('%B')}" colspan="3" id="prev"><a href="#" title="View posts for ${c.prev_month.strftime('%B %Y')}">&laquo; ${c.prev_month.strftime('%b')}</a></td> <td abbr="${c.prev_month.strftime('%B')}" colspan="3" id="prev"><a href="/calendar/${c.prev_month.strftime('%Y/%m')}" title="View posts for ${c.prev_month.strftime('%B %Y')}">&laquo; ${c.prev_month.strftime('%b')}</a></td>
<td class="pad">&nbsp;</td> <td class="pad">&nbsp;</td>
<td abbr="${c.next_month.strftime('%B')}" colspan="3" id="next"><a href="#" title="View posts for ${c.next_month.strftime('%B %Y')}">${c.next_month.strftime('%b')} &raquo;</a></td> <td abbr="${c.next_month.strftime('%B')}" colspan="3" id="next"><a href="/calendar/${c.next_month.strftime('%Y/%m')}" title="View posts for ${c.next_month.strftime('%B %Y')}">${c.next_month.strftime('%b')} &raquo;</a></td>
</tr> </tr>
</tfoot> </tfoot>
<tbody> <tbody>