New UI tool: confirm button

pull/1/head
yflory 5 years ago
parent 689ea40a92
commit 2e631a8b5f

@ -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) { button:not(.pure-button):not(.md-button):not(.mdl-button) {

@ -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) { UI.proposal = function (content, cb) {
var buttons = [{ var buttons = [{

@ -1208,7 +1208,7 @@ define([
var spinner = UI.makeSpinner(); var spinner = UI.makeSpinner();
var button = h('button.btn.btn-danger-alt', { var button = h('button.btn.btn-danger-alt', {
disabled: 'disabled' disabled: 'disabled'
}, Messages.trimHistory_button || 'test'); // XXX }, Messages.trimHistory_button || 'delete history... xxx'); // XXX
var currentSize = h('p', $(spinner.spinner).clone()[0]); var currentSize = h('p', $(spinner.spinner).clone()[0]);
var content = h('div', [ var content = h('div', [
currentSize, currentSize,
@ -1238,7 +1238,10 @@ define([
}).nThen(function () { }).nThen(function () {
$(currentSize).html(Messages._getKey('trimHistory_currentSize', [size])); $(currentSize).html(Messages._getKey('trimHistory_currentSize', [size]));
$button.click(function () { $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; } if (!yes) { return; }
$button.remove(); $button.remove();

Loading…
Cancel
Save