<commit_before>/**
 * Copyright (c) 2011, <NAME> <<EMAIL>>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */

var UserList = {
	useUndo: true,

	/**
	 * @brief Initiate user deletion process in UI
	 * @param string uid the user ID to be deleted
	 *
	 * Does not actually delete the user; it sets them for
	 * deletion when the current page is unloaded, at which point
	 * finishDelete() completes the process. This allows for 'undo'.
	 */
	do_delete: function (uid) {
		if (typeof UserList.deleteUid !== 'undefined') {
			//Already a user in the undo queue
			UserList.finishDelete(null);
		}
		UserList.deleteUid = uid;

		// Set undo flag
		UserList.deleteCanceled = false;

		// Provide user with option to undo
		$('#notification').data('deleteuser', true);
		OC.Notification.showHtml(t('users', 'deleted') + ' ' + uid + '<span class="undo">' + t('users', 'undo') + '</span>');
	},

	/**
	 * @brief Delete a user via ajax
	 * @param bool ready whether to use ready() upon completion
	 *
	 * Executes deletion via ajax of user identified by property deleteUid
	 * if 'undo' has not been used.  Completes the user deletion procedure
	 * and reflects success in UI.
	 */
	finishDelete: function (ready) {

		// Check deletion has not been undone
		if (!UserList.deleteCanceled && UserList.deleteUid) {

			// Delete user via ajax
			$.ajax({
				type: 'POST',
				url: OC.filePath('settings', 'ajax', 'removeuser.php'),
				async: false,
				data: { username: UserList.deleteUid },
				success: function (result) {
					if (result.status == 'success') {
						// Remove undo option, & remove user from table
						OC.Notification.hide();
						$('tr').filterAttr('data-uid', UserList.deleteUid).remove();
						UserList.deleteCanceled = true;
						if (ready) {
							ready();
						}
					} else {
						oc.dialogs.alert(result.data.message, t('settings', 'Unable to remove user'));
					}
				}
			});
		}
	},

	add: function (username, groups, subadmin, quota, sort) {
		var tr = $('tbody tr').first().clone();
		tr.attr('data-uid', username);
		tr.attr('data-displayName', username);
		tr.find('td.name').text(username);
		tr.find('td.displayName').text(username);
		var groupsSelect = $('<select multiple="multiple" class="groupsselect" data-placehoder="Groups" title="' + t('settings', 'Groups') + '"></select>').attr('data-username', username).attr('data-user-groups', groups);
		tr.find('td.groups').empty();
		if (tr.find('td.subadmins').length > 0) {
			var subadminSelect = $('<select multiple="multiple" class="subadminsselect" data-placehoder="subadmins" title="' + t('settings', 'Group Admin') + '">').attr('data-username', username).attr('data-user-groups', groups).attr('data-subadmin', subadmin);
			tr.find('td.subadmins').empty();
		}
		var allGroups = String($('#content table').attr('data-groups')).split(', ');
		$.each(allGroups, function (i, group) {
			groupsSelect.append($('<option value="' + group + '">' + group + '</option>'));
			if (typeof subadminSelect !== 'undefined' && group != 'admin') {
				subadminSelect.append($('<option value="' + group + '">' + group + '</option>'));
			}
		});
		tr.find('td.groups').append(groupsSelect);
		UserList.applyMultiplySelect(groupsSelect);
		if (tr.find('td.subadmins').length > 0) {
			tr.find('td.subadmins').append(subadminSelect);
			UserList.applyMultiplySelect(subadminSelect);
		}
		if (tr.find('td.remove img').length == 0 && OC.currentUser != username) {
			var rm_img = $('<img>', {
				class: 'svg action',
				src: OC.imagePath('core', 'actions/delete')
			});
			var rm_link = $('<a>', { class: 'action delete', href: '#', 'original-title': t('settings', 'Delete')}).append(rm_img);<commit_msg>fixing javascript errors IE8 in user management<commit_after>/**
 * Copyright (c) 2011, <NAME> <<EMAIL>>
 * This file is licensed under the Affero General Public License version 3 or later.
 * See the COPYING-README file.
 */

var UserList = {
	useUndo: true,

	/**
	 * @brief Initiate user deletion process in UI
	 * @param string uid the user ID to be deleted
	 *
	 * Does not actually delete the user; it sets them for
	 * deletion when the current page is unloaded, at which point
	 * finishDelete() completes the process. This allows for 'undo'.
	 */
	do_delete: function (uid) {
		if (typeof UserList.deleteUid !== 'undefined') {
			//Already a user in the undo queue
			UserList.finishDelete(null);
		}
		UserList.deleteUid = uid;

		// Set undo flag
		UserList.deleteCanceled = false;

		// Provide user with option to undo
		$('#notification').data('deleteuser', true);
		OC.Notification.showHtml(t('users', 'deleted') + ' ' + uid + '<span class="undo">' + t('users', 'undo') + '</span>');
	},

	/**
	 * @brief Delete a user via ajax
	 * @param bool ready whether to use ready() upon completion
	 *
	 * Executes deletion via ajax of user identified by property deleteUid
	 * if 'undo' has not been used.  Completes the user deletion procedure
	 * and reflects success in UI.
	 */
	finishDelete: function (ready) {

		// Check deletion has not been undone
		if (!UserList.deleteCanceled && UserList.deleteUid) {

			// Delete user via ajax
			$.ajax({
				type: 'POST',
				url: OC.filePath('settings', 'ajax', 'removeuser.php'),
				async: false,
				data: { username: UserList.deleteUid },
				success: function (result) {
					if (result.status == 'success') {
						// Remove undo option, & remove user from table
						OC.Notification.hide();
						$('tr').filterAttr('data-uid', UserList.deleteUid).remove();
						UserList.deleteCanceled = true;
						if (ready) {
							ready();
						}
					} else {
						oc.dialogs.alert(result.data.message, t('settings', 'Unable to remove user'));
					}
				}
			});
		}
	},

	add: function (username, groups, subadmin, quota, sort) {
		var tr = $('tbody tr').first().clone();
		tr.attr('data-uid', username);
		tr.attr('data-displayName', username);
		tr.find('td.name').text(username);
		tr.find('td.displayName').text(username);
		var groupsSelect = $('<select multiple="multiple" class="groupsselect" data-placehoder="Groups" title="' + t('settings', 'Groups') + '"></select>').attr('data-username', username).attr('data-user-groups', groups);
		tr.find('td.groups').empty();
		if (tr.find('td.subadmins').length > 0) {
			var subadminSelect = $('<select multiple="multiple" class="subadminsselect" data-placehoder="subadmins" title="' + t('settings', 'Group Admin') + '">').attr('data-username', username).attr('data-user-groups', groups).attr('data-subadmin', subadmin);
			tr.find('td.subadmins').empty();
		}
		var allGroups = String($('#content table').attr('data-groups')).split(', ');
		$.each(allGroups, function (i, group) {
			groupsSelect.append($('<option value="' + group + '">' + group + '</option>'));
			if (typeof subadminSelect !== 'undefined' && group != 'admin') {
				subadminSelect.append($('<option value="' + group + '">' + group + '</option>'));
			}
		});
		tr.find('td.groups').append(groupsSelect);
		UserList.applyMultiplySelect(groupsSelect);
		if (tr.find('td.subadmins').length > 0) {
			tr.find('td.subadmins').append(subadminSelect);
			UserList.applyMultiplySelect(subadminSelect);
		}
		if (tr.find('td.remove img').length == 0 && OC.currentUser != username) {
			var rm_img = $('<img class="svg action">').attr({
				src: OC.imagePath('core', 'actions/delete')
			});
			var rm_link = $('<a class="action delete">')
				.attr({ href: '#', 'original-title': t('settings', 'Delete')})
				.append(rm_img);
{'fraction_non_alphanumeric': 0.18030182684670373, 'fraction_numerical': 0.0022504633306857295, 'mean_word_length': 3.8274760383386583, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, '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': '5152560', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2333, 'n_words': 627}