LT-253: Added Collection to store Additional Findings in the database. Set up some form components that store temporary UI state

This commit is contained in:
Erik Ziegler committed 2016-07-22 11:12:04 +02:00
1 parent 022c534895
commit 40062e2e9d
35 files changed
+599 -216

No files matched your search

@@ -0,0 +1,7 @@
<template name="helpBlock">
{{#if isInvalidKey key}}
<span class="help-block m-b-none">
{{invalidKeyMessage key}}
</span>
{{/if}}
</template>
@@ -0,0 +1,10 @@
import { Template } from 'meteor/templating';
import './helpBlock.html';
Template.helpBlock.onCreated(function helpBlockOnCreated() {
var instance = this;
// Invalid keys comes from Trials schema
instance.invalidKeys = this.data.invalidKeys;
});
@@ -0,0 +1,22 @@
<template name="radioOptionGroup">
<div class="{{class}} form-group">
{{ #with getSchema key }}
<h5>{{label}}</h5>
<div class="radio-group">
{{#each option in allowedValues}}
<div class="radio-option">
<input type="radio"
id="{{../key}}_{{option}}"
name="{{../key}}"
value="{{option}}"
class="form-control js-form-update"
{{inlineIf value option 'checked'}}/>
<label for="{{../key}}_{{option}}">
{{option}}
</label>
</div>
{{/each}}
</div>
{{ /with }}
</div>
</template>
@@ -0,0 +1,40 @@
import { Template } from 'meteor/templating';
import './radioOptionGroup.html';
Template.radioOptionGroup.onCreated(function radioOptionGroupOnCreated() {
let instance = this;
instance.currentSchema = this.data.currentSchema;
// Here we set this Template instance's state property to equal the input state data
// The purpose of this is to make our helpers and events more consistent across templates.
instance.state = this.data.state;
// Invalid keys comes from Trials schema
instance.invalidKeys = this.data.invalidKeys;
// Validation Context of registrationWorkflow
instance.validationContext = this.data.validationContext;
// isModified records whether or not the user has unsaved changes
instance.isModified = this.data.isModified;
});
Template.radioOptionGroup.events({
'change .js-form-update'(event, instance) {
const value = event.currentTarget.value;
const key = instance.data.key;
if (event.currentTarget.checked) {
instance.state.set(key, value);
}
}
});
Template.radioOptionGroup.helpers({
value() {
const instance = Template.instance();
const key = instance.data.key;
return instance.state.get(key);
}
});
@@ -0,0 +1,22 @@
<template name="select2Input">
<div class="form-group {{#if isInvalidKey key}}has-error{{/if}}">
<label class="control-label">
{{#with getSchema key }}
{{label}}
{{/with }}
</label>
<div>
<select id="{{key}}"
name="{{key}}"
required="{{isRequired}}"
class="form-control js-form-update">
{{#each option in options}}
<option value="{{option.id}}">
{{option.text}}
</option>
{{/each}}
</select>
{{> helpBlock}}
</div>
</div>
</template>
@@ -0,0 +1,80 @@
import { Template } from 'meteor/templating';
import './select2Input.html';
Template.select2Input.onCreated(function selectInputOnCreated() {
let instance = this;
instance.currentSchema = this.data.currentSchema;
// Here we set this Template instance's state property to equal the input state data
// The purpose of this is to make our helpers and events more consistent across templates.
instance.state = this.data.state;
// Invalid keys comes from Trials schema
instance.invalidKeys = this.data.invalidKeys;
// Validation Context of registrationWorkflow
instance.validationContext = this.data.validationContext;
// isModified records whether or not the user has unsaved changes
instance.isModified = this.data.isModified;
});
Template.select2Input.onRendered(function select2InputOnRendered() {
const instance = this;
Meteor.defer(function() {
// Initialize select2 box
const selectBox = instance.$('select');
selectBox.select2(instance.data.select2Options);
// Set selected value(s) from current state;
const key = instance.data.key;
const value = instance.state.get(key);
if (value) {
selectBox.val(value).trigger('change');
}
});
});
Template.select2Input.helpers({
options() {
const instance = Template.instance();
if (instance.data.options) {
return instance.data.options;
}
const key = instance.data.key;
const schema = instance.currentSchema.schema(key);
const allowedValues = schema.allowedSelect2Values;
return allowedValues.map((value) => {
return {
id: value,
text: value
};
});
}
});
Template.select2Input.events({
'focus .select2'(event, instance) {
var control = event.currentTarget;
// Find select element that is assigned to select2
var hiddenSelect2Box = $(control).prev('select');
// Prevent auto open for select2 boxes that has multiple attribute
if (!hiddenSelect2Box || $(hiddenSelect2Box).prop('multiple')) {
return;
}
$(hiddenSelect2Box).select2('open');
},
'change .js-form-update'(event, instance) {
const value = $(event.currentTarget).val();
const key = instance.data.key;
instance.state.set(key, value);
}
});
@@ -0,0 +1,23 @@
<template name="selectInput">
<div class="form-group {{#if isInvalidKey key}}has-error{{/if}}">
{{ #with getSchema key }}
<label class="control-label">
{{label}}
</label>
<div>
<select id="{{../key}}"
name="{{../key}}"
required="{{isRequired}}"
class="form-control js-form-update">
{{#each option in allowedValues}}
<option value="{{option}}"
selected="{{#if equals selectedOptionValue option}}selected{{/if}}">
{{option}}
</option>
{{/each}}
</select>
{{> helpBlock }}
</div>
{{ /with }}
</div>
</template>
@@ -0,0 +1,38 @@
import { Template } from 'meteor/templating';
import './selectInput.html';
Template.selectInput.onCreated(function selectInputOnCreated() {
let instance = this;
instance.currentSchema = this.data.currentSchema;
// Here we set this Template instance's state property to equal the input state data
// The purpose of this is to make our helpers and events more consistent across templates.
instance.state = this.data.state;
// Invalid keys comes from Trials schema
instance.invalidKeys = this.data.invalidKeys;
// Validation Context of registrationWorkflow
instance.validationContext = this.data.validationContext;
// isModified records whether or not the user has unsaved changes
instance.isModified = this.data.isModified;
});
Template.selectInput.helpers({
selectedOptionValue() {
const instance = Template.instance();
var key = instance.data.key;
return instance.state.get(key);
}
});
Template.selectInput.events({
'change .js-form-update'(event, instance) {
const value = $(event.currentTarget).val();
const key = instance.data.key;
instance.state.set(key, value);
}
});