var root = $(location).attr('href'); var vJSON={DEVICE:[],ANALOGINPUTS:[],DIGITALINPUTS:[],COUNTERS:[],DIGITALOUTPUTS:[],CALCULATEDANALOGINPUTS:[],CONVERTERS:[],SPECIALPROTECTIONS:[],SPM:[],SERVICEPLAN:[],ANALOGOUTPUTS:[], ES: { ACTIVE:false, NRPARTICIPANTS:null, STATE:null, REGULATIONPRESSURE:null, CONTROLVSD:null, SLAVES:[], MASTERBAR:null } }; var language = new language(); var es = new es(); var page="machine"; // generic method that executes an ajax request and calls the appropriate callback function depending on the outcome function request(url, method, callbackSuccess, callbackError, dataType) { if(dataType == null){ dataType = 'text'; } $.ajax({ url: root + url, type: method, dataType: dataType, success: function(data, textStatus, xhr) { callbackSuccess(data, textStatus, xhr); }, error: function(xhr, textStatus, errorThrown) { callbackError(xhr, textStatus, errorThrown); } }); } $(document).ready(function() { $.ajaxSetup({ async: false, timeout:5000 }); init_interface(); load_files(); }); function init_interface() { $('#error').hide(); $('#units').hide(); $('#tablees_l3').hide(); $('#link2str').hide(); $('#page').html(machine['Model']); $('#logo_link').attr('href', brand_url); } function load_files() { for(var typeIndex in FILE_TYPES) { var fileType = FILE_TYPES[typeIndex]; for(var fileIndex in files[fileType.index]) { var path = fileType.dir + '/' + files[fileType.index][fileIndex]; request_file(path, typeIndex, fileType); } } populate_language_dropdown(); // 4: set timer window.setInterval(refresh_data, 5000); } function request_file(path, typeIndex, fileType) { path = path + '?_=' + new Date().getTime(); request(path, 'GET', // success function(data) { switch(typeIndex) { case "CSS": var fileref = document.createElement('link'); fileref.type = fileType.type; fileref.rel = 'stylesheet'; fileref.href = path; document.getElementsByTagName('head')[0].appendChild(fileref); //$('head').append(fileref); break; case "JAVASCRIPT": var fileref = document.createElement('script'); fileref.type = fileType.type; fileref.src = path; document.getElementsByTagName('head')[0].appendChild(fileref); //$('head').append(fileref); break; case "IMAGE": var fileref = new Image(); fileref.src = path; if(path.indexOf('Brandlogo') != -1) { $('#logo_link img').attr('src', path); } fileref.onerror = function() { request_file(path, typeIndex, fileType); } break; } }, // error function(xhr, textStatus, errorThrown) { request_file(path, typeIndex, fileType); }, fileType.dataType ); } function populate_language_dropdown() { $('#language_select').empty(); for(var i in languages) { $('#language_select') .append($('