Skip to content

Commit

Permalink
Review and annotate MapDiscussionController
Browse files Browse the repository at this point in the history
  • Loading branch information
sethlu committed Sep 9, 2017
1 parent ec4a82e commit d150b50
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
9 changes: 8 additions & 1 deletion scripts/map/MapConversationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ MapConversationController.createViewFragment = function () {
let sourceElement = sourcesElement.querySelector(".source");

let sourceElementUpdated = function () {
let sourceIndex = this.children.indexOf(sourceElement);
let sourceIndex;
for (let [index, element] of Object.entries(this.children)) {
if (element === sourceElement) {
sourceIndex = parseInt(index);
break;
}
}

this.parentNode.parentNode.querySelector("[data-ica-conversation-source-index]").textContent = (sourceIndex + 1).toString();
this.parentNode.parentNode.querySelector("[data-ica-action='previous-source']").style.opacity = sourceElement.previousElementSibling ? 1 : 0;
this.parentNode.parentNode.querySelector("[data-ica-action='next-source']").style.opacity = sourceElement.nextElementSibling ? 1 : 0;
Expand Down
56 changes: 36 additions & 20 deletions scripts/map/MapDiscussionController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

/**
* MapDiscussionController
* Concrete view controller to display a Discussion.
* @constructor
*/
const MapDiscussionController = DiscussionController.createComponent("MapDiscussionController");

MapDiscussionController.createViewFragment = function () {
Expand All @@ -7,29 +12,40 @@ MapDiscussionController.createViewFragment = function () {

// View

MapDiscussionController.defineMethod("initView", function initView() {
if (!this.view) return;
(function (MapDiscussionController) {

this.view.addEventListener("click", function (e) {
e.stopPropagation();
}.bind(this.view));
MapDiscussionController.defineMethod("initView", function initView() {
if (!this.view) return;

});
this.view.addEventListener("click", viewOnClick);

MapDiscussionController.defineMethod("updateView", function updateView() {
if (!this.view) return;
});

this.view.querySelectorAll("[data-ica-discussion-predicate]").forEach(function (element) {
let predicate = getElementProperty(element, "discussion-predicate");
if (isEmpty(this.discussion[predicate])) {
element.style.display = "none";
} else {
element.style.display = "";
}
}.bind(this));
MapDiscussionController.defineMethod("updateView", function updateView() {
if (!this.view) return;

this.view.querySelectorAll("[data-ica-discussion]").forEach(function (element) {
element.textContent = this.discussion[getElementProperty(element, "discussion")]["0"];
}.bind(this));
this.view.querySelectorAll("[data-ica-discussion-predicate]").forEach(function (element) {
let predicate = getElementProperty(element, "discussion-predicate");
element.style.display = isEmpty(this.discussion[predicate]) ? "none" : "";
}.bind(this));

});
this.view.querySelectorAll("[data-ica-discussion]").forEach(function (element) {
element.textContent = this.discussion[getElementProperty(element, "discussion")]["0"];
}.bind(this));

});

MapDiscussionController.defineMethod("uninitView", function uninitView() {
if (!this.view) return;

this.view.removeEventListener("click", viewOnClick);

});

// Shared functions

function viewOnClick(event) {
event.stopPropagation();
}

})(MapDiscussionController);

0 comments on commit d150b50

Please sign in to comment.