From 2b446698ea1fef0094f1123d9f216890d6ec8782 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 7 Oct 2011 14:25:57 +0200 Subject: renamed nd-functions into networkDiscovery.js --- NetworkDiscovery/html/js/nd-functions.js | 73 ---------- NetworkDiscovery/html/js/networkDiscovery.js | 198 +++++++++++++++++++++++++++ NetworkDiscovery/html/js/test.js | 3 - NetworkDiscovery/html/networkdiscovery.html | 4 +- NetworkDiscovery/ndgui.cpp | 7 +- 5 files changed, 203 insertions(+), 82 deletions(-) delete mode 100644 NetworkDiscovery/html/js/nd-functions.js create mode 100644 NetworkDiscovery/html/js/networkDiscovery.js delete mode 100644 NetworkDiscovery/html/js/test.js diff --git a/NetworkDiscovery/html/js/nd-functions.js b/NetworkDiscovery/html/js/nd-functions.js deleted file mode 100644 index e3ee793..0000000 --- a/NetworkDiscovery/html/js/nd-functions.js +++ /dev/null @@ -1,73 +0,0 @@ -var abortBootDialog = function (m) { - $("#nd_abort_boot_msg").html(m); - $("#nd_abort_boot_dialog").dialog( - { buttons: { "Show Log": function() {fbgui.showLog(); - $(this).dialog("close");}, - "Restart": function() {fbgui.restartSystem(); - $(this).dialog("close"); }, - "Shut Down": function() { fbgui.shutDownSystem(); - $(this).dialog("close"); } - } , - minWidth: 450, - modal: true, - resizable: false, - draggable: false, - open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();} - }); -}; - -var chooseInterfaceDialog = function (i) { - var cb = ""+ - ""; - $("#nd_choose_interface_msg").html(cb); - $("#nd_choose_interface_dialog").dialog( - { buttons: { "Show Log": function() {fbgui.showLog(); - $(this).dialog("close");}, - "Restart": function() {fbgui.restartSystem(); - $(this).dialog("close"); }, - "Shut Down": function() { fbgui.shutDownSystem(); - $(this).dialog("close"); }, - "Continue": function() { fbgui.continueBoot(); - $(this).dialog("close"); } - } , - minWidth: 550, - modal: true, - resizable: false, - draggable: false, - open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();} - }); -} - -var updateStatus = function (s){ - -}; - -var updateIfProgressBar = function (i, p){ - if (p >= 0 && p <= 100){ - $("#"+i+"_progress").progressbar({ value: p }); - }else{ - $("#"+i+"_progress").progressbar({ value: 0 }); - } -}; - -var updateIfStatus = function(i, s){ - $("#"+i+"_status").html(s); -}; - -var addInterface = function (i){ - $("#nd_progress_container").append( - "
"+ - " Interface: " +i+ - " Start DHCP " + - "
"+ - "
" - ); - $("#"+i+"_progress").progressbar({ value: 33 }); -}; - - diff --git a/NetworkDiscovery/html/js/networkDiscovery.js b/NetworkDiscovery/html/js/networkDiscovery.js new file mode 100644 index 0000000..2200d82 --- /dev/null +++ b/NetworkDiscovery/html/js/networkDiscovery.js @@ -0,0 +1,198 @@ +var updateTips = function ( t ) { + $( ".validateTips" ) + .text( t ) + .addClass( "ui-state-highlight" ); + setTimeout( + function() { + $( ".validateTips" ).removeClass( "ui-state-highlight", 1500 ); + }, + 500 ); +}; + +var checkLength = function ( o, n, min, max ) { + if ( o.val().length > max || o.val().length < min ) { + o.addClass( "ui-state-error" ); + updateTips( "Length of " + n + " must be between " + + min + " and " + max + "." ); + return false; + } else { + return true; + } +}; + +var checkRegexp = function ( o, regexp, n ) { + if ( !( regexp.test( o.val() ) ) ) { + o.addClass( "ui-state-error" ); + updateTips( n ); + return false; + } else { + return true; + } +}; + +var showLog = function (t) { + $("#nd_show_log_msg").val(t); + $("#nd_show_log_msg").attr('readonly','readonly'); + $("#nd_show_log_dialog").dialog( + { minWidth: 450, + modal: true, + resizable: false, + draggable: false + }); +}; + +var ip4_manualConfigurationDialog = function () { + var jsonArr = fbgui.getManualConfInterfaces(); + //jsonArr = eval('(' + jsonArr + ')'); + var c = ""; + $("#nd_mc_ifname").html(c); + + var ifname = $("#nd_mc_ifname_select :selected").text(), + ipaddr = $("#ipaddr"), + netmask = $("#netmask"), + broadcast = $("#broadcast"), + gateway = $("#gateway"), + dns = $("#dns"), + allFields = $([]).add(ipaddr).add(netmask).add(broadcast).add(gateway).add(dns); + + + $("#nd_manual_configuration_dialog").dialog( + { buttons: { "Cancel": function() { + $(this).dialog("close");}, + "Ok": function() { + var bValid = true; + allFields.removeClass("ui-state-error"); + + bValid = bValid && checkLength(ipaddr, "IP-Address", 7, 15); + bValid = bValid && checkLength(netmask, "Netmask Address", 7, 15); + bValid = bValid && checkLength(broadcast, "Broadcast Address", 7, 15); + bValid = bValid && checkLength(gateway, "Gateway Address", 7, 15); + bValid = bValid && checkLength(dns, "DNS Address", 7, 15); + + bValid = bValid && checkRegexp(ipaddr, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.2 (max value is 255)"); + bValid = bValid && checkRegexp(netmask, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 255.255.255.0 (max value is 255)"); + bValid = bValid && checkRegexp(broadcast, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.255 (max value is 255)"); + bValid = bValid && checkRegexp(gateway, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.254 (max value is 255)"); + bValid = bValid && checkRegexp(dns, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.111 (max value is 255)"); + + if (bValid) { + // put variables into a json object + // send to qt networkdiscovery + var o = {"ifname" : ifname, + "ipaddr" : ipaddr.val(), + "netmask" : netmask.val(), + "broadcast" : broadcast.val(), + "gateway" : gateway.val(), + "dns" : dns.val() } + try { + fbgui.ip4_setManualConfiguration(o); + } catch (e) { + fbgui.notifyCall(e); + } + $(this).dialog("close"); + } } + } , + minWidth: 450, + modal: true, + resizable: false, + draggable: false, + close: function() {allFields.val("").removeClass("ui-state-error");}, + open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();} + }); +}; + +var abortBootDialog = function (m) { + fbgui.notifyCall("abortBootDialog"); + $("#nd_abort_boot_msg").html(m); + $("#nd_abort_boot_dialog").dialog( + { buttons: { "Manual Configure": function() { + ip4_manualConfigurationDialog();}, + "Show Log": function() { + var text = fbgui.readLogFile(); + showLog(text); + $(this).dialog("close");}, + "Restart": function() {fbgui.restartSystem(); + $(this).dialog("close"); }, + "Shut Down": function() { fbgui.shutDownSystem(); + $(this).dialog("close"); } + } , + minWidth: 450, + modal: true, + resizable: false, + draggable: false, + open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();} + }); +}; + +var chooseInterfaceDialog = function (i) { + var cb = ""+ + ""; + + $("#nd_choose_interface_msg").html(cb); + $("#nd_choose_interface_dialog").dialog( + { buttons: { "Manual Configure": function() { + ip4_manualConfigurationDialog();}, + "Show Log": function() { + var text = fbgui.readLogFile(); + showLog(text);}, + "Restart": function() {fbgui.restartSystem(); + $(this).dialog("close"); }, + "Shut Down": function() { fbgui.shutDownSystem(); + $(this).dialog("close"); }, + "Continue": function() { + var ifName = $("#nd_ifName_select :selected").text(); + fbgui.continueBoot(ifName,1); + $(this).dialog("close"); + } + } , + minWidth: 550, + modal: true, + resizable: false, + draggable: false, + open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();} + }); +} + +var updateStatus = function (s){ + +}; + +var updateIfProgressBar = function (i, p){ + if (p >= 0 && p <= 100){ + $("#"+i+"_progress").progressbar({ value: p }); + }else{ + $("#"+i+"_progress").progressbar({ value: 0 }); + } +}; + +var updateIfStatus = function(i, s){ + $("#"+i+"_status").html(s); +}; + +var addInterface = function (i){ + $("#nd_progress_container").append( + "
"+ + " Interface: " +i+ + " Start DHCP " + + "
"+ + "
" + ); + $("#"+i+"_progress").progressbar({ value: 33 }); +}; + + diff --git a/NetworkDiscovery/html/js/test.js b/NetworkDiscovery/html/js/test.js deleted file mode 100644 index be4ec41..0000000 --- a/NetworkDiscovery/html/js/test.js +++ /dev/null @@ -1,3 +0,0 @@ -function qrcAlert(){ - alert('Hello qrc'); -} diff --git a/NetworkDiscovery/html/networkdiscovery.html b/NetworkDiscovery/html/networkdiscovery.html index 6d370d1..66c571e 100644 --- a/NetworkDiscovery/html/networkdiscovery.html +++ b/NetworkDiscovery/html/networkdiscovery.html @@ -5,8 +5,9 @@ - + + diff --git a/NetworkDiscovery/ndgui.cpp b/NetworkDiscovery/ndgui.cpp index bf3b05e..6132079 100644 --- a/NetworkDiscovery/ndgui.cpp +++ b/NetworkDiscovery/ndgui.cpp @@ -186,7 +186,7 @@ void ndgui::loadJQuery() { if (fi.suffix() == "js") { //qDebug()<< fi.fileName(); //qxtLog->debug() << fi.fileName(); - if (fi.fileName() != "test.js" && fi.fileName() != "nd-functions.js") { + //if (fi.fileName() != "test.js" && fi.fileName() != "nd-functions.js") { QFile file; file.setFileName(pathToJsDir + "/" + fi.fileName()); file.open(QIODevice::ReadOnly); @@ -195,7 +195,7 @@ void ndgui::loadJQuery() { _webView->page()->mainFrame()->evaluateJavaScript(js); //qxtLog->debug() << "evaluated " + fi.fileName(); - } + //} } } } @@ -209,7 +209,6 @@ void ndgui::loadJQuery() { // und _webView->page()->mainFrame() zu _parent void ndgui::abortBoot(const QString msg) { - qDebug() << _tag << "call abortBoot:" << msg; QString code = QString("abortBootDialog('\%1')").arg(msg); _webView->page()->mainFrame()->evaluateJavaScript(code); } @@ -235,7 +234,6 @@ void ndgui::updateStatus(const QString &status) { void ndgui::updateIfProgressBar(const QString &ifName, const int& percent) { if (percent == 0) return; - qDebug() << _tag << "call updateIfProgressBar"; QString code = QString("updateIfProgressBar('\%1',\%2)").arg(ifName).arg(percent); _webView->page()->mainFrame()->evaluateJavaScript(code); } @@ -254,7 +252,6 @@ void ndgui::updateIfStatus(const QString &ifName, const QString &status) { void ndgui::addInterface(const QString &ifName) { if (ifName == "") return; - qDebug() << _tag << "call addInterface"; _manConfList.append(ifName); QString code = QString("addInterface('\%1')").arg(ifName); _webView->page()->mainFrame()->evaluateJavaScript(code); -- cgit v1.2.3-55-g7522