Browse Source

Save via ajax description

sbkwgh 8 years ago
parent
commit
6b99116c91
1 changed files with 43 additions and 2 deletions
  1. 43 2
      src/components/routes/SettingsGeneral.vue

+ 43 - 2
src/components/routes/SettingsGeneral.vue

@@ -12,7 +12,13 @@
 				:error='description.error'
 				type='password'
 			></fancy-textarea>
-			<loading-button class='button button--green'>Save description</loading-button>
+			<loading-button
+				class='button button--green'
+				:loading='description.loading'
+				@click='saveDescription'
+			>
+				Save description
+			</loading-button>
 		</p>
 	</div>
 </template>
@@ -21,6 +27,8 @@
 	import FancyTextarea from '../FancyTextarea'
 	import LoadingButton from '../LoadingButton'
 
+	import AjaxErrorHandler from '../../assets/js/errorHandler'
+
 	export default {
 		name: 'settingsGeneral',
 		components: {
@@ -31,12 +39,45 @@
 			return {
 				description: {
 					value: '',
+					loading: false,
 					error: ''
 				}
 			}
 		},
 		computed: {},
-		methods: {}
+		methods: {
+			saveDescription () {
+				this.description.error = ''
+				this.description.loading = true
+
+				this.axios
+					.put('/api/v1/user/' + this.$store.state.username, {
+						description: this.description.value
+					})
+					.then(res => {
+						this.description.loading = false
+					})
+					.catch(e => {
+						this.description.loading = false
+
+						AjaxErrorHandler(this.$store)(e, error => {
+							this.description.error = error.message
+						})
+					})
+			}
+		},
+		created () {
+			this.$nextTick(() => {
+				this.axios
+					.get('/api/v1/user/' + this.$store.state.username)
+					.then(res => {
+						this.description.value = res.data.description || ''
+					})
+					.catch(e => {
+						AjaxErrorHandler(this.$store)(e)
+					})
+			})
+		}
 	}
 </script>