Contact.rythm
Jump to navigation
Jump to search
Links
Source
@// Rythm template for the WikiCMS approach
@include(wiki.MediaWiki.Bootstrap.rythm)
@include(wiki.MediaWiki.BITPlan.rythm)
@import com.bitplan.smw.PropertyMap
@import com.bitplan.wikifrontend.PostService
@import javax.ws.rs.core.MultivaluedMap
@args() {
String content,
String lang,
String title,
PostService postService,
String postToken,
PropertyMap smwprops;
}
@def static{
class ContactPost {
String name="";
String email="";
String message="";
String captcha="";
String expected="-"; // default is unequal to captcha
MultivaluedMap<String, String> formParams;
public ContactPost(PostService postService,String postToken) {
if (postToken!=null) {
formParams=postService.getPostData(postToken);
if (formParams!=null) {
name=formParams.getFirst("contactName");
email=formParams.getFirst("contactEmail");
message=formParams.getFirst("contactMessage");
captcha=formParams.getFirst("contactCaptcha");
expected=formParams.getFirst("expected");
}
}
}
}
}
@{
ContactPost contact=new ContactPost(postService,postToken);
}
@def contactDebug(ContactPost contact) {
@if (contact.formParams!=null) {
<pre>
@for(String key : contact.formParams.keySet()){
@(key)=@(contact.formParams.getFirst(key))
}
</pre>
}
}
@// display an alert
@def alert(String alertType,String icon, String message) {
<div class="row">
<div class="col-md-12">
<div class="alert alert-@(alertType)"><strong><span class="glyphicon glyphicon-@(icon)"></span> @(message)</strong></div>
</div>
</div>
}
@def contactForm(ContactPost contact, boolean de) {
<div class="row">
<form role="form" action="" method="post" >
<div class="col-lg-6">
<div class="well well-sm"><strong><i class="glyphicon glyphicon-ok form-control-feedback"></i>@(de?"Pflichtfeld":"Required Field")</strong></div>
<div class="form-group">
<label for="InputName">@(de?"Ihr Name":"Your Name"):</label>
<div class="input-group">
<input type="text" class="form-control" name="contactName" id="contactName" placeholder="Enter Name" value="@(contact.name)" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
</div>
<div class="form-group">
<label for="InputEmail">@(de?"Ihre E-Mail":"Your Email"):</label>
<div class="input-group">
<input type="email" class="form-control" id="contactEmail" name="contactEmail" placeholder="Enter Email" value="@(contact.email)" required >
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
</div>
<div class="form-group">
<label for="InputMessage">@(de?"Nachricht":"Message"):</label>
<div class="input-group">
<textarea name="contactMessage" id="contactMessage" class="form-control" rows="5" required>@(contact.message)</textarea>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
</div>
<div class="form-group">
@{
int a1=(int)(Math.random() * 10 + 1);
int a2=(int)(Math.random() * 10 + 1);
int expected=a1+a2;
}
<label for="InputReal">@(de?"Was ist "+a1+"+"+a2:"What is "+a1+"+"+a2)?</label>
<div class="input-group">
<input type="text" class="form-control" name="contactCaptcha" id="contactCaptcha" value="@(contact.captcha)" required>
<span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
<input type="hidden" class="form-control" name="expected" id="expected" placeholder="postToken" value="@(expected)" required>
<input type="hidden" class="form-control" name="postToken" id="postToken" placeholder="postToken" value="@(postService.getPostToken())" required>
</div>
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-right">
</div>
</form>
@contactDebug(contact)
</div>
}
@header(languageCode,title)
@bootstrap()
@style()
</head>
<body>
<header class='row'>
<a class='logo' href='http://training.bitplan.com/index.php/Willkommen'>
<img src='http://wiki.bitplan.com/images/wiki/7/7a/BITPlanLogo2012FontLess.svg' width='100%'>
</a>
</header>
<div class="container">
@if (!(contact.captcha.isEmpty())) {
@if (contact.captcha.equals(contact.expected)) {
@{ String msg=de?"Vielen Dank - Ihre Nachricht wurde gesendet":"Thank you - your message was sent"; }
@alert("success","send",msg);
} else {
@contactForm(contact,de)
@{ String msg=de?"Bitte geben Sie das richtige Ergebnis ein":"Please enter the correct result"; }
@alert("danger","alert",msg);
}
} else {
@contactForm(contact,de)
}
</div>
@footer(languageCode)