From 2e631a8b5f6682ba11933dfff47aa867e1cca096 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 4 Feb 2020 14:49:31 +0100 Subject: [PATCH] New UI tool: confirm button --- customize.dist/src/less2/include/buttons.less | 16 ++++++ www/common/common-interface.js | 53 +++++++++++++++++++ www/settings/inner.js | 7 ++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/customize.dist/src/less2/include/buttons.less b/customize.dist/src/less2/include/buttons.less index a907d2a0b..4bcb61e44 100644 --- a/customize.dist/src/less2/include/buttons.less +++ b/customize.dist/src/less2/include/buttons.less @@ -48,6 +48,22 @@ } } + div.cp-button-confirm { + display: inline-block; + button { + margin: 0; + } + .cp-button-timer { + height: 3px; + & > div { + height: 100%; + background-color: @colortheme_alertify-primary; + &.danger, &.btn-danger, &.danger-alt, &.btn-danger-alt { + background-color: @colortheme_alertify-red; + } + } + } + } button:not(.pure-button):not(.md-button):not(.mdl-button) { diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 1d681d6e9..9ca5dbac8 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -593,6 +593,59 @@ define([ } }); }; + UI.confirmButton = function (originalBtn, config, _cb) { + config = config || {}; + cb = Util.once(Util.mkAsync(_cb)); + + var classes = 'btn ' + (config.classes || 'btn-primary'); + + var button = h('button', { + "class": classes, + title: config.title || '' + }, Messages.areYouSure || "Are you sure?"); // XXX + var $button = $(button); + + var div = h('div', { + "class": config.classes || '' + }); + var timer = h('div.cp-button-timer', div); + + var content = h('div.cp-button-confirm', [ + button, + timer + ]); + + var to; + + var done = function (res) { + cb(res); + clearTimeout(to); + $(content).remove(); + $(originalBtn).show(); + }; + + $button.click(function () { + done(true); + }); + + var TIMEOUT = 3000; + var INTERVAL = 10; + var i = 1; + + var todo = function () { + var p = 100 * ((TIMEOUT - (i * INTERVAL)) / TIMEOUT); + if (i++ * INTERVAL >= TIMEOUT) { + done(false); + return; + } + $(div).css('width', p+'%'); + to = setTimeout(todo, INTERVAL); + }; + to = setTimeout(todo, INTERVAL); + + $(originalBtn).hide().after(content); + }; + UI.proposal = function (content, cb) { var buttons = [{ diff --git a/www/settings/inner.js b/www/settings/inner.js index 8270c7c2d..b19716fde 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -1208,7 +1208,7 @@ define([ var spinner = UI.makeSpinner(); var button = h('button.btn.btn-danger-alt', { disabled: 'disabled' - }, Messages.trimHistory_button || 'test'); // XXX + }, Messages.trimHistory_button || 'delete history... xxx'); // XXX var currentSize = h('p', $(spinner.spinner).clone()[0]); var content = h('div', [ currentSize, @@ -1238,7 +1238,10 @@ define([ }).nThen(function () { $(currentSize).html(Messages._getKey('trimHistory_currentSize', [size])); $button.click(function () { - UI.confirm(Messages.trimHistory_confirm, function (yes) { + //UI.confirm(Messages.trimHistory_confirm, function (yes) { + UI.confirmButton(button, { + classes: 'btn-danger' + }, function (yes) { if (!yes) { return; } $button.remove();