<commit_before>/**
 * app.js
 *
 * Contains Firebase initialization calls and AJAX functions for interacting
 * with the server
 *
 * Notice: this file utilizes conventions from ES6 (ES2015).
 * jQuery 3.2.0+
 *
 * TODO: Move DOM listeners to interact.js
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2017 DUiT
 * @since     File available since release 0.0.3  
 */

(function(){
	// Initialize Firebase
	let config = {
		apiKey: "<KEY>",
		authDomain: "duit-ba651.firebaseapp.com",
		databaseURL: "https://duit-ba651.firebaseio.com",
		projectId: "duit-ba651",
		storageBucket: "duit-ba651.appspot.com",
		messagingSenderId: "948811797559"
	};
	firebase.initializeApp(config);


	const txtEmail = document.getElementById('txtEmail');
	const txtPassword = document.getElementById('txtPassword');
	const btnDisplayDus = document.getElementById('btnDisplayDus');
	const btnAddDu = document.getElementById('btnAddDu');
	const btnLogin = document.getElementById('btnLogin');
	const btnSignUp = document.getElementById('btnSignUp');
	const btnLogout = document.getElementById('btnLogout');
	const deleteDuList = document.getElementsByClassName('deleteDu');

	//$('.deleteDu')

	// Add login event
	if (btnLogin) {
		btnLogin.addEventListener('click', e=>{
			login();
		});
	}

	function login(){
		// Get email and pass
		const email = txtEmail.value;
		const pass = txtPassword.value;
		const auth = firebase.auth();
		// Sign in
		const promise = auth.signInWithEmailAndPassword(email,pass);
		promise.catch(e=>console.log(e.message));

	}

	// Add dus table display event
	if (btnDisplayDus) {
			btnDisplayDus.addEventListener('click',e=>{
				callServer("displayAsTableDus");
		});
	}

	// Add tags table display event
	if (btnDisplayTags) {
			btnDisplayTags.addEventListener('click',e=>{
				callServer("displayAsTableTags");
		});
	}

	// Add users table display event
	if (btnDisplayUsers) {
			btnDisplayUsers.addEventListener('click',e=>{
				callServer("displayAsTableUsers");
		});
	}

	// Delete selected du
	if (deleteDuList) {
		$(document).on('click','.deleteDu',function(e){
			deleteDu();
		});
	}

	function deleteDu(){
		let du_id = $(e.currentTarget).attr('class').slice(12);
		let params = {
			"du_id": du_id
		};
		callServer("deleteDu",params);
	}

	// Add new du
	if (btnAddDu) {
		btnAddDu.addEventListener('click',e=>{
			addDu();
		});
	}

	function addDu(){
		let du_name = $("#du_name").val();
		let du_time_start = $('#du_time_start').val();<commit_msg>Fix deleteDu event passing<commit_after>/**
 * app.js
 *
 * Contains Firebase initialization calls and AJAX functions for interacting
 * with the server
 *
 * Notice: this file utilizes conventions from ES6 (ES2015).
 * jQuery 3.2.0+
 *
 * TODO: Move DOM listeners to interact.js
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2017 DUiT
 * @since     File available since release 0.0.3  
 */

(function(){
	// Initialize Firebase
	let config = {
		apiKey: "<KEY>",
		authDomain: "duit-ba651.firebaseapp.com",
		databaseURL: "https://duit-ba651.firebaseio.com",
		projectId: "duit-ba651",
		storageBucket: "duit-ba651.appspot.com",
		messagingSenderId: "948811797559"
	};
	firebase.initializeApp(config);


	const txtEmail = document.getElementById('txtEmail');
	const txtPassword = document.getElementById('txtPassword');
	const btnDisplayDus = document.getElementById('btnDisplayDus');
	const btnAddDu = document.getElementById('btnAddDu');
	const btnLogin = document.getElementById('btnLogin');
	const btnSignUp = document.getElementById('btnSignUp');
	const btnLogout = document.getElementById('btnLogout');
	const deleteDuList = document.getElementsByClassName('deleteDu');

	//$('.deleteDu')

	// Add login event
	if (btnLogin) {
		btnLogin.addEventListener('click', e=>{
			login();
		});
	}

	function login(){
		// Get email and pass
		const email = txtEmail.value;
		const pass = txtPassword.value;
		const auth = firebase.auth();
		// Sign in
		const promise = auth.signInWithEmailAndPassword(email,pass);
		promise.catch(e=>console.log(e.message));

	}

	// Add dus table display event
	if (btnDisplayDus) {
			btnDisplayDus.addEventListener('click',e=>{
				callServer("displayAsTableDus");
		});
	}

	// Add tags table display event
	if (btnDisplayTags) {
			btnDisplayTags.addEventListener('click',e=>{
				callServer("displayAsTableTags");
		});
	}

	// Add users table display event
	if (btnDisplayUsers) {
			btnDisplayUsers.addEventListener('click',e=>{
				callServer("displayAsTableUsers");
		});
	}

	// Delete selected du
	if (deleteDuList) {
		$(document).on('click','.deleteDu',function(e){
			deleteDu(e);
		});
	}

	function deleteDu(event){
		let du_id = $(event.currentTarget).attr('class').slice(12);
		let params = {
			"du_id": du_id
		};
		callServer("deleteDu",params);
	}

	// Add new du
	if (btnAddDu) {
		btnAddDu.addEventListener('click',e=>{
			addDu();
		});
	}

	function addDu(){
		let du_name = $("#du_name").val();
		let du_time_start = $('#du_time_start').val();
{'fraction_non_alphanumeric': 0.15307553596473653, 'fraction_numerical': 0.01642957323181727, 'mean_word_length': 4.31063829787234, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '4093988', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1610, 'n_words': 348}