<commit_before>var Contract = Backbone.Model.extend({
    initialize: function(options) {
        this.options = options;
        this.annotationCollection = new MyAnnotationCollection();
        this.searchResultCollection = new SearchResultCollection();
        this.pageModel = new Page({
            id: options.currentPageId,
            pageNumber: options.currentPage || 1,             
            loadUrl: options.textLoadAPI, 
            saveUrl: options.textSaveAPI,
            annotatorjsUrl: options.annotatorjsAPI,
            contractModel: this
        });
        this.pageModel.load();
    },
    getPageModel: function() {
        return this.pageModel;
    },
    getTotalPages: function() {
        return this.options.totalPages;
    },
    canAnnotate: function() {
        return this.options.canAnnotate || false;
    },
    canEdit: function() {
        return this.options.canEdit || false;
    },
    getPaginationEl: function() {
        return this.options.paginationEl;
    },
    getEditorEl: function() {
        return this.options.editorEl
    },
    getPdfviewEl: function() {
        return this.options.pdfviewEl;
    },
    getAnnotatorjsEl: function() {
        return this.options.annotatorjsEl;
    },
    getAnnotationsListEl: function() {
        return this.options.annotationslistEl;
    },
    getMetadataEl: function() {
        return this.options.metadataEl;
    },
    addAnnotation: function(annotation) {
        this.annotationCollection.add(annotation);
    }
});

var Page = Backbone.Model.extend({
    initialize: function(options) {
        this.options = options;
        this.set('isReadOnly', !this.options.contractModel.canEdit());
        this.set('isAnnotable', this.options.contractModel.canAnnotate());
        this.set('pageNumber', this.options.pageNumber);
        return this;
    },
    defaults: function() {
        return {
            pageNumber: 1,
            text: 'Not loaded yet!',
        }
    },
    setPageNumber: function(pageNumber) {
        this.set('pageNumber', pageNumber);
        this.load();
    },
    setSearchTerm: function(searchTerm) {
        this.searchTerm = searchTerm;
    },
    load: function() {
        var that = this;
        $.ajax({
            url: that.options.loadUrl,
            data: 'page=' + that.get('pageNumber'),
            type: 'GET',
            async: false,
            success: function (response) {
                that.set('text', response.text);
                that.set('pdf_url', response.pdf_url);
                if(that.searchTerm) {
                    that.highLightText(that.searchTerm);
                }
                that.trigger('pageChange');
            }
        });
    },
    getPdfLocation: function() {
        console.log(this.get('pdf_url'));
        return "http://{2}/data/{0}/pages/{1}.pdf".format(this.options.contractModel.get('id'), this.get('pageNumber'),'resourcecontracts-demo.elasticbeanstalk.com');
    },
    highLightText: function(searchTerm) {
        var regex = new RegExp(searchTerm, "gi");        
        this.set('text',this.get('text').replace(regex, function(matched) {
                return "<span style='background-color: rgba(80,80,80,0.5);'>" + matched + "</span>";
            })
        );
    }
});

var PageView = Backbone.View.extend({
    initialize: function(options) {
        this.bind('pageTextLoaded', this.pageTextLoaded);        
        this.options = options;
        this.paginationView = options.paginationView || null;
        this.textEditorView = options.textEditorView || null;
        this.pdfView = options.pdfView || null;
        this.annotatorjsView = options.annotatorjsView || null;
        this.annotationsListView = options.annotationsListView || null;
        this.metadataView = options.metadataView || null;
        this.searchFormView = options.searchFormView || null;
        // this.paginationView = new PaginationView({paginationEl: options.contractModel.getPaginationEl(), totalPages: options.contractModel.get('totalPages'), pageModel: options.model});
        // this.textEditorView = new TextEditorView({editorEl: options.contractModel.getEditorEl(), model: options.model});
        // this.annotationList = new AnnotationSideList({el: options.contractModel.getAnnotationListEl(), collection: options.contractModel.annotationCollection, pageModel: options.model}).render();
        // this.listenTo(this.model, 'pageChange', this.pageChange);
        // this.bind('pageChange', this.pageChange);
        return this;
    },
    render: function() {
        if(this.paginationView) this.paginationView.render();<commit_msg>pdf location<commit_after>var Contract = Backbone.Model.extend({
    initialize: function(options) {
        this.options = options;
        this.annotationCollection = new MyAnnotationCollection();
        this.searchResultCollection = new SearchResultCollection();
        this.pageModel = new Page({
            id: options.currentPageId,
            pageNumber: options.currentPage || 1,             
            loadUrl: options.textLoadAPI, 
            saveUrl: options.textSaveAPI,
            annotatorjsUrl: options.annotatorjsAPI,
            contractModel: this
        });
        this.pageModel.load();
    },
    getPageModel: function() {
        return this.pageModel;
    },
    getTotalPages: function() {
        return this.options.totalPages;
    },
    canAnnotate: function() {
        return this.options.canAnnotate || false;
    },
    canEdit: function() {
        return this.options.canEdit || false;
    },
    getPaginationEl: function() {
        return this.options.paginationEl;
    },
    getEditorEl: function() {
        return this.options.editorEl
    },
    getPdfviewEl: function() {
        return this.options.pdfviewEl;
    },
    getAnnotatorjsEl: function() {
        return this.options.annotatorjsEl;
    },
    getAnnotationsListEl: function() {
        return this.options.annotationslistEl;
    },
    getMetadataEl: function() {
        return this.options.metadataEl;
    },
    addAnnotation: function(annotation) {
        this.annotationCollection.add(annotation);
    }
});

var Page = Backbone.Model.extend({
    initialize: function(options) {
        this.options = options;
        this.set('isReadOnly', !this.options.contractModel.canEdit());
        this.set('isAnnotable', this.options.contractModel.canAnnotate());
        this.set('pageNumber', this.options.pageNumber);
        return this;
    },
    defaults: function() {
        return {
            pageNumber: 1,
            text: 'Not loaded yet!',
        }
    },
    setPageNumber: function(pageNumber) {
        this.set('pageNumber', pageNumber);
        this.load();
    },
    setSearchTerm: function(searchTerm) {
        this.searchTerm = searchTerm;
    },
    load: function() {
        var that = this;
        $.ajax({
            url: that.options.loadUrl,
            data: 'page=' + that.get('pageNumber'),
            type: 'GET',
            async: false,
            success: function (response) {
                that.set('text', response.text);
                that.set('pdf_url', response.pdf_url);
                if(that.searchTerm) {
                    that.highLightText(that.searchTerm);
                }
                that.trigger('pageChange');
            }
        });
    },
    getPdfLocation: function() {
        return this.get('pdf_url');
    },
    highLightText: function(searchTerm) {
        var regex = new RegExp(searchTerm, "gi");        
        this.set('text',this.get('text').replace(regex, function(matched) {
                return "<span style='background-color: rgba(80,80,80,0.5);'>" + matched + "</span>";
            })
        );
    }
});

var PageView = Backbone.View.extend({
    initialize: function(options) {
        this.bind('pageTextLoaded', this.pageTextLoaded);        
        this.options = options;
        this.paginationView = options.paginationView || null;
        this.textEditorView = options.textEditorView || null;
        this.pdfView = options.pdfView || null;
        this.annotatorjsView = options.annotatorjsView || null;
        this.annotationsListView = options.annotationsListView || null;
        this.metadataView = options.metadataView || null;
        this.searchFormView = options.searchFormView || null;
        // this.paginationView = new PaginationView({paginationEl: options.contractModel.getPaginationEl(), totalPages: options.contractModel.get('totalPages'), pageModel: options.model});
        // this.textEditorView = new TextEditorView({editorEl: options.contractModel.getEditorEl(), model: options.model});
        // this.annotationList = new AnnotationSideList({el: options.contractModel.getAnnotationListEl(), collection: options.contractModel.annotationCollection, pageModel: options.model}).render();
        // this.listenTo(this.model, 'pageChange', this.pageChange);
        // this.bind('pageChange', this.pageChange);
        return this;
    },
    render: function() {
        if(this.paginationView) this.paginationView.render();
{'fraction_non_alphanumeric': 0.12757562472599737, 'fraction_numerical': 0.002520824199912319, 'mean_word_length': 2.4099402092675635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5685715', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2472, 'n_words': 432}