diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-01-23 16:34:11 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-03-01 20:56:17 +0100 |
commit | 51057c539feace8381ab83310b307749fec60f91 (patch) | |
tree | 07e93c511122227849ebfb595c5d88e77eb868a0 /apps | |
parent | 7a4b2db2a7a624081de2d9264129358857f2b6e5 (diff) | |
download | nextcloud-server-51057c539feace8381ab83310b307749fec60f91.tar.gz nextcloud-server-51057c539feace8381ab83310b307749fec60f91.zip |
Use proper public javascript methods
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/src/collaborationresources.js | 58 | ||||
-rw-r--r-- | apps/files_sharing/src/components/CollectionListItem.vue | 17 | ||||
-rw-r--r-- | apps/files_sharing/src/files_sharing.js | 19 | ||||
-rw-r--r-- | apps/files_sharing/src/views/CollaborationView.vue | 18 |
4 files changed, 47 insertions, 65 deletions
diff --git a/apps/files_sharing/src/collaborationresources.js b/apps/files_sharing/src/collaborationresources.js index 3b0a12c5b2b..0370c367bb7 100644 --- a/apps/files_sharing/src/collaborationresources.js +++ b/apps/files_sharing/src/collaborationresources.js @@ -36,55 +36,10 @@ import View from './views/CollaborationView' let selectAction = {}; let icons = {}; let types = {}; - -window.Collaboration = { - /** - * - * @param type - * @param {callback} selectCallback should return a promise - */ - registerType(type, typeDefinition) { - types[type] = typeDefinition; - }, - trigger(type) { - return types[type].action() - }, - getTypes() { - return Object.keys(types); - }, - getIcon(type) { - return types[type].icon; - }, - getLabel(type) { - return t('files_sharing', 'Link to a {label}', { label: types[type].typeString || type }, 1) - }, - getLink(type, id) { - /* TODO: Allow action to be executed instead of href as well */ - return types[type].link(id); - } -} - -window.Collaboration.registerType('files', { - action: () => { - return new Promise((resolve, reject) => { - OC.dialogs.filepicker('Link to a file', function (f) { - const client = OC.Files.getClient(); - client.getFileInfo(f).then((status, fileInfo) => { - resolve(fileInfo.id) - }, () => { - reject() - }) - }, false); - }) - }, - link: (id) => OC.generateUrl('/f/') + id, - icon: 'nav-icon-files', - /** used in "Link to a {typeString}" */ - typeString: 'file' -}); +console.log('register types'); /* TODO: temporary data for testing */ -window.Collaboration.registerType('calendar', { +window.OCP.Collaboration.registerType('calendar', { action: () => { return new Promise((resolve, reject) => { var id = window.prompt("calendar id", "1"); @@ -92,9 +47,10 @@ window.Collaboration.registerType('calendar', { }) }, icon: 'icon-calendar-dark', - typeName: 'calendar', + typeString: 'calendar', + link: (id) => '#' + id, }); -window.Collaboration.registerType('contact', { +window.OCP.Collaboration.registerType('contact', { action: () => { return new Promise((resolve, reject) => { var id = window.prompt("contacts id", "1"); @@ -102,7 +58,9 @@ window.Collaboration.registerType('contact', { }) }, icon: 'icon-contacts-dark', - typeName: 'contact', + link: (id) => '#' + id, + /** used in "Link to a {typeString}" */ + typeString: 'contact' }); export { Vue, View } diff --git a/apps/files_sharing/src/components/CollectionListItem.vue b/apps/files_sharing/src/components/CollectionListItem.vue index 8819497ca66..aebab670ac2 100644 --- a/apps/files_sharing/src/components/CollectionListItem.vue +++ b/apps/files_sharing/src/components/CollectionListItem.vue @@ -24,11 +24,12 @@ <li class="collection-list"> <avatar :displayName="collection.name" :allowPlaceholder="true"></avatar> <span class="username" title="">{{ collection.name }}</span> - <div class="linked-icons"> - <transition name="fade"> - <a v-if="!detailsOpen" v-for="resource in collection.resources" :href="getLink(resource)" v-tooltip="resource.name"><span :class="getIcon(resource)"></span></a> - </transition> - </div> + <transition name="fade"> + <div class="linked-icons" v-if="!detailsOpen"> + <a v-for="resource in collection.resources" :href="getLink(resource)" v-tooltip="resource.name" :key="resource.id"><span :class="getIcon(resource)"></span></a> + </div> + </transition> + <span class="sharingOptionsGroup"> <div class="share-menu" v-click-outside="close"> <a href="#" class="icon icon-more" @click="toggle"></a> @@ -41,7 +42,7 @@ <transition name="fade"> <ul class="resource-list-details" v-if="detailsOpen" v-click-outside="hideDetails"> <li v-for="resource in collection.resources"> - <a :href="getLink(resource)"><span :class="getIcon(resource)"></span> {{ resource.name }}</a> + <a :href="getLink(resource)"><span :class="getIcon(resource)"></span> {{ resource.name || '' }}</a> <span class="icon-delete"></span> </li> </ul> @@ -91,10 +92,10 @@ ] }, getIcon() { - return (resource) => [window.Collaboration.getIcon(resource.type)] + return (resource) => [window.OCP.Collaboration.getIcon(resource.type)] }, getLink() { - return (resource) => window.Collaboration.getLink(resource.type, resource.id) + return (resource) => window.OCP.Collaboration.getLink(resource.type, resource.id) } }, methods: { diff --git a/apps/files_sharing/src/files_sharing.js b/apps/files_sharing/src/files_sharing.js index c31c8c6e205..9009bdde7ec 100644 --- a/apps/files_sharing/src/files_sharing.js +++ b/apps/files_sharing/src/files_sharing.js @@ -13,4 +13,23 @@ import '../js/sharetabview' import '../js/share' import '../js/sharebreadcrumbview' +window.OCP.Collaboration.registerType('files', { + action: () => { + return new Promise((resolve, reject) => { + OC.dialogs.filepicker('Link to a file', function (f) { + const client = OC.Files.getClient(); + client.getFileInfo(f).then((status, fileInfo) => { + resolve(fileInfo.id) + }, () => { + reject() + }) + }, false); + }) + }, + link: (id) => OC.generateUrl('/f/') + id, + icon: 'nav-icon-files', + /** used in "Link to a {typeString}" */ + typeString: 'file' +}); + window.OCA.Sharing = OCA.Sharing diff --git a/apps/files_sharing/src/views/CollaborationView.vue b/apps/files_sharing/src/views/CollaborationView.vue index e5431ba580e..99a5fb43df6 100644 --- a/apps/files_sharing/src/views/CollaborationView.vue +++ b/apps/files_sharing/src/views/CollaborationView.vue @@ -110,13 +110,13 @@ }, options() { let options = []; - let types = window.Collaboration.getTypes(); + let types = window.OCP.Collaboration.getTypes(); for(let type in types) { options.push({ type: types[type], - title: window.Collaboration.getLabel(types[type]), - class: window.Collaboration.getIcon(types[type]), - action: () => window.Collaboration.trigger(types[type]) + title: window.OCP.Collaboration.getLabel(types[type]), + class: window.OCP.Collaboration.getIcon(types[type]), + action: () => window.OCP.Collaboration.trigger(types[type]) }) } for(let index in this.collections) { @@ -161,13 +161,16 @@ 'Content-Type': 'application/json; charset=UTF-8' } }).then((response) => { - console.log(response.data.ocs.data) + let newCollection = response.data.ocs.data + console.log('Add new collection', newCollection) + this.collections.push(newCollection) + this.addResourceToCollection(newCollection.id, resourceType.toString(), resourceId.toString()) }); }, addResourceToCollection(collectionId, resourceType, resourceId) { /** TODO move to service */ const resourceBase = OC.linkToOCS(`collaboration/resources/collections`, 2); - axios.post(`${resourceBase}${collectionId}?format=json`, { + return axios.post(`${resourceBase}${collectionId}?format=json`, { resourceType, resourceId }, { @@ -176,7 +179,8 @@ 'Content-Type': 'application/json; charset=UTF-8' } }).then((response) => { - console.log(response) + console.log('Add new collection', response.data.ocs.data) + this.collections.find((_item) => _item.id === collectionId).resources.push(response.data.ocs.data) }); } } |