<commit_before><link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-fab/paper-fab.html">
<link rel="import" href="../../bower_components/core-icons/core-icons.html">
<link rel="import" href="../../bower_components/core-ajax/core-ajax.html">
<link rel="import" href="../../bower_components/firebase-element/firebase-element.html">


<polymer-element name="beta-form" attributes="">

  <template>

    <core-ajax id="add_madmimi_request"
      url="madmimi.php?email={{email}}&create_at={{timestamp}}"
      handleAs="text"
      on-core-response="{{ajaxResponse}}"></core-ajax>

    <link rel="stylesheet" href="beta-form.css">

    <div id="container_div" vertical layout center>
      <h3 id="title_message">Actionplanr Beta coming<br> soon by invitation only.<br>Get yours:</h3>
      <div id="form_div" horizontal layout center>
        <paper-input id="email_input" label="Input Email" type="email" error="Input is not an email!" on-enter="{{saveData}}" on-keypress="{{ keypressAction }}"
  required></paper-input><br> <!-- validate="^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$" error=" " -->
        <paper-fab id"submit_input" icon="check" class="fab-success green" on-click="{{saveData}}" style="background: #D0F5A9;" ></paper-fab>
      </div>

      <div id="success" hidden>
        <h3>{{email}}</h3>
        <h2 id="success_h2">Thank you for requesting <br>a beta invite!</h2>
        <p>We will email you when it is ready.</p>
        <p>In the meantime,<br> get the latest productivity updates<br> at our blog <a href="//actionplanr.com/blog">actionplanr.com/blog</a></p>
      </div>
    </div>
  </template>
  <script>

    (function () {
      'use strict';

      Polymer({

        ready: function() {
          this.status = 'blank';  // blank, add, loaded, changed, added, saved, cancelled
          this.email = "";
          this.timestamp = new Date();
        },

        ajaxResponse: function(event, response) {
            console.log("ajaxResponse: ", response);
        },

        saveData: function() {
          var timestamp = new Date();
          var email = this.$.email_input.inputValue;
          var atpos = email.indexOf("@");
          var dotpos = email.lastIndexOf(".");
          if (atpos < 1 || dotpos<atpos+2 || dotpos + 2 >= email.length) {
              this.$.email_input.error="Not a valid email";
              //console.log('saveData email NOT VALID: ' +  this.$.email_input.inputValue, timestamp.toLocaleString());
              alert(email + "\n\nNot a valid e-mail address, please try again!");
              this.email = "";
          } else {
            this.email = email;
            this.timestamp = new Date();
            this.$.add_madmimi_request.go();

            new Firebase('https://beta-invite.firebaseio.com/requests').push({
              email: email,
              create_at: timestamp.toLocaleString(),
              create_at_full: timestamp.toString()
            });

            console.log('saveData email: ' +  this.$.email_input.inputValue, timestamp.toLocaleString());
            this.status = 'saved';
            this.$.form_div.hidden = true;
            this.$.title_message.hidden = true;
            this.$.success.hidden = false;<commit_msg>Replace Alert with Poylmer Dialog<commit_after><link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-fab/paper-fab.html">
<link rel="import" href="../../bower_components/core-icons/core-icons.html">
<link rel="import" href="../../bower_components/core-ajax/core-ajax.html">
<link rel="import" href="../../bower_components/firebase-element/firebase-element.html">
<link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html">


<polymer-element name="beta-form" attributes="">

  <template>

    <paper-dialog id="dialog1" heading="Actionplanr Message" >
      <p>{{email1}}</p>
      <p>{{dialogMessage}}</p>
      <!-- <paper-button label="More Info..." dismissive></paper-button> -->
      <paper-button label="Cancel" affirmative hidden></paper-button>
      <paper-button label="OK" affirmative autofocus></paper-button>
    </paper-dialog>

    <core-ajax id="add_madmimi_request"
      url="madmimi.php?email={{email}}&create_at={{timestamp}}"
      handleAs="text"
      on-core-response="{{ajaxResponse}}"></core-ajax>

    <link rel="stylesheet" href="beta-form.css">

    <div id="container_div" vertical layout center>
      <h3 id="title_message">Actionplanr Beta coming<br> soon by invitation only.<br>Get yours:</h3>
      <div id="form_div" horizontal layout center>
        <paper-input id="email_input" label="Input Email" type="email" error="Input is not an email!" on-enter="{{saveData}}" on-keypress="{{keypressAction}}"
  required></paper-input><br> <!-- validate="^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$" error=" " -->
        <paper-fab id"submit_input" icon="check" class="fab-success green" on-click="{{saveData}}" style="background: #D0F5A9;" ></paper-fab>
      </div>

      <div id="success" hidden>
        <h3>{{email}}</h3>
        <h2 id="success_h2">Thank you for requesting <br>a beta invite!</h2>
        <p>We will email you when it is ready.</p>
        <p>In the meantime,<br> get the latest productivity updates<br> at our blog <a href="//actionplanr.com/blog">actionplanr.com/blog</a></p>
      </div>
    </div>
  </template>
  <script>

    (function () {
      'use strict';

      Polymer({

        dialogMessage: 'Sample Message',
        email1: 'Blank',

        ready: function() {
          this.status = 'blank';  // blank, add, loaded, changed, added, saved, cancelled
          this.email = "Blank";
          this.timestamp = new Date();
        },

        ajaxResponse: function(event, response) {
            console.log("ajaxResponse: ", response);
        },

        showDialog: function(msg) {
          this.dialogMessage = msg;
          this.$.dialog1.toggle();
        },

        saveData: function() {
          var timestamp = new Date();
          var email = this.$.email_input.inputValue;
          var atpos = email.indexOf("@");
          var dotpos = email.lastIndexOf(".");
          if (atpos < 1 || dotpos<atpos+2 || dotpos + 2 >= email.length) {
              this.$.email_input.error="Not a valid email";
              //console.log('saveData email NOT VALID: ' +  this.$.email_input.inputValue, timestamp.toLocaleString());
              // alert(email + "\n\nNot a valid e-mail address, please try again!");
              if (email) {
                this.email1 = email;
              }

              this.showDialog("Not a valid e-mail address, please try again!");
              this.email = "";
          } else {
            this.email = email;
            this.timestamp = new Date();
            this.$.add_madmimi_request.go();

            new Firebase('https://beta-invite.firebaseio.com/requests').push({
              email: email,
              create_at: timestamp.toLocaleString(),
              create_at_full: timestamp.toString()
            });

            console.log('saveData email: ' +  this.$.email_input.inputValue, timestamp.toLocaleString());
            this.status = 'saved';
            this.$.form_div.hidden = true;
            this.$.title_message.hidden = true;
            this.$.success.hidden = false;
{'fraction_non_alphanumeric': 0.17557755775577558, 'fraction_numerical': 0.005676567656765677, 'mean_word_length': 2.5803402646502835, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 103, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3088693', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2245, 'n_words': 457}