<commit_before>/*
* Copyright 2017 the Isard-vdi project authors:
*      <NAME>
*      <NAME>
* License: AGPLv3
*/

var users_table= ''
$(document).ready(function() {
    $('.admin-status').show()
    $template = $(".template-detail-users");
    
	$('.btn-new-user').on('click', function () {
        setQuotaMax('#users-quota',kind='category',id=false,disabled=false);
        $('#modalAddUser').modal({backdrop: 'static', keyboard: false}).modal('show');
        $('#modalAddUserForm')[0].reset();
        setModalUser();
	});


    
	$('.btn-new-bulkusers').on('click', function () {
        setQuotaMax('#bulkusers-quota',kind='category',id=false,disabled=false);
        $('#modalAddBulkUsers').modal({backdrop: 'static', keyboard: false}).modal('show');
        $('#modalAddBulkUsersForm')[0].reset();
        setModalUser();
	});

	$('#btn-download-bulkusers').on('click', function () {
        var viewerFile = new Blob(["username,name,email,password\<PASSWORD>,<NAME>,<EMAIL>,sup3rs3cr3t\nauser,Another User,<EMAIL>,a1sera1ser"], {type: "text/csv"});
        var a = document.createElement('a');
            a.download = 'bulk-users-template.csv';
            a.href = window.URL.createObjectURL(viewerFile);
        var ev = document.createEvent("MouseEvents");
            ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            a.dispatchEvent(ev);  
	});

    $("#add-category").on('change', function () {
        let category = $(this).val()
        $('#add-group').find('option').each(function () {
            if (this.value.startsWith(category + "-")) {
                this.disabled = false
            } else {
                this.disabled = true
                if (this.selected) {
                    $(this).prop('selected', false)
                }
            }
        })
    })

    $("#modalAddUser #send").on('click', function(e){
        var form = $('#modalAddUserForm');
        formdata = form.serializeObject()
        form.parsley().validate();
        if (form.parsley().isValid()){   // || 'unlimited' in formdata){   
            data=userQuota2dict(formdata);
            data['password']=data['<PASSWORD>'];<commit_msg>Fix webapp by disabling other categories groups at bulk user creation form<commit_after>/*
* Copyright 2017 the Isard-vdi project authors:
*      <NAME>
*      <NAME>
* License: AGPLv3
*/

var users_table= ''
$(document).ready(function() {
    $('.admin-status').show()
    $template = $(".template-detail-users");
    
	$('.btn-new-user').on('click', function () {
        setQuotaMax('#users-quota',kind='category',id=false,disabled=false);
        $('#modalAddUser').modal({backdrop: 'static', keyboard: false}).modal('show');
        $('#modalAddUserForm')[0].reset();
        setModalUser();
	});


    
	$('.btn-new-bulkusers').on('click', function () {
        setQuotaMax('#bulkusers-quota',kind='category',id=false,disabled=false);
        $('#modalAddBulkUsers').modal({backdrop: 'static', keyboard: false}).modal('show');
        $('#modalAddBulkUsersForm')[0].reset();
        setModalUser();
	});

	$('#btn-download-bulkusers').on('click', function () {
        var viewerFile = new Blob(["username,name,email,password\<PASSWORD>,John <PASSWORD>,<EMAIL>,sup3rs3cr3t\nauser,Another User,<EMAIL>,a1sera1ser"], {type: "text/csv"});
        var a = document.createElement('a');
            a.download = 'bulk-users-template.csv';
            a.href = window.URL.createObjectURL(viewerFile);
        var ev = document.createEvent("MouseEvents");
            ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            a.dispatchEvent(ev);  
	});

    function filter_groups(category_select, group_select) {
        let category = category_select.val()
        group_select.find('option').each(function () {
            if (this.value.startsWith(category + "-")) {
                this.disabled = false
            } else {
                this.disabled = true
                if (this.selected) {
                    $(this).prop('selected', false)
                }
            }
        })
    }
    $("#add-category").on('change', function () {
        filter_groups($(this), $('#add-group'))
    })
    $("#bulk-category").on('change', function () {
        filter_groups($(this), $('#bulk-group'))
    })

    $("#modalAddUser #send").on('click', function(e){
        var form = $('#modalAddUserForm');
        formdata = form.serializeObject()
        form.parsley().validate();
        if (form.parsley().isValid()){   // || 'unlimited' in formdata){   
            data=userQuota2dict(formdata);
            data['password']=<PASSWORD>['<PASSWORD>'];
{'fraction_non_alphanumeric': 0.1944209636517329, 'fraction_numerical': 0.008030431107354184, 'mean_word_length': 2.7267716535433073, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4144205', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1429, 'n_words': 226}