<commit_before><link rel="import" href="polymer/polymer.html">
<link rel="import" href="iron-form/iron-form.html">
<link rel="import" href="iron-ajax/iron-ajax.html">
<link rel="import" href="paper-dialog/paper-dialog.html">
<link rel="import" href="paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="paper-listbox/paper-listbox.html">
<link rel="import" href="paper-toolbar/paper-toolbar.html">
<link rel="import" href="paper-input/paper-input.html">
<link rel="import" href="paper-button/paper-button.html">
<link rel="import" href="paper-tooltip/paper-tooltip.html">
<link rel="import" href="paper-toggle-button/paper-toggle-button.html" >
<link rel="import" href="paper-toast/paper-toast.html">
<link rel="import" href="paper-styles/color.html">

<dom-module id="sig-client-add">
	<style is="custom-style">
		paper-dialog {
			width: 60%;
			height: 50%;
			padding: 10px;
		}
		paper-toolbar{
			color: white;
			background-color: #bc5100;
		}
		.add-button {
			background-color: var(--paper-lime-a700);
			color: black;
			float: right;
			width: 8em;
		}
		.cancel-button {
			color: black;
		}
		paper-toast.error {
			background-color: var(--paper-red-a400);
		}
		paper-toggle-button {
			--paper-toggle-button-checked-bar-color: #ffb04c;
			--paper-toggle-button-checked-button-color: var(--paper-yellow-900);
		}
	</style>
	<template>
		<paper-dialog id="clientAddModal" modal>
			<paper-toolbar>
				<h2>Add Client</h2>
			</paper-toolbar>
			<form
					is="iron-form"
					id="clientAddForm"
					method="post"
					content-type="application/json">
				<paper-input
						id="add-client1"
						name="address"
						label="IP Address">
				</paper-input>
				<paper-tooltip >
					IP address of network access server, router or access point
				</paper-tooltip>
				<paper-input
						id="add-client2"
						name="port"
						label="Listen Port"
						type="number"
						value=3799>
				</paper-input>
				<paper-tooltip>
					Port network access server, router or access point listens on
				</paper-tooltip>
				<paper-input
						id="add-client4"
						name="secret"
						label="Secret">
				</paper-input>
				<paper-tooltip>
					Secret, or password, shared with the network access server, router or access point.
				</paper-tooltip>
				<paper-dropdown-menu
						id="add-client3"
						label="Protocol">
					<paper-listbox
							slot="dropdown-content"
							class="dropdown-content"
							selected="0">
						<paper-item value="RADIUS">
							RADIUS
						</paper-item>
						<paper-item value="DIAMETER">
							DIAMETER
						</paper-item>
					</paper-listbox>
				</paper-dropdown-menu>
				<div class="buttons">
					<paper-button
							raised
							class="add-button"
							onclick="_submitClientForm()">
						Submit
					</paper-button>
					<paper-button
							class="cancel-button"
							dialog-confirm
							autofocus
							onclick="clientAddModal.close()">
						Cancel
					</paper-button>
				</div>
			</form>
		</paper-dialog>
		<iron-ajax
				id="clientAddAjax"
				url="/ocs/v1/client"
				method = "post"
				headers='{"Accept": "application/json", "Content-type": "application/json"}'
				on-loading-changed="_onLoadingChanged"
				client-as="json"
				debounce-duration="300">
		</iron-ajax>
		<script>
			function _submitClientForm() {
				document.getElementById('clientAddForm').submit();
			}
			function toastErrorClose(event) {
				document.getElementById('toastError').close();
			}
		</script>
	</template>
	<script>
		Polymer (
			{
				is: 'sig-client-add',
				listeners: {
					'clientAddForm.iron-form-presubmit': '_clientFormPreSubmit',
					'clientAddForm.iron-form-error': '_clientFormError',
					'clientAddForm.iron-form-response': '_clientFormResponse',
				},
				_clientFormPreSubmit: function() {
					var form = document.getElementById('presubmit3');
					var formData = new Object();
					formData.id = document.getElementById("add-client1").value;
					formData.port = parseInt(document.getElementById("add-client2").value);
					formData.protocol = document.getElementById("add-client3").value;
					formData.secret = document.getElementById("add-client4").value;
					var ajax = document.getElementById("clientAddAjax");
					ajax.body = formData;
					ajax.generateRequest();
				},
				_clientFormError: function() {
					var toast = document.getElementById("toastError");
					toast.open();
					toast.duration = 0;
					toast.fitInto = document.getElementById("response-display-container");
				},
				_onLoadingChanged: function(event) {
					if (document.getElementById("clientAddAjax").loading) {
						document.getElementById('progress').disabled = false;
					} else {
						document.getElementById('progress').disabled = true;
					}
				},
				_clientFormResponse: function(event) {
					var toast = document.getElementById("toast-success");
					toast.open();
					toast.duration = 4;
					toast.fitInto = document.getElementById("response-display-container");
					document.getElementById("clientAddForm").reset();
					document.getElementById("clientAddModal").close();
					document.getElementById("getClients").generateRequest();
				}
			}
		);
	</script>
</dom-module><commit_msg>implement success toast and validation<commit_after><link rel="import" href="polymer/polymer.html">
<link rel="import" href="iron-form/iron-form.html">
<link rel="import" href="iron-ajax/iron-ajax.html">
<link rel="import" href="paper-dialog/paper-dialog.html">
<link rel="import" href="paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="paper-listbox/paper-listbox.html">
<link rel="import" href="paper-toolbar/paper-toolbar.html">
<link rel="import" href="paper-input/paper-input.html">
<link rel="import" href="paper-button/paper-button.html">
<link rel="import" href="paper-tooltip/paper-tooltip.html">
<link rel="import" href="paper-toggle-button/paper-toggle-button.html" >
<link rel="import" href="paper-toast/paper-toast.html">
<link rel="import" href="paper-styles/color.html">

<dom-module id="sig-client-add">
	<style is="custom-style">
		paper-dialog {
			width: 60%;
			height: 50%;
			padding: 10px;
		}
		paper-toolbar{
			color: white;
			background-color: #bc5100;
		}
		.add-button {
			background-color: var(--paper-lime-a700);
			color: black;
			float: right;
			width: 8em;
		}
		.cancel-button {
			color: black;
		}
		paper-toast.error {
			background-color: var(--paper-red-a400);
		}
		paper-toggle-button {
			--paper-toggle-button-checked-bar-color: #ffb04c;
			--paper-toggle-button-checked-button-color: var(--paper-yellow-900);
		}
	</style>
	<template>
		<paper-dialog id="clientAddModal" modal>
			<paper-toolbar>
				<h2>Add Client</h2>
			</paper-toolbar>
			<form
					is="iron-form"
					id="clientAddForm"
					method="post"
					content-type="application/json">
				<paper-input
						id="add-client1"
						name="address"
						label="IP Address"
						allowed-pattern="[0-9\.]"
						required>
				</paper-input>
				<paper-tooltip >
					IP address of network access server, router or access point
				</paper-tooltip>
				<paper-input
						id="add-client2"
						name="port"
						label="Listen Port"
						type="number"
						value=3799>
				</paper-input>
				<paper-tooltip>
					Port network access server, router or access point listens on
				</paper-tooltip>
				<paper-input
						id="add-client4"
						name="secret"
						label="Secret">
				</paper-input>
				<paper-tooltip>
					Secret, or password, shared with the network access server, router or access point.
				</paper-tooltip>
				<paper-dropdown-menu
						id="add-client3"
						label="Protocol">
					<paper-listbox
							slot="dropdown-content"
							class="dropdown-content"
							selected="0">
						<paper-item value="RADIUS">
							RADIUS
						</paper-item>
						<paper-item value="DIAMETER">
							DIAMETER
						</paper-item>
					</paper-listbox>
				</paper-dropdown-menu>
				<div class="buttons">
					<paper-button
							raised
							class="add-button"
							onclick="_submitClientForm()">
						Submit
					</paper-button>
					<paper-button
							class="cancel-button"
							dialog-confirm
							autofocus
							onclick="clientAddModal.close()">
						Cancel
					</paper-button>
				</div>
			</form>
				<paper-toast id="toastSuccess" class="fit-bottom">
					<h2>client added</h2>
				</paper-toast>
		</paper-dialog>
		<iron-ajax
				id="clientAddAjax"
				url="/ocs/v1/client"
				method = "post"
				headers='{"Accept": "application/json", "Content-type": "application/json"}'
				on-loading-changed="_onLoadingChanged"
				client-as="json"
				debounce-duration="300">
		</iron-ajax>
		<script>
			function _submitClientForm() {
				document.getElementById('clientAddForm').submit();
			}
		</script>
	</template>
	<script>
		Polymer (
			{
				is: 'sig-client-add',
				listeners: {
					'clientAddForm.iron-form-presubmit': '_clientFormPreSubmit',
					'clientAddForm.iron-form-submit': '_handleFormSubmit',
					'clientAddForm.iron-form-response': '_clientFormResponse',
				},
				_clientFormPreSubmit: function() {
					var form = document.getElementById('clientAddForm');
					var formData = new Object();
					formData.id = document.getElementById("add-client1").value;
					formData.port = parseInt(document.getElementById("add-client2").value);
					formData.protocol = document.getElementById("add-client3").value;
					formData.secret = document.getElementById("add-client4").value;
					var ajax = document.getElementById("clientAddAjax");
					ajax.body = formData;
					ajax.generateRequest();
				},
				_handleFormSubmit: function() {
               var form = document.getElementById('clientAddForm');
               form.request.headers='{"Content-Type": "application/json"}';
               form.request.contentType = "application/json";
            },
				_onLoadingChanged: function(event) {
					if (document.getElementById("clientAddAjax").loading) {
						document.getElementById('progress').disabled = false;
					} else {
						document.getElementById('progress').disabled = true;
					}
				},
				_clientFormResponse: function(event) {
					var toast = document.getElementById("toastSuccess");
					toast.open();
					toast.duration = 4;
					document.getElementById("clientAddForm").reset();
					document.getElementById("getClients").generateRequest();
				},
				toastErrorClose: function(event) {
               var toast = document.getElementById("toastError");
               toast.close();
            }
			}
		);
	</script>
</dom-module>
{'fraction_non_alphanumeric': 0.15628850345938775, 'fraction_numerical': 0.008529997156667614, 'mean_word_length': 3.1250977326035967, 'pattern_counts': {'":': 5, '<': 125, '<?xml version=': 0, '>': 125, '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': '2461628', 'n_tokens_mistral': 4356, 'n_tokens_neox': 3292, 'n_words': 554}