# HG changeset patch # User jbe # Date 1426376956 -3600 # Node ID 4654d59a40797bb5104a0cb13c7a0c3870b0b721 # Parent 9e4be058959d2bd87a84b196f3d264b11a820354 Remove env/ui_deprecated diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/__init.lua --- a/framework/env/ui_deprecated/__init.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -ui_deprecated._form = {} - diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/_prepare_redirect_params.lua --- a/framework/env/ui_deprecated/_prepare_redirect_params.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -function ui_deprecated._prepare_redirect_params(params, redirect_to) - if redirect_to then - for status, settings in pairs(redirect_to) do - local module, view = settings.module, settings.view - if not module then - error("No redirection module specified.") - end - if not view then - error("No redirection view specified.") - end - if status == "ok" then - params["_webmcp_routing." .. status .. ".mode"] = "redirect" - else - params["_webmcp_routing." .. status .. ".mode"] = "forward" - end - params["_webmcp_routing." .. status .. ".module"] = settings.module - params["_webmcp_routing." .. status .. ".view"] = settings.view - params["_webmcp_routing." .. status .. ".id"] = settings.id - if settings.params then - for key, value in pairs(settings.params) do - params["_webmcp_routing." .. status .. ".params." .. key] = value - end - end - end - end -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/_stringify_table.lua --- a/framework/env/ui_deprecated/_stringify_table.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function ui_deprecated._stringify_table(table) - if not table then - return '' - end - local string = '' - for key, value in pairs(table) do - string = string .. ' ' .. key .. '="' .. value ..'"' - end - return string -end - diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/box.lua --- a/framework/env/ui_deprecated/box.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ ---[[doc: ui_deprecated.box - -Starts a box - -label (string) Label, optional -class (string) Style class, optional -content (function) or (string) The content of the box - - -Example: - -ui_deprecated.box{ - label = 'My box label', - class = 'my_css_class', - content = function() - ui_deprecated.text('My text') - end -} - ---]] - -function ui_deprecated.box(args) - if args.class then - args.html_options = args.html_options or {} - args.html_options.class = args.class - end - ui_deprecated.tag('div', args) -end - diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/calendar.lua --- a/framework/env/ui_deprecated/calendar.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -function ui_deprecated.calendar(args) - local record = assert(slot.get_state_table(), "ui_deprecated.calender was not called within a form.").form_record - local value = param.get(args.field, atom.date) or record[args.field] - local year = param.get('_ui_calendar_year', atom.integer) or args.year or 2008 - local month = param.get('_ui_calendar_month', atom.integer) or args.month or 10 - local empty_days = atom.date{ year = year, month = month, day = 1 }.iso_weekday -1 - local enabled = not args.disabled - - local prev_year = year - local prev_month = month - 1 - if prev_month == 0 then - prev_month = 12 - prev_year = prev_year - 1 - end - - local next_year = year - local next_month = month + 1 - if next_month == 13 then - next_month = 1 - next_year = next_year + 1 - end - - ui_deprecated.tag('div', { - html_options = { - class="ui_field ui_calendar" - }, - content = function() - ui_deprecated.tag('input', { - html_options = { - type = 'hidden', - value = year, - name = '_ui_calendar_year', - id = '_ui_calendar_year', - onchange = 'this.form.submit();' - } - }) - ui_deprecated.tag('input', { - html_options = { - type = 'hidden', - value = month, - name = '_ui_calendar_month', - id = '_ui_calendar_month', - onchange = 'this.form.submit();' - } - }) - ui_deprecated.tag('input', { - html_options = { - type = 'hidden', - value = value and tostring(value) or '', - name = args.field, - id = '_ui_calendar_input', - onchange = 'this.form.submit();' - } - }) - if args.label then - ui_deprecated.tag('div', { - html_options = { - class="label" - }, - content = function() - ui_deprecated.text(args.label) - end - }) - end - ui_deprecated.tag('div', { - html_options = { - class="value" - }, - content = function() - ui_deprecated.tag('div', { - html_options = { - class = 'next', - href = '#', - 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 '', - }, - content = '>>>'; - }) - ui_deprecated.tag('div', { - html_options = { - class = 'prev', - href = '#', - 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 '', - }, - content = '<<<'; - }) - ui_deprecated.tag('div', { - html_options = { - class="title" - }, - content = function() - local months = {_'January', _'February', _'March', _'April', _'May', _'June', _'July', _'August', _'September', _'October', _'November', _'December' } - ui_deprecated.text(months[month]) - ui_deprecated.text(' ') - ui_deprecated.text(tostring(year)) - end - }) - ui_deprecated.tag('table', { - content = function() - ui_deprecated.tag('thead', { - content = function() - ui_deprecated.tag('tr', { - content = function() - local dows = { _'Mon', _'Tue', _'Wed', _'Thu', _'Fri', _'Sat', _'Sun' } - for col = 1,7 do - ui_deprecated.tag('th', { content = dows[col] }) - end - end - }) - end - }) - ui_deprecated.tag('tbody', { - content = function() - for row = 1,6 do - ui_deprecated.tag('tr', { - content = function() - for col = 1,7 do - local day = (row -1) * 7 + col - empty_days - local date = atom.date.invalid - if day > 0 then - date = atom.date{ year = year, month = month, day = day } - end - ui_deprecated.tag('td', { - html_options = { - onclick = enabled and 'document.getElementById(\'_ui_calendar_input\').value = \'' .. tostring(date) .. '\'; document.getElementById(\'_ui_calendar_input\').onchange(); ' or '' - }, - content = function() - if date.invalid then - slot.put(' ') - else - local selected = date == value - args.day_func(date, selected) - end - end - }) - end - end - }) - end - end - }) - end - }) - end - }) - end - }) -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/field.lua --- a/framework/env/ui_deprecated/field.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ --- --- Creates an output field --- --- label (string) The label of the field --- value (atom) The value to put out --- field_type (string) The type of the field (default: 'string') --- --- Example: --- --- ui_deprecated.field({ --- label = _'Id', --- value = myobject.id, --- field_type = 'integer' --- }) --- - -function ui_deprecated.field(args) - local value_type = args.value_type or atom.string - slot.put( - '
', - '
', - encode.html(args.label or ''), - '
', - '
') - if args.value then - slot.put(encode.html(convert.to_human(args.value, value_type))) - elseif args.link then - ui_deprecated.link(args.link) - end - slot.put( - '
', - '
\n' - ) -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/form.lua --- a/framework/env/ui_deprecated/form.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ --- --- Creates a formular --- --- record (record) Take field values from this object (optional) --- class (string) Style class (optional) --- method (string) Submit method ['post', 'get'] (optional) --- module (string) The module to submit to --- action (string) The action to submit to --- params (table) The GET parameter to be send with --- content (function) Function for the content of the form --- --- Example: --- --- ui_deprecated.form({ --- object = client, --- class = 'form_class', --- method = 'post', --- module = 'client', --- action = 'update', --- params = { --- id = client.id --- }, --- redirect_to = { --- ok = { --- module = 'client', --- view = 'list' --- }, --- error = { --- module = 'client', --- view = 'edit', --- params = { --- id = client.id --- } --- } --- }, --- }) - -function ui_deprecated.form(args) - local slot_state = slot.get_state_table() - if slot_state.form_opened then - error("Cannot open a form inside a form.") - end - slot_state.form_opened = true - local old_record = slot_state.form_record - slot_state.form_record = args.record or {} -- TODO: decide what really should happen when no record is specified - - local params = {} - if args.params then - for key, value in pairs(args.params) do - params[key] = value - end - end - ui_deprecated._prepare_redirect_params(params, args.redirect_to) - - local attr_action = args.url or encode.url{ - module = args.module, - view = args.view, - action = args.action, - id = args.id, - params = params - } - - local base = request.get_relative_baseurl() - local attr_class = table.concat({ 'ui_form', args.class }, ' ') - local attr_method = args.method or 'POST' -- TODO: uppercase/sanatize method - - slot.put( - '\n' - ) - - if type(args.content) == 'function' then - args.content() - else - error('No content function') - end - - slot.put('') - slot_state.form_record = old_record - slot_state.form_opened = false - -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/image.lua --- a/framework/env/ui_deprecated/image.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ --- --- Creates an image --- --- image (string) --- --- Example: --- --- ui_deprecated.image({ --- image = 'test.png', --- }) --- - -function ui_deprecated.image(args) - assert(args.image, "No image argument given.") - slot.put( - '' - ) -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input.lua --- a/framework/env/ui_deprecated/input.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ --- --- Creates an input field in a form --- --- label (string) The label of the input field --- field (string) The name of the record field --- field_type (string) The type of the record field --- --- Example: --- --- ui_deprecated.input({ --- label = _'Comment', --- field = 'comment', --- field_type = 'textarea' --- }) --- -local field_type_to_atom_class_map = { - text = atom.string, - textarea = atom.string, - number = atom.number, - percentage = atom.number, -} - -function ui_deprecated.input(args) - local record = assert(slot.get_state_table(), "ui_deprecated.input was not called within a form.").form_record - - local field_type = args.field_type or "text" - - local field_func = assert(ui_deprecated.input_field[field_type], "no field helper for given type '" .. field_type .. "'") - - local html_name = args.name or args.field - local field_html - - if args.field then - local param_type = field_type_to_atom_class_map[field_type] or error('Unkown field type') - field_html = field_func{ - name = html_name, - value = param.get(html_name, param_type) - or record[args.field], - height = args.height, - } - - elseif args.value then - field_html = field_func{ - name = html_name, - value = args.value, - height = args.height, - } - - else - field_html = field_func{ - name = html_name, - value = '', - height = args.height, - } - - end - - slot.put('
\n') - if args.label then - slot.put('
', encode.html(args.label), '
\n') - end - slot.put('
', - field_html, - '
\n', - '
\n' - ) -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/boolean.lua diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/date.lua diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/datetime.lua diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/number.lua --- a/framework/env/ui_deprecated/input_field/number.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function ui_deprecated.input_field.number(args) - name = args.name or '' - value = args.value or 0 - return '' -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/percentage.lua --- a/framework/env/ui_deprecated/input_field/percentage.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function ui_deprecated.input_field.percentage(args) - name = args.name or '' - value = args.value or 0 - return ' %' -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/reset.lua diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/text.lua --- a/framework/env/ui_deprecated/input_field/text.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function ui_deprecated.input_field.text(args) - name = args.name or '' - value = args.value or '' - return '' -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/textarea.lua --- a/framework/env/ui_deprecated/input_field/textarea.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function ui_deprecated.input_field.textarea(args) - local value = args.value or '' - local name = assert(args.name, 'No field name given') - local style = '' - if args.height then - style = 'style="height:' .. args.height .. '"' - end - return '' -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/input_field/time.lua diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/label.lua --- a/framework/env/ui_deprecated/label.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function ui_deprecated.label(value) - slot.put '
' - ui_deprecated.text( value ) - slot.put '
\n' -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/link.lua --- a/framework/env/ui_deprecated/link.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -function ui_deprecated.link(args) - if args.action then - local params = {} - if args.params then - for key, value in pairs(args.params) do - params[key] = value - end - end - ui_deprecated._prepare_redirect_params(params, args.redirect_to) - - local attr_action = args.url or encode.url{ - module = args.module or request.get_module(), - action = args.action, - id = args.id, - params = params - } - local attr_class = table.concat({ 'ui_link', args.class }, ' ') - local attr_target = args.target or '' - local redirect_to = args.redirect_to - local unique_id = "unique_" .. multirand.string(32, "abcdefghijklmnopqrstuvwxyz0123456789") - slot.put( - '\n', - '', - '', - '") - else - local attr_class = table.concat({ 'ui_link', args.class }, ' ') - slot.put( - '' - ) - if args.icon then - ui_deprecated.image{ image = 'ui/icon/' .. args.icon } - end - if args.image then - ui_deprecated.image{ image = args.image } - end - if args.label then - slot.put(args.label) - end - slot.put('') - end -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/list.lua --- a/framework/env/ui_deprecated/list.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ --- --- Creates a list view of a collection --- --- Example: --- --- ui_deprecated.list({ --- label = 'Point table', --- collection = mycollection, --- type = 'table' -- 'table', 'ulli' --- cols = { --- { --- label = _'Id', --- field = 'id', --- width = 100, --- link = { module = 'mymodule', view = 'show' }, --- sort = true, --- }, --- { --- label = _'Name', --- field = 'name', --- width = 200, --- link = { module = 'mymodule', view = 'show' }, --- sort = true, --- }, --- { --- label = _'Points', --- func = function(record) --- return record.points_a + record.points_b + record.points_c --- end, --- width = 300 --- } --- } --- }) --- - -function ui_deprecated.list(args) - local args = args - args.type = args.type or 'table' - if args.label then - slot.put('
' .. encode.html(args.label) .. '
\n') - end - if not args or not args.collection or not args.cols then - error('No args for ui_deprecated.list_end') - end - if args.type == 'table' then - slot.put('') - slot.put('') - elseif args.type == 'ulli' then - slot.put('') - elseif args.type == 'ulli' then - slot.put('
') - slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) ) - slot.put('
') - end - end - if args.type == 'table' then - slot.put('') - elseif args.type == 'ulli' then - slot.put('
') - slot.put('') - end - for i, obj in ipairs(args.collection) do - if args.type == 'table' then - slot.put('') - elseif args.type == 'ulli' then - slot.put('
  • ') - end - for j, col in ipairs(args.cols) do - class_string = '' - if col.align then - class_string = ' class="ui_list_col_align_' .. col.align .. '"' - end - if args.type == 'table' then - slot.put('') - elseif args.type == 'ulli' then - slot.put('
    ') - end - if col.link then - local params = {} - if col.link then - params = col.link.params or {} - end - if col.link_values then - for key, field in pairs(col.link_values) do - params[key] = obj[field] - end - end - local id - if col.link_id_field then - id = obj[col.link_id_field] - end - local value - if col.value then - value = col.value - else - value = obj[col.field] - end - ui_deprecated.link{ - label = convert.to_human(value), - module = col.link.module, - view = col.link.view, - id = id, - params = params, - } - elseif col.link_func then - local link = col.link_func(obj) - if link then - ui_deprecated.link(link) - end - else - local text - if col.func then - text = col.func(obj) - elseif col.value then - text = convert.to_human(value) - else - text = convert.to_human(obj[col.field]) - end - ui_deprecated.box{ name = 'ui_list_col_value', content = text } - end - if args.type == 'table' then - slot.put('') - elseif args.type == 'ulli' then - slot.put('
    ') - end - end - if args.type == 'table' then - slot.put('
  • ') - elseif args.type == 'ulli' then - slot.put('
    ') - slot.put('') - end - end - if args.type == 'table' then - slot.put('
    ') - slot.put(ui_deprecated.box({ name = 'ui_list_col_value', content = encode.html(col.label) }) ) - slot.put('
    ') - elseif args.type == 'ulli' then - slot.put('
     
    ') - end -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/multiselect.lua --- a/framework/env/ui_deprecated/multiselect.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -function ui_deprecated.multiselect(args) - local record = assert(slot.get_state_table(), "ui_deprecated.multiselect was not called within a form.").form_record - local name = args.name - local relationship = args.relationship - - local foreign_records = relationship.foreign_records - - local selector = relationship.connected_by_model:new_selector() - selector:add_where{ relationship.connected_by_my_id .. ' = ?', record[relationship.my_id] } - local connected_by_records = selector:exec() - - local connections = {} - for i, connected_by_record in ipairs(connected_by_records) do - connections[connected_by_record[relationship.connected_by_foreign_id]] = connected_by_record - end - - local html = {} - - if args.type == "checkboxes" then - for i, foreign_record in ipairs(foreign_records) do - local selected = '' - if connections[foreign_record[relationship.foreign_id]] then - selected = ' checked="1"' - end - html[#html + 1] = ' ' .. convert.to_human(foreign_record[relationship.foreign_name], "string") .. '
    \n' - end - - else - html[#html + 1] = '' - - end - - slot.put('
    \n') - if args.label then - slot.put('
    ', encode.html(args.label), '
    \n') - end - slot.put('
    ', - table.concat(html), - '
    \n', - '
    \n' - ) -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/select.lua --- a/framework/env/ui_deprecated/select.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -function ui_deprecated.select(args) - local record = assert(slot.get_state_table(), "ui_deprecated.select was not called within a form.").form_record - local value = param.get(args.field) or record[args.field] - local html_options = args.html_options or {} - html_options.name = args.field - - ui_deprecated.tag("div", { html_options = { class="ui_field ui_select" }, content = function() - if args.label then - ui_deprecated.tag("div", { html_options = { class="label" }, content = function() - ui_deprecated.text(args.label) - end }) - end - ui_deprecated.tag("div", { html_options = { class="value" }, content = function() - ui_deprecated.tag("select", { html_options = html_options, content = function() - if args.include_option then - ui_deprecated.tag("option", { html_options = { value = "" }, content = args.include_option }) - end - for i, object in ipairs(args.foreign_records) do - local selected = nil - if tostring(object[args.foreign_id]) == tostring(value) then - selected = "1" - end - ui_deprecated.tag("option", { html_options = { value = object[args.foreign_id], selected = selected }, content = object[args.foreign_name] }) - end - end }) -- /select - end }) -- /div - end }) -- /div -end - - - diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/submit.lua --- a/framework/env/ui_deprecated/submit.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ --- --- Creates a submit buttom for a form --- --- label (string) The label of the box --- --- Example: --- --- ui_deprecated.submit({ --- label = 'Save' --- }) --- - -function ui_deprecated.submit(args) - local args = args or {} - args.label = args.label or 'Submit' - slot.put( - '
    ', - '
     
    ', - '
    ', - '', - '
    ', - '
    ' - ) -end diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/tag.lua --- a/framework/env/ui_deprecated/tag.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -function ui_deprecated.tag(name, args) - - local html_options = args.html_options or {} - - slot.put('<', name, ui_deprecated._stringify_table(html_options), '>') - - if args.label then - ui_deprecated.label(args.label) - end - - if type(args.content) == 'function' then - args.content() - else - ui_deprecated.text(args.content) - end - - slot.put('') - - -end \ No newline at end of file diff -r 9e4be058959d -r 4654d59a4079 framework/env/ui_deprecated/text.lua --- a/framework/env/ui_deprecated/text.lua Sat Mar 14 23:39:47 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ - -function ui_deprecated.text(value) - slot.put(encode.html(convert.to_human(value))) -end \ No newline at end of file