Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-05-27 21:40:54 +0300
committerdartcafe <github@dartcafe.de>2020-05-27 21:40:54 +0300
commit9ecaf4e38d83df772bce1f225dc1ca15ce42ff04 (patch)
tree4a17966ec99a7e0a6d91823d67587cd3dd0863f5 /src/js/store/modules/subModules/shares.js
parentc85fe41a3ac46678d586cdf0a5cb2c39521473e5 (diff)
namespaced shares.js submodule
Diffstat (limited to 'src/js/store/modules/subModules/shares.js')
-rw-r--r--src/js/store/modules/subModules/shares.js142
1 files changed, 142 insertions, 0 deletions
diff --git a/src/js/store/modules/subModules/shares.js b/src/js/store/modules/subModules/shares.js
new file mode 100644
index 00000000..ff560d85
--- /dev/null
+++ b/src/js/store/modules/subModules/shares.js
@@ -0,0 +1,142 @@
+/*
+ * @copyright Copyright (c) 2019 Rene Gieling <github@dartcafe.de>
+ *
+ * @author Rene Gieling <github@dartcafe.de>
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import axios from '@nextcloud/axios'
+import { generateUrl } from '@nextcloud/router'
+
+const defaultShares = () => {
+ return {
+ shares: [],
+ }
+}
+
+const state = defaultShares()
+
+const namespaced = true
+
+const mutations = {
+ set(state, payload) {
+ state.shares = payload.shares
+ },
+
+ delete(state, payload) {
+ state.shares = state.shares.filter(share => {
+ return share.id !== payload.share.id
+ })
+ },
+
+ reset(state) {
+ Object.assign(state, defaultShares())
+ },
+
+ add(state, payload) {
+ state.shares.push(payload)
+ },
+
+}
+
+const getters = {
+ invitation: state => {
+ const invitationTypes = ['user', 'group', 'email', 'external', 'contact']
+ return state.shares.filter(share => {
+ return invitationTypes.includes(share.type)
+ })
+ },
+
+ public: state => {
+ const invitationTypes = ['public']
+ return state.shares.filter(share => {
+ return invitationTypes.includes(share.type)
+ })
+ },
+
+}
+
+const actions = {
+ addPersonal(context, payload) {
+ const endPoint = 'apps/polls/share/create/s/'
+
+ return axios.post(generateUrl(endPoint), { token: payload.token, userName: payload.userName })
+ .then((response) => {
+ return { token: response.data.token }
+ }, (error) => {
+ console.error('Error writing share', { error: error.response }, { payload: payload })
+ throw error
+ })
+
+ },
+
+ add(context, payload) {
+ const endPoint = 'apps/polls/share/write/'
+ payload.share.pollId = context.rootState.poll.id
+ return axios.post(generateUrl(endPoint), { pollId: context.rootState.poll.id, share: payload.share })
+ .then((response) => {
+ context.commit('add', response.data.share)
+
+ if (response.data.sendResult.sentMails.length > 0) {
+ const sendList = response.data.sendResult.sentMails.map(element => {
+
+ if (element.displayName) {
+ return element.displayName
+ } else if (element.userId) {
+ return element.userId
+ } else if (element.eMailAddress) {
+ return element.eMailAddress
+ }
+ })
+ OC.Notification.showTemporary(t('polls', 'Invitation mail sent to %n.', 1, sendList.join(', ')), { type: 'success' })
+ }
+
+ if (response.data.sendResult.abortedMails.length > 0) {
+ const errorList = response.data.sendResult.abortedMails.map(element => {
+ if (element.displayName) {
+ return element.displayName
+ } else if (element.userId) {
+ return element.userId
+ } else if (element.eMailAddress) {
+ return element.eMailAddress
+ }
+ })
+ OC.Notification.showTemporary(t('polls', 'Error sending invitation mail to %n.', 1, errorList.join(', ')), { type: 'error' })
+ }
+ return response.data
+ }, (error) => {
+ console.error('Error writing share', { error: error.response }, { payload: payload })
+ throw error
+ })
+ },
+
+ delete(context, payload) {
+ const endPoint = 'apps/polls/share/remove/'
+ return axios.post(generateUrl(endPoint), { share: payload.share })
+ .then(() => {
+ context.commit('delete', { share: payload.share })
+ }, (error) => {
+ console.error('Error removing share', { error: error.response }, { payload: payload })
+ throw error
+ })
+ },
+
+}
+
+export default { namespaced, state, mutations, actions, getters }