From 729a167e5913599451b10fed244dcf66b375c4c9 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 13 Mar 2020 15:05:07 +0100 Subject: [PATCH] Confirm button in kanban edit modal --- .../src/less2/include/alertify.less | 7 ++- www/common/common-interface.js | 23 ++++++++- www/kanban/inner.js | 50 ++++++++++--------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/customize.dist/src/less2/include/alertify.less b/customize.dist/src/less2/include/alertify.less index cd6a65853..f9c63215c 100644 --- a/customize.dist/src/less2/include/alertify.less +++ b/customize.dist/src/less2/include/alertify.less @@ -288,15 +288,18 @@ nav { padding: @alertify_padding-base; text-align: right; - button { + button, div.cp-button-confirm { margin: 0px !important; - &:not(:first-child) { + &:not(:first-child):not(.left) { margin-left: @alertify_padding-base !important; } &.left { float: left; } } + div.cp-button-confirm { + vertical-align: middle; + } } } } diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 1a9e2c7ba..6f9b4bed2 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -386,7 +386,7 @@ define([ buttons.forEach(function (b) { if (!b.name || !b.onClick) { return; } var button = h('button', { tabindex: '1', 'class': b.className || '' }, b.name); - $(button).click(function () { + var todo = function () { var noClose = b.onClick(); if (noClose) { return; } var $modal = $(button).parents('.alertify').first(); @@ -397,7 +397,17 @@ define([ } }); } - }); + }; + if (b.confirm) { + UI.confirmButton(button, { + classes: 'danger', + divClasses: 'left' + }, todo); + } else { + $(button).click(function () { + todo(); + }); + } if (b.keys && b.keys.length) { $(button).attr('data-keys', JSON.stringify(b.keys)); } navs.push(button); }); @@ -620,6 +630,9 @@ define([ button, timer ]); + if (config.divClasses) { + $(content).addClass(config.divClasses); + } var to; @@ -653,6 +666,12 @@ define([ to = setTimeout(todo, INTERVAL); $(originalBtn).hide().after(content); }); + + return { + reset: function () { + done(false); + } + }; }; diff --git a/www/kanban/inner.js b/www/kanban/inner.js index 5a3655a3f..bdff3e640 100644 --- a/www/kanban/inner.js +++ b/www/kanban/inner.js @@ -332,32 +332,11 @@ define([ } }; - var setId = function (_isBoard, _id) { - isBoard = _isBoard; - id = _id; - if (_isBoard) { - onCursorUpdate.fire({ - board: _id - }); - dataObject = kanban.getBoardJSON(id); - $(content) - .find('#cp-kanban-edit-body, #cp-kanban-edit-tags, [for="cp-kanban-edit-body"], [for="cp-kanban-edit-tags"]') - .hide(); - } else { - onCursorUpdate.fire({ - item: _id - }); - dataObject = kanban.getItemJSON(id); - $(content) - .find('#cp-kanban-edit-body, #cp-kanban-edit-tags, [for="cp-kanban-edit-body"], [for="cp-kanban-edit-tags"]') - .show(); - } - }; - var button = [{ className: 'danger left', name: Messages.kanban_delete, - onClick: function () { + confirm: true, + onClick: function (button) { var boards = kanban.options.boards || {}; if (isBoard) { var list = boards.list || []; @@ -390,6 +369,31 @@ define([ }); modal.classList.add('cp-kanban-edit-modal'); + var setId = function (_isBoard, _id) { + // Reset the mdoal with a new id + isBoard = _isBoard; + id = _id; + if (_isBoard) { + onCursorUpdate.fire({ + board: _id + }); + dataObject = kanban.getBoardJSON(id); + $(content) + .find('#cp-kanban-edit-body, #cp-kanban-edit-tags, [for="cp-kanban-edit-body"], [for="cp-kanban-edit-tags"]') + .hide(); + } else { + onCursorUpdate.fire({ + item: _id + }); + dataObject = kanban.getItemJSON(id); + $(content) + .find('#cp-kanban-edit-body, #cp-kanban-edit-tags, [for="cp-kanban-edit-body"], [for="cp-kanban-edit-tags"]') + .show(); + } + // Also reset the buttons + $(modal).find('nav').after(UI.dialog.getButtons(button)).remove(); + }; + onRemoteChange.reg(function () { if (isBoard) { dataObject = kanban.getBoardJSON(id);