54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
var ContentModule = React.createClass({
|
|
loadScript: function(url, fnLoad, fnError) {
|
|
const script = document.createElement("script");
|
|
script.src = url;
|
|
script.onload = fnLoad;
|
|
script.onerror = fnError;
|
|
document.body.appendChild(script);
|
|
},
|
|
loadStyle: function(url, fnLoad, fnError) {
|
|
const style = document.createElement("link");
|
|
style.rel = "stylesheet";
|
|
style.href = url;
|
|
style.onload = fnLoad;
|
|
style.onerror = fnError;
|
|
document.body.appendChild(style);
|
|
},
|
|
getInitialState: function(){return{
|
|
nvScriptReady: 0,
|
|
}},
|
|
componentWillMount: function(){
|
|
var _this = this;
|
|
|
|
this.loadScript("/mcsmanager/components.js");
|
|
this.loadScript(
|
|
"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js",
|
|
function(){
|
|
_this.loadStyle("https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.5/nv.d3.min.css");
|
|
_this.loadScript(
|
|
"https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.5/nv.d3.js",
|
|
function(){ _this.setState({nvScriptReady: 1}); console.info('nv ok'); },
|
|
function(){ _this.setState({nvScriptReady: 2}); console.error('nv error load'); }
|
|
);
|
|
},
|
|
function(){ _this.setState({nvScriptReady: 2}); console.error('d3 error load'); }
|
|
);
|
|
},
|
|
render: function(){
|
|
var element;
|
|
if (this.state.nvScriptReady == 1) {
|
|
element = ce(NvLineChart);
|
|
} else if (this.state.nvScriptReady == 2) {
|
|
element = ce('span', null, 'error');
|
|
} else {
|
|
element = ce('span', null, 'loading...');
|
|
}
|
|
|
|
return(
|
|
ce(Panel, {title: 'MC Server Manager'},
|
|
element
|
|
)
|
|
)
|
|
}
|
|
});
|