mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-05 22:29:34 +00:00
Add middle_name support to passport.
Also allow editing document without its details.
This commit is contained in:
parent
7c173bd63f
commit
36fcf2c60e
@ -1617,10 +1617,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_passport_reupload_main_page" = "Reupload a scan of the main page";
|
||||
"lng_passport_personal_details" = "Personal details";
|
||||
"lng_passport_personal_details_enter" = "Enter your personal details";
|
||||
"lng_passport_document_details" = "Document details";
|
||||
"lng_passport_choose_image" = "Choose scan image";
|
||||
"lng_passport_delete_scan_undo" = "Undo";
|
||||
"lng_passport_scan_uploaded" = "Uploaded on {date}";
|
||||
"lng_passport_first_name" = "Name";
|
||||
"lng_passport_middle_name" = "Middle name";
|
||||
"lng_passport_last_name" = "Surname";
|
||||
"lng_passport_birth_date" = "Date of birth";
|
||||
"lng_passport_gender" = "Gender";
|
||||
|
@ -224,13 +224,15 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
|
||||
list,
|
||||
keyForAttachmentTo,
|
||||
[](const std::pair<QString, QString> &value) {
|
||||
return value.first;
|
||||
});
|
||||
return value.first;
|
||||
});
|
||||
Assert(i != end(list));
|
||||
if (i->second.isEmpty()) {
|
||||
i->second = value.trimmed();
|
||||
} else {
|
||||
i->second += ' ' + value.trimmed();
|
||||
if (const auto data = value.trimmed(); !data.isEmpty()) {
|
||||
if (i->second.isEmpty()) {
|
||||
i->second = data;
|
||||
} else {
|
||||
i->second += ' ' + data;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -98,12 +98,19 @@ EditDocumentScheme GetDocumentScheme(
|
||||
const auto CountryValidate = FromBoolean([=](const QString &value) {
|
||||
return !CountryFormat(value).isEmpty();
|
||||
});
|
||||
const auto NameOrEmptyValidate = [=](const QString &value) -> Result {
|
||||
if (value.isEmpty()) {
|
||||
return base::none;
|
||||
}
|
||||
return NameValidate(value);
|
||||
};
|
||||
|
||||
// #TODO passport scheme
|
||||
switch (type) {
|
||||
case Scope::Type::Identity: {
|
||||
auto result = Scheme();
|
||||
result.rowsHeader = lang(lng_passport_personal_details);
|
||||
result.detailsHeader = lang(lng_passport_personal_details);
|
||||
result.fieldsHeader = lang(lng_passport_document_details);
|
||||
if (scansType) {
|
||||
switch (*scansType) {
|
||||
case Value::Type::Passport:
|
||||
@ -132,6 +139,16 @@ EditDocumentScheme GetDocumentScheme(
|
||||
DontFormat,
|
||||
kMaxNameSize,
|
||||
},
|
||||
{
|
||||
ValueClass::Fields,
|
||||
PanelDetailsType::Text,
|
||||
qsl("middle_name"),
|
||||
lang(lng_passport_middle_name),
|
||||
NameOrEmptyValidate,
|
||||
DontFormat,
|
||||
kMaxNameSize,
|
||||
qsl("first_name")
|
||||
},
|
||||
{
|
||||
ValueClass::Fields,
|
||||
PanelDetailsType::Text,
|
||||
@ -197,7 +214,7 @@ EditDocumentScheme GetDocumentScheme(
|
||||
|
||||
case Scope::Type::Address: {
|
||||
auto result = Scheme();
|
||||
result.rowsHeader = lang(lng_passport_address);
|
||||
result.detailsHeader = lang(lng_passport_address);
|
||||
if (scansType) {
|
||||
switch (*scansType) {
|
||||
case Value::Type::UtilityBill:
|
||||
@ -1048,12 +1065,16 @@ void PanelController::editScope(int index, int documentIndex) {
|
||||
_editDocument->scanMissingError,
|
||||
valueFiles(*_editDocument),
|
||||
valueSpecialFiles(*_editDocument))
|
||||
// #TODO passport document without details
|
||||
: object_ptr<PanelEditDocument>(
|
||||
_panel->widget(),
|
||||
this,
|
||||
GetDocumentScheme(_editScope->type),
|
||||
_editValue->data.parsedInEdit);
|
||||
GetDocumentScheme(
|
||||
_editScope->type,
|
||||
_editDocument->type),
|
||||
_editDocument->data.parsedInEdit,
|
||||
_editDocument->scanMissingError,
|
||||
valueFiles(*_editDocument),
|
||||
valueSpecialFiles(*_editDocument));
|
||||
const auto weak = make_weak(result.data());
|
||||
_panelHasUnsavedChanges = [=] {
|
||||
return weak ? weak->hasUnsavedChanges() : false;
|
||||
|
@ -224,7 +224,32 @@ PanelEditDocument::PanelEditDocument(
|
||||
langFactory(lng_passport_save_value),
|
||||
st::passportPanelSaveValue) {
|
||||
setupControls(
|
||||
data,
|
||||
&data,
|
||||
&scanData,
|
||||
missingScansError,
|
||||
std::move(files),
|
||||
std::move(specialFiles));
|
||||
}
|
||||
|
||||
PanelEditDocument::PanelEditDocument(
|
||||
QWidget*,
|
||||
not_null<PanelController*> controller,
|
||||
Scheme scheme,
|
||||
const ValueMap &scanData,
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
std::map<SpecialFile, ScanInfo> &&specialFiles)
|
||||
: _controller(controller)
|
||||
, _scheme(std::move(scheme))
|
||||
, _scroll(this, st::passportPanelScroll)
|
||||
, _topShadow(this)
|
||||
, _bottomShadow(this)
|
||||
, _done(
|
||||
this,
|
||||
langFactory(lng_passport_save_value),
|
||||
st::passportPanelSaveValue) {
|
||||
setupControls(
|
||||
nullptr,
|
||||
&scanData,
|
||||
missingScansError,
|
||||
std::move(files),
|
||||
@ -245,11 +270,11 @@ PanelEditDocument::PanelEditDocument(
|
||||
this,
|
||||
langFactory(lng_passport_save_value),
|
||||
st::passportPanelSaveValue) {
|
||||
setupControls(data, nullptr, QString(), {}, {});
|
||||
setupControls(&data, nullptr, QString(), {}, {});
|
||||
}
|
||||
|
||||
void PanelEditDocument::setupControls(
|
||||
const ValueMap &data,
|
||||
const ValueMap *data,
|
||||
const ValueMap *scanData,
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
@ -273,7 +298,7 @@ void PanelEditDocument::setupControls(
|
||||
}
|
||||
|
||||
not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
|
||||
const ValueMap &data,
|
||||
const ValueMap *data,
|
||||
const ValueMap *scanData,
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
@ -308,14 +333,6 @@ not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
|
||||
st::passportFormDividerHeight));
|
||||
}
|
||||
|
||||
inner->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
inner,
|
||||
_scheme.rowsHeader,
|
||||
Ui::FlatLabel::InitType::Simple,
|
||||
st::passportFormHeader),
|
||||
st::passportDetailsHeaderPadding);
|
||||
|
||||
const auto valueOrEmpty = [&](
|
||||
const ValueMap &values,
|
||||
const QString &key) {
|
||||
@ -330,7 +347,7 @@ not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
|
||||
for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) {
|
||||
const auto &row = _scheme.rows[i];
|
||||
auto fields = (row.valueClass == Scheme::ValueClass::Fields)
|
||||
? &data
|
||||
? data
|
||||
: scanData;
|
||||
if (!fields) {
|
||||
continue;
|
||||
@ -347,24 +364,33 @@ not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
|
||||
maxLabelWidth,
|
||||
PanelDetailsRow::LabelWidth(row.label));
|
||||
});
|
||||
enumerateRows([&](
|
||||
int i,
|
||||
const EditDocumentScheme::Row &row,
|
||||
const ValueMap &fields) {
|
||||
const auto current = valueOrEmpty(fields, row.key);
|
||||
_details.emplace(i, inner->add(PanelDetailsRow::Create(
|
||||
inner,
|
||||
row.inputType,
|
||||
_controller,
|
||||
row.label,
|
||||
maxLabelWidth,
|
||||
current.text,
|
||||
current.error,
|
||||
row.lengthLimit)));
|
||||
});
|
||||
if (maxLabelWidth > 0) {
|
||||
inner->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
inner,
|
||||
data ? _scheme.detailsHeader : _scheme.fieldsHeader,
|
||||
Ui::FlatLabel::InitType::Simple,
|
||||
st::passportFormHeader),
|
||||
st::passportDetailsHeaderPadding);
|
||||
enumerateRows([&](
|
||||
int i,
|
||||
const EditDocumentScheme::Row &row,
|
||||
const ValueMap &fields) {
|
||||
const auto current = valueOrEmpty(fields, row.key);
|
||||
_details.emplace(i, inner->add(PanelDetailsRow::Create(
|
||||
inner,
|
||||
row.inputType,
|
||||
_controller,
|
||||
row.label,
|
||||
maxLabelWidth,
|
||||
current.text,
|
||||
current.error,
|
||||
row.lengthLimit)));
|
||||
});
|
||||
|
||||
inner->add(
|
||||
object_ptr<Ui::FixedHeightWidget>(inner, st::passportDetailsSkip));
|
||||
inner->add(
|
||||
object_ptr<Ui::FixedHeightWidget>(inner, st::passportDetailsSkip));
|
||||
}
|
||||
if (auto text = _controller->deleteValueLabel()) {
|
||||
inner->add(
|
||||
object_ptr<Info::Profile::Button>(
|
||||
|
@ -49,7 +49,8 @@ struct EditDocumentScheme {
|
||||
QString keyForAttachmentTo; // attach last_name to first_name
|
||||
};
|
||||
std::vector<Row> rows;
|
||||
QString rowsHeader;
|
||||
QString fieldsHeader;
|
||||
QString detailsHeader;
|
||||
QString scansHeader;
|
||||
|
||||
};
|
||||
@ -67,6 +68,14 @@ public:
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
std::map<SpecialFile, ScanInfo> &&specialFiles);
|
||||
PanelEditDocument(
|
||||
QWidget *parent,
|
||||
not_null<PanelController*> controller,
|
||||
Scheme scheme,
|
||||
const ValueMap &scanData,
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
std::map<SpecialFile, ScanInfo> &&specialFiles);
|
||||
PanelEditDocument(
|
||||
QWidget *parent,
|
||||
not_null<PanelController*> controller,
|
||||
@ -82,13 +91,13 @@ protected:
|
||||
private:
|
||||
struct Result;
|
||||
void setupControls(
|
||||
const ValueMap &data,
|
||||
const ValueMap *data,
|
||||
const ValueMap *scanData,
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
std::map<SpecialFile, ScanInfo> &&specialFiles);
|
||||
not_null<Ui::RpWidget*> setupContent(
|
||||
const ValueMap &data,
|
||||
const ValueMap *data,
|
||||
const ValueMap *scanData,
|
||||
const QString &missingScansError,
|
||||
std::vector<ScanInfo> &&files,
|
||||
|
Loading…
Reference in New Issue
Block a user