Difference between revisions of "Contact.rythm"
Jump to navigation
Jump to search
Line 14: | Line 14: | ||
String task=de?"Was ist "+a1+"+"+a2:"What is "+a1+"+"+a2; | String task=de?"Was ist "+a1+"+"+a2:"What is "+a1+"+"+a2; | ||
} | } | ||
+ | @// static classes | ||
@def static{ | @def static{ | ||
class ContactPost { | class ContactPost { | ||
Line 23: | Line 24: | ||
MultivaluedMap<String, String> formParams; | MultivaluedMap<String, String> formParams; | ||
+ | // constructor | ||
public ContactPost(PostService postService,String postToken) { | public ContactPost(PostService postService,String postToken) { | ||
if (postToken!=null) { | if (postToken!=null) { | ||
Line 37: | Line 39: | ||
} | } | ||
} | } | ||
+ | @// optional debugging of contact | ||
@def contactDebug(ContactPost contact) { | @def contactDebug(ContactPost contact) { | ||
@if (contact.formParams!=null) { | @if (contact.formParams!=null) { | ||
Line 54: | Line 57: | ||
</div> | </div> | ||
} | } | ||
+ | @// show the contact Form | ||
@def contactForm(ContactPost contact, boolean de) { | @def contactForm(ContactPost contact, boolean de) { | ||
<div class="row"> | <div class="row"> | ||
Line 94: | Line 98: | ||
@// BITPlan Contact Form | @// BITPlan Contact Form | ||
@// | @// | ||
− | |||
@header(languageCode,title) | @header(languageCode,title) | ||
@bootstrap() | @bootstrap() | ||
Line 106: | Line 109: | ||
</header> | </header> | ||
<div class="container"> | <div class="container"> | ||
+ | @(languageCode) | ||
+ | @(title) | ||
@if (!(contact.captcha.isEmpty())) { | @if (!(contact.captcha.isEmpty())) { | ||
@if (contact.captcha.equals(contact.expected)) { | @if (contact.captcha.equals(contact.expected)) { | ||
Line 113: | Line 118: | ||
@contactForm(contact,de) | @contactForm(contact,de) | ||
@{ | @{ | ||
− | String msg=de?"Bitte geben Sie das richtige Ergebnis für die Aufgabe | + | String msg=de?"Bitte geben Sie das richtige Ergebnis für die Aufgabe ein":"Please enter the correct result for the task"; |
} | } | ||
@alert("danger","alert",msg) | @alert("danger","alert",msg) |
Revision as of 15:35, 3 November 2017
Links
Source
@// Rythm template for the WikiCMS approach
@include(wiki.MediaWiki.Bootstrap.rythm)
@include(wiki.MediaWiki.BITPlan.rythm)
@// non static
@{
ContactPost contact=new ContactPost(postService,postToken);
int a1=(int)(Math.random() * 10 + 1);
int a2=(int)(Math.random() * 10 + 1);
int expected=a1+a2;
String task=de?"Was ist "+a1+"+"+a2:"What is "+a1+"+"+a2;
}
@// static classes
@def static{
class ContactPost {
String name="";
String email="";
String message="";
String captcha="";
String expected="-"; // default is unequal to captcha
MultivaluedMap<String, String> formParams;
// constructor
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");
}
}
}
}
}
@// optional debugging of contact
@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>
}
@// show the contact Form
@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">
<label for="InputReal">@(task)?</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>
}
@//
@// BITPlan Contact Form
@//
@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">
@(languageCode)
@(title)
@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 für die Aufgabe ein":"Please enter the correct result for the task";
}
@alert("danger","alert",msg)
}
} else {
@contactForm(contact,de)
}
</div>
@footer(languageCode)