fulcrum-core
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -13,14 +13,8 @@ 'use strict'; | ||
var _elementFactory = require('./element-factory'); | ||
var _choice = require('./choice'); | ||
var _elementFactory2 = _interopRequireDefault(_elementFactory); | ||
var _choice2 = _interopRequireDefault(_choice); | ||
var _choice3 = require('./choice'); | ||
var _choice4 = _interopRequireDefault(_choice3); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -58,3 +52,3 @@ | ||
_this._choices.push(new _choice4.default(choice)); | ||
_this._choices.push(new _choice2.default(choice)); | ||
} | ||
@@ -81,85 +75,22 @@ } catch (err) { | ||
key: 'load', | ||
value: function () { | ||
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, choice; | ||
value: function load(dataSource, callback) { | ||
var _this2 = this; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!this._choiceListID) { | ||
_context.next = 7; | ||
break; | ||
} | ||
this._choicesByValue = null; | ||
_context.next = 3; | ||
return _elementFactory2.default.getProvider().getChoiceList(this._choiceListID); | ||
if (this._choiceListID) { | ||
dataSource.getChoiceList(this._choiceListID, function (err, choiceList) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
case 3: | ||
this.choiceList = _context.sent; | ||
_this2.choiceList = choiceList; | ||
_this2._choices = _this2.choiceList.choices.slice(); | ||
this._choices = this.choiceList.choices.slice(); | ||
_context.next = 26; | ||
break; | ||
case 7: | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context.prev = 10; | ||
for (_iterator2 = this.attributes.choices[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
choice = _step2.value; | ||
this._choices.push(new _choice4.default(choice)); | ||
} | ||
_context.next = 18; | ||
break; | ||
case 14: | ||
_context.prev = 14; | ||
_context.t0 = _context['catch'](10); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context.t0; | ||
case 18: | ||
_context.prev = 18; | ||
_context.prev = 19; | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
case 21: | ||
_context.prev = 21; | ||
if (!_didIteratorError2) { | ||
_context.next = 24; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 24: | ||
return _context.finish(21); | ||
case 25: | ||
return _context.finish(18); | ||
case 26: | ||
this._choicesByValue = null; | ||
case 27: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this, [[10, 14, 18, 26], [19,, 21, 25]]); | ||
})); | ||
return function load() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
return callback(); | ||
}); | ||
} else { | ||
setImmediate(callback); | ||
} | ||
} | ||
}, { | ||
@@ -171,23 +102,23 @@ key: 'choiceByValue', | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator3 = this.choices[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var _choice = _step3.value; | ||
for (var _iterator2 = this.choices[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var choice = _step2.value; | ||
this._choicesByValue[_choice.value] = _choice; | ||
this._choicesByValue[choice.value] = choice; | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
@@ -221,16 +152,16 @@ } | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator4 = items[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var item = _step4.value; | ||
var _iteratorNormalCompletion5 = true; | ||
var _didIteratorError5 = false; | ||
var _iteratorError5 = undefined; | ||
for (var _iterator3 = items[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var item = _step3.value; | ||
var _iteratorNormalCompletion4 = true; | ||
var _didIteratorError4 = false; | ||
var _iteratorError4 = undefined; | ||
try { | ||
for (var _iterator5 = this.choiceFilter[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { | ||
var filter = _step5.value; | ||
for (var _iterator4 = this.choiceFilter[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { | ||
var filter = _step4.value; | ||
@@ -242,12 +173,12 @@ if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) { | ||
} catch (err) { | ||
_didIteratorError5 = true; | ||
_iteratorError5 = err; | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion5 && _iterator5.return) { | ||
_iterator5.return(); | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError5) { | ||
throw _iteratorError5; | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
} | ||
@@ -258,12 +189,12 @@ } | ||
} catch (err) { | ||
_didIteratorError4 = true; | ||
_iteratorError4 = err; | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion4 && _iterator4.return) { | ||
_iterator4.return(); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError4) { | ||
throw _iteratorError4; | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
@@ -290,25 +221,25 @@ } | ||
var _iteratorNormalCompletion6 = true; | ||
var _didIteratorError6 = false; | ||
var _iteratorError6 = undefined; | ||
var _iteratorNormalCompletion5 = true; | ||
var _didIteratorError5 = false; | ||
var _iteratorError5 = undefined; | ||
try { | ||
for (var _iterator6 = overrideChoices[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { | ||
var choiceAttributes = _step6.value; | ||
for (var _iterator5 = overrideChoices[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { | ||
var choiceAttributes = _step5.value; | ||
var _choice2 = new _choice4.default(choiceAttributes); | ||
var choice = new _choice2.default(choiceAttributes); | ||
choices.push(_choice2); | ||
choices.push(choice); | ||
} | ||
} catch (err) { | ||
_didIteratorError6 = true; | ||
_iteratorError6 = err; | ||
_didIteratorError5 = true; | ||
_iteratorError5 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion6 && _iterator6.return) { | ||
_iterator6.return(); | ||
if (!_iteratorNormalCompletion5 && _iterator5.return) { | ||
_iterator5.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError6) { | ||
throw _iteratorError6; | ||
if (_didIteratorError5) { | ||
throw _iteratorError5; | ||
} | ||
@@ -315,0 +246,0 @@ } |
@@ -13,6 +13,2 @@ 'use strict'; | ||
var _elementFactory = require('./element-factory'); | ||
var _elementFactory2 = _interopRequireDefault(_elementFactory); | ||
var _classification = require('./classification'); | ||
@@ -24,4 +20,2 @@ | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -52,26 +46,15 @@ | ||
key: 'load', | ||
value: function () { | ||
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return _elementFactory2.default.getProvider().getClassificationSet(this._classificationSetID); | ||
value: function load(dataSource, callback) { | ||
var _this2 = this; | ||
case 2: | ||
this.classificationSet = _context.sent; | ||
dataSource.getClassificationSet(this._classificationSetID, function (err, classificationSet) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
case 3: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
_this2.classificationSet = classificationSet; | ||
return function load() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
return callback(); | ||
}); | ||
} | ||
}, { | ||
@@ -78,0 +61,0 @@ key: 'classificationItems', |
@@ -85,4 +85,2 @@ 'use strict'; | ||
var SchemaProvider = null; | ||
var Constructors = { | ||
@@ -131,12 +129,2 @@ Section: _sectionElement2.default, | ||
} | ||
}, { | ||
key: 'setProvider', | ||
value: function setProvider(provider) { | ||
SchemaProvider = provider; | ||
} | ||
}, { | ||
key: 'getProvider', | ||
value: function getProvider() { | ||
return SchemaProvider; | ||
} | ||
}]); | ||
@@ -143,0 +131,0 @@ |
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _element = require('./element'); | ||
@@ -12,2 +14,10 @@ | ||
var _recordLinkCondition = require('./record-link-condition'); | ||
var _recordLinkCondition2 = _interopRequireDefault(_recordLinkCondition); | ||
var _recordLinkDefault = require('./record-link-default'); | ||
var _recordLinkDefault2 = _interopRequireDefault(_recordLinkDefault); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -29,3 +39,3 @@ | ||
_this.formID = attributes.form_id; | ||
_this._formID = attributes.form_id; | ||
@@ -39,7 +49,80 @@ _this.allowMultiple = !!attributes.allow_multiple_records; | ||
_this.recordConditionsType = attributes.record_conditions_type; | ||
_this.recordConditions = attributes.record_conditions; | ||
_this.recordDefaults = attributes.record_defaults; | ||
_this.recordConditions = []; | ||
if (attributes.record_conditions) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = attributes.record_conditions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var condition = _step.value; | ||
_this.recordConditions.push(new _recordLinkCondition2.default(condition)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
_this.recordDefaults = []; | ||
if (attributes.record_defaults) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = attributes.record_defaults[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var def = _step2.value; | ||
_this.recordDefaults.push(new _recordLinkDefault2.default(def)); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
} | ||
return _this; | ||
} | ||
_createClass(RecordLinkElement, [{ | ||
key: 'load', | ||
value: function load(dataSource, callback) { | ||
var _this2 = this; | ||
dataSource.getForm(this._formID, function (err, form) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
_this2.form = form; | ||
return callback(); | ||
}); | ||
} | ||
}]); | ||
return RecordLinkElement; | ||
@@ -46,0 +129,0 @@ }(_element2.default); |
111
dist/form.js
@@ -25,6 +25,8 @@ 'use strict'; | ||
var _async = require('async'); | ||
var _async2 = _interopRequireDefault(_async); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -52,83 +54,36 @@ | ||
key: 'load', | ||
value: function () { | ||
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, element; | ||
value: function load(dataSource, callback) { | ||
var loadElements = []; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context.prev = 3; | ||
_iterator = this.allElements[Symbol.iterator](); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
case 5: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context.next = 13; | ||
break; | ||
} | ||
try { | ||
for (var _iterator = this.allElements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var element = _step.value; | ||
element = _step.value; | ||
if (!element.load) { | ||
_context.next = 10; | ||
break; | ||
} | ||
_context.next = 10; | ||
return element.load(); | ||
case 10: | ||
_iteratorNormalCompletion = true; | ||
_context.next = 5; | ||
break; | ||
case 13: | ||
_context.next = 19; | ||
break; | ||
case 15: | ||
_context.prev = 15; | ||
_context.t0 = _context['catch'](3); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t0; | ||
case 19: | ||
_context.prev = 19; | ||
_context.prev = 20; | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
case 22: | ||
_context.prev = 22; | ||
if (!_didIteratorError) { | ||
_context.next = 25; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 25: | ||
return _context.finish(22); | ||
case 26: | ||
return _context.finish(19); | ||
case 27: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
if (element.load) { | ||
loadElements.push(element); | ||
} | ||
}, _callee, this, [[3, 15, 19, 27], [20,, 22, 26]]); | ||
})); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return function load() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}() | ||
_async2.default.each(loadElements, function (element, cb) { | ||
element.load(dataSource, cb); | ||
}, callback); | ||
} | ||
}, { | ||
@@ -135,0 +90,0 @@ key: 'createRecord', |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.FeatureValidator = exports.SectionElement = exports.TextValue = exports.TextElement = exports.CalculatedValue = exports.CalculatedElement = exports.DateValue = exports.DateElement = exports.ClassificationValue = exports.ClassificationElement = exports.ChoiceValue = exports.ChoiceElement = exports.BarcodeValue = exports.BarcodeElement = exports.AddressValue = exports.AddressElement = exports.VideoValue = exports.VideoItemValue = exports.PhotoValue = exports.PhotoItemValue = exports.AudioValue = exports.AudioItemValue = exports.RepeatableElement = exports.Condition = exports.ChildElements = exports.NumberUtils = exports.DateUtils = exports.TextUtils = exports.FormValues = exports.Feature = exports.RepeatableValue = exports.RepeatableItemValue = exports.ElementFactory = exports.ClassificationSet = exports.Classification = exports.ChoiceList = exports.Choice = exports.FormValue = exports.Element = exports.Record = exports.Form = undefined; | ||
exports.MemoryDataSource = exports.DataSource = exports.FeatureValidator = exports.RecordLinkItemValue = exports.RecordLinkValue = exports.RecordLinkElement = exports.SectionElement = exports.TextValue = exports.TextElement = exports.CalculatedValue = exports.CalculatedElement = exports.DateValue = exports.DateElement = exports.ClassificationValue = exports.ClassificationElement = exports.ChoiceValue = exports.ChoiceElement = exports.BarcodeValue = exports.BarcodeElement = exports.AddressValue = exports.AddressElement = exports.VideoValue = exports.VideoItemValue = exports.PhotoValue = exports.PhotoItemValue = exports.AudioValue = exports.AudioItemValue = exports.RepeatableElement = exports.Condition = exports.ChildElements = exports.NumberUtils = exports.DateUtils = exports.TextUtils = exports.FormValues = exports.Feature = exports.RepeatableValue = exports.RepeatableItemValue = exports.ElementFactory = exports.ClassificationSet = exports.Classification = exports.ChoiceList = exports.Choice = exports.FormValue = exports.Element = exports.Record = exports.Form = undefined; | ||
@@ -169,2 +169,10 @@ var _form = require('./form'); | ||
var _recordLinkValue = require('./values/record-link-value'); | ||
var _recordLinkValue2 = _interopRequireDefault(_recordLinkValue); | ||
var _recordLinkItemValue = require('./values/record-link-item-value'); | ||
var _recordLinkItemValue2 = _interopRequireDefault(_recordLinkItemValue); | ||
var _featureValidator = require('./validation/feature-validator'); | ||
@@ -174,2 +182,10 @@ | ||
var _dataSource = require('./data-source'); | ||
var _dataSource2 = _interopRequireDefault(_dataSource); | ||
var _memoryDataSource = require('./utils/memory-data-source'); | ||
var _memoryDataSource2 = _interopRequireDefault(_memoryDataSource); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -217,3 +233,8 @@ | ||
exports.SectionElement = _sectionElement2.default; | ||
exports.RecordLinkElement = _sectionElement2.default; | ||
exports.RecordLinkValue = _recordLinkValue2.default; | ||
exports.RecordLinkItemValue = _recordLinkItemValue2.default; | ||
exports.FeatureValidator = _featureValidator2.default; | ||
exports.DataSource = _dataSource2.default; | ||
exports.MemoryDataSource = _memoryDataSource2.default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "fulcrum-core", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Fulcrum Core", | ||
@@ -36,2 +36,3 @@ "homepage": "http://github.com/fulcrumapp/fulcrum-core", | ||
"dependencies": { | ||
"async": "^1.5.2", | ||
"lodash": "^3.10.1", | ||
@@ -38,0 +39,0 @@ "mixmatch": "0.0.2", |
import Element from './element'; | ||
import ElementFactory from './element-factory'; | ||
import Choice from './choice'; | ||
@@ -25,16 +24,19 @@ | ||
async load() { | ||
// TODO(zhm) once babel gets fixed this can be removed | ||
// https://phabricator.babeljs.io/T2765 | ||
load(dataSource, callback) { | ||
this._choicesByValue = null; | ||
if (this._choiceListID) { | ||
this.choiceList = await ElementFactory.getProvider().getChoiceList(this._choiceListID); | ||
this._choices = this.choiceList.choices.slice(); | ||
dataSource.getChoiceList(this._choiceListID, (err, choiceList) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
this.choiceList = choiceList; | ||
this._choices = this.choiceList.choices.slice(); | ||
return callback(); | ||
}); | ||
} else { | ||
for (let choice of this.attributes.choices) { | ||
this._choices.push(new Choice(choice)); | ||
} | ||
setImmediate(callback); | ||
} | ||
this._choicesByValue = null; | ||
} | ||
@@ -41,0 +43,0 @@ |
import Element from './element'; | ||
import ElementFactory from './element-factory'; | ||
import Classification from './classification'; | ||
@@ -17,6 +16,12 @@ | ||
async load() { | ||
// const self = this; | ||
load(dataSource, callback) { | ||
dataSource.getClassificationSet(this._classificationSetID, (err, classificationSet) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
this.classificationSet = await ElementFactory.getProvider().getClassificationSet(this._classificationSetID); | ||
this.classificationSet = classificationSet; | ||
return callback(); | ||
}); | ||
} | ||
@@ -23,0 +28,0 @@ |
@@ -20,4 +20,2 @@ import Section from './section-element'; | ||
let SchemaProvider = null; | ||
const Constructors = { | ||
@@ -59,10 +57,2 @@ Section: Section, | ||
} | ||
static setProvider(provider) { | ||
SchemaProvider = provider; | ||
} | ||
static getProvider() { | ||
return SchemaProvider; | ||
} | ||
} |
import Element from './element'; | ||
import RecordLinkCondition from './record-link-condition'; | ||
import RecordLinkDefault from './record-link-default'; | ||
@@ -7,3 +9,3 @@ export default class RecordLinkElement extends Element { | ||
this.formID = attributes.form_id; | ||
this._formID = attributes.form_id; | ||
@@ -17,6 +19,32 @@ this.allowMultiple = !!attributes.allow_multiple_records; | ||
this.recordConditionsType = attributes.record_conditions_type; | ||
this.recordConditions = attributes.record_conditions; | ||
this.recordDefaults = attributes.record_defaults; | ||
this.recordConditions = []; | ||
if (attributes.record_conditions) { | ||
for (const condition of attributes.record_conditions) { | ||
this.recordConditions.push(new RecordLinkCondition(condition)); | ||
} | ||
} | ||
this.recordDefaults = []; | ||
if (attributes.record_defaults) { | ||
for (const def of attributes.record_defaults) { | ||
this.recordDefaults.push(new RecordLinkDefault(def)); | ||
} | ||
} | ||
} | ||
load(dataSource, callback) { | ||
dataSource.getForm(this._formID, (err, form) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
this.form = form; | ||
return callback(); | ||
}); | ||
} | ||
} | ||
@@ -5,2 +5,3 @@ import ChildElements from './elements/child-elements'; | ||
import Record from './record'; | ||
import async from 'async'; | ||
@@ -23,8 +24,14 @@ export default class Form { | ||
async load() { | ||
load(dataSource, callback) { | ||
const loadElements = []; | ||
for (const element of this.allElements) { | ||
if (element.load) { | ||
await element.load(); | ||
loadElements.push(element); | ||
} | ||
} | ||
async.each(loadElements, (element, cb) => { | ||
element.load(dataSource, cb); | ||
}, callback); | ||
} | ||
@@ -31,0 +38,0 @@ |
@@ -41,3 +41,8 @@ import Form from './form'; | ||
import SectionElement from './elements/section-element'; | ||
import RecordLinkElement from './elements/section-element'; | ||
import RecordLinkValue from './values/record-link-value'; | ||
import RecordLinkItemValue from './values/record-link-item-value'; | ||
import FeatureValidator from './validation/feature-validator'; | ||
import DataSource from './data-source'; | ||
import MemoryDataSource from './utils/memory-data-source'; | ||
@@ -84,2 +89,7 @@ export {Form}; | ||
export {SectionElement}; | ||
export {RecordLinkElement}; | ||
export {RecordLinkValue}; | ||
export {RecordLinkItemValue}; | ||
export {FeatureValidator}; | ||
export {DataSource}; | ||
export {MemoryDataSource}; |
@@ -8,5 +8,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
done(); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -13,0 +14,0 @@ |
@@ -8,5 +8,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
done(); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -13,0 +14,0 @@ |
@@ -9,5 +9,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
done(); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -14,0 +15,0 @@ |
@@ -8,8 +8,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
const single = record.form.find('single_choice'); | ||
const multi = record.form.find('multiple_choice'); | ||
single.load().then(res => multi.load().then(done)); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -16,0 +14,0 @@ |
@@ -8,7 +8,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
const field = record.form.find('os'); | ||
field.load().then(done); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -15,0 +14,0 @@ |
@@ -8,5 +8,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
done(); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -13,0 +14,0 @@ |
@@ -8,5 +8,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
done(); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -13,0 +14,0 @@ |
@@ -9,5 +9,6 @@ import setup from '../helper'; | ||
beforeEach((done) => { | ||
({ record } = setup()); | ||
done(); | ||
setup((rec) => { | ||
record = rec; | ||
done(); | ||
}); | ||
}); | ||
@@ -14,0 +15,0 @@ |
import fs from 'fs'; | ||
import path from 'path'; | ||
import {Form, Record} from '../src'; | ||
import ElementFactory from '../src/elements/element-factory'; | ||
import FileProvider from '../src/utils/file-provider'; | ||
import DataSource from '../src/data-source'; | ||
import MemoryDataSource from '../src/utils/memory-data-source'; | ||
import FileDataSource from '../src/utils/file-data-source'; | ||
const fileRoot = path.join('.', 'test', 'fixtures'); | ||
ElementFactory.setProvider(new FileProvider(fileRoot)); | ||
const dataSource = new DataSource(); | ||
export default function setup() { | ||
dataSource.add(new MemoryDataSource()) | ||
.add(new FileDataSource(fileRoot)); | ||
export default function setup(callback) { | ||
let form = null; | ||
@@ -22,10 +26,11 @@ let formJson = null; | ||
form = new Form(formJson); | ||
record = new Record(recordJson); | ||
record._form = form; | ||
record._formValuesJSON = recordJson.form_values; | ||
form.load(dataSource, () => { | ||
record = new Record(recordJson); | ||
const result = { record: record }; | ||
record._form = form; | ||
record._formValuesJSON = recordJson.form_values; | ||
return result; | ||
callback(record); | ||
}); | ||
} |
import fs from 'fs'; | ||
import path from 'path'; | ||
import {Form, Record} from '../src'; | ||
import DataSource from '../src/data-source'; | ||
import MemoryDataSource from '../src/utils/memory-data-source'; | ||
import FileDataSource from '../src/utils/file-data-source'; | ||
const fileRoot = path.join('.', 'test', 'fixtures'); | ||
const dataSource = new DataSource(); | ||
dataSource.add(new MemoryDataSource()) | ||
.add(new FileDataSource(fileRoot)); | ||
let form = null; | ||
@@ -15,8 +26,11 @@ let formJson = null; | ||
form = new Form(formJson); | ||
record = new Record(recordJson); | ||
record._form = form; | ||
record._formValuesJSON = recordJson.form_values; | ||
form.load(dataSource, () => { | ||
record = new Record(recordJson); | ||
done(); | ||
record._form = form; | ||
record._formValuesJSON = recordJson.form_values; | ||
done(); | ||
}); | ||
}); | ||
@@ -23,0 +37,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
701802
282
11931
4
+ Addedasync@^1.5.2
+ Addedasync@1.5.2(transitive)