MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Alert from inside function

    Scheduled Pinned Locked Moved Development
    6 Posts 2 Posters 2.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L Offline
      Luukth
      last edited by

      I want to display a notification every time the interval runs. I get this error message:

      Uncaught TypeError: this.sendNotification is not a function at OV.js:40

      I think is thas something to do with where I place it because if I place it outside the interval function it does work. Maybe someone can point me in the right direction.

      Module.register("OV",{
         // Default module config.
         defaults: {
         	text: "Openbaar Vervoer!lsdksdkk"
         },
         
         // Override dom generator.
         getDom: function() {
         	var wrapper = document.createElement("div");
         	
         	function updateOV() {
         	this.sendUpdate;
         	var xhttp = new XMLHttpRequest();
         	xhttp.onreadystatechange = function() {
         		if (this.readyState == 4 && this.status == 200) {
         		var string = "";
         		//console.log(this.responseText);
         		var data = JSON.parse(this.responseText);
         		//console.log(decodeURI(data.dest));
         		string += "<table>";
         		$.each(data, function( index, value ) {
         			string += "<tr>"
         			console.log(value );
         			string += "<td>" + value.service + "</td>";
         			string += "<td>" + decodeURI(value.dest) + "</td>";
         			string += "<td>" + value.time + "</td>";
         			string += "<td>" + value.state + "</td>";
         			string += "</tr>";
         		});
         		string += "</table>";
         		wrapper.innerHTML = string;
         		}
         	  };
         	  xhttp.open("GET", "http://192.168.1.167/esp/bustijden.php");
         	  xhttp.send();
         	}
         	
         	setInterval(function() {
         		updateOV();
         		this.sendNotification("SHOW_ALERT", {title: "OV", message: "Bustijden ge-update.", timer: "1000"});
         	}, 10000);
         	updateOV();
         	
         	return wrapper;
         },
         
         getScripts: function() {
         return [
         	'https://code.jquery.com/jquery-2.2.3.min.js',  // this file will be loaded from the jquery servers.
         ]
         },
      
      });
      
      strawberry 3.141S 1 Reply Last reply Reply Quote 0
      • strawberry 3.141S Offline
        strawberry 3.141 Project Sponsor Module Developer @Luukth
        last edited by

        @Luukth thats an issue of accessing the right scope, you can fix that by using an arrow function

        setInterval(() => {
          updateOV();
          this.sendNotification("SHOW_ALERT", {title: "OV", message: "Bustijden ge-update.", timer: "1000"});
        }, 10000);
        

        Please create a github issue if you need help, so I can keep track

        L 1 Reply Last reply Reply Quote 1
        • L Offline
          Luukth @strawberry 3.141
          last edited by

          @strawberry-3.141 Thanks that did the trick.

          strawberry 3.141S 1 Reply Last reply Reply Quote 0
          • strawberry 3.141S Offline
            strawberry 3.141 Project Sponsor Module Developer @Luukth
            last edited by

            @Luukth I suggest to outsource the data query from the render function

            Please create a github issue if you need help, so I can keep track

            L 1 Reply Last reply Reply Quote 0
            • L Offline
              Luukth @strawberry 3.141
              last edited by

              @strawberry-3.141 said in Alert from inside function:

              I suggest to outsource the data query from the render function

              Can you maybe link me to a documentation. I can’t really find a good way to learn how to make al of those functions.

              strawberry 3.141S 1 Reply Last reply Reply Quote 0
              • strawberry 3.141S Offline
                strawberry 3.141 Project Sponsor Module Developer @Luukth
                last edited by

                @Luukth https://github.com/MichMich/MagicMirror/tree/master/modules
                or you also can checkout some modules

                Please create a github issue if you need help, so I can keep track

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Sam, technical setup by Karsten.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy