jbe/bsw@0: -- jbe/bsw@0: -- Creates a formular jbe/bsw@0: -- jbe/bsw@0: -- record (record) Take field values from this object (optional) jbe/bsw@0: -- class (string) Style class (optional) jbe/bsw@0: -- method (string) Submit method ['post', 'get'] (optional) jbe/bsw@0: -- module (string) The module to submit to jbe/bsw@0: -- action (string) The action to submit to jbe/bsw@0: -- params (table) The GET parameter to be send with jbe/bsw@0: -- content (function) Function for the content of the form jbe/bsw@0: -- jbe/bsw@0: -- Example: jbe/bsw@0: -- jbe/bsw@0: -- ui_deprecated.form({ jbe/bsw@0: -- object = client, jbe/bsw@0: -- class = 'form_class', jbe/bsw@0: -- method = 'post', jbe/bsw@0: -- module = 'client', jbe/bsw@0: -- action = 'update', jbe/bsw@0: -- params = { jbe/bsw@0: -- id = client.id jbe/bsw@0: -- }, jbe/bsw@0: -- redirect_to = { jbe/bsw@0: -- ok = { jbe/bsw@0: -- module = 'client', jbe/bsw@0: -- view = 'list' jbe/bsw@0: -- }, jbe/bsw@0: -- error = { jbe/bsw@0: -- module = 'client', jbe/bsw@0: -- view = 'edit', jbe/bsw@0: -- params = { jbe/bsw@0: -- id = client.id jbe/bsw@0: -- } jbe/bsw@0: -- } jbe/bsw@0: -- }, jbe/bsw@0: -- }) jbe/bsw@0: jbe/bsw@0: function ui_deprecated.form(args) jbe/bsw@0: local slot_state = slot.get_state_table() jbe/bsw@0: if slot_state.form_opened then jbe/bsw@0: error("Cannot open a form inside a form.") jbe/bsw@0: end jbe/bsw@0: slot_state.form_opened = true jbe/bsw@0: local old_record = slot_state.form_record jbe/bsw@0: slot_state.form_record = args.record or {} -- TODO: decide what really should happen when no record is specified jbe/bsw@0: jbe/bsw@0: local params = {} jbe/bsw@0: if args.params then jbe/bsw@0: for key, value in pairs(args.params) do jbe/bsw@0: params[key] = value jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: ui_deprecated._prepare_redirect_params(params, args.redirect_to) jbe/bsw@0: jbe/bsw@0: local attr_action = args.url or encode.url{ jbe/bsw@0: module = args.module, jbe/bsw@0: view = args.view, jbe/bsw@0: action = args.action, jbe/bsw@0: id = args.id, jbe/bsw@0: params = params jbe/bsw@0: } jbe/bsw@0: jbe/bsw@0: local base = request.get_relative_baseurl() jbe/bsw@0: local attr_class = table.concat({ 'ui_form', args.class }, ' ') jbe/bsw@0: local attr_method = args.method or 'POST' -- TODO: uppercase/sanatize method jbe/bsw@0: jbe/bsw@0: slot.put( jbe/bsw@0: '\n' jbe/bsw@0: ) jbe/bsw@0: jbe/bsw@0: if type(args.content) == 'function' then jbe/bsw@0: args.content() jbe/bsw@0: else jbe/bsw@0: error('No content function') jbe/bsw@0: end jbe/bsw@0: jbe/bsw@0: slot.put('') jbe/bsw@0: slot_state.form_record = old_record jbe/bsw@0: slot_state.form_opened = false jbe/bsw@0: jbe/bsw@0: end