Commit ae615da2 authored by Bas Lijnse's avatar Bas Lijnse

Fixed subforms in submit mode, there are no longer extra submit buttons in nested forms


git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@154 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 2c16359d
......@@ -46,7 +46,8 @@ print :: !String -> FoF
(<+) infixl :: !*HtmlStream !a -> *HtmlStream | gHpr{|*|} a
(<+>) infixl :: !*HtmlStream !FoF -> *HtmlStream
htmlAttrCmnd :: !hdr !tag !body -> FoF | gHpr{|*|} hdr & gHpr{|*|} tag & gHpr{|*|} body
openCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
styleCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
styleAttrCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
htmlAttrCmnd :: !hdr !tag !body -> FoF | gHpr{|*|} hdr & gHpr{|*|} tag & gHpr{|*|} body
htmlBodylessAttrCmnd :: !hdr !attr -> FoF | gHpr{|*|} hdr & gHpr{|*|} attr
openCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
styleCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
styleAttrCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
......@@ -95,6 +95,9 @@ closeCmnd hdr = \file -> print "</" file <+ hdr <+ ">"
htmlAttrCmnd :: !hdr !attr !body -> FoF | gHpr{|*|} hdr & gHpr{|*|} attr & gHpr{|*|} body
htmlAttrCmnd hdr attr txt = \file -> closeCmnd hdr (openCmnd hdr attr file <+ txt)
htmlBodylessAttrCmnd :: !hdr !attr -> FoF | gHpr{|*|} hdr & gHpr{|*|} attr
htmlBodylessAttrCmnd hdr attr = \file -> [|"<":file] <+ hdr <+ attr <+ " />"
styleCmnd :: !a !b -> FoF | gHpr{|*|} a & gHpr{|*|} b
styleCmnd stylename attr = \file -> print "." file <+ stylename <+ "{" <+ attr <+ "}"
......
......@@ -143,7 +143,7 @@ function addState(form) {
//Sends the information in a form to the server/client handler
function sendForm(formid, onclient) {
var form = document.getElementById(formid);
if(form == undefined) {
......@@ -159,6 +159,7 @@ function sendForm(formid, onclient) {
return; //When sapl fails we try sending via ajax or submit.
}
}
//Send the form to the server. Either via ajax or with a submit.
if(use_ajax) {
ajaxSendForm(form);
......@@ -210,6 +211,7 @@ function getForm(elem)
//Sends a form by submitting it
function submitSendForm(form) {
//Always send the values of checkboxes
var inputs = form.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
......
......@@ -23,6 +23,7 @@ derive write Inline
:: *HSt = { cntr :: !Int // counts position in expression
, submits :: !Bool // True if we are in submitting mode
, issub :: !Bool // True if this form is a subform of another
, states :: !*FormStates // all form states are collected here ...
, request :: !HTTPRequest // to enable access to the current HTTP request
, world :: *NWorld // to enable all other kinds of I/O
......
......@@ -20,6 +20,7 @@ gPrint{|(->)|} gArg gRes _ _ = abort "functions can only be used with dynamic st
:: *HSt = { cntr :: !Int // counts position in expression
, submits :: !Bool // True if we are in submit form
, issub :: !Bool // True if this form is a subform of another
, states :: !*FormStates // all form states are collected here ...
, request :: !HTTPRequest // to enable access to the current HTTP request
, world :: *NWorld // to enable all other kinds of I/O
......@@ -201,7 +202,7 @@ doHtmlClient userpage world
mkHSt :: *FormStates *NWorld -> *HSt
mkHSt states nworld = {cntr=0, states=states, request= http_emptyRequest, world=nworld, submits = False }
mkHSt states nworld = {cntr=0, states=states, request= http_emptyRequest, world=nworld, submits = False, issub = False }
// The function mkViewForm is *the* magic main function
......@@ -209,7 +210,7 @@ mkHSt states nworld = {cntr=0, states=states, request= http_emptyRequest, world=
// It does everything, a swiss army knife editor that makes coffee too ...
mkViewForm :: !(InIDataId d) !(HBimap d v) !*HSt -> (Form d,!*HSt) | iData v
mkViewForm (init,formid) bm=:{toForm, updForm, fromForm, resetForm} hst=:{states,world,submits}
mkViewForm (init,formid) bm=:{toForm, updForm, fromForm, resetForm} hst=:{states,world,submits,issub}
| init == Const && formid.lifespan <> Temp
= mkViewForm (init,{formid & lifespan = Temp}) bm hst // constant i-data are never stored
| init == Const // constant i-data, no look up of previous value
......@@ -238,7 +239,7 @@ where
,mkHSt states world)
# (viewform,{states,world}) // make a form for it
= mkForm (init,if (init == Const) vformid (reuseFormId formid view)) ({mkHSt states world & submits = submits})
= mkForm (init,if (init == Const) vformid (reuseFormId formid view)) ({mkHSt states world & submits = submits, issub = issub})
| viewform.changed && not isupdated // important: redo it all to handle the case that a user defined specialisation is updated !!
= calcnextView True (Just viewform.value) states world
......@@ -335,23 +336,26 @@ where
// gForm: automatically derives a Html form for any Clean type
mkForm :: !(InIDataId a) !*HSt -> *(Form a, !*HSt) | gForm {|*|} a
mkForm (init,formid) hst
# (form,hst) = gForm{|*|} (init,formid) {hst & submits = (formid.mode == Submit) } //Use gForm to create the html form
mkForm (init,formid) hst =: {issub}
# (form,hst) = gForm{|*|} (init,formid) {hst & submits = (formid.mode == Submit), issub = True} //Use gForm to create the html form
# buttons = if (formid.mode == Submit) //Add submit and clear buttons to a form in submit mode.
[ Br
, Input [ Inp_Type Inp_Submit, Inp_Value (SV "Submit")] ""
, Input [ Inp_Type Inp_Reset, Inp_Value (SV "Clear")] ""
, Br
]
[ Input [Inp_Type Inp_Submit, `Inp_Std [Std_Style "display: none"] ] ""] //Add a hidden submit input to allow updates on press of "enter" button
# sform = [Form [ Frm_Action ("/" +++ ThisExe) //Wrap the form in html form tags
# sform = if issub
form.form
[Form [ Frm_Action ("/" +++ ThisExe) //Wrap the form in html form tags
, Frm_Method Post
, Frm_Name (encodeString formid.id) //Enable the use of any character in a form name
, Frm_Enctype "multipart/form-data"
, `Frm_Events [OnSubmit (SScript "return catchSubmit(this);")]
, `Frm_Std [Std_Id (encodeString formid.id)]
] (form.form ++ buttons)
]
]
= ({form & form = sform} ,hst)
generic gForm a :: !(InIDataId a) !*HSt -> *(Form a, !*HSt)
......
......@@ -62,11 +62,11 @@ gHpr{|BodyTag|} prev (H3 attr text) = prev <+> htmlAttrCmnd "h3" attr tex
gHpr{|BodyTag|} prev (H4 attr text) = prev <+> htmlAttrCmnd "h4" attr text
gHpr{|BodyTag|} prev (H5 attr text) = prev <+> htmlAttrCmnd "h5" attr text
gHpr{|BodyTag|} prev (H6 attr text) = prev <+> htmlAttrCmnd "h6" attr text
gHpr{|BodyTag|} prev (Hr attr) = prev <+> htmlAttrCmnd "hr" attr None
gHpr{|BodyTag|} prev (Hr attr) = prev <+> htmlBodylessAttrCmnd "hr" attr
gHpr{|BodyTag|} prev (I attr text) = prev <+> htmlAttrCmnd "i" attr text
gHpr{|BodyTag|} prev (Iframe attr) = prev <+> htmlAttrCmnd "iframe" attr None
gHpr{|BodyTag|} prev (Img attr) = prev <+> htmlAttrCmnd "img" attr None
gHpr{|BodyTag|} prev (Input attr text) = prev <+> htmlAttrCmnd "input" attr text
gHpr{|BodyTag|} prev (Input attr text) = prev <+> htmlBodylessAttrCmnd "input" attr
gHpr{|BodyTag|} prev (Ins attr text) = prev <+> htmlAttrCmnd "ins" attr text
gHpr{|BodyTag|} prev (Kbd attr text) = prev <+> htmlAttrCmnd "kbd" attr text
gHpr{|BodyTag|} prev (Label attr text) = prev <+> htmlAttrCmnd "label" attr text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment