@ninjabreadman thanks for the guidance, the new modules is pretty complex, is there a simpler module to take an example from?
All I’m really after is the data produced from the trainSchedule
function to be accessible by the getDom
function.
@ninjabreadman thanks for the guidance, the new modules is pretty complex, is there a simpler module to take an example from?
All I’m really after is the data produced from the trainSchedule
function to be accessible by the getDom
function.
Hi,
I’m trying to pass the value in the variable ajaxResult
to the getDom
function so that I can render it into a table.
I’ve tried to return
the value from the start
function but that comes up as undefined
How are values passed between these functions?
Thanks for the help in advance
`/* global Module */
Module.register(“trainScheduler”,{
// Default module config.
defaults: {
text: "| --- | --- | --- | --- |"
},
currentWeatherType: "",
// Define required scripts.
getScripts: function() {
return ["moment.js"];
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
var ajaxResult;
// Log.info('RESULT' + ajaxResult);
if (this.config.remoteFile != null) {
this.trainSchedule(
(response) => {
this.config = JSON.parse(response);
//function call to send the result to out!
responseRunner(response);
}
);
function responseRunner (response) {
ajaxResult = response;
};
}
// Schedule update timer.
// LEMME COME BACK TO THIS AUTO REFERESHER THING
// var self = this;
// setInterval(function() {
// self.updateDom(self.config.fadeSpeed);
// }, this.config.updateInterval);
},
/* complimentFile(callback)
* Retrieve a file from the local filesystem
*/
trainSchedule: function(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open("GET", this.file(this.config.remoteFile), true);
xobj.onreadystatechange = function() {
if (xobj.readyState == 4 && xobj.status == "200") {
callback(xobj.responseText);
}
};
xobj.send(null);
},
// Override dom generator.
getDom: function() {
var complimentText = 1;
var compliment = document.createTextNode(complimentText);
var wrapper = document.createElement("div");
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
wrapper.appendChild(compliment);
return wrapper;
},
});
`