webmcp
diff framework/env/ui_deprecated/calendar.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/ui_deprecated/calendar.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,147 @@ 1.4 +function ui_deprecated.calendar(args) 1.5 + local record = assert(slot.get_state_table(), "ui_deprecated.calender was not called within a form.").form_record 1.6 + local value = param.get(args.field, atom.date) or record[args.field] 1.7 + local year = param.get('_ui_calendar_year', atom.integer) or args.year or 2008 1.8 + local month = param.get('_ui_calendar_month', atom.integer) or args.month or 10 1.9 + local empty_days = atom.date{ year = year, month = month, day = 1 }.iso_weekday -1 1.10 + local enabled = not args.disabled 1.11 + 1.12 + local prev_year = year 1.13 + local prev_month = month - 1 1.14 + if prev_month == 0 then 1.15 + prev_month = 12 1.16 + prev_year = prev_year - 1 1.17 + end 1.18 + 1.19 + local next_year = year 1.20 + local next_month = month + 1 1.21 + if next_month == 13 then 1.22 + next_month = 1 1.23 + next_year = next_year + 1 1.24 + end 1.25 + 1.26 + ui_deprecated.tag('div', { 1.27 + html_options = { 1.28 + class="ui_field ui_calendar" 1.29 + }, 1.30 + content = function() 1.31 + ui_deprecated.tag('input', { 1.32 + html_options = { 1.33 + type = 'hidden', 1.34 + value = year, 1.35 + name = '_ui_calendar_year', 1.36 + id = '_ui_calendar_year', 1.37 + onchange = 'this.form.submit();' 1.38 + } 1.39 + }) 1.40 + ui_deprecated.tag('input', { 1.41 + html_options = { 1.42 + type = 'hidden', 1.43 + value = month, 1.44 + name = '_ui_calendar_month', 1.45 + id = '_ui_calendar_month', 1.46 + onchange = 'this.form.submit();' 1.47 + } 1.48 + }) 1.49 + ui_deprecated.tag('input', { 1.50 + html_options = { 1.51 + type = 'hidden', 1.52 + value = value and tostring(value) or '', 1.53 + name = args.field, 1.54 + id = '_ui_calendar_input', 1.55 + onchange = 'this.form.submit();' 1.56 + } 1.57 + }) 1.58 + if args.label then 1.59 + ui_deprecated.tag('div', { 1.60 + html_options = { 1.61 + class="label" 1.62 + }, 1.63 + content = function() 1.64 + ui_deprecated.text(args.label) 1.65 + end 1.66 + }) 1.67 + end 1.68 + ui_deprecated.tag('div', { 1.69 + html_options = { 1.70 + class="value" 1.71 + }, 1.72 + content = function() 1.73 + ui_deprecated.tag('div', { 1.74 + html_options = { 1.75 + class = 'next', 1.76 + href = '#', 1.77 + 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 '', 1.78 + }, 1.79 + content = '>>>'; 1.80 + }) 1.81 + ui_deprecated.tag('div', { 1.82 + html_options = { 1.83 + class = 'prev', 1.84 + href = '#', 1.85 + 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 '', 1.86 + }, 1.87 + content = '<<<'; 1.88 + }) 1.89 + ui_deprecated.tag('div', { 1.90 + html_options = { 1.91 + class="title" 1.92 + }, 1.93 + content = function() 1.94 + local months = {_'January', _'February', _'March', _'April', _'May', _'June', _'July', _'August', _'September', _'October', _'November', _'December' } 1.95 + ui_deprecated.text(months[month]) 1.96 + ui_deprecated.text(' ') 1.97 + ui_deprecated.text(tostring(year)) 1.98 + end 1.99 + }) 1.100 + ui_deprecated.tag('table', { 1.101 + content = function() 1.102 + ui_deprecated.tag('thead', { 1.103 + content = function() 1.104 + ui_deprecated.tag('tr', { 1.105 + content = function() 1.106 + local dows = { _'Mon', _'Tue', _'Wed', _'Thu', _'Fri', _'Sat', _'Sun' } 1.107 + for col = 1,7 do 1.108 + ui_deprecated.tag('th', { content = dows[col] }) 1.109 + end 1.110 + end 1.111 + }) 1.112 + end 1.113 + }) 1.114 + ui_deprecated.tag('tbody', { 1.115 + content = function() 1.116 + for row = 1,6 do 1.117 + ui_deprecated.tag('tr', { 1.118 + content = function() 1.119 + for col = 1,7 do 1.120 + local day = (row -1) * 7 + col - empty_days 1.121 + local date = atom.date.invalid 1.122 + if day > 0 then 1.123 + date = atom.date{ year = year, month = month, day = day } 1.124 + end 1.125 + ui_deprecated.tag('td', { 1.126 + html_options = { 1.127 + onclick = enabled and 'document.getElementById(\'_ui_calendar_input\').value = \'' .. tostring(date) .. '\'; document.getElementById(\'_ui_calendar_input\').onchange(); ' or '' 1.128 + }, 1.129 + content = function() 1.130 + if date.invalid then 1.131 + slot.put(' ') 1.132 + else 1.133 + local selected = date == value 1.134 + args.day_func(date, selected) 1.135 + end 1.136 + end 1.137 + }) 1.138 + end 1.139 + end 1.140 + }) 1.141 + end 1.142 + end 1.143 + }) 1.144 + end 1.145 + }) 1.146 + end 1.147 + }) 1.148 + end 1.149 + }) 1.150 +end