<commit_before>'use strict';

/* global cordova */

define(function(require) {
    var _ = require('underscore');
    var location = require('./location');
    var PositionRecorder = require('./position-recorder');
    var utils = require('./utils');

    //Constants
    var PLUGIN_PATH = 'plugins/position-tracking';

    var templates = {};
    templates.groupItem = _.template(
        '<li class="group">' +
            '<span><%-name%></span>' +
        '</li>'
    );

    templates.editorItem = _.template(
        '<li class="editor">' +
            '<div class="editor-label"><%-name%></div>' +
            '<div class="controls" data-editor-id="<%=editorId%>" data-group-id="<%=groupId%>">' +
                '<div class="control-button record off"></div>' +
                '<div class="control-button pause"></div>' +
                '<div class="control-button stop"></div>' +
            '</div>' +
        '</li>'
    );

    /**
     * Render the list of editors and the recording controls
     */
    var renderEditorsList = function() {
        var editorsMetadata = utils.getLocalItem('editors-metadata');
        var html = '';

        _.forEach(editorsMetadata, function(editors, group) {
            // Add a group separator if has items
            if (_.keys(editors).length > 0) {
                html += templates.groupItem({
                    name: group
                });
            }

            // Add the editors
            _.forEach(editors, function(editor) {
                html += templates.editorItem({
                    name: editor.title,
                    editorId: editor.type,
                    groupId: editor.group
                });
            });
        });

        $('#position-tracking-editors-list')
            .html(html)
            .listview('refresh');
    };

    /**
     * Initialize the plugin
     */
    var initPlugin = function() {
        // Inject the plugin styles
        $('head').prepend('<link rel="stylesheet" href="' + PLUGIN_PATH + '/css/style.css" type="text/css" />');

        $(document).on('vclick', '.position-tracking-page-button', function(event) {
            event.preventDefault();
            $('body').pagecontainer('change', 'position-tracking-main-page.html');
        });

        $(document).on('pagebeforeshow', '#position-tracking-main-page', function() {
            renderEditorsList();
        });
    };

    initPlugin();
});<commit_msg>Associate the start/stop/pause buttons to the recorders manager equivalents<commit_after>'use strict';

/* global cordova */

define(function(require) {
    var _ = require('underscore');
    var location = require('./location');
    var utils = require('./utils');
    var recorderManager = require('./position-recorders-manager').PositionRecordersManager;

    //Constants
    var PLUGIN_PATH = 'plugins/position-tracking';

    var templates = {};
    templates.groupItem = _.template(
        '<li class="group">' +
            '<span><%-name%></span>' +
        '</li>'
    );

    templates.editorItem = _.template(
        '<li class="editor">' +
            '<div class="editor-label"><%-name%></div>' +
            '<div class="controls" data-editor-id="<%=editorId%>" data-group-id="<%=groupId%>">' +
                '<div class="control-button record off"></div>' +
                '<div class="control-button pause"></div>' +
                '<div class="control-button stop"></div>' +
            '</div>' +
        '</li>'
    );

    /**
     * Render the list of editors and the recording controls
     */
    var renderEditorsList = function() {
        var editorsMetadata = utils.getLocalItem('editors-metadata');
        var html = '';

        _.forEach(editorsMetadata, function(editors, group) {
            // Add a group separator if has items
            if (_.keys(editors).length > 0) {
                html += templates.groupItem({
                    name: group
                });
            }

            // Add the editors
            _.forEach(editors, function(editor) {
                html += templates.editorItem({
                    name: editor.title,
                    editorId: editor.type,
                    groupId: editor.group
                });
            });
        });

        $('#position-tracking-editors-list')
            .html(html)
            .listview('refresh');
    };

    var registerControlEvents = function() {

        var toggleRecordButton = function($control, recorder) {
            var $recordButton = $control.find('.control-button.record');

            if (recorder && recorder.isRecording()) {
                $recordButton
                    .removeClass('off')
                    .addClass('on');
            }
            else {
                $recordButton
                    .removeClass('on')
                    .addClass('off');
            }
        };

        var getActionName = function($target) {
            var controlTypes = ['record', 'pause', 'stop'];
            var action;

            action = _.find(controlTypes, function(className) {
                return $target.hasClass(className);
            });

            return action;
        };

        $('#position-tracking-editors-list').on('vclick', '.control-button', function(event) {
            var recorder;
            var $targetButton = $(event.target);
            var $controls = $targetButton.parent('.controls');
            var editorId = $controls.data('editor-id');
            var groupId = $controls.data('group-id');

            switch (getActionName($targetButton)) {
                case 'record':
                    recorder = recorderManager.startRecorder(editorId, groupId);
                    break;
                case 'pause':
                    recorder = recorderManager.pauseRecorder(editorId, groupId);
                    break;
                case 'stop':
                    recorder = recorderManager.stopRecorder(editorId, groupId);
                    break;
            }

            toggleRecordButton($controls, recorder);
        });
    };

    /**
     * Initialize the plugin
     */
    var initPlugin = function() {
        // Inject the plugin styles
        $('head').prepend('<link rel="stylesheet" href="' + PLUGIN_PATH + '/css/style.css" type="text/css" />');

        $(document).on('vclick', '.position-tracking-page-button', function(event) {
            event.preventDefault();
            $('body').pagecontainer('change', 'position-tracking-main-page.html');
        });

        $(document).on('pagebeforeshow', '#position-tracking-main-page', function() {
            renderEditorsList();
            registerControlEvents();
        });
    };

    initPlugin();
});
{'fraction_non_alphanumeric': 0.15276337235145948, 'fraction_numerical': 0.000296340198547933, 'mean_word_length': 1.7350081037277147, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 47, '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': '5372997', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1710, 'n_words': 339}