class Controller { constructor(model, view) { this.model = model; this.view = view; this.redrawDirTree(view); var cloneBtn = document.getElementsByClassName("clone")[0]; var purgeBtn = document.getElementsByClassName("wipe")[0]; var settingsBtn = document.getElementsByClassName("settingsBtn")[0]; var settingsClose = document.getElementsByClassName("close"); var settingsSubmit = document.getElementById("settingsSubmit"); var saveBtn = document.getElementById("saveBtn"); cloneBtn.addEventListener("click", this.cloneRep.bind(this)); purgeBtn.addEventListener("click", this.wipeFS.bind(this)); settingsBtn.addEventListener("click", view.openSettings.bind(this)); for (let i = 0; i < settingsClose.length; i++) { settingsClose[i].addEventListener("click", view.closeSettings.bind(this)); } settingsSubmit.addEventListener("click", this.saveSettings.bind(this)); view.simplemde.codemirror.on("change", this.saveButton.bind(this)); saveBtn.addEventListener("click", this.saveFile.bind(this)); } saveButton() { var textArea = this.view.simplemde; this.view.showSaveButton(textArea.value() == this.openedFileValue); } wipeFS() { this.model.wipeFS(); //window.location.reload(); this.redrawDirTree(this.view); } cloneRep(repurl) { var loading = document.getElementsByClassName("loading")[0]; loading.style.display = "grid"; this.model.cloneRep().then( function (value) { loading.style.removeProperty("display"); this.redrawDirTree(this.view); }.bind(this), function (error) {} ); } redrawDirTree(view) { this.model.getDirTree().then( function (value) { view.removeDirTree(); view.drawDirTree(value, undefined, this); view.dirTreeToggler(); this.updateFileStats(); }.bind(this), function (error) {} ); } updateFileStats() { this.model.getGitStatusTree().then( function (value) { this.view.statDirTree(value, undefined); console.log(value); }.bind(this), function (error) { console.log(error); } ); } saveSettings() { let repo = document.getElementById("inputRepository"); let baseDir = document.getElementById("inputBaseDir"); this.model.setRepo(repo.value); this.model.setBaseDir(baseDir.value); this.redrawDirTree(this.view); this.view.closeSettings(); console.log(repo.value); } loadFile(file) { this.openedFile = file; this.model.readFile(file).then( function (value) { this.openedFileValue = value; this.view.openFile(value); }.bind(this), function (error) {} ); } saveFile() { var textArea = this.view.simplemde; this.model.saveFile(this.openedFile, textArea.value()); this.openedFileValue = textArea.value(); this.saveButton(); this.updateFileStats(); } }