Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fulcrum-core

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fulcrum-core - npm Package Compare versions

Comparing version 0.0.15 to 0.6.2

dist/changeset.js

78

dist/choice-list.js

@@ -5,2 +5,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 _choice = require('./elements/choice');

@@ -14,33 +16,65 @@

var ChoiceList = function ChoiceList(attributes) {
_classCallCheck(this, ChoiceList);
var ChoiceList = function () {
function ChoiceList(attributes) {
_classCallCheck(this, ChoiceList);
attributes = attributes || {};
this.updateFromAPIAttributes(attributes);
}
this.id = attributes.id;
this.name = attributes.name;
this.description = attributes.description;
this.choices = [];
ChoiceList.prototype.updateFromAPIAttributes = function updateFromAPIAttributes(attrs) {
var attributes = attrs || {};
if (attributes.choices) {
for (var _iterator = attributes.choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
this._choicesJSON = attributes.choices || [];
};
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
_createClass(ChoiceList, [{
key: 'id',
get: function get() {
return this._id;
}
}, {
key: 'name',
get: function get() {
return this._name;
}
}, {
key: 'description',
get: function get() {
return this._description;
}
}, {
key: 'choices',
get: function get() {
if (!this._choices) {
this._choices = [];
for (var _iterator = this._choicesJSON, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var choice = _ref;
this._choices.push(new _choice2.default(choice));
}
}
var choice = _ref;
this.choices.push(new _choice2.default(choice));
return this._choices;
}
}
};
}]);
return ChoiceList;
}();
exports.default = ChoiceList;
//# sourceMappingURL=choice-list.js.map

@@ -5,2 +5,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 _classification = require('./elements/classification');

@@ -14,33 +16,65 @@

var ClassificationSet = function ClassificationSet(attributes) {
_classCallCheck(this, ClassificationSet);
var ClassificationSet = function () {
function ClassificationSet(attributes) {
_classCallCheck(this, ClassificationSet);
attributes = attributes || {};
this.updateFromAPIAttributes(attributes);
}
this.id = attributes.id;
this.name = attributes.name;
this.description = attributes.description;
this.items = [];
ClassificationSet.prototype.updateFromAPIAttributes = function updateFromAPIAttributes(attrs) {
var attributes = attrs || {};
if (attributes.items) {
for (var _iterator = attributes.items, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
this._itemsJSON = attributes.items || [];
};
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
_createClass(ClassificationSet, [{
key: 'id',
get: function get() {
return this._id;
}
}, {
key: 'name',
get: function get() {
return this._name;
}
}, {
key: 'description',
get: function get() {
return this._description;
}
}, {
key: 'items',
get: function get() {
if (!this._items) {
this._items = [];
for (var _iterator = this._itemsJSON, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var item = _ref;
this._items.push(new _classification2.default(null, item));
}
}
var item = _ref;
this.items.push(new _classification2.default(null, item));
return this._items;
}
}
};
}]);
return ClassificationSet;
}();
exports.default = ClassificationSet;
//# sourceMappingURL=classification-set.js.map

@@ -5,49 +5,57 @@ '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 _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; }; }(); /*
The DataSource class is a composable series of layers that can be used to
chain data providers together to form more complex schemes.
For example, we can setup several layers of caching and data providers:
* A - First look in an in-memory hash (e.g. lives until a page refresh)
* B - Then look in indexedDB (lives beyond a page refresh, but requires pulling from somewhere else)
* C - Then finally actually hit the API to get it
Given this configuration, when requesting data when it's not present at all, the request will travel
all the way to the end and then each layer is given a chance to process it back on the way up. Passing
the object back up is critical to being able to store the result at each level.
A.then(B).then(C);
get(callback) -> A -> B -> C -
|
callback(object) <- A <- B <- C -
So in this configuration, when asking for a form object, the memory data source would miss and delegate
to the indexedDB data source, which would also miss and the API data source would end up providing the
record from the live API. At that point the object is passed back to the indexedDB where it can be stored
for the next time. After indexedDB stores it, it's passed to the memory cache so it can also store it. And
finally the actual original callback is invoked with the object. The next time the object is fetched, it will
be returned from the memory store. Unless a full page refresh happens, and indexedDB will return it first.
After the first fetch:
get(callback) -> A B C
|
callback(object) <- A B C
After a full page refresh
get(callback) -> A -> B C
|
callback(object) <- A <- B C
*/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _async = require('async');
/*
var _async2 = _interopRequireDefault(_async);
The DataSource class is a composable series of layers that can be used to
chain data providers together to form more complex schemes.
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
For example, we can setup several layers of caching and data providers:
* A - First look in an in-memory hash (e.g. lives until a page refresh)
* B - Then look in indexedDB (lives beyond a page refresh, but requires pulling from somewhere else)
* C - Then finally actually hit the API to get it
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Given this configuration, when requesting data when it's not present at all, the request will travel
all the way to the end and then each layer is given a chance to process it back on the way up. Passing
the object back up is critical to being able to store the result at each level.
function noop() {
for (var _len = arguments.length, params = Array(_len), _key = 0; _key < _len; _key++) {
params[_key] = arguments[_key];
}
A.then(B).then(C);
get(callback) -> A -> B -> C -
|
callback(object) <- A <- B <- C -
So in this configuration, when asking for a form object, the memory data source would miss and delegate
to the indexedDB data source, which would also miss and the API data source would end up providing the
record from the live API. At that point the object is passed back to the indexedDB where it can be stored
for the next time. After indexedDB stores it, it's passed to the memory cache so it can also store it. And
finally the actual original callback is invoked with the object. The next time the object is fetched, it will
be returned from the memory store. Unless a full page refresh happens, and indexedDB will return it first.
After the first fetch:
get(callback) -> A B C
|
callback(object) <- A B C
After a full page refresh
get(callback) -> A -> B C
|
callback(object) <- A <- B C
*/
function noop() {
(arguments.length <= arguments.length - 1 + 0 ? undefined : arguments[arguments.length - 1 + 0])();
params[params.length - 1]();
}

@@ -66,4 +74,4 @@

var invokeCallback = function invokeCallback(err) {
for (var _len = arguments.length, objects = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
objects[_key - 1] = arguments[_key];
for (var _len2 = arguments.length, objects = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
objects[_key2 - 1] = arguments[_key2];
}

@@ -101,5 +109,5 @@

return _this2.process(dataSource.previous, method, params, objects, callback);
} else {
return callback.apply(null, [null].concat(objects));
}
return callback.apply(null, [null].concat(objects));
};

@@ -125,2 +133,50 @@

DataSource.prototype.prepare = function prepare(formID, callback) {
var _this3 = this;
var result = {};
var tasks = {
form: function form(callback) {
_this3.getForm(formID, function (err, form) {
if (err) {
callback(err);
return;
}
result.form = form;
result.form.load(_this3, callback);
});
},
users: function users(callback) {
_this3.getUsers(null, function (err, users) {
if (err) {
callback(err);
return;
}
result.users = users;
callback(err);
});
},
projects: function projects(callback) {
_this3.getProjects(null, function (err, projects) {
if (err) {
callback(err);
return;
}
result.projects = projects;
callback(err);
});
}
};
_async2.default.parallel(tasks, function (err) {
return callback(err, result);
});
};
DataSource.prototype.getChoiceList = function getChoiceList(id, callback) {

@@ -138,6 +194,10 @@ this.invoke(this.root, 'getChoiceList', [id], callback);

DataSource.prototype.getRecord = function getRecord(id, callback) {
this.invoke(this.root, 'getRecord', [id], callback);
DataSource.prototype.getUser = function getUser(id, callback) {
this.invoke(this.root, 'getUser', [id], callback);
};
DataSource.prototype.getRecord = function getRecord(id, form, callback) {
this.invoke(this.root, 'getRecord', [id, form], callback);
};
DataSource.prototype.getRecords = function getRecords(form, params, callback) {

@@ -147,2 +207,6 @@ this.invoke(this.root, 'getRecords', [form, params], callback);

DataSource.prototype.queryRecords = function queryRecords(form, params, callback) {
this.invoke(this.root, 'queryRecords', [form, params], callback);
};
DataSource.prototype.getUsers = function getUsers(params, callback) {

@@ -156,3 +220,64 @@ this.invoke(this.root, 'getUsers', [params], callback);

DataSource.prototype.getChangeset = function getChangeset(id, callback) {
this.invoke(this.root, 'getChangeset', [id], callback);
};
DataSource.prototype.getPhoto = function getPhoto(id, callback) {
this.invoke(this.root, 'getPhoto', [id], callback);
};
DataSource.prototype.getAudio = function getAudio(id, callback) {
this.invoke(this.root, 'getAudio', [id], callback);
};
DataSource.prototype.getAudioTrack = function getAudioTrack(id, callback) {
this.invoke(this.root, 'getAudioTrack', [id], callback);
};
DataSource.prototype.getVideo = function getVideo(id, callback) {
this.invoke(this.root, 'getVideo', [id], callback);
};
DataSource.prototype.getVideoTrack = function getVideoTrack(id, callback) {
this.invoke(this.root, 'getVideoTrack', [id], callback);
};
DataSource.prototype.createPhoto = function createPhoto(accessKey, file, progress, callback) {
this.invoke(this.root, 'createPhoto', [accessKey, file, progress], callback);
};
DataSource.prototype.createVideo = function createVideo(accessKey, file, progress, callback) {
this.invoke(this.root, 'createVideo', [accessKey, file, progress], callback);
};
DataSource.prototype.createAudio = function createAudio(accessKey, file, progress, callback) {
this.invoke(this.root, 'createAudio', [accessKey, file, progress], callback);
};
DataSource.prototype.createSignature = function createSignature(accessKey, file, progress, callback) {
this.invoke(this.root, 'createSignature', [accessKey, file, progress], callback);
};
DataSource.prototype.saveVideoTrack = function saveVideoTrack(accessKey, file, progress, callback) {
this.invoke(this.root, 'saveVideoTrack', [accessKey, file, progress], callback);
};
DataSource.prototype.saveAudioTrack = function saveAudioTrack(accessKey, file, progress, callback) {
this.invoke(this.root, 'saveAudioTrack', [accessKey, file, progress], callback);
};
DataSource.prototype.saveRecord = function saveRecord(record, callback) {
this.invoke(this.root, 'saveRecord', [record], callback);
};
DataSource.prototype.deleteRecord = function deleteRecord(record, callback) {
this.invoke(this.root, 'deleteRecord', [record], callback);
};
_createClass(DataSource, [{
key: 'source',
get: function get() {
return this.sources[this.sources.length - 1];
}
}, {
key: 'root',

@@ -159,0 +284,0 @@ get: function get() {

@@ -5,5 +5,5 @@ 'use strict';

var _element = require('./element');
var _textualElement = require('./textual-element');
var _element2 = _interopRequireDefault(_element);
var _textualElement2 = _interopRequireDefault(_textualElement);

@@ -30,5 +30,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

return BarcodeElement;
}(_element2.default);
}(_textualElement2.default);
exports.default = BarcodeElement;
//# sourceMappingURL=barcode-element.js.map

@@ -11,2 +11,6 @@ 'use strict';

var _elementFactory = require('./element-factory');
var _elementFactory2 = _interopRequireDefault(_elementFactory);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -22,4 +26,2 @@

var ElementFactory = null;
var ChildElements = function (_Mixin) {

@@ -35,21 +37,25 @@ _inherits(ChildElements, _Mixin);

ChildElements.prototype.createChildElements = function createChildElements(elements) {
this.elements = [];
this._elements = [];
for (var _iterator = elements, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (elements) {
for (var _iterator = elements, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var element = _ref;
var element = _ref;
// hack for circular dependency, not ideal
ElementFactory = ElementFactory || require('./element-factory').default;
this.elements.push(ElementFactory.create(this, element));
var el = _elementFactory2.default.create(this, element);
if (el) {
this._elements.push(el);
}
}
}

@@ -155,2 +161,11 @@ };

_createClass(ChildElements, [{
key: 'elements',
get: function get() {
if (!this._elements) {
this.createChildElements(this._elementsJSON);
}
return this._elements;
}
}, {
key: 'allElements',

@@ -157,0 +172,0 @@ get: function get() {

@@ -35,5 +35,6 @@ 'use strict';

_this.allowOther = !!attributes.allow_other;
_this.choiceFilter = null;
_this.overrideChoices = null;
_this._choiceFilter = null;
_this._overrideChoices = null;
_this._choiceListID = attributes.choice_list_id;

@@ -44,3 +45,3 @@ _this._choices = [];

if (attributes.choices) {
for (var _iterator = _this.attributes.choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
for (var _iterator = attributes.choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;

@@ -72,2 +73,5 @@

dataSource.getChoiceList(this._choiceListID, function (err, choiceList) {
// TODO(zhm) Some forms have orphaned choice lists (life sucks)
// Maybe we should add a parameter to the load() method to throw
// errors.
if (err) {

@@ -87,2 +91,9 @@ return callback(err);

ChoiceElement.prototype.resetOverrides = function resetOverrides() {
_Element.prototype.resetOverrides.call(this);
this._choiceFilter = null;
this._overrideChoices = null;
};
ChoiceElement.prototype.choiceByValue = function choiceByValue(value) {

@@ -124,2 +135,10 @@ if (!this._choicesByValue) {

}, {
key: 'choiceFilter',
get: function get() {
return this._choiceFilter;
},
set: function set(choiceFilter) {
this._choiceFilter = choiceFilter;
}
}, {
key: 'filteredChoices',

@@ -207,2 +226,10 @@ get: function get() {

}
}, {
key: 'overrideValues',
get: function get() {
return Object.assign(Object.getOwnPropertyDescriptor(_element2.default.prototype, 'overrideValues').get.call(this), {
choiceFilter: this._choiceFilter,
overrideChoices: this._overrideChoices
});
}
}]);

@@ -209,0 +236,0 @@

@@ -33,5 +33,6 @@ 'use strict';

_this.allowOther = !!attributes.allowOther;
_this.choiceFilter = null;
_this.allowOther = !!attributes.allow_other;
_this._choiceFilter = null;
_this._overrideClassificationItems = null;

@@ -47,2 +48,5 @@

dataSource.getClassificationSet(this._classificationSetID, function (err, classificationSet) {
// TODO(zhm) Some forms have orphaned classification sets (life sucks)
// Maybe we should add a parameter to the load() method to throw
// errors.
if (err) {

@@ -58,2 +62,9 @@ return callback(err);

ClassificationElement.prototype.resetOverrides = function resetOverrides() {
_Element.prototype.resetOverrides.call(this);
this._choiceFilter = null;
this._overrideClassificationItems = null;
};
_createClass(ClassificationElement, [{

@@ -65,2 +76,10 @@ key: 'classificationItems',

}, {
key: 'choiceFilter',
get: function get() {
return this._choiceFilter;
},
set: function set(choiceFilter) {
this._choiceFilter = choiceFilter;
}
}, {
key: 'overrideClassificationItems',

@@ -97,4 +116,16 @@ set: function set(overrideClassificationSetItems) {

}, {
key: 'overrideValues',
get: function get() {
return Object.assign(Object.getOwnPropertyDescriptor(_element2.default.prototype, 'overrideValues').get.call(this), {
choiceFilter: this._choiceFilter,
overrideClassificationItems: this._overrideClassificationItems
});
}
}, {
key: 'filteredClassifications',
get: function get() {
if (!this.classificationSet) {
return [];
}
var items = this.classificationSet.items;

@@ -108,32 +139,34 @@

for (var _iterator2 = items, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (items) {
for (var _iterator2 = items, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var item = _ref2;
var item = _ref2;
for (var _iterator3 = this.classificationFilter, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
for (var _iterator3 = this.classificationFilter, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var filter = _ref3;
var filter = _ref3;
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {
filteredItems.push(item);
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {
filteredItems.push(item);
}
}

@@ -140,0 +173,0 @@ }

@@ -16,3 +16,3 @@ "use strict";

this.value = attributes.value || attributes.label;
this.children = [];
this._items = [];

@@ -34,3 +34,3 @@ if (attributes.child_classifications) {

this.children.push(new Classification(this, child));
this._items.push(new Classification(this, child));
}

@@ -66,2 +66,7 @@ }

_createClass(Classification, [{
key: "items",
get: function get() {
return this._items.slice();
}
}, {
key: "exploded",

@@ -72,3 +77,5 @@ get: function get() {

/* eslint-disable consistent-this */
var iterator = this;
/* eslint-enable consistent-this */

@@ -75,0 +82,0 @@ while (iterator && iterator.parent) {

@@ -31,3 +31,3 @@ 'use strict';

Condition.isEmpty = function isEmpty(formValue) {
return formValue === null || formValue.isEmpty();
return formValue == null || formValue.isEmpty;
};

@@ -63,8 +63,8 @@

Condition.shouldElementBeVisible = function shouldElementBeVisible(element, record, values, cache) {
if (cache != null && cache[element.key] != null) {
return cache[element.key];
Condition.shouldElementBeVisible = function shouldElementBeVisible(element, record, values, visibilityCache) {
if (visibilityCache != null && visibilityCache[element.key] != null) {
return visibilityCache[element.key];
}
cache = cache || {};
var cache = visibilityCache || {};

@@ -114,3 +114,3 @@ var shouldBeVisible = Condition.shouldElementBeVisibleRecursive(element, record, values, cache);

if (element.hidden || element.hasHiddenParent) {
if (element.isHidden || element.hasHiddenParent) {
cache[element.key] = false;

@@ -204,3 +204,3 @@ return false;

if (!element.hasRequiredConditions) {
return element.required;
return element.isRequired;
}

@@ -265,3 +265,3 @@

if (condition.fieldKey === '@status') {
return record.statusValue();
return record.statusValue;
}

@@ -273,3 +273,3 @@ return values.get(condition.fieldKey);

if (condition.fieldKey === '@status') {
return record.statusValue().statusElement;
return record.statusValue.element;
}

@@ -289,3 +289,3 @@ return record.form.elementsByKey[condition.fieldKey];

var skipElement = referencedElement.hidden || referencedElement.hasHiddenParent;
var skipElement = referencedElement.isHidden || referencedElement.hasHiddenParent;

@@ -332,6 +332,6 @@ if (!skipElement) {

case 'greater_than':
return Condition.greaterThan(formValue, this.value);
return Condition.isGreaterThan(formValue, this.value);
case 'less_than':
return Condition.lessThan(formValue, this.value);
return Condition.isLessThan(formValue, this.value);

@@ -338,0 +338,0 @@ default:

@@ -35,2 +35,31 @@ 'use strict';

ContainerElement.prototype.resetOverrides = function resetOverrides() {
_Element.prototype.resetOverrides.call(this);
for (var _iterator = this.elements, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var element = _ref;
element.resetOverrides();
}
};
ContainerElement.initialize = function initialize() {
// this is a bit of a hack to get around circular dependencies. This gets
// called once from within the factory to setup the class. Putting this
// at global scope introduces circular dependency errors because ChildElements
// ends up loading the factory.
_childElements2.default.includeInto(ContainerElement);
};
return ContainerElement;

@@ -40,5 +69,2 @@ }(_element2.default);

exports.default = ContainerElement;
_childElements2.default.includeInto(ContainerElement);
//# sourceMappingURL=container-element.js.map

@@ -77,2 +77,6 @@ 'use strict';

var _containerElement = require('./container-element');
var _containerElement2 = _interopRequireDefault(_containerElement);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -104,2 +108,4 @@

var initialized = false;
var ElementFactory = function () {

@@ -113,4 +119,9 @@ function ElementFactory() {

if (!initialized) {
initialized = true;
_containerElement2.default.initialize();
}
if (constructor == null) {
throw new Error('Unsupported element ' + attributes.type);
return null;
}

@@ -117,0 +128,0 @@

@@ -39,4 +39,6 @@ 'use strict';

RecordLinkElement: 'RecordLinkField'
RecordLinkElement: 'RecordLinkField',
StatusElement: 'StatusField'
};
//# sourceMappingURL=element-types.js.map

@@ -19,4 +19,2 @@ 'use strict';

var ElementFactory = null;
var Element = function () {

@@ -26,27 +24,27 @@ function Element(parent, attributes) {

this.parent = parent;
this._parent = parent;
this.attributes = attributes;
this._attributes = attributes;
this.key = attributes.key;
this._key = attributes.key;
this.type = attributes.type;
this._type = attributes.type;
this.label = attributes.label;
this._label = attributes.label;
this.description = attributes.description;
this._description = attributes.description;
this.dataName = attributes.data_name;
this._dataName = attributes.data_name;
this.defaultValue = attributes.default_value;
this._defaultValue = attributes.default_value;
this.required = !!attributes.required;
this._isRequired = !!attributes.required;
this.hidden = !!attributes.hidden;
this._isHidden = !!attributes.hidden;
this.disabled = !!attributes.disabled;
this._isDisabled = !!attributes.disabled;
this.visibleConditionsType = this.attributes.visible_conditions_type;
this._visibleConditionsType = attributes.visible_conditions_type;
this.visibleConditions = [];
this._visibleConditions = [];

@@ -68,9 +66,9 @@ if (attributes.visible_conditions) {

this.visibleConditions.push(new _condition3.default(this, condition));
this._visibleConditions.push(new _condition3.default(this, condition));
}
}
this.requiredConditionsType = this.attributes.required_conditions_type;
this._requiredConditionsType = attributes.required_conditions_type;
this.requiredConditions = [];
this._requiredConditions = [];

@@ -92,51 +90,36 @@ if (attributes.required_conditions) {

this.requiredConditions.push(new _condition3.default(this, _condition));
this._requiredConditions.push(new _condition3.default(this, _condition));
}
}
this.minLength = -1;
this.maxLength = -1;
this._minLength = -1;
this._maxLength = -1;
if (attributes.min_length != null) {
this.minLength = +attributes.min_length;
this._minLength = +attributes.min_length;
}
if (attributes.max_length != null) {
this.maxLength = +attributes.max_length;
this._maxLength = +attributes.max_length;
}
this._overrideLabel = null;
this._overrideDescription = null;
this._overrideIsRequired = null;
this._overrideIsHidden = null;
this._overrideIsDisabled = null;
this._overrideMinLength = null;
this._overrideMaxLength = null;
}
Element.factory = function factory() {
return ElementFactory = ElementFactory || require('./element-factory').default;
Element.prototype.resetOverrides = function resetOverrides() {
this._overrideLabel = null;
this._overrideDescription = null;
this._overrideIsRequired = null;
this._overrideIsHidden = null;
this._overrideIsDisabled = null;
this._overrideMinLength = null;
this._overrideMaxLength = null;
};
Element.create = function create(parent, attributes) {
return Element.factory().create(parent, attributes);
};
Element.classes = function classes() {
if (Element._classes == null) {
Element._classes = {};
for (var _iterator3 = Object.keys(_elementTypes2.default), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var klass = _ref3;
Element._classes[klass] = Element.factory().classes()[_elementTypes2.default[klass]];
}
}
return Element._classes;
};
Element.prototype.isType = function isType(type) {

@@ -147,2 +130,151 @@ return this.type === type;

_createClass(Element, [{
key: 'parent',
get: function get() {
return this._parent;
}
}, {
key: 'type',
get: function get() {
return this._type;
}
}, {
key: 'key',
get: function get() {
return this._key;
}
}, {
key: 'label',
get: function get() {
return this._overrideLabel != null ? this._overrideLabel : this._label;
}
}, {
key: 'description',
get: function get() {
return this._overrideDescription != null ? this._overrideDescription : this._description;
}
}, {
key: 'dataName',
get: function get() {
return this._dataName;
}
}, {
key: 'defaultValue',
get: function get() {
return this._defaultValue;
}
}, {
key: 'isRequired',
get: function get() {
return this._overrideIsRequired != null ? this._overrideIsRequired : this._isRequired;
}
}, {
key: 'isHidden',
get: function get() {
return this._overrideIsHidden != null ? this._overrideIsHidden : this._isHidden;
}
}, {
key: 'isDisabled',
get: function get() {
return this._overrideIsDisabled != null ? this._overrideIsDisabled : this._isDisabled;
}
}, {
key: 'visibleConditionsType',
get: function get() {
return this._visibleConditionsType;
}
}, {
key: 'visibleConditions',
get: function get() {
return this._visibleConditions;
}
}, {
key: 'requiredConditionsType',
get: function get() {
return this._requiredConditionsType;
}
}, {
key: 'requiredConditions',
get: function get() {
return this._requiredConditions;
}
}, {
key: 'minLength',
get: function get() {
return this._overrideMinLength != null ? this._overrideMinLength : this._minLength;
}
}, {
key: 'maxLength',
get: function get() {
return this._overrideMaxLength != null ? this._overrideMinLength : this._maxLength;
}
}, {
key: 'overrideLabel',
get: function get() {
return this._overrideLabel;
},
set: function set(value) {
this._overrideLabel = value;
}
}, {
key: 'overrideDescription',
get: function get() {
return this._overrideDescription;
},
set: function set(value) {
this._overrideDescription = value;
}
}, {
key: 'overrideIsRequired',
get: function get() {
return this._overrideIsRequired;
},
set: function set(value) {
this._overrideIsRequired = value != null ? !!value : null;
}
}, {
key: 'overrideIsHidden',
get: function get() {
return this._overrideIsHidden;
},
set: function set(value) {
this._overrideIsHidden = value != null ? !!value : null;
}
}, {
key: 'overrideIsDisabled',
get: function get() {
return this._overrideIsDisabled;
},
set: function set(value) {
this._overrideIsDisabled = value != null ? !!value : null;
}
}, {
key: 'overrideMinLength',
get: function get() {
return this._overrideMinLength;
},
set: function set(value) {
this._overrideMinLength = value != null ? +value : null;
}
}, {
key: 'overrideMaxLength',
get: function get() {
return this._overrideMaxLength;
},
set: function set(value) {
this._overrideMaxLength = value != null ? +value : null;
}
}, {
key: 'overrideValues',
get: function get() {
return {
overrideLabel: this._overrideLabel,
overrideDescription: this._overrideDescription,
overrideIsRequired: this._overrideIsRequired,
overrideIsHidden: this._overrideIsHidden,
overrideIsDisabled: this._overrideIsDisabled,
overrideMinLength: this._overrideMinLength,
overrideMaxLength: this._overrideMaxLength
};
}
}, {
key: 'isLengthValidationSupported',

@@ -175,4 +307,4 @@ get: function get() {

get: function get() {
if (this.parent == null || this.hidden) {
return this.hidden;
if (this.parent == null || this.isHidden) {
return this.isHidden;
}

@@ -271,2 +403,7 @@ return this.parent.hasHiddenParent;

}
}, {
key: 'isStatusElement',
get: function get() {
return this.isType(_elementTypes2.default.StatusElement);
}
}]);

@@ -273,0 +410,0 @@

@@ -5,2 +5,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');

@@ -29,2 +31,30 @@

MediaElement.prototype.resetOverrides = function resetOverrides() {
_Element.prototype.resetOverrides.call(this);
this._overrideMediaGalleryEnabled = null;
};
_createClass(MediaElement, [{
key: 'isLengthValidationSupported',
get: function get() {
return true;
}
}, {
key: 'overrideMediaGalleryEnabled',
set: function set(override) {
this._overrideMediaGalleryEnabled = override;
},
get: function get() {
return this._overrideMediaGalleryEnabled;
}
}, {
key: 'overrideValues',
get: function get() {
return Object.assign(Object.getOwnPropertyDescriptor(_element2.default.prototype, 'overrideValues').get.call(this), {
overrideMediaGalleryEnabled: this._overrideMediaGalleryEnabled
});
}
}]);
return MediaElement;

@@ -31,0 +61,0 @@ }(_element2.default);

@@ -94,8 +94,9 @@ 'use strict';

if (err) {
return callback(err);
callback(err);
return;
}
// recursively load the linked forms
_this2.form = form;
return callback();
_this2.form.load(dataSource, callback);
});

@@ -102,0 +103,0 @@ };

@@ -5,2 +5,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 _containerElement = require('./container-element');

@@ -28,10 +30,27 @@

_this.titleFieldKeys = attributes.title_field_keys;
_this.titleFieldKeys = attributes.title_field_keys || [attributes.title_field_key];
_this.geometryTypes = attributes.geometry_types;
_this._geometryTypes = attributes.geometry_types;
_this.geometryRequired = !!attributes.geometry_required;
_this._geometryRequired = !!attributes.geometry_required;
return _this;
}
_createClass(RepeatableElement, [{
key: 'isGeometryEnabled',
get: function get() {
return this._geometryTypes && this._geometryTypes.length > 0;
}
}, {
key: 'isGeometryRequired',
get: function get() {
return this.isGeometryEnabled && this._geometryRequired;
}
}, {
key: 'isLengthValidationSupported',
get: function get() {
return true;
}
}]);
return RepeatableElement;

@@ -38,0 +57,0 @@ }(_containerElement2.default);

@@ -15,2 +15,6 @@ 'use strict';

var _element = require('./element');
var _element2 = _interopRequireDefault(_element);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -26,2 +30,11 @@

var DEFAULT_STATUS_ELEMENT = {
label: 'Status',
key: '@status',
data_name: 'status',
enabled: false,
read_only: false,
choices: []
};
var StatusElement = function (_TextualElement) {

@@ -33,25 +46,33 @@ _inherits(StatusElement, _TextualElement);

var _this = _possibleConstructorReturn(this, _TextualElement.call(this, parent, attributes));
attributes.type = 'StatusField';
_this.choices = [];
var attrs = Object.assign({}, DEFAULT_STATUS_ELEMENT, attributes);
for (var _iterator = attributes.choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
var _this = _possibleConstructorReturn(this, _TextualElement.call(this, parent, attrs));
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
_this._statusFilter = null;
var choice = _ref;
_this._choices = [];
_this.choices.push(new _statusChoice2.default(choice));
if (attrs.choices) {
for (var _iterator = attrs.choices, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var choice = _ref;
_this._choices.push(new _statusChoice2.default(choice));
}
}
_this._enabled = !!attributes.enabled;
_this._readOnly = !!attributes.read_only;
_this._enabled = !!attrs.enabled;
_this._readOnly = !!attrs.read_only;
return _this;

@@ -83,3 +104,14 @@ }

StatusElement.prototype.resetOverrides = function resetOverrides() {
_TextualElement.prototype.resetOverrides.call(this);
this._statusFilter = null;
};
_createClass(StatusElement, [{
key: 'choices',
get: function get() {
return this.filteredChoices;
}
}, {
key: 'isEnabled',

@@ -92,4 +124,66 @@ get: function get() {

get: function get() {
return this._readOnly;
return this._overrideIsDisabled != null ? this._overrideIsDisabled : this._readOnly;
}
}, {
key: 'statusFilter',
get: function get() {
return this._statusFilter;
},
set: function set(statusFilter) {
this._statusFilter = statusFilter;
}
}, {
key: 'filteredChoices',
get: function get() {
var items = this._choices;
if (!this.statusFilter) {
return items;
}
var filteredItems = [];
for (var _iterator3 = items, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var item = _ref3;
for (var _iterator4 = this.statusFilter, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref4;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref4 = _iterator4[_i4++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref4 = _i4.value;
}
var filter = _ref4;
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {
filteredItems.push(item);
}
}
}
return filteredItems;
}
}, {
key: 'overrideValues',
get: function get() {
return Object.assign(Object.getOwnPropertyDescriptor(_element2.default.prototype, 'overrideValues').get.call(this), {
statusFilter: this._statusFilter
});
}
}]);

@@ -96,0 +190,0 @@

@@ -29,3 +29,3 @@ 'use strict';

_this.numeric = !!attributes.numeric;
_this._isNumeric = !!attributes.numeric;

@@ -67,3 +67,3 @@ _this.format = attributes.format;

get: function get() {
return this.numeric && this.format === 'decimal';
return this._isNumeric && this.format === 'decimal';
}

@@ -73,5 +73,10 @@ }, {

get: function get() {
return this.numeric && this.format === 'integer';
return this._isNumeric && this.format === 'integer';
}
}, {
key: 'isNumeric',
get: function get() {
return this._isNumeric;
}
}, {
key: 'hasMin',

@@ -78,0 +83,0 @@ get: function get() {

@@ -61,2 +61,32 @@ 'use strict';

}
}, {
key: 'searchableValue',
get: function get() {
notImplemented();
}
}, {
key: 'createdDuration',
get: function get() {
notImplemented();
}
}, {
key: 'updatedDuration',
get: function get() {
notImplemented();
}
}, {
key: 'editedDuration',
get: function get() {
notImplemented();
}
}, {
key: 'hasCreatedCoordinate',
get: function get() {
notImplemented();
}
}, {
key: 'hasUpdatedCoordinate',
get: function get() {
notImplemented();
}
}]);

@@ -63,0 +93,0 @@

@@ -35,17 +35,38 @@ 'use strict';

// TODO(zhm) remove json attr
this._json = attributes;
// TODO(zhm) this might need to go away
this.titleFieldKeys = attributes.title_field_keys;
this.script = attributes.script;
this.createChildElements(attributes.elements);
this.updateFromAPIAttributes(attributes);
}
Form.prototype.updateFromAPIAttributes = function updateFromAPIAttributes(attrs) {
var attributes = attrs || {};
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
this._elementsJSON = attributes.elements;
this._elements = null;
this._statusFieldJSON = attributes.status_field;
this._statusField = null;
this._name = attributes.name;
this._script = attributes.script;
this._geometryRequired = !!attributes.geometry_required;
}
this._geometryTypes = attributes.geometry_types;
this._reportTemplatesJSON = attributes.report_templates;
this._projectEnabled = attributes.projects_enabled != null ? !!attributes.projects_enabled : true;
this._assignmentEnabled = attributes.assignment_enabled != null ? !!attributes.assignment_enabled : true;
if (attributes.title_field_keys || attributes.record_title_key) {
this._titleFieldKeysJSON = attributes.title_field_keys || [attributes.record_title_key];
} else {
this._titleFieldKeysJSON = [];
}
};
Form.prototype.load = function load(dataSource, callback) {
if (this._schemaLoaded) {
callback();
return;
}
this._schemaLoaded = true;
var loadElements = [];

@@ -73,3 +94,13 @@

_async2.default.each(loadElements, function (element, cb) {
element.load(dataSource, cb);
element.load(dataSource, function (err) {
if (err) {
// TODO(zhm) We need a parameter to control what happens when there's an error. We don't
// want to throw right here because some actual forms have orphaned objects. We can't have this
// blow up here because in a migration we need to keep going even when a form is 'slightly bogus'.
// In some cases it might be desirable to have more strict verification of the choice lists and
// classification sets.
}
cb();
});
}, callback);

@@ -79,8 +110,4 @@ };

Form.prototype.createRecord = function createRecord(attributes) {
var record = new _record2.default(attributes);
var record = new _record2.default(attributes, this);
// TODO(zhm) this might not be final
record._form = this;
record._formValuesJSON = {};
_defaultValues2.default.applyDefaultValuesForElements(this.elements, record.formValues, record);

@@ -100,7 +127,53 @@

Form.prototype.toJSON = function toJSON() {
// TODO(zhm) actually implement this so it returns a copy
return this._json;
var json = {};
json.id = this.id || null;
json.name = this.name || null;
json.description = this.description || null;
json.script = this.script || null;
json.elements = JSON.parse(JSON.stringify(this._elementsJSON));
json.assignment_enabled = this.isAssignmentEnabled;
json.projects_enabled = this.isProjectEnabled;
json.geometry_required = this.isGeometryRequired;
json.geometry_types = this._geometryTypes;
json.title_field_keys = this.titleFieldKeys;
json.report_templates = this.reportTemplates;
if (this._statusFieldJSON) {
json.status_field = JSON.parse(JSON.stringify(this._statusFieldJSON));
}
return json;
};
Form.prototype.resetOverrides = function resetOverrides() {
for (var _iterator2 = this.elements, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var element = _ref2;
element.resetOverrides();
}
this.statusField.resetOverrides();
this._overrideManualLocationEnabled = null;
this._overrideMediaGalleryEnabled = null;
};
_createClass(Form, [{
key: 'id',
get: function get() {
return this._id;
}
}, {
key: 'statusField',

@@ -119,2 +192,17 @@ get: function get() {

}, {
key: 'isProjectEnabled',
get: function get() {
return this._projectEnabled;
}
}, {
key: 'isAssignmentEnabled',
get: function get() {
return this._assignmentEnabled;
}
}, {
key: 'isGeometryEnabled',
get: function get() {
return this._geometryTypes && this._geometryTypes.length > 0;
}
}, {
key: 'isGeometryRequired',

@@ -129,2 +217,66 @@ get: function get() {

}
}, {
key: 'description',
get: function get() {
return this._description;
}
}, {
key: 'script',
get: function get() {
return this._script;
}
}, {
key: 'titleFieldKeys',
get: function get() {
return this._titleFieldKeysJSON || [];
}
}, {
key: 'reportTemplates',
get: function get() {
return this._reportTemplatesJSON || [];
}
}, {
key: 'reportTemplate',
get: function get() {
return this.reportTemplates.length ? this.reportTemplates[0] : null;
}
}, {
key: 'overrideManualLocationEnabled',
set: function set(override) {
this._overrideManualLocationEnabled = override;
}
}, {
key: 'isManualLocationEnabled',
get: function get() {
return this._overrideManualLocationEnabled != null ? !!this._overrideManualLocationEnabled : true;
}
}, {
key: 'overrideMediaGalleryEnabled',
set: function set(override) {
this._overrideMediaGalleryEnabled = override;
}
}, {
key: 'isMediaGalleryEnabled',
get: function get() {
return this._overrideMediaGalleryEnabled != null ? !!this._overrideMediaGalleryEnabled : true;
}
}, {
key: 'overrideEditDurationsEnabled',
set: function set(override) {
this._overrideEditDurationsEnabled = override;
}
}, {
key: 'isEditDurationsEnabled',
get: function get() {
return this._overrideEditDurationsEnabled != null ? !!this._overrideEditDurationsEnabled : true;
}
}, {
key: 'overrideValues',
get: function get() {
return {
overrideManualLocationEnabled: this._overrideManualLocationEnabled,
overrideMediaGalleryEnabled: this._overrideMediaGalleryEnabled,
overrideEditDurationsEnabled: this._overrideEditDurationsEnabled
};
}
}]);

@@ -131,0 +283,0 @@

'use strict';
exports.__esModule = true;
exports.Project = exports.User = exports.CustomValidationError = exports.DefaultValues = 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;
exports.TrackPlayer = exports.TrackSegment = exports.TrackPoint = exports.Track = exports.Changeset = exports.Project = exports.Role = exports.User = exports.MediaItemValue = exports.MediaValue = exports.MediaElement = exports.CustomValidationError = exports.DefaultValues = exports.MemoryDataSource = exports.DataSource = exports.FeatureValidator = exports.RecordLinkItemValue = exports.RecordLinkValue = exports.RecordLinkElement = exports.SectionElement = exports.TextValue = exports.TextElement = exports.CalculatedValue = exports.CalculatedElement = exports.TimeValue = exports.TimeElement = 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;

@@ -146,2 +146,10 @@ var _form = require('./form');

var _timeElement = require('./elements/time-element');
var _timeElement2 = _interopRequireDefault(_timeElement);
var _timeValue = require('./values/time-value');
var _timeValue2 = _interopRequireDefault(_timeValue);
var _calculatedElement = require('./elements/calculated-element');

@@ -167,2 +175,6 @@

var _recordLinkElement = require('./elements/record-link-element');
var _recordLinkElement2 = _interopRequireDefault(_recordLinkElement);
var _recordLinkValue = require('./values/record-link-value');

@@ -196,2 +208,14 @@

var _mediaElement = require('./elements/media-element');
var _mediaElement2 = _interopRequireDefault(_mediaElement);
var _mediaValue = require('./values/media-value');
var _mediaValue2 = _interopRequireDefault(_mediaValue);
var _mediaItemValue = require('./values/media-item-value');
var _mediaItemValue2 = _interopRequireDefault(_mediaItemValue);
var _user = require('./user');

@@ -201,2 +225,6 @@

var _role = require('./role');
var _role2 = _interopRequireDefault(_role);
var _project = require('./project');

@@ -206,2 +234,22 @@

var _changeset = require('./changeset');
var _changeset2 = _interopRequireDefault(_changeset);
var _track = require('./media/track');
var _track2 = _interopRequireDefault(_track);
var _trackPoint = require('./media/track-point');
var _trackPoint2 = _interopRequireDefault(_trackPoint);
var _trackSegment = require('./media/track-segment');
var _trackSegment2 = _interopRequireDefault(_trackSegment);
var _trackPlayer = require('./media/track-player');
var _trackPlayer2 = _interopRequireDefault(_trackPlayer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -244,2 +292,4 @@

exports.DateValue = _dateValue2.default;
exports.TimeElement = _timeElement2.default;
exports.TimeValue = _timeValue2.default;
exports.CalculatedElement = _calculatedElement2.default;

@@ -250,3 +300,3 @@ exports.CalculatedValue = _calculatedValue2.default;

exports.SectionElement = _sectionElement2.default;
exports.RecordLinkElement = _sectionElement2.default;
exports.RecordLinkElement = _recordLinkElement2.default;
exports.RecordLinkValue = _recordLinkValue2.default;

@@ -259,4 +309,13 @@ exports.RecordLinkItemValue = _recordLinkItemValue2.default;

exports.CustomValidationError = _customValidationError2.default;
exports.MediaElement = _mediaElement2.default;
exports.MediaValue = _mediaValue2.default;
exports.MediaItemValue = _mediaItemValue2.default;
exports.User = _user2.default;
exports.Role = _role2.default;
exports.Project = _project2.default;
exports.Changeset = _changeset2.default;
exports.Track = _track2.default;
exports.TrackPoint = _trackPoint2.default;
exports.TrackSegment = _trackSegment2.default;
exports.TrackPlayer = _trackPlayer2.default;
//# sourceMappingURL=index.js.map

@@ -5,15 +5,42 @@ "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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Project = function Project(attributes) {
_classCallCheck(this, Project);
var Project = function () {
function Project(attributes) {
_classCallCheck(this, Project);
attributes = attributes || {};
this.updateFromAPIAttributes(attributes);
}
this.id = attributes.id;
this.name = attributes.name;
this.description = attributes.description;
};
Project.prototype.updateFromAPIAttributes = function updateFromAPIAttributes(attrs) {
var attributes = attrs || {};
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
};
_createClass(Project, [{
key: "id",
get: function get() {
return this._id;
}
}, {
key: "name",
get: function get() {
return this._name;
}
}, {
key: "description",
get: function get() {
return this._description;
}
}]);
return Project;
}();
exports.default = Project;
//# sourceMappingURL=project.js.map

@@ -27,2 +27,10 @@ 'use strict';

var _uuid = require('uuid');
var _uuid2 = _interopRequireDefault(_uuid);
var _loadObject = require('./load-object');
var _loadObject2 = _interopRequireDefault(_loadObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -41,39 +49,144 @@

function Record(attributes) {
function Record(attributes, form) {
_classCallCheck(this, Record);
return _possibleConstructorReturn(this, _Feature.call(this));
var _this = _possibleConstructorReturn(this, _Feature.call(this));
// this._id = attributes.id;
// this._createdAt = DateUtils.parseTimestamp(attributes.client_created_at);
// this._updatedAt = DateUtils.parseTimestamp(attributes.client_updated_at);
// this._formValuesJSON = attributes.form_values;
// this._latitude = attributes.latitude;
// this._longitude = attributes.longitude;
_this._form = form || null;
_this.updateFromAPIAttributes(attributes);
return _this;
}
Record.prototype.loadChangeset = function loadChangeset(dataSource, callback) {
return (0, _loadObject2.default)(this, dataSource, 'changeset', 'getChangeset', callback);
};
Record.prototype.toJSON = function toJSON() {
var json = {};
// TODO(zhm) this is incomplete
json.id = this.id;
json.client_created_at = _dateUtils2.default.formatTimestamp(this.createdAt);
json.client_updated_at = _dateUtils2.default.formatTimestamp(this.updatedAt);
json.form_id = this._form.id;
json.id = this.id || null;
json.version = this._version || null;
json.created_at = _dateUtils2.default.formatISOTimestamp(this.createdAt);
json.updated_at = _dateUtils2.default.formatISOTimestamp(this.updatedAt);
json.client_created_at = _dateUtils2.default.formatISOTimestamp(this.clientCreatedAt);
json.client_updated_at = _dateUtils2.default.formatISOTimestamp(this.clientUpdatedAt);
json.form_values = this.formValues.toJSON();
json.latitude = this._latitude;
json.longitude = this._longitude;
json.project_id = this._projectID;
json.assigned_to_id = this._assignedToID;
json.latitude = this._latitude || null;
json.longitude = this._longitude || null;
json.project_id = this._projectID || null;
json.assigned_to_id = this._assignedToID || null;
json.status = this._status || null;
json.created_by_id = this._createdByID || null;
json.created_by = this._createdBy || null;
json.updated_by_id = this._updatedByID || null;
json.updated_by = this._updatedBy || null;
if (this._horizontalAccuracy != null) {
json.horizontal_accuracy = this._horizontalAccuracy;
}
if (this._verticalAccuracy != null) {
json.vertical_accuracy = this._verticalAccuracy;
}
if (this._altitude != null) {
json.altitude = this._altitude;
}
if (this._speed != null) {
json.speed = this._speed;
}
if (this._course != null) {
json.course = this._course;
}
if (this._changesetID) {
json.changeset_id = this._changesetID;
}
json.created_location = this.createdLocation;
json.updated_location = this.updatedLocation;
json.created_duration = this.createdDuration;
json.updated_duration = this.updatedDuration;
json.edited_duration = this.editedDuration;
return json;
};
Record.prototype.updateFromAPIAttributes = function updateFromAPIAttributes(attrs) {
var attributes = attrs || {};
this._id = attributes.id || _uuid2.default.v4();
this._version = attributes.version || null;
this._createdAt = _dateUtils2.default.parseISOTimestamp(attributes.created_at);
this._updatedAt = _dateUtils2.default.parseISOTimestamp(attributes.updated_at);
this._clientCreatedAt = _dateUtils2.default.parseISOTimestamp(attributes.client_created_at);
this._clientUpdatedAt = _dateUtils2.default.parseISOTimestamp(attributes.client_updated_at);
this._formValuesJSON = attributes.form_values || {};
this._latitude = attributes.latitude || null;
this._longitude = attributes.longitude || null;
this._projectID = attributes.project_id || null;
this._assignedToID = attributes.assigned_to_id || null;
this._status = attributes.status || null;
this._createdByID = attributes.created_by_id || null;
this._createdBy = attributes.created_by || null;
this._updatedByID = attributes.updated_by_id || null;
this._updatedBy = attributes.updated_by || null;
this._horizontalAccuracy = attributes.horizontal_accuracy || null;
this._verticalAccuracy = attributes.vertical_accuracy || null;
this._altitude = attributes.altitude || null;
this._speed = attributes.speed || null;
this._course = attributes.course || null;
this._changesetID = attributes.changeset_id || null;
this._createdDuration = attributes.created_duration || null;
this._updatedDuration = attributes.updated_duration || null;
this._editedDuration = attributes.edited_duration || null;
var createdLocation = attributes.created_location;
this._createdLatitude = null;
this._createdLongitude = null;
this._createdAltitude = null;
this._createdAccuracy = null;
if (createdLocation) {
this._createdLatitude = createdLocation.latitude;
this._createdLongitude = createdLocation.longitude;
this._createdAltitude = createdLocation.altitude;
this._createdAccuracy = createdLocation.horizontal_accuracy;
}
var updatedLocation = attributes.updated_location;
this._updatedLatitude = null;
this._updatedLongitude = null;
this._updatedAltitude = null;
this._updatedAccuracy = null;
if (updatedLocation) {
this._updatedLatitude = updatedLocation.latitude;
this._updatedLongitude = updatedLocation.longitude;
this._updatedAltitude = updatedLocation.altitude;
this._updatedAccuracy = updatedLocation.horizontal_accuracy;
}
};
Record.prototype.updateTimestamps = function updateTimestamps() {
var now = new Date();
if (this._createdAt == null) {
this.createdAt = now;
if (this.clientCreatedAt == null) {
this.clientCreatedAt = now;
}
this.updatedAt = now;
this.clientUpdatedAt = now;
};

@@ -98,2 +211,82 @@

Record.prototype.updateFromActionAttributes = function updateFromActionAttributes(attributes, role) {
for (var _iterator = Object.keys(attributes), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var dataName = _ref;
switch (dataName) {
case 'project_id':
{
if (attributes.project_id && role.canChangeProject) {
this.projectID = attributes.project_id;
}
break;
}
case 'assigned_to_id':
{
if (attributes.assigned_to_id && role.canChangeAssignment) {
this.assignedToID = attributes.assigned_to_id;
}
break;
}
case 'status':
{
if (attributes.status && role.canChangeStatus) {
this.status = attributes.status;
}
break;
}
case 'latitude':
{
if (attributes.latitude != null && attributes.latitude >= -90 && attributes.latitude <= 90) {
this.latitude = +attributes.latitude;
}
break;
}
case 'longitude':
{
if (attributes.longitude != null && attributes.longitude >= -180 && attributes.longitude <= 180) {
this.longitude = +attributes.longitude;
}
break;
}
default:
{
var element = this.form.elementsByDataName[dataName];
var value = attributes[dataName];
if (element && value != null) {
var formValue = this.formValues.createValueFromString(element, value);
if (formValue) {
this.formValues.set(element.key, formValue);
}
}
break;
}
}
}
};
_createClass(Record, [{

@@ -113,2 +306,7 @@ key: 'id',

}, {
key: 'version',
get: function get() {
return this._version;
}
}, {
key: 'createdAt',

@@ -130,2 +328,18 @@ get: function get() {

}, {
key: 'clientCreatedAt',
get: function get() {
return this._clientCreatedAt;
},
set: function set(createdAt) {
this._clientCreatedAt = createdAt;
}
}, {
key: 'clientUpdatedAt',
get: function get() {
return this._clientUpdatedAt;
},
set: function set(updatedAt) {
this._clientUpdatedAt = updatedAt;
}
}, {
key: 'formValues',

@@ -145,2 +359,26 @@ get: function get() {

}, {
key: 'changeset',
get: function get() {
return this._changeset;
},
set: function set(changeset) {
this._changesetID = changeset.id;
this._changeset = changeset;
}
}, {
key: 'changesetID',
get: function get() {
return this._changesetID;
}
}, {
key: 'createdBy',
get: function get() {
return this._createdBy;
}
}, {
key: 'updatedBy',
get: function get() {
return this._updatedBy;
}
}, {
key: 'isGeometryEnabled',

@@ -156,2 +394,7 @@ get: function get() {

}, {
key: 'searchableValue',
get: function get() {
return this.formValues.searchableValue;
}
}, {
key: 'displayValue',

@@ -162,15 +405,15 @@ get: function get() {

for (var _iterator = titleFieldKeys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
for (var _iterator2 = titleFieldKeys, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var fieldKey = _ref;
var fieldKey = _ref2;

@@ -206,2 +449,7 @@ var value = this.formValues.get(fieldKey);

}, {
key: 'formID',
get: function get() {
return this.form ? this.form.id : null;
}
}, {
key: 'projectID',

@@ -223,2 +471,12 @@ get: function get() {

}, {
key: 'createdByID',
get: function get() {
return this._createdByID;
}
}, {
key: 'updatedByID',
get: function get() {
return this._updatedByID;
}
}, {
key: 'status',

@@ -231,2 +489,196 @@ get: function get() {

}
}, {
key: 'latitude',
get: function get() {
return this._latitude;
},
set: function set(latitude) {
this._latitude = latitude;
}
}, {
key: 'longitude',
get: function get() {
return this._longitude;
},
set: function set(longitude) {
this._longitude = longitude;
}
}, {
key: 'horizontalAccuracy',
get: function get() {
return this._horizontalAccuracy;
},
set: function set(accuracy) {
this._horizontalAccuracy = accuracy;
}
}, {
key: 'verticalAccuracy',
get: function get() {
return this._verticalAccuracy;
},
set: function set(accuracy) {
this._verticalAccuracy = accuracy;
}
}, {
key: 'altitude',
get: function get() {
return this._altitude;
},
set: function set(altitude) {
this._altitude = altitude;
}
}, {
key: 'speed',
get: function get() {
return this._speed;
},
set: function set(speed) {
this._speed = speed;
}
}, {
key: 'course',
get: function get() {
return this._course;
},
set: function set(course) {
this._course = course;
}
}, {
key: 'geometryAsGeoJSON',
get: function get() {
if (!this.hasCoordinate) {
return null;
}
return {
type: 'Point',
coordinates: [this.longitude, this.latitude]
};
}
}, {
key: 'createdDuration',
get: function get() {
return this._createdDuration;
},
set: function set(value) {
this._createdDuration = value != null ? +value : null;
}
}, {
key: 'updatedDuration',
get: function get() {
return this._updatedDuration;
},
set: function set(value) {
this._updatedDuration = value != null ? +value : null;
}
}, {
key: 'editedDuration',
get: function get() {
return this._editedDuration;
},
set: function set(value) {
this._editedDuration = value != null ? +value : null;
}
}, {
key: 'createdLatitude',
get: function get() {
return this._createdLatitude;
},
set: function set(value) {
this._createdLatitude = value != null ? +value : null;
}
}, {
key: 'createdLongitude',
get: function get() {
return this._createdLongitude;
},
set: function set(value) {
this._createdLongitude = value != null ? +value : null;
}
}, {
key: 'createdAltitude',
get: function get() {
return this._createdAltitude;
},
set: function set(value) {
this._createdAltitude = value != null ? +value : null;
}
}, {
key: 'createdAccuracy',
get: function get() {
return this._createdAccuracy;
},
set: function set(value) {
this._createdAccuracy = value != null ? +value : null;
}
}, {
key: 'updatedLatitude',
get: function get() {
return this._updatedLatitude;
},
set: function set(value) {
this._updatedLatitude = value != null ? +value : null;
}
}, {
key: 'updatedLongitude',
get: function get() {
return this._updatedLongitude;
},
set: function set(value) {
this._updatedLongitude = value != null ? +value : null;
}
}, {
key: 'updatedAltitude',
get: function get() {
return this._updatedAltitude;
},
set: function set(value) {
this._updatedAltitude = value != null ? +value : null;
}
}, {
key: 'updatedAccuracy',
get: function get() {
return this._updatedAccuracy;
},
set: function set(value) {
this._updatedAccuracy = value != null ? +value : null;
}
}, {
key: 'hasCreatedCoordinate',
get: function get() {
return this.createdLatitude != null && this.createdLongitude != null;
}
}, {
key: 'hasUpdatedCoordinate',
get: function get() {
return this.updatedLatitude != null && this.updatedLongitude != null;
}
}, {
key: 'createdLocation',
get: function get() {
if (this.hasCreatedCoordinate) {
return {
latitude: this.createdLatitude,
longitude: this.createdLongitude,
altitude: this.createdAltitude,
horizontal_accuracy: this.createdAccuracy
};
}
return null;
}
}, {
key: 'updatedLocation',
get: function get() {
if (this.hasUpdatedCoordinate) {
return {
latitude: this.updatedLatitude,
longitude: this.updatedLongitude,
altitude: this.updatedAltitude,
horizontal_accuracy: this.updatedAccuracy
};
}
return null;
}
}]);

@@ -233,0 +685,0 @@

@@ -1,18 +0,53 @@

"use strict";
'use strict';
exports.__esModule = true;
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; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var User = function User(attributes) {
_classCallCheck(this, User);
var User = function () {
function User(attrs) {
_classCallCheck(this, User);
attributes = attributes || {};
var attributes = attrs || {};
this.id = attributes.id;
this.name = attributes.name;
this.email = attributes.email;
};
this._id = attributes.id;
this._firstName = attributes.first_name;
this._lastName = attributes.last_name;
this._email = attributes.email;
this._fullName = attributes.name;
}
_createClass(User, [{
key: 'id',
get: function get() {
return this._id;
}
}, {
key: 'firstName',
get: function get() {
return this._firstName;
}
}, {
key: 'lastName',
get: function get() {
return this._lastName;
}
}, {
key: 'fullName',
get: function get() {
return this._fullName || this.firstName + ' ' + this.lastName;
}
}, {
key: 'email',
get: function get() {
return this._email;
}
}]);
return User;
}();
exports.default = User;
//# sourceMappingURL=user.js.map

@@ -9,6 +9,10 @@ 'use strict';

var _lodash = require('lodash');
var _lodash = require('lodash.padstart');
var _lodash2 = _interopRequireDefault(_lodash);
var _relativeDate = require('relative-date');
var _relativeDate2 = _interopRequireDefault(_relativeDate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -30,3 +34,9 @@

DateUtils.parseDate = function parseDate(dateString) {
return new Date(dateString.replace(/-/g, '/'));
var date = new Date(dateString.replace(/-/g, '/'));
if (date == null || isNaN(date.getTime())) {
return null;
}
return date;
};

@@ -38,8 +48,26 @@

}
return timeString;
var _timeString$split = timeString.split(':');
var hours = _timeString$split[0];
var minutes = _timeString$split[1];
if (hours == null || minutes == null) {
return null;
}
hours = +hours;
minutes = +minutes;
if (isNaN(hours) || isNaN(minutes)) {
return null;
}
return hours * 60 + minutes;
};
DateUtils.formatTime = function formatTime(date) {
var hours = _lodash2.default.padStart(date.getHours(), 2, '0');
var minutes = _lodash2.default.padStart(date.getMinutes(), 2, '0');
var hours = (0, _lodash2.default)(date.getHours(), 2, '0');
var minutes = (0, _lodash2.default)(date.getMinutes(), 2, '0');

@@ -49,17 +77,139 @@ return hours + ':' + minutes;

DateUtils.parseTimestamp = function parseTimestamp(timestampString) {
DateUtils.formatTimeSeconds = function formatTimeSeconds(seconds) {
var milliseconds = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var ss = +seconds % 60;
var div = (+seconds - ss) / 60;
var mm = div % 60;
var hh = (div - mm) / 60;
var ms = ss * 1000 % 1000;
var h = (0, _lodash2.default)(Math.floor(hh), 2, '0');
var m = (0, _lodash2.default)(Math.floor(mm), 2, '0');
var s = (0, _lodash2.default)(Math.floor(ss), 2, '0');
var u = (0, _lodash2.default)(Math.floor(ms), 3, '0');
return h + ':' + m + ':' + s + (milliseconds ? '.' + u : '');
};
DateUtils.formatTimeParts = function formatTimeParts(hours, minutes, seconds) {
var h = (0, _lodash2.default)(+hours, 2, '0');
var m = (0, _lodash2.default)(+minutes, 2, '0');
var s = (0, _lodash2.default)(+seconds, 2, '0');
return h + ':' + m + ':' + s;
};
DateUtils.parseISOTimestamp = function parseISOTimestamp(timestampString) {
if (!timestampString) {
return null;
}
return new Date(timestampString);
};
DateUtils.parseEpochTimestamp = function parseEpochTimestamp(timestampString) {
if (!timestampString) {
return null;
}
return new Date(parseFloat(timestampString) * 1000);
};
DateUtils.formatTimestamp = function formatTimestamp(date) {
if (date == null) {
DateUtils.formatISOTimestamp = function formatISOTimestamp(date) {
if (date == null || isNaN(date.getTime())) {
return null;
}
return date.getTime().toFixed(3);
return date.toISOString();
};
DateUtils.formatEpochTimestamp = function formatEpochTimestamp(date) {
if (date == null || isNaN(date.getTime())) {
return null;
}
return (date.getTime() / 1000).toFixed(3);
};
DateUtils.isValidTime = function isValidTime(timeString) {
if (timeString == null) {
return true;
}
if (timeString.length !== 5) {
return false;
}
var parts = timeString.split(':');
if (parts.length !== 2) {
return false;
}
var hourPart = parts[0];
var minutePart = parts[1];
if (hourPart.length !== 2 || minutePart.length !== 2) {
return false;
}
var hour = +hourPart;
var minute = +minutePart;
if (isNaN(hour) || isNaN(minute)) {
return false;
}
if (hour < 0 || hour >= 24) {
return false;
}
if (minute < 0 || minute >= 60) {
return false;
}
return true;
};
DateUtils.isValidDate = function isValidDate(dateString) {
if (dateString == null) {
return true;
}
if (dateString.length !== 10) {
return false;
}
var parts = dateString.split('-');
if (parts.length !== 3) {
return false;
}
var yearPart = parts[0];
var monthPart = parts[1];
var dayPart = parts[2];
if (yearPart.length !== 4 || monthPart.length !== 2 || dayPart.length !== 2) {
return false;
}
var year = +yearPart;
var month = +monthPart;
var day = +dayPart;
if (isNaN(year) || isNaN(month) || isNaN(day)) {
return false;
}
var parsed = DateUtils.parseDate(dateString);
return parsed && !isNaN(parsed);
};
DateUtils.formatDate = function formatDate(date) {
var year = date.getFullYear();
var month = _lodash2.default.padStart(date.getMonth() + 1, 2, '0');
var day = _lodash2.default.padStart(date.getDate(), 2, '0');
var month = (0, _lodash2.default)(date.getMonth() + 1, 2, '0');
var day = (0, _lodash2.default)(date.getDate(), 2, '0');

@@ -73,10 +223,23 @@ return year + '-' + month + '-' + day;

}
return DateUtils.__formatLocalizedDate(date);
};
DateUtils.formatLocalizedTimestamp = function formatLocalizedTimestamp(date) {
if (date == null) {
return null;
}
return date.toLocaleString();
};
DateUtils.formatRelativeTimestamp = function formatRelativeTimestamp(date) {
return (0, _relativeDate2.default)(date);
};
DateUtils.__formatLocalizedDate = function __formatLocalizedDate(date) {
if (!_locale2.default.supportsECMA402()) {
var year = date.getFullYear();
var month = _lodash2.default.padStart(date.getMonth() + 1, 2, '0');
var day = _lodash2.default.padStart(date.getDate(), 2, '0');
var month = (0, _lodash2.default)(date.getMonth() + 1, 2, '0');
var day = (0, _lodash2.default)(date.getDate(), 2, '0');
return year + '-' + month + '-' + day;

@@ -91,3 +254,11 @@ }

return new intl.DateTimeFormat(_locale2.default.currentLocale(), options).format(date);
var result = null;
try {
result = new intl.DateTimeFormat(_locale2.default.currentLocale(), options).format(date);
} catch (ex) {
// RangeError: Provided date is not in valid range.
}
return result;
};

@@ -94,0 +265,0 @@

@@ -23,5 +23,5 @@ 'use strict';

return true;
} else {
return false;
}
return false;
};

@@ -28,0 +28,0 @@

@@ -14,2 +14,6 @@ "use strict";

this.users = null;
this.photos = {};
this.audio = {};
this.videos = {};
this.tracks = {};
}

@@ -29,3 +33,3 @@

MemoryDataSource.prototype.getRecord = function getRecord(id, callback) {
MemoryDataSource.prototype.getRecord = function getRecord(id, form, callback) {
return callback(null, this.cache[id]);

@@ -42,2 +46,22 @@ };

MemoryDataSource.prototype.getPhoto = function getPhoto(id, callback) {
return callback(null, this.photos[id]);
};
MemoryDataSource.prototype.getAudio = function getAudio(id, callback) {
return callback(null, this.audio[id]);
};
MemoryDataSource.prototype.getAudioTrack = function getAudioTrack(id, callback) {
return callback(null, this.tracks[id]);
};
MemoryDataSource.prototype.getVideo = function getVideo(id, callback) {
return callback(null, this.videos[id]);
};
MemoryDataSource.prototype.getVideoTrack = function getVideoTrack(id, callback) {
return callback(null, this.tracks[id]);
};
MemoryDataSource.prototype.getChoiceListComplete = function getChoiceListComplete(id, object, callback) {

@@ -58,3 +82,3 @@ this.cache[id] = object;

MemoryDataSource.prototype.getRecordComplete = function getRecordComplete(id, object, callback) {
MemoryDataSource.prototype.getRecordComplete = function getRecordComplete(id, form, object, callback) {
this.cache[id] = object;

@@ -74,2 +98,34 @@ callback();

MemoryDataSource.prototype.getPhotoComplete = function getPhotoComplete(id, object, callback) {
if (object.processed) {
this.photos[id] = object;
}
callback();
};
MemoryDataSource.prototype.getAudioComplete = function getAudioComplete(id, object, callback) {
if (object.processed) {
this.audio[id] = object;
}
callback();
};
MemoryDataSource.prototype.getAudioTrackComplete = function getAudioTrackComplete(id, object, callback) {
this.tracks[id] = object;
callback();
};
MemoryDataSource.prototype.getVideoComplete = function getVideoComplete(id, object, callback) {
if (object.processed) {
this.videos[id] = object;
}
callback();
};
MemoryDataSource.prototype.getVideoTrackComplete = function getVideoTrackComplete(id, object, callback) {
this.tracks[id] = object;
callback();
};
return MemoryDataSource;

@@ -76,0 +132,0 @@ }();

@@ -5,2 +5,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 _locale = require('./locale');

@@ -24,3 +26,5 @@

if (typeof Intl !== 'undefined') {
intl = global.Intl;
/* eslint-disable no-undef */
intl = Intl;
/* eslint-enable no-undef */
}

@@ -34,6 +38,20 @@

NumberUtils.parseDouble = function parseDouble(input) {
return +input;
var number = +input;
if (number == null || isNaN(number)) {
return null;
}
return number;
};
NumberUtils.localizedStringFromMachineString = function localizedStringFromMachineString(machineString, allowDecimals) {
NumberUtils.localizedStringFromMachineString = function localizedStringFromMachineString(machineString) {
var allowDecimals = arguments.length <= 1 || arguments[1] === undefined ? true : arguments[1];
if (allowDecimals && NumberUtils.localeDecimalFormatter) {
return NumberUtils.localeDecimalFormatter.format(machineString);
} else if (NumberUtils.localeIntegerFormatter) {
return NumberUtils.localeIntegerFormatter.format(machineString);
}
return machineString;

@@ -43,8 +61,2 @@ };

NumberUtils.formatMachine = function formatMachine(number) {
if (intl) {
if (NumberUtils.machineFormatter == null) {
NumberUtils.machineFormatter = new intl.NumberFormat(['en-US'], MachineFormatterOptions);
}
}
return NumberUtils.formatWithFormatter(NumberUtils.machineFormatter, number);

@@ -85,10 +97,39 @@ };

return number;
} else {
return string;
}
} else {
return number.toString();
return string;
}
return number.toString();
};
_createClass(NumberUtils, null, [{
key: 'localeDecimalFormatter',
get: function get() {
if (!this._localeDecimalFormatter && intl) {
this._localeDecimalFormatter = new intl.NumberFormat();
}
return this._localeDecimalFormatter;
}
}, {
key: 'localeIntegerFormatter',
get: function get() {
if (!this._localeIntegerFormatter && intl) {
this._localeIntegerFormatter = new intl.NumberFormat([], { maximumFractionDigits: 0 });
}
return this._localeIntegerFormatter;
}
}, {
key: 'machineFormatter',
get: function get() {
if (!this._machineFormatter && intl) {
this._machineFormatter = new intl.NumberFormat(['en-US'], MachineFormatterOptions);
}
return this._machineFormatter;
}
}]);
return NumberUtils;

@@ -95,0 +136,0 @@ }();

@@ -5,6 +5,14 @@ 'use strict';

var _lodash = require('lodash');
var _lodash = require('lodash.includes');
var _lodash2 = _interopRequireDefault(_lodash);
var _lodash3 = require('lodash.startswith');
var _lodash4 = _interopRequireDefault(_lodash3);
var _lodash5 = require('lodash.trim');
var _lodash6 = _interopRequireDefault(_lodash5);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -36,19 +44,19 @@

TextUtils.contains = function contains(haystack, needle) {
if (needle === null) {
if (needle == null) {
return false;
}
return _lodash2.default.contains(haystack.toLowerCase(), needle.toLowerCase());
return (0, _lodash2.default)(haystack.toLowerCase(), needle.toLowerCase());
};
TextUtils.startsWith = function startsWith(haystack, needle) {
if (needle === null) {
if (needle == null) {
return false;
}
return _lodash2.default.startsWith(haystack, needle);
return (0, _lodash4.default)(haystack, needle);
};
TextUtils.trim = function trim(value) {
return _lodash2.default.trim(value);
return (0, _lodash6.default)(value);
};

@@ -55,0 +63,0 @@

@@ -41,2 +41,10 @@ 'use strict';

var _dateFormatValidationError = require('./date-format-validation-error');
var _dateFormatValidationError2 = _interopRequireDefault(_dateFormatValidationError);
var _timeFormatValidationError = require('./time-format-validation-error');
var _timeFormatValidationError2 = _interopRequireDefault(_timeFormatValidationError);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -69,3 +77,3 @@

if (record.isStatusFieldEnabled && record.status == null) {
errors.push(new _requiredFieldValidationError2.default(record.form.statusField.label));
errors.push(new _requiredFieldValidationError2.default(record.form.statusField));
}

@@ -106,6 +114,4 @@

FeatureValidator.validateFieldsInElements = function validateFieldsInElements(elements, record, formValues, errors, cache) {
if (!cache) {
cache = {};
}
FeatureValidator.validateFieldsInElements = function validateFieldsInElements(elements, record, formValues, errors, visibilityCache) {
var cache = visibilityCache || {};

@@ -169,5 +175,4 @@ for (var _iterator = elements, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {

if (element.isLengthValidationSupported) {
var _fieldValue = formValues.get(element.key);
var _error2 = FeatureValidator.validateLengthForElement(element, _fieldValue);
if (element.isDateElement) {
var _error2 = FeatureValidator.validateDateField(element, formValues.get(element.key));

@@ -178,2 +183,19 @@ if (_error2) {

}
if (element.isTimeElement) {
var _error3 = FeatureValidator.validateTimeField(element, formValues.get(element.key));
if (_error3) {
errors.push(_error3);
}
}
if (element.isLengthValidationSupported) {
var _fieldValue = formValues.get(element.key);
var _error4 = FeatureValidator.validateLengthForElement(element, _fieldValue);
if (_error4) {
errors.push(_error4);
}
}
}

@@ -216,3 +238,3 @@

var regex = new RegExp(element.pattern);
var regex = new RegExp('^(?:' + element.pattern + ')$');

@@ -263,4 +285,4 @@ if (regex) {

if (element.isInteger) {
if (value.indexOf(decimalSeparator) > -1) {
if (element.isIntegerFormat) {
if (value.textValue.indexOf(decimalSeparator) > -1) {
return new _numericFormatValidationError2.default(element);

@@ -272,3 +294,3 @@ }

if (numberValue < element.min || numberValue > element.max) {
if (element.hasMin && numberValue < element.min || element.hasMax && numberValue > element.max) {
return new _numericRangeValidationError2.default(element);

@@ -280,2 +302,26 @@ }

FeatureValidator.validateDateField = function validateDateField(element, value) {
if (value == null || value.isEmpty) {
return null;
}
if (!value.isValid) {
return new _dateFormatValidationError2.default(element);
}
return null;
};
FeatureValidator.validateTimeField = function validateTimeField(element, value) {
if (value == null || value.isEmpty) {
return null;
}
if (!value.isValid) {
return new _timeFormatValidationError2.default(element);
}
return null;
};
FeatureValidator.formatErrors = function formatErrors(errors) {

@@ -282,0 +328,0 @@ var messages = [];

@@ -51,5 +51,5 @@ 'use strict';

return (0, _util.format)(singularFormat, this.label, length);
} else {
return (0, _util.format)(pluralFormat, this.label, length);
}
return (0, _util.format)(pluralFormat, this.label, length);
};

@@ -56,0 +56,0 @@

@@ -35,3 +35,3 @@ 'use strict';

get: function get() {
var messageFormat = this.element.isInteger ? "The value of field '%s' must be an integer number." : "The value of field '%s' must be an decimal number.";
var messageFormat = this.element.isIntegerFormat ? "The value of field '%s' must be an integer number." : "The value of field '%s' must be an decimal number.";

@@ -38,0 +38,0 @@ return (0, _util.format)(messageFormat, this.label);

@@ -35,3 +35,3 @@ 'use strict';

get: function get() {
var message = void 0;
var message = null;

@@ -38,0 +38,0 @@ var fieldLabel = this.label;

@@ -41,2 +41,6 @@ 'use strict';

AddressValue.prototype.toJSON = function toJSON() {
if (this.isEmpty) {
return null;
}
return this.address.toJSON();

@@ -68,3 +72,3 @@ };

get: function get() {
return this.address.isEmpty();
return this.address.isEmpty;
}

@@ -89,5 +93,26 @@ }, {

get: function get() {
return null;
// TODO(zhm) implement
// throw new Error('Not implemented');
var value = {};
var address = this.address.toJSON();
for (var _iterator = Object.keys(address), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var key = _ref;
value['f' + this.element.key + '_' + key] = address[key];
}
value['f' + this.element.key] = this.searchableValue;
return value;
}

@@ -94,0 +119,0 @@ }, {

@@ -57,6 +57,2 @@ 'use strict';

Address.prototype.isEmpty = function isEmpty() {
return !(_textUtils2.default.isPresent(this.streetNumber) || _textUtils2.default.isPresent(this.streetName) || _textUtils2.default.isPresent(this.suite) || _textUtils2.default.isPresent(this.city) || _textUtils2.default.isPresent(this.county) || _textUtils2.default.isPresent(this.state) || _textUtils2.default.isPresent(this.postalCode) || _textUtils2.default.isPresent(this.country));
};
Address.prototype.line = function line() {

@@ -92,2 +88,7 @@ var result = [];

_createClass(Address, [{
key: 'isEmpty',
get: function get() {
return !(_textUtils2.default.isPresent(this.streetNumber) || _textUtils2.default.isPresent(this.streetName) || _textUtils2.default.isPresent(this.suite) || _textUtils2.default.isPresent(this.city) || _textUtils2.default.isPresent(this.county) || _textUtils2.default.isPresent(this.state) || _textUtils2.default.isPresent(this.postalCode) || _textUtils2.default.isPresent(this.country));
}
}, {
key: 'lines',

@@ -94,0 +95,0 @@ get: function get() {

@@ -44,5 +44,5 @@ 'use strict';

return '1 Audio File';
} else {
return this.length + ' Audio Files';
}
return this.length + ' Audio Files';
}

@@ -49,0 +49,0 @@ }]);

@@ -66,3 +66,3 @@ 'use strict';

if (date) {
return date.getTime();
return date.getTime() / 1000;
}

@@ -69,0 +69,0 @@ }

@@ -15,3 +15,3 @@ 'use strict';

var _lodash = require('lodash');
var _lodash = require('lodash.includes');

@@ -139,3 +139,3 @@ var _lodash2 = _interopRequireDefault(_lodash);

ChoiceValue.prototype.isEqual = function isEqual(value) {
if (_lodash2.default.includes(this.selectedValues, value)) {
if ((0, _lodash2.default)(this.selectedValues, value)) {
return true;

@@ -245,3 +245,6 @@ }

values.push(choice.label);
values.push(choice.value);
if (choice.label !== choice.value) {
values.push(choice.value);
}
} else {

@@ -323,3 +326,3 @@ values.push(rawValue);

return '\t' + allValues.join('\t') + '\t';
return allValues;
}

@@ -326,0 +329,0 @@ }, {

@@ -45,37 +45,41 @@ 'use strict';

if (attributes) {
for (var _iterator = attributes.choice_values, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (attributes.choice_values) {
for (var _iterator = attributes.choice_values, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var choice = _ref;
var choice = _ref;
if (_textUtils2.default.isPresent(choice)) {
_this._choiceValues.push(choice);
if (_textUtils2.default.isPresent(choice)) {
_this._choiceValues.push(choice);
}
}
}
for (var _iterator2 = attributes.other_values, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (attributes.other_values) {
for (var _iterator2 = attributes.other_values, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref2 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref2 = _i2.value;
}
var _choice = _ref2;
var _choice = _ref2;
if (_textUtils2.default.isPresent(_choice)) {
_this._otherValues.push(_choice);
if (_textUtils2.default.isPresent(_choice)) {
_this._otherValues.push(_choice);
}
}

@@ -87,2 +91,52 @@ }

ClassificationValue.prototype.isEqual = function isEqual(value) {
var classification = this.selectedClassification;
var choiceValues = classification ? classification.toJSON() : null;
var ESCAPED = /\\,/g;
var parts = value.replace(ESCAPED, '\t\t').split(',').map(function (part) {
return part.replace(/\t\t/g, ',');
});
var allMatchSoFar = false;
var partIndex = 0;
for (var _iterator3 = parts, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
}
var part = _ref3;
if (part != null && choiceValues && partIndex < choiceValues.length && choiceValues[partIndex].toLowerCase() === part.replace(ESCAPED, ',').toLowerCase()) {
allMatchSoFar = true;
} else {
allMatchSoFar = false;
break;
}
++partIndex;
}
return allMatchSoFar;
};
ClassificationValue.prototype.contains = function contains(value) {
return this.isEqual(value);
};
ClassificationValue.prototype.startsWith = function startsWith(value) {
return this.contains(value);
};
ClassificationValue.prototype.toJSON = function toJSON() {

@@ -104,4 +158,12 @@ if (this.isEmpty) {

if (classification instanceof _classification2.default) {
this._choiceValues = classification.toJSON();
this.setSelectedClassificationJSON(classification.toJSON(), otherValue);
} else {
this.setSelectedClassificationJSON(null, otherValue);
}
};
ClassificationValue.prototype.setSelectedClassificationJSON = function setSelectedClassificationJSON(classificationAsJSON, otherValue) {
if (classificationAsJSON && classificationAsJSON.length) {
this._choiceValues = classificationAsJSON;
} else {
this._choiceValues = [];

@@ -113,3 +175,3 @@ }

} else {
this._otherVaues = [];
this._otherValues = [];
}

@@ -139,15 +201,15 @@ };

if (classification) {
for (var _iterator3 = classification.exploded, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref3;
for (var _iterator4 = classification.exploded, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref4;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref3 = _iterator3[_i3++];
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref4 = _iterator4[_i4++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref3 = _i3.value;
_i4 = _iterator4.next();
if (_i4.done) break;
_ref4 = _i4.value;
}
var item = _ref3;
var item = _ref4;

@@ -174,15 +236,15 @@ if (item.label) {

if (classification) {
for (var _iterator4 = classification.exploded, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref4;
for (var _iterator5 = classification.exploded, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
var _ref5;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref4 = _iterator4[_i4++];
if (_isArray5) {
if (_i5 >= _iterator5.length) break;
_ref5 = _iterator5[_i5++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref4 = _i4.value;
_i5 = _iterator5.next();
if (_i5.done) break;
_ref5 = _i5.value;
}
var item = _ref4;
var item = _ref5;

@@ -193,3 +255,3 @@ if (item.label) {

if (item.value) {
if (item.value && item.value !== item.label) {
values.push(item.value);

@@ -216,15 +278,15 @@ }

for (var _iterator5 = this._choiceValues, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
var _ref5;
for (var _iterator6 = this._choiceValues, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
var _ref6;
if (_isArray5) {
if (_i5 >= _iterator5.length) break;
_ref5 = _iterator5[_i5++];
if (_isArray6) {
if (_i6 >= _iterator6.length) break;
_ref6 = _iterator6[_i6++];
} else {
_i5 = _iterator5.next();
if (_i5.done) break;
_ref5 = _i5.value;
_i6 = _iterator6.next();
if (_i6.done) break;
_ref6 = _i6.value;
}
var value = _ref5;
var value = _ref6;

@@ -234,15 +296,15 @@ allValues.push(value);

for (var _iterator6 = this._otherValues, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
var _ref6;
for (var _iterator7 = this._otherValues, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
var _ref7;
if (_isArray6) {
if (_i6 >= _iterator6.length) break;
_ref6 = _iterator6[_i6++];
if (_isArray7) {
if (_i7 >= _iterator7.length) break;
_ref7 = _iterator7[_i7++];
} else {
_i6 = _iterator6.next();
if (_i6.done) break;
_ref6 = _i6.value;
_i7 = _iterator7.next();
if (_i7.done) break;
_ref7 = _i7.value;
}
var _value = _ref6;
var _value = _ref7;

@@ -256,3 +318,3 @@ allValues.push(_value);

return allValues.join('\t');
return allValues;
}

@@ -277,2 +339,9 @@ }, {

return this._otherValues[0];
},
set: function set(value) {
if (value && value.length) {
this._otherValues = [value];
} else {
this._otherValues = [];
}
}

@@ -290,33 +359,33 @@ }, {

for (var _iterator7 = this._choiceValues, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
var _ref7;
for (var _iterator8 = this._choiceValues, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
var _ref8;
if (_isArray7) {
if (_i7 >= _iterator7.length) break;
_ref7 = _iterator7[_i7++];
if (_isArray8) {
if (_i8 >= _iterator8.length) break;
_ref8 = _iterator8[_i8++];
} else {
_i7 = _iterator7.next();
if (_i7.done) break;
_ref7 = _i7.value;
_i8 = _iterator8.next();
if (_i8.done) break;
_ref8 = _i8.value;
}
var classificationValue = _ref7;
var classificationValue = _ref8;
for (var _iterator8 = currentClassifications, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
var _ref8;
for (var _iterator9 = currentClassifications, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
var _ref9;
if (_isArray8) {
if (_i8 >= _iterator8.length) break;
_ref8 = _iterator8[_i8++];
if (_isArray9) {
if (_i9 >= _iterator9.length) break;
_ref9 = _iterator9[_i9++];
} else {
_i8 = _iterator8.next();
if (_i8.done) break;
_ref8 = _i8.value;
_i9 = _iterator9.next();
if (_i9.done) break;
_ref9 = _i9.value;
}
var classification = _ref8;
var classification = _ref9;
if (classification.value === classificationValue) {
result = classification;
currentClassifications = classification.children;
currentClassifications = classification.items;
break;

@@ -323,0 +392,0 @@ }

@@ -32,6 +32,6 @@ 'use strict';

function DateValue(element, value) {
function DateValue() {
_classCallCheck(this, DateValue);
return _possibleConstructorReturn(this, _TextualValue.call(this, element, value));
return _possibleConstructorReturn(this, _TextualValue.apply(this, arguments));
}

@@ -90,2 +90,11 @@

}, {
key: 'isValid',
get: function get() {
if (this.isEmpty) {
return true;
}
return _dateUtils2.default.isValidDate(this.textValue);
}
}, {
key: 'dateValue',

@@ -95,2 +104,17 @@ get: function get() {

}
}, {
key: 'columnValue',
get: function get() {
if (this.isEmpty) {
return null;
}
return this.dateValue;
// The following code can be used to convert a date to a unix timestamp integer
//
// const timestamp = this.textValue + 'T00:00:00Z';
// const date = DateUtils.parseISOTimestamp(timestamp);
// return date ? date.getTime() / 1000 : null;
}
}]);

@@ -97,0 +121,0 @@

@@ -24,3 +24,5 @@ 'use strict';

DefaultValues.applyDefaultValue = function applyDefaultValue(defaultValue, element, formValues) {
DefaultValues.applyDefaultValue = function applyDefaultValue(elementDefaultValue, element, formValues) {
var defaultValue = elementDefaultValue;
var value = formValues.get(element.key);

@@ -30,3 +32,3 @@

if (hasValue || defaultValue == null) {
if (hasValue || defaultValue == null || defaultValue.length === 0) {
return;

@@ -33,0 +35,0 @@ }

@@ -102,3 +102,3 @@ 'use strict';

if (constructor == null) {
throw new Error('Unsupported element ' + element.type);
return null;
}

@@ -105,0 +105,0 @@

@@ -7,5 +7,5 @@ 'use strict';

var _elementTypes = require('../elements/element-types');
var _formValueFactory = require('./form-value-factory');
var _elementTypes2 = _interopRequireDefault(_elementTypes);
var _formValueFactory2 = _interopRequireDefault(_formValueFactory);

@@ -20,4 +20,2 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var FormValueFactory = null;
var FormValue = function () {

@@ -55,39 +53,6 @@ function FormValue(element, value) {

FormValue.factory = function factory() {
return FormValueFactory = FormValueFactory || require('./form-value-factory').default;
};
FormValue.create = function create(element, attributes) {
return FormValue.factory().create(element, attributes);
return _formValueFactory2.default.create(element, attributes);
};
FormValue.classes = function classes() {
if (FormValue._classes == null) {
FormValue._classes = {};
for (var _iterator = Object.keys(_elementTypes2.default), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var klass = _ref;
var _constructor = FormValue.factory().classes()[_elementTypes2.default[klass]];
if (_constructor) {
FormValue._classes[_constructor.name] = _constructor;
}
}
}
return FormValue._classes;
};
_createClass(FormValue, [{

@@ -94,0 +59,0 @@ key: 'element',

@@ -23,2 +23,18 @@ 'use strict';

var _condition = require('../elements/condition');
var _condition2 = _interopRequireDefault(_condition);
var _mediaValue = require('./media-value');
var _mediaValue2 = _interopRequireDefault(_mediaValue);
var _signatureValue = require('./signature-value');
var _signatureValue2 = _interopRequireDefault(_signatureValue);
var _repeatableValue = require('./repeatable-value');
var _repeatableValue2 = _interopRequireDefault(_repeatableValue);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -36,3 +52,3 @@

this.container = container;
this.loadValues(container.elements, attributes);
this.loadValues(container.elements, attributes || {});
}

@@ -160,2 +176,6 @@

FormValues.prototype.createValue = function createValue(element, rawValue) {
if (element == null) {
throw new Error('element cannot be null');
}
return _formValueFactory2.default.create(element, rawValue != null ? rawValue : null);

@@ -241,2 +261,55 @@ };

FormValues.prototype.clearInvisibleValues = function clearInvisibleValues(valuesForConditions, record) {
var elementsToRemove = [];
var cache = {};
for (var _iterator4 = this.all, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref4;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref4 = _iterator4[_i4++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref4 = _i4.value;
}
var formValue = _ref4;
var element = formValue.element;
// don't clear out fields that are explicitly marked hidden, or have any parents explicitly marked as hidden
var skipElement = element.isHidden || element.hasHiddenParent;
if (!skipElement) {
var shouldBeVisible = _condition2.default.shouldElementBeVisible(element, record, valuesForConditions, cache);
if (!shouldBeVisible) {
elementsToRemove.push(element);
}
}
}
for (var _iterator5 = elementsToRemove, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
var _ref5;
if (_isArray5) {
if (_i5 >= _iterator5.length) break;
_ref5 = _iterator5[_i5++];
} else {
_i5 = _iterator5.next();
if (_i5.done) break;
_ref5 = _i5.value;
}
var _element = _ref5;
var blankValue = this.createValue(_element, null);
this.set(_element.key, blankValue);
}
};
_createClass(FormValues, [{

@@ -247,15 +320,15 @@ key: 'all',

for (var _iterator4 = Object.keys(this._values), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref4;
for (var _iterator6 = Object.keys(this._values), _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
var _ref6;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref4 = _iterator4[_i4++];
if (_isArray6) {
if (_i6 >= _iterator6.length) break;
_ref6 = _iterator6[_i6++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref4 = _i4.value;
_i6 = _iterator6.next();
if (_i6.done) break;
_ref6 = _i6.value;
}
var key = _ref4;
var key = _ref6;

@@ -272,15 +345,15 @@ result.push(this._values[key]);

for (var _iterator5 = Object.keys(this._values), _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
var _ref5;
for (var _iterator7 = Object.keys(this._values), _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
var _ref7;
if (_isArray5) {
if (_i5 >= _iterator5.length) break;
_ref5 = _iterator5[_i5++];
if (_isArray7) {
if (_i7 >= _iterator7.length) break;
_ref7 = _iterator7[_i7++];
} else {
_i5 = _iterator5.next();
if (_i5.done) break;
_ref5 = _i5.value;
_i7 = _iterator7.next();
if (_i7.done) break;
_ref7 = _i7.value;
}
var key = _ref5;
var key = _ref7;

@@ -293,3 +366,3 @@ var formValue = this._values[key];

if (searchValue != null) {
searchValues.push(searchValue);
searchValues.push(searchValue.trim());
}

@@ -299,4 +372,92 @@ }

return searchValues.join(SearchValueSeparator);
return searchValues.join(SearchValueSeparator).trim();
}
}, {
key: 'mediaValues',
get: function get() {
var values = [];
for (var _iterator8 = this.all, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
var _ref8;
if (_isArray8) {
if (_i8 >= _iterator8.length) break;
_ref8 = _iterator8[_i8++];
} else {
_i8 = _iterator8.next();
if (_i8.done) break;
_ref8 = _i8.value;
}
var formValue = _ref8;
if (formValue instanceof _mediaValue2.default) {
values.push.apply(values, formValue.items);
} else if (formValue instanceof _signatureValue2.default) {
values.push(formValue);
} else if (formValue instanceof _repeatableValue2.default) {
for (var _iterator9 = formValue.items, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
var _ref9;
if (_isArray9) {
if (_i9 >= _iterator9.length) break;
_ref9 = _iterator9[_i9++];
} else {
_i9 = _iterator9.next();
if (_i9.done) break;
_ref9 = _i9.value;
}
var item = _ref9;
values.push.apply(values, item.formValues.mediaValues);
}
}
}
return values;
}
}, {
key: 'repeatableItems',
get: function get() {
var items = [];
for (var _iterator10 = this.all, _isArray10 = Array.isArray(_iterator10), _i10 = 0, _iterator10 = _isArray10 ? _iterator10 : _iterator10[Symbol.iterator]();;) {
var _ref10;
if (_isArray10) {
if (_i10 >= _iterator10.length) break;
_ref10 = _iterator10[_i10++];
} else {
_i10 = _iterator10.next();
if (_i10.done) break;
_ref10 = _i10.value;
}
var formValue = _ref10;
if (formValue instanceof _repeatableValue2.default) {
items.push.apply(items, formValue.items);
for (var _iterator11 = formValue.items, _isArray11 = Array.isArray(_iterator11), _i11 = 0, _iterator11 = _isArray11 ? _iterator11 : _iterator11[Symbol.iterator]();;) {
var _ref11;
if (_isArray11) {
if (_i11 >= _iterator11.length) break;
_ref11 = _iterator11[_i11++];
} else {
_i11 = _iterator11.next();
if (_i11.done) break;
_ref11 = _i11.value;
}
var item = _ref11;
items.push.apply(items, item.formValues.repeatableItems);
}
}
}
return items;
}
}]);

@@ -303,0 +464,0 @@

@@ -8,5 +8,6 @@ "use strict";

var MediaItemValue = function () {
function MediaItemValue(attributes) {
function MediaItemValue(mediaValue, attributes) {
_classCallCheck(this, MediaItemValue);
this.mediaValue = mediaValue;
this.caption = attributes.caption;

@@ -13,0 +14,0 @@ this.mediaID = attributes[this.mediaKey];

@@ -43,3 +43,3 @@ 'use strict';

if (items != null) {
if (Array.isArray(items)) {
for (var _iterator = items, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {

@@ -59,3 +59,3 @@ var _ref;

_this._items.push(new _this.ItemClass(item));
_this._items.push(new _this.ItemClass(_this, item));
}

@@ -67,2 +67,6 @@ }

MediaValue.prototype.toJSON = function toJSON() {
if (this.isEmpty) {
return null;
}
var items = [];

@@ -115,3 +119,3 @@

MediaValue.prototype.addItem = function addItem(id, caption) {
var item = new this.ItemClass({ caption: caption });
var item = new this.ItemClass(this, { caption: caption });

@@ -125,2 +129,16 @@ item.mediaID = id;

MediaValue.prototype.removeItem = function removeItem(id) {
for (var index = 0; index < this._items.length; ++index) {
if (this._items[index].mediaID === id) {
var item = this._items[index];
this._items.splice(index, 1);
return item;
}
}
return null;
};
_createClass(MediaValue, [{

@@ -169,3 +187,8 @@ key: 'isEmpty',

get: function get() {
if (this.isEmpty) {
return null;
}
var ids = [];
var captions = [];

@@ -187,5 +210,11 @@ for (var _iterator4 = this._items, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {

ids.push(item.mediaID);
captions.push(item.caption);
}
return ids.join(',');
var value = {};
value['f' + this.element.key + '_captions'] = captions;
value['f' + this.element.key] = ids;
return value;
}

@@ -216,2 +245,34 @@ }, {

}
}, {
key: 'hasCaptions',
get: function get() {
for (var _iterator6 = this._items, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
var _ref6;
if (_isArray6) {
if (_i6 >= _iterator6.length) break;
_ref6 = _iterator6[_i6++];
} else {
_i6 = _iterator6.next();
if (_i6.done) break;
_ref6 = _i6.value;
}
var item = _ref6;
if (_textUtils2.default.isPresent(item.caption)) {
return true;
}
}
return false;
}
// return a copy until it's determined that a mutable API is necessary
}, {
key: 'items',
get: function get() {
return this._items.slice();
}
}]);

@@ -218,0 +279,0 @@

@@ -44,5 +44,5 @@ 'use strict';

return '1 Photo';
} else {
return this.length + ' Photos';
}
return this.length + ' Photos';
}

@@ -49,0 +49,0 @@ }]);

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -7,15 +7,18 @@ exports.__esModule = true;

var _assert = require('assert');
var _assert2 = _interopRequireDefault(_assert);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var RecordLinkItemValue = function () {
function RecordLinkItemValue(attributes) {
function RecordLinkItemValue(parent, attributes) {
_classCallCheck(this, RecordLinkItemValue);
this._parent = parent;
this._recordID = attributes.record_id;
}
RecordLinkItemValue.prototype.id = function id() {
return this._recordID;
};
RecordLinkItemValue.prototype.toJSON = function toJSON() {

@@ -27,6 +30,45 @@ return {

RecordLinkItemValue.prototype.load = function load(dataSource, callback) {
var _this = this;
(0, _assert2.default)(this.parent.element.form, 'form must be present before loading the record');
dataSource.getRecord(this._recordID, this.parent.element.form, function (err, record) {
if (err) {
return callback(err);
}
_this._record = record;
return callback();
});
};
_createClass(RecordLinkItemValue, [{
key: "record",
key: 'parent',
get: function get() {
return this._parent;
}
}, {
key: 'id',
get: function get() {
return this._recordID;
}
}, {
key: 'displayValue',
get: function get() {
if (this._record) {
return this._record.displayValue;
}
return null;
}
}, {
key: 'record',
get: function get() {
return this._record;
},
set: function set(record) {
this._recordID = record;
this._record = record;
}

@@ -33,0 +75,0 @@ }]);

@@ -58,3 +58,3 @@ 'use strict';

_this._items.push(new _recordLinkItemValue2.default(item));
_this._items.push(new _recordLinkItemValue2.default(_this, item));
}

@@ -109,9 +109,43 @@ }

RecordLinkValue.prototype.addRecord = function addRecord(record) {
var item = new _recordLinkItemValue2.default({ record_id: record.id });
var item = new _recordLinkItemValue2.default(this, { record_id: record.id });
item._record = record;
this._items.push(item);
this.insertItem(item);
};
RecordLinkValue.prototype.itemIndex = function itemIndex(id) {
for (var index = 0; index < this._items.length; ++index) {
if (id === this._items[index].id) {
return index;
}
}
return -1;
};
RecordLinkValue.prototype.insertItem = function insertItem(item) {
var index = this.itemIndex(item.id);
if (index > -1) {
this._items[index] = item;
} else {
this._items.push(item);
}
};
RecordLinkValue.prototype.removeItem = function removeItem(id) {
var index = this.itemIndex(id);
if (index > -1) {
var item = this._items[index];
this._items.splice(index, 1);
return item;
}
return null;
};
_createClass(RecordLinkValue, [{

@@ -148,7 +182,6 @@ key: 'isEmpty',

get: function get() {
return null;
}
}, {
key: 'multipleValues',
get: function get() {
if (this.isEmpty) {
return null;
}
var ids = [];

@@ -170,3 +203,3 @@

ids.push(new _multipleValueItem2.default(this.element, item.recordID));
ids.push(item.id);
}

@@ -177,5 +210,29 @@

}, {
key: 'multipleValues',
get: function get() {
var ids = [];
for (var _iterator4 = this._items, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref4;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref4 = _iterator4[_i4++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref4 = _i4.value;
}
var item = _ref4;
ids.push(new _multipleValueItem2.default(this.element, item.id));
}
return ids;
}
}, {
key: 'items',
get: function get() {
return this._items;
return this._items.slice();
}

@@ -182,0 +239,0 @@ }]);

@@ -23,2 +23,6 @@ 'use strict';

var _loadObject = require('../load-object');
var _loadObject2 = _interopRequireDefault(_loadObject);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -46,12 +50,48 @@

_this._id = item.id;
_this._createdAt = _dateUtils2.default.parseTimestamp(item.created_at);
_this._updatedAt = _dateUtils2.default.parseTimestamp(item.updated_at);
_this._createdAt = _dateUtils2.default.parseEpochTimestamp(item.created_at);
_this._updatedAt = _dateUtils2.default.parseEpochTimestamp(item.updated_at);
_this._formValuesJSON = item.form_values;
_this._version = item.version || 1;
_this._changesetID = item.changeset_id;
_this._createdByID = item.created_by_id;
_this._updatedByID = item.updated_by_id;
var geometry = item.geometry;
if (geometry != null && geometry.type === 'Point') {
if (geometry != null && geometry.type === 'Point' && geometry.coordinates && geometry.coordinates.length > 1) {
_this._latitude = geometry.coordinates[1];
_this._longitude = geometry.coordinates[0];
}
_this._createdDuration = item.created_duration || null;
_this._updatedDuration = item.updated_duration || null;
_this._editedDuration = item.edited_duration || null;
var createdLocation = item.created_location;
_this._createdLatitude = null;
_this._createdLongitude = null;
_this._createdAltitude = null;
_this._createdAccuracy = null;
if (createdLocation) {
_this._createdLatitude = createdLocation.latitude;
_this._createdLongitude = createdLocation.longitude;
_this._createdAltitude = createdLocation.altitude;
_this._createdAccuracy = createdLocation.horizontal_accuracy;
}
var updatedLocation = item.updated_location;
_this._updatedLatitude = null;
_this._updatedLongitude = null;
_this._updatedAltitude = null;
_this._updatedAccuracy = null;
if (updatedLocation) {
_this._updatedLatitude = updatedLocation.latitude;
_this._updatedLongitude = updatedLocation.longitude;
_this._updatedAltitude = updatedLocation.altitude;
_this._updatedAccuracy = updatedLocation.horizontal_accuracy;
}
return _this;

@@ -63,7 +103,12 @@ }

json.id = this.identifier;
json.created_at = _dateUtils2.default.formatTimestamp(this.createdAt);
json.updated_at = _dateUtils2.default.formatTimestamp(this.updatedAt);
json.id = this.id;
json.created_at = _dateUtils2.default.formatEpochTimestamp(this.createdAt);
json.updated_at = _dateUtils2.default.formatEpochTimestamp(this.updatedAt);
json.form_values = this.formValues.toJSON();
json.geometry = this.geometryAsGeoJSON();
json.geometry = this.geometryAsGeoJSON;
json.created_location = this.createdLocation;
json.updated_location = this.updatedLocation;
json.created_duration = this.createdDuration;
json.updated_duration = this.updatedDuration;
json.edited_duration = this.editedDuration;

@@ -83,13 +128,14 @@ return json;

RepeatableItemValue.prototype.geometryAsGeoJSON = function geometryAsGeoJSON() {
if (!this.hasCoordinate) {
return null;
}
RepeatableItemValue.prototype.loadChangeset = function loadChangeset(dataSource, callback) {
return (0, _loadObject2.default)(this, dataSource, 'changeset', 'getChangeset', callback);
};
return {
type: 'Point',
coordinates: [this._longitude, this._latitude]
};
RepeatableItemValue.prototype.loadCreatedBy = function loadCreatedBy(dataSource, callback) {
return (0, _loadObject2.default)(this, dataSource, 'updatedBy', 'getUser', callback);
};
RepeatableItemValue.prototype.loadUpdatedBy = function loadUpdatedBy(dataSource, callback) {
return (0, _loadObject2.default)(this, dataSource, 'createdBy', 'getUser', callback);
};
_createClass(RepeatableItemValue, [{

@@ -109,7 +155,26 @@ key: 'element',

return this._createdAt;
},
set: function set(createdAt) {
if (createdAt != null && !(createdAt instanceof Date)) {
throw new TypeError('createdAt must be a Date');
}
this._createdAt = createdAt;
}
}, {
key: 'version',
get: function get() {
return this._version;
}
}, {
key: 'updatedAt',
get: function get() {
return this._updatedAt;
},
set: function set(updatedAt) {
if (updatedAt != null && !(updatedAt instanceof Date)) {
throw new TypeError('updatedAt must be a Date');
}
this._updatedAt = updatedAt;
}

@@ -136,12 +201,2 @@ }, {

}, {
key: 'latitude',
get: function get() {
return this._latitude;
}
}, {
key: 'longitude',
get: function get() {
return this._longitude;
}
}, {
key: 'displayValue',

@@ -179,2 +234,191 @@ get: function get() {

}
}, {
key: 'searchableValue',
get: function get() {
return this.formValues.searchableValue;
}
}, {
key: 'geometryAsGeoJSON',
get: function get() {
if (!this.hasCoordinate) {
return null;
}
return {
type: 'Point',
coordinates: [this._longitude, this._latitude]
};
}
}, {
key: 'latitude',
get: function get() {
return this._latitude;
},
set: function set(latitude) {
this._latitude = latitude;
}
}, {
key: 'longitude',
get: function get() {
return this._longitude;
},
set: function set(longitude) {
this._longitude = longitude;
}
}, {
key: 'changesetID',
get: function get() {
return this._changesetID;
}
}, {
key: 'createdByID',
get: function get() {
return this._createdByID;
}
}, {
key: 'updatedByID',
get: function get() {
return this._updatedByID;
}
}, {
key: 'changeset',
get: function get() {
return this._changeset;
}
}, {
key: 'updatedBy',
get: function get() {
return this._updatedBy;
}
}, {
key: 'createdBy',
get: function get() {
return this._createdBy;
}
}, {
key: 'createdDuration',
get: function get() {
return this._createdDuration;
},
set: function set(value) {
this._createdDuration = value != null ? +value : null;
}
}, {
key: 'updatedDuration',
get: function get() {
return this._updatedDuration;
},
set: function set(value) {
this._updatedDuration = value != null ? +value : null;
}
}, {
key: 'editedDuration',
get: function get() {
return this._editedDuration;
},
set: function set(value) {
this._editedDuration = value != null ? +value : null;
}
}, {
key: 'createdLatitude',
get: function get() {
return this._createdLatitude;
},
set: function set(value) {
this._createdLatitude = value != null ? +value : null;
}
}, {
key: 'createdLongitude',
get: function get() {
return this._createdLongitude;
},
set: function set(value) {
this._createdLongitude = value != null ? +value : null;
}
}, {
key: 'createdAltitude',
get: function get() {
return this._createdAltitude;
},
set: function set(value) {
this._createdAltitude = value != null ? +value : null;
}
}, {
key: 'createdAccuracy',
get: function get() {
return this._createdAccuracy;
},
set: function set(value) {
this._createdAccuracy = value != null ? +value : null;
}
}, {
key: 'updatedLatitude',
get: function get() {
return this._updatedLatitude;
},
set: function set(value) {
this._updatedLatitude = value != null ? +value : null;
}
}, {
key: 'updatedLongitude',
get: function get() {
return this._updatedLongitude;
},
set: function set(value) {
this._updatedLongitude = value != null ? +value : null;
}
}, {
key: 'updatedAltitude',
get: function get() {
return this._updatedAltitude;
},
set: function set(value) {
this._updatedAltitude = value != null ? +value : null;
}
}, {
key: 'updatedAccuracy',
get: function get() {
return this._updatedAccuracy;
},
set: function set(value) {
this._updatedAccuracy = value != null ? +value : null;
}
}, {
key: 'hasCreatedCoordinate',
get: function get() {
return this.createdLatitude != null && this.createdLongitude != null;
}
}, {
key: 'hasUpdatedCoordinate',
get: function get() {
return this.updatedLatitude != null && this.updatedLongitude != null;
}
}, {
key: 'createdLocation',
get: function get() {
if (this.hasCreatedCoordinate) {
return {
latitude: this.createdLatitude,
longitude: this.createdLongitude,
altitude: this.createdAltitude,
horizontal_accuracy: this.createdAccuracy
};
}
return null;
}
}, {
key: 'updatedLocation',
get: function get() {
if (this.hasUpdatedCoordinate) {
return {
latitude: this.updatedLatitude,
longitude: this.updatedLongitude,
altitude: this.updatedAltitude,
horizontal_accuracy: this.updatedAccuracy
};
}
return null;
}
}]);

@@ -181,0 +425,0 @@

@@ -117,2 +117,5 @@ 'use strict';

// return a copy until it's determined that a mutable API is necessary
RepeatableValue.prototype.forEachItem = function forEachItem(callback) {

@@ -122,2 +125,36 @@ this.mapItems(callback);

RepeatableValue.prototype.itemIndex = function itemIndex(id) {
for (var index = 0; index < this._items.length; ++index) {
if (id === this._items[index].id) {
return index;
}
}
return -1;
};
RepeatableValue.prototype.insertItem = function insertItem(item) {
var index = this.itemIndex(item.id);
if (index > -1) {
this._items[index] = item;
} else {
this._items.push(item);
}
};
RepeatableValue.prototype.removeItem = function removeItem(id) {
var index = this.itemIndex(id);
if (index > -1) {
var item = this._items[index];
this._items.splice(index, 1);
return item;
}
return null;
};
RepeatableValue.prototype.createNewItem = function createNewItem() {

@@ -129,7 +166,3 @@ var attributes = {

var item = new _repeatableItemValue2.default(this.element, attributes, this._items.length);
this._items.push(item);
return item;
return new _repeatableItemValue2.default(this.element, attributes, this._items.length);
};

@@ -147,5 +180,5 @@

return '1 Item';
} else {
return this.length + ' Items';
}
return this.length + ' Items';
}

@@ -199,2 +232,7 @@ }, {

}
}, {
key: 'items',
get: function get() {
return this._items.slice();
}
}]);

@@ -201,0 +239,0 @@

@@ -11,2 +11,6 @@ 'use strict';

var _dateUtils = require('../utils/date-utils');
var _dateUtils2 = _interopRequireDefault(_dateUtils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -32,3 +36,3 @@

_this._identifier = attributes.signature_id;
_this._timestamp = attributes.timestamp;
_this._timestamp = _dateUtils2.default.parseISOTimestamp(attributes.timestamp);
}

@@ -38,6 +42,15 @@ return _this;

SignatureValue.prototype.clear = function clear() {
this._identifier = null;
this._timestamp = null;
};
SignatureValue.prototype.toJSON = function toJSON() {
if (this.isEmpty) {
return null;
}
return {
signature_id: this._identifier,
timestamp: this._timestamp
timestamp: _dateUtils2.default.formatISOTimestamp(this._timestamp)
};

@@ -67,5 +80,25 @@ };

_createClass(SignatureValue, [{
key: 'id',
get: function get() {
return this._identifier;
},
set: function set(id) {
this._identifier = id;
}
}, {
key: 'timestamp',
get: function get() {
return this._timestamp;
},
set: function set(timestamp) {
if (!(timestamp instanceof Date)) {
throw new TypeError('timestamp must be a Date');
}
this._timestamp = timestamp;
}
}, {
key: 'isEmpty',
get: function get() {
return false;
return this._identifier == null;
}

@@ -75,3 +108,3 @@ }, {

get: function get() {
return '1 Signature';
return this.isEmpty ? null : '1 Signature';
}

@@ -86,3 +119,3 @@ }, {

get: function get() {
return 1;
return this.isEmpty ? 0 : 1;
}

@@ -92,3 +125,12 @@ }, {

get: function get() {
return this._identifier;
if (this.isEmpty) {
return null;
}
var value = {};
value['f' + this.element.key + '_timestamp'] = this.timestamp;
value['f' + this.element.key] = this._identifier;
return value;
}

@@ -95,0 +137,0 @@ }, {

@@ -5,2 +5,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 _textualValue = require('./textual-value');

@@ -29,2 +31,16 @@

_createClass(StatusValue, [{
key: 'displayValue',
get: function get() {
var choice = this.element.statusForValue(this.textValue);
return choice ? choice.label : this.textValue || '';
}
}, {
key: 'searchableValue',
get: function get() {
return this.displayValue;
}
}]);
return StatusValue;

@@ -31,0 +47,0 @@ }(_textualValue2.default);

@@ -33,3 +33,3 @@ 'use strict';

get: function get() {
if (this.element.numeric) {
if (this.element.isNumeric) {
return this.numericValue;

@@ -36,0 +36,0 @@ }

@@ -37,3 +37,3 @@ 'use strict';

_this.textValue = textValue;
_this.textValue = textValue != null ? textValue.toString() : null;
return _this;

@@ -55,5 +55,5 @@ }

stringValue = stringValue == null ? '' : stringValue.toString();
var string = stringValue == null ? '' : stringValue.toString();
return this.textValue.toLowerCase() === stringValue.toLowerCase();
return this.textValue.toLowerCase() === string.toLowerCase();
};

@@ -70,5 +70,5 @@

stringValue = stringValue.toString();
var string = stringValue.toString();
return _textUtils2.default.contains(this.textValue, stringValue);
return _textUtils2.default.contains(this.textValue, string);
};

@@ -85,5 +85,3 @@

stringValue = stringValue.toString();
return _textUtils2.default.startsWith(this.textValue, stringValue);
return _textUtils2.default.startsWith(this.textValue, stringValue.toString());
};

@@ -96,9 +94,15 @@

var string = null;
if (stringValue != null) {
stringValue = stringValue.toString();
string = stringValue.toString();
}
var thisValue = _numberUtils2.default.parseDouble(this.textValue);
var thatValue = _numberUtils2.default.parseDouble(stringValue);
var thatValue = _numberUtils2.default.parseDouble(string);
if (thisValue == null || thatValue == null) {
return false;
}
return thisValue < thatValue;

@@ -112,7 +116,11 @@ };

stringValue = stringValue == null ? '' : stringValue.toString();
var string = stringValue == null ? '' : stringValue.toString();
var thisValue = _numberUtils2.default.parseDouble(this.textValue);
var thatValue = _numberUtils2.default.parseDouble(stringValue);
var thatValue = _numberUtils2.default.parseDouble(string);
if (thisValue == null || thatValue == null) {
return false;
}
return thisValue > thatValue;

@@ -124,3 +132,3 @@ };

get: function get() {
return _textUtils2.default.isEmpty(this.textValue);
return this.textValue == null || this.textValue.length === 0;
}

@@ -135,3 +143,3 @@ }, {

get: function get() {
return this.textValue || '';
return this.displayValue || '';
}

@@ -162,2 +170,13 @@ }, {

}
}, {
key: 'isNumeric',
get: function get() {
if (!this.isEmpty) {
var number = _numberUtils2.default.parseDouble(this.textValue);
return number != null;
}
return true;
}
}]);

@@ -164,0 +183,0 @@

@@ -43,3 +43,3 @@ 'use strict';

var thisTime = this.timeValue();
var thisTime = this.timeValue;
var thatTime = _dateUtils2.default.parseTime(stringValue);

@@ -51,3 +51,3 @@

return thisTime.getTime() < thatTime.getTime();
return thisTime < thatTime;
};

@@ -60,3 +60,3 @@

var thisTime = this.timeValue();
var thisTime = this.timeValue;
var thatTime = _dateUtils2.default.parseTime(stringValue);

@@ -68,28 +68,41 @@

return thisTime.getTime() > thatTime.getTime();
return thisTime > thatTime;
};
TimeValue.prototype.timeValue = function timeValue() {
return _dateUtils2.default.parseTime(this.textValue);
};
_createClass(TimeValue, [{
key: 'displayValue',
get: function get() {
return this.textValue;
}
}, {
key: 'searchableValue',
get: function get() {
return this.textValue;
}
}, {
key: 'isValid',
get: function get() {
if (this.isEmpty) {
return null;
return true;
}
var time = this.timeValue();
if (time == null) {
return _dateUtils2.default.isValidTime(this.textValue);
}
}, {
key: 'timeValue',
get: function get() {
if (this.isEmpty) {
return null;
}
return time;
return _dateUtils2.default.parseTime(this.textValue);
}
}, {
key: 'searchableValue',
key: 'columnValue',
get: function get() {
return this.textValue;
if (!this.isValid) {
return null;
}
return this.textValue || null;
}

@@ -96,0 +109,0 @@ }]);

@@ -44,5 +44,5 @@ 'use strict';

return '1 Video';
} else {
return this.length + ' Videos';
}
return this.length + ' Videos';
}

@@ -49,0 +49,0 @@ }]);

{
"name": "fulcrum-core",
"version": "0.0.15",
"version": "0.6.2",
"description": "Fulcrum Core",

@@ -11,6 +11,8 @@ "homepage": "http://github.com/fulcrumapp/fulcrum-core",

"prepublish": "npm run lint && npm run clean && npm run build",
"lint": "node_modules/.bin/eslint src",
"lint": "node_modules/.bin/eslint src/* src/**/*",
"build": "node_modules/.bin/babel src --out-dir dist --source-maps",
"watch": "node_modules/.bin/babel src --out-dir dist --source-maps --watch",
"clean": "rm -rf dist"
"clean": "rm -rf dist",
"check-deps": "node_modules/.bin/ncu",
"update-deps": "node_modules/.bin/ncu -u"
},

@@ -23,22 +25,34 @@ "author": "Zac McCormick <zac.mccormick@gmail.com> (http://github.com/zhm)",

},
"eslintConfig": {
"extends": "fulcrum"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-core": "^6.5.2",
"babel-eslint": "^5.0.0",
"babel-cli": "^6.7.7",
"babel-core": "^6.7.7",
"babel-eslint": "^6.0.4",
"babel-plugin-transform-proto-to-assign": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-es2015-node5": "^1.1.2",
"babel-preset-stage-3": "^6.5.0",
"babel-preset-es2015-node5": "^1.2.0",
"babel-preset-stage-1": "^6.5.0",
"chai": "^3.5.0",
"eslint": "~2.2.0",
"eslint": "^2.9.0",
"eslint-config-fulcrum": "^1.0.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-react": "^5.0.1",
"mocha": "^2.4.5",
"should": "^8.2.2",
"npm-check-updates": "^2.6.3",
"should": "^8.3.1",
"source-map-support": "^0.4.0"
},
"dependencies": {
"async": "^1.5.2",
"lodash": "^4.6.1",
"async": "^2.0.0-rc.3",
"lodash.compact": "^3.0.1",
"lodash.includes": "^4.1.3",
"lodash.padstart": "^4.5.0",
"lodash.startswith": "^4.1.0",
"lodash.trim": "^4.4.0",
"mixmatch": "0.0.2",
"uuid": "^2.0.1"
"relative-date": "^1.1.3",
"uuid": "^2.0.2"
},

@@ -45,0 +59,0 @@ "keywords": [

@@ -5,15 +5,37 @@ import Choice from './elements/choice';

constructor(attributes) {
attributes = attributes || {};
this.updateFromAPIAttributes(attributes);
}
this.id = attributes.id;
this.name = attributes.name;
this.description = attributes.description;
this.choices = [];
updateFromAPIAttributes(attrs) {
const attributes = attrs || {};
if (attributes.choices) {
for (let choice of attributes.choices) {
this.choices.push(new Choice(choice));
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
this._choicesJSON = attributes.choices || [];
}
get id() {
return this._id;
}
get name() {
return this._name;
}
get description() {
return this._description;
}
get choices() {
if (!this._choices) {
this._choices = [];
for (const choice of this._choicesJSON) {
this._choices.push(new Choice(choice));
}
}
return this._choices;
}
}

@@ -5,15 +5,37 @@ import Classification from './elements/classification';

constructor(attributes) {
attributes = attributes || {};
this.updateFromAPIAttributes(attributes);
}
this.id = attributes.id;
this.name = attributes.name;
this.description = attributes.description;
this.items = [];
updateFromAPIAttributes(attrs) {
const attributes = attrs || {};
if (attributes.items) {
for (let item of attributes.items) {
this.items.push(new Classification(null, item));
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
this._itemsJSON = attributes.items || [];
}
get id() {
return this._id;
}
get name() {
return this._name;
}
get description() {
return this._description;
}
get items() {
if (!this._items) {
this._items = [];
for (const item of this._itemsJSON) {
this._items.push(new Classification(null, item));
}
}
return this._items;
}
}

@@ -42,2 +42,4 @@ /*

import async from 'async';
function noop(...params) {

@@ -52,2 +54,6 @@ params[params.length - 1]();

get source() {
return this.sources[this.sources.length - 1];
}
invoke(dataSource, method, params, callback) {

@@ -66,3 +72,3 @@ const invokeCallback = (err, ...objects) => {

const invokeArguments = params.concat([invokeCallback]);
const invokeArguments = params.concat([ invokeCallback ]);

@@ -74,3 +80,3 @@ (dataSource[method] || noop).apply(dataSource, invokeArguments);

if (dataSource == null) {
return callback.apply(null, [null].concat(objects));
return callback.apply(null, [ null ].concat(objects));
}

@@ -85,8 +91,8 @@

return this.process(dataSource.previous, method, params, objects, callback);
} else {
return callback.apply(null, [null].concat(objects));
}
return callback.apply(null, [ null ].concat(objects));
};
const processArguments = params.concat(objects.concat([processCallback]));
const processArguments = params.concat(objects.concat([ processCallback ]));

@@ -109,2 +115,46 @@ (dataSource[processMethod] || noop).apply(dataSource, processArguments);

prepare(formID, callback) {
const result = {};
const tasks = {
form: (callback) => {
this.getForm(formID, (err, form) => {
if (err) {
callback(err);
return;
}
result.form = form;
result.form.load(this, callback);
});
},
users: (callback) => {
this.getUsers(null, (err, users) => {
if (err) {
callback(err);
return;
}
result.users = users;
callback(err);
});
},
projects: (callback) => {
this.getProjects(null, (err, projects) => {
if (err) {
callback(err);
return;
}
result.projects = projects;
callback(err);
});
}
};
async.parallel(tasks, (err) => callback(err, result));
}
get root() {

@@ -115,28 +165,92 @@ return this.sources[0];

getChoiceList(id, callback) {
this.invoke(this.root, 'getChoiceList', [id], callback);
this.invoke(this.root, 'getChoiceList', [ id ], callback);
}
getClassificationSet(id, callback) {
this.invoke(this.root, 'getClassificationSet', [id], callback);
this.invoke(this.root, 'getClassificationSet', [ id ], callback);
}
getForm(id, callback) {
this.invoke(this.root, 'getForm', [id], callback);
this.invoke(this.root, 'getForm', [ id ], callback);
}
getRecord(id, callback) {
this.invoke(this.root, 'getRecord', [id], callback);
getUser(id, callback) {
this.invoke(this.root, 'getUser', [ id ], callback);
}
getRecord(id, form, callback) {
this.invoke(this.root, 'getRecord', [ id, form ], callback);
}
getRecords(form, params, callback) {
this.invoke(this.root, 'getRecords', [form, params], callback);
this.invoke(this.root, 'getRecords', [ form, params ], callback);
}
queryRecords(form, params, callback) {
this.invoke(this.root, 'queryRecords', [ form, params ], callback);
}
getUsers(params, callback) {
this.invoke(this.root, 'getUsers', [params], callback);
this.invoke(this.root, 'getUsers', [ params ], callback);
}
getProjects(params, callback) {
this.invoke(this.root, 'getProjects', [params], callback);
this.invoke(this.root, 'getProjects', [ params ], callback);
}
getChangeset(id, callback) {
this.invoke(this.root, 'getChangeset', [ id ], callback);
}
getPhoto(id, callback) {
this.invoke(this.root, 'getPhoto', [ id ], callback);
}
getAudio(id, callback) {
this.invoke(this.root, 'getAudio', [ id ], callback);
}
getAudioTrack(id, callback) {
this.invoke(this.root, 'getAudioTrack', [ id ], callback);
}
getVideo(id, callback) {
this.invoke(this.root, 'getVideo', [ id ], callback);
}
getVideoTrack(id, callback) {
this.invoke(this.root, 'getVideoTrack', [ id ], callback);
}
createPhoto(accessKey, file, progress, callback) {
this.invoke(this.root, 'createPhoto', [ accessKey, file, progress ], callback);
}
createVideo(accessKey, file, progress, callback) {
this.invoke(this.root, 'createVideo', [ accessKey, file, progress ], callback);
}
createAudio(accessKey, file, progress, callback) {
this.invoke(this.root, 'createAudio', [ accessKey, file, progress ], callback);
}
createSignature(accessKey, file, progress, callback) {
this.invoke(this.root, 'createSignature', [ accessKey, file, progress ], callback);
}
saveVideoTrack(accessKey, file, progress, callback) {
this.invoke(this.root, 'saveVideoTrack', [ accessKey, file, progress ], callback);
}
saveAudioTrack(accessKey, file, progress, callback) {
this.invoke(this.root, 'saveAudioTrack', [ accessKey, file, progress ], callback);
}
saveRecord(record, callback) {
this.invoke(this.root, 'saveRecord', [ record ], callback);
}
deleteRecord(record, callback) {
this.invoke(this.root, 'deleteRecord', [ record ], callback);
}
}

@@ -1,4 +0,4 @@

import TextualElement from './element';
import TextualElement from './textual-element';
export default class BarcodeElement extends TextualElement {
}

@@ -26,3 +26,3 @@ import TextualElement from './textual-element';

for (let element of container.elements) {
for (const element of container.elements) {
if (element.isCalculatedElement) {

@@ -29,0 +29,0 @@ elements.push(element);

import Mixin from 'mixmatch';
import ElementFactory from './element-factory';
let ElementFactory = null;
export default class ChildElements extends Mixin {
get elements() {
if (!this._elements) {
this.createChildElements(this._elementsJSON);
}
export default class ChildElements extends Mixin {
return this._elements;
}
createChildElements(elements) {
this.elements = [];
this._elements = [];
for (let element of elements) {
// hack for circular dependency, not ideal
ElementFactory = ElementFactory || require('./element-factory').default;
this.elements.push(ElementFactory.create(this, element));
if (elements) {
for (const element of elements) {
const el = ElementFactory.create(this, element);
if (el) {
this._elements.push(el);
}
}
}

@@ -51,3 +62,3 @@ }

for (let element of elements) {
for (const element of elements) {
flat.push(element);

@@ -66,3 +77,3 @@

for (let element of elements) {
for (const element of elements) {
flat[element[attr]] = element;

@@ -73,3 +84,3 @@

for (let key of Object.keys(children)) {
for (const key of Object.keys(children)) {
flat[key] = children[key];

@@ -76,0 +87,0 @@ }

@@ -10,5 +10,6 @@ import Element from './element';

this.allowOther = !!attributes.allow_other;
this.choiceFilter = null;
this.overrideChoices = null;
this._choiceFilter = null;
this._overrideChoices = null;
this._choiceListID = attributes.choice_list_id;

@@ -19,3 +20,3 @@ this._choices = [];

if (attributes.choices) {
for (let choice of this.attributes.choices) {
for (const choice of attributes.choices) {
this._choices.push(new Choice(choice));

@@ -31,2 +32,5 @@ }

dataSource.getChoiceList(this._choiceListID, (err, choiceList) => {
// TODO(zhm) Some forms have orphaned choice lists (life sucks)
// Maybe we should add a parameter to the load() method to throw
// errors.
if (err) {

@@ -54,2 +58,10 @@ return callback(err);

get choiceFilter() {
return this._choiceFilter;
}
set choiceFilter(choiceFilter) {
this._choiceFilter = choiceFilter;
}
get filteredChoices() {

@@ -64,4 +76,4 @@ const items = this._choices;

for (let item of items) {
for (let filter of this.choiceFilter) {
for (const item of items) {
for (const filter of this.choiceFilter) {
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {

@@ -90,3 +102,3 @@ filteredItems.push(item);

for (let choiceAttributes of overrideChoices) {
for (const choiceAttributes of overrideChoices) {
const choice = new Choice(choiceAttributes);

@@ -100,2 +112,16 @@

get overrideValues() {
return Object.assign(Object.getOwnPropertyDescriptor(Element.prototype, 'overrideValues').get.call(this), {
choiceFilter: this._choiceFilter,
overrideChoices: this._overrideChoices
});
}
resetOverrides() {
super.resetOverrides();
this._choiceFilter = null;
this._overrideChoices = null;
}
choiceByValue(value) {

@@ -105,3 +131,3 @@ if (!this._choicesByValue) {

for (let choice of this.choices) {
for (const choice of this.choices) {
this._choicesByValue[choice.value] = choice;

@@ -108,0 +134,0 @@ }

@@ -8,5 +8,6 @@ import Element from './element';

this.allowOther = !!attributes.allowOther;
this.choiceFilter = null;
this.allowOther = !!attributes.allow_other;
this._choiceFilter = null;
this._overrideClassificationItems = null;

@@ -19,2 +20,5 @@

dataSource.getClassificationSet(this._classificationSetID, (err, classificationSet) => {
// TODO(zhm) Some forms have orphaned classification sets (life sucks)
// Maybe we should add a parameter to the load() method to throw
// errors.
if (err) {

@@ -34,2 +38,10 @@ return callback(err);

get choiceFilter() {
return this._choiceFilter;
}
set choiceFilter(choiceFilter) {
this._choiceFilter = choiceFilter;
}
set overrideClassificationItems(overrideClassificationSetItems) {

@@ -43,3 +55,3 @@ if (!overrideClassificationSetItems || overrideClassificationSetItems.length < 1) {

for (let classificationAttributes of overrideClassificationSetItems) {
for (const classificationAttributes of overrideClassificationSetItems) {
const classification = new Classification(null, classificationAttributes);

@@ -53,3 +65,21 @@

get overrideValues() {
return Object.assign(Object.getOwnPropertyDescriptor(Element.prototype, 'overrideValues').get.call(this), {
choiceFilter: this._choiceFilter,
overrideClassificationItems: this._overrideClassificationItems
});
}
resetOverrides() {
super.resetOverrides();
this._choiceFilter = null;
this._overrideClassificationItems = null;
}
get filteredClassifications() {
if (!this.classificationSet) {
return [];
}
const items = this.classificationSet.items;

@@ -63,6 +93,8 @@

for (let item of items) {
for (let filter of this.classificationFilter) {
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {
filteredItems.push(item);
if (items) {
for (const item of items) {
for (const filter of this.classificationFilter) {
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {
filteredItems.push(item);
}
}

@@ -69,0 +101,0 @@ }

@@ -6,7 +6,7 @@ export default class Classification {

this.value = attributes.value || attributes.label;
this.children = [];
this._items = [];
if (attributes.child_classifications) {
for (let child of attributes.child_classifications) {
this.children.push(new Classification(this, child));
for (const child of attributes.child_classifications) {
this._items.push(new Classification(this, child));
}

@@ -16,2 +16,6 @@ }

get items() {
return this._items.slice();
}
get exploded() {

@@ -21,3 +25,5 @@ // return an array of all classifications including all parent items

/* eslint-disable consistent-this */
let iterator = this;
/* eslint-enable consistent-this */

@@ -39,3 +45,3 @@ while (iterator && iterator.parent) {

for (let item of this.exploded) {
for (const item of this.exploded) {
if (item.value) {

@@ -42,0 +48,0 @@ values.push(item.value);

@@ -19,3 +19,3 @@ import TextUtils from '../utils/text-utils';

static isEmpty(formValue) {
return formValue === null || formValue.isEmpty();
return formValue == null || formValue.isEmpty;
}

@@ -51,8 +51,8 @@

static shouldElementBeVisible(element, record, values, cache) {
if (cache != null && cache[element.key] != null) {
return cache[element.key];
static shouldElementBeVisible(element, record, values, visibilityCache) {
if (visibilityCache != null && visibilityCache[element.key] != null) {
return visibilityCache[element.key];
}
cache = cache || {};
const cache = visibilityCache || {};

@@ -64,3 +64,3 @@ let shouldBeVisible = Condition.shouldElementBeVisibleRecursive(element, record, values, cache);

for (let childElement of element.elements) {
for (const childElement of element.elements) {
const visible = Condition.shouldElementBeVisibleRecursive(childElement, record, values, cache);

@@ -90,3 +90,3 @@

if (element.hidden || element.hasHiddenParent) {
if (element.isHidden || element.hasHiddenParent) {
cache[element.key] = false;

@@ -103,3 +103,3 @@ return false;

if (element.visibleConditionsType === 'any') {
for (let condition of element.visibleConditions) {
for (const condition of element.visibleConditions) {
const isSatisfied = condition.isSatisfied(record, values, cache);

@@ -115,3 +115,3 @@

for (let condition of element.visibleConditions) {
for (const condition of element.visibleConditions) {
const isSatisfied = condition.isSatisfied(record, values, cache);

@@ -156,3 +156,3 @@

if (!element.hasRequiredConditions) {
return element.required;
return element.isRequired;
}

@@ -165,3 +165,3 @@

if (element.requiredConditionsType === 'any') {
for (let condition of element.requiredConditions) {
for (const condition of element.requiredConditions) {
const isSatisfied = condition.isSatisfied(record, values, cache);

@@ -177,3 +177,3 @@

for (let condition of element.requiredConditions) {
for (const condition of element.requiredConditions) {
const isSatisfied = condition.isSatisfied(record, values, cache);

@@ -193,3 +193,3 @@

if (condition.fieldKey === '@status') {
return record.statusValue();
return record.statusValue;
}

@@ -201,3 +201,3 @@ return values.get(condition.fieldKey);

if (condition.fieldKey === '@status') {
return record.statusValue().statusElement;
return record.statusValue.element;
}

@@ -217,3 +217,3 @@ return record.form.elementsByKey[condition.fieldKey];

const skipElement = referencedElement.hidden || referencedElement.hasHiddenParent;
const skipElement = referencedElement.isHidden || referencedElement.hasHiddenParent;

@@ -260,6 +260,6 @@ if (!skipElement) {

case 'greater_than':
return Condition.greaterThan(formValue, this.value);
return Condition.isGreaterThan(formValue, this.value);
case 'less_than':
return Condition.lessThan(formValue, this.value);
return Condition.isLessThan(formValue, this.value);

@@ -266,0 +266,0 @@ default:

@@ -10,4 +10,18 @@ import Element from './element';

}
resetOverrides() {
super.resetOverrides();
for (const element of this.elements) {
element.resetOverrides();
}
}
static initialize() {
// this is a bit of a hack to get around circular dependencies. This gets
// called once from within the factory to setup the class. Putting this
// at global scope introduces circular dependency errors because ChildElements
// ends up loading the factory.
ChildElements.includeInto(ContainerElement);
}
}
ChildElements.includeInto(ContainerElement);

@@ -1,2 +0,2 @@

import Section from './section-element';
import SectionElement from './section-element';
import ChoiceElement from './choice-element';

@@ -19,5 +19,6 @@ import TextElement from './text-element';

import RecordLinkElement from './record-link-element';
import ContainerElement from './container-element';
const Constructors = {
Section: Section,
Section: SectionElement,
ChoiceField: ChoiceElement,

@@ -43,2 +44,4 @@ TextField: TextElement,

let initialized = false;
export default class ElementFactory {

@@ -48,4 +51,9 @@ static create(parent, attributes) {

if (!initialized) {
initialized = true;
ContainerElement.initialize();
}
if (constructor == null) {
throw new Error('Unsupported element ' + attributes.type);
return null;
}

@@ -60,1 +68,2 @@

}

@@ -36,3 +36,5 @@ export default {

RecordLinkElement: 'RecordLinkField'
RecordLinkElement: 'RecordLinkField',
StatusElement: 'StatusField'
};
import Types from './element-types';
import Condition from './condition';
let ElementFactory = null;
export default class Element {
constructor(parent, attributes) {
this.parent = parent;
this._parent = parent;
this.attributes = attributes;
this._attributes = attributes;
this.key = attributes.key;
this._key = attributes.key;
this.type = attributes.type;
this._type = attributes.type;
this.label = attributes.label;
this._label = attributes.label;
this.description = attributes.description;
this._description = attributes.description;
this.dataName = attributes.data_name;
this._dataName = attributes.data_name;
this.defaultValue = attributes.default_value;
this._defaultValue = attributes.default_value;
this.required = !!attributes.required;
this._isRequired = !!attributes.required;
this.hidden = !!attributes.hidden;
this._isHidden = !!attributes.hidden;
this.disabled = !!attributes.disabled;
this._isDisabled = !!attributes.disabled;
this.visibleConditionsType = this.attributes.visible_conditions_type;
this._visibleConditionsType = attributes.visible_conditions_type;
this.visibleConditions = [];
this._visibleConditions = [];
if (attributes.visible_conditions) {
for (let condition of attributes.visible_conditions) {
this.visibleConditions.push(new Condition(this, condition));
for (const condition of attributes.visible_conditions) {
this._visibleConditions.push(new Condition(this, condition));
}
}
this.requiredConditionsType = this.attributes.required_conditions_type;
this._requiredConditionsType = attributes.required_conditions_type;
this.requiredConditions = [];
this._requiredConditions = [];
if (attributes.required_conditions) {
for (let condition of attributes.required_conditions) {
this.requiredConditions.push(new Condition(this, condition));
for (const condition of attributes.required_conditions) {
this._requiredConditions.push(new Condition(this, condition));
}
}
this.minLength = -1;
this.maxLength = -1;
this._minLength = -1;
this._maxLength = -1;
if (attributes.min_length != null) {
this.minLength = +attributes.min_length;
this._minLength = +attributes.min_length;
}
if (attributes.max_length != null) {
this.maxLength = +attributes.max_length;
this._maxLength = +attributes.max_length;
}
this._overrideLabel = null;
this._overrideDescription = null;
this._overrideIsRequired = null;
this._overrideIsHidden = null;
this._overrideIsDisabled = null;
this._overrideMinLength = null;
this._overrideMaxLength = null;
}
static factory() {
return (ElementFactory = ElementFactory || require('./element-factory').default);
get parent() {
return this._parent;
}
static create(parent, attributes) {
return Element.factory().create(parent, attributes);
get type() {
return this._type;
}
static classes() {
if (Element._classes == null) {
Element._classes = {};
get key() {
return this._key;
}
for (let klass of Object.keys(Types)) {
Element._classes[klass] = Element.factory().classes()[Types[klass]];
}
}
get label() {
return this._overrideLabel != null ? this._overrideLabel : this._label;
}
return Element._classes;
get description() {
return this._overrideDescription != null ? this._overrideDescription : this._description;
}
get dataName() {
return this._dataName;
}
get defaultValue() {
return this._defaultValue;
}
get isRequired() {
return this._overrideIsRequired != null ? this._overrideIsRequired : this._isRequired;
}
get isHidden() {
return this._overrideIsHidden != null ? this._overrideIsHidden : this._isHidden;
}
get isDisabled() {
return this._overrideIsDisabled != null ? this._overrideIsDisabled : this._isDisabled;
}
get visibleConditionsType() {
return this._visibleConditionsType;
}
get visibleConditions() {
return this._visibleConditions;
}
get requiredConditionsType() {
return this._requiredConditionsType;
}
get requiredConditions() {
return this._requiredConditions;
}
get minLength() {
return this._overrideMinLength != null ? this._overrideMinLength : this._minLength;
}
get maxLength() {
return this._overrideMaxLength != null ? this._overrideMinLength : this._maxLength;
}
get overrideLabel() {
return this._overrideLabel;
}
set overrideLabel(value) {
this._overrideLabel = value;
}
get overrideDescription() {
return this._overrideDescription;
}
set overrideDescription(value) {
this._overrideDescription = value;
}
get overrideIsRequired() {
return this._overrideIsRequired;
}
set overrideIsRequired(value) {
this._overrideIsRequired = value != null ? !!value : null;
}
get overrideIsHidden() {
return this._overrideIsHidden;
}
set overrideIsHidden(value) {
this._overrideIsHidden = value != null ? !!value : null;
}
get overrideIsDisabled() {
return this._overrideIsDisabled;
}
set overrideIsDisabled(value) {
this._overrideIsDisabled = value != null ? !!value : null;
}
get overrideMinLength() {
return this._overrideMinLength;
}
set overrideMinLength(value) {
this._overrideMinLength = value != null ? +value : null;
}
get overrideMaxLength() {
return this._overrideMaxLength;
}
set overrideMaxLength(value) {
this._overrideMaxLength = value != null ? +value : null;
}
get overrideValues() {
return {
overrideLabel: this._overrideLabel,
overrideDescription: this._overrideDescription,
overrideIsRequired: this._overrideIsRequired,
overrideIsHidden: this._overrideIsHidden,
overrideIsDisabled: this._overrideIsDisabled,
overrideMinLength: this._overrideMinLength,
overrideMaxLength: this._overrideMaxLength
};
}
resetOverrides() {
this._overrideLabel = null;
this._overrideDescription = null;
this._overrideIsRequired = null;
this._overrideIsHidden = null;
this._overrideIsDisabled = null;
this._overrideMinLength = null;
this._overrideMaxLength = null;
}
get isLengthValidationSupported() {

@@ -103,4 +231,4 @@ return false;

get hasHiddenParent() {
if (this.parent == null || this.hidden) {
return this.hidden;
if (this.parent == null || this.isHidden) {
return this.isHidden;
}

@@ -185,2 +313,6 @@ return this.parent.hasHiddenParent;

}
get isStatusElement() {
return this.isType(Types.StatusElement);
}
}
import Element from './element';
export default class MediaElement extends Element {
get isLengthValidationSupported() {
return true;
}
set overrideMediaGalleryEnabled(override) {
this._overrideMediaGalleryEnabled = override;
}
get overrideMediaGalleryEnabled() {
return this._overrideMediaGalleryEnabled;
}
get overrideValues() {
return Object.assign(Object.getOwnPropertyDescriptor(Element.prototype, 'overrideValues').get.call(this), {
overrideMediaGalleryEnabled: this._overrideMediaGalleryEnabled
});
}
resetOverrides() {
super.resetOverrides();
this._overrideMediaGalleryEnabled = null;
}
}

@@ -39,8 +39,9 @@ import Element from './element';

if (err) {
return callback(err);
callback(err);
return;
}
// recursively load the linked forms
this.form = form;
return callback();
this.form.load(dataSource, callback);
});

@@ -47,0 +48,0 @@ }

@@ -7,8 +7,20 @@ import ContainerElement from './container-element';

this.titleFieldKeys = attributes.title_field_keys;
this.titleFieldKeys = attributes.title_field_keys || [ attributes.title_field_key ];
this.geometryTypes = attributes.geometry_types;
this._geometryTypes = attributes.geometry_types;
this.geometryRequired = !!attributes.geometry_required;
this._geometryRequired = !!attributes.geometry_required;
}
get isGeometryEnabled() {
return this._geometryTypes && this._geometryTypes.length > 0;
}
get isGeometryRequired() {
return this.isGeometryEnabled && this._geometryRequired;
}
get isLengthValidationSupported() {
return true;
}
}
import TextualElement from './textual-element';
import StatusChoice from './status-choice';
import Element from './element';
const DEFAULT_STATUS_ELEMENT = {
label: 'Status',
key: '@status',
data_name: 'status',
enabled: false,
read_only: false,
choices: []
};
export default class StatusElement extends TextualElement {
constructor(parent, attributes) {
super(parent, attributes);
attributes.type = 'StatusField';
this.choices = [];
const attrs = Object.assign({}, DEFAULT_STATUS_ELEMENT, attributes);
for (const choice of attributes.choices) {
this.choices.push(new StatusChoice(choice));
super(parent, attrs);
this._statusFilter = null;
this._choices = [];
if (attrs.choices) {
for (const choice of attrs.choices) {
this._choices.push(new StatusChoice(choice));
}
}
this._enabled = !!attributes.enabled;
this._readOnly = !!attributes.read_only;
this._enabled = !!attrs.enabled;
this._readOnly = !!attrs.read_only;
}
get choices() {
return this.filteredChoices;
}
get isEnabled() {

@@ -23,5 +45,13 @@ return this._enabled;

get isReadOnly() {
return this._readOnly;
return this._overrideIsDisabled != null ? this._overrideIsDisabled : this._readOnly;
}
get statusFilter() {
return this._statusFilter;
}
set statusFilter(statusFilter) {
this._statusFilter = statusFilter;
}
statusForValue(value) {

@@ -36,2 +66,34 @@ for (const choice of this.choices) {

}
get filteredChoices() {
const items = this._choices;
if (!this.statusFilter) {
return items;
}
const filteredItems = [];
for (const item of items) {
for (const filter of this.statusFilter) {
if (item.value.toLowerCase().indexOf(filter.toLowerCase()) !== -1) {
filteredItems.push(item);
}
}
}
return filteredItems;
}
get overrideValues() {
return Object.assign(Object.getOwnPropertyDescriptor(Element.prototype, 'overrideValues').get.call(this), {
statusFilter: this._statusFilter
});
}
resetOverrides() {
super.resetOverrides();
this._statusFilter = null;
}
}

@@ -7,3 +7,3 @@ import TextualElement from './textual-element';

this.numeric = !!attributes.numeric;
this._isNumeric = !!attributes.numeric;

@@ -41,9 +41,13 @@ this.format = attributes.format;

get isDecimalFormat() {
return this.numeric && this.format === 'decimal';
return this._isNumeric && this.format === 'decimal';
}
get isIntegerFormat() {
return this.numeric && this.format === 'integer';
return this._isNumeric && this.format === 'integer';
}
get isNumeric() {
return this._isNumeric;
}
get hasMin() {

@@ -50,0 +54,0 @@ return this.min != null;

@@ -11,2 +11,1 @@ import MediaElement from './media-element';

}

@@ -34,2 +34,6 @@ const notImplemented = () => {

get searchableValue() {
notImplemented();
}
toJSON() {

@@ -42,2 +46,22 @@ notImplemented();

}
get createdDuration() {
notImplemented();
}
get updatedDuration() {
notImplemented();
}
get editedDuration() {
notImplemented();
}
get hasCreatedCoordinate() {
notImplemented();
}
get hasUpdatedCoordinate() {
notImplemented();
}
}

@@ -9,17 +9,42 @@ import ChildElements from './elements/child-elements';

constructor(attributes) {
// TODO(zhm) remove json attr
this._json = attributes;
// TODO(zhm) this might need to go away
this.titleFieldKeys = attributes.title_field_keys;
this.script = attributes.script;
this.createChildElements(attributes.elements);
this.updateFromAPIAttributes(attributes);
}
updateFromAPIAttributes(attrs) {
const attributes = attrs || {};
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
this._elementsJSON = attributes.elements;
this._elements = null;
this._statusFieldJSON = attributes.status_field;
this._statusField = null;
this._script = attributes.script;
this._geometryRequired = !!attributes.geometry_required;
this._geometryTypes = attributes.geometry_types;
this._reportTemplatesJSON = attributes.report_templates;
this._name = attributes.name;
this._geometryRequired = !!attributes.geometry_required;
this._projectEnabled = attributes.projects_enabled != null ? !!attributes.projects_enabled : true;
this._assignmentEnabled = attributes.assignment_enabled != null ? !!attributes.assignment_enabled : true;
if (attributes.title_field_keys || attributes.record_title_key) {
this._titleFieldKeysJSON = attributes.title_field_keys || [ attributes.record_title_key ];
} else {
this._titleFieldKeysJSON = [];
}
}
get id() {
return this._id;
}
load(dataSource, callback) {
if (this._schemaLoaded) {
callback();
return;
}
this._schemaLoaded = true;
const loadElements = [];

@@ -34,3 +59,13 @@

async.each(loadElements, (element, cb) => {
element.load(dataSource, cb);
element.load(dataSource, (err) => {
if (err) {
// TODO(zhm) We need a parameter to control what happens when there's an error. We don't
// want to throw right here because some actual forms have orphaned objects. We can't have this
// blow up here because in a migration we need to keep going even when a form is 'slightly bogus'.
// In some cases it might be desirable to have more strict verification of the choice lists and
// classification sets.
}
cb();
});
}, callback);

@@ -40,8 +75,4 @@ }

createRecord(attributes) {
const record = new Record(attributes);
const record = new Record(attributes, this);
// TODO(zhm) this might not be final
record._form = this;
record._formValuesJSON = {};
DefaultValues.applyDefaultValuesForElements(this.elements,

@@ -73,7 +104,36 @@ record.formValues,

get isProjectEnabled() {
return this._projectEnabled;
}
get isAssignmentEnabled() {
return this._assignmentEnabled;
}
toJSON() {
// TODO(zhm) actually implement this so it returns a copy
return this._json;
const json = {};
json.id = this.id || null;
json.name = this.name || null;
json.description = this.description || null;
json.script = this.script || null;
json.elements = JSON.parse(JSON.stringify(this._elementsJSON));
json.assignment_enabled = this.isAssignmentEnabled;
json.projects_enabled = this.isProjectEnabled;
json.geometry_required = this.isGeometryRequired;
json.geometry_types = this._geometryTypes;
json.title_field_keys = this.titleFieldKeys;
json.report_templates = this.reportTemplates;
if (this._statusFieldJSON) {
json.status_field = JSON.parse(JSON.stringify(this._statusFieldJSON));
}
return json;
}
get isGeometryEnabled() {
return this._geometryTypes && this._geometryTypes.length > 0;
}
get isGeometryRequired() {

@@ -86,4 +146,67 @@ return this._geometryRequired;

}
get description() {
return this._description;
}
get script() {
return this._script;
}
get titleFieldKeys() {
return this._titleFieldKeysJSON || [];
}
get reportTemplates() {
return this._reportTemplatesJSON || [];
}
get reportTemplate() {
return this.reportTemplates.length ? this.reportTemplates[0] : null;
}
set overrideManualLocationEnabled(override) {
this._overrideManualLocationEnabled = override;
}
get isManualLocationEnabled() {
return this._overrideManualLocationEnabled != null ? !!this._overrideManualLocationEnabled : true;
}
set overrideMediaGalleryEnabled(override) {
this._overrideMediaGalleryEnabled = override;
}
get isMediaGalleryEnabled() {
return this._overrideMediaGalleryEnabled != null ? !!this._overrideMediaGalleryEnabled : true;
}
set overrideEditDurationsEnabled(override) {
this._overrideEditDurationsEnabled = override;
}
get isEditDurationsEnabled() {
return this._overrideEditDurationsEnabled != null ? !!this._overrideEditDurationsEnabled : true;
}
get overrideValues() {
return {
overrideManualLocationEnabled: this._overrideManualLocationEnabled,
overrideMediaGalleryEnabled: this._overrideMediaGalleryEnabled,
overrideEditDurationsEnabled: this._overrideEditDurationsEnabled
};
}
resetOverrides() {
for (const element of this.elements) {
element.resetOverrides();
}
this.statusField.resetOverrides();
this._overrideManualLocationEnabled = null;
this._overrideMediaGalleryEnabled = null;
}
}
ChildElements.includeInto(Form);

@@ -1,101 +0,61 @@

import Form from './form';
import Record from './record';
import Element from './elements/element';
import FormValue from './values/form-value';
import Choice from './elements/choice';
import ChoiceList from './choice-list';
import Classification from './elements/classification';
import ClassificationSet from './classification-set';
import ElementFactory from './elements/element-factory';
import RepeatableItemValue from './values/repeatable-item-value';
import RepeatableValue from './values/repeatable-value';
import Feature from './feature';
import FormValues from './values/form-values';
import TextUtils from './utils/text-utils';
import DateUtils from './utils/date-utils';
import NumberUtils from './utils/number-utils';
import ChildElements from './elements/child-elements';
import Condition from './elements/condition';
import RepeatableElement from './elements/repeatable-element';
import AudioItemValue from './values/audio-item-value';
import AudioValue from './values/audio-value';
import PhotoItemValue from './values/photo-item-value';
import PhotoValue from './values/photo-value';
import VideoItemValue from './values/video-item-value';
import VideoValue from './values/video-value';
import AddressElement from './elements/address-element';
import AddressValue from './values/address-value';
import BarcodeElement from './elements/barcode-element';
import BarcodeValue from './values/barcode-value';
import ChoiceElement from './elements/choice-element';
import ChoiceValue from './values/choice-value';
import ClassificationElement from './elements/classification-element';
import ClassificationValue from './values/classification-value';
import DateElement from './elements/date-element';
import DateValue from './values/date-value';
import CalculatedElement from './elements/calculated-element';
import CalculatedValue from './values/calculated-value';
import TextElement from './elements/text-element';
import TextValue from './values/text-value';
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';
import DefaultValues from './values/default-values';
import CustomValidationError from './validation/custom-validation-error';
import User from './user';
import Project from './project';
export {Form};
export {Record};
export {Element};
export {FormValue};
export {Choice};
export {ChoiceList};
export {Classification};
export {ClassificationSet};
export {ElementFactory};
export {RepeatableItemValue};
export {RepeatableValue};
export {Feature};
export {FormValues};
export {TextUtils};
export {DateUtils};
export {NumberUtils};
export {ChildElements};
export {Condition};
export {RepeatableElement};
export {AudioItemValue};
export {AudioValue};
export {PhotoItemValue};
export {PhotoValue};
export {VideoItemValue};
export {VideoValue};
export {AddressElement};
export {AddressValue};
export {BarcodeElement};
export {BarcodeValue};
export {ChoiceElement};
export {ChoiceValue};
export {ClassificationElement};
export {ClassificationValue};
export {DateElement};
export {DateValue};
export {CalculatedElement};
export {CalculatedValue};
export {TextElement};
export {TextValue};
export {SectionElement};
export {RecordLinkElement};
export {RecordLinkValue};
export {RecordLinkItemValue};
export {FeatureValidator};
export {DataSource};
export {MemoryDataSource};
export {DefaultValues};
export {CustomValidationError};
export {User};
export {Project};
export Form from './form';
export Record from './record';
export Element from './elements/element';
export FormValue from './values/form-value';
export Choice from './elements/choice';
export ChoiceList from './choice-list';
export Classification from './elements/classification';
export ClassificationSet from './classification-set';
export ElementFactory from './elements/element-factory';
export RepeatableItemValue from './values/repeatable-item-value';
export RepeatableValue from './values/repeatable-value';
export Feature from './feature';
export FormValues from './values/form-values';
export TextUtils from './utils/text-utils';
export DateUtils from './utils/date-utils';
export NumberUtils from './utils/number-utils';
export ChildElements from './elements/child-elements';
export Condition from './elements/condition';
export RepeatableElement from './elements/repeatable-element';
export AudioItemValue from './values/audio-item-value';
export AudioValue from './values/audio-value';
export PhotoItemValue from './values/photo-item-value';
export PhotoValue from './values/photo-value';
export VideoItemValue from './values/video-item-value';
export VideoValue from './values/video-value';
export AddressElement from './elements/address-element';
export AddressValue from './values/address-value';
export BarcodeElement from './elements/barcode-element';
export BarcodeValue from './values/barcode-value';
export ChoiceElement from './elements/choice-element';
export ChoiceValue from './values/choice-value';
export ClassificationElement from './elements/classification-element';
export ClassificationValue from './values/classification-value';
export DateElement from './elements/date-element';
export DateValue from './values/date-value';
export TimeElement from './elements/time-element';
export TimeValue from './values/time-value';
export CalculatedElement from './elements/calculated-element';
export CalculatedValue from './values/calculated-value';
export TextElement from './elements/text-element';
export TextValue from './values/text-value';
export SectionElement from './elements/section-element';
export RecordLinkElement from './elements/record-link-element';
export RecordLinkValue from './values/record-link-value';
export RecordLinkItemValue from './values/record-link-item-value';
export FeatureValidator from './validation/feature-validator';
export DataSource from './data-source';
export MemoryDataSource from './utils/memory-data-source';
export DefaultValues from './values/default-values';
export CustomValidationError from './validation/custom-validation-error';
export MediaElement from './elements/media-element';
export MediaValue from './values/media-value';
export MediaItemValue from './values/media-item-value';
export User from './user';
export Role from './role';
export Project from './project';
export Changeset from './changeset';
export Track from './media/track';
export TrackPoint from './media/track-point';
export TrackSegment from './media/track-segment';
export TrackPlayer from './media/track-player';
export default class Project {
constructor(attributes) {
attributes = attributes || {};
this.updateFromAPIAttributes(attributes);
}
this.id = attributes.id;
this.name = attributes.name;
this.description = attributes.description;
updateFromAPIAttributes(attrs) {
const attributes = attrs || {};
this._id = attributes.id;
this._name = attributes.name;
this._description = attributes.description;
}
get id() {
return this._id;
}
get name() {
return this._name;
}
get description() {
return this._description;
}
}

@@ -6,13 +6,12 @@ import Feature from './feature';

import StatusValue from './values/status-value';
import uuid from 'uuid';
import loadObject from './load-object';
export default class Record extends Feature {
constructor(attributes) {
constructor(attributes, form) {
super();
// this._id = attributes.id;
// this._createdAt = DateUtils.parseTimestamp(attributes.client_created_at);
// this._updatedAt = DateUtils.parseTimestamp(attributes.client_updated_at);
// this._formValuesJSON = attributes.form_values;
// this._latitude = attributes.latitude;
// this._longitude = attributes.longitude;
this._form = form || null;
this.updateFromAPIAttributes(attributes);
}

@@ -32,2 +31,6 @@

get version() {
return this._version;
}
get createdAt() {

@@ -49,2 +52,18 @@ return this._createdAt;

get clientCreatedAt() {
return this._clientCreatedAt;
}
set clientCreatedAt(createdAt) {
this._clientCreatedAt = createdAt;
}
get clientUpdatedAt() {
return this._clientUpdatedAt;
}
set clientUpdatedAt(updatedAt) {
this._clientUpdatedAt = updatedAt;
}
get formValues() {

@@ -62,26 +81,154 @@ if (this._formValues == null) {

get changeset() {
return this._changeset;
}
set changeset(changeset) {
this._changesetID = changeset.id;
this._changeset = changeset;
}
get changesetID() {
return this._changesetID;
}
get createdBy() {
return this._createdBy;
}
get updatedBy() {
return this._updatedBy;
}
loadChangeset(dataSource, callback) {
return loadObject(this, dataSource, 'changeset', 'getChangeset', callback);
}
toJSON() {
const json = {};
// TODO(zhm) this is incomplete
json.id = this.id;
json.client_created_at = DateUtils.formatTimestamp(this.createdAt);
json.client_updated_at = DateUtils.formatTimestamp(this.updatedAt);
json.form_id = this._form.id;
json.id = this.id || null;
json.version = this._version || null;
json.created_at = DateUtils.formatISOTimestamp(this.createdAt);
json.updated_at = DateUtils.formatISOTimestamp(this.updatedAt);
json.client_created_at = DateUtils.formatISOTimestamp(this.clientCreatedAt);
json.client_updated_at = DateUtils.formatISOTimestamp(this.clientUpdatedAt);
json.form_values = this.formValues.toJSON();
json.latitude = this._latitude;
json.longitude = this._longitude;
json.project_id = this._projectID;
json.assigned_to_id = this._assignedToID;
json.latitude = this._latitude || null;
json.longitude = this._longitude || null;
json.project_id = this._projectID || null;
json.assigned_to_id = this._assignedToID || null;
json.status = this._status || null;
json.created_by_id = this._createdByID || null;
json.created_by = this._createdBy || null;
json.updated_by_id = this._updatedByID || null;
json.updated_by = this._updatedBy || null;
if (this._horizontalAccuracy != null) {
json.horizontal_accuracy = this._horizontalAccuracy;
}
if (this._verticalAccuracy != null) {
json.vertical_accuracy = this._verticalAccuracy;
}
if (this._altitude != null) {
json.altitude = this._altitude;
}
if (this._speed != null) {
json.speed = this._speed;
}
if (this._course != null) {
json.course = this._course;
}
if (this._changesetID) {
json.changeset_id = this._changesetID;
}
json.created_location = this.createdLocation;
json.updated_location = this.updatedLocation;
json.created_duration = this.createdDuration;
json.updated_duration = this.updatedDuration;
json.edited_duration = this.editedDuration;
return json;
}
updateFromAPIAttributes(attrs) {
const attributes = attrs || {};
this._id = attributes.id || uuid.v4();
this._version = attributes.version || null;
this._createdAt = DateUtils.parseISOTimestamp(attributes.created_at);
this._updatedAt = DateUtils.parseISOTimestamp(attributes.updated_at);
this._clientCreatedAt = DateUtils.parseISOTimestamp(attributes.client_created_at);
this._clientUpdatedAt = DateUtils.parseISOTimestamp(attributes.client_updated_at);
this._formValuesJSON = attributes.form_values || {};
this._latitude = attributes.latitude || null;
this._longitude = attributes.longitude || null;
this._projectID = attributes.project_id || null;
this._assignedToID = attributes.assigned_to_id || null;
this._status = attributes.status || null;
this._createdByID = attributes.created_by_id || null;
this._createdBy = attributes.created_by || null;
this._updatedByID = attributes.updated_by_id || null;
this._updatedBy = attributes.updated_by || null;
this._horizontalAccuracy = attributes.horizontal_accuracy || null;
this._verticalAccuracy = attributes.vertical_accuracy || null;
this._altitude = attributes.altitude || null;
this._speed = attributes.speed || null;
this._course = attributes.course || null;
this._changesetID = attributes.changeset_id || null;
this._createdDuration = attributes.created_duration || null;
this._updatedDuration = attributes.updated_duration || null;
this._editedDuration = attributes.edited_duration || null;
const createdLocation = attributes.created_location;
this._createdLatitude = null;
this._createdLongitude = null;
this._createdAltitude = null;
this._createdAccuracy = null;
if (createdLocation) {
this._createdLatitude = createdLocation.latitude;
this._createdLongitude = createdLocation.longitude;
this._createdAltitude = createdLocation.altitude;
this._createdAccuracy = createdLocation.horizontal_accuracy;
}
const updatedLocation = attributes.updated_location;
this._updatedLatitude = null;
this._updatedLongitude = null;
this._updatedAltitude = null;
this._updatedAccuracy = null;
if (updatedLocation) {
this._updatedLatitude = updatedLocation.latitude;
this._updatedLongitude = updatedLocation.longitude;
this._updatedAltitude = updatedLocation.altitude;
this._updatedAccuracy = updatedLocation.horizontal_accuracy;
}
}
updateTimestamps() {
const now = new Date();
if (this._createdAt == null) {
this.createdAt = now;
if (this.clientCreatedAt == null) {
this.clientCreatedAt = now;
}
this.updatedAt = now;
this.clientUpdatedAt = now;
}

@@ -114,2 +261,6 @@

get searchableValue() {
return this.formValues.searchableValue;
}
get displayValue() {

@@ -119,3 +270,3 @@ const titleFieldKeys = this.form.titleFieldKeys;

for (let fieldKey of titleFieldKeys) {
for (const fieldKey of titleFieldKeys) {
const value = this.formValues.get(fieldKey);

@@ -149,2 +300,6 @@

get formID() {
return this.form ? this.form.id : null;
}
get projectID() {

@@ -166,2 +321,10 @@ return this._projectID;

get createdByID() {
return this._createdByID;
}
get updatedByID() {
return this._updatedByID;
}
get status() {

@@ -174,2 +337,255 @@ return this._status;

}
get latitude() {
return this._latitude;
}
set latitude(latitude) {
this._latitude = latitude;
}
get longitude() {
return this._longitude;
}
set longitude(longitude) {
this._longitude = longitude;
}
get horizontalAccuracy() {
return this._horizontalAccuracy;
}
set horizontalAccuracy(accuracy) {
this._horizontalAccuracy = accuracy;
}
get verticalAccuracy() {
return this._verticalAccuracy;
}
set verticalAccuracy(accuracy) {
this._verticalAccuracy = accuracy;
}
get altitude() {
return this._altitude;
}
set altitude(altitude) {
this._altitude = altitude;
}
get speed() {
return this._speed;
}
set speed(speed) {
this._speed = speed;
}
get course() {
return this._course;
}
set course(course) {
this._course = course;
}
get geometryAsGeoJSON() {
if (!this.hasCoordinate) {
return null;
}
return {
type: 'Point',
coordinates: [
this.longitude,
this.latitude
]
};
}
get createdDuration() {
return this._createdDuration;
}
set createdDuration(value) {
this._createdDuration = (value != null ? +value : null);
}
get updatedDuration() {
return this._updatedDuration;
}
set updatedDuration(value) {
this._updatedDuration = (value != null ? +value : null);
}
get editedDuration() {
return this._editedDuration;
}
set editedDuration(value) {
this._editedDuration = (value != null ? +value : null);
}
get createdLatitude() {
return this._createdLatitude;
}
get createdLongitude() {
return this._createdLongitude;
}
get createdAltitude() {
return this._createdAltitude;
}
get createdAccuracy() {
return this._createdAccuracy;
}
set createdLatitude(value) {
this._createdLatitude = (value != null ? +value : null);
}
set createdLongitude(value) {
this._createdLongitude = (value != null ? +value : null);
}
set createdAltitude(value) {
this._createdAltitude = (value != null ? +value : null);
}
set createdAccuracy(value) {
this._createdAccuracy = (value != null ? +value : null);
}
get updatedLatitude() {
return this._updatedLatitude;
}
get updatedLongitude() {
return this._updatedLongitude;
}
get updatedAltitude() {
return this._updatedAltitude;
}
get updatedAccuracy() {
return this._updatedAccuracy;
}
set updatedLatitude(value) {
this._updatedLatitude = (value != null ? +value : null);
}
set updatedLongitude(value) {
this._updatedLongitude = (value != null ? +value : null);
}
set updatedAltitude(value) {
this._updatedAltitude = (value != null ? +value : null);
}
set updatedAccuracy(value) {
this._updatedAccuracy = (value != null ? +value : null);
}
get hasCreatedCoordinate() {
return this.createdLatitude != null && this.createdLongitude != null;
}
get hasUpdatedCoordinate() {
return this.updatedLatitude != null && this.updatedLongitude != null;
}
get createdLocation() {
if (this.hasCreatedCoordinate) {
return {
latitude: this.createdLatitude,
longitude: this.createdLongitude,
altitude: this.createdAltitude,
horizontal_accuracy: this.createdAccuracy
};
}
return null;
}
get updatedLocation() {
if (this.hasUpdatedCoordinate) {
return {
latitude: this.updatedLatitude,
longitude: this.updatedLongitude,
altitude: this.updatedAltitude,
horizontal_accuracy: this.updatedAccuracy
};
}
return null;
}
updateFromActionAttributes(attributes, role) {
for (const dataName of Object.keys(attributes)) {
switch (dataName) {
case 'project_id': {
if (attributes.project_id && role.canChangeProject) {
this.projectID = attributes.project_id;
}
break;
}
case 'assigned_to_id': {
if (attributes.assigned_to_id && role.canChangeAssignment) {
this.assignedToID = attributes.assigned_to_id;
}
break;
}
case 'status': {
if (attributes.status && role.canChangeStatus) {
this.status = attributes.status;
}
break;
}
case 'latitude': {
if (attributes.latitude != null && attributes.latitude >= -90 && attributes.latitude <= 90) {
this.latitude = +attributes.latitude;
}
break;
}
case 'longitude': {
if (attributes.longitude != null && attributes.longitude >= -180 && attributes.longitude <= 180) {
this.longitude = +attributes.longitude;
}
break;
}
default: {
const element = this.form.elementsByDataName[dataName];
const value = attributes[dataName];
if (element && value != null) {
const formValue = this.formValues.createValueFromString(element, value);
if (formValue) {
this.formValues.set(element.key, formValue);
}
}
break;
}
}
}
}
}
export default class User {
constructor(attributes) {
attributes = attributes || {};
constructor(attrs) {
const attributes = attrs || {};
this.id = attributes.id;
this.name = attributes.name;
this.email = attributes.email;
this._id = attributes.id;
this._firstName = attributes.first_name;
this._lastName = attributes.last_name;
this._email = attributes.email;
this._fullName = attributes.name;
}
get id() {
return this._id;
}
get firstName() {
return this._firstName;
}
get lastName() {
return this._lastName;
}
get fullName() {
return this._fullName || (this.firstName + ' ' + this.lastName);
}
get email() {
return this._email;
}
}
import Locale from './locale';
import _ from 'lodash';
import padStart from 'lodash.padstart';
import relativeDate from 'relative-date';

@@ -12,3 +13,9 @@ let intl = null;

static parseDate(dateString) {
return new Date(dateString.replace(/-/g, '/'));
const date = new Date(dateString.replace(/-/g, '/'));
if (date == null || isNaN(date.getTime())) {
return null;
}
return date;
}

@@ -20,8 +27,22 @@

}
return timeString;
let [ hours, minutes ] = timeString.split(':');
if (hours == null || minutes == null) {
return null;
}
hours = +hours;
minutes = +minutes;
if (isNaN(hours) || isNaN(minutes)) {
return null;
}
return (hours * 60) + minutes;
}
static formatTime(date) {
const hours = _.padStart(date.getHours(), 2, '0');
const minutes = _.padStart(date.getMinutes(), 2, '0');
const hours = padStart(date.getHours(), 2, '0');
const minutes = padStart(date.getMinutes(), 2, '0');

@@ -31,17 +52,134 @@ return hours + ':' + minutes;

static parseTimestamp(timestampString) {
static formatTimeSeconds(seconds, milliseconds = false) {
const ss = +seconds % 60;
const div = (+seconds - ss) / 60;
const mm = div % 60;
const hh = (div - mm) / 60;
const ms = (ss * 1000 % 1000);
const h = padStart(Math.floor(hh), 2, '0');
const m = padStart(Math.floor(mm), 2, '0');
const s = padStart(Math.floor(ss), 2, '0');
const u = padStart(Math.floor(ms), 3, '0');
return h + ':' + m + ':' + s + (milliseconds ? '.' + u : '');
}
static formatTimeParts(hours, minutes, seconds) {
const h = padStart(+hours, 2, '0');
const m = padStart(+minutes, 2, '0');
const s = padStart(+seconds, 2, '0');
return h + ':' + m + ':' + s;
}
static parseISOTimestamp(timestampString) {
if (!timestampString) {
return null;
}
return new Date(timestampString);
}
static parseEpochTimestamp(timestampString) {
if (!timestampString) {
return null;
}
return new Date(parseFloat(timestampString) * 1000);
}
static formatTimestamp(date) {
if (date == null) {
static formatISOTimestamp(date) {
if (date == null || isNaN(date.getTime())) {
return null;
}
return date.getTime().toFixed(3);
return date.toISOString();
}
static formatEpochTimestamp(date) {
if (date == null || isNaN(date.getTime())) {
return null;
}
return (date.getTime() / 1000).toFixed(3);
}
static isValidTime(timeString) {
if (timeString == null) {
return true;
}
if (timeString.length !== 5) {
return false;
}
const parts = timeString.split(':');
if (parts.length !== 2) {
return false;
}
const [ hourPart, minutePart ] = parts;
if (hourPart.length !== 2 || minutePart.length !== 2) {
return false;
}
const hour = +hourPart;
const minute = +minutePart;
if (isNaN(hour) || isNaN(minute)) {
return false;
}
if (hour < 0 || hour >= 24) {
return false;
}
if (minute < 0 || minute >= 60) {
return false;
}
return true;
}
static isValidDate(dateString) {
if (dateString == null) {
return true;
}
if (dateString.length !== 10) {
return false;
}
const parts = dateString.split('-');
if (parts.length !== 3) {
return false;
}
const [ yearPart, monthPart, dayPart ] = parts;
if (yearPart.length !== 4 ||
monthPart.length !== 2 ||
dayPart.length !== 2) {
return false;
}
const year = +yearPart;
const month = +monthPart;
const day = +dayPart;
if (isNaN(year) || isNaN(month) || isNaN(day)) {
return false;
}
const parsed = DateUtils.parseDate(dateString);
return parsed && !isNaN(parsed);
}
static formatDate(date) {
const year = date.getFullYear();
const month = _.padStart(date.getMonth() + 1, 2, '0');
const day = _.padStart(date.getDate(), 2, '0');
const month = padStart(date.getMonth() + 1, 2, '0');
const day = padStart(date.getDate(), 2, '0');

@@ -55,10 +193,23 @@ return year + '-' + month + '-' + day;

}
return DateUtils.__formatLocalizedDate(date);
}
static formatLocalizedTimestamp(date) {
if (date == null) {
return null;
}
return date.toLocaleString();
}
static formatRelativeTimestamp(date) {
return relativeDate(date);
}
static __formatLocalizedDate(date) {
if (!Locale.supportsECMA402()) {
const year = date.getFullYear();
const month = _.padStart(date.getMonth() + 1, 2, '0');
const day = _.padStart(date.getDate(), 2, '0');
const month = padStart(date.getMonth() + 1, 2, '0');
const day = padStart(date.getDate(), 2, '0');
return year + '-' + month + '-' + day;

@@ -73,4 +224,12 @@ }

return new intl.DateTimeFormat(Locale.currentLocale(), options).format(date);
let result = null;
try {
result = new intl.DateTimeFormat(Locale.currentLocale(), options).format(date);
} catch (ex) {
// RangeError: Provided date is not in valid range.
}
return result;
}
}

@@ -13,6 +13,6 @@ export default class Locale {

return true;
} else {
return false;
}
return false;
}
}

@@ -6,2 +6,6 @@ export default class MemoryDataSource {

this.users = null;
this.photos = {};
this.audio = {};
this.videos = {};
this.tracks = {};
}

@@ -21,3 +25,3 @@

getRecord(id, callback) {
getRecord(id, form, callback) {
return callback(null, this.cache[id]);

@@ -34,2 +38,22 @@ }

getPhoto(id, callback) {
return callback(null, this.photos[id]);
}
getAudio(id, callback) {
return callback(null, this.audio[id]);
}
getAudioTrack(id, callback) {
return callback(null, this.tracks[id]);
}
getVideo(id, callback) {
return callback(null, this.videos[id]);
}
getVideoTrack(id, callback) {
return callback(null, this.tracks[id]);
}
getChoiceListComplete(id, object, callback) {

@@ -50,3 +74,3 @@ this.cache[id] = object;

getRecordComplete(id, object, callback) {
getRecordComplete(id, form, object, callback) {
this.cache[id] = object;

@@ -65,2 +89,34 @@ callback();

}
getPhotoComplete(id, object, callback) {
if (object.processed) {
this.photos[id] = object;
}
callback();
}
getAudioComplete(id, object, callback) {
if (object.processed) {
this.audio[id] = object;
}
callback();
}
getAudioTrackComplete(id, object, callback) {
this.tracks[id] = object;
callback();
}
getVideoComplete(id, object, callback) {
if (object.processed) {
this.videos[id] = object;
}
callback();
}
getVideoTrackComplete(id, object, callback) {
this.tracks[id] = object;
callback();
}
}

@@ -13,3 +13,5 @@ import Locale from './locale';

if (typeof Intl !== 'undefined') {
intl = global.Intl;
/* eslint-disable no-undef */
intl = Intl;
/* eslint-enable no-undef */
}

@@ -19,6 +21,42 @@

static parseDouble(input) {
return +input;
const number = +input;
if (number == null || isNaN(number)) {
return null;
}
return number;
}
static localizedStringFromMachineString(machineString, allowDecimals) {
static get localeDecimalFormatter() {
if (!this._localeDecimalFormatter && intl) {
this._localeDecimalFormatter = new intl.NumberFormat();
}
return this._localeDecimalFormatter;
}
static get localeIntegerFormatter() {
if (!this._localeIntegerFormatter && intl) {
this._localeIntegerFormatter = new intl.NumberFormat([], {maximumFractionDigits: 0});
}
return this._localeIntegerFormatter;
}
static get machineFormatter() {
if (!this._machineFormatter && intl) {
this._machineFormatter = new intl.NumberFormat([ 'en-US' ], MachineFormatterOptions);
}
return this._machineFormatter;
}
static localizedStringFromMachineString(machineString, allowDecimals = true) {
if (allowDecimals && NumberUtils.localeDecimalFormatter) {
return NumberUtils.localeDecimalFormatter.format(machineString);
} else if (NumberUtils.localeIntegerFormatter) {
return NumberUtils.localeIntegerFormatter.format(machineString);
}
return machineString;

@@ -28,8 +66,2 @@ }

static formatMachine(number) {
if (intl) {
if (NumberUtils.machineFormatter == null) {
NumberUtils.machineFormatter = new intl.NumberFormat(['en-US'], MachineFormatterOptions);
}
}
return NumberUtils.formatWithFormatter(NumberUtils.machineFormatter, number);

@@ -66,13 +98,13 @@ }

if (formatter != null) {
let string = formatter.format(number);
const string = formatter.format(number);
if (string === 'NaN') {
return number;
} else {
return string;
}
} else {
return number.toString();
return string;
}
return number.toString();
}
}

@@ -1,2 +0,4 @@

import _ from 'lodash';
import includes from 'lodash.includes';
import startsWith from 'lodash.startswith';
import trim from 'lodash.trim';

@@ -21,20 +23,20 @@ export default class TextUtils {

static contains(haystack, needle) {
if (needle === null) {
if (needle == null) {
return false;
}
return _.contains(haystack.toLowerCase(), needle.toLowerCase());
return includes(haystack.toLowerCase(), needle.toLowerCase());
}
static startsWith(haystack, needle) {
if (needle === null) {
if (needle == null) {
return false;
}
return _.startsWith(haystack, needle);
return startsWith(haystack, needle);
}
static trim(value) {
return _.trim(value);
return trim(value);
}
}

@@ -21,3 +21,3 @@ import Form from '../form';

const parentLabels = parents.reverse().concat([this.element.label]);
const parentLabels = parents.reverse().concat([ this.element.label ]);

@@ -24,0 +24,0 @@ return parentLabels.join(' / ');

@@ -10,2 +10,4 @@ import RepeatableItemValue from '../values/repeatable-item-value';

import NumericRangeValidationError from './numeric-range-validation-error';
import DateFormatValidationError from './date-format-validation-error';
import TimeFormatValidationError from './time-format-validation-error';

@@ -31,3 +33,3 @@ export default class FeatureValidator {

if (record.isStatusFieldEnabled && record.status == null) {
errors.push(new RequiredFieldValidationError(record.form.statusField.label));
errors.push(new RequiredFieldValidationError(record.form.statusField));
}

@@ -68,6 +70,4 @@

static validateFieldsInElements(elements, record, formValues, errors, cache) {
if (!cache) {
cache = {};
}
static validateFieldsInElements(elements, record, formValues, errors, visibilityCache) {
const cache = visibilityCache || {};

@@ -118,2 +118,18 @@ for (const element of elements) {

if (element.isDateElement) {
const error = FeatureValidator.validateDateField(element, formValues.get(element.key));
if (error) {
errors.push(error);
}
}
if (element.isTimeElement) {
const error = FeatureValidator.validateTimeField(element, formValues.get(element.key));
if (error) {
errors.push(error);
}
}
if (element.isLengthValidationSupported) {

@@ -151,3 +167,3 @@ const fieldValue = formValues.get(element.key);

const regex = new RegExp(element.pattern);
const regex = new RegExp('^(?:' + element.pattern + ')$');

@@ -198,4 +214,4 @@ if (regex) {

if (element.isInteger) {
if (value.indexOf(decimalSeparator) > -1) {
if (element.isIntegerFormat) {
if (value.textValue.indexOf(decimalSeparator) > -1) {
return new NumericFormatValidationError(element);

@@ -207,3 +223,3 @@ }

if (numberValue < element.min || numberValue > element.max) {
if ((element.hasMin && numberValue < element.min) || (element.hasMax && numberValue > element.max)) {
return new NumericRangeValidationError(element);

@@ -215,2 +231,26 @@ }

static validateDateField(element, value) {
if (value == null || value.isEmpty) {
return null;
}
if (!value.isValid) {
return new DateFormatValidationError(element);
}
return null;
}
static validateTimeField(element, value) {
if (value == null || value.isEmpty) {
return null;
}
if (!value.isValid) {
return new TimeFormatValidationError(element);
}
return null;
}
static formatErrors(errors) {

@@ -217,0 +257,0 @@ const messages = [];

@@ -199,6 +199,6 @@ import ElementValidationError from './element-validation-error';

return format(singularFormat, this.label, length);
} else {
return format(pluralFormat, this.label, length);
}
return format(pluralFormat, this.label, length);
}
}

@@ -6,4 +6,4 @@ import ElementValidationError from './element-validation-error';

get message() {
const messageFormat = this.element.isInteger ? "The value of field '%s' must be an integer number."
: "The value of field '%s' must be an decimal number.";
const messageFormat = this.element.isIntegerFormat ? "The value of field '%s' must be an integer number."
: "The value of field '%s' must be an decimal number.";

@@ -10,0 +10,0 @@ return format(messageFormat, this.label);

@@ -6,3 +6,3 @@ import ElementValidationError from './element-validation-error';

get message() {
let message;
let message = null;

@@ -9,0 +9,0 @@ const fieldLabel = this.label;

@@ -12,3 +12,3 @@ import FormValue from './form-value';

get isEmpty() {
return this.address.isEmpty();
return this.address.isEmpty;
}

@@ -29,5 +29,13 @@

get columnValue() {
return null;
// TODO(zhm) implement
// throw new Error('Not implemented');
const value = {};
const address = this.address.toJSON();
for (const key of Object.keys(address)) {
value['f' + this.element.key + '_' + key] = address[key];
}
value['f' + this.element.key] = this.searchableValue;
return value;
}

@@ -42,2 +50,6 @@

toJSON() {
if (this.isEmpty) {
return null;
}
return this.address.toJSON();

@@ -44,0 +56,0 @@ }

@@ -43,3 +43,3 @@ import TextUtils from '../utils/text-utils';

isEmpty() {
get isEmpty() {
return !(TextUtils.isPresent(this.streetNumber) ||

@@ -92,3 +92,3 @@ TextUtils.isPresent(this.streetName) ||

for (let part of parts) {
for (const part of parts) {
if (TextUtils.isPresent(part)) {

@@ -95,0 +95,0 @@ result.push(part);

@@ -12,6 +12,6 @@ import MediaValue from './media-value';

return '1 Audio File';
} else {
return `${this.length} Audio Files`;
}
return `${this.length} Audio Files`;
}
}

@@ -36,3 +36,3 @@ import TextualValue from './textual-value';

if (date) {
return date.getTime();
return date.getTime() / 1000;
}

@@ -39,0 +39,0 @@ }

import FormValue from './form-value';
import TextUtils from '../utils/text-utils';
import _ from 'lodash';
import includes from 'lodash.includes';

@@ -17,3 +17,3 @@ const ChoiceDisplaySeparator = ', ';

if (attributes.choice_values) {
for (let choice of attributes.choice_values) {
for (const choice of attributes.choice_values) {
if (TextUtils.isPresent(choice)) {

@@ -26,3 +26,3 @@ this._choiceValues.push(choice);

if (attributes.other_values) {
for (let choice of attributes.other_values) {
for (const choice of attributes.other_values) {
if (TextUtils.isPresent(choice)) {

@@ -49,3 +49,3 @@ this._otherValues.push(choice);

for (let rawValue of this._choiceValues) {
for (const rawValue of this._choiceValues) {
const choice = this.element.choiceByValue(rawValue);

@@ -60,3 +60,3 @@

for (let otherValue of this._otherValues) {
for (const otherValue of this._otherValues) {
labels.push(otherValue);

@@ -71,3 +71,3 @@ }

for (let rawValue of this._choiceValues) {
for (const rawValue of this._choiceValues) {
const choice = this.element.choiceByValue(rawValue);

@@ -77,3 +77,6 @@

values.push(choice.label);
values.push(choice.value);
if (choice.label !== choice.value) {
values.push(choice.value);
}
} else {

@@ -84,3 +87,3 @@ values.push(rawValue);

for (let otherValue of this._otherValues) {
for (const otherValue of this._otherValues) {
values.push(otherValue);

@@ -104,7 +107,7 @@ }

for (let rawValue of this._choiceValues) {
for (const rawValue of this._choiceValues) {
choiceValues.push(rawValue);
}
for (let otherValue of this._otherValues) {
for (const otherValue of this._otherValues) {
otherValues.push(otherValue);

@@ -122,7 +125,7 @@ }

for (let rawValue of this._choiceValues) {
for (const rawValue of this._choiceValues) {
allValues.push(rawValue);
}
for (let otherValue of this._otherValues) {
for (const otherValue of this._otherValues) {
allValues.push(otherValue);

@@ -139,3 +142,3 @@ }

return '\t' + allValues.join('\t') + '\t';
return allValues;
}

@@ -176,3 +179,3 @@

isEqual(value) {
if (_.includes(this.selectedValues, value)) {
if (includes(this.selectedValues, value)) {
return true;

@@ -179,0 +182,0 @@ }

@@ -17,11 +17,15 @@ import FormValue from './form-value';

if (attributes) {
for (let choice of attributes.choice_values) {
if (TextUtils.isPresent(choice)) {
this._choiceValues.push(choice);
if (attributes.choice_values) {
for (const choice of attributes.choice_values) {
if (TextUtils.isPresent(choice)) {
this._choiceValues.push(choice);
}
}
}
for (let choice of attributes.other_values) {
if (TextUtils.isPresent(choice)) {
this._otherValues.push(choice);
if (attributes.other_values) {
for (const choice of attributes.other_values) {
if (TextUtils.isPresent(choice)) {
this._otherValues.push(choice);
}
}

@@ -44,2 +48,38 @@ }

isEqual(value) {
const classification = this.selectedClassification;
const choiceValues = classification ? classification.toJSON() : null;
const ESCAPED = /\\,/g;
const parts = value.replace(ESCAPED, '\t\t').split(',').map(part => part.replace(/\t\t/g, ','));
let allMatchSoFar = false;
let partIndex = 0;
for (const part of parts) {
if (part != null && choiceValues && partIndex < choiceValues.length &&
choiceValues[partIndex].toLowerCase() === part.replace(ESCAPED, ',').toLowerCase()) {
allMatchSoFar = true;
} else {
allMatchSoFar = false;
break;
}
++partIndex;
}
return allMatchSoFar;
}
contains(value) {
return this.isEqual(value);
}
startsWith(value) {
return this.contains(value);
}
get displayValue() {

@@ -51,3 +91,3 @@ const values = [];

if (classification) {
for (let item of classification.exploded) {
for (const item of classification.exploded) {
if (item.label) {

@@ -72,3 +112,3 @@ values.push(item.label);

if (classification) {
for (let item of classification.exploded) {
for (const item of classification.exploded) {
if (item.label) {

@@ -78,3 +118,3 @@ values.push(item.label);

if (item.value) {
if (item.value && item.value !== item.label) {
values.push(item.value);

@@ -113,7 +153,7 @@ }

for (let value of this._choiceValues) {
for (const value of this._choiceValues) {
allValues.push(value);
}
for (let value of this._otherValues) {
for (const value of this._otherValues) {
allValues.push(value);

@@ -126,3 +166,3 @@ }

return allValues.join('\t');
return allValues;
}

@@ -146,2 +186,10 @@

set otherValue(value) {
if (value && value.length) {
this._otherValues = [ value ];
} else {
this._otherValues = [];
}
}
get selectedClassification() {

@@ -156,7 +204,7 @@ let result = null;

for (let classificationValue of this._choiceValues) {
for (let classification of currentClassifications) {
for (const classificationValue of this._choiceValues) {
for (const classification of currentClassifications) {
if (classification.value === classificationValue) {
result = classification;
currentClassifications = classification.children;
currentClassifications = classification.items;
break;

@@ -172,4 +220,12 @@ }

if (classification instanceof Classification) {
this._choiceValues = classification.toJSON();
this.setSelectedClassificationJSON(classification.toJSON(), otherValue);
} else {
this.setSelectedClassificationJSON(null, otherValue);
}
}
setSelectedClassificationJSON(classificationAsJSON, otherValue) {
if (classificationAsJSON && classificationAsJSON.length) {
this._choiceValues = classificationAsJSON;
} else {
this._choiceValues = [];

@@ -181,5 +237,5 @@ }

} else {
this._otherVaues = [];
this._otherValues = [];
}
}
}

@@ -6,6 +6,2 @@ import TextualValue from './textual-value';

export default class DateValue extends TextualValue {
constructor(element, value) {
super(element, value);
}
get displayValue() {

@@ -59,5 +55,27 @@ if (this.isEmpty) {

get isValid() {
if (this.isEmpty) {
return true;
}
return DateUtils.isValidDate(this.textValue);
}
get dateValue() {
return DateUtils.parseDate(this.textValue);
}
get columnValue() {
if (this.isEmpty) {
return null;
}
return this.dateValue;
// The following code can be used to convert a date to a unix timestamp integer
//
// const timestamp = this.textValue + 'T00:00:00Z';
// const date = DateUtils.parseISOTimestamp(timestamp);
// return date ? date.getTime() / 1000 : null;
}
}

@@ -7,3 +7,5 @@ import DateUtils from '../utils/date-utils';

export default class DefaultValues {
static applyDefaultValue(defaultValue, element, formValues) {
static applyDefaultValue(elementDefaultValue, element, formValues) {
let defaultValue = elementDefaultValue;
const value = formValues.get(element.key);

@@ -13,3 +15,3 @@

if (hasValue || defaultValue == null) {
if (hasValue || defaultValue == null || defaultValue.length === 0) {
return;

@@ -16,0 +18,0 @@ }

@@ -43,3 +43,3 @@ import ChoiceValue from './choice-value';

if (constructor == null) {
throw new Error('Unsupported element ' + element.type);
return null;
}

@@ -46,0 +46,0 @@

@@ -1,2 +0,2 @@

import Types from '../elements/element-types';
import FormValueFactory from './form-value-factory';

@@ -7,4 +7,2 @@ function notImplemented() {

let FormValueFactory = null;
export default class FormValue {

@@ -72,25 +70,5 @@ constructor(element, value) {

static factory() {
return (FormValueFactory = FormValueFactory || require('./form-value-factory').default);
}
static create(element, attributes) {
return FormValue.factory().create(element, attributes);
return FormValueFactory.create(element, attributes);
}
static classes() {
if (FormValue._classes == null) {
FormValue._classes = {};
for (let klass of Object.keys(Types)) {
const constructor = FormValue.factory().classes()[Types[klass]];
if (constructor) {
FormValue._classes[constructor.name] = constructor;
}
}
}
return FormValue._classes;
}
}

@@ -5,2 +5,6 @@ import FormValueFactory from './form-value-factory';

import TextUtils from '../utils/text-utils';
import Condition from '../elements/condition';
import MediaValue from './media-value';
import SignatureValue from './signature-value';
import RepeatableValue from './repeatable-value';

@@ -13,3 +17,3 @@ const SearchValueSeparator = ' ';

this.container = container;
this.loadValues(container.elements, attributes);
this.loadValues(container.elements, attributes || {});
}

@@ -54,3 +58,3 @@

loadValues(elements, attributes) {
for (let element of elements) {
for (const element of elements) {
this.loadValue(element, attributes);

@@ -77,3 +81,3 @@ }

for (let key of Object.keys(this._values)) {
for (const key of Object.keys(this._values)) {
const formValue = this._values[key];

@@ -102,3 +106,3 @@

for (let key of Object.keys(formValues._values)) {
for (const key of Object.keys(formValues._values)) {
const formValue = formValues._values[key];

@@ -111,2 +115,6 @@

createValue(element, rawValue) {
if (element == null) {
throw new Error('element cannot be null');
}
return FormValueFactory.create(element, rawValue != null ? rawValue : null);

@@ -196,3 +204,3 @@ }

for (let key of Object.keys(this._values)) {
for (const key of Object.keys(this._values)) {
const formValue = this._values[key];

@@ -204,3 +212,3 @@

if (searchValue != null) {
searchValues.push(searchValue);
searchValues.push(searchValue.trim());
}

@@ -210,4 +218,68 @@ }

return searchValues.join(SearchValueSeparator);
return searchValues.join(SearchValueSeparator).trim();
}
clearInvisibleValues(valuesForConditions, record) {
const elementsToRemove = [];
const cache = {};
for (const formValue of this.all) {
const element = formValue.element;
// don't clear out fields that are explicitly marked hidden, or have any parents explicitly marked as hidden
const skipElement = element.isHidden || element.hasHiddenParent;
if (!skipElement) {
const shouldBeVisible = Condition.shouldElementBeVisible(element,
record,
valuesForConditions,
cache);
if (!shouldBeVisible) {
elementsToRemove.push(element);
}
}
}
for (const element of elementsToRemove) {
const blankValue = this.createValue(element, null);
this.set(element.key, blankValue);
}
}
get mediaValues() {
const values = [];
for (const formValue of this.all) {
if (formValue instanceof MediaValue) {
values.push.apply(values, formValue.items);
} else if (formValue instanceof SignatureValue) {
values.push(formValue);
} else if (formValue instanceof RepeatableValue) {
for (const item of formValue.items) {
values.push.apply(values, item.formValues.mediaValues);
}
}
}
return values;
}
get repeatableItems() {
const items = [];
for (const formValue of this.all) {
if (formValue instanceof RepeatableValue) {
items.push.apply(items, formValue.items);
for (const item of formValue.items) {
items.push.apply(items, item.formValues.repeatableItems);
}
}
}
return items;
}
}
export default class MediaItemValue {
constructor(attributes) {
constructor(mediaValue, attributes) {
this.mediaValue = mediaValue;
this.caption = attributes.caption;

@@ -4,0 +5,0 @@ this.mediaID = attributes[this.mediaKey];

@@ -12,5 +12,5 @@ import FormValue from './form-value';

if (items != null) {
for (let item of items) {
this._items.push(new this.ItemClass(item));
if (Array.isArray(items)) {
for (const item of items) {
this._items.push(new this.ItemClass(this, item));
}

@@ -45,9 +45,20 @@ }

get columnValue() {
if (this.isEmpty) {
return null;
}
const ids = [];
const captions = [];
for (let item of this._items) {
for (const item of this._items) {
ids.push(item.mediaID);
captions.push(item.caption);
}
return ids.join(',');
const value = {};
value['f' + this.element.key + '_captions'] = captions;
value['f' + this.element.key] = ids;
return value;
}

@@ -58,3 +69,3 @@

for (let item of this._items) {
for (const item of this._items) {
items.push(new MultipleValueItem(this.element, item.mediaID));

@@ -67,5 +78,9 @@ }

toJSON() {
if (this.isEmpty) {
return null;
}
const items = [];
for (let item of this._items) {
for (const item of this._items) {
items.push(item.toJSON());

@@ -102,3 +117,3 @@ }

addItem(id, caption) {
const item = new this.ItemClass({ caption: caption });
const item = new this.ItemClass(this, { caption: caption });

@@ -111,2 +126,31 @@ item.mediaID = id;

}
removeItem(id) {
for (let index = 0; index < this._items.length; ++index) {
if (this._items[index].mediaID === id) {
const item = this._items[index];
this._items.splice(index, 1);
return item;
}
}
return null;
}
get hasCaptions() {
for (const item of this._items) {
if (TextUtils.isPresent(item.caption)) {
return true;
}
}
return false;
}
// return a copy until it's determined that a mutable API is necessary
get items() {
return this._items.slice();
}
}

@@ -12,6 +12,6 @@ import MediaValue from './media-value';

return '1 Photo';
} else {
return `${this.length} Photos`;
}
return `${this.length} Photos`;
}
}

@@ -0,7 +1,14 @@

import assert from 'assert';
export default class RecordLinkItemValue {
constructor(attributes) {
constructor(parent, attributes) {
this._parent = parent;
this._recordID = attributes.record_id;
}
id() {
get parent() {
return this._parent;
}
get id() {
return this._recordID;

@@ -16,5 +23,32 @@ }

get displayValue() {
if (this._record) {
return this._record.displayValue;
}
return null;
}
get record() {
return this._record;
}
set record(record) {
this._recordID = record;
this._record = record;
}
load(dataSource, callback) {
assert(this.parent.element.form, 'form must be present before loading the record');
dataSource.getRecord(this._recordID, this.parent.element.form, (err, record) => {
if (err) {
return callback(err);
}
this._record = record;
return callback();
});
}
}

@@ -13,4 +13,4 @@ import FormValue from './form-value';

if (items) {
for (let item of items) {
this._items.push(new RecordLinkItemValue(item));
for (const item of items) {
this._items.push(new RecordLinkItemValue(this, item));
}

@@ -47,3 +47,3 @@ }

for (let item of this._items) {
for (const item of this._items) {
items.push(item.toJSON());

@@ -56,3 +56,13 @@ }

get columnValue() {
return null;
if (this.isEmpty) {
return null;
}
const ids = [];
for (const item of this._items) {
ids.push(item.id);
}
return ids;
}

@@ -63,4 +73,4 @@

for (let item of this._items) {
ids.push(new MultipleValueItem(this.element, item.recordID));
for (const item of this._items) {
ids.push(new MultipleValueItem(this.element, item.id));
}

@@ -92,12 +102,46 @@

get items() {
return this._items;
return this._items.slice();
}
addRecord(record) {
const item = new RecordLinkItemValue({record_id: record.id});
const item = new RecordLinkItemValue(this, {record_id: record.id});
item._record = record;
this._items.push(item);
this.insertItem(item);
}
itemIndex(id) {
for (let index = 0; index < this._items.length; ++index) {
if (id === this._items[index].id) {
return index;
}
}
return -1;
}
insertItem(item) {
const index = this.itemIndex(item.id);
if (index > -1) {
this._items[index] = item;
} else {
this._items.push(item);
}
}
removeItem(id) {
const index = this.itemIndex(id);
if (index > -1) {
const item = this._items[index];
this._items.splice(index, 1);
return item;
}
return null;
}
}

@@ -5,2 +5,3 @@ import Feature from '../feature';

import TextUtils from '../utils/text-utils';
import loadObject from '../load-object';

@@ -15,12 +16,51 @@ export default class RepeatableItemValue extends Feature {

this._id = item.id;
this._createdAt = DateUtils.parseTimestamp(item.created_at);
this._updatedAt = DateUtils.parseTimestamp(item.updated_at);
this._createdAt = DateUtils.parseEpochTimestamp(item.created_at);
this._updatedAt = DateUtils.parseEpochTimestamp(item.updated_at);
this._formValuesJSON = item.form_values;
this._version = item.version || 1;
this._changesetID = item.changeset_id;
this._createdByID = item.created_by_id;
this._updatedByID = item.updated_by_id;
const geometry = item.geometry;
if (geometry != null && geometry.type === 'Point') {
if (geometry != null &&
geometry.type === 'Point' &&
geometry.coordinates &&
geometry.coordinates.length > 1) {
this._latitude = geometry.coordinates[1];
this._longitude = geometry.coordinates[0];
}
this._createdDuration = item.created_duration || null;
this._updatedDuration = item.updated_duration || null;
this._editedDuration = item.edited_duration || null;
const createdLocation = item.created_location;
this._createdLatitude = null;
this._createdLongitude = null;
this._createdAltitude = null;
this._createdAccuracy = null;
if (createdLocation) {
this._createdLatitude = createdLocation.latitude;
this._createdLongitude = createdLocation.longitude;
this._createdAltitude = createdLocation.altitude;
this._createdAccuracy = createdLocation.horizontal_accuracy;
}
const updatedLocation = item.updated_location;
this._updatedLatitude = null;
this._updatedLongitude = null;
this._updatedAltitude = null;
this._updatedAccuracy = null;
if (updatedLocation) {
this._updatedLatitude = updatedLocation.latitude;
this._updatedLongitude = updatedLocation.longitude;
this._updatedAltitude = updatedLocation.altitude;
this._updatedAccuracy = updatedLocation.horizontal_accuracy;
}
}

@@ -40,2 +80,14 @@

get version() {
return this._version;
}
set createdAt(createdAt) {
if (createdAt != null && !(createdAt instanceof Date)) {
throw new TypeError('createdAt must be a Date');
}
this._createdAt = createdAt;
}
get updatedAt() {

@@ -45,2 +97,10 @@ return this._updatedAt;

set updatedAt(updatedAt) {
if (updatedAt != null && !(updatedAt instanceof Date)) {
throw new TypeError('updatedAt must be a Date');
}
this._updatedAt = updatedAt;
}
get formValues() {

@@ -61,7 +121,12 @@ if (!this._formValues) {

json.id = this.identifier;
json.created_at = DateUtils.formatTimestamp(this.createdAt);
json.updated_at = DateUtils.formatTimestamp(this.updatedAt);
json.id = this.id;
json.created_at = DateUtils.formatEpochTimestamp(this.createdAt);
json.updated_at = DateUtils.formatEpochTimestamp(this.updatedAt);
json.form_values = this.formValues.toJSON();
json.geometry = this.geometryAsGeoJSON();
json.geometry = this.geometryAsGeoJSON;
json.created_location = this.createdLocation;
json.updated_location = this.updatedLocation;
json.created_duration = this.createdDuration;
json.updated_duration = this.updatedDuration;
json.edited_duration = this.editedDuration;

@@ -85,10 +150,2 @@ return json;

get latitude() {
return this._latitude;
}
get longitude() {
return this._longitude;
}
get displayValue() {

@@ -98,3 +155,3 @@ const titleFieldKeys = this._element.titleFieldKeys;

for (let fieldKey of titleFieldKeys) {
for (const fieldKey of titleFieldKeys) {
const formValue = this.formValues.get(fieldKey);

@@ -114,3 +171,7 @@

geometryAsGeoJSON() {
get searchableValue() {
return this.formValues.searchableValue;
}
get geometryAsGeoJSON() {
if (!this.hasCoordinate) {

@@ -122,5 +183,179 @@ return null;

type: 'Point',
coordinates: [this._longitude, this._latitude]
coordinates: [ this._longitude, this._latitude ]
};
}
get latitude() {
return this._latitude;
}
set latitude(latitude) {
this._latitude = latitude;
}
get longitude() {
return this._longitude;
}
set longitude(longitude) {
this._longitude = longitude;
}
get changesetID() {
return this._changesetID;
}
get createdByID() {
return this._createdByID;
}
get updatedByID() {
return this._updatedByID;
}
loadChangeset(dataSource, callback) {
return loadObject(this, dataSource, 'changeset', 'getChangeset', callback);
}
loadCreatedBy(dataSource, callback) {
return loadObject(this, dataSource, 'updatedBy', 'getUser', callback);
}
loadUpdatedBy(dataSource, callback) {
return loadObject(this, dataSource, 'createdBy', 'getUser', callback);
}
get changeset() {
return this._changeset;
}
get updatedBy() {
return this._updatedBy;
}
get createdBy() {
return this._createdBy;
}
get createdDuration() {
return this._createdDuration;
}
set createdDuration(value) {
this._createdDuration = (value != null ? +value : null);
}
get updatedDuration() {
return this._updatedDuration;
}
set updatedDuration(value) {
this._updatedDuration = (value != null ? +value : null);
}
get editedDuration() {
return this._editedDuration;
}
set editedDuration(value) {
this._editedDuration = (value != null ? +value : null);
}
get createdLatitude() {
return this._createdLatitude;
}
get createdLongitude() {
return this._createdLongitude;
}
get createdAltitude() {
return this._createdAltitude;
}
get createdAccuracy() {
return this._createdAccuracy;
}
set createdLatitude(value) {
this._createdLatitude = (value != null ? +value : null);
}
set createdLongitude(value) {
this._createdLongitude = (value != null ? +value : null);
}
set createdAltitude(value) {
this._createdAltitude = (value != null ? +value : null);
}
set createdAccuracy(value) {
this._createdAccuracy = (value != null ? +value : null);
}
get updatedLatitude() {
return this._updatedLatitude;
}
get updatedLongitude() {
return this._updatedLongitude;
}
get updatedAltitude() {
return this._updatedAltitude;
}
get updatedAccuracy() {
return this._updatedAccuracy;
}
set updatedLatitude(value) {
this._updatedLatitude = (value != null ? +value : null);
}
set updatedLongitude(value) {
this._updatedLongitude = (value != null ? +value : null);
}
set updatedAltitude(value) {
this._updatedAltitude = (value != null ? +value : null);
}
set updatedAccuracy(value) {
this._updatedAccuracy = (value != null ? +value : null);
}
get hasCreatedCoordinate() {
return this.createdLatitude != null && this.createdLongitude != null;
}
get hasUpdatedCoordinate() {
return this.updatedLatitude != null && this.updatedLongitude != null;
}
get createdLocation() {
if (this.hasCreatedCoordinate) {
return {
latitude: this.createdLatitude,
longitude: this.createdLongitude,
altitude: this.createdAltitude,
horizontal_accuracy: this.createdAccuracy
};
}
return null;
}
get updatedLocation() {
if (this.hasUpdatedCoordinate) {
return {
latitude: this.updatedLatitude,
longitude: this.updatedLongitude,
altitude: this.updatedAltitude,
horizontal_accuracy: this.updatedAccuracy
};
}
return null;
}
}

@@ -15,3 +15,3 @@ import FormValue from './form-value';

if (items != null) {
for (let item of items) {
for (const item of items) {
this._items.push(new RepeatableItemValue(this.element, item, this._items.length));

@@ -29,5 +29,5 @@ }

return '1 Item';
} else {
return this.length + ' Items';
}
return this.length + ' Items';
}

@@ -42,3 +42,3 @@

for (let item of this._items) {
for (const item of this._items) {
const searchValue = item.searchableValue;

@@ -65,3 +65,3 @@

for (let item of this._items) {
for (const item of this._items) {
items.push(item.toJSON());

@@ -105,2 +105,7 @@ }

// return a copy until it's determined that a mutable API is necessary
get items() {
return this._items.slice();
}
forEachItem(callback) {

@@ -110,2 +115,36 @@ this.mapItems(callback);

itemIndex(id) {
for (let index = 0; index < this._items.length; ++index) {
if (id === this._items[index].id) {
return index;
}
}
return -1;
}
insertItem(item) {
const index = this.itemIndex(item.id);
if (index > -1) {
this._items[index] = item;
} else {
this._items.push(item);
}
}
removeItem(id) {
const index = this.itemIndex(id);
if (index > -1) {
const item = this._items[index];
this._items.splice(index, 1);
return item;
}
return null;
}
createNewItem() {

@@ -117,8 +156,4 @@ const attributes = {

const item = new RepeatableItemValue(this.element, attributes, this._items.length);
this._items.push(item);
return item;
return new RepeatableItemValue(this.element, attributes, this._items.length);
}
}
import FormValue from './form-value';
import DateUtils from '../utils/date-utils';

@@ -9,12 +10,37 @@ export default class SignatureValue extends FormValue {

this._identifier = attributes.signature_id;
this._timestamp = attributes.timestamp;
this._timestamp = DateUtils.parseISOTimestamp(attributes.timestamp);
}
}
get id() {
return this._identifier;
}
set id(id) {
this._identifier = id;
}
get timestamp() {
return this._timestamp;
}
set timestamp(timestamp) {
if (!(timestamp instanceof Date)) {
throw new TypeError('timestamp must be a Date');
}
this._timestamp = timestamp;
}
clear() {
this._identifier = null;
this._timestamp = null;
}
get isEmpty() {
return false;
return this._identifier == null;
}
get displayValue() {
return '1 Signature';
return this.isEmpty ? null : '1 Signature';
}

@@ -27,7 +53,16 @@

get length() {
return 1;
return this.isEmpty ? 0 : 1;
}
get columnValue() {
return this._identifier;
if (this.isEmpty) {
return null;
}
const value = {};
value['f' + this.element.key + '_timestamp'] = this.timestamp;
value['f' + this.element.key] = this._identifier;
return value;
}

@@ -40,5 +75,9 @@

toJSON() {
if (this.isEmpty) {
return null;
}
return {
signature_id: this._identifier,
timestamp: this._timestamp
timestamp: DateUtils.formatISOTimestamp(this._timestamp)
};

@@ -45,0 +84,0 @@ }

import TextualValue from './textual-value';
export default class StatusValue extends TextualValue {
get displayValue() {
const choice = this.element.statusForValue(this.textValue);
return choice ? choice.label : this.textValue || '';
}
get searchableValue() {
return this.displayValue;
}
}

@@ -5,3 +5,3 @@ import TextualValue from './textual-value';

get columnValue() {
if (this.element.numeric) {
if (this.element.isNumeric) {
return this.numericValue;

@@ -8,0 +8,0 @@ }

@@ -9,7 +9,7 @@ import FormValue from './form-value';

this.textValue = textValue;
this.textValue = textValue != null ? textValue.toString() : null;
}
get isEmpty() {
return TextUtils.isEmpty(this.textValue);
return this.textValue == null || this.textValue.length === 0;
}

@@ -22,3 +22,3 @@

get searchableValue() {
return this.textValue || '';
return this.displayValue || '';
}

@@ -55,5 +55,5 @@

stringValue = (stringValue == null ? '' : stringValue.toString());
const string = (stringValue == null ? '' : stringValue.toString());
return this.textValue.toLowerCase() === stringValue.toLowerCase();
return this.textValue.toLowerCase() === string.toLowerCase();
}

@@ -70,5 +70,5 @@

stringValue = stringValue.toString();
const string = stringValue.toString();
return TextUtils.contains(this.textValue, stringValue);
return TextUtils.contains(this.textValue, string);
}

@@ -85,5 +85,3 @@

stringValue = stringValue.toString();
return TextUtils.startsWith(this.textValue, stringValue);
return TextUtils.startsWith(this.textValue, stringValue.toString());
}

@@ -96,9 +94,15 @@

let string = null;
if (stringValue != null) {
stringValue = stringValue.toString();
string = stringValue.toString();
}
const thisValue = NumberUtils.parseDouble(this.textValue);
const thatValue = NumberUtils.parseDouble(stringValue);
const thatValue = NumberUtils.parseDouble(string);
if (thisValue == null || thatValue == null) {
return false;
}
return thisValue < thatValue;

@@ -112,7 +116,11 @@ }

stringValue = (stringValue == null ? '' : stringValue.toString());
const string = (stringValue == null ? '' : stringValue.toString());
const thisValue = NumberUtils.parseDouble(this.textValue);
const thatValue = NumberUtils.parseDouble(stringValue);
const thatValue = NumberUtils.parseDouble(string);
if (thisValue == null || thatValue == null) {
return false;
}
return thisValue > thatValue;

@@ -124,2 +132,12 @@ }

}
get isNumeric() {
if (!this.isEmpty) {
const number = NumberUtils.parseDouble(this.textValue);
return number != null;
}
return true;
}
}

@@ -7,13 +7,3 @@ import TextualValue from './textual-value';

get displayValue() {
if (this.isEmpty) {
return null;
}
const time = this.timeValue();
if (time == null) {
return null;
}
return time;
return this.textValue;
}

@@ -30,3 +20,3 @@

const thisTime = this.timeValue();
const thisTime = this.timeValue;
const thatTime = DateUtils.parseTime(stringValue);

@@ -38,3 +28,3 @@

return thisTime.getTime() < thatTime.getTime();
return thisTime < thatTime;
}

@@ -47,3 +37,3 @@

const thisTime = this.timeValue();
const thisTime = this.timeValue;
const thatTime = DateUtils.parseTime(stringValue);

@@ -55,8 +45,28 @@

return thisTime.getTime() > thatTime.getTime();
return thisTime > thatTime;
}
timeValue() {
get isValid() {
if (this.isEmpty) {
return true;
}
return DateUtils.isValidTime(this.textValue);
}
get timeValue() {
if (this.isEmpty) {
return null;
}
return DateUtils.parseTime(this.textValue);
}
get columnValue() {
if (!this.isValid) {
return null;
}
return this.textValue || null;
}
}

@@ -12,6 +12,6 @@ import MediaValue from './media-value';

return '1 Video';
} else {
return `${this.length} Videos`;
}
return `${this.length} Videos`;
}
}

@@ -55,7 +55,7 @@ import setup from '../helper';

value.searchableValue.should.eql('1969-12-31');
value.searchableValue.should.eql('December 31, 1969');
value.toJSON().should.eql('1969-12-31');
value.columnValue.should.eql(-86400000);
value.columnValue.should.eql(-86400);
});

@@ -70,5 +70,5 @@

value.displayValue.should.eql('1337');
value.displayValue.should.eql('1,337');
value.searchableValue.should.eql('1337');
value.searchableValue.should.eql('1,337');

@@ -89,3 +89,3 @@ value.toJSON().should.eql('1337');

value.searchableValue.should.eql('1337.37');
value.searchableValue.should.eql('$1,337.37');

@@ -92,0 +92,0 @@ value.toJSON().should.eql('1337.37');

@@ -154,3 +154,3 @@ import setup from '../helper';

value.columnValue.should.eql('\t24\t38\tAnother\t');
value.columnValue.should.eql(['24', '38', 'Another']);

@@ -157,0 +157,0 @@ value.hasOtherValue.should.eql(true);

@@ -23,3 +23,3 @@ import setup from '../helper';

field.classificationItems[0].should.be.instanceof(Classification);
field.classificationItems[1].children[0].should.be.instanceof(Classification);
field.classificationItems[1].items[0].should.be.instanceof(Classification);
});

@@ -38,6 +38,6 @@

// override the options on the fly
field.classificationItems[1].children[0].should.be.instanceof(Classification);
field.classificationItems[1].children[0].value.should.eql('Red');
field.classificationItems[1].children[1].value.should.eql('Green');
field.classificationItems[1].children[2].value.should.eql('Blue');
field.classificationItems[1].items[0].should.be.instanceof(Classification);
field.classificationItems[1].items[0].value.should.eql('Red');
field.classificationItems[1].items[1].value.should.eql('Green');
field.classificationItems[1].items[2].value.should.eql('Blue');

@@ -47,4 +47,4 @@ // now bring the original items back

field.classificationItems[1].children[0].value.should.eql('Server');
field.classificationItems[2].children[0].value.should.eql('Ubuntu');
field.classificationItems[1].items[0].value.should.eql('Server');
field.classificationItems[2].items[0].value.should.eql('Ubuntu');
});

@@ -87,3 +87,3 @@

value.searchableValue.should.eql('Linux Linux Ubuntu Ubuntu 11.1 11.1');
value.searchableValue.should.eql('Linux Ubuntu 11.1');

@@ -94,3 +94,3 @@ value.toJSON().should.eql({ choice_values: [ 'Linux', 'Ubuntu', '11.1' ], other_values: [] });

value.columnValue.should.eql('Linux\tUbuntu\t11.1');
value.columnValue.should.eql(['Linux', 'Ubuntu', '11.1']);

@@ -109,3 +109,3 @@ value.hasOtherValue.should.eql(false);

const newItem = value.element.classificationItems[1].children[0].children[0];
const newItem = value.element.classificationItems[1].items[0].items[0];

@@ -120,3 +120,3 @@ value.setSelectedClassification(newItem);

value.searchableValue.should.eql('Windows Windows Server Server 2000 2000');
value.searchableValue.should.eql('Windows Server 2000');

@@ -127,3 +127,3 @@ value.toJSON().should.eql({ choice_values: [ 'Windows', 'Server', '2000' ], other_values: [] });

value.columnValue.should.eql('Windows\tServer\t2000');
value.columnValue.should.eql(['Windows', 'Server', '2000']);

@@ -156,3 +156,3 @@ value.hasOtherValue.should.eql(false);

// set an other value
const anotherItem = value.element.classificationItems[1].children[0];
const anotherItem = value.element.classificationItems[1].items[0];

@@ -167,3 +167,3 @@ value.setSelectedClassification(anotherItem, '2015');

value.searchableValue.should.eql('Windows Windows Server Server 2015');
value.searchableValue.should.eql('Windows Server 2015');

@@ -174,3 +174,3 @@ value.toJSON().should.eql({ choice_values: [ 'Windows', 'Server' ], other_values: [ '2015' ] });

value.columnValue.should.eql('Windows\tServer\t2015');
value.columnValue.should.eql(['Windows', 'Server', '2015']);

@@ -177,0 +177,0 @@ value.hasOtherValue.should.eql(true);

@@ -25,5 +25,5 @@ import setup from '../helper';

element.defaultValue.should.eql('no name');
element.required.should.eql(true);
element.hidden.should.eql(false);
element.disabled.should.eql(false);
element.isRequired.should.eql(true);
element.isHidden.should.eql(false);
element.isDisabled.should.eql(false);
element.minLength.should.eql(1);

@@ -30,0 +30,0 @@ element.maxLength.should.eql(30);

@@ -20,3 +20,3 @@ import setup from '../helper';

field.should.be.instanceof(TextElement);
field.numeric.should.eql(false);
field.isNumeric.should.eql(false);
field.pattern.should.eql('[a-zA-Z0-9]+');

@@ -23,0 +23,0 @@ field.patternDescription.should.eql('Alphanumeric Only');

@@ -1,1 +0,1 @@

{"form":{"name":"Test Form (fulcrum-core)","description":null,"bounding_box":[27.7695993399641,-82.6439975202084,27.7695993399641,-82.6439975202084],"record_title_key":"ae75","title_field_keys":["ae75","a861","cfe6"],"status_field":{"type":"StatusField","label":"Record Status","key":"@status","data_name":"status","default_value":"complete","enabled":true,"read_only":false,"hidden":false,"description":"","choices":[{"label":"Complete","value":"complete","color":"#87D30F"},{"label":"Pending","value":"pending","color":"#FFD300"},{"label":"Failed","value":"failed","color":"#CB0D0C"}],"required":false,"disabled":false,"default_previous_value":false},"auto_assign":false,"hidden_on_dashboard":false,"record_count":1,"geometry_types":["Point"],"geometry_required":false,"script":null,"id":"18300cfb-20e3-4e8b-9aef-878636b09ac4","created_at":"2015-12-03T01:36:21Z","updated_at":"2015-12-04T00:16:01Z","image":null,"image_thumbnail":null,"image_small":null,"image_large":null,"elements":[{"type":"TextField","key":"ae75","label":"Name","description":"Enter your name","required":true,"disabled":false,"hidden":false,"data_name":"name","default_value":"no name","visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":"[a-zA-Z0-9]+","pattern_description":"Alphanumeric Only","min_length":1,"max_length":30,"default_previous_value":false},{"type":"TextField","key":"a861","label":"Integer Number","description":null,"required":true,"disabled":false,"hidden":false,"data_name":"integer_number","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":true,"format":"integer","min":null,"max":null,"min_length":null,"max_length":null,"default_previous_value":false},{"type":"TextField","key":"cfe6","label":"Decimal Number","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"decimal_number","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":true,"format":"decimal","min":null,"max":null,"min_length":null,"max_length":null,"default_previous_value":false},{"type":"YesNoField","key":"3a9c","label":"Yes/No","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"yesno","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"positive":{"label":"Yes","value":"yes"},"negative":{"label":"No","value":"no"},"neutral":{"label":"N/A","value":"n/a"},"neutral_enabled":false,"default_previous_value":false},{"type":"YesNoField","key":"01ed","label":"Yes/No/NA","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"yesnona","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"positive":{"label":"Yes","value":"yes"},"negative":{"label":"No","value":"no"},"neutral":{"label":"N/A","value":"n/a"},"neutral_enabled":false,"default_previous_value":false},{"type":"ChoiceField","key":"31e8","label":"Single Choice","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"single_choice","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"multiple":false,"allow_other":false,"choice_list_id":"032804cc-496a-4c77-b102-ec0b237cbd10","default_previous_value":false},{"type":"ChoiceField","key":"f464","label":"Multiple Choice","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"multiple_choice","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"multiple":true,"allow_other":true,"choice_list_id":"e7cba93d-fcea-4c52-a9e1-b75f19908f25","min_length":null,"max_length":null,"default_previous_value":false},{"type":"ClassificationField","key":"4412","label":"OS","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"os","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"allow_other":true,"classification_set_id":"b2b43507-a734-4d29-a141-22f60c36af71","default_previous_value":false},{"type":"PhotoField","key":"e840","label":"Photos","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"photos","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"min_length":null,"max_length":null},{"type":"VideoField","key":"38b1","label":"Videos","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"videos","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"track_enabled":true,"audio_enabled":true,"min_length":null,"max_length":null},{"type":"AudioField","key":"8530","label":"Audio","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"audio","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"track_enabled":false,"min_length":null,"max_length":null},{"type":"BarcodeField","key":"849a","label":"Barcode","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"barcode","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"default_previous_value":false},{"type":"DateTimeField","key":"8fd4","label":"Date","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"date","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"default_previous_value":false},{"type":"TimeField","key":"dfd5","label":"Time","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"time","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"default_previous_value":false},{"type":"Section","key":"13db","label":"More Info Inline","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"more_info_inline","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"display":"inline","elements":[{"type":"TextField","key":"7b1f","label":"Sub Name Inline","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"sub_name_inline","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":null,"pattern_description":null,"min_length":null,"max_length":null,"default_previous_value":false}]},{"type":"Section","key":"e457","label":"More Info Drilldown","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"more_info_drilldown","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"display":"drilldown","elements":[{"type":"TextField","key":"b410","label":"Sub Name Drilldown","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"sub_name_drilldown","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":null,"pattern_description":null,"min_length":null,"max_length":null,"default_previous_value":false}]},{"type":"Repeatable","key":"cff5","label":"Rooms","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"rooms","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"elements":[{"type":"TextField","key":"bc81","label":"Room Number","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"room_number","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":null,"pattern_description":null,"min_length":null,"max_length":null,"default_previous_value":false}],"title_field_key":null,"title_field_keys":["bc81"],"geometry_types":["Point"],"geometry_required":false,"min_length":null,"max_length":null},{"type":"AddressField","key":"fe3c","label":"Address","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"address","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"auto_populate":true,"default_previous_value":false},{"type":"SignatureField","key":"93bd","label":"Signature","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"signature","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"agreement_text":""},{"type":"HyperlinkField","key":"0751","label":"Hyperlink","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"hyperlink","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"default_url":""},{"type":"CalculatedField","key":"e1f6","label":"Text Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"text_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"'text value'","display":{"style":"text","currency":null},"default_values":null,"default_previous_value":false},{"type":"CalculatedField","key":"857d","label":"Number Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"number_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"1337","display":{"style":"number","currency":null},"default_values":null,"default_previous_value":false},{"type":"CalculatedField","key":"0755","label":"Date Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"date_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"new Date(0);","display":{"style":"date","currency":null},"default_values":null,"default_previous_value":false},{"type":"CalculatedField","key":"ce49","label":"Currency Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"currency_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"1337.37","display":{"style":"currency","currency":"USD"},"default_values":null,"default_previous_value":false}]}}
{"form":{"name":"Test Form (fulcrum-core)","description":null,"projects_enabled":false,"assignment_enabled":false,"bounding_box":[27.7695993399641,-82.6439975202084,27.7695993399641,-82.6439975202084],"record_title_key":"ae75","title_field_keys":["ae75","a861","cfe6"],"status_field":{"type":"StatusField","label":"Record Status","key":"@status","data_name":"status","default_value":"complete","enabled":true,"read_only":false,"hidden":false,"description":"","choices":[{"label":"Complete","value":"complete","color":"#87D30F"},{"label":"Pending","value":"pending","color":"#FFD300"},{"label":"Failed","value":"failed","color":"#CB0D0C"}],"required":false,"disabled":false,"default_previous_value":false},"auto_assign":false,"hidden_on_dashboard":false,"record_count":1,"geometry_types":["Point"],"geometry_required":false,"script":null,"id":"18300cfb-20e3-4e8b-9aef-878636b09ac4","created_at":"2015-12-03T01:36:21Z","updated_at":"2015-12-04T00:16:01Z","image":null,"image_thumbnail":null,"image_small":null,"image_large":null,"elements":[{"type":"TextField","key":"ae75","label":"Name","description":"Enter your name","required":true,"disabled":false,"hidden":false,"data_name":"name","default_value":"no name","visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":"[a-zA-Z0-9]+","pattern_description":"Alphanumeric Only","min_length":1,"max_length":30,"default_previous_value":false},{"type":"TextField","key":"a861","label":"Integer Number","description":null,"required":true,"disabled":false,"hidden":false,"data_name":"integer_number","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":true,"format":"integer","min":null,"max":null,"min_length":null,"max_length":null,"default_previous_value":false},{"type":"TextField","key":"cfe6","label":"Decimal Number","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"decimal_number","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":true,"format":"decimal","min":null,"max":null,"min_length":null,"max_length":null,"default_previous_value":false},{"type":"YesNoField","key":"3a9c","label":"Yes/No","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"yesno","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"positive":{"label":"Yes","value":"yes"},"negative":{"label":"No","value":"no"},"neutral":{"label":"N/A","value":"n/a"},"neutral_enabled":false,"default_previous_value":false},{"type":"YesNoField","key":"01ed","label":"Yes/No/NA","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"yesnona","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"positive":{"label":"Yes","value":"yes"},"negative":{"label":"No","value":"no"},"neutral":{"label":"N/A","value":"n/a"},"neutral_enabled":false,"default_previous_value":false},{"type":"ChoiceField","key":"31e8","label":"Single Choice","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"single_choice","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"multiple":false,"allow_other":false,"choice_list_id":"032804cc-496a-4c77-b102-ec0b237cbd10","default_previous_value":false},{"type":"ChoiceField","key":"f464","label":"Multiple Choice","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"multiple_choice","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"multiple":true,"allow_other":true,"choice_list_id":"e7cba93d-fcea-4c52-a9e1-b75f19908f25","min_length":null,"max_length":null,"default_previous_value":false},{"type":"ClassificationField","key":"4412","label":"OS","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"os","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"allow_other":true,"classification_set_id":"b2b43507-a734-4d29-a141-22f60c36af71","default_previous_value":false},{"type":"PhotoField","key":"e840","label":"Photos","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"photos","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"min_length":null,"max_length":null},{"type":"VideoField","key":"38b1","label":"Videos","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"videos","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"track_enabled":true,"audio_enabled":true,"min_length":null,"max_length":null},{"type":"AudioField","key":"8530","label":"Audio","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"audio","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"track_enabled":false,"min_length":null,"max_length":null},{"type":"BarcodeField","key":"849a","label":"Barcode","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"barcode","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"default_previous_value":false},{"type":"DateTimeField","key":"8fd4","label":"Date","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"date","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"default_previous_value":false},{"type":"TimeField","key":"dfd5","label":"Time","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"time","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"default_previous_value":false},{"type":"Section","key":"13db","label":"More Info Inline","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"more_info_inline","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"display":"inline","elements":[{"type":"TextField","key":"7b1f","label":"Sub Name Inline","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"sub_name_inline","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":null,"pattern_description":null,"min_length":null,"max_length":null,"default_previous_value":false}]},{"type":"Section","key":"e457","label":"More Info Drilldown","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"more_info_drilldown","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"display":"drilldown","elements":[{"type":"TextField","key":"b410","label":"Sub Name Drilldown","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"sub_name_drilldown","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":null,"pattern_description":null,"min_length":null,"max_length":null,"default_previous_value":false}]},{"type":"Repeatable","key":"cff5","label":"Rooms","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"rooms","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"elements":[{"type":"TextField","key":"bc81","label":"Room Number","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"room_number","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"numeric":false,"pattern":null,"pattern_description":null,"min_length":null,"max_length":null,"default_previous_value":false}],"title_field_key":null,"title_field_keys":["bc81"],"geometry_types":["Point"],"geometry_required":false,"min_length":null,"max_length":null},{"type":"AddressField","key":"fe3c","label":"Address","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"address","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"auto_populate":true,"default_previous_value":false},{"type":"SignatureField","key":"93bd","label":"Signature","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"signature","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":null,"agreement_text":""},{"type":"HyperlinkField","key":"0751","label":"Hyperlink","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"hyperlink","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"default_url":""},{"type":"CalculatedField","key":"e1f6","label":"Text Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"text_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"'text value'","display":{"style":"text","currency":null},"default_values":null,"default_previous_value":false},{"type":"CalculatedField","key":"857d","label":"Number Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"number_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"1337","display":{"style":"number","currency":null},"default_values":null,"default_previous_value":false},{"type":"CalculatedField","key":"0755","label":"Date Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"date_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"new Date(0);","display":{"style":"date","currency":null},"default_values":null,"default_previous_value":false},{"type":"CalculatedField","key":"ce49","label":"Currency Calculation","description":null,"required":false,"disabled":false,"hidden":false,"data_name":"currency_calculation","default_value":null,"visible_conditions_type":null,"visible_conditions":null,"required_conditions_type":null,"required_conditions":[],"expression":"1337.37","display":{"style":"currency","currency":"USD"},"default_values":null,"default_previous_value":false}]}}

@@ -28,3 +28,3 @@ import fs from 'fs';

form.load(dataSource, () => {
record = new Record(recordJson);
record = new Record(recordJson, form);

@@ -31,0 +31,0 @@ record._form = form;

@@ -28,5 +28,4 @@ import fs from 'fs';

form.load(dataSource, () => {
record = new Record(recordJson);
record = new Record(recordJson, form);
record._form = form;
record._formValuesJSON = recordJson.form_values;

@@ -51,1 +50,11 @@

});
describe('Form', () => {
it('parses project_enabled', () => {
form.isProjectEnabled.should.eql(false);
});
it('parses assignment_enabled', () => {
form.isAssignmentEnabled.should.eql(false);
});
});

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc