浏览代码

Add save button functionality

sbkwgh 8 年之前
父节点
当前提交
582db1b852
共有 1 个文件被更改,包括 49 次插入4 次删除
  1. 49 4
      src/components/AdminForumInfo.vue

+ 49 - 4
src/components/AdminForumInfo.vue

@@ -3,9 +3,17 @@
 		<div class='cateogry_widget__text'>
 			<div class='category_widget__text__title'>Forum info</div>
 		</div>
-		<fancy-input placeholder='Forum name' v-model='name'></fancy-input>
-		<fancy-input placeholder='Forum description' v-model='description'></fancy-input>
-		<loading-button :loading='loading'>Save settings</loading-button>
+		<fancy-input
+			placeholder='Forum name'
+			v-model='name'
+			:error='errors.forumName'
+		></fancy-input>
+		<fancy-input
+			placeholder='Forum description'
+			v-model='description'
+			:error='errors.forumDescription'
+		></fancy-input>
+		<loading-button :loading='loading' @click='save'>Save settings</loading-button>
 	</div>
 </template>
 
@@ -25,7 +33,44 @@
 			return {
 				name: '',
 				description: '',
-				loading: false
+				loading: false,
+				errors: {
+					forumName: '',
+					forumDescription: ''
+				}
+			}
+		},
+		methods: {
+			save () {
+				this.errors.forumName = ''
+				this.errors.forumDescription = ''
+
+				if(!this.name.trim().length) {
+					this.errors.forumName = 'Forum name can\'t be blank'
+					return
+				}
+
+				this.loading = true
+
+				let settingsReq = this.axios.put('/api/v1/settings', {
+					forumName: this.name,
+					forumDescription: this.description
+				})
+
+				settingsReq.then(res => {
+					this.loading = false
+					this.$store.commit('setForumName', res.data.forumName)
+				}).catch(e => {
+					this.loading = false
+
+					AjaxErrorHandler(this.$store)(err, (error, modalErrors) => {
+						if(this.errors[error.path] !== undefined) {
+							this.errors[error.path] = error.message
+						} else {
+							modalErrors.push(error.message)
+						}
+					})
+				})
 			}
 		},
 		mounted () {