1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-25 16:19:44 +02:00

remove pages (#27)

* remove pages

* requested changes and unit tests

* update

* fix unit test

* requested changes

* add confirmation

* remove deeply

* remove log

* bugfix

* update placeholder
This commit is contained in:
Murod Khaydarov 2019-01-25 06:19:37 +03:00 committed by GitHub
parent d872e78339
commit ccd627151f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 265 additions and 44 deletions

View file

@ -27,6 +27,7 @@ export default class Writing {
this.nodes = {
editorWrapper: null,
saveButton: null,
removeButton: null,
parentIdSelector: null,
putAboveIdSelector: null,
uriInput: null
@ -42,11 +43,7 @@ export default class Writing {
/**
* Create Editor
*/
this.nodes.editorWrapper = document.createElement('div');
this.nodes.editorWrapper.id = 'codex-editor';
moduleEl.appendChild(this.nodes.editorWrapper);
this.nodes.editorWrapper = document.getElementById('codex-editor');
if (settings.page) {
this.page = settings.page;
}
@ -58,10 +55,24 @@ export default class Writing {
/**
* Activate form elements
*/
this.nodes.saveButton = moduleEl.querySelector('[name="js-submit"]');
this.nodes.saveButton = moduleEl.querySelector('[name="js-submit-save"]');
this.nodes.saveButton.addEventListener('click', () => {
this.saveButtonClicked();
});
this.nodes.removeButton = moduleEl.querySelector('[name="js-submit-remove"]');
if (this.nodes.removeButton) {
this.nodes.removeButton.addEventListener('click', () => {
const isUserAgree = confirm("Are you sure?");
if (!isUserAgree) {
return
}
this.removeButtonClicked();
});
}
this.nodes.parentIdSelector = moduleEl.querySelector('[name="parent"]');
this.nodes.putAboveIdSelector = moduleEl.querySelector('[name="above"]');
this.nodes.uriInput = moduleEl.querySelector('[name="uri-input"]');
@ -149,4 +160,31 @@ export default class Writing {
console.log('Saving error: ', savingError);
}
}
/**
* @returns {Promise<void>}
*/
async removeButtonClicked() {
try {
const endpoint = this.page ? '/api/page/' + this.page._id : '';
let response = await fetch(endpoint, {
method: 'DELETE'
});
response = await response.json();
if (response.success) {
if (response.result && response.result._id) {
document.location = '/page/' + response.result._id;
} else {
document.location = '/';
}
} else {
alert(response.error);
console.log('Server fetch failed:', response.error);
}
} catch (e) {
console.log('Server fetch failed due to the:', e);
}
}
}

View file

@ -35,6 +35,7 @@
&__button {
@apply --button;
@apply --button-primary;
margin: auto 30px auto auto;
}
}

View file

@ -28,6 +28,7 @@
&-button {
@apply --button;
@apply --button-primary;
padding: 5px 10px;
font-size: 13px;
margin-left: 10px;

View file

@ -10,6 +10,7 @@
&__save {
@apply --button;
@apply --button-primary;
margin-left: auto;
}
@ -23,6 +24,13 @@
}
}
.writing-buttons {
&__remove {
@apply --button;
@apply --button-danger;
}
}
.uri-input {
box-sizing: border-box;
width: 100%;

View file

@ -3,6 +3,7 @@
--color-text-second: #7B7E89;
--color-line-gray: #E8E8EB;
--color-link-active: #388AE5;
--color-button-danger: #ff1629;
--color-gray-border: rgba(var(--color-line-gray), 0.48);
/**
@ -17,15 +18,33 @@
display: inline-block;
padding: 9px 15px;
border-radius: 3px;
background: var(--color-link-active);
color: #fff;
color: #6c6375;
background: #fcfcff;
box-shadow: inset 0 0 0 1px rgba(184, 189, 206, 0.2);
font-size: 14px;
line-height: 1em;
text-decoration: none;
cursor: pointer;
svg {
margin: 0 0.3em 0 -0.05em;
}
}
--button-danger {
background: var(--color-button-danger);
color: #fff;
box-shadow: none;
&:hover {
background: color-mod(var(--color-button-danger) blackness(+10%));
}
}
--button-primary {
background: var(--color-link-active);
color: #fff;
box-shadow: none;
&:hover {
background: color-mod(var(--color-link-active) blackness(+10%));