LT-275: Storing the selected label and description on measurements collection
This commit is contained in:
1 parent
20a2a8e453
commit
cd5a1277aa
10 files changed
+157
-84
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<template name="measureFlow">
|
||||
<div class="measure-flow {{#if this.threeColumns}}tree-columns{{/if}} {{instance.state.get}}" style="top:{{choose position.y 0}}px;left:{{choose position.x 0}}px">
|
||||
<div class="measure-flow {{#if this.threeColumns}}tree-columns{{/if}} {{instance.state.get}}" style="top:{{choose position.y 0}}px;left:{{choose position.x 0}}px" tabindex="-1">
|
||||
<button class="btn-add">Add label</button>
|
||||
{{#if eq instance.state.get 'selected'}}
|
||||
<div class="tree-leaf">
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Template } from 'meteor/templating';
|
||||
import { Blaze } from 'meteor/blaze';
|
||||
import { ReactiveVar } from 'meteor/reactive-var';
|
||||
@@ -8,8 +9,10 @@ import { $ } from 'meteor/jquery';
|
||||
Template.measureFlow.onCreated(() => {
|
||||
const instance = Template.instance();
|
||||
|
||||
instance.value = instance.data.currentValue || '';
|
||||
|
||||
instance.state = new ReactiveVar('closed');
|
||||
instance.description = new ReactiveVar('');
|
||||
instance.description = new ReactiveVar(instance.data.currentDescription || '');
|
||||
instance.descriptionEdit = new ReactiveVar(false);
|
||||
|
||||
const items = [
|
||||
@@ -76,6 +79,8 @@ Template.measureFlow.onRendered(() => {
|
||||
|
||||
// Make the measure flow bounded by the window borders
|
||||
instance.$('.measure-flow').bounded();
|
||||
|
||||
instance.$('.btn-add').focus();
|
||||
});
|
||||
|
||||
Template.measureFlow.events({
|
||||
@@ -84,6 +89,8 @@ Template.measureFlow.events({
|
||||
},
|
||||
|
||||
'click .measure-flow .btn-add, click .measure-flow .btn-rename'(event, instance) {
|
||||
const $measureFlow = instance.$('.measure-flow');
|
||||
|
||||
// Set the open state for the component
|
||||
instance.state.set('open');
|
||||
|
||||
@@ -109,10 +116,13 @@ Template.measureFlow.events({
|
||||
};
|
||||
|
||||
// Define in which element the selectTree will be rendered in
|
||||
const parentElement = instance.$('.measure-flow')[0];
|
||||
const parentElement = $measureFlow[0];
|
||||
|
||||
// Render the selectTree element
|
||||
instance.selectTreeView = Blaze.renderWithData(Template.selectTree, data, parentElement);
|
||||
|
||||
// Focus the measure flow to handle closing
|
||||
$measureFlow.focus();
|
||||
});
|
||||
},
|
||||
|
||||
@@ -149,6 +159,7 @@ Template.measureFlow.events({
|
||||
if (event.which === 13 || event.which === 27) {
|
||||
instance.$('.measure-flow .actions').removeClass('fadeOut');
|
||||
instance.descriptionEdit.set(false);
|
||||
instance.$('.measure-flow').focus();
|
||||
}
|
||||
|
||||
// Keep the current description if ENTER was pressed
|
||||
@@ -219,5 +230,31 @@ Template.measureFlow.events({
|
||||
|
||||
// Wait the fade-out transition and remove the selectTree component
|
||||
$container.one('transitionend', event => Blaze.remove(instance.selectTreeView));
|
||||
},
|
||||
|
||||
'blur .measure-flow'(event, instance) {
|
||||
const $measureFlow = $(event.currentTarget);
|
||||
const element = $measureFlow[0];
|
||||
Meteor.defer(() => {
|
||||
const focused = $(':focus')[0];
|
||||
if (element !== focused && !$.contains(element, focused)) {
|
||||
$measureFlow.trigger('close');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
'mouseout .measure-flow'(event, instance) {
|
||||
const $measureFlow = $(event.currentTarget);
|
||||
const canClose = instance.state.get() === 'selected' && !instance.descriptionEdit.get();
|
||||
if (canClose && !$.contains($measureFlow[0], event.toElement)) {
|
||||
$measureFlow.trigger('close');
|
||||
}
|
||||
},
|
||||
|
||||
'close .measure-flow'(event, instance) {
|
||||
const $measureFlow = $(event.currentTarget);
|
||||
$measureFlow.one('animationend', () => {
|
||||
instance.data.doneCallback(instance.value.value, instance.description.get());
|
||||
}).addClass('fadeOut');
|
||||
}
|
||||
});
|
||||
@@ -1,9 +1,13 @@
|
||||
@import "{design}/app"
|
||||
|
||||
.measure-flow
|
||||
outline: none
|
||||
position: fixed
|
||||
z-index: 1
|
||||
|
||||
&.fadeOut
|
||||
animateFadeOut()
|
||||
|
||||
&.open,
|
||||
&.selected
|
||||
|
||||
@@ -61,7 +65,7 @@
|
||||
display: none
|
||||
|
||||
.actions
|
||||
margin-top: 16px
|
||||
padding-top: 16px
|
||||
opacity: 0
|
||||
|
||||
&:not(.fadeOut)
|
||||
@@ -84,7 +88,7 @@
|
||||
|
||||
.description
|
||||
margin-top: -10px
|
||||
margin-bottom: 26px
|
||||
margin-bottom: 10px
|
||||
|
||||
textarea
|
||||
background-color: white
|
||||
@@ -102,7 +106,7 @@
|
||||
background-color: white
|
||||
box-shadow: 0 10px white
|
||||
line-height: 20px
|
||||
margin-bottom: 26px
|
||||
margin-bottom: 10px
|
||||
margin-top: -10px
|
||||
padding: 0 12px
|
||||
|
||||
|
||||
Reference in new issue
Block a user