includes/clientside/static/ajax.js
changeset 329 0437a7cf1acc
parent 326 ab66d6d1f1f4
child 335 67bd3121a12e
equal deleted inserted replaced
328:dc838fd61a06 329:0437a7cf1acc
  1287   domObjChangeOpac(0, mydiv);
  1287   domObjChangeOpac(0, mydiv);
  1288   var body = document.getElementsByTagName('body')[0];
  1288   var body = document.getElementsByTagName('body')[0];
  1289   body.appendChild(mydiv);
  1289   body.appendChild(mydiv);
  1290 }
  1290 }
  1291 
  1291 
       
  1292 function ajaxUpdateCheck(targetelement)
       
  1293 {
       
  1294   if ( !document.getElementById(targetelement) )
       
  1295   {
       
  1296     return false;
       
  1297   }
       
  1298   var target = document.getElementById(targetelement);
       
  1299   target.innerHTML = '';
       
  1300   var img = document.createElement('img');
       
  1301   img.src = scriptPath + '/images/loading.gif';
       
  1302   img.alt = 'Loading...';
       
  1303   target.appendChild(img);
       
  1304   ajaxGet(makeUrlNS('Admin', 'Home/updates.xml'), function()
       
  1305     {
       
  1306       if ( ajax.readyState == 4 )
       
  1307       {
       
  1308         var releases = new Array();
       
  1309         var update_available = false;
       
  1310         if ( ajax.responseXML == null )
       
  1311         {
       
  1312           alert("Error fetching updates list:\n" + ajax.responseText);
       
  1313           return false;
       
  1314         }
       
  1315         if ( ajax.responseXML.firstChild.tagName == 'enano' )
       
  1316         {
       
  1317           var enanotag = ajax.responseXML.firstChild;
       
  1318           for ( var i in enanotag.childNodes )
       
  1319           {
       
  1320             if ( enanotag.childNodes[i].tagName == 'error' )
       
  1321             {
       
  1322               alert(enanotag.childNodes[i].firstChild.nodeValue);
       
  1323             }
       
  1324             else if ( enanotag.childNodes[i].tagName == 'latest' )
       
  1325             {
       
  1326               // got <latest>
       
  1327               var latesttag = enanotag.childNodes[i];
       
  1328               for ( var i in latesttag.childNodes )
       
  1329               {
       
  1330                 var node = latesttag.childNodes[i];
       
  1331                 if ( node.tagName == 'release' )
       
  1332                 {
       
  1333                   var releasedata = new Object();
       
  1334                   for ( var i in node.attributes )
       
  1335                   {
       
  1336                     releasedata[node.attributes[i].nodeName] = node.attributes[i].nodeValue;
       
  1337                   }
       
  1338                   releases.push(releasedata);
       
  1339                 }
       
  1340                 else if ( node.tagName == 'haveupdates' )
       
  1341                 {
       
  1342                   update_available = true;
       
  1343                 }
       
  1344               }
       
  1345               break;
       
  1346             }
       
  1347           }
       
  1348         }
       
  1349         else
       
  1350         {
       
  1351           if ( window.console )
       
  1352             window.console.error('Invalid XML response');
       
  1353           return false;
       
  1354         }
       
  1355         var thediv = document.getElementById(targetelement);
       
  1356         thediv.innerHTML = '';
       
  1357         if ( !thediv )
       
  1358         {
       
  1359           if ( window.console )
       
  1360             window.console.error('Can\'t get the div');
       
  1361           return false;
       
  1362         }
       
  1363         if ( releases.length > 0 )
       
  1364         {
       
  1365           thediv.className = 'tblholder';
       
  1366           if ( update_available )
       
  1367           {
       
  1368             var infobox = document.createElement('div');
       
  1369             infobox.className = 'info-box-mini';
       
  1370             infobox.appendChild(document.createTextNode('An update for Enano is available.'));
       
  1371             infobox.style.borderWidth = '0';
       
  1372             infobox.style.margin = '0 0 0 0';
       
  1373             thediv.appendChild(infobox);
       
  1374           }
       
  1375           else
       
  1376           {
       
  1377             var infobox = document.createElement('div');
       
  1378             infobox.className = 'info-box-mini';
       
  1379             infobox.appendChild(document.createTextNode('No new updates are available.'));
       
  1380             infobox.style.borderWidth = '0';
       
  1381             infobox.style.margin = '0 0 0 0';
       
  1382             thediv.appendChild(infobox);
       
  1383           }
       
  1384           var table = document.createElement('table');
       
  1385           table.border = '0';
       
  1386           table.cellspacing = '1';
       
  1387           table.cellpadding = '4';
       
  1388           
       
  1389           var tr = document.createElement('tr');
       
  1390           
       
  1391           var td1 = document.createElement('th');
       
  1392           var td2 = document.createElement('th');
       
  1393           var td3 = document.createElement('th');
       
  1394           var td4 = document.createElement('th');
       
  1395           
       
  1396           td1.appendChild( document.createTextNode('Release type') );
       
  1397           td2.appendChild( document.createTextNode('Version') );
       
  1398           td3.appendChild( document.createTextNode('Code name') );
       
  1399           td4.appendChild( document.createTextNode('Release notes') );
       
  1400           
       
  1401           tr.appendChild(td1);
       
  1402           tr.appendChild(td2);
       
  1403           tr.appendChild(td3);
       
  1404           tr.appendChild(td4);
       
  1405             
       
  1406           table.appendChild(tr);
       
  1407           
       
  1408           var cls = 'row2';
       
  1409           
       
  1410           var j = 0;
       
  1411           for ( var i in releases )
       
  1412           {
       
  1413             j++;
       
  1414             if ( j > 5 )
       
  1415               break;
       
  1416             if ( update_available && j == 1 )
       
  1417               cls = 'row1_green';
       
  1418             else
       
  1419               cls = ( cls == 'row1' ) ? 'row2' : 'row1';
       
  1420             var release = releases[i];
       
  1421             var tr = document.createElement('tr');
       
  1422             window.console.debug(release);
       
  1423             
       
  1424             var td1 = document.createElement('td');
       
  1425             var td2 = document.createElement('td');
       
  1426             var td3 = document.createElement('td');
       
  1427             var td4 = document.createElement('td');
       
  1428             
       
  1429             td1.className = cls;
       
  1430             td2.className = cls;
       
  1431             td3.className = cls;
       
  1432             td4.className = cls;
       
  1433             
       
  1434             if ( release.tag )
       
  1435               td1.appendChild( document.createTextNode(release.tag) );
       
  1436             
       
  1437             if ( release.version )
       
  1438               td2.appendChild( document.createTextNode(release.version) );
       
  1439             
       
  1440             if ( release.codename )
       
  1441               td3.appendChild( document.createTextNode(release.codename) );
       
  1442             
       
  1443             if ( release.relnotes )
       
  1444             {
       
  1445               var a = document.createElement('a');
       
  1446               a.href = release.relnotes;
       
  1447               a.appendChild(document.createTextNode('View'));
       
  1448               td4.appendChild( a );
       
  1449             }
       
  1450             
       
  1451             tr.appendChild(td1);
       
  1452             tr.appendChild(td2);
       
  1453             tr.appendChild(td3);
       
  1454             tr.appendChild(td4);
       
  1455             
       
  1456             table.appendChild(tr);
       
  1457           }
       
  1458           thediv.appendChild(table);
       
  1459         }
       
  1460         else
       
  1461         {
       
  1462           thediv.appendChild(document.createTextNode('No releases available.'));
       
  1463         }
       
  1464       }
       
  1465     });
       
  1466 }
       
  1467