/* Copyright (C) 2019 Intel Corporation. All rights reserved. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ /* * Dom Location * */ function setDivCenter(divname) // make qn element center aligned { var Top =($(window).height()-$(divname).height())/2; var Left = ($(window).width()-$(divname).width())/2; var scrollTop = $(document).scrollTop(); var scrollLeft = $(document).scrollLeft(); $(divname).css({posisiton:'absolute','top':Top+scrollTop,'left':Left+scrollLeft}); }; setDivCenter(".middlebox"); setDivCenter(".deletebox"); function setmain(divname){ // Set the pop-up window of apps for download at the right place var x = $('#btn').offset().top; var Top = x + $('#btn').height()+15; var y = $('#btn').offset().left; var Left = y + ($('#btn').width()/2)-($(divname).width()/2); console.log(Top,Left) $(divname).css({'top':Top,'left':Left}); } setmain(".main") /* * download apps * */ function getthis(val) //Telling background which app to be loaded from appstore_list and to be installed in the current device. { /* Get the ip adress and the port of a device, as well as the application ID to be downloaded on this device*/ var ip,port,name,version; var ipArr=$("#IPs").text().split(":"); ip=ipArr[1]; var portArr=$("#ports").text().split(":"); port=portArr[1]; name = $(val).parent().find("#appsinfo1").text().split(":")[1]; version = $(val).parent().find("#appsinfo2").text().split(":")[1]; $(".main").fadeOut(); for (num in alist){ if (alist[num]['pname'].trim() == name.trim()) {alert("This app has been downloaded."); return;}}; $("#loading").fadeIn(); var sNode = document.getElementById("APPS"); var tempNode= sNode.cloneNode(true); sNode.parentNode.appendChild(tempNode); $("#appinfo1").html("Product Name : "+ name); $("#appinfo2").html("Status : "+"Installing"); $("#appinfo3").html("Current_Version : "+ version); $.get("/appDownload/",{'ip':ip.trim(),'port':port.trim(),'name':name.trim(),},function (ret) { var status = $.trim(ret.split(":")[1].split("}")[0]); $(".loadapp").html(name+" is downloading now"); var msg = JSON.parse(status) console.log(msg) if (JSON.parse(status)=="ok"){ $(".middlebox").fadeIn(); $(".sourceapp").fadeOut(); $("#loading").fadeOut(); $(".findapp").html("Download "+name +" successfully"); $(".surebtn").click(function (){ $(".middlebox").fadeOut(); window.location.reload(); })} else if (JSON.parse(status)=="Fail!"){ alert("Download failed!"); $("#loading").fadeOut(); sNode.remove(); } else { alert("Install app failed:" + msg) $("#loading").fadeOut(); sNode.remove(); } }) }; window.onload = function clone() //Add & Delete apps to the device. { /*Install Apps*/ var sourceNode = document.getElementById("APPS"); if (alist.length != 0) { $("#appinfo1").html("Product Name : "+ alist[0]['pname']); $("#appinfo2").html("Status : "+ alist[0]['status']); $("#appinfo3").html("Current_Version : "+ alist[0]['current_version']); $("#delete").attr('class','delet0'); $("#APPS").attr('class','app0'); for (var i=1; i=3){ alert("Install app failed: exceed max app installations.") } $(".main").fadeOut(); getthis(".mybtn2"); var newurl = "?"+"ip="+ip+"&port="+port; window.location.href= newurl; }); } } givevalue(); function popbox(){ /*Open and close the "install apps" window*/ $(".btn").click(function(){ $(".main").fadeIn(); }); $(".close").click(function(){ $(".main").fadeOut(); }); }; popbox();