<commit_before>goog.provide('modernPaste.paste.ViewController');

goog.require('modernPaste.universal.AlertController');
goog.require('modernPaste.universal.CommonController');
goog.require('modernPaste.universal.URIController');


/**
 * This controller handles loading paste information into the paste view page via an AJAX call.
 *
 * @constructor
 */
modernPaste.paste.ViewController = function() {
    // Metadata
    this.metadata = {
        'deactivationToken': $('#metadata #paste-deactivation-token').data('paste-deactivation-token'),  // User-supplied
        'pasteId': $('#metadata #paste-id').data('paste-id'),
        'showDeactivationLink': $('#metadata #show-deactivate-link').text().toLowerCase() === 'true'
    };

    // Page elements
    this.pasteLoadSplash = $('.paste-load-splash');
    this.spinner = $('.paste-load-splash .spinner');

    // Paste UI elements
    this.rawPasteContents = $('.raw-paste-contents');
    this.pasteTitle = $('.paste-header .paste-title');
    this.pasteLanguage = $('.paste-header .paste-language');
    this.pastePosterUsername = $('.paste-header .paste-poster-username');
    this.pastePostTime = $('.paste-header .paste-post-time');
    this.pasteExpiryTimeContainer = $('.paste-expiry-time-container');
    this.pasteExpiryTime = $('.paste-header .paste-expiry-time');
    this.pasteViews = $('.paste-header .paste-views');
    this.passwordProtectionNotice = $('.password-protected');
    this.pastePasswordField = $('.password-protected .paste-password-field');
    this.passwordSubmitButton = $('.password-protected .password-submit-button');

    // Paste header links
    this.pasteDownloadLink = $('.paste-header .paste-download-link');
    this.pasteDownloadContent = $('.paste-view-container .paste-download-content');
    this.pasteForkContainer = $('.paste-header .paste-fork-container');
    this.pasteDeactivateContainer = $('.paste-header .paste-deactivate-container');
    this.pasteDeactivateLink = $('.paste-header .paste-deactivate-link');

    // Modals
    this.pasteDeactivationModal = $('.deactivate-confirm-modal');

    // Two ways to bring up the paste deactivation modal: either by supplying a deactivation token or being logged in and owning the paste
    if (this.metadata.deactivationToken !== '') {
        modernPaste.paste.ViewController.showModal.bind(this)();
    }
    if (!this.metadata.showDeactivationLink) {
        this.pasteDeactivateContainer.hide();
    }

    modernPaste.paste.ViewController.loadPaste.bind(this)();

    this.passwordSubmitButton.on('click', modernPaste.paste.ViewController.verifyPastePassword.bind(this));
    this.pasteDownloadLink.on('click', modernPaste.paste.ViewController.downloadPasteAsFile.bind(this));
    this.pasteDeactivateLink.on('click', modernPaste.paste.ViewController.showModal.bind(this));
    this.pasteDeactivationModal.find('.deactivate-button').on('click', modernPaste.paste.ViewController.deactivatePaste.bind(this));
    this.pasteDeactivationModal.find('.canel-button').on('click', modernPaste.paste.ViewController.hideModal.bind(this));
};

/**
 * Begin loading the specified paste, then initialize all the UI elements on success or display an error.
 */
modernPaste.paste.ViewController.loadPaste = function() {
    $.ajax({
        'method': 'POST',
        'url': modernPaste.universal.URIController.uris.PasteDetailsURI,
        'contentType': 'application/json',
        'data': JSON.stringify({
            'paste_id': this.metadata.pasteId
        })
    })
    .done(modernPaste.paste.ViewController.initializePasteDetails.bind(this))
    .fail(modernPaste.paste.ViewController.handlePasteLoadFail.bind(this));
};

/**
 * Update all UI elements on the page with the paste details.
 */
modernPaste.paste.ViewController.initializePasteDetails = function(data) {
    this.passwordProtectionNotice.fadeOut('fast');

    this.pasteTitle.text(data.details.title);
    this.pasteLanguage.text(data.details.language.toUpperCase());<commit_msg>Hotfix: password submit button not disabled after success<commit_after>goog.provide('modernPaste.paste.ViewController');

goog.require('modernPaste.universal.AlertController');
goog.require('modernPaste.universal.CommonController');
goog.require('modernPaste.universal.URIController');


/**
 * This controller handles loading paste information into the paste view page via an AJAX call.
 *
 * @constructor
 */
modernPaste.paste.ViewController = function() {
    // Metadata
    this.metadata = {
        'deactivationToken': $('#metadata #paste-deactivation-token').data('paste-deactivation-token'),  // User-supplied
        'pasteId': $('#metadata #paste-id').data('paste-id'),
        'showDeactivationLink': $('#metadata #show-deactivate-link').text().toLowerCase() === 'true'
    };

    // Page elements
    this.pasteLoadSplash = $('.paste-load-splash');
    this.spinner = $('.paste-load-splash .spinner');

    // Paste UI elements
    this.rawPasteContents = $('.raw-paste-contents');
    this.pasteTitle = $('.paste-header .paste-title');
    this.pasteLanguage = $('.paste-header .paste-language');
    this.pastePosterUsername = $('.paste-header .paste-poster-username');
    this.pastePostTime = $('.paste-header .paste-post-time');
    this.pasteExpiryTimeContainer = $('.paste-expiry-time-container');
    this.pasteExpiryTime = $('.paste-header .paste-expiry-time');
    this.pasteViews = $('.paste-header .paste-views');
    this.passwordProtectionNotice = $('.password-protected');
    this.pastePasswordField = $('.password-protected .paste-password-field');
    this.passwordSubmitButton = $('.password-protected .password-submit-button');

    // Paste header links
    this.pasteDownloadLink = $('.paste-header .paste-download-link');
    this.pasteDownloadContent = $('.paste-view-container .paste-download-content');
    this.pasteForkContainer = $('.paste-header .paste-fork-container');
    this.pasteDeactivateContainer = $('.paste-header .paste-deactivate-container');
    this.pasteDeactivateLink = $('.paste-header .paste-deactivate-link');

    // Modals
    this.pasteDeactivationModal = $('.deactivate-confirm-modal');

    // Two ways to bring up the paste deactivation modal: either by supplying a deactivation token or being logged in and owning the paste
    if (this.metadata.deactivationToken !== '') {
        modernPaste.paste.ViewController.showModal.bind(this)();
    }
    if (!this.metadata.showDeactivationLink) {
        this.pasteDeactivateContainer.hide();
    }

    modernPaste.paste.ViewController.loadPaste.bind(this)();

    this.passwordSubmitButton.on('click', modernPaste.paste.ViewController.verifyPastePassword.bind(this));
    this.pasteDownloadLink.on('click', modernPaste.paste.ViewController.downloadPasteAsFile.bind(this));
    this.pasteDeactivateLink.on('click', modernPaste.paste.ViewController.showModal.bind(this));
    this.pasteDeactivationModal.find('.deactivate-button').on('click', modernPaste.paste.ViewController.deactivatePaste.bind(this));
    this.pasteDeactivationModal.find('.canel-button').on('click', modernPaste.paste.ViewController.hideModal.bind(this));
};

/**
 * Begin loading the specified paste, then initialize all the UI elements on success or display an error.
 */
modernPaste.paste.ViewController.loadPaste = function() {
    $.ajax({
        'method': 'POST',
        'url': modernPaste.universal.URIController.uris.PasteDetailsURI,
        'contentType': 'application/json',
        'data': JSON.stringify({
            'paste_id': this.metadata.pasteId
        })
    })
    .done(modernPaste.paste.ViewController.initializePasteDetails.bind(this))
    .fail(modernPaste.paste.ViewController.handlePasteLoadFail.bind(this));
};

/**
 * Update all UI elements on the page with the paste details.
 */
modernPaste.paste.ViewController.initializePasteDetails = function(data) {
    this.passwordSubmitButton.prop('disabled', false);
    this.passwordProtectionNotice.fadeOut('fast');

    this.pasteTitle.text(data.details.title);
    this.pasteLanguage.text(data.details.language.toUpperCase());
{'fraction_non_alphanumeric': 0.15155264134603488, 'fraction_numerical': 0.0, 'mean_word_length': 4.208762886597938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1770441', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2225, 'n_words': 376}