2021-12-25 16:45:22 +08:00
|
|
|
function translate_text(text) {
|
|
|
|
if (text.indexOf('Failed') == 0 && text.indexOf(': ') > 0) {
|
|
|
|
var fds = text.split(': ');
|
|
|
|
for (var i = 0; i < fds.length; ++i) {
|
2022-02-01 02:38:52 +08:00
|
|
|
fds[i] = translate(fds[i]);
|
2021-12-25 16:45:22 +08:00
|
|
|
}
|
|
|
|
text = fds.join(': ');
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2021-12-25 16:45:22 +08:00
|
|
|
return text;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
2022-02-01 16:32:56 +08:00
|
|
|
var msgboxTimerFunc = function() {}
|
2022-02-01 02:38:52 +08:00
|
|
|
function closeMsgbox() {
|
2022-02-01 16:32:56 +08:00
|
|
|
self.timer(0, msgboxTimerFunc);
|
2022-02-01 02:38:52 +08:00
|
|
|
$(#msgbox).content(<span />);
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-02-01 02:38:52 +08:00
|
|
|
class MsgboxComponent: Reactor.Component {
|
|
|
|
function this(params) {
|
|
|
|
this.width = params.width;
|
|
|
|
this.height = params.height;
|
|
|
|
this.type = params.type;
|
|
|
|
this.title = params.title;
|
|
|
|
this.content = params.content;
|
2022-10-14 11:19:49 +08:00
|
|
|
this.link = params.link;
|
2022-02-01 02:38:52 +08:00
|
|
|
this.remember = params.remember;
|
|
|
|
this.callback = params.callback;
|
|
|
|
this.hasRetry = params.hasRetry;
|
2022-05-12 17:35:25 +08:00
|
|
|
this.auto_login = params.auto_login;
|
2022-02-01 02:38:52 +08:00
|
|
|
this.contentStyle = params.contentStyle;
|
|
|
|
try { this.content = translate_text(this.content); } catch (e) {}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getIcon(color) {
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "input-password") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return <svg viewBox="0 0 505 505"><circle cx="252.5" cy="252.5" r="252.5" fill={color}/><path d="M271.9 246.1c29.2 17.5 67.6 13.6 92.7-11.5 29.7-29.7 29.7-77.8 0-107.4s-77.8-29.7-107.4 0c-25.1 25.1-29 63.5-11.5 92.7L118.1 347.4l26.2 26.2 26.4 26.4 10.6-10.6-10.1-10.1 9.7-9.7 10.1 10.1 10.6-10.6-10.1-10 9.7-9.7 10.1 10.1 10.6-10.6-26.4-26.3 76.4-76.5z" fill="#fff"/><circle cx="337.4" cy="154.4" r="17.7" fill={color}/></svg>;
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "connecting") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return <svg viewBox="0 0 300 300"><g fill={color}><path d="m221.76 89.414h-143.51c-1.432 0-2.594 1.162-2.594 2.594v95.963c0 1.432 1.162 2.594 2.594 2.594h143.51c1.432 0 2.594-1.162 2.594-2.594v-95.964c0-1.431-1.162-2.593-2.594-2.593z"/><path d="m150 0c-82.839 0-150 67.161-150 150s67.156 150 150 150 150-67.163 150-150-67.164-150-150-150zm92.508 187.97c0 11.458-9.29 20.749-20.749 20.749h-47.144v11.588h23.801c4.298 0 7.781 3.483 7.781 7.781s-3.483 7.781-7.781 7.781h-96.826c-4.298 0-7.781-3.483-7.781-7.781s3.483-7.781 7.781-7.781h23.801v-11.588h-47.145c-11.458 0-20.749-9.29-20.749-20.749v-95.963c0-11.458 9.29-20.749 20.749-20.749h143.51c11.458 0 20.749 9.29 20.749 20.749v95.963z"/></g><path d="m169.62 154.35c-5.0276-5.0336-11.97-8.1508-19.624-8.1508-7.6551 0-14.597 3.1172-19.624 8.1508l-11.077-11.091c7.8656-7.8752 18.725-12.754 30.701-12.754s22.835 4.8788 30.701 12.754l-11.077 11.091zm-32.184 7.0728 12.56 12.576 12.56-12.576c-3.2147-3.2172-7.6555-5.208-12.56-5.208-4.9054 0-9.3457 1.9908-12.56 5.208zm12.56-39.731c14.403 0 27.464 5.8656 36.923 15.338l11.078-11.091c-12.298-12.314-29.276-19.94-48-19.94-18.724 0-35.703 7.626-48 19.94l11.077 11.091c9.4592-9.4728 22.52-15.338 36.923-15.338z" fill="#fff"/></svg>;
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "success") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return <svg viewBox="0 0 512 512"><circle cx="256" cy="256" r="256" fill={color} /><path fill="#fff" d="M235.472 392.08l-121.04-94.296 34.416-44.168 74.328 57.904 122.672-177.016 46.032 31.888z"/></svg>;
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type.indexOf("error") >= 0 || this.type == "re-input-password") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return <svg viewBox="0 0 512 512"><ellipse cx="256" cy="256" rx="256" ry="255.832" fill={color}/><g fill="#fff"><path d="M376.812 337.18l-39.592 39.593-201.998-201.999 39.592-39.592z"/><path d="M376.818 174.825L174.819 376.824l-39.592-39.592 201.999-201.999z"/></g></svg>;
|
|
|
|
}
|
2022-02-01 18:33:18 +08:00
|
|
|
return null;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getInputPasswordContent() {
|
2022-02-01 02:38:52 +08:00
|
|
|
var ts = this.remember ? { checked: true } : {};
|
2021-03-29 15:59:14 +08:00
|
|
|
return <div .form>
|
2022-02-01 02:38:52 +08:00
|
|
|
<div>{translate('Please enter your password')}</div>
|
2021-12-25 16:45:22 +08:00
|
|
|
<PasswordComponent />
|
2022-02-01 02:38:52 +08:00
|
|
|
<div><button|checkbox(remember) {ts}>{translate('Remember password')}</button></div>
|
2021-03-29 15:59:14 +08:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getContent() {
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "input-password") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return this.getInputPasswordContent();
|
|
|
|
}
|
2022-05-12 17:35:25 +08:00
|
|
|
if (this.type == "custom-os-password") {
|
|
|
|
var ts = this.auto_login ? { checked: true } : {};
|
|
|
|
return <div .form>
|
|
|
|
<PasswordComponent value={this.content} />
|
2022-09-06 15:13:22 +08:00
|
|
|
<div><button|checkbox(auto_login) {ts} style="width: *; word-wrap: break-word; overflow-wrap: break-word; white-space: normal; height: auto; overflow: hidden;">{translate('Auto Login')}</button></div>
|
2022-05-12 17:35:25 +08:00
|
|
|
</div>;
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
return this.content;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getColor() {
|
2022-05-12 17:35:25 +08:00
|
|
|
if (this.type == "input-password" || this.type == "custom-os-password") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return "#AD448E";
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "success") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return "#32bea6";
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type.indexOf("error") >= 0 || this.type == "re-input-password") {
|
2021-03-29 15:59:14 +08:00
|
|
|
return "#e04f5f";
|
|
|
|
}
|
|
|
|
return "#2C8CFF";
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasSkip() {
|
2022-02-01 02:38:52 +08:00
|
|
|
return this.type.indexOf("skip") >= 0;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
2022-02-01 02:38:52 +08:00
|
|
|
this.set_outline_focus();
|
2021-03-29 15:59:14 +08:00
|
|
|
var color = this.getColor();
|
|
|
|
var icon = this.getIcon(color);
|
|
|
|
var content = this.getContent();
|
2022-07-25 19:35:15 +08:00
|
|
|
var hasCancel = this.type.indexOf("error") < 0 && this.type.indexOf("nocancel") < 0 && this.type != "restarting";
|
2022-06-13 15:38:30 +08:00
|
|
|
var hasOk = this.type != "connecting" && this.type != "success" && this.type.indexOf("nook") < 0;
|
2022-10-14 11:19:49 +08:00
|
|
|
var hasLink = this.link != "";
|
2022-02-01 02:38:52 +08:00
|
|
|
var hasClose = this.type.indexOf("hasclose") >= 0;
|
|
|
|
var show_progress = this.type == "connecting";
|
2021-03-29 15:59:14 +08:00
|
|
|
var me = this;
|
2022-02-01 16:32:56 +08:00
|
|
|
self.timer(0, msgboxTimerFunc);
|
|
|
|
msgboxTimerFunc = function() {
|
2021-03-29 15:59:14 +08:00
|
|
|
if (typeof content == "string")
|
2022-02-01 02:38:52 +08:00
|
|
|
me.$(#content).html = translate(content);
|
2021-03-29 15:59:14 +08:00
|
|
|
else
|
|
|
|
me.$(#content).content(content);
|
2022-02-01 16:32:56 +08:00
|
|
|
};
|
|
|
|
self.timer(3ms, msgboxTimerFunc);
|
2022-02-01 02:38:52 +08:00
|
|
|
return (<div><div style="position: absolute; size:*; background:black; opacity:0.5;" />
|
|
|
|
<div style="size: *; position: absolute;">
|
2022-05-22 09:05:58 +08:00
|
|
|
<div style={"border: " + color + " solid 1px; background: color(bg); margin: *; width:" + (this.width) + "px; min-height:" + (this.height) + "px"}>
|
2022-02-01 02:38:52 +08:00
|
|
|
<div .caption style={"background: " + color}>
|
|
|
|
{translate(this.title)}
|
|
|
|
</div>
|
2021-03-29 15:59:14 +08:00
|
|
|
<div style="padding: 1em 2em; size: *;">
|
|
|
|
<div style="height: *; flow: horizontal">
|
2022-02-01 02:38:52 +08:00
|
|
|
{icon && <div style="height: *; margin: * 0; padding-right: 2em;" .msgbox-icon>{icon}</div>}
|
|
|
|
<div style={this.contentStyle || "size: *; margin: * 0;"} #content />
|
2021-03-29 15:59:14 +08:00
|
|
|
</div>
|
|
|
|
<div style="text-align: right;">
|
2022-01-19 23:30:21 +08:00
|
|
|
<span style="display:inline-block; max-width: 250px; font-size:12px;" #error />
|
2021-12-25 16:45:22 +08:00
|
|
|
<progress #progress style={"color:" + color + "; display: " + (show_progress ? "inline-block" : "none")} />
|
2022-02-01 02:38:52 +08:00
|
|
|
{hasCancel || this.hasRetry ? <button .button #cancel .outline>{translate(this.hasRetry ? "OK" : "Cancel")}</button> : ""}
|
|
|
|
{this.hasSkip() ? <button .button #skip .outline>{translate('Skip')}</button> : ""}
|
|
|
|
{hasOk || this.hasRetry ? <button .button #submit>{translate(this.hasRetry ? "Retry" : "OK")}</button> : ""}
|
2022-10-14 11:19:49 +08:00
|
|
|
{hasLink ? <button .button #jumplink .outline>{translate('JumpLink')}</button> : ""}
|
2022-02-01 02:38:52 +08:00
|
|
|
{hasClose ? <button .button #cancel .outline>{translate('Close')}</button> : ""}
|
2021-03-29 15:59:14 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-02-01 02:38:52 +08:00
|
|
|
</div>
|
|
|
|
</div></div>);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
event click $(.custom-event) (_, me) {
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.callback) this.callback(me);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
function submit() {
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.$(button#submit)) {
|
|
|
|
this.$(button#submit).sendEvent("click");
|
2022-01-29 16:56:24 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
function cancel() {
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.$(button#cancel)) {
|
|
|
|
this.$(button#cancel).sendEvent("click");
|
2022-01-29 16:56:24 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
event click $(button#cancel) {
|
2022-02-01 02:38:52 +08:00
|
|
|
this.close();
|
|
|
|
if (this.callback) this.callback(null);
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
event click $(button#skip) {
|
|
|
|
var values = this.getValues();
|
|
|
|
values.skip = true;
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.callback) this.callback(values);
|
2022-03-28 19:05:12 +08:00
|
|
|
if (this.close) this.close();
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-10-14 11:19:49 +08:00
|
|
|
|
|
|
|
event click $(button#jumplink) {
|
|
|
|
if (this.link.indexOf("http") == 0) {
|
2022-10-17 09:41:02 +08:00
|
|
|
Sciter.launch(this.link);
|
2022-10-14 11:19:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
event click $(button#submit) {
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "error") {
|
|
|
|
if (this.hasRetry) {
|
|
|
|
retryConnect(true);
|
|
|
|
return;
|
2022-01-29 16:56:24 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "re-input-password") {
|
|
|
|
this.type = "input-password";
|
2022-02-01 16:32:56 +08:00
|
|
|
this.update();
|
2022-01-29 16:56:24 +08:00
|
|
|
return;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
var values = this.getValues();
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.callback) {
|
2022-03-09 21:43:50 +08:00
|
|
|
var self = this;
|
|
|
|
var err = this.callback(values, function(a=1, b='') { self.show_progress(a, b); });
|
2022-02-01 02:38:52 +08:00
|
|
|
if (!err) {
|
2022-03-28 19:05:12 +08:00
|
|
|
if (this.close) this.close();
|
2022-01-29 16:56:24 +08:00
|
|
|
return;
|
|
|
|
}
|
2022-03-04 00:52:59 +08:00
|
|
|
if (err && err.trim()) this.show_progress(false, err);
|
2022-02-01 02:38:52 +08:00
|
|
|
} else {
|
|
|
|
this.close();
|
2022-01-29 16:56:24 +08:00
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
event keydown (evt) {
|
|
|
|
if (!evt.shortcutKey) {
|
2022-02-09 16:06:44 +08:00
|
|
|
if (isEnterKey(evt)) {
|
2022-01-29 16:56:24 +08:00
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
if (evt.keyCode == Event.VK_ESCAPE) {
|
|
|
|
this.cancel();
|
|
|
|
}
|
2021-12-25 16:45:22 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
}
|
2022-09-15 17:31:28 +08:00
|
|
|
|
|
|
|
event click $(button#select_directory) {
|
|
|
|
var folder = view.selectFolder(translate("Change"), $(#folderPath).text);
|
|
|
|
if (folder) {
|
|
|
|
if (folder.indexOf("file://") == 0) folder = folder.substring(7);
|
|
|
|
$(#folderPath).text = folder;
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
function show_progress(show=1, err="") {
|
|
|
|
if (show == -1) {
|
2022-02-01 02:38:52 +08:00
|
|
|
this.close()
|
2021-03-29 15:59:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
this.$(#progress).style.set {
|
2022-01-29 16:56:24 +08:00
|
|
|
display: show ? "inline-block" : "none"
|
|
|
|
};
|
2022-02-01 02:38:52 +08:00
|
|
|
this.$(#error).text = err;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-01-29 16:56:24 +08:00
|
|
|
|
|
|
|
function getValues() {
|
2022-02-01 02:38:52 +08:00
|
|
|
var values = { type: this.type };
|
|
|
|
for (var el in this.$$(.form input)) {
|
2022-01-29 16:56:24 +08:00
|
|
|
values[el.attributes["name"]] = el.value;
|
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
for (var el in this.$$(.form textarea)) {
|
2022-01-29 16:56:24 +08:00
|
|
|
values[el.attributes["name"]] = el.value;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
for (var el in this.$$(.form button)) {
|
2022-01-29 16:56:24 +08:00
|
|
|
values[el.attributes["name"]] = el.value;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
if (this.type == "input-password") {
|
2022-01-29 16:56:24 +08:00
|
|
|
values.password = (values.password || "").trim();
|
|
|
|
if (!values.password) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return values;
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|
2022-02-01 02:38:52 +08:00
|
|
|
|
|
|
|
function set_outline_focus() {
|
|
|
|
var me = this;
|
|
|
|
self.timer(30ms, function() {
|
|
|
|
var el = me.$(.outline-focus);
|
2021-03-29 15:59:14 +08:00
|
|
|
if (el) view.focus = el;
|
2022-02-01 02:38:52 +08:00
|
|
|
else {
|
|
|
|
el = me.$(#submit);
|
|
|
|
if (el) {
|
|
|
|
view.focus = el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
|
2022-02-01 02:38:52 +08:00
|
|
|
function close() {
|
|
|
|
closeMsgbox();
|
|
|
|
}
|
2021-03-29 15:59:14 +08:00
|
|
|
}
|