Skip to content
This repository was archived by the owner on Sep 5, 2019. It is now read-only.

Commit 643394b

Browse files
author
Denis Krienbühl
committed
Shows a new date widget for event dates
1 parent 57ef918 commit 643394b

File tree

10 files changed

+373
-117
lines changed

10 files changed

+373
-117
lines changed

HISTORY.rst

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Changelog
22
---------
33

4+
- Shows a new date widget for event dates.
5+
[href]
6+
47
- Fixes print output of events and reservations.
58
[href]
69

onegov/org/app.py

+6
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ def get_many():
403403
yield 'many.jsx'
404404

405405

406+
@OrgApp.webasset('monthly-view')
407+
def get_monthly_view():
408+
yield 'daypicker.js'
409+
yield 'monthly-view.jsx'
410+
411+
406412
@OrgApp.webasset('common')
407413
def get_common_asset():
408414
yield 'global.js'

onegov/org/assets/js/daypicker.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

onegov/org/assets/js/monthly-view.jsx

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
var WEEKDAYS_SHORT = {
2+
de: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
3+
fr: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa']
4+
};
5+
6+
var MONTHS = {
7+
de: [
8+
'Januar',
9+
'Februar',
10+
'März',
11+
'April',
12+
'Mai',
13+
'Juni',
14+
'Juli',
15+
'August',
16+
'September',
17+
'Oktober',
18+
'November',
19+
'Dezember'
20+
],
21+
fr: [
22+
'Janvier',
23+
'Février',
24+
'Mars',
25+
'Avril',
26+
'Mai',
27+
'Juin',
28+
'Juillet',
29+
'Août',
30+
'Septembre',
31+
'Octobre',
32+
'Novembre',
33+
'Décembre'
34+
]
35+
};
36+
37+
var WEEKDAYS_LONG = {
38+
de: [
39+
'Sonntag',
40+
'Montag',
41+
'Dienstag',
42+
'Mittwoch',
43+
'Donnerstag',
44+
'Freitag',
45+
'Samstag'
46+
],
47+
fr: [
48+
'Dimanche',
49+
'Lundi',
50+
'Mardi',
51+
'Mercredi',
52+
'Jeudi',
53+
'Vendredi',
54+
'Samedi'
55+
]
56+
};
57+
58+
var FIRST_DAY_OF_WEEK = {
59+
de: 1,
60+
fr: 1
61+
};
62+
63+
var BUTTON_LABELS = {
64+
de: {
65+
nextMonth: 'nächster Monat',
66+
previousMonth: 'vorheriger Monat'
67+
},
68+
fr: {
69+
nextMonth: 'mois précédent',
70+
previousMonth: 'mois prochain'
71+
}
72+
};
73+
74+
var MonthlyView = React.createClass({
75+
render: function() {
76+
var locale = $('html').attr('lang').substring(0, 2);
77+
78+
return (
79+
<DayPicker
80+
locale={locale}
81+
months={MONTHS[locale]}
82+
weekdaysLong={WEEKDAYS_LONG[locale]}
83+
weekdaysShort={WEEKDAYS_SHORT[locale]}
84+
firstDayOfWeek={FIRST_DAY_OF_WEEK[locale]}
85+
labels={BUTTON_LABELS[locale]}
86+
selectedDays={this.props.selectedDays}
87+
fromMonth={this.props.selectedDays[0]}
88+
toMonth={this.props.selectedDays[this.props.selectedDays.length - 1]}
89+
/>
90+
);
91+
}
92+
});
93+
94+
var parseIsoDate = function(text) {
95+
var parts = text.split("-");
96+
97+
return new Date(
98+
parseInt(parts[0], 10),
99+
parseInt(parts[1], 10) - 1,
100+
parseInt(parts[2], 10)
101+
);
102+
};
103+
104+
var parseIsoDates = function(text) {
105+
var dates = (text || '').split(';');
106+
107+
for (var i = 0; i < dates.length; i++) {
108+
dates[i] = parseIsoDate(dates[i]);
109+
}
110+
111+
return dates;
112+
};
113+
114+
jQuery.fn.monthlyView = function() {
115+
return this.each(function() {
116+
var target = $(this);
117+
118+
var el = $('<div class="monthly-view-wrapper" />');
119+
el.appendTo(target);
120+
121+
ReactDOM.render(
122+
<MonthlyView selectedDays={parseIsoDates(target.attr('data-dates'))} />,
123+
el.get(0)
124+
);
125+
});
126+
};
127+
128+
$(document).ready(function() {
129+
$('.monthly-view').monthlyView();
130+
});

onegov/org/layout.py

+5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def view_example(self, request):
7171
date_long_without_year_format = 'E d. MMMM'
7272
datetime_long_without_year_format = 'E d. MMMM HH:mm'
7373
event_format = 'EEEE, d. MMMM YYYY'
74+
isodate_format = 'y-M-d'
7475

7576
def __init__(self, *args, **kwargs):
7677
# overrides body attributes set in the layout template
@@ -1308,6 +1309,10 @@ def editbar_links(self):
13081309

13091310
class OccurrenceLayout(EventBaseLayout):
13101311

1312+
def __init__(self, model, request):
1313+
super().__init__(model, request)
1314+
self.request.include('monthly-view')
1315+
13111316
@cached_property
13121317
def collection(self):
13131318
return OccurrenceCollection(self.request.session)

onegov/org/locale/de_CH/LC_MESSAGES/onegov.org.po

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
msgid ""
22
msgstr ""
33
"Project-Id-Version: PACKAGE 1.0\n"
4-
"POT-Creation-Date: 2018-11-28 14:25+0100\n"
4+
"POT-Creation-Date: 2018-11-29 15:56+0100\n"
55
"PO-Revision-Date: 2018-11-09 11:12+0100\n"
66
"Last-Translator: Marc Sommerhalder <[email protected]>\n"
77
"Language-Team: German\n"
@@ -2435,9 +2435,6 @@ msgstr ""
24352435
msgid "Drop files to verify them"
24362436
msgstr "Dateien zur Prüfung hierhin ziehen"
24372437

2438-
msgid "This is an imported event"
2439-
msgstr "Dies ist eine importierte Veranstaltung"
2440-
24412438
msgid "Export this event"
24422439
msgstr "Diesen Termin exportieren"
24432440

@@ -2447,6 +2444,12 @@ msgstr "Alle Termine exportieren"
24472444
msgid "All occurrences of this event"
24482445
msgstr "Alle Termine dieser Veranstaltung"
24492446

2447+
msgid "Origin"
2448+
msgstr "Herkunft"
2449+
2450+
msgid "This is an imported event"
2451+
msgstr "Dies ist eine importierte Veranstaltung"
2452+
24502453
msgid ""
24512454
"Subscribers may always unsubscribe themselves through a link shown at the "
24522455
"bottom of the newsletter. If you unsubscribe them here, they will not be "

0 commit comments

Comments
 (0)