Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

validation through connect button

  • Loading branch information...
commit 9cfa100a8ea1ad8fbc137de34556976ae658d8ab 1 parent 39565ba
@dhobi authored
View
18 src/main/scala/code/comet/ChatUser.scala
@@ -35,7 +35,8 @@ class ChatUser extends User with CometActor {
val splitted = str.split(",")
Coords(splitted.head.toDouble, splitted.last.toDouble)
}
- }).toJsCmd
+ SetHtml("connectButton", generateConnectButton)
+ })
def initPosition = coords match {
case Full(Coords(lat, long)) => JsRaw("map.setPosition(new google.maps.LatLng(" + lat + "," + long + "))").cmd
@@ -47,7 +48,7 @@ class ChatUser extends User with CometActor {
var lat = event.latLng.lat();
var lng = event.latLng.lng();
var value = lat+","+lng;
- """ + callback("value") + """})""").cmd
+ """ + callback("value").toJsCmd + """})""").cmd
}
def showForm = SetHtml("userform", userForm)
@@ -107,6 +108,17 @@ class ChatUser extends User with CometActor {
this.color = str
JsCmds.Noop
}) &
- "#userSubmit" #> SHtml.ajaxButton(Text("Connect"), () => initGlobalChat))(Templates(List("templates", "userSetup")).openOr(NodeSeq.Empty))
+ "#userSubmit" #> generateConnectButton)(Templates(List("templates", "userSetup")).openOr(NodeSeq.Empty))
+ }
+
+ def validations = List((() => this.coords.isDefined,"Please set your location on the map first."))
+
+ def getErrors = validations.collect {
+ case (validfunc, msg) if !validfunc() => msg
+ }
+
+ def generateConnectButton = getErrors match {
+ case l if l.isEmpty => SHtml.ajaxButton(Text("Connect"), () => initGlobalChat, "id" -> "userSubmit")
+ case l => SHtml.ajaxButton(Text(l.mkString(",")), () => JsCmds.Noop)
}
}
View
4 src/main/webapp/templates/userSetup.html
@@ -3,5 +3,7 @@
<input type="text" id="colorpicker">
<br/>
<div id="googleMap"></div>
- <input type="button" id="userSubmit">
+ <span id="connectButton">
+ <input type="button" id="userSubmit">
+ </span>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.