2016-09-22 05:24:25 +00:00
|
|
|
var phones = [
|
|
|
|
{
|
|
|
|
number: "89171111111",
|
|
|
|
description: "Number format 1"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: "89371111111",
|
|
|
|
description: "Number format 1"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: "+79171111111",
|
|
|
|
description: "Number format 2"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
number: "9171111111",
|
|
|
|
description: "Number format 3"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
function suggestionsContainerStyle(suggestionsCount) {
|
|
|
|
return {
|
|
|
|
marginVertical: 1,
|
|
|
|
marginHorizontal: 0,
|
|
|
|
height: Math.min(150, (56 * suggestionsCount)),
|
|
|
|
backgroundColor: "white",
|
2016-11-12 09:25:48 +00:00
|
|
|
borderRadius: 5,
|
|
|
|
flex: 1
|
2016-09-22 05:24:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var suggestionContainerStyle = {
|
|
|
|
paddingLeft: 16,
|
|
|
|
backgroundColor: "white"
|
|
|
|
};
|
|
|
|
|
|
|
|
var suggestionSubContainerStyle = {
|
|
|
|
height: 56,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderBottomColor: "#0000001f"
|
|
|
|
};
|
|
|
|
|
|
|
|
var valueStyle = {
|
|
|
|
marginTop: 9,
|
|
|
|
fontSize: 14,
|
|
|
|
fontFamily: "font",
|
|
|
|
color: "#000000de"
|
|
|
|
};
|
|
|
|
|
|
|
|
var descriptionStyle = {
|
|
|
|
marginTop: 1.5,
|
|
|
|
fontSize: 14,
|
|
|
|
fontFamily: "font",
|
|
|
|
color: "#838c93de"
|
|
|
|
};
|
|
|
|
|
|
|
|
function startsWith(str1, str2) {
|
|
|
|
// String.startsWith(...) doesn't work in otto
|
|
|
|
return str1.lastIndexOf(str2, 0) == 0 && str1 != str2;
|
|
|
|
}
|
|
|
|
|
|
|
|
function phoneSuggestions(params) {
|
|
|
|
var ph, suggestions;
|
2016-10-06 13:15:57 +00:00
|
|
|
if (!params.phone || params.phone == "") {
|
2016-09-22 05:24:25 +00:00
|
|
|
ph = phones;
|
|
|
|
} else {
|
|
|
|
ph = phones.filter(function (phone) {
|
2016-10-06 13:15:57 +00:00
|
|
|
return startsWith(phone.number, params.phone);
|
2016-09-22 05:24:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ph.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
suggestions = ph.map(function (phone) {
|
|
|
|
return status.components.touchable(
|
|
|
|
{onPress: [status.events.SET_VALUE, phone.number]},
|
|
|
|
status.components.view(suggestionContainerStyle,
|
|
|
|
[status.components.view(suggestionSubContainerStyle,
|
|
|
|
[
|
|
|
|
status.components.text(
|
|
|
|
{style: valueStyle},
|
|
|
|
phone.number
|
|
|
|
),
|
|
|
|
status.components.text(
|
|
|
|
{style: descriptionStyle},
|
|
|
|
phone.description
|
|
|
|
)
|
|
|
|
])])
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-11-12 09:25:48 +00:00
|
|
|
/*var view = status.components.view(
|
|
|
|
{style: {flex: 1, flexDirection: "column"}},
|
|
|
|
[status.components.scrollView(
|
|
|
|
suggestionsContainerStyle(ph.length),
|
|
|
|
suggestions
|
|
|
|
)]
|
|
|
|
);*/
|
|
|
|
|
2016-09-22 05:24:25 +00:00
|
|
|
var view = status.components.scrollView(
|
|
|
|
suggestionsContainerStyle(ph.length),
|
|
|
|
suggestions
|
|
|
|
);
|
|
|
|
|
|
|
|
return {markup: view};
|
|
|
|
}
|
|
|
|
|
|
|
|
var phoneConfig = {
|
|
|
|
name: "phone",
|
2016-10-31 13:41:47 +00:00
|
|
|
icon: "phone_white",
|
2016-11-10 08:33:44 +00:00
|
|
|
title: "Send Phone Number",
|
|
|
|
description: "Find friends using your number",
|
2016-10-31 13:41:47 +00:00
|
|
|
color: "#5bb2a2",
|
2016-09-22 05:24:25 +00:00
|
|
|
params: [{
|
|
|
|
name: "phone",
|
|
|
|
type: status.types.PHONE,
|
|
|
|
suggestions: phoneSuggestions,
|
|
|
|
placeholder: "Phone number"
|
2016-10-19 12:22:05 +00:00
|
|
|
}]
|
2016-09-22 05:24:25 +00:00
|
|
|
};
|
|
|
|
status.response(phoneConfig);
|
|
|
|
status.command(phoneConfig);
|
|
|
|
|
|
|
|
|
|
|
|
status.command({
|
|
|
|
name: "help",
|
2016-11-10 08:33:44 +00:00
|
|
|
title: "Help",
|
|
|
|
description: "Request help from Console",
|
2016-09-22 05:24:25 +00:00
|
|
|
color: "#7099e6",
|
|
|
|
params: [{
|
|
|
|
name: "query",
|
|
|
|
type: status.types.TEXT
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
status.response({
|
|
|
|
name: "confirmation-code",
|
|
|
|
color: "#7099e6",
|
|
|
|
description: "Confirmation code",
|
|
|
|
params: [{
|
|
|
|
name: "code",
|
|
|
|
type: status.types.NUMBER
|
|
|
|
}],
|
2016-10-06 13:15:57 +00:00
|
|
|
validator: function (params) {
|
|
|
|
if (!/^[\d]{4}$/.test(params.code)) {
|
2016-09-22 05:24:25 +00:00
|
|
|
var error = status.components.validationMessage(
|
|
|
|
"Confirmation code",
|
|
|
|
"Wrong format"
|
|
|
|
);
|
|
|
|
|
|
|
|
return {errors: [error]}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
status.response({
|
2016-09-29 16:07:36 +00:00
|
|
|
name: "password",
|
2016-09-22 05:24:25 +00:00
|
|
|
color: "#7099e6",
|
2016-10-06 13:15:57 +00:00
|
|
|
description: "Password",
|
|
|
|
icon: "lock_white",
|
2016-09-22 05:24:25 +00:00
|
|
|
params: [{
|
|
|
|
name: "password",
|
2016-09-29 16:07:36 +00:00
|
|
|
type: status.types.PASSWORD,
|
|
|
|
placeholder: "Type your password"
|
2016-10-06 13:15:57 +00:00
|
|
|
}, {
|
|
|
|
name: "password-confirmation",
|
|
|
|
type: status.types.PASSWORD,
|
|
|
|
placeholder: "Please re-enter password to confirm"
|
2016-09-22 05:24:25 +00:00
|
|
|
}],
|
2016-10-06 13:15:57 +00:00
|
|
|
validator: function (params, context) {
|
|
|
|
var errorMessages = [];
|
|
|
|
var currentParameter = context["current-parameter"];
|
|
|
|
|
|
|
|
if (
|
|
|
|
currentParameter == "password" &&
|
|
|
|
params.password.length < 6
|
|
|
|
) {
|
|
|
|
errorMessages.push("Password should be not less then 6 symbols.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentParameter == "password-confirmation" &&
|
|
|
|
params.password != params["password-confirmation"]) {
|
|
|
|
errorMessages.push("Password confirmation doesn't match password.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errorMessages.length) {
|
|
|
|
var errors = [];
|
|
|
|
for (var idx in errorMessages) {
|
|
|
|
errors.push(
|
2016-09-19 11:47:02 +00:00
|
|
|
status.components.validationMessage(
|
|
|
|
"Password",
|
2016-10-06 13:15:57 +00:00
|
|
|
errorMessages[idx]
|
2016-09-19 11:47:02 +00:00
|
|
|
)
|
2016-10-06 13:15:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {errors: errors};
|
2016-09-19 11:47:02 +00:00
|
|
|
}
|
2016-10-06 13:15:57 +00:00
|
|
|
|
|
|
|
return {params: params, context: context};
|
2016-09-19 11:47:02 +00:00
|
|
|
},
|
2016-10-06 13:15:57 +00:00
|
|
|
preview: function (params, context) {
|
2016-09-29 16:07:36 +00:00
|
|
|
var style = {
|
|
|
|
marginTop: 5,
|
|
|
|
marginHorizontal: 0,
|
|
|
|
fontSize: 14,
|
|
|
|
color: "black"
|
|
|
|
};
|
|
|
|
|
2016-10-06 13:15:57 +00:00
|
|
|
if (context.platform == "ios") {
|
2016-09-29 16:07:36 +00:00
|
|
|
style.fontSize = 8;
|
|
|
|
style.marginTop = 10;
|
|
|
|
style.marginBottom = 2;
|
|
|
|
style.letterSpacing = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status.components.text({style: style}, "●●●●●●●●●●");
|
2016-09-22 05:24:25 +00:00
|
|
|
}
|
|
|
|
});
|