From 0efc6355f774a0301306b06fd2a9104bb023d79a Mon Sep 17 00:00:00 2001 From: Timur Sufiev Date: Mon, 27 Apr 2015 21:26:49 +0300 Subject: [PATCH] Rewrite directive Instead of showing popup for the value being edited it now allows editing the same value in-place, accompanied with 2 buttons - confirm & reject the edit. Only when one of 2 these buttons is pressed (or equivalend Enter/Esc keys are pressed) the value will be applied. The directive could be used both for changing Action/Workflow entity names, for changing dictionary and varlist keys. Change-Id: I4e7e1c0fcaed71aa649b1c9925a9b53005ff9a2d Closes-Bug: #1411649 --- .../mistral/templates/fields/varlist.html | 2 +- .../mistral/templates/mistral/create.html | 3 +- karma-unit.conf.js | 1 + merlin/static/merlin/js/merlin.directives.js | 71 ++++++++--- .../static/merlin/js/merlin.field.models.js | 7 ++ merlin/static/merlin/js/merlin.filters.js | 10 +- merlin/static/merlin/scss/merlin.scss | 4 + .../merlin/templates/collapsible-panel.html | 10 +- .../merlin/templates/editable-popup.html | 7 -- merlin/static/merlin/templates/editable.html | 10 ++ .../merlin/templates/fields/dictionary.html | 2 +- merlin/test/js/directivesSpec.js | 112 ++++++++++++++---- 12 files changed, 183 insertions(+), 56 deletions(-) delete mode 100644 merlin/static/merlin/templates/editable-popup.html create mode 100644 merlin/static/merlin/templates/editable.html diff --git a/extensions/mistral/static/mistral/templates/fields/varlist.html b/extensions/mistral/static/mistral/templates/fields/varlist.html index 52f9d29..6979be3 100644 --- a/extensions/mistral/static/mistral/templates/fields/varlist.html +++ b/extensions/mistral/static/mistral/templates/fields/varlist.html @@ -37,7 +37,7 @@
+ content="panel">
-
+

- {$ title $} -

+ + + +
-
\ No newline at end of file +
diff --git a/merlin/static/merlin/templates/editable-popup.html b/merlin/static/merlin/templates/editable-popup.html deleted file mode 100644 index 555601b..0000000 --- a/merlin/static/merlin/templates/editable-popup.html +++ /dev/null @@ -1,7 +0,0 @@ -{$ value $} - - diff --git a/merlin/static/merlin/templates/editable.html b/merlin/static/merlin/templates/editable.html new file mode 100644 index 0000000..06bdd31 --- /dev/null +++ b/merlin/static/merlin/templates/editable.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/merlin/static/merlin/templates/fields/dictionary.html b/merlin/static/merlin/templates/fields/dictionary.html index c0a2ebb..9e6c039 100644 --- a/merlin/static/merlin/templates/fields/dictionary.html +++ b/merlin/static/merlin/templates/fields/dictionary.html @@ -3,7 +3,7 @@
')($scope); + function makePanelElem(content) { + var panel = $compile('')($scope); $scope.$digest(); return panel; } @@ -67,35 +66,35 @@ describe('merlin directives', function() { return element; } - it('shows panel heading when and only when title is passed via attr', function() { + it('shows panel heading when and only when its title() is not false', function() { var title = 'My Panel', - element1 = makePanelElem('title="' + title +'"'), - element2 = makePanelElem(''); + element1, element2; + + $scope.panel1 = { + title: function() { return title; } + }; + $scope.panel2 = {}; + element1 = makePanelElem('panel1'); + element2 = makePanelElem(''); expect(getPanelHeading(element1).hasClass('ng-hide')).toBe(false); expect(element1.html()).toContain(title); expect(getPanelHeading(element2).hasClass('ng-hide')).toBe(true); }); - it('requires both `title` and `removable` to be removable', function() { + it('requires both `.title()` and `.removable` to be removable', function() { var title = 'My Panel', element1, element2; - element1 = makePanelElem('title="' + title +'" removable="true"'); - element2 = makePanelElem('title="' + title +'"'); - - expect(getPanelRemoveButton(element1).hasClass('ng-hide')).toBe(false); - expect(getPanelRemoveButton(element2).hasClass('ng-hide')).toBe(true); - }); - - it('with `on-remove`, but without `removable` is not removable', function() { - var title = 'My Panel', - element1, element2; - - $scope.remove = function() {}; - element1 = makePanelElem( - 'title="' + title +'" removable="true" on-remove="remove()"'); - element2 = makePanelElem('title="' + title +'" on-remove="remove()"'); + $scope.panel1 = { + title: function() { return title; }, + removable: true + }; + $scope.panel2 = { + title: function() { return title; } + }; + element1 = makePanelElem('panel1'); + element2 = makePanelElem('panel2'); expect(getPanelRemoveButton(element1).hasClass('ng-hide')).toBe(false); expect(getPanelRemoveButton(element2).hasClass('ng-hide')).toBe(true); @@ -253,4 +252,67 @@ describe('merlin directives', function() { expect(element.html()).toContain('
')($scope); + $scope.$digest(); + }); + + it('allows to immediately set focus on element after it was shown', function() { + expect(element.is(':focus')).toBe(false); + + $scope.show = true; + $scope.$apply(); + + expect(element.is(':focus')).toBe(true); + }) + }); + + describe('', function() { + it('starts with the value not being edited', function() { + + }); + + it("enters the editing mode once user clicks 'fa-pencil' icon", function() { + + }); + + describe('during editing', function() { + it("pressing any key except 'Enter' or 'Esc' neither exits editing state, nor changes model", function() { + + }); + + it("pressing 'Enter' key changes model and exits editing state", function() { + + }); + + it("clicking 'fa-check' icon changes model and exits editing state", function() { + + }); + + it("pressing 'Esc' key exits editing state without changing model", function() { + + }); + + it("clicking 'fa-close' icon exits editing state without changing model", function() { + + }); + + describe('edit box automatically enlarges', function() { + it('to fit the value being edited', function() { + + }); + + it('up to the limit', function() { + + }); + }) + + }); + + }); }); \ No newline at end of file