Added events to know when a content is changed/saved
This commit is contained in:
parent
0875406bf8
commit
083572dfe3
@ -44,7 +44,13 @@ class WikiContent {
|
|||||||
|
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
this.mde.codemirror.on("change", (instance, changeObj) => {
|
this.mde.codemirror.on("change", (instance, changeObj) => {
|
||||||
|
if(self.loading) return;
|
||||||
|
|
||||||
console.log(changeObj);
|
console.log(changeObj);
|
||||||
|
|
||||||
|
var event = new CustomEvent("myWiki::change", {myWiki:{ wikiId:self.wikiId,pageId:self.pageId }});
|
||||||
|
document.dispatchEvent(event);
|
||||||
|
|
||||||
clearTimeout(self.timeout);
|
clearTimeout(self.timeout);
|
||||||
self.timeout = setTimeout(()=>self._mde_save(), this.waitSecondsToAutoSave);
|
self.timeout = setTimeout(()=>self._mde_save(), this.waitSecondsToAutoSave);
|
||||||
});
|
});
|
||||||
@ -55,8 +61,10 @@ class WikiContent {
|
|||||||
this.save(this.mde.value());
|
this.save(this.mde.value());
|
||||||
}
|
}
|
||||||
_mde_set(content) {
|
_mde_set(content) {
|
||||||
|
this.loading = true;
|
||||||
this.mde.clearAutosavedValue();
|
this.mde.clearAutosavedValue();
|
||||||
this.mde.value(content);
|
this.mde.value(content);
|
||||||
|
this.loading = false;
|
||||||
}
|
}
|
||||||
_mde_get() {
|
_mde_get() {
|
||||||
return this.mde.value();
|
return this.mde.value();
|
||||||
@ -128,6 +136,8 @@ class WikiContent {
|
|||||||
data: JSON.stringify({title:null, content:content})
|
data: JSON.stringify({title:null, content:content})
|
||||||
}).done(function (response) {
|
}).done(function (response) {
|
||||||
console.info(`JDG :: WikiContent.save(${self.wikiId}, ${self.pageId})`, response);
|
console.info(`JDG :: WikiContent.save(${self.wikiId}, ${self.pageId})`, response);
|
||||||
|
var event = new CustomEvent("myWiki::saved", {myWiki:{ wikiId:self.wikiId,pageId:self.pageId }});
|
||||||
|
document.dispatchEvent(event);
|
||||||
}).fail(function (response, code) {
|
}).fail(function (response, code) {
|
||||||
OC.dialogs.alert('Error', t(appName,'Error saving wiki page({wikiId}, {pageId})',{wikiId:self.wikiId,pageId:self.pageId}));
|
OC.dialogs.alert('Error', t(appName,'Error saving wiki page({wikiId}, {pageId})',{wikiId:self.wikiId,pageId:self.pageId}));
|
||||||
console.error(`JDG :: WikiContent.save(${self.wikiId}, ${self.pageId})`, response);
|
console.error(`JDG :: WikiContent.save(${self.wikiId}, ${self.pageId})`, response);
|
||||||
|
@ -7,6 +7,14 @@ class WikiPages {
|
|||||||
constructor(container, onClickLoadPage) {
|
constructor(container, onClickLoadPage) {
|
||||||
this.ul = container;
|
this.ul = container;
|
||||||
this._onClickLoadPage = onClickLoadPage;
|
this._onClickLoadPage = onClickLoadPage;
|
||||||
|
|
||||||
|
document.addEventListener("myWiki::change", function(e) {
|
||||||
|
console.log("myWiki::change",e.myWiki);
|
||||||
|
});
|
||||||
|
document.addEventListener("myWiki::saved", function(e) {
|
||||||
|
console.log("myWiki::saved", e.myWiki);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
@ -55,6 +63,11 @@ class WikiPages {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highlightSelectedPage(pageId) {
|
||||||
|
this.ul.querySelectorAll('li[data-page-id]').forEach( x=>x.querySelector('a').classList.remove('active') );
|
||||||
|
this.ul.querySelector(`li[data-page-id="${pageId}"] a`).classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------
|
||||||
addListener(root) {
|
addListener(root) {
|
||||||
const self = this;
|
const self = this;
|
||||||
@ -69,9 +82,12 @@ class WikiPages {
|
|||||||
onClickLoadPage(e) {
|
onClickLoadPage(e) {
|
||||||
const li = e.target.closest("li[data-page-id]");
|
const li = e.target.closest("li[data-page-id]");
|
||||||
let pageId = li.dataset.pageId;
|
let pageId = li.dataset.pageId;
|
||||||
|
this.highlightSelectedPage(pageId);
|
||||||
this._onClickLoadPage(this.wikiId, pageId);
|
this._onClickLoadPage(this.wikiId, pageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onClickEdit(e) {
|
onClickEdit(e) {
|
||||||
const li = e.target.closest("li[data-page-id]");
|
const li = e.target.closest("li[data-page-id]");
|
||||||
li.querySelector("input").value = li.querySelector("a").innerText;
|
li.querySelector("input").value = li.querySelector("a").innerText;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user