<commit_before><link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="toast-ajax/toast-ajax.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">

<polymer-element name="edit-group" attributes="gid name info">
	<template>
		<link rel="stylesheet" type="text/css" href="../css/shared-styles.css">
		<style>
			:host {
				display: inherit;
			}
			paper-button {
				width: 100%;
			}
		</style>
		<!-- Edit group API. -->
		<toast-ajax id="editAPI"
			method="PUT"
			url="{{'http://urop2014.dtg.cl.cam.ac.uk/UROP_UI/api/group/' + gid }}"
			on-core-response="{{editResponse}}"
			contentType="application/json"
			
			waitMessage="Saving changes..."
            waitBeforeToast="1000"
            captureError
            popUpError
            errorMessage="Error Saving changes.">
		</toast-ajax>

		<!-- Edit button. -->
		<paper-icon-button id="editButton"
			icon="create"
			on-click="{{toggleDialog}}">
		</paper-icon-button>

		<!-- Edit dialog -->
		<paper-dialog id="editGroupDialog" heading="Edit Group:" backdrop	
				transition="core-transition-top">
			<paper-input id="editGroupName"
				required
				floatingLabel
				label="Group name..."
				error="Required."
				on-input="{{handleNameInput}}"
				value="{{newName}}">
			</paper-input>
			<h2 class="subtitle">Group Info:</h2>
			<paper-input id="editGroupInfo"
				multiline
				maxRows="5"
				label=""
				value="{{newInfo}}"
				error="Invalid group name.">
			</paper-input>
			
			<template if="{{showSubmit}}">
				<paper-button id="editSubmit" class="dialogSubmit" label="EDIT" on-click="{{editButtonClicked}}" affirmative></paper-button>
			</template>
		</paper-dialog>

	</template>
	<script>
	Polymer('edit-group', {
		domReady: function() {
			this.newName = this.name;
			this.newInfo = this.info;
			
		},
		
		handleNameInput: function () {
			if (this.$.editGroupName.inputValue === "") {
				this.showSubmit = false;
			}
			else {
				this.showSubmit = true;
			}
		},

		toggleDialog: function () {
			this.$.editGroupDialog.toggle();
		},

		editButtonClicked: function () {

			var name = this.$.editGroupName.inputValue;
			var info = encodeURI(this.$.editGroupInfo.inputValue);
			var api = this.$.editAPI;

			api.body = '{"name":"' + name + '", "info":"' + info + '"}';
			api.go();
		}, 
		
		editResponse: function () {
			this.name = this.newName;
			this.info = this.newInfo;
		}

	});
	</script>
</polymer-element><commit_msg>Fixed edit group button hiding and multiline input.<commit_after><link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="toast-ajax/toast-ajax.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">

<polymer-element name="edit-group" attributes="gid name info">
	<template>
		<link rel="stylesheet" type="text/css" href="../css/shared-styles.css">
		<style>
			:host {
				display: inherit;
			}
			paper-button {
				width: 100%;
			}
			#editGroupInfo {
				width: 100%;
				outline: none;
				border-bottom: 1px solid #757575;
			}

		</style>
		<!-- Edit group API. -->
		<toast-ajax id="editAPI"
			method="PUT"
			url="{{'http://urop2014.dtg.cl.cam.ac.uk/UROP_UI/api/group/' + gid }}"
			on-core-response="{{editResponse}}"
			handleAs="json"
			contentType="application/json"
			waitMessage="Saving changes..."
            waitBeforeToast="1000"
            captureError
            popUpError
            errorMessage="Error Saving changes.">
		</toast-ajax>

		<!-- Edit button. -->
		<paper-icon-button id="editButton"
			icon="create"
			on-click="{{toggleDialog}}">
		</paper-icon-button>

		<!-- Edit dialog -->
		<paper-dialog id="editGroupDialog" heading="Edit Group:" backdrop	
				transition="core-transition-top">
			<paper-input id="editGroupName"
				required
				floatingLabel
				label="Group name..."
				error="Required."
				on-input="{{handleNameInput}}"
				value="{{newName}}">
			</paper-input>
			<h2 class="subtitle">Group Info:</h2>
			<textarea id="editGroupInfo" rows="3">{{newInfo}}</textarea>
			
			<template if="{{!$.editGroupName.invalid}}">
				<paper-button id="editSubmit" class="dialogSubmit" label="EDIT" on-click="{{editButtonClicked}}" affirmative></paper-button>
			</template>
		</paper-dialog>

	</template>
	<script>
	Polymer('edit-group', {
		domReady: function() {
			this.newName = this.name;
			this.newInfo = this.info;
			
		},

		toggleDialog: function () {
			this.$.editGroupDialog.toggle();
		},

		editButtonClicked: function () {

			var name = this.$.editGroupName.inputValue;
			var info = encodeURI(this.$.editGroupInfo.value);
			var api = this.$.editAPI;

			api.body = '{"name":"' + name + '", "info":"' + info + '"}';
			api.go();
		}, 
		
		editResponse: function () {
			var group = this.$.editAPI.response;
			console.log(group);
		}

	});
	</script>
</polymer-element>
{'fraction_non_alphanumeric': 0.18871775839673408, 'fraction_numerical': 0.007051401002041195, 'mean_word_length': 3.3679092382495948, 'pattern_counts': {'":': 4, '<': 71, '<?xml version=': 0, '>': 71, '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': '356138', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1756, 'n_words': 298}