journeyapps
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -549,2 +549,34 @@ // # schema module | ||
function NestedType(parent) { | ||
if(parent) { | ||
this.attributes = Object.create(parent.attributes); | ||
} else { | ||
this.attributes = {}; | ||
} | ||
} | ||
NestedType.prototype = new Type('scope'); | ||
NestedType.prototype.toJSON = function() { | ||
var result = {}; | ||
for(var key in this.attributes) { | ||
// Don't include parent keys | ||
if(this.attributes.hasOwnProperty(key)) { | ||
result[key] = this.attributes[key].toJSON(); | ||
} | ||
} | ||
return result; | ||
}; | ||
NestedType.fromJSON = function(schema, parent, data) { | ||
var type = new NestedType(parent); | ||
for(var name in data) { | ||
var varData = data[name]; | ||
var variable = parser.parseJsonVariable(schema, name, varData); | ||
type.addAttribute(variable); | ||
} | ||
return type; | ||
}; | ||
var exports = { | ||
@@ -556,2 +588,3 @@ Schema: Schema, | ||
ArrayType: ArrayType, | ||
NestedType: NestedType, | ||
Variable: Variable, | ||
@@ -558,0 +591,0 @@ EnumOption: EnumOption, |
@@ -11,2 +11,3 @@ // # schema module | ||
var NestedType = schema.NestedType; | ||
@@ -188,2 +189,10 @@ // This list specifies the *allowed* attributes on components, along with validations for those attributes. | ||
}, | ||
'object-repeat': { | ||
query: xml.attribute.notBlank, | ||
as: xml.attribute.notBlank, | ||
label: undefined, | ||
bind: undefined, | ||
required: undefined, | ||
_required: ['as'] | ||
}, | ||
'scan-barcode': { | ||
@@ -368,2 +377,3 @@ prompt: xml.attribute.label, | ||
var allowedColumnElements = {}; | ||
var allowedRepeatElements = {}; | ||
@@ -373,2 +383,3 @@ componentTags.forEach(function(componentName) { | ||
allowedColumnElements[componentName] = 4; | ||
allowedRepeatElements[componentName] = 4; | ||
}); | ||
@@ -398,12 +409,9 @@ | ||
function format(element, attribute, type) { | ||
if(typeof type === 'undefined') { | ||
type = view.type; | ||
} | ||
function format(element, attribute, scopeType) { | ||
var value = getAttribute(element, attribute); | ||
var formatString = evaluator.formatString(value); | ||
if(formatString !== null) { | ||
var errors = formatString.validate(type); | ||
var errors = formatString.validate(scopeType); | ||
if (recordReferences) { | ||
var validations = formatString.validateAndReturnRecordings(type); | ||
var validations = formatString.validateAndReturnRecordings(scopeType); | ||
for (var i = 0; i < validations.length; i++) { | ||
@@ -420,12 +428,9 @@ pushValidationRecording(validations[i]); | ||
function formatText(element, type) { | ||
if(typeof type === 'undefined') { | ||
type = view.type; | ||
} | ||
function formatText(element, scopeType) { | ||
var value = element.textContent; | ||
var formatString = evaluator.formatString(value); | ||
if(formatString !== null && type !== null) { | ||
var errors = formatString.validate(type); | ||
if(formatString !== null && scopeType !== null) { | ||
var errors = formatString.validate(scopeType); | ||
if (recordReferences) { | ||
var validations = formatString.validateAndReturnRecordings(type); | ||
var validations = formatString.validateAndReturnRecordings(scopeType); | ||
for (var i = 0; i < validations.length; i++) { | ||
@@ -446,3 +451,3 @@ pushValidationRecording(validations[i]); | ||
// TODO: dedup with schemaParser? | ||
function loadIntegerOptions(element, scope) { | ||
function loadIntegerOptions(element, scopeType) { | ||
var options = []; | ||
@@ -453,3 +458,3 @@ xml.children(element, 'option').forEach(function (e) { | ||
var key = keyText == null ? 0 : parseInt(keyText, 10); | ||
var label = formatText(e, scope); | ||
var label = formatText(e, scopeType); | ||
options.push({key: key, label: label}); | ||
@@ -460,3 +465,3 @@ }); | ||
function loadStringOptions(element, scope) { | ||
function loadStringOptions(element, scopeType) { | ||
var options = []; | ||
@@ -466,3 +471,3 @@ xml.children(element, 'option').forEach(function (e) { | ||
var key = getAttribute(e, 'key'); | ||
var label = formatText(e, scope); | ||
var label = formatText(e, scopeType); | ||
options.push({key: key, label: label}); | ||
@@ -473,3 +478,3 @@ }); | ||
function loadBooleanOptions(element, scope) { | ||
function loadBooleanOptions(element, scopeType) { | ||
var options = []; | ||
@@ -480,3 +485,3 @@ xml.children(element, 'option').forEach(function (e) { | ||
var key = {'true': true, 'false': false}[keyText]; | ||
var label = formatText(e, scope); | ||
var label = formatText(e, scopeType); | ||
if (key != null) { | ||
@@ -512,7 +517,7 @@ options.push({key: key, label: label}); | ||
view.title = format(root, 'title'); | ||
view.title = format(root, 'title', view.type); | ||
view.onBack = getAttribute(root, 'on-back'); | ||
// Sidebar | ||
parseSidebar(root); | ||
parseSidebar(root, view.type); | ||
@@ -523,3 +528,3 @@ // Components | ||
xml.children(root, componentTags).forEach(function(e) { | ||
var component = parseComponent(e); | ||
var component = parseComponent(e, view.type); | ||
view.components.push(component); | ||
@@ -593,3 +598,3 @@ }); | ||
function parseSidebar(root) { | ||
function parseSidebar(root, scopeType) { | ||
var sidebar = xml.children(root, 'sidebar')[0]; | ||
@@ -606,6 +611,6 @@ view.hasSidebar = (sidebar != null); | ||
onpress: getAttribute(element, tag.onPress), | ||
icon: format(element, 'icon'), | ||
label: formatText(element) | ||
icon: format(element, 'icon', view.type), | ||
label: formatText(element, view.type) | ||
}; | ||
parseShowHide(element, item); | ||
parseShowHide(element, item, scopeType); | ||
item.iconURI = iconUriFn(view, item); | ||
@@ -684,3 +689,3 @@ items.push(item); | ||
*/ | ||
function validateBinding(element, attr, allowFunctionBinding) { | ||
function validateBinding(element, attr, allowFunctionBinding, scopeType) { | ||
if (typeof allowFunctionBinding === 'undefined' || allowFunctionBinding == null) { | ||
@@ -702,3 +707,3 @@ allowFunctionBinding = false; | ||
} | ||
var bindingType = view.type.getType(binding); | ||
var bindingType = scopeType.getType(binding); | ||
if(bindingType == null) { | ||
@@ -710,3 +715,3 @@ pushError(xml.attributeNode(element, attr), 'Undefined variable ' + binding); | ||
function parseShowHide(element, component) { | ||
function parseShowHide(element, component, scopeType) { | ||
if(getAttribute(element, 'show-if')) { | ||
@@ -718,4 +723,4 @@ component.showIf = getAttribute(element, 'show-if'); | ||
} | ||
validateBinding(element, 'show-if', true); | ||
validateBinding(element, 'hide-if', true); | ||
validateBinding(element, 'show-if', true, scopeType); | ||
validateBinding(element, 'hide-if', true, scopeType); | ||
} | ||
@@ -754,3 +759,7 @@ | ||
// Parse a single component and its children. | ||
function parseComponent(element) { | ||
function parseComponent(element, scopeType) { | ||
if(scopeType == null) { | ||
scopeType = view.type; | ||
} | ||
parseElement(element, attributeMap); | ||
@@ -780,3 +789,3 @@ | ||
bindingVar = view.type.getVariable(component.bind); | ||
bindingVar = scopeType.getVariable(component.bind); | ||
component.bindingType = bindingVar == null ? null : bindingVar.type; | ||
@@ -798,3 +807,3 @@ | ||
} else if(labelString != null) { | ||
component.label = format(element, 'label'); | ||
component.label = format(element, 'label', scopeType); | ||
} else if(bindingVar != null && v3_1) { | ||
@@ -806,3 +815,3 @@ component.label = evaluator.formatString(bindingVar.label); | ||
parseShowHide(element, component); | ||
parseShowHide(element, component, scopeType); | ||
@@ -832,5 +841,5 @@ if(getAttribute(element, 'id')) { | ||
if(getAttribute(element, 'value')) { | ||
component.value = format(element, 'value'); | ||
component.value = format(element, 'value', scopeType); | ||
} else if(element.textContent) { | ||
component.value = formatText(element); | ||
component.value = formatText(element, scopeType); | ||
} | ||
@@ -853,6 +862,6 @@ } | ||
component.validate = getAttribute(element, 'validate') != 'false'; | ||
component.icon = format(element, 'icon'); | ||
component.icon = format(element, 'icon', scopeType); | ||
if(getAttribute(element, 'subtext')) { | ||
component.subtext = format(element, 'subtext'); | ||
component.subtext = format(element, 'subtext', scopeType); | ||
} | ||
@@ -880,3 +889,3 @@ | ||
components: [], | ||
label: format(columnEl, 'label'), | ||
label: format(columnEl, 'label', scopeType), | ||
hasLabel: false | ||
@@ -890,3 +899,3 @@ }; | ||
xml.children(columnEl, componentTags).forEach(function(e) { | ||
var inner = parseComponent(e); | ||
var inner = parseComponent(e, scopeType); | ||
column.components.push(inner); | ||
@@ -909,3 +918,3 @@ }); | ||
xml.children(element, rows).forEach(function(e) { | ||
var inner = parseComponent(e); | ||
var inner = parseComponent(e, scopeType); | ||
component.rows.push(inner); | ||
@@ -921,3 +930,3 @@ }); | ||
xml.children(element, 'button').forEach(function(e) { | ||
var inner = parseComponent(e); | ||
var inner = parseComponent(e, scopeType); | ||
inner.subtype = 'menu'; | ||
@@ -950,7 +959,7 @@ component.components.push(inner); | ||
if(component.bindingType.name == 'text' || component.bindingType.name == 'single-choice') { | ||
component.options = loadStringOptions(element, view.type); | ||
component.options = loadStringOptions(element, scopeType); | ||
} else if(component.bindingType.name == 'integer' || component.bindingType.name == 'single-choice-integer') { | ||
component.options = loadIntegerOptions(element, view.type); | ||
component.options = loadIntegerOptions(element, scopeType); | ||
} else if(component.bindingType.name == 'boolean') { | ||
component.options = loadBooleanOptions(element, view.type); | ||
component.options = loadBooleanOptions(element, scopeType); | ||
} | ||
@@ -966,5 +975,5 @@ } | ||
if(component.bindingType.name == 'multiple-choice') { | ||
component.options = loadStringOptions(element, view.type); | ||
component.options = loadStringOptions(element, scopeType); | ||
} else if(component.bindingType.name == 'multiple-choice-integer') { | ||
component.options = loadIntegerOptions(element, view.type); | ||
component.options = loadIntegerOptions(element, scopeType); | ||
} | ||
@@ -1023,3 +1032,3 @@ } | ||
if(type == 'html' || type == 'display-image') { | ||
component.src = format(element, 'src'); | ||
component.src = format(element, 'src', scopeType); | ||
} | ||
@@ -1045,3 +1054,3 @@ | ||
if(getAttribute(element, 'placeholder') != null) { | ||
component.placeholder = format(element, 'placeholder'); | ||
component.placeholder = format(element, 'placeholder', scopeType); | ||
} else { | ||
@@ -1052,2 +1061,32 @@ component.placeholder = component.label; | ||
if(type == 'object-repeat') { | ||
component.collection = getAttribute(element, 'query'); | ||
component.collectionType = scopeType.getType(component.collection); | ||
var asName = getAttribute(element, 'as'); | ||
component.components = []; | ||
if(component.collection == null) { | ||
pushError(element, 'query is required'); | ||
} else if(component.collectionType == null) { | ||
pushError(xml.attributeNode(element, 'query'), 'Undefined variable ' + component.collection); | ||
} else if(!component.collectionType.isCollection) { | ||
pushError(xml.attributeNode(element, 'query'), 'query must be a query or array'); | ||
} else { | ||
var nestedType = new NestedType(scopeType); | ||
var variable = new schema.Variable(asName, component.collectionType.objectType); | ||
component.as = variable; | ||
nestedType.addAttribute(variable); | ||
component.scopeType = nestedType; | ||
pushErrors(xml.validateChildren(element, allowedRepeatElements)); | ||
// We recursively parse the children of the object-repeat | ||
xml.children(element, componentTags).forEach(function(e) { | ||
var inner = parseComponent(e, nestedType); | ||
component.components.push(inner); | ||
}); | ||
} | ||
} | ||
if(type == 'list' || type == 'object-table' || type == 'object-dropdown' || type == 'object-list') { | ||
@@ -1057,3 +1096,3 @@ // <list bind="current_building" collection="all_buildings" type="static" label="Buildings" required="true"/> | ||
component.collection = getAttribute(element, 'collection') || getAttribute(element, 'query'); | ||
component.collectionType = view.type.getType(component.collection); | ||
component.collectionType = scopeType.getType(component.collection); | ||
@@ -1082,5 +1121,5 @@ if(component.collection == null) { | ||
if(getAttribute(element, 'emptyMessage') != null) { | ||
component.emptyMessage = format(element, 'emptyMessage'); | ||
component.emptyMessage = format(element, 'emptyMessage', scopeType); | ||
} else if(getAttribute(element, 'empty-message') != null) { | ||
component.emptyMessage = format(element, 'empty-message'); | ||
component.emptyMessage = format(element, 'empty-message', scopeType); | ||
} else { | ||
@@ -1116,3 +1155,3 @@ // Set empty message to null, Runtime sets to 'No data' | ||
var column = { | ||
heading: format(columnElement, 'heading'), | ||
heading: format(columnElement, 'heading', scopeType), | ||
value: formatText(columnElement, objectType) | ||
@@ -1119,0 +1158,0 @@ }; |
{ | ||
"name": "journeyapps", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Journey JS library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
447017
11451