Difference between revisions of "Contact.rythm"

From BITPlan Wiki
Jump to navigation Jump to search
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Links =
 
= Links =
 +
* https://codepen.io/jaycbrf/pen/iBszr
 +
* {{Link|target=MediaWiki:Bootstrap.rythm}}
 +
* {{Link|target=MediaWiki:BITPlan.rythm}}
 +
* {{Link|target=MediaWiki:Form.rythm}}
  
= Source =
+
= Rythm template =
<source lang='html4strict'>
+
<source lang='html'>
 
@// Rythm template for the WikiCMS approach
 
@// Rythm template for the WikiCMS approach
@include(wiki.MediaWiki.Bootstrap.rythm)
 
 
@include(wiki.MediaWiki.BITPlan.rythm)
 
@include(wiki.MediaWiki.BITPlan.rythm)
@import org.simplejavamail.email.Email
 
@import org.simplejavamail.email.EmailBuilder
 
@import org.simplejavamail.mailer.Mailer
 
@import com.bitplan.mail.SimpleMail
 
@//  non static
 
 
@{
 
@{
   ContactPost contact=new ContactPost(postService,postToken);
+
   Field[] fields={
  int a1=(int)(Math.random() * 10 + 1);
+
    new TextField("name","Name","Name","John Doe","Erika Mustermann","user",2),
   int a2=(int)(Math.random() * 10 + 1);
+
    new TextField("organisation","Organization","Organisation","Doe Inc.","Mustermann GmbH","user",2),
   int expected=a1+a2;
+
    new TextField("email","E-Mail Address","E-Mail Adresse","john@doe.com","erika@mustermann.de","envelope",5),
  String task=de?"Was ist "+a1+"+"+a2:"What is "+a1+"+"+a2+"?";
+
    new TextAreaField("message","Your Message to us","Ihre Nachricht an us","Your Message","Ihre Nachricht","pencil",10)
 +
  };
 +
   Form form=new Form(de,postService,postToken,fields);
 +
   form.setTitle("Your contact with us","Ihre Nachricht an uns");
 +
  form.setSuccess("Thanks for contacting us, we will get back to you shortly","Vielen Dank für Ihre Kontaktaufnahme, wir melden uns unverzüglich");
 
}
 
}
@// static classes
+
@BITPlanHeader(languageCode,title)
@def static{
+
@BITPlanForm(de,form)
  class ContactPost {
 
    String name="";
 
    String email="";
 
    String message="";
 
    String captcha="";
 
    String expected="-"; // default is unequal to captcha
 
    MultivaluedMap<String, String> formParams;
 
 
 
    public String asMail() {
 
      String mail=String.format("name=%s\nemail=%s\n%s\n",name,email,message);
 
      return mail;
 
    }
 
    // 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, String task,int expected,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="contactName">@(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="contactEmail">@(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="contactMessage">@(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="contactCaptcha">@(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">
 
@if (!(contact.captcha.isEmpty())) {
 
  @if (contact.captcha.equals(contact.expected)) {
 
    @{
 
      Email email=new EmailBuilder()
 
          .from("BITPlan WebMaster","webmaster@bitplan.com")
 
          .to("info@bitplan.com")
 
          .subject("Contact Form Request")
 
          .text(contact.asMail())
 
          .build();
 
      String msg=de?"Vielen Dank - Ihre Nachricht wurde gesendet":"Thank you - your message was sent";
 
    }
 
    @alert("success","send",msg)
 
  } else {
 
      @contactForm(contact,task,expected,de)
 
      @{
 
        String msg=de?"Bitte geben Sie das richtige Ergebnis für die Aufgabe "+task+" ein":"Please enter the correct result for the task "+task;
 
      }
 
      @alert("danger","alert",msg)
 
  }
 
} else {
 
@contactForm(contact,task,expected,de)
 
}
 
    </div>
 
@footer(languageCode)
 
 
</source>
 
</source>
 +
[[Category:RythmTemplate]]

Latest revision as of 16:56, 9 November 2017

Links

Rythm template

@// Rythm template for the WikiCMS approach
@include(wiki.MediaWiki.BITPlan.rythm)
@{
  Field[] fields={
    new TextField("name","Name","Name","John Doe","Erika Mustermann","user",2),
    new TextField("organisation","Organization","Organisation","Doe Inc.","Mustermann GmbH","user",2),
    new TextField("email","E-Mail Address","E-Mail Adresse","john@doe.com","erika@mustermann.de","envelope",5),
    new TextAreaField("message","Your Message to us","Ihre Nachricht an us","Your Message","Ihre Nachricht","pencil",10)
  };
  Form form=new Form(de,postService,postToken,fields);
  form.setTitle("Your contact with us","Ihre Nachricht an uns");
  form.setSuccess("Thanks for contacting us, we will get back to you shortly","Vielen Dank für Ihre Kontaktaufnahme, wir melden uns unverzüglich");
}
@BITPlanHeader(languageCode,title)
@BITPlanForm(de,form)