<commit_before><template>
  <div id="audit-flow">
    <button class="action one-line save" v-if="dirtyForm" v-on:click.stop.prevent="save">Save</button>
    <publish-button v-else-if="allNodesSpecified"></publish-button>
    <button class="action audit-casebook" v-on:click.stop.prevent="startAudit()" v-else>Finalize entries</button>
  </div>
</template>

<script>
import _ from "lodash";
import pp from "../libs/text_outline_parser";
import PublishButton from "./PublishButton";
import Axios from "../config/axios";
import urls from "../libs/urls";
import Vue from "vue";
const bus = new Vue();

Vue.component('DirtyForm',{
  data: () => ({original: {}}),
  props: ['cssClass', 'formMethod'],
  mounted: function() {
    for(let k of this.$refs.form.elements) {
      if (k.id) {
        k.addEventListener('change', this.emitDirty)
      }
    }
  },
  methods: {
    emitDirty: function() {
      bus.$emit('dirtiedForm', {})
    }
  },
  //template: '<div ref="parent"><slot></slot></div>'
  template: '<form ref="form" :class="cssClass" :method="formMethod"><slot></slot></form>'
})
<commit_msg>Improve form-dirty checking<commit_after><template>
  <div id="audit-flow">
    <button class="action one-line save" v-if="dirtyForm" v-on:click.stop.prevent="save">Save</button>
    <publish-button v-else-if="allNodesSpecified"></publish-button>
    <button class="action audit-casebook" v-on:click.stop.prevent="startAudit()" v-else>Finalize entries</button>
  </div>
</template>

<script>
import _ from "lodash";
import _tinymce from 'tinymce/tinymce';
import pp from "../libs/text_outline_parser";
import PublishButton from "./PublishButton";
import Axios from "../config/axios";
import urls from "../libs/urls";
import Vue from "vue";
const bus = new Vue();

Vue.component('DirtyForm',{
  data: () => ({fired: false}),
  props: ['cssClass', 'formMethod'],
    mounted: function() {
    for(let k of this.$refs.form.elements) {
      if (k.id) {
          k.addEventListener('input', this.emitDirty);
      }
    }
    const self = this;
    setTimeout(() => {
        window.tinyMCE.editors.forEach(editor => {
            editor.on('input', self.emitDirty);
        }, 100)
    })
  },
  methods: {
      emitDirty: function() {
          if (this.fired) return;
        bus.$emit('dirtiedForm', {})
        this.fired = true;
    }
  },
  //template: '<div ref="parent"><slot></slot></div>'
  template: '<form ref="form" :class="cssClass" :method="formMethod"><slot></slot></form>'
})

{'fraction_non_alphanumeric': 0.19374247894103488, 'fraction_numerical': 0.0012033694344163659, 'mean_word_length': 3.661682242990654, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, 'https://': 0, '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': '2387168', 'n_tokens_mistral': 844, 'n_tokens_neox': 832, 'n_words': 170}