diff --git a/libresapi/src/webui-src/app/accountselect.js b/libresapi/src/webui-src/app/accountselect.js index 3def5da58..1b989579c 100644 --- a/libresapi/src/webui-src/app/accountselect.js +++ b/libresapi/src/webui-src/app/accountselect.js @@ -32,10 +32,15 @@ module.exports = {view: function(){ accounts.map(function(account){ accountMap.set(account.id,account); return [ - m("div.btn2", {onclick: m.withAttr("account", selAccount), account:account.id }, account.location + " (" + account.name + ")"), + m("div.btn2", { + onclick: m.withAttr("account", selAccount), + account:account.id + }, + account.location + " (" + account.name + ")"), m("br") - ] - })]); + ] + }) + ]); } else { return m("div", "logging in ..." ); } diff --git a/libresapi/src/webui-src/app/assets/index.html b/libresapi/src/webui-src/app/assets/index.html index f4aacba35..438ac876d 100644 --- a/libresapi/src/webui-src/app/assets/index.html +++ b/libresapi/src/webui-src/app/assets/index.html @@ -14,6 +14,9 @@ var ui = require("main"); var main = document.getElementById("main"); ui.init(main); + if (m.initControl != undefined) { + m.initControl.focus(); + } } diff --git a/libresapi/src/webui-src/app/createlogin.js b/libresapi/src/webui-src/app/createlogin.js new file mode 100644 index 000000000..1161b7656 --- /dev/null +++ b/libresapi/src/webui-src/app/createlogin.js @@ -0,0 +1,110 @@ +var m = require("mithril"); +var rs = require("retroshare"); + +var locationName = ""; +var password =""; + +function listprofiles(){ + var locations = rs("control/locations"); + var knownProfileIds = []; + var result = []; + if(locations === undefined || locations == null){ + return m("div", "profiles: waiting_server"); + } + locations.map(function(location) { + if (knownProfileIds.indexOf(location.pgp_id)<0){ + knownProfileIds.push(location.pgp_id); + result.push(m( + "div.btn2",{ + onclick: function(){ + m.route("/createlogin",{ + id: location.pgp_id, + name: location.name, + }) + } + }, + location.name + )); + } + }); + + return result; +} + +function setLocationName(location) { + locationName = location; +} + +function setPasswd(passwd) { + password = passwd; +} + + +function createLocation(loc) { + rs.request("control/create_location",loc,function(data){ + m.route("/accountselect", {}); + }); + m.route("/createlogin",{state:wait}); +} + + +module.exports = { + view: function(){ + var profile = m.route.param("id"); + var state = m.route.param("state"); + var profname = m.route.param("name"); + var hidden = m.route.param("hidden"); + if (state == "wait"){ + return m("div","waiting ..."); + } else if (profile === undefined) { + return m("div",[ + m("h2","create login - Step 1 / 2: select profile(PGP-ID)"), + m("hr"), + m("div.btn2",{} ,""), + m("div.btn2",{} ,""), + listprofiles() + ]); + }; + m.initControl = "txtpasswd"; + return m("div",[ + m("h2","create login - Step 2 / 2: create location"), + m("h3","- for " + profname + " (" +profile + ")"), + m("hr"), + m("h2","enter password:"), + m("input", { + id: "txtpasswd", + type:"password", + onchange: m.withAttr("value",setPasswd), + onkeydown: function(event){ + if (event.keyCode == 13){ + setPasswd(this.value); + document.getElementById("txtlocation").focus(); + } + } + }), + m("h2","location name:"), + m("input",{ + id: "txtlocation", + type:"text", + onchange:m.withAttr("value", setLocationName), + onkeydown: function(event){ + if (event.keyCode == 13){ + createLocation({ + ssl_name: this.value, + pgp_id: profile, + pgp_password: password, + }); + } + }, + }), + m("br"), + m("input",{ + type: "button", + onclick: function(){ + createLocation(locationName); + }, + value: "create location", + }), + ]); + } +} diff --git a/libresapi/src/webui-src/app/main.js b/libresapi/src/webui-src/app/main.js index 32ea255a0..5483609d0 100644 --- a/libresapi/src/webui-src/app/main.js +++ b/libresapi/src/webui-src/app/main.js @@ -27,12 +27,27 @@ function Page(content, runst){ } else if (runstate.runstate == null){ return m("h2", "server down"); } else if (needpasswd != undefined && needpasswd.want_password === true){ + m.initControl = "txtpasswd"; return m("div",[ m("h2","password required"), m("h3",needpasswd.key_name), - m("input",{type:"password", onchange:m.withAttr("value", setPasswd)}), + m("input",{ + id: "txtpasswd", + type:"password", + onchange:m.withAttr("value", setPasswd), + onkeydown: function(event){ + if (event.keyCode == 13){ + setPasswd(this.value); + sendPassword(needpasswd); + } + } + }), m("br"), - m("input[type=button][value=send password]",{onclick: function(){sendPassword(needpasswd);}}), + m("input[type=button][value=send password]",{ + onclick: function(){ + sendPassword(needpasswd); + } + }), ]); } else { if ("waiting_init|waiting_startup".match(runstate.runstate)) { diff --git a/libresapi/src/webui-src/app/menudef.js b/libresapi/src/webui-src/app/menudef.js index 9da066caa..cac6299a0 100644 --- a/libresapi/src/webui-src/app/menudef.js +++ b/libresapi/src/webui-src/app/menudef.js @@ -8,6 +8,12 @@ module.exports = { nodes: [ module: "accountselect", runstate: "waiting_account_select", }, + { + name: "create login", + path: "/createlogin", + module: "createlogin", + runstate: "waiting_account_select", + }, { name: "peers", runstate: "running_ok.*", diff --git a/libresapi/src/webui-src/app/retroshare.js b/libresapi/src/webui-src/app/retroshare.js index 4bedf306d..6c1763573 100644 --- a/libresapi/src/webui-src/app/retroshare.js +++ b/libresapi/src/webui-src/app/retroshare.js @@ -88,6 +88,7 @@ function check_for_changes(){ m.sync(requests).then(function trigger_render(){ m.startComputation(); m.endComputation(); + checkFocus(); setTimeout(check_for_changes, 500); }); } @@ -148,10 +149,23 @@ function schedule_request_missing(){ m.sync(requests).then(function trigger_render(){ m.startComputation(); m.endComputation(); + checkFocus(); }); }); } +function checkFocus(){ + if (m.initControl != undefined) { + var ctrl = document.getElementById(m.initControl); + if (ctrl!= null) { + ctrl.focus(); + m.initControl = undefined; + } else { + console.log("focus-control '" + m.initControl + "' not found!") + } + } +} + // called every time, rs or rs.request failed, only response or value is set function requestFail(path, response, value) { rs.error = "error on " + path;