Added event emitters and fixed document deletion
This commit is contained in:
@ -8,11 +8,12 @@ import ErrorsStore from 'stores/ErrorsStore';
|
||||
import parseTitle from '../../shared/parseTitle';
|
||||
|
||||
import type { User } from 'types';
|
||||
import BaseModel from './BaseModel';
|
||||
import Collection from './Collection';
|
||||
|
||||
const DEFAULT_TITLE = 'Untitled document';
|
||||
|
||||
class Document {
|
||||
class Document extends BaseModel {
|
||||
isSaving: boolean = false;
|
||||
hasPendingChanges: boolean = false;
|
||||
errors: ErrorsStore;
|
||||
@ -109,14 +110,6 @@ class Document {
|
||||
}
|
||||
};
|
||||
|
||||
@action delete = async () => {
|
||||
try {
|
||||
await client.post('/documents.delete', { id: this.id });
|
||||
} catch (e) {
|
||||
this.errors.add('Document failed to delete');
|
||||
}
|
||||
};
|
||||
|
||||
@action fetch = async () => {
|
||||
try {
|
||||
const res = await client.post('/documents.info', { id: this.id });
|
||||
@ -177,6 +170,19 @@ class Document {
|
||||
return this;
|
||||
};
|
||||
|
||||
@action delete = async () => {
|
||||
try {
|
||||
await client.post('/documents.delete', { id: this.id });
|
||||
this.emit('document.delete', {
|
||||
id: this.id,
|
||||
collectionId: this.collection.id,
|
||||
});
|
||||
} catch (e) {
|
||||
this.errors.add('Error while deleting the document');
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
updateData(data: Object = {}, dirty: boolean = false) {
|
||||
if (data.text) {
|
||||
const { title, emoji } = parseTitle(data.text);
|
||||
@ -189,6 +195,8 @@ class Document {
|
||||
}
|
||||
|
||||
constructor(data?: Object = {}) {
|
||||
super();
|
||||
|
||||
this.updateData(data);
|
||||
this.errors = stores.errors;
|
||||
}
|
||||
|
Reference in New Issue
Block a user