Permalink
Browse files

Make enter work for submitting stuff

  • Loading branch information...
1 parent c489d23 commit 9ad4aa99e9777010f0d87c4c6c2ce5de7899064b @norm2782 norm2782 committed Apr 6, 2012
Showing with 22 additions and 4 deletions.
  1. +19 −4 resources/static/hjs/jcu.hs
  2. +3 −0 src/JCU/Templates.hs
@@ -102,9 +102,10 @@ initInterpreter = do
rlsref <- newIORef []
ajaxQ GET "/rules/stored" obj (addRules rlsref) noop
registerEvents [ ("#submitquery", Click , submitQuery rlsref)
- , ("#txtAddRule" , KeyPress, noevent)
+ , ("#txtAddRule" , KeyPress, addRuleKeypress rlsref)
, ("#txtAddRule" , Blur , checkTermSyntax)
- , ("#btnAddRule" , Click , addRuleEvent rlsref) ]
+ , ("#btnAddRule" , Click , addRuleEvent rlsref)
+ , ("#query" , KeyPress, queryKeyPress rlsref) ]
where submitQuery rlsref _ = do
qryFld <- jQuery "#query"
qry <- valString qryFld
@@ -117,6 +118,16 @@ initInterpreter = do
showProof result _ _ = do
resFld <- jQuery "#output"
_setHTML resFld result
+ addRuleKeypress rlsref obj = do
+ (which :: Int) <- getAttr "which" obj
+ when ((which :: Int) == 13) $
+ addRuleEvent rlsref undefined >> return ()
+ return True
+ queryKeyPress rlsref obj = do
+ (which :: Int) <- getAttr "which" obj
+ when ((which :: Int) == 13) $
+ submitQuery rlsref undefined >> return ()
+ return True
checkTermSyntax :: EventHandler
checkTermSyntax _ = do
@@ -148,15 +159,19 @@ initProofTree = do -- Rendering
registerEvents [ ("#btnCheck" , Click , toggleClue rlsref emptyProof)
, ("#btnAddRule", Click , addRuleEvent rlsref)
, ("#btnReset" , Click , resetTree rlsref)
- , ("#txtAddRule", KeyPress, clr)
+ , ("#txtAddRule", KeyPress, clr rlsref)
, ("#txtAddRule", Blur , checkTermSyntax) ]
where resetTree rlsref _ = do -- Do not forget to add the class that hides the colours
jQuery "#proof-tree-div" >>= flip addClass "noClue"
-- Always store False in the store.
updateStore storeDoCheckId (const False)
replaceRuleTree rlsref emptyProof
return True
- clr _ = jQuery "#txtAddRule" >>= clearClasses >> return True
+ clr rlsref obj = do
+ which <- getAttr "which" obj
+ when ((which :: Int) == 13) $
+ addRuleEvent rlsref undefined >> return ()
+ jQuery "#txtAddRule" >>= clearClasses >> return True
-- Toggles checking of the proof and showing the results
toggleClue :: RulesRef -> Proof -> EventHandler
View
@@ -141,6 +141,9 @@ index = mainHTML $ do
H.input ! A.type_ "hidden" ! A.id "storeDoChecking" ! A.value "False"
H.input ! A.type_ "button" ! A.id "btnCheck" ! A.value "Check Proof"
H.input ! A.type_ "button" ! A.id "btnReset" ! A.value "Reset Tree"
+ H.h3 $ H.toHtml ("The Goal" :: Text)
+ H.p ! A.class_ "lhsText" $
+ H.toHtml ("With this exercise you get to do what a Prolog interpreter usually does for you: unifying terms and rules and find substitutions for variables. To start, you enter a Prolog query in the textfield above. Your job then is to proof that there exist solutions for this query. This is done by dragging rules from the right-hand side of the screen onto your query. This will unify the two and produce new terms to proof. When the bottom text fields all contain facts, your work is done! If you do not have rules and facts yet, you can load the examples below and/or add new ones yourself using the text field on the right-hand side of the screen. Good luck!" :: Text)
H.h3 $ H.toHtml ("Color coding help" :: Text)
H.ul ! A.id "color-coding-list" $ do
H.li $ do

0 comments on commit 9ad4aa9

Please sign in to comment.