var type, title, text, getParams, remember, hasRetry, callback; function updateParams(params) { type = params.type; title = params.title; text = params.text; getParams = params.getParams; remember = params.remember; callback = params.callback; hasRetry = type == "error" && title == "Connection Error" && text.toLowerCase().indexOf("offline") < 0 && text.toLowerCase().indexOf("exist") < 0 && text.toLowerCase().indexOf("handshake") < 0 && text.toLowerCase().indexOf("failed") < 0 && text.toLowerCase().indexOf("resolve") < 0 && text.toLowerCase().indexOf("manually") < 0; if (hasRetry) { self.timer(1s, function() { view.close({ reconnect: true }); }); } } var params = view.parameters; updateParams(params); var svg_eye_cross = ; class Password: Reactor.Component { this var visible = false; function render() { return
{this.visible ? svg_eye_cross : svg_eye}
; } event click $(svg) { var el = this.$(input); var value = el.value; var start = el.xcall(#selectionStart) || 0; var end = el.xcall(#selectionEnd); this.update({ visible: !this.visible }); self.timer(30ms, function() { var el = this.$(input); view.focus = el; el.value = value; el.xcall(#setSelection, start, end); }); } } var body; class Body: Reactor.Component { function this() { body = this; } function getIcon(color) { if (type == "input-password") { return ; } if (type == "connecting") { return ; } if (type == "success") { return ; } if (type.indexOf("error") >= 0 || type == "re-input-password") { return ; } return ; } function getInputPasswordContent() { var ts = remember ? { checked: true } : {}; return
Please enter your password
Remember password
; } function getContent() { if (type == "input-password") { return this.getInputPasswordContent(); } return text; } function getColor() { if (type == "input-password") { return "#AD448E"; } if (type == "success") { return "#32bea6"; } if (type.indexOf("error") >= 0 || type == "re-input-password") { return "#e04f5f"; } return "#2C8CFF"; } function hasSkip() { return type.indexOf("skip") >= 0; } function render() { var color = this.getColor(); var icon = this.getIcon(color); var content = this.getContent(); var hasCancel = type.indexOf("error") < 0 && type != "success" && type.indexOf("nocancel") < 0; var hasOk = type != "connecting" && type.indexOf("nook") < 0; var hasClose = type.indexOf("hasclose") >= 0; var show_progress = type == "connecting"; self.style.set { border: color + " solid 1px" }; var me = this; self.timer(1ms, function() { if (typeof content == "string") me.$(#content).html = content; else me.$(#content).content(content); }); return (
{title}
{icon &&
{icon}
}
{show_progress ? : ""} {hasCancel || hasRetry ? : ""} {this.hasSkip() ? : ""} {hasOk || hasRetry ? : ""} {hasClose ? : ""}
); } event click $(.custom-event) (_, me) { if (callback) callback(me); } } $(body).content(); function submit() { if ($(button#submit)) { $(button#submit).sendEvent("click"); } } function cancel() { if ($(button#cancel)) { $(button#cancel).sendEvent("click"); } } event click $(button#cancel) { view.close(); if (callback) callback(null); } event click $(button#skip) { var values = getValues(); values.skip = true; view.close(values); if (callback) callback(values); } function getValues() { var values = { type: type }; for (var el in $$(.form input)) { values[el.attributes["name"]] = el.value; } for (var el in $$(.form textarea)) { values[el.attributes["name"]] = el.value; } for (var el in $$(.form button)) { values[el.attributes["name"]] = el.value; } if (type == "input-password") { values.password = (values.password || "").trim(); if (!values.password) { return; } } return values; } event click $(button#submit) { if (type == "error") { if (hasRetry) { view.close({ reconnect: true }); } else { view.close(); if (callback) callback(null); } return; } if (type == "re-input-password") { type = "input-password"; body.update(); set_outline_focus(); return; } var values = getValues(); if (callback) { var err = callback(values); if (err) { $(#error).text = err; return; } } view.close(values); } event keydown (evt) { if (!evt.shortcutKey) { if (evt.keyCode == Event.VK_ENTER || (is_osx && evt.keyCode == 0x4C) || (is_linux && evt.keyCode == 65421)) { submit(); } if (evt.keyCode == Event.VK_ESCAPE) { cancel(); } } } function set_outline_focus() { self.timer(30ms, function() { var el = $(input.outline-focus); if (el) view.focus = el; else { el = $(#submit); if (el) view.focus = el; } }); } set_outline_focus(); function checkParams() { self.timer(30ms, function() { var tmp = getParams(); if (!tmp || !tmp.type) { view.close("!alive"); return; } else if (tmp != params) { params = tmp; updateParams(params); body.update(); set_outline_focus(); } checkParams(); }); } checkParams();