Contact.rythm: Difference between revisions

From BITPlan Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
= Links =
= Links =
* https://codepen.io/jaycbrf/pen/iBszr
* {{Link|target=MediaWiki:Bootstrap.rythm}}
* {{Link|target=MediaWiki:Bootstrap.rythm}}
* {{Link|target=MediaWiki:BITPlan.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.Bootstrap.rythm)
@include(wiki.MediaWiki.BITPlan.rythm)
@include(wiki.MediaWiki.BITPlan.rythm)
@import org.simplejavamail.email.Email
@include(wiki.MediaWiki.Form.rythm)
@import org.simplejavamail.email.EmailBuilder
@import org.simplejavamail.mailer.Mailer
@import com.bitplan.mail.SimpleMail
@//  non static
@{
@{
   ContactPost contact=new ContactPost(postService,postToken);
   SelectField selectField=new SelectField("training","Seminar","Training","CPSA-F","CPSA-F","book",0);
   int a1=(int)(Math.random() * 10 + 1);
   String [] trainings={"Certified Professional for Software Architecture Foundation-Level CPSA-F","Certified Professional for Requirements Engineering Foundation-Level CPRE-FL"};
   int a2=(int)(Math.random() * 10 + 1);
   selectField.addSelections(trainings);
   int expected=a1+a2;
   Field[] fields={
  String task=de?"Was ist "+a1+"+"+a2+"?":"What is "+a1+"+"+a2+"?";
    //selectField,
}
    new TextField("name","Name","Name","John Doe","Erika Mustermann","user",2),
@// static classes
     new TextField("organisation","Organization","Organiation","Doe Inc.","Mustermann GmbH","user",2),
@def static{
     new TextField("email","E-Mail Address","E-Mail Adresse","john@doe.com","erika@mustermann.de","envelope",5),
  class ContactPost {
     //new TextField("phone","Phone number","Telefon","+1 845 555-1212","+49 30 675797","earphone",8),
     String name="";
     new TextAreaField("message","Your Message to us","Ihre Nachricht an us","Your Message","Ihre Nachricht","pencil",10)
     String email="";
    //new TextField("address","Address","Adresse","12 Westend Ave","Mauerstr. 12","home",8),
     String message="";
     //new TextField("zip","ZIP Code","PLZ","10023","10117","home",3),
    String captcha="";
    //new TextField("city","City","Ort","New York","Berlin","home",2)
    String expected="-"; // default is unequal to captcha
  };
    MultivaluedMap<String, String> formParams;
  Form form=new Form(de,postService,postToken,fields);
 
  form.setTitle("Your contact with us","Ihre Nachricht an uns");
     public String asMail() {
  form.setSuccess("Thanks for contacting us, we will get back to you shortly","Vielen Dank für Ihre Kontaktaufnahme, wir melden uns unverzüglich");
      String mail=String.format("name=%s\nemail=%s\n%s\n",name,email,message);
   for (Field field:form.getFields()) {  
      return mail;
    field.labelClass="bitplanorange";
    }
     // 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>
}
@def requiredIcon(String icon) {
<span class="input-group-addon"><i class="glyphicon glyphicon-@(icon) form-control-feedback"></i></span></div>
}
@// add a field
@def field(boolean de,String name,String label_de,String label_en,String value,boolean isRequired) {
@{
  String required="";
  if (isRequired) required="required";
}
  <div class="form-group @(required)">
    <label class="control-label" for="@(name)">@(de?label_de:label_en):</label>
    <div class="input-group">
    <input type="text" class="form-control" name="@(name)" id="@(name)" placeholder="@(de?"":"Enter") @(de?label_de:label_en)" value="@(value)" @(required)>
    @if(isRequired) {
      @requiredIcon("asterisk")
    }
  </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-asterisk form-control-feedback"></i>@(de?"Pflichtfeld":"Required Field")</strong>
    </div>
    @field(de,"contactName","Ihr Name","Your Name",contact.name,true)
    @field(de,"contactEmail","Ihre E-Mail","Your Email",contact.email,true)
      <div class="form-group required">
        <label class="control-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>
          @requiredIcon("asterisk")
      </div>
      <div class="form-group required">
        <label class="control-label" for="contactCaptcha">@(task)</label>
        <div class="input-group">
          <input type="text" class="form-control" name="contactCaptcha" id="contactCaptcha" value="@(contact.captcha)" required>
          @requiredIcon("asterisk")
          <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,"ContactTest")
@//  BITPlan Contact Form
@//
@header(languageCode,title)
@bootstrap()
@bootstrap()
@style()
@style()
@formvalidate(form)
   </head>
   </head>
<body>
  <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">
   <div class="container">
@if (!(contact.captcha.isEmpty())) {
@showform(form)  
  @if (contact.captcha.equals(contact.expected)) {
@formDebug(form)
    @{
  </div><!-- /.container -->
      String msg=de?"Entschuldigen Sie bitte - es ist ein Problem aufgetreten. Bitte nehmen Sie über einen anderen Weg laut Impressum Kontakt mit uns auf!!":"Sorry - there is a problem please contact us via a different channel as per our imprint!";
      String alertType="danger";
      String icon="alert";
      try {
        Mailer mailer=SimpleMail.getMailer();
        if (mailer!=null) {
            Email email=new EmailBuilder()
            .from("BITPlan WebMaster","webmaster@bitplan.com")
            .to("info@bitplan.com")
            .subject("Contact Form Request")
            .text(contact.asMail())
            .build();
            mailer.sendMail(email);
            msg=de?"Vielen Dank - Ihre Nachricht wurde gesendet":"Thank you - your message was sent";
            alertType="success";
            icon="send";
        }
      } catch (Throwable th) {
        msg="Exception "+th.getClass().getName()+":"+th.getMessage();
      }
    }
    @alert(alertType,icon,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(de)
@footer(de)
</source>
</source>
[[Category:RythmTemplate]]
[[Category:RythmTemplate]]

Revision as of 08:26, 9 November 2017

Links

Rythm template

@// Rythm template for the WikiCMS approach
@include(wiki.MediaWiki.Bootstrap.rythm)
@include(wiki.MediaWiki.BITPlan.rythm)
@include(wiki.MediaWiki.Form.rythm)
@{
  SelectField selectField=new SelectField("training","Seminar","Training","CPSA-F","CPSA-F","book",0);
  String [] trainings={"Certified Professional for Software Architecture Foundation-Level CPSA-F","Certified Professional for Requirements Engineering Foundation-Level CPRE-FL"};
  selectField.addSelections(trainings);
  Field[] fields={
    //selectField,
    new TextField("name","Name","Name","John Doe","Erika Mustermann","user",2),
    new TextField("organisation","Organization","Organiation","Doe Inc.","Mustermann GmbH","user",2),
    new TextField("email","E-Mail Address","E-Mail Adresse","john@doe.com","erika@mustermann.de","envelope",5),
    //new TextField("phone","Phone number","Telefon","+1 845 555-1212","+49 30 675797","earphone",8),
    new TextAreaField("message","Your Message to us","Ihre Nachricht an us","Your Message","Ihre Nachricht","pencil",10)
    //new TextField("address","Address","Adresse","12 Westend Ave","Mauerstr. 12","home",8),
    //new TextField("zip","ZIP Code","PLZ","10023","10117","home",3),
    //new TextField("city","City","Ort","New York","Berlin","home",2)
  };
  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");
  for (Field field:form.getFields()) { 
    field.labelClass="bitplanorange";
  }
}
@header(languageCode,"ContactTest")
@bootstrap()
@style()
@formvalidate(form)
  </head>
  <body>
  <div class="container">
@showform(form) 
@formDebug(form)
   </div><!-- /.container -->
@footer(de)