<commit_before><link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="definition-edit">
  <template>
    <style>
      :host {
        display: block;
        padding: 20px;
      }
      .mainframe {
        max-width: 1024px;
        margin: 0 auto;
        width: 100%;
      }
      paper-dialog.size-position {
        position: fixed;
        top: 16px;
        right: 16px;
        width: 300px;
        height: 300px;
        overflow: auto;
      }
    </style>
    <firebase-document
      id="firedoc"
          location=""
          data="{{definition}}"></firebase-document>
      <div class="mainframe">
        <h2>Edit Definition
          <tooltip-icon icon="build" tooltip="Enable editing" hidden$="{{canEdit}}" on-tap="login"></tooltip-icon>
        </h2>
        <paper-input readonly="{{!canEdit}}" label="Term" value="{{term}}"></paper-input>
        <paper-input readonly="{{!canEdit}}" label="Text" value="{{text}}"></paper-input>
        <paper-button disabled="{{!canEdit}}" on-tap="_saveTerm" disabled="{{!cansave}}" raised>Save</paper-button>
        <paper-button disabled="{{!canEdit}}" on-tap="_deleteItem" raised>Delete</paper-button>
      </div>

      <login-dialog id="loginDialog" can-edit="{{canEdit}}"></login-dialog>

      <paper-toast id="errorToast" text="{{_errmsg}}"></paper-toast>
  </template>

  <script>
    (function () {
      'use strict';

      Polymer({
        is: 'definition-edit',
        properties: {
          term: {
            type: String,
            notify: true,
            observer: '_valueChanged',
          },
          text: {
            type: String,
            notify: true,
            observer: '_valueChanged',
          },
          cansave: {
            type: Boolean,
            value: false,
          }, key: {
            type: String,
            observer: '_keyChanged',
          },
          urlBase: {
            type: String,
            value: 'https://biodictionary.firebaseio.com/definitions/',
          },
          _errmsg: {
            type: String,
            value: 'Error'
          },
          canEdit: {
            type: Boolean,
            value: false,
          },
        },
        _keyChanged: function() {
          if (!this.key) {
            this.term = '';
            this.text = ''  ;
          } else {
            var ref = new Firebase(this.urlBase + this.key);
            var defedit = this;
            ref.on('value', function(snapshot) {
              defedit.term = snapshot.val().term;
              defedit.text = snapshot.val().text;
            }, function (errorObject) {
              console.log(errorObject);
            });
          }
        },
        login: function() {
          this.$.loginDialog.open();
        },
        _valueChanged: function() {
          this.cansave = this._canSave();
        },
        _canSave: function() {
          return this.text && this.term;
        },
        _deleteItem: function() {
          var thisthing = this;
          var onComplete = function(error) {
            if (error) {
              thisthing._errmsg = error.message;
              thisthing.$.errorToast.show();
            } else {
              page('/');
            }
          };
          if (this.key) {
            var def = new Firebase(this.urlBase + this.key);
            def.remove(onComplete);
          } else {
            page('/');
          }
          //page('/');
        },
        _saveTerm: function() {
          var thisthing = this;
          var onComplete = function(error) {
            if (error) {
              thisthing._errmsg = error;
              thisthing.$.errorToast.show();
            } else {
              page('/');
            }
          };
          if( this._canSave()) {
            var val = { 'term': this.term, 'lcterm': this.term.toLowerCase(), 'text': this.text};
            if (this.key) {
              var def = new Firebase(this.urlBase + this.key);
              def.update(val, onComplete );
            } else {
              var definitions = new Firebase(this.urlBase);
              this.key = definitions.push(val, onComplete);
            }
          }
        }
      });
    })();
  </script>

</dom-module><commit_msg>new twice should work<commit_after><link rel="import" href="../../bower_components/polymer/polymer.html">
<dom-module id="definition-edit">
  <template>
    <style>
      :host {
        display: block;
        padding: 20px;
      }
      .mainframe {
        max-width: 1024px;
        margin: 0 auto;
        width: 100%;
      }
      paper-dialog.size-position {
        position: fixed;
        top: 16px;
        right: 16px;
        width: 300px;
        height: 300px;
        overflow: auto;
      }
    </style>
    <firebase-document
      id="firedoc"
          location=""
          data="{{definition}}"></firebase-document>
      <div class="mainframe">
        <h2>Edit Definition
          <tooltip-icon icon="build" tooltip="Enable editing" hidden$="{{canEdit}}" on-tap="login"></tooltip-icon>
        </h2>
        <paper-input readonly="{{!canEdit}}" label="Term" value="{{term}}"></paper-input>
        <paper-input readonly="{{!canEdit}}" label="Text" value="{{text}}"></paper-input>
        <paper-button disabled="{{!canEdit}}" on-tap="_saveTerm" disabled="{{!cansave}}" raised>Save</paper-button>
        <paper-button disabled="{{!canEdit}}" on-tap="_deleteItem" raised>Delete</paper-button>
      </div>

      <login-dialog id="loginDialog" can-edit="{{canEdit}}"></login-dialog>

      <paper-toast id="errorToast" text="{{_errmsg}}"></paper-toast>
  </template>

  <script>
    (function () {
      'use strict';

      Polymer({
        is: 'definition-edit',
        properties: {
          term: {
            type: String,
            notify: true,
            observer: '_valueChanged',
          },
          text: {
            type: String,
            notify: true,
            observer: '_valueChanged',
          },
          cansave: {
            type: Boolean,
            value: false,
          }, key: {
            type: String,
            observer: '_keyChanged',
          },
          urlBase: {
            type: String,
            value: 'https://biodictionary.firebaseio.com/definitions/',
          },
          _errmsg: {
            type: String,
            value: 'Error'
          },
          canEdit: {
            type: Boolean,
            value: false,
          },
        },
        _keyChanged: function() {
          if (!this.key) {
            this.term = '';
            this.text = '';
          } else {
            var ref = new Firebase(this.urlBase + this.key);
            var defedit = this;
            ref.on('value', function(snapshot) {
              var val = snapshot.val();
              if (!val) {
                defedit.term = '';
                defedit.text = '';
              } else {
                defedit.term = val.term;
                defedit.text = val.text;
              }

            }, function (errorObject) {
              console.log(errorObject);
            });
          }
        },
        login: function() {
          this.$.loginDialog.open();
        },
        _valueChanged: function() {
          this.cansave = this._canSave();
        },
        _canSave: function() {
          return this.text && this.term;
        },
        _deleteItem: function() {
          var thisthing = this;
          var onComplete = function(error) {
            if (error) {
              thisthing._errmsg = error.message;
              thisthing.$.errorToast.show();
            } else {
              thisthing.term = '';
              thisthing.text = '';
              page('/');
            }
          };
          if (this.key) {
            var def = new Firebase(this.urlBase + this.key);
            def.remove(onComplete);
          } else {
            this.term = '';
            this.text = '';
            page('/');
          }
        },
        _saveTerm: function() {
          var thisthing = this;
          var onComplete = function(error) {
            if (error) {
              thisthing._errmsg = error;
              thisthing.$.errorToast.show();
            } else {
              thisthing.term = '';
              thisthing.text = '';
              page('/');
            }
          };
          if( this._canSave()) {
            var val = { 'term': this.term, 'lcterm': this.term.toLowerCase(), 'text': this.text};
            if (this.key) {
              var def = new Firebase(this.urlBase + this.key);
              def.update(val, onComplete );
            } else {
              var definitions = new Firebase(this.urlBase);
              definitions.push(val, onComplete);
            }
          }
        }
      });
    })();
  </script>

</dom-module>
{'fraction_non_alphanumeric': 0.14764798559531847, 'fraction_numerical': 0.00495160927301373, 'mean_word_length': 1.3915500538213132, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, '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': '6123785', 'n_tokens_mistral': 2498, 'n_tokens_neox': 2449, 'n_words': 468}