Skip to content

Commit

Permalink
replace DocumentEditorView with SourceEditorView
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Jan 9, 2025
1 parent 53cc639 commit 7809142
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 62 deletions.
19 changes: 8 additions & 11 deletions indigo_app/static/javascript/indigo/views/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,11 @@
this.revisionsView = new Indigo.DocumentRevisionsView({document: this.document, documentContent: this.documentContent});
this.tocView = new Indigo.DocumentTOCView({model: this.documentContent, document: this.document});

this.bodyEditorView = new Indigo.DocumentEditorView({
this.sourceEditorView = new Indigo.SourceEditorView({
model: this.document,
documentContent: this.documentContent,
tocView: this.tocView,
});
this.bodyEditorView.on('dirty', this.setDirty, this);
this.bodyEditorView.on('clean', this.setClean, this);
this.bodyEditorView.editorReady.then(function() {
this.sourceEditorView.editorReady.then(function() {
// select the appropriate element in the toc
// TODO: there's a race condition here: the TOC might not be built yet
if (Indigo.queryParams.toc && self.tocView.selectItemById(Indigo.queryParams.toc)) {
Expand All @@ -198,13 +195,13 @@
model: this.document,
prefocus: parseInt(Indigo.queryParams.anntn),
});
this.annotationsView.listenTo(this.bodyEditorView.sourceEditor, 'rendered', this.annotationsView.renderAnnotations);
this.annotationsView.listenTo(this.sourceEditorView, 'rendered', this.annotationsView.renderAnnotations);

this.activityView = new Indigo.DocumentActivityView({document: this.document});
this.issuesView = new Indigo.DocumentIssuesView({
document: this.document,
documentContent: this.documentContent,
editorView: this.bodyEditorView,
editorView: this.sourceEditorView,
});

const akn = this.el.querySelector('.document-primary-pane-content-pane la-akoma-ntoso');
Expand Down Expand Up @@ -236,7 +233,7 @@
},

isDirty: function(e) {
return this.dirty || this.bodyEditorView.isDirty();
return this.dirty || this.sourceEditorView.isDirty();
},

setDirty: function() {
Expand All @@ -247,7 +244,7 @@

setClean: function() {
// disable the save button if all views are clean
if (!this.bodyEditorView.dirty && !this.attachmentsView.dirty) {
if (!this.sourceEditorView.isDirty() && !this.attachmentsView.dirty) {
this.dirty = false;
this.$saveBtn
.prop('disabled', true)
Expand Down Expand Up @@ -283,7 +280,7 @@
},

save: async function() {
if (!this.bodyEditorView.canCancelEdits()) return;
if (!this.sourceEditorView.confirmAndDiscardChanges()) return;

this.$saveBtn
.prop('disabled', true)
Expand All @@ -297,7 +294,7 @@
await Indigo.deferredToAsync(this.attachmentsView.save());

// TODO: a better way of reloading the page (will redirect to provision chooser for now)
if (this.bodyEditorView.sourceEditor.aknTextEditor.reloadOnSave) {
if (this.sourceEditorView.aknTextEditor.reloadOnSave) {
window.location.reload();
}
} catch {
Expand Down
53 changes: 4 additions & 49 deletions indigo_app/static/javascript/indigo/views/document_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
},

initialize: function(options) {
this.parent = options.parent;
this.name = 'source';
this.document = this.parent.model;
this.document = this.model;
this.xmlElement = null;
this.quickEditTemplate = $('<a href="#" class="quick-edit"><i class="fas fa-pencil-alt"></i></a>')[0];
this.sheetInner = document.querySelector('.document-workspace .document-sheet-container .sheet-inner');
Expand Down Expand Up @@ -59,7 +58,7 @@
this.listenTo(this.document.content, 'mutation', this.onDomMutated);

// setup table editor
this.tableEditor = new Indigo.TableEditorView({parent: this, documentContent: this.parent.documentContent});
this.tableEditor = new Indigo.TableEditorView({parent: this, documentContent: this.document.content});
this.tableEditor.on('start', this.onTableEditStart, this);
this.tableEditor.on('finish', this.onTableEditFinish, this);
this.tableEditor.on('discard', this.editActivityCancelled, this);
Expand Down Expand Up @@ -92,7 +91,7 @@
quickEdit: function(e) {
const htmlElement = e.currentTarget.parentElement.parentElement;
const elemId = htmlElement.id;
const element = this.parent.documentContent.xmlDocument.querySelector('[eId="' + elemId + '"]');
const element = this.document.content.xmlDocument.querySelector('[eId="' + elemId + '"]');

if (element && this.confirmAndDiscardChanges()) {
this.editXmlElement(element);
Expand Down Expand Up @@ -320,7 +319,7 @@
if (!this.comparisonDocumentId) return;

data.document = this.document.toJSON();
data.document.content = this.parent.documentContent.toXml();
data.document.content = this.document.content.toXml();
data.element_id = this.xmlElement.getAttribute('eId');

if (!data.element_id && this.xmlElement.tagName !== "akomaNtoso") {
Expand Down Expand Up @@ -510,48 +509,4 @@
return this.aknTextEditor.dirty || this.tableEditor.editing;
}
});

// Handle the document editor, tracking changes and saving it back to the server.
// TODO: this doesn't really do much any more and the remaining functionality could
// be moved into SourceEditorView and/or DocumentDetailView
Indigo.DocumentEditorView = Backbone.View.extend({
el: 'body',

initialize: function(options) {
this.dirty = false;

this.documentContent = options.documentContent;
// XXX: check
this.documentContent.on('change', this.setDirty, this);
this.documentContent.on('sync', this.setClean, this);

// setup the editor views
this.sourceEditor = new Indigo.SourceEditorView({parent: this, tocView: options.tocView});

// this is a deferred to indicate when the editor is ready to edit
this.editorReady = this.sourceEditor.editorReady;
},

setDirty: function() {
if (!this.dirty) {
this.dirty = true;
this.trigger('dirty');
}
},

setClean: function() {
if (this.dirty) {
this.dirty = false;
this.trigger('clean');
}
},

isDirty: function() {
return this.dirty || this.sourceEditor.isDirty();
},

canCancelEdits: function() {
return this.sourceEditor.confirmAndDiscardChanges();
},
});
})(window);
4 changes: 2 additions & 2 deletions indigo_app/static/javascript/indigo/views/document_issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
this.$akn = this.$('#document-sheet la-akoma-ntoso');
this.nodes = [];

this.listenTo(this.editorView.sourceEditor, 'rendered', this.render);
this.listenTo(this.editorView, 'rendered', this.render);
this.listenTo(this.model, 'reset change add remove', this.render);
this.listenTo(this.documentContent, 'change', this.runLinters);
this.listenTo(this.attachments, 'reset change add remove', this.runLinters);
Expand Down Expand Up @@ -81,7 +81,7 @@
for (var i = 0; i < targets.length; i++) {
var target = targets[i];

var gutter = self.editorView.sourceEditor.ensureGutterActions(target);
var gutter = self.editorView.ensureGutterActions(target);
var node = $(self.template(issue.toJSON()))[0];
self.nodes.push(node);

Expand Down

0 comments on commit 7809142

Please sign in to comment.