<commit_before>/**
    FeedbackForm activity
**/
'use strict';

var Activity = require('../components/Activity'),
    VocElementEnum = require('../models/VocElementEnum');

var A = Activity.extend(function FeedbackFormActivity() {
    
    Activity.apply(this, arguments);
    
    this.viewModel = new ViewModel(this.app);
    
    this.accessLevel = null;
    
    var serviceProfessionalNavBar = Activity.createSubsectionNavBar('Back', {
        helpLink: this.viewModel.helpLinkProfessionals
    });
    this.serviceProfessionalNavBar = serviceProfessionalNavBar.model.toPlainObject(true);
    var clientNavBar = Activity.createSubsectionNavBar('Back', {
        helpLink: this.viewModel.helpLinkClients
    });
    this.clientNavBar = serviceProfessionalNavBar.model.toPlainObject(true);
    this.navBar = this.viewModel.user.isServiceProfessional() ? serviceProfessionalNavBar : clientNavBar;
});

exports.init = A.init;

A.prototype.show = function show(options) {
    //jshint maxcomplexity:10
    Activity.prototype.show.call(this, options);

    var params = this.requestData.route.segments || [];
    var elementName = params[0] || '',
        elementID = VocElementEnum[elementName] |0;

    this.viewModel.message(this.requestData.route.query.body || this.requestData.route.query.message || '');
    
    if (!elementName) {
        console.log('Feedback Ideas: Accessing feedback without specify an element, using General (0)');
    }
    else if (!VocElementEnum.hasOwnProperty(elementName)) {
        console.error('Feedback Ideas: given a bad VOC Element name:', elementName);
    }

    this.viewModel.vocElementID(elementID);
};

var ko = require('knockout');
function ViewModel(app) {
    this.helpLinkProfessionals = '/help/relatedArticles/201960863-providing-feedback-to-us';
    this.helpLinkClients = '/help/relatedArticles/202894686-providing-feedback-to-us';
    
    this.message = ko.observable('');
    this.becomeCollaborator = ko.observable(false);
    // Get reference to know if is already a collaborator
    this.isCollaborator = app.model.userProfile.data.isCollaborator;
    this.isSending = ko.observable(false);
    this.vocElementID = ko.observable(0);
    this.emailSubject = ko.observable('');

    this.submitText = ko.pureComputed(function() {
        return this.isSending() ? 'Sending..' : 'Send';
    }, this);
    
    this.isValid = ko.pureComputed(function() {
        var m = this.message();
        return m && !/^\s*$/.test(m);
    }, this);

    this.anonymousButtonUrl = ko.pureComputed(function() {
        if (!app.model.user().isAnonymous()) return '';

        var subject = encodeURIComponent('Feedback');
        var body = encodeURIComponent(this.message());
        var url = 'mailto:<EMAIL>?subject=' + subject + '&body=' + body;
        return url;
    }, this);

    this.send = function send() {
        // Check is valid, and do nothing if not
        if (!this.isValid() || app.model.user().isAnonymous()) {
            return;
        }
        this.isSending(true);
        app.model.feedback.postIdea({
            message: this.message(),
            becomeCollaborator: this.becomeCollaborator(),
            vocElementID: this.vocElementID()
        })
        .then(function() {
            // Update local profile in case marked becameCollaborator and was not already
            if (!this.isCollaborator() && this.becomeCollaborator()) {
                // Tag locally already
                this.isCollaborator(true);
                // But ask the profile to update, by request a 'save' even if
                // will not save the flag but will get it updated from database and will cache it
                app.model.userProfile.save();
            }
            // Success
            app.successSave({
                message: 'Sent! Thank you for your input.'
            });
            // Reset after being sent
            this.message('');
            this.becomeCollaborator(false);
        }.bind(this))
        .catch(function(err) {
            app.modals.showError({
                title: 'There was an error sending your feedback',
                error: err
            });
        })
        .then(function() {
            // Always
            this.isSending(false);
        }.bind(this));
    }.bind(this);
}
<commit_msg>Fixed /feedbackForm helpLinks<commit_after>/**
    FeedbackForm activity
**/
'use strict';

var Activity = require('../components/Activity'),
    VocElementEnum = require('../models/VocElementEnum');

var A = Activity.extend(function FeedbackFormActivity() {
    
    Activity.apply(this, arguments);
    
    this.viewModel = new ViewModel(this.app);
    
    this.accessLevel = null;
    
    var serviceProfessionalNavBar = Activity.createSubsectionNavBar('Back', {
        helpLink: this.viewModel.helpLinkProfessionals
    });
    this.serviceProfessionalNavBar = serviceProfessionalNavBar.model.toPlainObject(true);
    var clientNavBar = Activity.createSubsectionNavBar('Back', {
        helpLink: this.viewModel.helpLinkClients
    });
    this.clientNavBar = serviceProfessionalNavBar.model.toPlainObject(true);
    this.navBar = this.viewModel.user.isServiceProfessional() ? serviceProfessionalNavBar : clientNavBar;
});

exports.init = A.init;

A.prototype.show = function show(options) {
    //jshint maxcomplexity:10
    Activity.prototype.show.call(this, options);

    var params = this.requestData.route.segments || [];
    var elementName = params[0] || '',
        elementID = VocElementEnum[elementName] |0;

    this.viewModel.message(this.requestData.route.query.body || this.requestData.route.query.message || '');
    
    if (!elementName) {
        console.log('Feedback Ideas: Accessing feedback without specify an element, using General (0)');
    }
    else if (!VocElementEnum.hasOwnProperty(elementName)) {
        console.error('Feedback Ideas: given a bad VOC Element name:', elementName);
    }

    this.viewModel.vocElementID(elementID);
};

var ko = require('knockout');
function ViewModel(app) {
    
    this.user = app.model.userProfile.data;
    this.helpLinkProfessionals = '/help/relatedArticles/201960863-providing-feedback-to-us';
    this.helpLinkClients = '/help/relatedArticles/202894686-providing-feedback-to-us';
    this.helpLink = ko.pureComputed(function() {
        return this.user.isServiceProfessional() ? this.helpLinkProfessionals : this.helpLinkClients ;
    }, this);
    this.helpLink = '/help/relatedArticles/201960863-providing-feedback-to-us';
    this.message = ko.observable('');
    this.becomeCollaborator = ko.observable(false);
    // Get reference to know if is already a collaborator
    this.isCollaborator = app.model.userProfile.data.isCollaborator;
    this.isSending = ko.observable(false);
    this.vocElementID = ko.observable(0);
    this.emailSubject = ko.observable('');

    this.submitText = ko.pureComputed(function() {
        return this.isSending() ? 'Sending..' : 'Send';
    }, this);
    
    this.isValid = ko.pureComputed(function() {
        var m = this.message();
        return m && !/^\s*$/.test(m);
    }, this);

    this.anonymousButtonUrl = ko.pureComputed(function() {
        if (!app.model.user().isAnonymous()) return '';

        var subject = encodeURIComponent('Feedback');
        var body = encodeURIComponent(this.message());
        var url = 'mailto:<EMAIL>?subject=' + subject + '&body=' + body;
        return url;
    }, this);

    this.send = function send() {
        // Check is valid, and do nothing if not
        if (!this.isValid() || app.model.user().isAnonymous()) {
            return;
        }
        this.isSending(true);
        app.model.feedback.postIdea({
            message: this.message(),
            becomeCollaborator: this.becomeCollaborator(),
            vocElementID: this.vocElementID()
        })
        .then(function() {
            // Update local profile in case marked becameCollaborator and was not already
            if (!this.isCollaborator() && this.becomeCollaborator()) {
                // Tag locally already
                this.isCollaborator(true);
                // But ask the profile to update, by request a 'save' even if
                // will not save the flag but will get it updated from database and will cache it
                app.model.userProfile.save();
            }
            // Success
            app.successSave({
                message: 'Sent! Thank you for your input.'
            });
            // Reset after being sent
            this.message('');
            this.becomeCollaborator(false);
        }.bind(this))
        .catch(function(err) {
            app.modals.showError({
                title: 'There was an error sending your feedback',
                error: err
            });
        })
        .then(function() {
            // Always
            this.isSending(false);
        }.bind(this));
    }.bind(this);
}

{'fraction_non_alphanumeric': 0.12706750111756818, 'fraction_numerical': 0.006370138578453285, 'mean_word_length': 2.521841794569067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4541240', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2523, 'n_words': 523}