<commit_before>/*global
 define
 */
/*jslint
 browser: true,
 white: true
 */
define([
    'kb/common/html',
    'jquery',
    'bluebird',
    'kb_plugin_login'
],
function (html, $, Promise, Plugin) {
    'use strict';

    var panelId = html.genId();

    function EventMan() {
        var events = [];
        function add(type, handler, data) {
            var id = html.genId();
            events.push({
                type: type,
                selector: '#' + id,
                handler: handler,
                data: data
            });
            return id;
        }
        function attachEvents($container) {
            events.forEach(function (event) {
                $container.on(event.type, event.selector, event.data, event.handler);
            });
        }
        function reset($container) {
            events.forEach(function (event) {
                if (event.listener) {
                    $container.off(event.type, event.selector);
                }
            });
            events = [];
        }
        return {
            add: add,
            attach: attachEvents,
            reset: reset
        };
    }

    function widget(config) {
        var mount, container, $container, runtime = config.runtime,
            nextRequest;

        // This should be somewhere else, and handle all types of fields
        // I'm sure we've done this already.
        function getFieldValue(name) {
            var field = $(container).find(' form [name="' + name + '"]');
            if (field) {
                return field.val();
            }
        }
        function node(selector) {
            return $(container).find(selector);
        }
        function element(name) {
            return node('[data-element="' + name + '"]');
        }

        function handleLogin(e) {
            e.preventDefault();

            // TODO: add support for nextPath, nextURL

            var username = getFieldValue('username'),
                    password = getFieldValue('password');

            if (!username) {
                element('error').html('The username is required').show();
                return;
            }
            if (!password) {
                element('error').html('The password is required').show();
                return;
            }

            element('error').hide();
            element('sign-in').hide();
            element('signing-in').show();
            runtime.send('ui', 'setTitle', 'Signing in ...');
            runtime.getService('session').login({
                username: username,
                password: password
            })
                    .then(function () {
                        runtime.send('ui', 'setTitle', 'Successful Sign In!');
                        runtime.send('app', 'loggedin');
                        /* TODO should be configurable default login location */
                        if (nextRequest) {
                            runtime.send('app', 'navigate', nextRequest);
                        } else {
                            runtime.send('app', 'navigate', '');
                        }
                    })
                    .catch(function (errorMsg) {
                        runtime.send('ui', 'setTitle', 'Sign In Error');
                        element('running').hide();
                        if (errorMsg === "LoginFailure: Authentication failed.") {
                            errorMsg = "Login Failed: your username/password is incorrect.";
                        }
                        element('error').html(errorMsg).show();
                        element('sign-in').show();
                        element('signing-in').hide();
                    })
                    .done();
        }

        var eventMan = EventMan();

        function renderForm() {
            var form = html.tag('form'),
                    input = html.tag('input'),
                    button = html.tag('button'),
                    div = html.tag('div'),
                    p = html.tag('p'),
                    h1 = html.tag('h1'),
                    legend = html.tag('legend'),
                    i = html.tag('i'),
                    a = html.tag('a');

            /* TODO: use the actual next path */
            // Variables for form.
            var nextPath = 'next path',
                    nextURL = 'next url';

            eventMan.reset();
            var doodlePath = Plugin.plugin.fullPath + '/doodle.png';

            return div({class: 'container', style: 'margin-top: 4em', id: panelId}, [
                div({}, [
                    div({style: {
                            position: 'absolute',
                            backgroundImage: 'url(' + doodlePath + ')',
                            backgroundRepeat: 'no-repeat',
                            backgroundSize: '35%',
                            top: '0',
                            left: '0',
                            bottom: '0',
                            right: '0',
                            opacity: '0.1',
                            zIndex: '-1000'
                        }})
                ]),
                div({class: 'row'}, [
                    div({class: 'col-sm-7 col-sm-offset-1'}, [
                        h1({style: 'font-size:1.6em'}, ['Welcome to the KBase Narrative Interface']),
                        p('After signing in you can upload your own experimental data or find data integrated from external resources or shared by other users. You can then perform, organize, and share sophisticated comparative genomics and systems biology analyses by creating Narratives.'),
                        p('Narratives are user-created interactive, dynamic, and shareable documents that are KBase’s way of making systems biology research transparent, reproducible, and reusable.'),
                        p('The Narrative Interface lets you customize and execute a set of ordered KBase analyses to create your own Narratives that include your analysis steps, commentary, visualizations, and custom scripts.'),
                        p([
                            'Want to learn more? We have an extensive and growing ', 
                            a({href: [runtime.config('resources.docSite.base.url'), 'tutorials'].join('/')}, 'library of tutorials') ,
                            ' that show you how to use KBase’s new apps to analyze your data.'
                        ]),
                        p([
                            'To become familiar with the user interface, try the ', 
                            a({href: [runtime.config('resources.docSite.base.url'), 'narrative-guide'].join('/')}, 'Narrative Interface User Guide'), 
                            ' or the <a href="https://youtu.be/6ql7HAUzU7U">Narrative Interface video tutorial</a>.'
                        ])
                    ]),
                    div({class: 'col-sm-3'}, [
                        div({class: 'well well-kbase'}, [
                            form({class: 'form login-form', id: eventMan.add('submit', handleLogin)}, [
                                input({type: 'hidden', value: nextPath}),
                                input({type: 'hidden', value: nextURL}),
                                legend({style: 'text-align: center'}, 'KBase Sign In'),<commit_msg>update language and app link on login form<commit_after>/*global
 define
 */
/*jslint
 browser: true,
 white: true
 */
define([
    'kb/common/html',
    'jquery',
    'bluebird',
    'kb_plugin_login'
],
function (html, $, Promise, Plugin) {
    'use strict';

    var panelId = html.genId();

    function EventMan() {
        var events = [];
        function add(type, handler, data) {
            var id = html.genId();
            events.push({
                type: type,
                selector: '#' + id,
                handler: handler,
                data: data
            });
            return id;
        }
        function attachEvents($container) {
            events.forEach(function (event) {
                $container.on(event.type, event.selector, event.data, event.handler);
            });
        }
        function reset($container) {
            events.forEach(function (event) {
                if (event.listener) {
                    $container.off(event.type, event.selector);
                }
            });
            events = [];
        }
        return {
            add: add,
            attach: attachEvents,
            reset: reset
        };
    }

    function widget(config) {
        var mount, container, $container, runtime = config.runtime,
            nextRequest;

        // This should be somewhere else, and handle all types of fields
        // I'm sure we've done this already.
        function getFieldValue(name) {
            var field = $(container).find(' form [name="' + name + '"]');
            if (field) {
                return field.val();
            }
        }
        function node(selector) {
            return $(container).find(selector);
        }
        function element(name) {
            return node('[data-element="' + name + '"]');
        }

        function handleLogin(e) {
            e.preventDefault();

            // TODO: add support for nextPath, nextURL

            var username = getFieldValue('username'),
                    password = getFieldValue('password');

            if (!username) {
                element('error').html('The username is required').show();
                return;
            }
            if (!password) {
                element('error').html('The password is required').show();
                return;
            }

            element('error').hide();
            element('sign-in').hide();
            element('signing-in').show();
            runtime.send('ui', 'setTitle', 'Signing in ...');
            runtime.getService('session').login({
                username: username,
                password: password
            })
                    .then(function () {
                        runtime.send('ui', 'setTitle', 'Successful Sign In!');
                        runtime.send('app', 'loggedin');
                        /* TODO should be configurable default login location */
                        if (nextRequest) {
                            runtime.send('app', 'navigate', nextRequest);
                        } else {
                            runtime.send('app', 'navigate', '');
                        }
                    })
                    .catch(function (errorMsg) {
                        runtime.send('ui', 'setTitle', 'Sign In Error');
                        element('running').hide();
                        if (errorMsg === "LoginFailure: Authentication failed.") {
                            errorMsg = "Login Failed: your username/password is incorrect.";
                        }
                        element('error').html(errorMsg).show();
                        element('sign-in').show();
                        element('signing-in').hide();
                    })
                    .done();
        }

        var eventMan = EventMan();

        function renderForm() {
            var form = html.tag('form'),
                    input = html.tag('input'),
                    button = html.tag('button'),
                    div = html.tag('div'),
                    p = html.tag('p'),
                    h1 = html.tag('h1'),
                    legend = html.tag('legend'),
                    i = html.tag('i'),
                    a = html.tag('a');

            /* TODO: use the actual next path */
            // Variables for form.
            var nextPath = 'next path',
                    nextURL = 'next url';

            eventMan.reset();
            var doodlePath = Plugin.plugin.fullPath + '/doodle.png';

            return div({class: 'container', style: 'margin-top: 4em', id: panelId}, [
                div({}, [
                    div({style: {
                            position: 'absolute',
                            backgroundImage: 'url(' + doodlePath + ')',
                            backgroundRepeat: 'no-repeat',
                            backgroundSize: '35%',
                            top: '0',
                            left: '0',
                            bottom: '0',
                            right: '0',
                            opacity: '0.1',
                            zIndex: '-1000'
                        }})
                ]),
                div({class: 'row'}, [
                    div({class: 'col-sm-7 col-sm-offset-1'}, [
                        h1({style: 'font-size:1.6em'}, ['Welcome to the KBase Narrative Interface']),
                        p('After signing in you can upload your own experimental data or find data integrated from external resources or shared by other users. You can then perform, organize, and share sophisticated comparative genomics and systems biology analyses by creating Narratives.'),
                        p('Narratives are user-created interactive, dynamic, and shareable documents that are KBase’s way of making systems biology research transparent, reproducible, and reusable.'),
                        p([
                            'The Narrative Interface lets you customize and execute a set of ordered ',
                            a({href: [runtime.config('resources.docSite.base.url'), 'apps'].join('/')}, 'KBase apps'),
                            ' to create your own Narratives that include your analysis steps, commentary, visualizations, and custom scripts.'
                        ]),
                        p([
                            'Want to learn more? We have an extensive and growing ', 
                            a({href: [runtime.config('resources.docSite.base.url'), 'tutorials'].join('/')}, 'library of tutorials') ,
                            ' that show you how to use KBase apps to analyze your data.'
                        ]),
                        p([
                            'To become familiar with the user interface, try the ', 
                            a({href: [runtime.config('resources.docSite.base.url'), 'narrative-guide'].join('/')}, 'Narrative Interface User Guide'), 
                            ' or the <a href="https://youtu.be/6ql7HAUzU7U">Narrative Interface video tutorial</a>.'
                        ])
                    ]),
                    div({class: 'col-sm-3'}, [
                        div({class: 'well well-kbase'}, [
                            form({class: 'form login-form', id: eventMan.add('submit', handleLogin)}, [
                                input({type: 'hidden', value: nextPath}),
                                input({type: 'hidden', value: nextURL}),
                                legend({style: 'text-align: center'}, 'KBase Sign In'),
{'fraction_non_alphanumeric': 0.12216099986560947, 'fraction_numerical': 0.0032253729337454644, 'mean_word_length': 1.2313343328335833, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '2488550', 'n_tokens_mistral': 3593, 'n_tokens_neox': 3359, 'n_words': 925}