<commit_before>hqDefine('app_manager/js/graph-config.js', function () {
    /**
     * Create a view model that is bound to an "Edit graph" button. The ui property
     * of this view model allows us to integrate the knockout elements with the
     * jquery based part of the ui.
     *
     * @param moduleOptions
     * A mapping of configuration options from the module. The following keys are required:
     *      lang
     *      langs
     *      childCaseTypes
     *      fixtures
     * @param serverRepresentationOfGraph
     * Object corresponding to a graph configuration saved in couch.
     * @constructor
     */
    var GraphConfigurationUiElement = function(moduleOptions, serverRepresentationOfGraph) {
        var self = this;
        moduleOptions = moduleOptions || {};

        var $editButtonDiv = $(
            '<div>' +
                '<button class="btn btn-default" data-bind="click: openModal">' +
                    '<i class="fa fa-pencil"></i>' +
                    ' Edit Graph' +
                '</button>' +
            '</div>'
        );

        self.ui = $editButtonDiv;
        self.graphViewModel = new GraphViewModel(moduleOptions);
        self.graphViewModel.populate(getGraphViewModelJS(serverRepresentationOfGraph, moduleOptions));

        self.openModal = function (uiElementViewModel){

            // make a copy of the view model
            var graphViewModelCopy = new GraphViewModel(moduleOptions);
            graphViewModelCopy.populate(ko.toJS(uiElementViewModel.graphViewModel));
            // Replace the original with the copy if save is clicked, otherwise discard it
            graphViewModelCopy.onSave = function(){
                uiElementViewModel.graphViewModel = graphViewModelCopy;
                self.fire("change");
            };

            // Load the modal with the copy
            var $modalDiv = $('<div data-bind="template: \'graph_configuration_modal\'"></div>');

            $modalDiv.koApplyBindings(graphViewModelCopy);

            var $modal = $modalDiv.find('.modal');
            $modal.appendTo('body');
            $modal.modal('show');
            $modal.on('hidden.bs.modal', function () {
                $modal.remove();
            });
        };
        self.setName = function(name){
            self.graphViewModel.graphDisplayName(name);
        };

        self.ui.koApplyBindings(self);
        eventize(self);

        /**
         * Return an object representing this graph configuration that is suitable
         * for sending to and saving on the server.
         * @returns {{}}
         */
        self.val = function(){
            var graphViewModelAsPOJS = ko.toJS(self.graphViewModel);
            var ret = {};

            /**
             * Convert objects like {'en': null, 'fra': 'baguette'} to {'fra': 'baguette'}
             * @param obj<commit_msg>Fix graph_configuration_modal template for jq3<commit_after>hqDefine('app_manager/js/graph-config.js', function () {
    /**
     * Create a view model that is bound to an "Edit graph" button. The ui property
     * of this view model allows us to integrate the knockout elements with the
     * jquery based part of the ui.
     *
     * @param moduleOptions
     * A mapping of configuration options from the module. The following keys are required:
     *      lang
     *      langs
     *      childCaseTypes
     *      fixtures
     * @param serverRepresentationOfGraph
     * Object corresponding to a graph configuration saved in couch.
     * @constructor
     */
    var GraphConfigurationUiElement = function(moduleOptions, serverRepresentationOfGraph) {
        var self = this;
        moduleOptions = moduleOptions || {};

        var $editButtonDiv = $(
            '<div>' +
                '<button class="btn btn-default" data-bind="click: openModal">' +
                    '<i class="fa fa-pencil"></i>' +
                    ' Edit Graph' +
                '</button>' +
            '</div>'
        );

        self.ui = $editButtonDiv;
        self.graphViewModel = new GraphViewModel(moduleOptions);
        self.graphViewModel.populate(getGraphViewModelJS(serverRepresentationOfGraph, moduleOptions));

        self.openModal = function (uiElementViewModel){

            // make a copy of the view model
            var graphViewModelCopy = new GraphViewModel(moduleOptions);
            graphViewModelCopy.populate(ko.toJS(uiElementViewModel.graphViewModel));
            // Replace the original with the copy if save is clicked, otherwise discard it
            graphViewModelCopy.onSave = function(){
                uiElementViewModel.graphViewModel = graphViewModelCopy;
                self.fire("change");
            };

            // Load the modal with the copy
            var $modalDiv = $(document.createElement("div"));
            $modalDiv.attr("data-bind", "template: \'graph_configuration_modal\'");

            $modalDiv.koApplyBindings(graphViewModelCopy);

            var $modal = $modalDiv.find('.modal');
            $modal.appendTo('body');
            $modal.modal('show');
            $modal.on('hidden.bs.modal', function () {
                $modal.remove();
            });
        };
        self.setName = function(name){
            self.graphViewModel.graphDisplayName(name);
        };

        self.ui.koApplyBindings(self);
        eventize(self);

        /**
         * Return an object representing this graph configuration that is suitable
         * for sending to and saving on the server.
         * @returns {{}}
         */
        self.val = function(){
            var graphViewModelAsPOJS = ko.toJS(self.graphViewModel);
            var ret = {};

            /**
             * Convert objects like {'en': null, 'fra': 'baguette'} to {'fra': 'baguette'}
             * @param obj
{'fraction_non_alphanumeric': 0.106426735218509, 'fraction_numerical': 0.00017137960582690659, 'mean_word_length': 1.997431946584489, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '136422', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1422, 'n_words': 392}