You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.3 KiB

  1. 'use strict'
  2. /* global usrData, usrDataName */
  3. import $ from 'jquery'
  4. import _ from 'lodash'
  5. import Vue from 'vue'
  6. module.exports = (alerts) => {
  7. if ($('#page-type-admin-profile').length) {
  8. let vueProfile = new Vue({
  9. el: '#page-type-admin-profile',
  10. data: {
  11. password: '********',
  12. passwordVerify: '********',
  13. name: ''
  14. },
  15. methods: {
  16. saveUser: (ev) => {
  17. if (vueProfile.password !== vueProfile.passwordVerify) {
  18. alerts.pushError('Error', "Passwords don't match!")
  19. return
  20. }
  21. $.post(window.location.href, {
  22. password: vueProfile.password,
  23. name: vueProfile.name
  24. }).done((resp) => {
  25. alerts.pushSuccess('Saved successfully', 'Changes have been applied.')
  26. }).fail((jqXHR, txtStatus, resp) => {
  27. alerts.pushError('Error', resp)
  28. })
  29. }
  30. },
  31. created: function () {
  32. this.name = usrDataName
  33. }
  34. })
  35. } else if ($('#page-type-admin-users').length) {
  36. require('../modals/admin-users-create.js')(alerts)
  37. } else if ($('#page-type-admin-users-edit').length) {
  38. let vueEditUser = new Vue({
  39. el: '#page-type-admin-users-edit',
  40. data: {
  41. id: '',
  42. email: '',
  43. password: '********',
  44. name: '',
  45. rights: [],
  46. roleoverride: 'none'
  47. },
  48. methods: {
  49. addRightsRow: (ev) => {
  50. vueEditUser.rights.push({
  51. role: 'write',
  52. path: '/',
  53. exact: false,
  54. deny: false
  55. })
  56. },
  57. removeRightsRow: (idx) => {
  58. _.pullAt(vueEditUser.rights, idx)
  59. vueEditUser.$forceUpdate()
  60. },
  61. saveUser: (ev) => {
  62. let formattedRights = _.cloneDeep(vueEditUser.rights)
  63. switch (vueEditUser.roleoverride) {
  64. case 'admin':
  65. formattedRights.push({
  66. role: 'admin',
  67. path: '/',
  68. exact: false,
  69. deny: false
  70. })
  71. break
  72. }
  73. $.post(window.location.href, {
  74. password: vueEditUser.password,
  75. name: vueEditUser.name,
  76. rights: JSON.stringify(formattedRights)
  77. }).done((resp) => {
  78. alerts.pushSuccess('Saved successfully', 'Changes have been applied.')
  79. }).fail((jqXHR, txtStatus, resp) => {
  80. alerts.pushError('Error', resp)
  81. })
  82. }
  83. },
  84. created: function () {
  85. this.id = usrData._id
  86. this.email = usrData.email
  87. this.name = usrData.name
  88. if (_.find(usrData.rights, { role: 'admin' })) {
  89. this.rights = _.reject(usrData.rights, ['role', 'admin'])
  90. this.roleoverride = 'admin'
  91. } else {
  92. this.rights = usrData.rights
  93. }
  94. }
  95. })
  96. require('../modals/admin-users-delete.js')(alerts)
  97. } else if ($('#page-type-admin-settings').length) {
  98. let vueSettings = new Vue({ // eslint-disable-line no-unused-vars
  99. el: '#page-type-admin-settings',
  100. data: {
  101. upgradeModal: {
  102. state: false,
  103. step: 'confirm',
  104. mode: 'upgrade',
  105. error: 'Something went wrong.'
  106. }
  107. },
  108. methods: {
  109. upgrade: (ev) => {
  110. vueSettings.upgradeModal.mode = 'upgrade'
  111. vueSettings.upgradeModal.step = 'confirm'
  112. vueSettings.upgradeModal.state = true
  113. },
  114. reinstall: (ev) => {
  115. vueSettings.upgradeModal.mode = 're-install'
  116. vueSettings.upgradeModal.step = 'confirm'
  117. vueSettings.upgradeModal.state = true
  118. },
  119. upgradeCancel: (ev) => {
  120. vueSettings.upgradeModal.state = false
  121. },
  122. upgradeStart: (ev) => {
  123. vueSettings.upgradeModal.step = 'running'
  124. $.post('/admin/settings/install', {
  125. mode: vueSettings.upgradeModal.mode
  126. }).done((resp) => {
  127. // todo
  128. }).fail((jqXHR, txtStatus, resp) => {
  129. vueSettings.upgradeModal.step = 'error'
  130. vueSettings.upgradeModal.error = jqXHR.responseText
  131. })
  132. },
  133. flushcache: (ev) => {
  134. window.alert('Coming soon!')
  135. },
  136. resetaccounts: (ev) => {
  137. window.alert('Coming soon!')
  138. },
  139. flushsessions: (ev) => {
  140. window.alert('Coming soon!')
  141. }
  142. }
  143. })
  144. }
  145. }