y 3 years ago
parent
commit
c858b8d8bf
3 changed files with 39 additions and 10 deletions
  1. 1 1
      css/style.css
  2. 16 5
      js/components/Home.js
  3. 22 4
      js/components/User.js

+ 1 - 1
css/style.css

@@ -165,7 +165,7 @@
  }
 
  .my-div {
-     position: absolute;
+     position: fixed;
      top: 0;
      left: 0;
      height: 100%;

+ 16 - 5
js/components/Home.js

@@ -16,12 +16,14 @@ export default class Home extends HTMLElement {
             description:"",
             position:"",
         }
-        this.service = null;
+        this.s = {
+            service: null
+        };
 
     }
 
     connectedCallback() {
-        if (!this.rendered) {
+        if (!this.rendered && this.user) {
             this.render();
         }
     }
@@ -33,10 +35,12 @@ export default class Home extends HTMLElement {
         })
         bindEvents("UserHomeOut", "user-logout", (e) => {
             this.user = null;
+            this.innerHTML = "";
         })
     }
 
     async render() {
+        this.innerHTML = "";
         if (!this.user) return;
         this.rendered = true;
         let res = (await f("service", "get", this.user.user_token)).data;
@@ -71,11 +75,13 @@ export default class Home extends HTMLElement {
     }
 
     async register(e) {
-        this.service = e.target.dataset.service
-        let res = await f("servicerecord", "post", this.user.user_token, this.data)
+        this.s.service = e.target.dataset.service
+        let res = await f("servicerecord", "post", this.user.user_token, this.s)
         console.log(res)
         e.target.innerHTML = "Записано"
         e.target.classList.add("disabled")
+
+        dEvent("user-cab",{status: "update"});
     }
 
     async restore(e) {
@@ -84,6 +90,8 @@ export default class Home extends HTMLElement {
         console.log(res)
         let el = document.getElementById(id);
         el.classList.add("disabled-block");
+
+        dEvent("user-cab",{status: "update"});
     }
 
     put(e) {
@@ -95,6 +103,7 @@ export default class Home extends HTMLElement {
         div.innerHTML = getTemplateRegistration(el);
         this.append(div);
         this.attachModel();
+
     }
     async change(e) {
         console.log(this.data)
@@ -111,7 +120,9 @@ export default class Home extends HTMLElement {
 
         let div = document.getElementsByClassName("my-div")[0];
 
-        div.classList.add("none")
+        div.classList.add("none");
+
+        dEvent("user-cab",{status: "update"});
 
     }
 

+ 22 - 4
js/components/User.js

@@ -17,31 +17,49 @@ export default class User extends HTMLElement {
             position:"",
         }
         this.service = null;
-
+        this.render();
     }
 
     connectedCallback() {
-        if (!this.rendered) {
+        if (!this.rendered && this.user) {
             this.render();
         }
     }
 
-    bind() {
+   bind() {
         bindEvents("UserLogin", "user-login", (e) => {
             this.user = e.detail;
             this.render();
         })
         bindEvents("UserOut", "user-logout", (e) => {
             this.user = null;
+            this.innerHTML = "";
+        })
+
+        bindEvents("UserCab", "user-cab", (e) => {
+           this.getUserCab();
         })
+
     }
 
+   async getUserCab() {
+        this.innerHTML = "";
+        let res = await f("servicerecord", "get", this.user.user_token);
+        console.log(res)
+        this.registrations = res.results;
+        for (let reg of this.registrations) {
+            this.innerHTML += (getTemplateCab(reg))
+        }
+        this.attachModel();
+    }
+
+
     async render() {
+        this.innerHTML = "";
         if (!this.user) return;
         this.rendered = true;
         let res = await f("servicerecord", "get", this.user.user_token);
         console.log(res)
-
         this.registrations = res.results;
         for (let reg of this.registrations) {
             this.innerHTML += (getTemplateCab(reg))