From 73bb52c63b74fbfd0fa2879c078e2a4347e6961c Mon Sep 17 00:00:00 2001
From: Hermann <blumh@ethz.ch>
Date: Sat, 9 Jun 2018 17:19:25 +0200
Subject: [PATCH] fix reloading of item content after patch

---
 src/itemcontroller.js | 2 +-
 src/views/itemView.js | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/itemcontroller.js b/src/itemcontroller.js
index ba54553..c05a367 100644
--- a/src/itemcontroller.js
+++ b/src/itemcontroller.js
@@ -44,7 +44,7 @@ export default class ItemController {
 
   changeModus(newModus) {
     this.modus = newModus;
-    if (this.modus === 'view') {
+    if (newModus === 'view') {
       // reload item to current state, patches do not return embeddinds...
       this.handler.getItem(this.id, this.embedded).then((item) => {
         this.data = item;
diff --git a/src/views/itemView.js b/src/views/itemView.js
index 60806ef..13c4503 100644
--- a/src/views/itemView.js
+++ b/src/views/itemView.js
@@ -21,8 +21,8 @@ export default class ItemView {
    */
   constructor({ attrs: { controller, onDelete } }) {
     this.controller = controller;
-    this.data = this.controller.data;
     this.handler = this.controller.handler;
+    this.data = this.controller.data;
     this.resource = this.controller.resource;
     if (!onDelete) this.onDelete = () => { m.route.set(`/${controller.resource}`); };
     else this.onDelete = onDelete;
@@ -51,6 +51,9 @@ export default class ItemView {
 
   layout(children) {
     if (!this.controller || !this.controller.data) return '';
+    // update the reference to the controller data, as this may be refreshed
+    // in between
+    this.data = this.controller.data;
     return m('div', [
       m(Toolbar, m('div.pe-button-row', [
         m(Button, {
-- 
GitLab