<commit_before>/* globals hqDefine */
hqDefine('builds/js/edit-builds', function () {
    var initial_page_data = hqImport('hqwebapp/js/initial_page_data').get,
        doc = initial_page_data('doc');

    function Version(version, label, superuser_only, j2me_enabled) {
        var self = this;
        self.version = ko.observable(version);
        self.label = ko.observable(label);
        self.superuser_only = ko.observable(superuser_only);
        self.j2me_enabled = ko.observable(j2me_enabled);

        // subscribe for change in version to update j2me_enabled
        // property and hence the checkbox in view
        self.version.subscribe(function(newValue){
            self.j2me_enabled(buildsMenu.j2me_enabled_versions.
                includes(newValue)
            );
        });
    }

    function Menu() {
        var self = this;

        self.available_versions = initial_page_data('available_versions');
        self.j2me_enabled_versions = initial_page_data('j2me_enabled_versions');
        self.versions = ko.observableArray([]);
        self.available_ones = [];
        self.available_twos = [];
        self.default_one = ko.observable();
        self.default_two = ko.observable();

        self.addVersion = function() {
            self.versions.push(new Version('', '', false));
        };
        self.removeVersion = function(version) { self.versions.remove(version); };

        _.each(doc.menu, function(version) {
            self.versions.push(new Version(
                version.build.version, version.label,
                version.superuser_only, version.j2me_enabled
            ));
        });
        _.each(doc.defaults, function(version_doc) {
            var version = version_doc.version;
            if (version[0] === '1') {
                self.default_one(version);
            } else if (version[0] === '2') {
                self.default_two(version);
            }
        });
        _.each(self.available_versions, function(version) {
            if (version[0] === '1') {
                self.available_ones.push(version);
            } else if (version[0] === '2') {
                self.available_twos.push(version);
            }
        });
    }

    function outputJSON(menu) {
        doc.menu = [];
        _.each(menu.versions(), function(version) {
            doc.menu.push({
                'j2me_enabled': version.j2me_enabled(),
                'superuser_only': version.superuser_only(),
                'label': version.label(),
                'build': {
                    'version': version.version(),
                    'build_number': null,
                    'latest': true,
                },
            });
        });
        doc.defaults = [];
        _.each([menu.default_one, menu.default_two], function(deflt) {
            doc.defaults.push({
                'version': deflt(),
                'build_number': null,
                'latest': true,
            });
        });
        return doc;
    }

    var buildsMenu = new Menu();
    $("#menu-form").koApplyBindings(buildsMenu);

    function postGo(url, params) {
        var $form = $("#submit-menu-form")
            .attr("action", url);
        $.each(params, function (name, value) {
            $("<input type='hidden'>")
                .attr("name", name)
                .attr("value", value)
                .appendTo($form);
        });
        $form.submit();
    }
<commit_msg>Edit Builds page<commit_after>/* globals hqDefine */
hqDefine('builds/js/edit-builds', function () {
    var initial_page_data = hqImport('hqwebapp/js/initial_page_data').get,
        doc = initial_page_data('doc');

    function versionModel(version, label, superuser_only, j2me_enabled) {
        var self = {};
        self.version = ko.observable(version);
        self.label = ko.observable(label);
        self.superuser_only = ko.observable(superuser_only);
        self.j2me_enabled = ko.observable(j2me_enabled);

        // subscribe for change in version to update j2me_enabled
        // property and hence the checkbox in view
        self.version.subscribe(function(newValue){
            self.j2me_enabled(buildsMenu.j2me_enabled_versions.
                includes(newValue)
            );
        });
        return self;
    }

    function menuModel() {
        var self = {};

        self.available_versions = initial_page_data('available_versions');
        self.j2me_enabled_versions = initial_page_data('j2me_enabled_versions');
        self.versions = ko.observableArray([]);
        self.available_ones = [];
        self.available_twos = [];
        self.default_one = ko.observable();
        self.default_two = ko.observable();

        self.addVersion = function() {
            self.versions.push(versionModel('', '', false));
        };
        self.removeVersion = function(version) { self.versions.remove(version); };

        _.each(doc.menu, function(version) {
            self.versions.push(versionModel(
                version.build.version, version.label,
                version.superuser_only, version.j2me_enabled
            ));
        });
        _.each(doc.defaults, function(version_doc) {
            var version = version_doc.version;
            if (version[0] === '1') {
                self.default_one(version);
            } else if (version[0] === '2') {
                self.default_two(version);
            }
        });
        _.each(self.available_versions, function(version) {
            if (version[0] === '1') {
                self.available_ones.push(version);
            } else if (version[0] === '2') {
                self.available_twos.push(version);
            }
        });

        return self;
    }

    function outputJSON(menu) {
        doc.menu = [];
        _.each(menu.versions(), function(version) {
            doc.menu.push({
                'j2me_enabled': version.j2me_enabled(),
                'superuser_only': version.superuser_only(),
                'label': version.label(),
                'build': {
                    'version': version.version(),
                    'build_number': null,
                    'latest': true,
                },
            });
        });
        doc.defaults = [];
        _.each([menu.default_one, menu.default_two], function(deflt) {
            doc.defaults.push({
                'version': deflt(),
                'build_number': null,
                'latest': true,
            });
        });
        return doc;
    }

    var buildsMenu = menuModel();
    $("#menu-form").koApplyBindings(buildsMenu);

    function postGo(url, params) {
        var $form = $("#submit-menu-form")
            .attr("action", url);
        $.each(params, function (name, value) {
            $("<input type='hidden'>")
                .attr("name", name)
                .attr("value", value)
                .appendTo($form);
        });
        $form.submit();
    }

{'fraction_non_alphanumeric': 0.13596428057035864, 'fraction_numerical': 0.00547313841278986, 'mean_word_length': 1.77427087495006, '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': '1784270', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1903, 'n_words': 319}