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:
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;
|
||||
});
|
||||
+22
@@ -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>
|
||||
+40
@@ -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);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* Compares two variables are equal in value
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Template.registerHelper('equals', function(a, b) {
|
||||
return a === b;
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
Template.registerHelper('getSchema', function(context) {
|
||||
const instance = Template.instance();
|
||||
if (!instance.currentSchema) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
return instance.currentSchema.schema(context);
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* A global Blaze UI helper function to return whether or not a key is part of the invalidKeys dictionary
|
||||
*/
|
||||
Template.registerHelper('isInvalidKey', function(context, format, options) {
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
const instance = Template.instance();
|
||||
if (!instance.invalidKeys) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show error message if key is at first index
|
||||
var firstInvalidKey = instance.invalidKeys.get(0);
|
||||
return (firstInvalidKey && firstInvalidKey.name === context)
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
|
||||
/**
|
||||
* A global Blaze UI helper function to return whether or not a
|
||||
* field is required based on the Template's specified currentSchema
|
||||
*/
|
||||
Template.registerHelper('stateDataWithKey', function(context) {
|
||||
const instance = Template.instance();
|
||||
|
||||
if (!context) {
|
||||
return {
|
||||
state: instance.state,
|
||||
invalidKeys: instance.invalidKeys,
|
||||
validationContext: instance.validationContext,
|
||||
currentSchema: instance.currentSchema,
|
||||
isModified: instance.isModified
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
key: context,
|
||||
state: instance.state,
|
||||
invalidKeys: instance.invalidKeys,
|
||||
validationContext: instance.validationContext,
|
||||
currentSchema: instance.currentSchema,
|
||||
isModified: instance.isModified
|
||||
};
|
||||
});
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
Package.describe({
|
||||
name: 'reactive-form-controls',
|
||||
summary: 'A set of basic form controls that store their state in a ReactiveDict',
|
||||
version: '0.0.1'
|
||||
});
|
||||
|
||||
Package.onUse(function(api) {
|
||||
api.versionsFrom('1.3.4.1');
|
||||
|
||||
api.use('standard-app-packages');
|
||||
api.use('ecmascript');
|
||||
api.use('jquery');
|
||||
api.use('stylus');
|
||||
api.use('reactive-dict');
|
||||
api.use('templating');
|
||||
api.use('natestrauser:select2@4.0.1', 'client');
|
||||
|
||||
api.addFiles('client/helpers/getSchema.js', ['client']);
|
||||
api.addFiles('client/helpers/isInvalidKey.js', ['client']);
|
||||
api.addFiles('client/helpers/stateDataWithKey.js', ['client']);
|
||||
api.addFiles('client/helpers/equals.js', ['client']);
|
||||
|
||||
api.addFiles('client/components/helpBlock/helpBlock.html', ['client']);
|
||||
api.addFiles('client/components/helpBlock/helpBlock.js', ['client']);
|
||||
|
||||
api.addFiles('client/components/radioOptionGroup/radioOptionGroup.html', ['client']);
|
||||
api.addFiles('client/components/radioOptionGroup/radioOptionGroup.js', ['client']);
|
||||
|
||||
api.addFiles('client/components/selectInput/selectInput.html', ['client']);
|
||||
api.addFiles('client/components/selectInput/selectInput.js', ['client']);
|
||||
|
||||
api.addFiles('client/components/select2Input/select2Input.html', ['client']);
|
||||
api.addFiles('client/components/select2Input/select2Input.js', ['client']);
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user