2020 -
2121 -->
2222<template >
23- <form v-if =" !showCollaboratorView" class =" album-creation- form" >
23+ <form v-if =" !showCollaboratorView" class =" album-form" >
2424 <div class =" form-inputs" >
2525 <input ref =" nameInput"
2626 v-model =" albumName"
2727 type =" text"
2828 name =" name"
2929 required
3030 autofocus =" true"
31- :placeholder =" t('photos', 'Name of the new album')" >
32- <label >
31+ :placeholder =" t('photos', 'Name of the album')" >
32+ <label v-if = " !editMode " >
3333 <MapMarker /><input v-model =" albumLocation"
34- type =" text"
3534 name =" location"
36- :placeholder =" t('photos', 'Add location')" >
35+ type =" text"
36+ :placeholder =" t('photos', 'Location of the album')" >
3737 </label >
3838 </div >
3939 <div class =" form-buttons" >
4747 </span >
4848 <span class =" right-buttons" >
4949
50- <Button :aria-label =" t (' photo' , ' Go to the add collaborators view.' )"
50+ <Button v-if =" ! editMode "
51+ :aria-label =" t (' photo' , ' Go to the add collaborators view.' )"
5152 type="secondary"
5253 :disabled =" albumName .trim () === ' ' || loading "
5354 @click =" showCollaboratorView = true " >
5657 </template >
5758 {{ t('photo', 'Add collaborators') }}
5859 </Button >
59- <Button :aria-label =" t (' photo' , ' Create the album.' )"
60+ <Button :aria-label =" editMode ? t ( ' photo ' , ' Save. ' ) : t (' photo' , ' Create the album.' )"
6061 type="primary"
6162 :disabled =" albumName .trim () === ' ' || loading "
62- @click =" createAlbum " >
63+ @click =" submit () " >
6364 <template #icon >
6465 <Loader v-if =" loading " />
6566 <Send v-else />
6667 </template >
67- {{ t('photo', 'Create album') }}
68+ {{ editMode ? t('photo', 'Save') : t('photo', 'Create album') }}
6869 </Button >
6970 </span >
7071 </div >
7172 </form >
7273 <CollaboratorsSelectionForm v-else
7374 class="add-collaborators-form"
74- @cancel =" showCollaboratorView = true "
75- @submit =" createAlbum " >
75+ @cancel =" showCollaboratorView = true " >
7676 <template slot-scope="{collaborators}">
7777 <span class =" left-buttons" >
7878 <Button :aria-label =" t (' photo' , ' Back to the new album form.' )"
8282 </Button >
8383 </span >
8484 <span class =" right-buttons" >
85- <Button :aria-label =" t (' photo' , ' Create the album.' )"
85+ <Button :aria-label =" editMode ? t ( ' photo ' , ' Save. ' ) : t (' photo' , ' Create the album.' )"
8686 type="primary"
8787 :disabled =" albumName .trim () === ' ' || loading "
88- @click =" createAlbum (collaborators )" >
88+ @click =" submit (collaborators )" >
8989 <template #icon >
9090 <Loader v-if =" loading " />
9191 <Send v-else />
9292 </template >
93- {{ t('photo', 'Create album') }}
93+ {{ editMode ? t('photo', 'Save') : t('photo', 'Create album') }}
9494 </Button >
9595 </span >
9696 </template >
9797 </CollaboratorsSelectionForm >
9898</template >
9999<script >
100+ import { mapActions } from ' vuex'
100101import MapMarker from ' vue-material-design-icons/MapMarker'
101102import AccountMultiplePlus from ' vue-material-design-icons/AccountMultiplePlus'
102103import Send from ' vue-material-design-icons/Send'
103104
104105import { Button } from ' @nextcloud/vue'
106+ import moment from ' @nextcloud/moment'
105107
106- import Loader from ' ../components /Loader.vue'
107- import CollaboratorsSelectionForm from ' ../components /CollaboratorsSelectionForm.vue'
108+ import Loader from ' ./Loader.vue'
109+ import CollaboratorsSelectionForm from ' ./CollaboratorsSelectionForm.vue'
108110
109111export default {
110- name: ' AlbumCreationForm ' ,
112+ name: ' AlbumForm ' ,
111113
112114 components: {
113115 Button,
@@ -119,6 +121,10 @@ export default {
119121 },
120122
121123 props: {
124+ album: {
125+ type: Object ,
126+ default: null ,
127+ },
122128 displayBackButton: {
123129 type: Boolean ,
124130 default: false ,
@@ -134,24 +140,57 @@ export default {
134140 }
135141 },
136142
143+ computed: {
144+ editMode () {
145+ return this .album !== null
146+ },
147+ },
148+
137149 mounted () {
150+ if (this .editMode ) {
151+ this .albumName = this .album .basename
152+ this .albumLocation = this .album .location
153+ }
154+
138155 this .$nextTick (() => {
139156 this .$refs .nameInput .focus ()
140157 })
141158 },
142159
143160 methods: {
144- async createAlbum (collaborators = []) {
161+ ... mapActions ([' createAlbum' , ' renameAlbum' ]),
162+
163+ submit (collaborators = []) {
164+ if (this .editMode ) {
165+ this .handleUpdateAlbum (collaborators)
166+ } else {
167+ this .handleCreateAlbum (collaborators)
168+ }
169+ },
170+
171+ async handleCreateAlbum (collaborators = []) {
145172 try {
146173 this .loading = true
147- const album = await this .$store . dispatch ( ' createAlbum' , {
174+ const album = await this .createAlbum ( {
148175 album: {
149- name: this .albumName ,
176+ basename: this .albumName ,
177+ size: 0 ,
178+ lastmod: moment ().unix (),
150179 location: this .albumLocation ,
151180 collaborators,
152181 },
153182 })
154- this .$emit (' album-created' , { album })
183+ this .$emit (' done' , { album })
184+ } finally {
185+ this .loading = false
186+ }
187+ },
188+
189+ async handleUpdateAlbum (collaborators = []) {
190+ try {
191+ this .loading = true
192+ const album = await this .renameAlbum ({ currentAlbumName: this .album .basename , newAlbumName: this .albumName })
193+ this .$emit (' done' , { album })
155194 } finally {
156195 this .loading = false
157196 }
@@ -164,7 +203,7 @@ export default {
164203}
165204 </script >
166205<style lang="scss" scoped>
167- .album-creation- form {
206+ .album-form {
168207 display : flex ;
169208 flex-direction : column ;
170209 height : 350px ;
0 commit comments