From e1c02fd8a45758b4b5a60c0f5b6a9acbcee6871e Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 6 Mar 2017 18:15:14 +0100 Subject: [PATCH] Drive rename: save pads and folders name on click, cancel with Esc. --- www/drive/main.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/www/drive/main.js b/www/drive/main.js index ed31ee6d8..9d1d0265c 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -245,7 +245,13 @@ define([ if (!$container.length) { return; } $container.html(''); }; - var removeInput = function () { + var removeInput = function (cancel) { + if (!cancel && $iframe.find('.element-row > input').length === 1) { + var $input = $iframe.find('.element-row > input'); + filesOp.renameElement($input.data('path'), $input.val(), function () { + refresh(); + }); + } $iframe.find('.element-row > input').remove(); $iframe.find('.element-row > span:hidden').removeAttr('style'); }; @@ -306,13 +312,17 @@ define([ var $input = $('', { placeholder: name, value: name - }); + }).data('path', path); $input.on('keyup', function (e) { if (e.which === 13) { - removeInput(); + removeInput(true); filesOp.renameElement(path, $input.val(), function () { refresh(); }); + return; + } + if (e.which === 27) { + removeInput(true); } }); //$element.parent().append($input); @@ -1812,12 +1822,12 @@ define([ $(ifrw).on('click', function (e) { if (e.which !== 1) { return ; } removeSelected(e); - removeInput(e); + removeInput(); module.hideMenu(e); hideNewButton(); }); $(ifrw).on('drag drop', function (e) { - removeInput(e); + removeInput(); module.hideMenu(e); }); $(ifrw).on('mouseup drop', function (e) {