root/LW/LWForm.lua

Revision 815 (checked in by rsz, 3 years ago)

cleanup

Line 
1 --------------------------------------------------------------------------------
2 -- Title:               LWForm.lua
3 -- Description:         Like a square peg in a round hole
4 -- Author:              Raphaël Szwarc http://alt.textdrive.com/lua/
5 -- Creation Date:       February 1, 2005
6 -- Legal:               Copyright (C) 2005 Raphaël Szwarc
7 --------------------------------------------------------------------------------
8
9 -- import dependencies
10 local LWComponent = require( "LWComponent" )
11 local LWStyle = require( "LWStyle" )
12 local LUList = require( "LUList" )
13 local LULocale = require( "LULocale" )
14
15 -- define the class
16 local super = LWComponent
17 local self = super()
18
19 -- method to access this form action
20 function self:action()
21         return self:bindings():get( "action" ) or self:context():request():uri():path()
22 end
23
24 -- method to access this form charset
25 function self:charset()
26         return self:bindings():get( "charset" ) or self:context():response():encoding()
27 end
28
29 -- method to access this form encoding
30 function self:encoding()
31         return self:bindings():get( "encoding" ) or "multipart/form-data"
32 end
33
34 -- method to access this form method
35 function self:method()
36         return self:bindings():get( "method" ) or "POST"
37 end
38
39 -- method to access this form target
40 function self:target()
41         return self:bindings():get( "target" ) or "_self"
42 end
43
44 -- method to access this form content
45 function self:content()
46         local aValue = self:bindings():get( "content" )
47        
48         return tostring( aValue )
49 end
50
51 -- method for string representation
52 function self:toString()
53         local aBuffer = LUList()
54         local aStyle = LWStyle:styleWithComponent( self )
55                
56         aBuffer:add( "<form " )
57         aBuffer:add( ( "accept-charset = \"%s\" " ):format( self:charset() ) )
58         aBuffer:add( ( "action = \"%s\" " ):format( self:action() ) )
59         aBuffer:add( ( "enctype = \"%s\" " ):format( self:encoding() ) )
60         aBuffer:add( ( "method = \"%s\" " ):format( self:method() ) )
61         aBuffer:add( ( "target = \"%s\" " ):format( self:target() ) )
62
63         if aStyle ~= nil then
64                 aBuffer:add( aStyle )
65         end
66        
67         aBuffer:add( ">" )
68         aBuffer:add( self:content() )
69         aBuffer:add( "</form>" )
70        
71         return aBuffer:join( "" )               
72 end
73
74 return self
Note: See TracBrowser for help on using the browser.