webmcp
view framework/env/ui_deprecated/calendar.lua @ 3:795b764629ca
Version 1.0.3
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
Important bugfix related to internal forwards (Bug was introduced by the restriction of views with underscore prefix in Version 1.0.2)
author | jbe |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children |
line source
1 function ui_deprecated.calendar(args)
2 local record = assert(slot.get_state_table(), "ui_deprecated.calender was not called within a form.").form_record
3 local value = param.get(args.field, atom.date) or record[args.field]
4 local year = param.get('_ui_calendar_year', atom.integer) or args.year or 2008
5 local month = param.get('_ui_calendar_month', atom.integer) or args.month or 10
6 local empty_days = atom.date{ year = year, month = month, day = 1 }.iso_weekday -1
7 local enabled = not args.disabled
9 local prev_year = year
10 local prev_month = month - 1
11 if prev_month == 0 then
12 prev_month = 12
13 prev_year = prev_year - 1
14 end
16 local next_year = year
17 local next_month = month + 1
18 if next_month == 13 then
19 next_month = 1
20 next_year = next_year + 1
21 end
23 ui_deprecated.tag('div', {
24 html_options = {
25 class="ui_field ui_calendar"
26 },
27 content = function()
28 ui_deprecated.tag('input', {
29 html_options = {
30 type = 'hidden',
31 value = year,
32 name = '_ui_calendar_year',
33 id = '_ui_calendar_year',
34 onchange = 'this.form.submit();'
35 }
36 })
37 ui_deprecated.tag('input', {
38 html_options = {
39 type = 'hidden',
40 value = month,
41 name = '_ui_calendar_month',
42 id = '_ui_calendar_month',
43 onchange = 'this.form.submit();'
44 }
45 })
46 ui_deprecated.tag('input', {
47 html_options = {
48 type = 'hidden',
49 value = value and tostring(value) or '',
50 name = args.field,
51 id = '_ui_calendar_input',
52 onchange = 'this.form.submit();'
53 }
54 })
55 if args.label then
56 ui_deprecated.tag('div', {
57 html_options = {
58 class="label"
59 },
60 content = function()
61 ui_deprecated.text(args.label)
62 end
63 })
64 end
65 ui_deprecated.tag('div', {
66 html_options = {
67 class="value"
68 },
69 content = function()
70 ui_deprecated.tag('div', {
71 html_options = {
72 class = 'next',
73 href = '#',
74 onclick = enabled and "document.getElementById('_ui_calendar_year').value = '" .. tostring(next_year) .. "'; document.getElementById('_ui_calendar_month').value = '" .. tostring(next_month) .. "'; document.getElementById('_ui_calendar_year').form.submit();" or '',
75 },
76 content = '>>>';
77 })
78 ui_deprecated.tag('div', {
79 html_options = {
80 class = 'prev',
81 href = '#',
82 onclick = enabled and "document.getElementById('_ui_calendar_year').value = '" .. tostring(prev_year) .. "'; document.getElementById('_ui_calendar_month').value = '" .. tostring(prev_month) .. "'; document.getElementById('_ui_calendar_year').form.submit();" or '',
83 },
84 content = '<<<';
85 })
86 ui_deprecated.tag('div', {
87 html_options = {
88 class="title"
89 },
90 content = function()
91 local months = {_'January', _'February', _'March', _'April', _'May', _'June', _'July', _'August', _'September', _'October', _'November', _'December' }
92 ui_deprecated.text(months[month])
93 ui_deprecated.text(' ')
94 ui_deprecated.text(tostring(year))
95 end
96 })
97 ui_deprecated.tag('table', {
98 content = function()
99 ui_deprecated.tag('thead', {
100 content = function()
101 ui_deprecated.tag('tr', {
102 content = function()
103 local dows = { _'Mon', _'Tue', _'Wed', _'Thu', _'Fri', _'Sat', _'Sun' }
104 for col = 1,7 do
105 ui_deprecated.tag('th', { content = dows[col] })
106 end
107 end
108 })
109 end
110 })
111 ui_deprecated.tag('tbody', {
112 content = function()
113 for row = 1,6 do
114 ui_deprecated.tag('tr', {
115 content = function()
116 for col = 1,7 do
117 local day = (row -1) * 7 + col - empty_days
118 local date = atom.date.invalid
119 if day > 0 then
120 date = atom.date{ year = year, month = month, day = day }
121 end
122 ui_deprecated.tag('td', {
123 html_options = {
124 onclick = enabled and 'document.getElementById(\'_ui_calendar_input\').value = \'' .. tostring(date) .. '\'; document.getElementById(\'_ui_calendar_input\').onchange(); ' or ''
125 },
126 content = function()
127 if date.invalid then
128 slot.put(' ')
129 else
130 local selected = date == value
131 args.day_func(date, selected)
132 end
133 end
134 })
135 end
136 end
137 })
138 end
139 end
140 })
141 end
142 })
143 end
144 })
145 end
146 })
147 end