refactor: admin-edit-user -> vue + fixes

pull/128/head
NGPixel 8 years ago
parent d590c67d50
commit 33c05b327b

@ -74,6 +74,7 @@ import pageLoaderComponent from './components/page-loader.vue'
import searchComponent from './components/search.vue'
import treeComponent from './components/tree.vue'
import adminEditUserComponent from './pages/admin-edit-user.component.js'
import adminProfileComponent from './pages/admin-profile.component.js'
import adminSettingsComponent from './pages/admin-settings.component.js'
import contentViewComponent from './pages/content-view.component.js'
@ -163,6 +164,7 @@ $(() => {
mixins: [helpers],
components: {
alert: alertComponent,
adminEditUser: adminEditUserComponent,
adminProfile: adminProfileComponent,
adminSettings: adminSettingsComponent,
anchor: anchorComponent,

@ -8,11 +8,11 @@
.modal-content(v-show='isShown')
header.is-blue
span {{ $t('modal.createusertitle') }}
p.modal-notify(v-bind:class='{ "is-active": isLoading }'): i
p.modal-notify(:class='{ "is-active": isLoading }'): i
section
label.label {{ $t('modal.createuseremail') }}
p.control.is-fullwidth
input.input(type='text', v-bind:placeholder='$t("modal.createuseremailplaceholder")', v-model='email', ref='createUserEmailInput')
input.input(type='text', :placeholder='$t("modal.createuseremailplaceholder")', v-model='email', ref='createUserEmailInput')
section
label.label {{ $t('modal.createuserprovider') }}
p.control.is-fullwidth
@ -30,11 +30,11 @@
section(v-if='provider=="local"')
label.label {{ $t('modal.createuserfullname') }}
p.control.is-fullwidth
input.input(type='text', v-bind:placeholder='$t("modal.createusernameplaceholder")', v-model='name')
input.input(type='text', :placeholder='$t("modal.createusernameplaceholder")', v-model='name')
footer
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.discard') }}
a.button(v-on:click='create', v-if='provider=="local"', v-bind:disabled='isLoading', v-bind:class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuser') }}
a.button(v-on:click='create', v-if='provider!="local"', v-bind:disabled='isLoading', v-bind:class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuserauthorize') }}
a.button.is-grey.is-outlined(@click='cancel') {{ $t('modal.discard') }}
a.button(@click='create', v-if='provider=="local"', :disabled='isLoading', :class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuser') }}
a.button(@click='create', v-if='provider!="local"', :disabled='isLoading', :class='{ "is-disabled": isLoading, "is-blue": !loading }') {{ $t('modal.createuserauthorize') }}
</template>
<script>
@ -96,10 +96,10 @@
msg: 'Error: ' + err.body.msg
})
})
}
},
mounted() {
this.$root.$on('modalCreateUser/init', this.init)
}
}
}
</script>

@ -12,8 +12,8 @@
section
span {{ $t('modal.deleteuserwarning') }}
footer
a.button.is-grey.is-outlined(v-on:click='cancel') {{ $t('modal.abort') }}
a.button.is-red(v-on:click='deleteUser') {{ $t('modal.delete') }}
a.button.is-grey.is-outlined(@click='cancel') {{ $t('modal.abort') }}
a.button.is-red(@click='deleteUser') {{ $t('modal.delete') }}
</template>
<script>
@ -35,7 +35,7 @@
this.isLoading = false
this.$store.dispatch('modalDeleteUser/close')
},
discard: function () {
deleteUser: function () {
let self = this
this.isLoading = true
this.$http.delete('/admin/users/' + this.currentUser).then(resp => {

@ -0,0 +1,74 @@
'use strict'
export default {
name: 'admin-edit-user',
props: ['usrdata'],
data() {
return {
id: '',
email: '',
password: '********',
name: '',
rights: [],
roleoverride: 'none'
}
},
methods: {
addRightsRow() {
this.rights.push({
role: 'write',
path: '/',
exact: false,
deny: false
})
},
removeRightsRow(idx) {
this._.pullAt(this.rights, idx)
this.$forceUpdate()
},
saveUser() {
let self = this
let formattedRights = this._.cloneDeep(this.rights)
switch (this.roleoverride) {
case 'admin':
formattedRights.push({
role: 'admin',
path: '/',
exact: false,
deny: false
})
break
}
this.$http.post(window.location.href, {
password: this.password,
name: this.name,
rights: JSON.stringify(formattedRights)
}).then(resp => {
self.$store.dispatch('alert', {
style: 'green',
icon: 'check',
msg: 'Changes have been applied successfully.'
})
}).catch(err => {
self.$store.dispatch('alert', {
style: 'red',
icon: 'square-cross',
msg: 'Error: ' + err.body.msg
})
})
}
},
mounted() {
let usr = JSON.parse(this.usrdata)
this.id = usr._id
this.email = usr.email
this.name = usr.name
if (this._.find(usr.rights, { role: 'admin' })) {
this.rights = this._.reject(usr.rights, ['role', 'admin'])
this.roleoverride = 'admin'
} else {
this.rights = usr.rights
}
}
}

@ -1,72 +0,0 @@
'use strict'
/* global usrData */
import $ from 'jquery'
import _ from 'lodash'
import Vue from 'vue'
module.exports = (alerts) => {
if ($('#page-type-admin-users-edit').length) {
let vueEditUser = new Vue({
el: '#page-type-admin-users-edit',
data: {
id: '',
email: '',
password: '********',
name: '',
rights: [],
roleoverride: 'none'
},
methods: {
addRightsRow: (ev) => {
vueEditUser.rights.push({
role: 'write',
path: '/',
exact: false,
deny: false
})
},
removeRightsRow: (idx) => {
_.pullAt(vueEditUser.rights, idx)
vueEditUser.$forceUpdate()
},
saveUser: (ev) => {
let formattedRights = _.cloneDeep(vueEditUser.rights)
switch (vueEditUser.roleoverride) {
case 'admin':
formattedRights.push({
role: 'admin',
path: '/',
exact: false,
deny: false
})
break
}
$.post(window.location.href, {
password: vueEditUser.password,
name: vueEditUser.name,
rights: JSON.stringify(formattedRights)
}).done((resp) => {
alerts.pushSuccess('Saved successfully', 'Changes have been applied.')
}).fail((jqXHR, txtStatus, resp) => {
alerts.pushError('Error', resp)
})
}
},
created: function () {
this.id = usrData._id
this.email = usrData.email
this.name = usrData.name
if (_.find(usrData.rights, { role: 'admin' })) {
this.rights = _.reject(usrData.rights, ['role', 'admin'])
this.roleoverride = 'admin'
} else {
this.rights = usrData.rights
}
}
})
require('../modals/admin-users-delete.js')(alerts)
}
}

@ -22,6 +22,7 @@
"discard": "Discard",
"edit": "Edit",
"history": "History",
"home": "Home",
"login": "Login",
"logout": "Logout",
"move": "Move",

@ -1,7 +1,7 @@
extends ../../layout.pug
block rootNavCenter
h2.nav-item= t('nav.account')
h2.nav-item= t('nav.settings')
block rootNavRight
loading-spinner
@ -48,7 +48,7 @@ block content
a(href='/admin/settings')
i.icon-cog
span= t('nav.syssettings')
li
//-li
a(href='/admin/theme')
i.icon-drop
span= t('nav.theme')

@ -8,9 +8,10 @@ block rootNavRight
span= t('admin:users.returntousers')
block adminContent
#page-type-admin-users-edit
admin-edit-user(inline-template, usrdata=JSON.stringify(usr))
div
.hero
h1.title#title= t('admin:users.edituser')
h1.title= t('admin:users.edituser')
h2.subtitle= usr.email
table.table
thead
@ -118,6 +119,3 @@ block adminContent
span Delete Account
modal-delete-user(current-user=usr._id)
script(type='text/javascript').
var usrData = !{JSON.stringify(usr)};

Loading…
Cancel
Save