Skip to content

Commit

Permalink
fix: Move to new dialogs APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliushaertl committed Dec 27, 2023
1 parent 5945876 commit 01b1903
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 213 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ module.exports = {
'jsdoc/check-values': 'off',
'jsdoc/valid-types': 'off',
'jsdoc/no-undefined-types': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-property-description': 'off',
}
}
8 changes: 4 additions & 4 deletions cypress/e2e/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ describe('Nextcloud integration', function() {
cy.get('#w2ui-overlay-download-as-menu .menu-text').eq(1).click()
})

cy.get('.oc-dialog').should('be.visible')
cy.get('.oc-dialog input[type=text]')
cy.get('.saveas-dialog').should('be.visible')
cy.get('.saveas-dialog input[type=text]')
.should('be.visible')
.should('have.value', 'document.rtf')
.should('have.value', '/document.rtf')

cy.get('.oc-dialog button.primary').click()
cy.get('.saveas-dialog button.button-vue--vue-primary').click()

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
Expand Down
13 changes: 6 additions & 7 deletions src/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import './init-shared.js'
import Vue from 'vue'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import AdminSettings from './components/AdminSettings.vue'
import '../css/admin.scss'
Expand Down Expand Up @@ -59,11 +61,8 @@ function deleteTemplate(event) {
elmt.classList.remove('icon-delete')

// send request
$.ajax({
url: remote,
type: 'DELETE',
})
.done(function() {
axios.delete(remote)
.then(function() {
// remove template
elmt.parentElement.remove()
// is list empty? Only the default template is left
Expand All @@ -72,7 +71,7 @@ function deleteTemplate(event) {
emptyElmt.classList.remove('hidden')
}
})
.fail(function(e) {
.catch(function(e) {
// failure, show warning
elmt.textContent = t('richdocuments', 'Error')
elmt.classList.remove('icon-loading')
Expand Down Expand Up @@ -139,6 +138,6 @@ function initTemplateManager() {
})
}

$(document).ready(function() {
document.addEventListener('DOMContentLoaded', () => {
initTemplateManager()
})
77 changes: 77 additions & 0 deletions src/components/Modal/Confirmation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<template>
<NcModal>
<div class="confirmation-dialog">
<h1>{{ name }}</h1>
<p>{{ description }}</p>
<div class="confirmation-dialog--buttons">
<NcButton type="secondary"
@click="() => close(false)">
{{ cancelButtonText }}
</NcButton>
<NcButton type="primary"
@click="() => close(true)">
{{ confirmButtonText }}
</NcButton>
</div>
</div>
</NcModal>
</template>
<script>
import { NcButton, NcModal } from '@nextcloud/vue'
import { translate as t } from '@nextcloud/l10n'
export default {
name: 'Confirmation',
components: {
NcButton,
NcModal,
},
props: {
name: {
type: String,
default: '',
},
description: {
type: String,
default: '',
},
confirmButtonText: {
type: String,
default: t('richdocuments', 'Confirm'),
},
cancelButtonText: {
type: String,
default: t('richdocuments', 'Cancel'),
},
},
emits: ['close'],
methods: {
t,
close(result) {
this.$emit('close', result)
},
},
}
</script>
<style lang="scss" scoped>
.confirmation-dialog {
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 24px;
h1 {
font-size: 120%;
font-weight: bold;
margin-bottom: 12px;
}
&--buttons {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 100%;
margin-top: 24px;
}
}
</style>
149 changes: 149 additions & 0 deletions src/components/Modal/SaveAs.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!--
- @copyright Copyright (c) 2023 Julius Härtl <[email protected]>
-
- @author Julius Härtl <[email protected]>
-
- @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/>.
-->

<template>
<NcModal>
<div class="saveas-dialog">
<h1>{{ name }}</h1>
<p>{{ description }}</p>
<NcTextField ref="nameInput"
v-model="newFileName"
:label-visible="true"
:label="t('richdocuments', 'Path to save')"
:placeholder="'/path/to/save'" />
<div class="saveas-dialog--buttons">
<NcButton type="secondary"
@click="cancel">
{{ t('richdocuments', 'Cancel') }}
</NcButton>
<NcButton type="primary"
@click="close">
{{ t('richdocuments', 'Save') }}
</NcButton>
</div>
</div>
</NcModal>
</template>

<script>
import { translate as t } from '@nextcloud/l10n'
import { NcModal, NcButton, NcTextField } from '@nextcloud/vue'
export default {
name: 'SaveAs',
components: {
NcModal,
NcButton,
NcTextField,
},
props: {
name: {
type: String,
default: t('richdocuments', 'Save As'),
},
description: {
type: String,
default: '',
},
buttonText: {
type: String,
default: t('richdocuments', 'Save'),
},
path: {
type: String,
default: '',
},
format: {
type: String,
default: '',
},
},
emits: ['close'],
data() {
return {
selectedPath: '',
}
},
computed: {
newFileName: {
get() {
if (this.selectedPath !== '') {
return this.selectedPath
}
const filename = this.path
const extension = filename.split('.').pop()
const filenameWithoutExtension = filename.substring(0, filename.length - extension.length - 1)
return filenameWithoutExtension + '.' + (this.format !== '' ? this.format : extension)
},
set(event) {
this.selectedPath = event.target.value
},
},
},
mounted() {
// prepare filename for having a separate picker for the path (.split('/').pop())
const filename = this.path
const extension = filename.split('.').pop()
const filenameWithoutExtension = filename.substring(0, filename.length - extension.length - 1)
this.$nextTick(() => {
const input = this.$refs.nameInput.$refs.inputField.$el.querySelector('input')
input.setSelectionRange(0, filenameWithoutExtension.length)
input.focus()
})
},
methods: {
t,
close() {
this.$emit('close', this.newFileName)
},
cancel() {
this.$emit('close', null)
},
},
}
</script>
<style lang="scss" scoped>
.saveas-dialog {
display: flex;
flex-direction: column;
align-items: flex-start;
margin: 24px;
h1 {
font-size: 120%;
font-weight: bold;
margin-bottom: 12px;
}
p {
margin-bottom: 12px;
}
&--buttons {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 100%;
margin-top: 24px;
}
}
</style>
Loading

0 comments on commit 01b1903

Please sign in to comment.