| 1 |
-------------------------------------------------------------------------------- |
|---|
| 2 |
-- Title: LWFormCheckBox.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 LWFormInput = require( "LWFormInput" ) |
|---|
| 11 |
local LWFormHidden = require( "LWFormHidden" ) |
|---|
| 12 |
local LWStyle = require( "LWStyle" ) |
|---|
| 13 |
local LUList = require( "LUList" ) |
|---|
| 14 |
|
|---|
| 15 |
-- define the class |
|---|
| 16 |
local super = LWFormInput |
|---|
| 17 |
local self = super() |
|---|
| 18 |
|
|---|
| 19 |
function self:handleComponentKeyWithValue( aComponent, aKey, aValue ) |
|---|
| 20 |
local aDefaultKey = aKey:gsub( "%.%_$", "" ) |
|---|
| 21 |
local aMethod = self:componentMethodWithKey( aComponent, aDefaultKey ) |
|---|
| 22 |
|
|---|
| 23 |
if aMethod ~= nil then |
|---|
| 24 |
local someParameters = aComponent:context():request():parameters() |
|---|
| 25 |
|
|---|
| 26 |
if aKey == aDefaultKey and someParameters:hasKey( aDefaultKey ) == true |
|---|
| 27 |
or aKey ~= aDefaultKey and someParameters:hasKey( aDefaultKey ) == false then |
|---|
| 28 |
|
|---|
| 29 |
if aValue == "true" then |
|---|
| 30 |
aValue = true |
|---|
| 31 |
else |
|---|
| 32 |
aValue = false |
|---|
| 33 |
end |
|---|
| 34 |
|
|---|
| 35 |
aComponent:invoke( aMethod, aValue ) |
|---|
| 36 |
end |
|---|
| 37 |
end |
|---|
| 38 |
end |
|---|
| 39 |
|
|---|
| 40 |
function self:prefix() |
|---|
| 41 |
return "checkbox." |
|---|
| 42 |
end |
|---|
| 43 |
|
|---|
| 44 |
function self:type() |
|---|
| 45 |
return "checkbox" |
|---|
| 46 |
end |
|---|
| 47 |
|
|---|
| 48 |
function self:isChecked() |
|---|
| 49 |
local aValue = self:bindings():get( "isChecked" ) |
|---|
| 50 |
|
|---|
| 51 |
if aValue == nil then |
|---|
| 52 |
aValue = false |
|---|
| 53 |
end |
|---|
| 54 |
|
|---|
| 55 |
return aValue |
|---|
| 56 |
end |
|---|
| 57 |
|
|---|
| 58 |
-- method for string representation |
|---|
| 59 |
function self:toString() |
|---|
| 60 |
local aBuffer = LUList() |
|---|
| 61 |
local aStyle = LWStyle:styleWithComponent( self ) |
|---|
| 62 |
|
|---|
| 63 |
aBuffer:add( "<input " ) |
|---|
| 64 |
aBuffer:add( ( "type = \"%s\" " ):format( self:type() ) ) |
|---|
| 65 |
aBuffer:add( ( "name = \"%s\" " ):format( self:name() ) ) |
|---|
| 66 |
aBuffer:add( ( "value = \"%s\" " ):format( "true" ) ) |
|---|
| 67 |
|
|---|
| 68 |
if self:isChecked() == true then |
|---|
| 69 |
aBuffer:add( "checked " ) |
|---|
| 70 |
end |
|---|
| 71 |
|
|---|
| 72 |
if self:isDisabled() == true then |
|---|
| 73 |
aBuffer:add( "disabled " ) |
|---|
| 74 |
end |
|---|
| 75 |
|
|---|
| 76 |
if self:isReadOnly() == true then |
|---|
| 77 |
aBuffer:add( "readonly " ) |
|---|
| 78 |
end |
|---|
| 79 |
|
|---|
| 80 |
if aStyle ~= nil then |
|---|
| 81 |
aBuffer:add( aStyle ) |
|---|
| 82 |
end |
|---|
| 83 |
|
|---|
| 84 |
aBuffer:add( ">" ) |
|---|
| 85 |
aBuffer:add( self:hidden() ) |
|---|
| 86 |
|
|---|
| 87 |
return aBuffer:join( "" ) |
|---|
| 88 |
end |
|---|
| 89 |
|
|---|
| 90 |
return self |
|---|