htmlHandler.dcl 3.09 KB
Newer Older
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
1
2
definition module htmlHandler

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
3
4
5
6
// Main entrance for en user
// Generating HTML code, converting Clean types to GEC's, automatic dealing with form's ..
// (c) MJP 2005 *** under construction

7
import htmlDataDef, htmlFormData
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
8
import StdBool
9
import GenPrint, GenParse
10

11
TraceInput :== False		// set it to True if you want to see what kind of information is received from browser
12

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
13
14
derive bimap Form, FormId

15
:: *HSt 					// unique state required for creating Html forms
16

17
18
// doHtml main wrapper for generating & handling of a Html form

19
doHtml 			:: .(*HSt -> (Html,!*HSt)) *World -> *World  	// use this application with some external server and php
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
20
doHtmlServer 	:: (*HSt -> (Html,!*HSt))  *World -> *World 	// use this application with the build-in Clean server: http://localhost/clean
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
21

22
23
// mkViewForm is the swiss army nife function creating stateful interactive forms with a view v of data d
// make shure that all editors have a unique identifier !
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
24

25
mkViewForm 		:: !(Init,FormId d) !(HBimap d v) !*HSt -> (Form d,!*HSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC v
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
26

27
28
// gForm converts any Clean type to html code (form) to be used in a body
// gUpd updates a value of type t given any user input in the html form
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
29

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
30
31
generic gForm a :: !(FormId a) !*HSt -> *(Form a, !*HSt)		// user defined gForms: use "specialize"	
generic gUpd a 	:: UpdMode a -> (UpdMode,a)						// gUpd can simply be derived
32

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
33
34
derive gForm Int, Real, Bool, String, UNIT, PAIR, EITHER, OBJECT, CONS, FIELD//, (,) 
derive gUpd  Int, Real, Bool, String, UNIT, PAIR, EITHER, OBJECT, CONS, FIELD//, (,) 
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
35

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
36
37
38
// specialize has to be used if one wants to specialize gForm for a user-defined type

specialize :: !(!(InIDataId a) !*HSt -> (!Form a,!*HSt)) !(InIDataId a) !*HSt -> (!Form a,!*HSt) | gUpd {|*|} a
39
		
40
41
// utility functions

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
42
43
44
45
toHtml 			:: a -> BodyTag | gForm {|*|} a				// toHtml displays any type into a non-editable form
toHtmlForm 		:: (*HSt -> *(Form a,*HSt)) -> [BodyTag] 	// toHtmlForm displays any form one can make with a form function
												| gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
toBody 			:: (Form a) -> BodyTag						// just (BodyTag form.body)
46

47
48
49
50
51
52
// definitions on HSt

instance FileSystem HSt												// enabling file IO on HSt

appWorldHSt		:: !.(*World -> *World)       !*HSt -> *HSt			// enabling World operations on HSt
accWorldHSt		:: !.(*World -> *(.a,*World)) !*HSt -> (.a,!*HSt)	// enabling World operations on HSt
53

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
54
// for testing
55

56
57
import iDataState

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
58
runUserApplication :: .(*HSt -> *(.a,*HSt)) *FormStates *NWorld -> *(.a,*FormStates,*NWorld)
Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
59

Rinus Plasmeijer's avatar
Rinus Plasmeijer committed
60
61
62
63
64
65
66
67
68
69
// low level utility functions handy when specialize cannot be used, only to be used by experts !!

incrHSt 		:: Int *HSt -> *HSt											// Cntr := Cntr + 1
CntrHSt 		:: *HSt -> (Int,*HSt)										// Hst.Cntr
mkInput 		:: !Int !(FormId d) Value UpdValue *HSt -> (BodyTag,*HSt)	// Html Form Creation utility 
getChangedId	:: !*HSt -> (String,!*HSt)					// id of form that has been changed by user

:: UpdMode	= UpdSearch UpdValue Int		// search for indicated postion and update it
			| UpdCreate [ConsPos]			// create new values if necessary
			| UpdDone						// and just copy the remaining stuff