<commit_before><nav class="navbar navbar-inverse navbar-fixed-bottom">
    <div id="controlbar" class="navbar-inner">
        <div class="container-fluid">
            <ul class="nav">
                <li class="autosave"><a href="#"><i class="icon-white icon-ok-circle"></i><i class="icon-white icon-ban-circle"></i> Autosave</a></li>
                <li><button id="save-all" class="btn btn-inverse">{{#trhtml 'label.saveall'}}Save all{{/trhtml}}</button></li>
            </ul>
        </div>
    </div>
</nav>
<div id="content" class="container-fluid">
    <div class="row-fluid">
        <div class="span3">
        </div>
        <div class="span5">
            <div class="row-fluid">
                <div id="record-list">
                </div>
            </div>
            <div class="row-fluid">
                <div>
                    <textarea id="record-entry"></textarea>
                </div>
            </div>
        </div>
        <div id="record-selector" class="span4">
        </div>
    </div>
</div>

{{#contentFor 'styles'}}
    <link href="/css/fields.css" media="all" type="text/css" rel="stylesheet">
{{/contentFor}}

{{#contentFor 'javascript'}}
    <script src="/lib/js/isbn.js"></script>
    <script type="text/javascript">
        var searching = { };
        $(document).ready(function () {
            $('body').addClass('autosave-enabled');
            $.ajax({
                type: "GET",
                url: "/views/partials/z3950preview.handlebars"
            }).done(function (template) {
                environment.renderer.register('marc21', template);
            });
            $('.autosave a').on('click', function (ev) {
                $('body').toggleClass('autosave-enabled');
                ev.preventDefault();
            });
            $('#record-entry').on('keydown', function (ev) {
                var self = this;
                if (ev.keyCode === 13) {
                    var lines = self.value.substring(0, self.selectionStart).split('\n');
                    var remainder = '';
                    var sections = [ ];
                    lines.forEach(function (line) {
                        if (line.substring(0,1) === '*') {
                            if (!searching[line.substring(1)]) {
                                searching[line.substring(1)] = true
                                search(line);
                            }
                            remainder += line + '\n';
                        } else {
                            sections.push(line);
                        }
                    });
                    if (self.value.substr(self.selectionStart-1, 1) === '\n') {
                        self.value = remainder + self.value.substring(self.selectionStart);
                        var rendered = '<article><header>' + sections[0] + '</header>';
                        for (var ii = 1; ii < sections.length - 1; ii++) {
                            rendered += '<section>' + sections[ii] + '</section>';
                        }
                        rendered += '</article>';
                        addRecord(null, rendered);
                        ev.preventDefault();
                    }
                }
            });
            $('body').on('keydown', '#recordlist [contenteditable="true"]', null, function (ev) {
                $(this).parents('.recordContainer').removeClass('saved');
            });
            $('body').on('click', 'button.select-bulk', null, function (ev) {
                var term = this.parentNode.getAttribute('data-key');
                var optlists = document.querySelectorAll('bulk-options');
                for (var ii = 0; ii < optlists.length; ii++) {
                    optlists[ii].style.display = 'none';
                }
                document.querySelector('.bulk-options[data-key="' + term + '"]').style.display = 'block';
            });
            $('body').on('click', 'button.choose-record', null, function (ev) {
                var term = this.parentNode.parentNode.getAttribute('data-key');
                var entrylist = document.querySelector('#record-list .recordContainer[data-key="' + term + '"]');
                entrylist.innerHTML = '<button class="remove-record btn btn-link">&times;</button><h4 class="record-key">' + term + '</h4><article>' + this.parentNode.querySelector('article').innerHTML + '</article><button class="btn save-bulk">Save</button>';

                this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
            });
            $('body').on('click', 'button.remove-record', null, function (ev) {
                this.parentNode.parentNode.removeChild(this.parentNode);
            });
            $('body').on('click', 'button.save-bulk', null, function (ev) {
                var container = this.parentNode;
                $.ajax({
                    type: "POST",
                    url: "/record/" + (container.getAttribute('data-id') ? encodeURIComponent(container.getAttribute('data-id')) : 'new'),
                    dataType: "json",
                    data: { data: JSON.stringify(window.formatters.bnjson.decompile(container.querySelector('article'))),
                            key: container.querySelector('.record-key').textContent
                          },
                }).done(function(msg) {
                    container.setAttribute('data-id', msg.id);
                    container.className = 'recordContainer saved';
                });
            });
            $('#save-all').click(saveAll);
        });

        function makeEditable(el) {
            var editable = el.querySelectorAll('.record-key, header, section');
            for (var ii = 0; ii < editable.length; ii++) {
                editable[ii].contentEditable = true;
            }
        }

        function search(term) {
            if (term.substring(0,1) === '*') term = term.substring(1);
            var original = term;
            term = term.trim();
            var ta = document.querySelector('#record-entry');
            if (term.length === 0) return;
            var query;
            var isbn = ISBN.parse(term), lccn = /^([0-9]{2}|[0-9]{4})-([0-9]{0,6})$/;
            if (isbn) {
                query = '@or @attr 1=7 "' + isbn.asIsbn13() + '" @attr 1=7 "' + isbn.asIsbn10() + '"';
            } else if ((lccn = lccn.exec(term))) {
                query = '@attr 1=9 "' + lccn[1];
                for (var ii = 6; ii > lccn[2].length; ii--) {
                    query += '0';
                }
                query += lccn[2] + '"';
            } else {
                query = '@attr 1=1016 "' + term +'"';
            }
            $.ajax({
                type: "GET",
                url: "/cataloging/copy",
                dataType: "json",
                data: {
                    q: encodeURIComponent(query)
                }
            }).done(function (res) {
                var records = [ ];
                res.records.forEach(function (rec) {
                    records.push(new models.Record({ data: rec, format: res.format }));
                });
                if (records.length === 0) {
                    addRecord(term, 'Unable to find record for "' + term + '"', true);
                } else if (records.length === 1) {
                    addRecord(term, records[0].render());
                } else {
                    addRecord(term, '<span>Multiple records matched your search.</span><button class="btn select-bulk">Select</button>', true);
                    var options = document.createElement('div');
                    options.className = 'bulk-options';
                    options.setAttribute('data-key', term);
                    options.innerHTML = '<h4>' + term + '</h4>';
                    options.style.display = 'none';
                    records.forEach(function (rec) {
                        var opt = document.createElement('div');
                        opt.className = 'recordContainer';
                        opt.innerHTML = rec.render() + '<button class="btn choose-record">Choose</button><button class="btn remove-record">Remove</button>';
                        options.appendChild(opt);
                    });
                    document.getElementById('record-selector').appendChild(options);
                }
                if (records.length > 0) {
                    var oldstart = ta.selectionStart;
                    var oldend = ta.selectionEnd;
                    ta.value = ta.value.replace('*' + original + '\n', '');
                    ta.selectionStart = oldstart - original.length - 2;
                    ta.selectionEnd = oldend - original.length - 2;
                }
            });
        }

        function addRecord(key, rendered, controlsincluded) {
            var listentry = document.createElement('div');
            listentry.className = 'recordContainer';
            listentry.setAttribute('data-key', key);
            var html = '<button class="remove-record btn btn-link">&times;</button>';
            if (key) html += '<h4 class="record-key">' + key + '</h4>';
            html += rendered;
            if (!controlsincluded) html += '<button class="btn save-bulk">Save</button>';
            listentry.innerHTML = html;
            makeEditable(listentry);
            document.getElementById('record-list').appendChild(listentry);
            if ($('body').hasClass('autosave-enabled')) saveAll();
        }

        function saveAll() {
            var buttons = document.querySelectorAll('.recordContainer:not(.saved) .save-bulk');
            for (var ii = 0; ii < buttons.length; ii++) {
                $(buttons[ii]).click()
            }
        }

        var fieldlist = {
            {{#each fields}}
                "{{schema}}_{{name}}": {<commit_msg>Save every minute when autosave is enabled on bulk entry<commit_after><nav class="navbar navbar-inverse navbar-fixed-bottom">
    <div id="controlbar" class="navbar-inner">
        <div class="container-fluid">
            <ul class="nav">
                <li class="autosave"><a href="#"><i class="icon-white icon-ok-circle"></i><i class="icon-white icon-ban-circle"></i> Autosave</a></li>
                <li><button id="save-all" class="btn btn-inverse">{{#trhtml 'label.saveall'}}Save all{{/trhtml}}</button></li>
            </ul>
        </div>
    </div>
</nav>
<div id="content" class="container-fluid">
    <div class="row-fluid">
        <div class="span3">
        </div>
        <div class="span5">
            <div class="row-fluid">
                <div id="record-list">
                </div>
            </div>
            <div class="row-fluid">
                <div>
                    <textarea id="record-entry"></textarea>
                </div>
            </div>
        </div>
        <div id="record-selector" class="span4">
        </div>
    </div>
</div>

{{#contentFor 'styles'}}
    <link href="/css/fields.css" media="all" type="text/css" rel="stylesheet">
{{/contentFor}}

{{#contentFor 'javascript'}}
    <script src="/lib/js/isbn.js"></script>
    <script type="text/javascript">
        var searching = { };
        $(document).ready(function () {
            $('body').addClass('autosave-enabled');
            $.ajax({
                type: "GET",
                url: "/views/partials/z3950preview.handlebars"
            }).done(function (template) {
                environment.renderer.register('marc21', template);
            });
            $('.autosave a').on('click', function (ev) {
                $('body').toggleClass('autosave-enabled');
                ev.preventDefault();
            });
            $('#record-entry').on('keydown', function (ev) {
                var self = this;
                if (ev.keyCode === 13) {
                    var lines = self.value.substring(0, self.selectionStart).split('\n');
                    var remainder = '';
                    var sections = [ ];
                    lines.forEach(function (line) {
                        if (line.substring(0,1) === '*') {
                            if (!searching[line.substring(1)]) {
                                searching[line.substring(1)] = true
                                search(line);
                            }
                            remainder += line + '\n';
                        } else {
                            sections.push(line);
                        }
                    });
                    if (self.value.substr(self.selectionStart-1, 1) === '\n') {
                        self.value = remainder + self.value.substring(self.selectionStart);
                        var rendered = '<article><header>' + sections[0] + '</header>';
                        for (var ii = 1; ii < sections.length - 1; ii++) {
                            rendered += '<section>' + sections[ii] + '</section>';
                        }
                        rendered += '</article>';
                        addRecord(null, rendered);
                        ev.preventDefault();
                    }
                }
            });
            $('body').on('keydown', '#record-list [contenteditable="true"]', null, function (ev) {
                $(this).parents('.recordContainer').removeClass('saved');
            });
            $('body').on('click', 'button.select-bulk', null, function (ev) {
                var term = this.parentNode.getAttribute('data-key');
                var optlists = document.querySelectorAll('bulk-options');
                for (var ii = 0; ii < optlists.length; ii++) {
                    optlists[ii].style.display = 'none';
                }
                document.querySelector('.bulk-options[data-key="' + term + '"]').style.display = 'block';
            });
            $('body').on('click', 'button.choose-record', null, function (ev) {
                var term = this.parentNode.parentNode.getAttribute('data-key');
                var entrylist = document.querySelector('#record-list .recordContainer[data-key="' + term + '"]');
                entrylist.innerHTML = '<button class="remove-record btn btn-link">&times;</button><h4 class="record-key">' + term + '</h4><article>' + this.parentNode.querySelector('article').innerHTML + '</article><button class="btn save-bulk">Save</button>';

                this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
                if ($('body').hasClass('autosave-enabled')) saveAll();
            });
            $('body').on('click', 'button.remove-record', null, function (ev) {
                this.parentNode.parentNode.removeChild(this.parentNode);
            });
            $('body').on('click', 'button.save-bulk', null, function (ev) {
                var container = this.parentNode;
                $.ajax({
                    type: "POST",
                    url: "/record/" + (container.getAttribute('data-id') ? encodeURIComponent(container.getAttribute('data-id')) : 'new'),
                    dataType: "json",
                    data: { data: JSON.stringify(window.formatters.bnjson.decompile(container.querySelector('article'))),
                            key: container.querySelector('.record-key').textContent
                          },
                }).done(function(msg) {
                    container.setAttribute('data-id', msg.id);
                    container.className = 'recordContainer saved';
                });
            });
            $('#save-all').click(saveAll);
        });

        function makeEditable(el) {
            var editable = el.querySelectorAll('.record-key, header, section');
            for (var ii = 0; ii < editable.length; ii++) {
                editable[ii].contentEditable = true;
            }
        }

        function search(term) {
            if (term.substring(0,1) === '*') term = term.substring(1);
            var original = term;
            term = term.trim();
            var ta = document.querySelector('#record-entry');
            if (term.length === 0) return;
            var query;
            var isbn = ISBN.parse(term), lccn = /^([0-9]{2}|[0-9]{4})-([0-9]{0,6})$/;
            if (isbn) {
                query = '@or @attr 1=7 "' + isbn.asIsbn13() + '" @attr 1=7 "' + isbn.asIsbn10() + '"';
            } else if ((lccn = lccn.exec(term))) {
                query = '@attr 1=9 "' + lccn[1];
                for (var ii = 6; ii > lccn[2].length; ii--) {
                    query += '0';
                }
                query += lccn[2] + '"';
            } else {
                query = '@attr 1=1016 "' + term +'"';
            }
            $.ajax({
                type: "GET",
                url: "/cataloging/copy",
                dataType: "json",
                data: {
                    q: encodeURIComponent(query)
                }
            }).done(function (res) {
                var records = [ ];
                res.records.forEach(function (rec) {
                    records.push(new models.Record({ data: rec, format: res.format }));
                });
                if (records.length === 0) {
                    addRecord(term, 'Unable to find record for "' + term + '"', true);
                } else if (records.length === 1) {
                    addRecord(term, records[0].render());
                } else {
                    addRecord(term, '<span>Multiple records matched your search.</span><button class="btn select-bulk">Select</button>', true);
                    var options = document.createElement('div');
                    options.className = 'bulk-options';
                    options.setAttribute('data-key', term);
                    options.innerHTML = '<h4>' + term + '</h4>';
                    options.style.display = 'none';
                    records.forEach(function (rec) {
                        var opt = document.createElement('div');
                        opt.className = 'recordContainer';
                        opt.innerHTML = rec.render() + '<button class="btn choose-record">Choose</button><button class="btn remove-record">Remove</button>';
                        options.appendChild(opt);
                    });
                    document.getElementById('record-selector').appendChild(options);
                }
                if (records.length > 0) {
                    var oldstart = ta.selectionStart;
                    var oldend = ta.selectionEnd;
                    ta.value = ta.value.replace('*' + original + '\n', '');
                    ta.selectionStart = oldstart - original.length - 2;
                    ta.selectionEnd = oldend - original.length - 2;
                }
            });
        }

        function addRecord(key, rendered, controlsincluded) {
            var listentry = document.createElement('div');
            listentry.className = 'recordContainer';
            listentry.setAttribute('data-key', key);
            var html = '<button class="remove-record btn btn-link">&times;</button>';
            if (key) html += '<h4 class="record-key">' + key + '</h4>';
            html += rendered;
            if (!controlsincluded) html += '<button class="btn save-bulk">Save</button>';
            listentry.innerHTML = html;
            makeEditable(listentry);
            document.getElementById('record-list').appendChild(listentry);
            if ($('body').hasClass('autosave-enabled')) saveAll();
        }

        var autosaveTimeout;
        function saveAll() {
            if (autosaveTimeout) clearTimeout(autosaveTimeout)
            delete autosaveTimeout;
            var buttons = document.querySelectorAll('.recordContainer:not(.saved) .save-bulk');
            for (var ii = 0; ii < buttons.length; ii++) {
                $(buttons[ii]).click()
            }
            if ($('body').hasClass('autosave-enabled')) autosaveTimeout = setTimeout(saveAll, 60000);
        }

        var fieldlist = {
            {{#each fields}}
                "{{schema}}_{{name}}": {
{'fraction_non_alphanumeric': 0.15888130016451468, 'fraction_numerical': 0.007228675407547734, 'mean_word_length': 1.5065600399850057, 'pattern_counts': {'":': 2, '<': 159, '<?xml version=': 0, '>': 155, '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': '4312633', 'n_tokens_mistral': 5301, 'n_tokens_neox': 5080, 'n_words': 978}