/
ValueTransformer.countriesandstates.js
75 lines (62 loc) · 2.3 KB
/
ValueTransformer.countriesandstates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var ValueTransformer = function () {
this.displayName = "Countries and States";
this.shortDescription = "Generate countries and US states.";
this.isEditingDisabled = true;
this.infoUrl = "https://github.com/SmartJSONEditor/PublicDocuments/wiki/ValueTransformer-CountriesAndStates";
this.parameters = function () {
var popupDefaultValue = [
{ displayName: "Country Name", value: "country" },
{ displayName: "Country Abbreviation", value: "country_abb" },
{ displayName: "US States", value: "us_states" },
{ displayName: "US State Abbreviation", value: "us_state_abbreviation" },
];
var popupUIParam = {
name: "type",
type: "Popup",
displayName: "Generate type",
description: "Select option you like.",
defaultValue: popupDefaultValue
};
var segmentsOutputDefaultValues = [
{ displayName: "Prepend", enabled: 0 },
{ displayName: "Replace", enabled: 1 },
{ displayName: "Append", enabled: 0 }
];
var segmentsOutputUIParam = {
type: "Segments",
name: "output",
displayName: "Output",
description: "Prepend, replace or append value.",
defaultValue: segmentsOutputDefaultValues
};
return [popupUIParam, segmentsOutputUIParam];
}
this.transform = function (inputValue, jsonValue, arrayIndex, parameters, info) {
var value = "";
var type = (parameters.type.constructor == Array) ? "country" : parameters.type;
var separator = parameters.separator;
var listName = [];
var listSurname = [];
var hasName = true
var hasSurname = false;
if (type == "country") {
value = DocumentModel.randomValueDatabase("country");
}
if (type == "country_abb") {
value = DocumentModel.randomValueDatabase("countryCode");
}
if (type == "us_states") {
value = DocumentModel.randomValueDatabase("USState");
}
if (type == "us_state_abbreviation") {
value = DocumentModel.randomValueDatabase("USStateCode");
}
if (parameters.output[0].enabled == 1) { return value + inputValue; };
if (parameters.output[1].enabled == 1) { return value; };
if (parameters.output[2].enabled == 1) { return inputValue + value; };
return inputValue;
};
}
function sjeClass() {
return new ValueTransformer();
}