diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 5bf6b6bf51..fcd4abe7cc 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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"; diff --git a/Telegram/SourceFiles/passport/passport_form_view_controller.cpp b/Telegram/SourceFiles/passport/passport_form_view_controller.cpp index 71c0057046..7cc168aa3d 100644 --- a/Telegram/SourceFiles/passport/passport_form_view_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_view_controller.cpp @@ -224,13 +224,15 @@ QString ComputeScopeRowReadyString(const Scope &scope) { list, keyForAttachmentTo, [](const std::pair &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; + } } } }; diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index d532496fd3..a902495de8 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -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( _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; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index 4446aed59f..528776c804 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -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 controller, + Scheme scheme, + const ValueMap &scanData, + const QString &missingScansError, + std::vector &&files, + std::map &&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 &&files, @@ -273,7 +298,7 @@ void PanelEditDocument::setupControls( } not_null PanelEditDocument::setupContent( - const ValueMap &data, + const ValueMap *data, const ValueMap *scanData, const QString &missingScansError, std::vector &&files, @@ -308,14 +333,6 @@ not_null PanelEditDocument::setupContent( st::passportFormDividerHeight)); } - inner->add( - object_ptr( - 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 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 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( + 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(inner, st::passportDetailsSkip)); + inner->add( + object_ptr(inner, st::passportDetailsSkip)); + } if (auto text = _controller->deleteValueLabel()) { inner->add( object_ptr( diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.h b/Telegram/SourceFiles/passport/passport_panel_edit_document.h index ed9e89a06c..a1a4ba7d01 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.h @@ -49,7 +49,8 @@ struct EditDocumentScheme { QString keyForAttachmentTo; // attach last_name to first_name }; std::vector rows; - QString rowsHeader; + QString fieldsHeader; + QString detailsHeader; QString scansHeader; }; @@ -67,6 +68,14 @@ public: const QString &missingScansError, std::vector &&files, std::map &&specialFiles); + PanelEditDocument( + QWidget *parent, + not_null controller, + Scheme scheme, + const ValueMap &scanData, + const QString &missingScansError, + std::vector &&files, + std::map &&specialFiles); PanelEditDocument( QWidget *parent, not_null 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 &&files, std::map &&specialFiles); not_null setupContent( - const ValueMap &data, + const ValueMap *data, const ValueMap *scanData, const QString &missingScansError, std::vector &&files,