Skip to content

Commit

Permalink
add notifiations to event creation, change mobile css, optimize calen…
Browse files Browse the repository at this point in the history
…dar templates a bit. solves a part of issue #66
  • Loading branch information
Andreas Demmelbauer committed Mar 6, 2017
1 parent 232bf60 commit d0d6270
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 163 deletions.
14 changes: 7 additions & 7 deletions cal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ def formatday(self, day, weekday):
if date.today() == date(self.year, self.month, day):
cssclass += ' today'
cssclass += ' filled'
body = ['<ul>']
body = ['<ul class="daily-events">']
for event in self.events.exclude(startDate__gt=d1).exclude(endDate__lt=d, endDate__isnull=False).exclude(endDate__isnull=True, startDate__lt=d):
body.append('<li>')
body.append('<li class="event">')
body.append('<a href="/wiki/%s">' % event.wikiPage)
body.append(event.startDate.strftime('%H:%M') + ' ' + esc(event.name))
body.append('<span class="event-time">' + event.startDate.strftime('%H:%M') + '</span> ' + esc(event.name))
body.append('</a>')
if self.admin:
body.append(u'<a href="%s" class="edit">/e</a>' % event.get_absolute_url())
body.append('</li>')
body.append('</ul>')
return self.day_cell(cssclass, '%d %s' % (day, (u''.join(body)).encode('utf-8')))
return self.day_cell(cssclass, '<div class="day-nr">%d</div> %s' % (day, (u''.join(body)).encode('utf-8')) )
return self.day_cell(cssclass, day)
return self.day_cell('noday', '&nbsp;')

def formatmonth(self, year, month, withyear=False):
def formatmonth(self, year, month):
self.year, self.month = year, month

d = date(int(year), int(month), 1)
prev = d - relativedelta.relativedelta(months=1)
next = d + relativedelta.relativedelta(months=1)
head = u'<a href="/calendar/%04d/%02d/">&lt;</a> <a href="/calendar/%04d/%02d/">&gt;</a>' % (prev.year, prev.month, next.year, next.month)
return head.encode('utf-8') + super(EventCalendar, self).formatmonth(year, month, withyear)
head = u'<a href="/calendar/%04d/%02d/" class="btn">&lsaquo;</a> <a href="/calendar/%04d/%02d/" class="btn">&rsaquo;</a>' % (prev.year, prev.month, next.year, next.month)
return head.encode('utf-8') + super(EventCalendar, self).formatmonth(year, month)

def group_by_day(self, events):
field = lambda event: event.startDate.day
Expand Down
49 changes: 30 additions & 19 deletions static/javascripts/ml-ajaxtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ function delete_entry(type, id) {
function toggleView(type, id, onoff) {
view = $(type + '-view-' + id);
edit = $(type + '-edit-' + id);

if (onoff) {
set_visible(edit);
set_invisible(view);
} else {
set_visible(view);
set_invisible(edit);
}
set_invisible(edit);
}
}

function set_visible(obj) {
Expand All @@ -98,10 +98,10 @@ function do_on_load()

function enter_pressed(e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return false;
return (keycode == 13);
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return false;
return (keycode == 13);
}

addEvent(window, 'load', do_on_load);
Expand All @@ -112,22 +112,33 @@ function submit_event(id) {
var cnt = $('calendar-edit-'+id);

new Ajax.Request(frm.readAttribute('action'), {
parameters: frm.serialize(true),
onSuccess: function(r) {
new Ajax.Updater('calendar-content', calendarUpdateURL, {
method: 'get'})
},
onFailure: function(r) {
cnt.innerHTML = r.responseText;
DateTimeShortcuts.init.defer(1);
}
})
parameters: frm.serialize(true),
onSuccess: function(r) {

var notification = document.createElement('div');
notification.className = 'notification success';
notification.innerHTML = '<h3>Event created or updated!</h3> ' + r.responseText;
document.getElementById('calendar-update').parentNode.appendChild(notification);

new Ajax.Updater('calendar-update', calendarUpdateURL, {
method: 'get'
});

// new Notification('success', 'Event created/updated!', r.responseText).show();


},
onFailure: function(r) {
cnt.innerHTML = r.responseText;
DateTimeShortcuts.init.defer(1);
}
})
}


function update_metasense() {
/*new Ajax.Request('http://metalab.at/metasense/status.html', {asynchronous:true, onFailure:function(){}, onException:function(){}, onSuccess:function(transport){ */
new Ajax.Request('/metasense/status.html', {asynchronous:true, onFailure:function(){}, onException:function(){}, onSuccess:function(transport){
new Ajax.Request('/metasense/status.html', {asynchronous:true, onFailure:function(){}, onException:function(){}, onSuccess:function(transport){
oopen = $('presence_open');
oclosed = $('presence_closed');
odefunct = $('presence_defunct');
Expand All @@ -137,7 +148,7 @@ function update_metasense() {
set_invisible(odefunct);
} else if( transport.responseText.match("niemand")){
set_visible(oclosed);
set_invisible(oopen);
set_invisible(oopen);
set_invisible(odefunct);
} else {
set_invisible(oopen);
Expand Down
92 changes: 42 additions & 50 deletions static/stylesheets/cal.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@

#calendar-content ul {
border: 1px solid #ddd;
box-sizing: border-box;
}

#calendar-content li {
display: block;
/* width:100%; broken on IE7 :(*/
width: 329px;
}

#calendar-content div {
padding: 1px 0 0 1px;
#calendar-content li {
padding: 1px 1px 0 1px;
}

#calendar-content li p {
Expand All @@ -27,7 +26,7 @@
}
*/
#calendar-content li .event {
background: #C8D8FF;
background: #C8D8FF;
}

#calendar-content li .past_event {
Expand Down Expand Up @@ -66,6 +65,7 @@

table.month {
border-collapse: collapse;
width: 100%;
}

table.month th {
Expand All @@ -78,7 +78,7 @@ table.month th {
table.month th.month {
background-color: inherit;
font-size: 20pt;
padding: 4px;
padding: 4px 0;
color: #aaa;
text-align: right;
}
Expand All @@ -87,8 +87,9 @@ table.month td {
border: 1px solid white;
background-color: #ddd;
width: 14%;
height: 110px;
height: 5em;
color: #999;
hyphens: auto;
}

table.month td:nth-last-child(-n+2) {
Expand All @@ -115,62 +116,53 @@ table.month td li:last-child {
}

table.month td.today {
background-color: #c0c0ff;
background-color: #c0c0ff;
color:white;
font-weight:bold;
}

table.month .day-nr {
text-align: right;
line-height: 1em;
}
table.month .event-time {
font-weight: bold;
}

#calendar-year-list {
text-align: right;
}

@media screen and (max-width: 800px) {
.edit-form {
max-width: 20em;
background-color: #f6f6f6;
padding: 1em;
}

table.month th.month {
text-align: left;
margin: .2em 0;
}


.month .noday, /* hide nodays */
.month tr:nth-child(2) /* hide weekdays*/
{
position: absolute;
top: -9999px;
left: -9999px;
}
@media screen and (max-width: 800px) {

table.month td {
width:auto;
table.month {
margin: 0 -2%;
width: 104%;
}


/* reset table stuff */
table.month,
.month tbody,
.month th,
.month td,
.month tr {
display: block;
table.month .event-time {
display: block;
font-size: .9em;
}

.month td {
position: relative;
padding-left: 2em;
table.month .event {
font-size: .9em;
word-wrap: break-word;
hyphens: auto;
line-height: 1em;
word-break: break-all;
overflow-wrap: break-word;
text-overflow: ellipsis;
overflow: hidden;
width: 100%;
word-wrap: normal;
}

/* weekdays via css */
.month td:before {
position: absolute;
top: 3px;
left: 3px;
padding-right: 10px;
white-space: nowrap;
}
.month td:nth-of-type(1):before { content: "Mo"; }
.month td:nth-of-type(2):before { content: "Di"; }
.month td:nth-of-type(3):before { content: "Mi"; }
.month td:nth-of-type(4):before { content: "Do"; }
.month td:nth-of-type(5):before { content: "Fr"; }
.month td:nth-of-type(6):before { content: "Sa"; }
.month td:nth-of-type(7):before { content: "So"; }
}

Loading

0 comments on commit d0d6270

Please sign in to comment.