<commit_before>var forms = require('forms'),
    fields = forms.fields,
    validators = forms.validators,
    widgets = forms.widgets;

/**
 * Initialize '/' route.
 *
 * @param {Object} app Express application object
 */
exports.init = function(app) {
    // Build list of radio stations indexes
    var radioStations = app.radio.getAvailableStations(),
        radioStationChoices = [];
    for(var index in radioStations) {
        if (!radioStations.hasOwnProperty(index)) {
            continue;
        }

        radioStationChoices[index] = radioStations[index].name;
    }

    // Build settings form
    var settingsForm = forms.create({
        useAlarm: fields.boolean({
            label: 'Alarm enabled'
        }),
        wakeUpHour: fields.number({
            required: true,
            label: 'Hour:',
            validators: [
                validators.min(0),
                validators.max(23)
            ]
        }),
        wakeUpMinute: fields.number({
            required: true,
            label: 'Minute:',
            validators: [
                validators.min(0),
                validators.max(59)
            ]
        }),
        radioStation: fields.array({
            required: true,
            label: 'Radio station:',
            choices: radioStationChoices,
            widget: widgets.multipleRadio()
        })
    });

    // Register routes
    app.get('/', function(req, res) {
        // Set default settings values and render the settings form
        var renderedSettingsForm = settingsForm.bind({
            useAlarm: app.enabled('alarm'),
            wakeUpHour: app.get('wake up hour'),
            wakeUpMinute: app.get('wake up minute'),
            radioStation: app.radio.getCurrentStation()
        }).toHTML();

        // Add messages if needed
        var messages = [];
        if (typeof req.query.saved !== 'undefined') {
            messages.push('Settings saved');
        }

        // Render the page
        res.render(
            'index', {
                messages: messages,
                settingsForm: renderedSettingsForm
            }
        );
    });

    app.post('/', function(req, res) {
        settingsForm.handle(req, {
            success: function (form) {
                // Save settings
                if (form.data.useAlarm) {
                    app.enable('alarm');
                }
                app.set('wake up hour', form.data.wakeUpHour);
                app.set('wake up minute', form.data.wakeUpMinute);
                app.radio.setCurrentStation(form.data.radioStation);

                // Redirect a user to home page
                res.redirect('/?saved');
            },
            other: function (form) {
                res.render('index', {settingsForm: form.toHTML()});
            }
        });
    });
}<commit_msg>Fix bug with disabling alarm<commit_after>var forms = require('forms'),
    fields = forms.fields,
    validators = forms.validators,
    widgets = forms.widgets;

/**
 * Initialize '/' route.
 *
 * @param {Object} app Express application object
 */
exports.init = function(app) {
    // Build list of radio stations indexes
    var radioStations = app.radio.getAvailableStations(),
        radioStationChoices = [];
    for(var index in radioStations) {
        if (!radioStations.hasOwnProperty(index)) {
            continue;
        }

        radioStationChoices[index] = radioStations[index].name;
    }

    // Build settings form
    var settingsForm = forms.create({
        useAlarm: fields.boolean({
            label: 'Alarm enabled'
        }),
        wakeUpHour: fields.number({
            required: true,
            label: 'Hour:',
            validators: [
                validators.min(0),
                validators.max(23)
            ]
        }),
        wakeUpMinute: fields.number({
            required: true,
            label: 'Minute:',
            validators: [
                validators.min(0),
                validators.max(59)
            ]
        }),
        radioStation: fields.array({
            required: true,
            label: 'Radio station:',
            choices: radioStationChoices,
            widget: widgets.multipleRadio()
        })
    });

    // Register routes
    app.get('/', function(req, res) {
        // Set default settings values and render the settings form
        var renderedSettingsForm = settingsForm.bind({
            useAlarm: app.enabled('alarm'),
            wakeUpHour: app.get('wake up hour'),
            wakeUpMinute: app.get('wake up minute'),
            radioStation: app.radio.getCurrentStation()
        }).toHTML();

        // Add messages if needed
        var messages = [];
        if (typeof req.query.saved !== 'undefined') {
            messages.push('Settings saved');
        }

        // Render the page
        res.render(
            'index', {
                messages: messages,
                settingsForm: renderedSettingsForm
            }
        );
    });

    app.post('/', function(req, res) {
        settingsForm.handle(req, {
            success: function (form) {
                // Save settings
                app.set('alarm', !!form.data.useAlarm);
                app.set('wake up hour', form.data.wakeUpHour);
                app.set('wake up minute', form.data.wakeUpMinute);
                app.radio.setCurrentStation(form.data.radioStation);

                // Redirect a user to home page
                res.redirect('/?saved');
            },
            other: function (form) {
                res.render('index', {settingsForm: form.toHTML()});
            }
        });
    });
}
{'fraction_non_alphanumeric': 0.12000706963591375, 'fraction_numerical': 0.0021208907741251328, 'mean_word_length': 1.5722727272727273, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2171065', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1474, 'n_words': 329}