<commit_before>/* This file is part of Indico.
 * Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
 *
 * Indico is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Indico is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Indico; if not, see <http://www.gnu.org/licenses/>.
 */

ndRegForm.controller('FieldCtrl', function($scope, regFormFactory) {
    $scope.fieldApi = {};
    $scope.getDefaultFieldSetting = regFormFactory.getDefaultFieldSetting;

    var getRequestParams = function(field) {
        return {
            confId: $scope.confId,
            sectionId: $scope.section.id,
            fieldId: field.id,
            confFormId: $scope.confFormId
        };
    };

    $scope.fieldApi.disableField = function(field) {
        regFormFactory[field.inputType == 'label' ? 'Labels' : 'Fields'].disable(getRequestParams(field), function(updatedField) {
            regFormFactory.processResponse(updatedField, {
                success: function(updatedField) {
                    var index = -1;
                    _.find($scope.section.items, function(item) {
                        index++;
                        return item.id == $scope.field.id;
                    });

                    $scope.field.isEnabled = updatedField.isEnabled;
                    $scope.section.items.splice(index, 1);
                    $scope.section.items.push($scope.field);
                }
            });
        }, handleAjaxError);
    };

    $scope.fieldApi.enableField = function(field) {
        regFormFactory[field.inputType == 'label' ? 'Labels' : 'Fields'].enable(getRequestParams(field), function(updatedField) {
            regFormFactory.processResponse(updatedField, {
                success: function(updatedField) {
                    $scope.field.isEnabled = updatedField.isEnabled;
                    $scope.section.items.sort(function(a, b) {
                        return a.position - b.position;
                    });
                }
            });
        }, handleAjaxError);
    };

    $scope.fieldApi.removeField = function(field) {
        $scope.sectionApi.removeField($scope.section, field);
    };

    $scope.fieldApi.updateField = function(field, data) {
        var postData = angular.extend(getRequestParams(field), {fieldData: data});

        if ($scope.isNew()) {
            delete postData['fieldId'];
        }
<commit_msg>Fix field enable/disable<commit_after>/* This file is part of Indico.
 * Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
 *
 * Indico is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Indico is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Indico; if not, see <http://www.gnu.org/licenses/>.
 */

ndRegForm.controller('FieldCtrl', function($scope, regFormFactory) {
    $scope.fieldApi = {};
    $scope.getDefaultFieldSetting = regFormFactory.getDefaultFieldSetting;

    var getRequestParams = function(field) {
        return {
            confId: $scope.confId,
            sectionId: $scope.section.id,
            fieldId: field.id,
            confFormId: $scope.confFormId
        };
    };

    $scope.fieldApi.disableField = function(field) {
        regFormFactory[field.inputType == 'label' ? 'Labels' : 'Fields'].disable(getRequestParams(field), function(updatedField) {
            regFormFactory.processResponse(updatedField, {
                success: function(updatedField) {
                    var index = -1;
                    _.find($scope.section.items, function(item) {
                        index++;
                        return item.id == $scope.field.id;
                    });

                    $scope.field.isEnabled = updatedField.view_data.isEnabled;
                    $scope.section.items.splice(index, 1);
                    $scope.section.items.push($scope.field);
                }
            });
        }, handleAjaxError);
    };

    $scope.fieldApi.enableField = function(field) {
        regFormFactory[field.inputType == 'label' ? 'Labels' : 'Fields'].enable(getRequestParams(field), function(updatedField) {
            regFormFactory.processResponse(updatedField, {
                success: function(updatedField) {
                    $scope.field.isEnabled = updatedField.view_data.isEnabled;
                    $scope.section.items.sort(function(a, b) {
                        return a.position - b.position;
                    });
                }
            });
        }, handleAjaxError);
    };

    $scope.fieldApi.removeField = function(field) {
        $scope.sectionApi.removeField($scope.section, field);
    };

    $scope.fieldApi.updateField = function(field, data) {
        var postData = angular.extend(getRequestParams(field), {fieldData: data});

        if ($scope.isNew()) {
            delete postData['fieldId'];
        }

{'fraction_non_alphanumeric': 0.10740933541558216, 'fraction_numerical': 0.0038174561860142286, 'mean_word_length': 2.1986681465038846, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4737716', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1460, 'n_words': 382}