Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
8df67ad95e
|
@ -13,6 +13,7 @@ export function directive(vnPopover) {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.directive('vnPopover', directive);
|
||||
|
||||
export class Popover {
|
||||
|
@ -69,6 +70,7 @@ export class Popover {
|
|||
width = innerWidth - dblMargin;
|
||||
style.width = width + 'px';
|
||||
}
|
||||
|
||||
if (height + dblMargin > innerHeight) {
|
||||
height = innerHeight - dblMargin;
|
||||
style.height = height + 'px';
|
||||
|
@ -82,11 +84,13 @@ export class Popover {
|
|||
|
||||
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;
|
||||
|
||||
|
@ -102,6 +106,7 @@ export class Popover {
|
|||
}
|
||||
return popoverId;
|
||||
}
|
||||
|
||||
showComponent(childComponent, $scope, parent) {
|
||||
let childElement = this.document.createElement(childComponent);
|
||||
let id = 'popover-' + this.popOpens;
|
||||
|
@ -111,12 +116,14 @@ export class Popover {
|
|||
this.show(childElement, parent, id);
|
||||
return childElement;
|
||||
}
|
||||
|
||||
_checkOpens() {
|
||||
this.popOpens = this.document.querySelectorAll('*[id^="popover-"]').length;
|
||||
if (this.popOpens === 0) {
|
||||
this._destroy();
|
||||
}
|
||||
}
|
||||
|
||||
_removeElement(val) {
|
||||
if (!val) return;
|
||||
let element = angular.element(val);
|
||||
|
@ -136,6 +143,7 @@ export class Popover {
|
|||
}
|
||||
this._checkOpens();
|
||||
}
|
||||
|
||||
hideChilds(id) {
|
||||
let popovers = this.document.querySelectorAll('*[id^="popover-"]');
|
||||
let idNumber = parseInt(id.split('-')[1], 10);
|
||||
|
@ -147,6 +155,7 @@ export class Popover {
|
|||
);
|
||||
this._checkOpens();
|
||||
}
|
||||
|
||||
hideAll() {
|
||||
let popovers = this.document.querySelectorAll('*[id^="popover-"]');
|
||||
popovers.forEach(
|
||||
|
@ -156,6 +165,7 @@ export class Popover {
|
|||
);
|
||||
this._checkOpens();
|
||||
}
|
||||
|
||||
_findPopOver(node) {
|
||||
while (node != null) {
|
||||
if (node.id && node.id.startsWith('popover-')) {
|
||||
|
@ -165,6 +175,7 @@ export class Popover {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
onDocMouseDown(event) {
|
||||
let targetId = this._findPopOver(event.target);
|
||||
if (targetId) {
|
||||
|
@ -173,6 +184,7 @@ export class Popover {
|
|||
this.hideAll();
|
||||
}
|
||||
}
|
||||
|
||||
onDocKeyDown(event) {
|
||||
if (event.keyCode === 27) {
|
||||
let targetId = this._findPopOver(this.lastTarget);
|
||||
|
@ -184,9 +196,12 @@ export class Popover {
|
|||
this.lastTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
onPopoverMouseDown(event) {
|
||||
this.lastTarget = event.target;
|
||||
}
|
||||
}
|
||||
|
||||
Popover.$inject = ['$document', '$compile', '$transitions'];
|
||||
|
||||
module.service('vnPopover', Popover);
|
||||
|
|
|
@ -7,12 +7,12 @@ export const NAME = util.getName(_NAME);
|
|||
|
||||
directive.$inject = [resolveFactory.NAME];
|
||||
export function directive(resolve) {
|
||||
return{
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: function(_, attrs) {
|
||||
return resolve.getTemplate(_NAME, attrs);
|
||||
return resolve.getTemplate(_NAME, attrs);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_module.directive(NAME, directive);
|
||||
|
|
|
@ -15,7 +15,7 @@ export function factory() {
|
|||
enabled: 'true',
|
||||
className: DEFAULT_CLASS
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_module.factory(NAME, factory);
|
||||
|
|
|
@ -36,7 +36,7 @@ export default class TextfieldController extends Component {
|
|||
this.hasValue = Boolean(this._value);
|
||||
this.mdlUpdate();
|
||||
}
|
||||
|
||||
|
||||
mdlUpdate() {
|
||||
let mdlField = this.$element[0].firstChild.MaterialTextfield;
|
||||
if (mdlField)
|
||||
|
@ -48,6 +48,7 @@ export default class TextfieldController extends Component {
|
|||
this.input.focus();
|
||||
}
|
||||
}
|
||||
|
||||
TextfieldController.$inject = ['$element', '$scope', '$attrs', '$timeout', normalizerFactory.NAME];
|
||||
|
||||
module.component('vnTextfield', {
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
import './textfield.js';
|
||||
|
||||
describe('Component vnTextfield', () => {
|
||||
let $componentController;
|
||||
let $scope;
|
||||
let $attrs;
|
||||
let $timeout;
|
||||
let $element;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
|
||||
$componentController = _$componentController_;
|
||||
$scope = $rootScope.$new();
|
||||
$attrs = {};
|
||||
$timeout = _$timeout_;
|
||||
$element = angular.element('<div><input></div>');
|
||||
}));
|
||||
|
||||
describe('value() setter', () => {
|
||||
it(`should set _value, input.value and hasValue properties to null, '' and false then call mdlUpdate()`, () => {
|
||||
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
|
||||
spyOn(controller, 'mdlUpdate');
|
||||
let testValue = '';
|
||||
controller.value = testValue;
|
||||
|
||||
expect(controller._value).toEqual(null);
|
||||
expect(controller.input.value).toEqual(testValue);
|
||||
expect(controller.hasValue).toEqual(Boolean(testValue));
|
||||
expect(controller.mdlUpdate).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it(`should set _value, input.value and hasValue propertiest to test, test and true then call mdlUpdate()`, () => {
|
||||
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
|
||||
spyOn(controller, 'mdlUpdate');
|
||||
let testValue = 'test';
|
||||
controller.value = testValue;
|
||||
|
||||
expect(controller._value).toEqual(testValue);
|
||||
expect(controller.input.value).toEqual(testValue);
|
||||
expect(controller.hasValue).toEqual(Boolean(testValue));
|
||||
expect(controller.mdlUpdate).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue