Commit bc931b90 authored by Jarek Ostrowski's avatar Jarek Ostrowski
parent 63124283
<script> <script>
import { GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui'; import { GlSafeHtmlDirective as SafeHtml, GlModal } from '@gitlab/ui';
import { escape } from 'lodash'; import { escape } from 'lodash';
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue'; import { __, s__, sprintf } from '~/locale';
import { s__, sprintf } from '~/locale';
export default { export default {
components: { components: {
DeprecatedModal, GlModal,
}, },
directives: { directives: {
SafeHtml, SafeHtml,
...@@ -66,51 +65,57 @@ export default { ...@@ -66,51 +65,57 @@ export default {
false, false,
); );
}, },
primaryButtonLabel() {
return s__('AdminProjects|Delete project');
},
canSubmit() { canSubmit() {
return this.enteredProjectName === this.projectName; return this.enteredProjectName === this.projectName;
}, },
primaryProps() {
return {
text: s__('Delete project'),
attributes: [{ variant: 'danger' }, { category: 'primary' }, { disabled: !this.canSubmit }],
};
},
}, },
methods: { methods: {
onCancel() { onCancel() {
this.enteredProjectName = ''; this.enteredProjectName = '';
}, },
onSubmit() { onSubmit() {
if (!this.canSubmit) {
return;
}
this.$refs.form.submit(); this.$refs.form.submit();
this.enteredProjectName = ''; this.enteredProjectName = '';
}, },
}, },
cancelProps: {
text: __('Cancel'),
},
}; };
</script> </script>
<template> <template>
<deprecated-modal <gl-modal
id="delete-project-modal" modal-id="delete-project-modal"
:title="title" :title="title"
:text="text" :action-primary="primaryProps"
:primary-button-label="primaryButtonLabel" :action-cancel="$options.cancelProps"
:submit-disabled="!canSubmit" :ok-disabled="!canSubmit"
kind="danger" @primary="onSubmit"
@submit="onSubmit"
@cancel="onCancel" @cancel="onCancel"
> >
<template #body="props"> <p v-safe-html="text"></p>
<p v-safe-html="props.text"></p> <p v-safe-html="confirmationTextLabel"></p>
<p v-safe-html="confirmationTextLabel"></p> <form ref="form" :action="deleteProjectUrl" method="post">
<form ref="form" :action="deleteProjectUrl" method="post"> <input ref="method" type="hidden" name="_method" value="delete" />
<input ref="method" type="hidden" name="_method" value="delete" /> <input :value="csrfToken" type="hidden" name="authenticity_token" />
<input :value="csrfToken" type="hidden" name="authenticity_token" /> <input
<input v-model="enteredProjectName"
v-model="enteredProjectName" name="projectName"
name="projectName" class="form-control"
class="form-control" type="text"
type="text" aria-labelledby="input-label"
aria-labelledby="input-label" autocomplete="off"
autocomplete="off" />
/> </form>
</form> </gl-modal>
</template>
</deprecated-modal>
</template> </template>
import $ from 'jquery';
import Vue from 'vue'; import Vue from 'vue';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
...@@ -17,6 +16,18 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -17,6 +16,18 @@ document.addEventListener('DOMContentLoaded', () => {
deleteProjectUrl: '', deleteProjectUrl: '',
projectName: '', projectName: '',
}, },
mounted() {
const deleteProjectButtons = document.querySelectorAll('.delete-project-button');
deleteProjectButtons.forEach(button => {
button.addEventListener('click', () => {
const buttonProps = button.dataset;
deleteModal.deleteProjectUrl = buttonProps.deleteProjectUrl;
deleteModal.projectName = buttonProps.projectName;
this.$root.$emit('bv::show::modal', 'delete-project-modal');
});
});
},
render(createElement) { render(createElement) {
return createElement(deleteProjectModal, { return createElement(deleteProjectModal, {
props: { props: {
...@@ -27,12 +38,4 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -27,12 +38,4 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}, },
}); });
$(document).on('shown.bs.modal', event => {
if (event.relatedTarget.classList.contains('delete-project-button')) {
const buttonProps = event.relatedTarget.dataset;
deleteModal.deleteProjectUrl = buttonProps.deleteProjectUrl;
deleteModal.projectName = buttonProps.projectName;
}
});
}); });
...@@ -5,10 +5,7 @@ ...@@ -5,10 +5,7 @@
%li.project-row{ class: ('no-description' if project.description.blank?) } %li.project-row{ class: ('no-description' if project.description.blank?) }
.controls .controls
= link_to 'Edit', edit_project_path(project), id: "edit_#{dom_id(project)}", class: "btn" = link_to 'Edit', edit_project_path(project), id: "edit_#{dom_id(project)}", class: "btn"
%button.delete-project-button.btn.btn-danger{ data: { toggle: 'modal', %button.delete-project-button.btn.btn-danger{ data: { delete_project_url: admin_project_path(project), project_name: project.name } }
target: '#delete-project-modal',
delete_project_url: admin_project_path(project),
project_name: project.name }, type: 'button' }
= s_('AdminProjects|Delete') = s_('AdminProjects|Delete')
.stats .stats
......
...@@ -1830,9 +1830,6 @@ msgstr "" ...@@ -1830,9 +1830,6 @@ msgstr ""
msgid "AdminProjects|Delete Project %{projectName}?" msgid "AdminProjects|Delete Project %{projectName}?"
msgstr "" msgstr ""
msgid "AdminProjects|Delete project"
msgstr ""
msgid "AdminSettings|Apply integration settings to all Projects" msgid "AdminSettings|Apply integration settings to all Projects"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment