Difference between revisions of "Contact.rythm"

From BITPlan Wiki
Jump to navigation Jump to search
 
(47 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)
@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);
+
   Field[] fields={
  int a2=(int)(Math.random() * 10 + 1);
+
    new TextField("name","Name","Name","John Doe","Erika Mustermann","user",2),
  int expected=a1+a2;
+
    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),
        <label for="InputReal">@(de?"Was ist "+a1+"+"+a2:"What is "+a1+"+"+a2)?</label>
+
    new TextAreaField("message","Your Message to us","Ihre Nachricht an us","Your Message","Ihre Nachricht","pencil",10)
        <div class="input-group">
+
   };
          <input type="text" class="form-control" name="contactCaptcha" id="contactCaptcha" value="@(contact.captcha)" required>
+
  Form form=new Form(de,postService,postToken,fields);
          <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
+
   form.setTitle("Your contact with us","Ihre Nachricht an uns");
          <input type="hidden" class="form-control" name="expected" id="expected" placeholder="postToken" value="@(expected)" required>
+
   form.setSuccess("Thanks for contacting us, we will get back to you shortly","Vielen Dank für Ihre Kontaktaufnahme, wir melden uns unverzüglich");
          <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>
 
}
 
<!doctype html>
 
<html lang="@(lang)">
 
<head>
 
  <!-- https://de.wikipedia.org/wiki/Bootstrap_(Framework) -->
 
  <meta charset="utf-8"/>
 
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
  <title>@(title)</title>
 
@bootstrap()
 
   <style>
 
    body{
 
      margin: 2vw auto;
 
      max-width: 60em;
 
    }
 
    * {
 
      font-family: Arial, Helvetica, sans-serif;
 
    }
 
    header,footer{
 
      background-color: #FFFFFF;
 
      text-align: center;
 
    }
 
    footer {
 
      clear:both;
 
    }
 
    nav a:link,a:visited {
 
      text-decoration: none;
 
    }
 
    a:hover {
 
      color: #FFFFFF;
 
      background-color: rgba(255,128,00,0.5);
 
    }
 
    main,article{
 
    }
 
    main {
 
      padding: 2vw;margin:1vw;
 
    }
 
    h1,h2,h3 {
 
      color: #FF8000;
 
    }
 
    .floatleft {
 
      float: left;
 
      margin: 1vw;
 
    }
 
    .floatright {
 
      float: right;
 
      margin: 1vw;
 
    }
 
    .logo {
 
      width: 6vw;
 
      float:left;
 
    }
 
    .copyright {
 
      font-size: 0.5vw;
 
    }
 
    .imprint {
 
      font-size: 0.8vw;
 
    }
 
    ul li{
 
      margin-bottom:1vh;
 
    }
 
 
 
/** Language styles */
 
 
 
span.lang-de, span.lang-De {
 
padding-right: 25px;
 
background: url(http://wiki.bitplan.com/images/e/e7/Lang-De.gif) center right no-repeat;
 
}
 
 
 
span.lang-en, span.lang-En {
 
padding-right: 25px;
 
background: url(http://wiki.bitplan.com/images/7/78/Lang-En.gif) center right no-repeat;
 
}
 
   </style>
 
  </head>
 
 
 
<body>
 
    <header class='row'>
 
@{
 
  Object languageCodeObj=smwprops.get("_LCODE");
 
  String languageCode="de";
 
  if (languageCodeObj!=null) {
 
    languageCode=languageCodeObj.toString();
 
   }
 
  boolean de="de".equals(languageCode);
 
}
 
  <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)) {
 
    @alert("success","send",de?"Vielen Dank - Ihre Nachricht wurde gesendet":"Thank you - your message was sent");
 
  } else {
 
      @contactForm(contact,de)
 
      @alert("danger","alert",de?"Bitte geben Sie das richtige Ergebnis ein":"Please enter the correct result");
 
  }
 
} else {
 
@contactForm(contact,de)
 
}
 
    </div>
 
    <footer>
 
      <nav>
 
        <span class='copyright'>© 2017&nbsp;
 
          <a href='http://www.bitplan.com'>BITPlan GmbH.</a>&nbsp;Alle Rechte vorbehalten.
 
        </span>
 
        &nbsp;
 
@if ("de".equals(languageCode)) {
 
        <span class='imprint'><a href='http://training.bitplan.com/index.php/Impressum'>Impressum</a></span>
 
} else {
 
        <span class='imprint'><a href='http://training.bitplan.com/index.php/Imprint'>Imprint</a></span>
 
 
}
 
}
      </nav>
+
@BITPlanHeader(languageCode,title)
    </footer>
+
@BITPlanForm(de,form)
  </body>
 
</html>
 
 
</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)