From 9435e6f1e60cd92a496678cb7f612656046a870f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 1 Feb 2017 10:05:15 +0100 Subject: [PATCH] Errores solucionados --- client/core/src/popover/index.js | 148 ++++++++++++++++--------------- client/core/src/validation.js | 4 +- package.json | 1 + 3 files changed, 78 insertions(+), 75 deletions(-) diff --git a/client/core/src/popover/index.js b/client/core/src/popover/index.js index 17bd9a077..3b38baf26 100644 --- a/client/core/src/popover/index.js +++ b/client/core/src/popover/index.js @@ -15,82 +15,84 @@ export function directive(popover) { } module.directive('vnPopover', directive); -factory.$inject = ['$document', '$compile']; -function factory($document, $compile) { - return { - show: function(childElement, parent) { - let popover = $document[0].createElement('div'); - popover.className = 'vn-popover'; - popover.addEventListener('mousedown', - this.onPopoverMouseDown.bind(this)); - popover.appendChild (childElement); - this.popover = popover; +export class Popover { + constructor($document, $compile) { + this.document = $document[0]; + this.$compile = $compile; + } + show(childElement, parent) { + let popover = this.document.createElement('div'); + popover.className = 'vn-popover'; + popover.addEventListener('mousedown', + (event) => this.onPopoverMouseDown(event)); + popover.appendChild(childElement); + this.popover = popover; - let style = popover.style; + let style = popover.style; - let spacing = 0; - let screenMargin = 20; - let dblMargin = screenMargin * 2; + let spacing = 0; + let screenMargin = 20; + let dblMargin = screenMargin * 2; - let width = popover.offsetWidth; - let height = popover.offsetHeight; - let innerWidth = window.innerWidth; - let innerHeight = window.innerHeight; + let width = popover.offsetWidth; + let height = popover.offsetHeight; + let innerWidth = window.innerWidth; + let innerHeight = window.innerHeight; - if(width + dblMargin > innerWidth) { - width = innerWidth - dblMargin; - style.width = width +'px'; - } - if(height + dblMargin > innerHeight) { - height = innerHeight - dblMargin; - style.height = height +'px'; - } - - if(parent) { - let parentNode = parent; - let rect = parentNode.getBoundingClientRect(); - let left = rect.left; - let top = rect.top + spacing + parentNode.offsetHeight; - - if(left + width > innerWidth) - left -= (left + width) - innerWidth + margin; - if(top + height > innerHeight) - top -= height + parentNode.offsetHeight + spacing * 2; - - if(left < 0) - left = screenMargin; - if(top < 0) - top = screenMargin; - - style.top = (top) +'px'; - style.left = (left) +'px'; - style.minWidth = (rect.width) +'px'; - } - - $document[0].body.appendChild (popover); - this.docMouseDownHandler = this.onDocMouseDown.bind(this); - $document.on('mousedown', this.docMouseDownHandler); - }, - showComponent: function(childComponent, $scope, parent) { - let childElement = $document[0].createElement(childComponent); - $compile(childElement)($scope); - this.show(childElement, parent); - }, - hide: function() { - if(!this.popover) return; - $document.off('mousedown', this.docMouseDownHandler); - $document[0].body.removeChild (this.popover); - this.popover = null; - this.lastEvent = null; - this.docMouseDownHandler = null; - }, - onDocMouseDown: function(event) { - if (event != this.lastEvent) - this.hide(); - }, - onPopoverMouseDown: function(event) { - this.lastEvent = event; + if(width + dblMargin > innerWidth) { + width = innerWidth - dblMargin; + style.width = width +'px'; } - }; + if(height + dblMargin > innerHeight) { + height = innerHeight - dblMargin; + style.height = height +'px'; + } + + if(parent) { + let parentNode = parent; + let rect = parentNode.getBoundingClientRect(); + let left = rect.left; + let top = rect.top + spacing + parentNode.offsetHeight; + + if(left + width > innerWidth) + left -= (left + width) - innerWidth + margin; + if(top + height > innerHeight) + top -= height + parentNode.offsetHeight + spacing * 2; + + if(left < 0) + left = screenMargin; + if(top < 0) + top = screenMargin; + + style.top = (top) +'px'; + style.left = (left) +'px'; + style.minWidth = (rect.width) +'px'; + } + + this.document.body.appendChild(popover); + this.docMouseDownHandler = (event) => this.onDocMouseDown(event); + this.document.addEventListener('mousedown', this.docMouseDownHandler); + } + showComponent(childComponent, $scope, parent) { + let childElement = this.document.createElement(childComponent); + this.$compile(childElement)($scope); + this.show(childElement, parent); + } + hide() { + if(!this.popover) return; + this.document.removeEventListener('mousedown', this.docMouseDownHandler); + this.document.body.removeChild(this.popover); + this.popover = null; + this.lastEvent = null; + this.docMouseDownHandler = null; + } + onDocMouseDown(event) { + if (event != this.lastEvent) + this.hide(); + } + onPopoverMouseDown(event) { + this.lastEvent = event; + } } -module.factory('vnPopover', factory); +Popover.$inject = ['$document', '$compile']; +module.service('vnPopover', Popover); diff --git a/client/core/src/validation.js b/client/core/src/validation.js index cc3eea55c..f68a8cf8f 100644 --- a/client/core/src/validation.js +++ b/client/core/src/validation.js @@ -50,13 +50,13 @@ export function directive(interpolate, compile, validationRules, validatorjs) { } } function createMessage(form, input, key) { - var template = "
"; + var template = '
'; var span = interpolate(template)({ form: form, input: input, key: key }); var element = angular.element(span); return element; } function createMessages(form, input) { - var template = "
"; + var template = '
'; return interpolate(template)({ form: form, input: input }); } diff --git a/package.json b/package.json index 8ea36e7ea..ae0cf14a5 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "angular-translate": "^2.13.1", "angular-translate-loader-partial": "^2.13.1", "angular-ui-router": "^1.0.0-beta.3", + "loopback-datasource-juggler": "^3.2.0", "material-design-lite": "^1.3.0", "oclazyload": "^0.6.3" },