2017-04-01 21:07:01 +00:00
|
|
|
'use strict'
|
2017-01-04 05:07:15 +00:00
|
|
|
|
2017-05-21 03:21:16 +00:00
|
|
|
/* global usrData */
|
2017-01-31 00:43:37 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
import $ from 'jquery'
|
|
|
|
import _ from 'lodash'
|
|
|
|
import Vue from 'vue'
|
2017-01-31 00:43:37 +00:00
|
|
|
|
2017-04-01 21:07:01 +00:00
|
|
|
module.exports = (alerts) => {
|
2017-05-21 03:21:16 +00:00
|
|
|
if ($('#page-type-admin-users').length) {
|
2017-04-01 21:07:01 +00:00
|
|
|
require('../modals/admin-users-create.js')(alerts)
|
|
|
|
} else 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'
|
2017-02-19 21:13:51 +00:00
|
|
|
},
|
2017-04-01 21:07:01 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
2017-02-19 21:13:51 +00:00
|
|
|
},
|
2017-04-01 21:07:01 +00:00
|
|
|
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)
|
|
|
|
}
|
2017-02-09 01:52:37 +00:00
|
|
|
}
|