From 77600d4d11a26d6c2e759b5c4b1fd508757d2516 Mon Sep 17 00:00:00 2001 From: Gerard Date: Fri, 8 Feb 2019 15:08:36 +0100 Subject: [PATCH] #1024 td-editable component created --- front/core/components/td-editable/index.html | 4 ++ front/core/components/td-editable/index.js | 44 ++++++++++++++++++++ front/core/components/td-editable/style.scss | 16 +++++++ 3 files changed, 64 insertions(+) create mode 100644 front/core/components/td-editable/index.html create mode 100644 front/core/components/td-editable/index.js create mode 100644 front/core/components/td-editable/style.scss diff --git a/front/core/components/td-editable/index.html b/front/core/components/td-editable/index.html new file mode 100644 index 000000000..14336126d --- /dev/null +++ b/front/core/components/td-editable/index.html @@ -0,0 +1,4 @@ + + + +
diff --git a/front/core/components/td-editable/index.js b/front/core/components/td-editable/index.js new file mode 100644 index 000000000..49a4c3dcd --- /dev/null +++ b/front/core/components/td-editable/index.js @@ -0,0 +1,44 @@ +import ngModule from '../../module'; +import Component from '../../lib/component'; +import './style.scss'; + +export default class Controller extends Component { + constructor($element, $scope, $transclude) { + super($element, $scope); + let element = $element[0]; + element.tabIndex = 0; + + element.addEventListener('focus', () => { + $transclude((tClone, tScope) => { + this.field = tClone; + this.tScope = tScope; + this.element.querySelector('.field').appendChild(this.field[0]); + }, null, 'field'); + element.classList.add('selected'); + }); + + element.addEventListener('focusout', event => { + this.lastEvent = event; + let target = event.relatedTarget; + while (target && target.parentNode != element) + target = target.parentNode; + + if (!target) { + this.tScope.$destroy(); + this.field.remove(); + element.classList.remove('selected'); + } + }); + } +} + +Controller.$inject = ['$element', '$scope', '$transclude']; + +ngModule.component('vnTdEditable', { + template: require('./index.html'), + controller: Controller, + transclude: { + text: 'text', + field: '?field' + } +}); diff --git a/front/core/components/td-editable/style.scss b/front/core/components/td-editable/style.scss new file mode 100644 index 000000000..563590b3d --- /dev/null +++ b/front/core/components/td-editable/style.scss @@ -0,0 +1,16 @@ +vn-td-editable { + cursor: pointer; + & > div.text-container{ + width: 100%; + } + + &.selected { + & > .text-container{ + display: none; + } + } + + vn-icon { + font-size: 1em; + } +} \ No newline at end of file