GenVerify.dcl 3.75 KB
Newer Older
ecrombag's avatar
 
ecrombag committed
1
definition module GenVerify
2

ecrombag's avatar
 
ecrombag committed
3 4
import GenUpdate

Steffen Michels's avatar
Steffen Michels committed
5
:: ErrorMessage = ErrorMessage !String | IsBlankError
ecrombag's avatar
 
ecrombag committed
6
:: HintMessage :== String
7
:: Optional :== Bool
ecrombag's avatar
 
ecrombag committed
8

Steffen Michels's avatar
Steffen Michels committed
9 10 11
:: VerifyMask = VMUntouched !(Maybe HintMessage) !Optional ![VerifyMask] 
			  | VMValid !(Maybe HintMessage) ![VerifyMask]
			  | VMInvalid !ErrorMessage ![VerifyMask]
12
			  
13
:: *VerSt =
Steffen Michels's avatar
Steffen Michels committed
14 15 16
	{ updateMask	:: ![UpdateMask]
	, verifyMask	:: ![VerifyMask]
	, optional		:: !Bool
17
	, staticDisplay	:: !Bool
ecrombag's avatar
 
ecrombag committed
18 19
	}

20
generic gVerify a :: !(Maybe a) !*VerSt -> *VerSt
ecrombag's avatar
 
ecrombag committed
21

22 23
instance GenMask VerifyMask
instance toString ErrorMessage
24

25
derive gVerify UNIT, PAIR, EITHER, OBJECT, CONS, RECORD, FIELD, Int, Real, Char, Bool, String, (,), (,,),(,,,),(->), []
26
derive gVerify Maybe, Dynamic, JSONNode, Void, Document, Either, Editable, Hidden, Display, VisualizationHint, HtmlTag, Timestamp
27
derive gVerify Username, Password, Date, Time, FormButton, EUR, USD, User, Note, DateTime, RadioChoice, ComboChoice, GridChoice, DynamicChoice, CheckMultiChoice, Map, Tree, TreeChoice, TreeNode, Table
28
derive gVerify EmailAddress, Action, HtmlInclude, ManagementMeta, TaskPriority
Bas Lijnse's avatar
Bas Lijnse committed
29
derive gVerify ControlSize, FillControlSize, FillWControlSize, FillHControlSize
ecrombag's avatar
 
ecrombag committed
30

31
/**
32
* Verify a form based on the value and its update mask.
33
*/
34 35 36 37 38 39
verifyForm :: !a !UpdateMask -> VerifyMask | gVerify{|*|} a

/**
* Verify a value (a form which is filled in completely).
*/
verifyValue :: !a -> Bool | gVerify{|*|}, gDefaultMask{|*|} a
40 41 42 43 44 45 46

/**
* Based on the verify mask of a value, determine if it is valid.
* A value is valid if the verify mask contains no invalid fields and all untouched fields are optional
*/
isValidValue :: !VerifyMask -> Bool

47 48 49 50 51 52 53 54 55 56
/**
* Verifies a value which is always valid.
* No hint message is shown.
*
* @param	The verify-state
*
* @return	The modified verify-state
*/
alwaysValid :: !*VerSt -> *VerSt

Steffen Michels's avatar
Steffen Michels committed
57 58 59 60 61 62 63 64 65 66
/**
* Verifies a value which is always valid if filled in (e.g. a basic value).
* So only a hint message is needed.
*
* @param	A hint message
* @param	The verify-state
*
* @return	The modified verify-state
*/
simpleVerify :: !String !*VerSt -> *VerSt
67

ecrombag's avatar
ecrombag committed
68
/**
Steffen Michels's avatar
Steffen Michels committed
69 70 71 72 73 74 75 76
* Verifies an ADT wrapping an already existing type to put extra restrictions on it.
* The ADT must have the form :: ADTName = ConsName x.
* The instances for gVisualize and gUpdate can be generically derived,
* which means that just a value of type x is visualized.
*
* For example the following type can be used to represent positive integers:
* :: PositiveInt = PositiveInt Int
* A predicate checking if the integer is positive has to be given to this function then.
ecrombag's avatar
ecrombag committed
77 78
* 
* @param 	An optional hint message
Steffen Michels's avatar
Steffen Michels committed
79
* @param	A predicate function
ecrombag's avatar
ecrombag committed
80 81 82 83 84 85
* @param	A function for error message generation, in case the predicate fails
* @param	The actual value (if present)
* @param	The verify-state
*
* @return	The modified verify-state
*/
Steffen Michels's avatar
Steffen Michels committed
86
wrapperVerify :: !(Maybe String) !(a -> Bool) !(a -> String) !(Maybe a) !*VerSt -> *VerSt
87

Steffen Michels's avatar
Steffen Michels committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
/**
* Verifies a custom ADT.
* For this ADT also a custom visualization has to be implemented.
* There is only one verify mask for the entire value.
* 
* @param 	An optional hint message
* @param	The predicate function
* @param	A function for error message generation, in case the predicate fails
* @param	The actual value (if present)
* @param	The verify-state
*
* @return	The modified verify-state
*/
customVerify :: !(Maybe String) !(a -> Bool) !(a -> String) !(Maybe a) !*VerSt -> *VerSt
102

103 104 105
/**
* Sets a number of fields identified by data-paths in a verify mask to invalid.
*
Steffen Michels's avatar
Steffen Michels committed
106 107
* @ param	A list of data-paths of field to be set to invalid.
*			Additionally an error message is given for each field.
108 109 110 111 112
* @ param	The verify mask to be modified
*
* @ return	The modified verify mask
*/
setInvalid :: ![(!DataPath,!ErrorMessage)] !VerifyMask -> VerifyMask