2018-03-31 01:45:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
2018-04-05 17:01:22 +00:00
|
|
|
#include "passport/passport_panel_edit_document.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
#include "passport/passport_panel_controller.h"
|
|
|
|
#include "passport/passport_panel_details_row.h"
|
2018-04-04 19:26:40 +00:00
|
|
|
#include "passport/passport_panel_edit_scans.h"
|
2018-04-13 16:43:17 +00:00
|
|
|
#include "info/profile/info_profile_button.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
2018-04-10 07:51:19 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2018-08-14 11:37:03 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2019-06-17 16:59:43 +00:00
|
|
|
#include "ui/text/text_utilities.h" // Ui::Text::ToUpper
|
2018-03-31 01:45:40 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-04-09 17:56:07 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2018-03-31 01:45:40 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "styles/style_passport.h"
|
|
|
|
|
|
|
|
namespace Passport {
|
2018-04-10 07:51:19 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class RequestTypeBox : public BoxContent {
|
|
|
|
public:
|
|
|
|
RequestTypeBox(
|
|
|
|
QWidget*,
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> title,
|
2018-04-10 07:51:19 +00:00
|
|
|
const QString &about,
|
|
|
|
std::vector<QString> labels,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit);
|
2018-04-10 07:51:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setupControls(
|
|
|
|
const QString &about,
|
|
|
|
std::vector<QString> labels,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit);
|
2018-04-10 07:51:19 +00:00
|
|
|
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> _title;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _submit;
|
2018-04-10 07:51:19 +00:00
|
|
|
int _height = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
class DeleteDocumentBox : public BoxContent {
|
|
|
|
public:
|
|
|
|
DeleteDocumentBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &detailsCheckbox,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool withDetails)> submit);
|
2018-04-13 16:43:17 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setupControls(
|
|
|
|
const QString &text,
|
|
|
|
const QString &detailsCheckbox,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool withDetails)> submit);
|
2018-04-13 16:43:17 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _submit;
|
2018-04-13 16:43:17 +00:00
|
|
|
int _height = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-10 07:51:19 +00:00
|
|
|
RequestTypeBox::RequestTypeBox(
|
|
|
|
QWidget*,
|
2019-06-18 15:00:55 +00:00
|
|
|
rpl::producer<QString> title,
|
2018-04-10 07:51:19 +00:00
|
|
|
const QString &about,
|
|
|
|
std::vector<QString> labels,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit)
|
2019-06-18 15:00:55 +00:00
|
|
|
: _title(std::move(title)) {
|
2018-04-10 07:51:19 +00:00
|
|
|
setupControls(about, std::move(labels), submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTypeBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(std::move(_title));
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_passport_upload_document(), _submit);
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2018-04-10 07:51:19 +00:00
|
|
|
setDimensions(st::boxWidth, _height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RequestTypeBox::setupControls(
|
|
|
|
const QString &about,
|
|
|
|
std::vector<QString> labels,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit) {
|
2018-04-10 07:51:19 +00:00
|
|
|
const auto header = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
this,
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_document_type(tr::now),
|
2018-06-04 11:43:49 +00:00
|
|
|
st::boxDividerLabel);
|
2018-04-10 07:51:19 +00:00
|
|
|
|
|
|
|
const auto group = std::make_shared<Ui::RadiobuttonGroup>(0);
|
|
|
|
auto buttons = std::vector<QPointer<Ui::Radiobutton>>();
|
|
|
|
auto index = 0;
|
|
|
|
for (const auto &label : labels) {
|
2019-06-12 20:11:41 +00:00
|
|
|
buttons.emplace_back(Ui::CreateChild<Ui::Radiobutton>(
|
2018-04-10 07:51:19 +00:00
|
|
|
this,
|
|
|
|
group,
|
|
|
|
index++,
|
|
|
|
label,
|
|
|
|
st::defaultBoxCheckbox));
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto description = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
this,
|
|
|
|
about,
|
2018-06-04 11:43:49 +00:00
|
|
|
st::boxDividerLabel);
|
2018-04-10 07:51:19 +00:00
|
|
|
|
|
|
|
auto y = 0;
|
|
|
|
const auto innerWidth = st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::boxPadding.right();
|
|
|
|
header->resizeToWidth(innerWidth);
|
|
|
|
header->moveToLeft(st::boxPadding.left(), y);
|
|
|
|
y += header->height() + st::passportRequestTypeSkip;
|
|
|
|
for (const auto &button : buttons) {
|
|
|
|
button->resizeToNaturalWidth(innerWidth);
|
|
|
|
button->moveToLeft(st::boxPadding.left(), y);
|
|
|
|
y += button->heightNoMargins() + st::passportRequestTypeSkip;
|
|
|
|
}
|
|
|
|
description->resizeToWidth(innerWidth);
|
|
|
|
description->moveToLeft(st::boxPadding.left(), y);
|
|
|
|
y += description->height() + st::passportRequestTypeSkip;
|
|
|
|
_height = y;
|
|
|
|
|
|
|
|
_submit = [=] {
|
|
|
|
const auto value = group->hasValue() ? group->value() : -1;
|
|
|
|
if (value >= 0) {
|
|
|
|
submit(value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
DeleteDocumentBox::DeleteDocumentBox(
|
|
|
|
QWidget*,
|
|
|
|
const QString &text,
|
|
|
|
const QString &detailsCheckbox,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool withDetails)> submit) {
|
2018-04-13 16:43:17 +00:00
|
|
|
setupControls(text, detailsCheckbox, submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteDocumentBox::prepare() {
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_box_delete(), _submit);
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
2018-04-13 16:43:17 +00:00
|
|
|
|
|
|
|
setDimensions(st::boxWidth, _height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteDocumentBox::setupControls(
|
|
|
|
const QString &text,
|
|
|
|
const QString &detailsCheckbox,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool withDetails)> submit) {
|
2018-04-13 16:43:17 +00:00
|
|
|
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
this,
|
|
|
|
text,
|
|
|
|
st::boxLabel);
|
|
|
|
const auto details = !detailsCheckbox.isEmpty()
|
|
|
|
? Ui::CreateChild<Ui::Checkbox>(
|
|
|
|
this,
|
|
|
|
detailsCheckbox,
|
|
|
|
false,
|
|
|
|
st::defaultBoxCheckbox)
|
|
|
|
: nullptr;
|
|
|
|
|
|
|
|
_height = st::boxPadding.top();
|
|
|
|
const auto availableWidth = st::boxWidth
|
|
|
|
- st::boxPadding.left()
|
|
|
|
- st::boxPadding.right();
|
|
|
|
label->resizeToWidth(availableWidth);
|
|
|
|
label->moveToLeft(st::boxPadding.left(), _height);
|
|
|
|
_height += label->height();
|
|
|
|
|
|
|
|
if (details) {
|
|
|
|
_height += st::boxPadding.bottom();
|
|
|
|
details->moveToLeft(st::boxPadding.left(), _height);
|
|
|
|
_height += details->heightNoMargins();
|
|
|
|
}
|
|
|
|
_height += st::boxPadding.bottom();
|
|
|
|
|
|
|
|
_submit = [=] {
|
|
|
|
submit(details ? details->checked() : false);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-10 07:51:19 +00:00
|
|
|
} // namespace
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-04-09 17:56:07 +00:00
|
|
|
struct PanelEditDocument::Result {
|
|
|
|
ValueMap data;
|
|
|
|
ValueMap filesData;
|
|
|
|
};
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
PanelEditDocument::PanelEditDocument(
|
2018-03-31 01:45:40 +00:00
|
|
|
QWidget*,
|
|
|
|
not_null<PanelController*> controller,
|
2018-04-05 17:01:22 +00:00
|
|
|
Scheme scheme,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &error,
|
2018-03-31 01:45:40 +00:00
|
|
|
const ValueMap &data,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &scansError,
|
|
|
|
const ValueMap &scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles)
|
2018-03-31 01:45:40 +00:00
|
|
|
: _controller(controller)
|
2018-04-05 17:01:22 +00:00
|
|
|
, _scheme(std::move(scheme))
|
2018-03-31 01:45:40 +00:00
|
|
|
, _scroll(this, st::passportPanelScroll)
|
|
|
|
, _topShadow(this)
|
|
|
|
, _bottomShadow(this)
|
|
|
|
, _done(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_passport_save_value(),
|
2018-03-31 01:45:40 +00:00
|
|
|
st::passportPanelSaveValue) {
|
2018-04-17 17:54:52 +00:00
|
|
|
setupControls(
|
2018-08-14 11:37:03 +00:00
|
|
|
&error,
|
2018-08-14 06:42:06 +00:00
|
|
|
&data,
|
2018-08-14 11:37:03 +00:00
|
|
|
&scansError,
|
|
|
|
&scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::move(scans),
|
|
|
|
std::move(translations),
|
2018-08-14 06:42:06 +00:00
|
|
|
std::move(specialFiles));
|
|
|
|
}
|
|
|
|
|
|
|
|
PanelEditDocument::PanelEditDocument(
|
|
|
|
QWidget*,
|
|
|
|
not_null<PanelController*> controller,
|
|
|
|
Scheme scheme,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &scansError,
|
|
|
|
const ValueMap &scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles)
|
2018-08-14 06:42:06 +00:00
|
|
|
: _controller(controller)
|
|
|
|
, _scheme(std::move(scheme))
|
|
|
|
, _scroll(this, st::passportPanelScroll)
|
|
|
|
, _topShadow(this)
|
|
|
|
, _bottomShadow(this)
|
|
|
|
, _done(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_passport_save_value(),
|
2018-08-14 06:42:06 +00:00
|
|
|
st::passportPanelSaveValue) {
|
|
|
|
setupControls(
|
|
|
|
nullptr,
|
2018-08-14 11:37:03 +00:00
|
|
|
nullptr,
|
|
|
|
&scansError,
|
|
|
|
&scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::move(scans),
|
|
|
|
std::move(translations),
|
2018-05-11 22:55:56 +00:00
|
|
|
std::move(specialFiles));
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
PanelEditDocument::PanelEditDocument(
|
|
|
|
QWidget*,
|
|
|
|
not_null<PanelController*> controller,
|
|
|
|
Scheme scheme,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString &error,
|
2018-04-05 17:01:22 +00:00
|
|
|
const ValueMap &data)
|
|
|
|
: _controller(controller)
|
|
|
|
, _scheme(std::move(scheme))
|
|
|
|
, _scroll(this, st::passportPanelScroll)
|
|
|
|
, _topShadow(this)
|
|
|
|
, _bottomShadow(this)
|
|
|
|
, _done(
|
|
|
|
this,
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::lng_passport_save_value(),
|
2018-04-05 17:01:22 +00:00
|
|
|
st::passportPanelSaveValue) {
|
2018-08-14 15:27:47 +00:00
|
|
|
setupControls(&error, &data, nullptr, nullptr, {}, {}, {});
|
2018-04-05 17:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PanelEditDocument::setupControls(
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *error,
|
2018-08-14 06:42:06 +00:00
|
|
|
const ValueMap *data,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *scansError,
|
|
|
|
const ValueMap *scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles) {
|
2018-04-10 19:00:52 +00:00
|
|
|
const auto inner = setupContent(
|
2018-08-14 11:37:03 +00:00
|
|
|
error,
|
2018-04-10 19:00:52 +00:00
|
|
|
data,
|
2018-08-14 11:37:03 +00:00
|
|
|
scansError,
|
|
|
|
scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::move(scans),
|
|
|
|
std::move(translations),
|
2018-05-11 22:55:56 +00:00
|
|
|
std::move(specialFiles));
|
2018-03-31 01:45:40 +00:00
|
|
|
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
|
|
|
_topShadow->toggleOn(
|
|
|
|
_scroll->scrollTopValue() | rpl::map(_1 > 0));
|
|
|
|
_done->addClickHandler([=] {
|
|
|
|
crl::on_main(this, [=] {
|
|
|
|
save();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
not_null<Ui::RpWidget*> PanelEditDocument::setupContent(
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *error,
|
2018-08-14 06:42:06 +00:00
|
|
|
const ValueMap *data,
|
2018-08-14 11:37:03 +00:00
|
|
|
const QString *scansError,
|
|
|
|
const ValueMap *scansData,
|
2018-08-14 15:27:47 +00:00
|
|
|
ScanListData &&scans,
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<ScanListData> &&translations,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::map<FileType, ScanInfo> &&specialFiles) {
|
2018-03-31 01:45:40 +00:00
|
|
|
const auto inner = _scroll->setOwnedWidget(
|
|
|
|
object_ptr<Ui::VerticalLayout>(this));
|
|
|
|
_scroll->widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
inner->resizeToWidth(width);
|
|
|
|
}, inner->lifetime());
|
|
|
|
|
2018-05-11 22:55:56 +00:00
|
|
|
if (!specialFiles.empty()) {
|
|
|
|
_editScans = inner->add(
|
|
|
|
object_ptr<EditScans>(
|
|
|
|
inner,
|
|
|
|
_controller,
|
2018-08-17 14:59:07 +00:00
|
|
|
_scheme.scansHeader,
|
2018-08-14 11:37:03 +00:00
|
|
|
*scansError,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::move(specialFiles),
|
|
|
|
std::move(translations)));
|
2018-08-14 11:37:03 +00:00
|
|
|
} else if (scansData) {
|
2018-04-05 17:01:22 +00:00
|
|
|
_editScans = inner->add(
|
2018-04-10 07:51:19 +00:00
|
|
|
object_ptr<EditScans>(
|
|
|
|
inner,
|
|
|
|
_controller,
|
|
|
|
_scheme.scansHeader,
|
2018-08-14 11:37:03 +00:00
|
|
|
*scansError,
|
2018-08-14 15:27:47 +00:00
|
|
|
std::move(scans),
|
|
|
|
std::move(translations)));
|
2018-04-05 17:01:22 +00:00
|
|
|
}
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-06-08 19:26:08 +00:00
|
|
|
const auto enumerateRows = [&](auto &&callback) {
|
|
|
|
for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) {
|
|
|
|
const auto &row = _scheme.rows[i];
|
2018-08-17 13:42:07 +00:00
|
|
|
|
|
|
|
Assert(row.valueClass != Scheme::ValueClass::Additional
|
|
|
|
|| !_scheme.additionalDependencyKey.isEmpty());
|
|
|
|
auto fields = (row.valueClass == Scheme::ValueClass::Scans)
|
|
|
|
? scansData
|
|
|
|
: data;
|
2018-06-08 19:26:08 +00:00
|
|
|
if (!fields) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
callback(i, row, *fields);
|
2018-04-05 17:01:22 +00:00
|
|
|
}
|
2018-06-08 19:26:08 +00:00
|
|
|
};
|
|
|
|
auto maxLabelWidth = 0;
|
|
|
|
enumerateRows([&](
|
|
|
|
int i,
|
|
|
|
const EditDocumentScheme::Row &row,
|
|
|
|
const ValueMap &fields) {
|
|
|
|
accumulate_max(
|
|
|
|
maxLabelWidth,
|
|
|
|
PanelDetailsRow::LabelWidth(row.label));
|
|
|
|
});
|
2018-08-14 06:42:06 +00:00
|
|
|
if (maxLabelWidth > 0) {
|
2018-08-14 11:37:03 +00:00
|
|
|
if (error && !error->isEmpty()) {
|
|
|
|
_commonError = inner->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::FlatLabel>>(
|
|
|
|
inner,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
|
|
|
*error,
|
|
|
|
st::passportVerifyErrorLabel),
|
|
|
|
st::passportValueErrorPadding));
|
|
|
|
_commonError->toggle(true, anim::type::instant);
|
|
|
|
}
|
2018-08-14 06:42:06 +00:00
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
inner,
|
|
|
|
data ? _scheme.detailsHeader : _scheme.fieldsHeader,
|
|
|
|
st::passportFormHeader),
|
|
|
|
st::passportDetailsHeaderPadding);
|
|
|
|
enumerateRows([&](
|
|
|
|
int i,
|
2018-08-17 13:42:07 +00:00
|
|
|
const Scheme::Row &row,
|
2018-08-14 06:42:06 +00:00
|
|
|
const ValueMap &fields) {
|
2018-08-17 13:42:07 +00:00
|
|
|
if (row.valueClass != Scheme::ValueClass::Additional) {
|
|
|
|
createDetailsRow(inner, i, row, fields, maxLabelWidth);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (data && !_scheme.additionalDependencyKey.isEmpty()) {
|
|
|
|
const auto row = findRow(_scheme.additionalDependencyKey);
|
|
|
|
const auto wrap = inner->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
2018-08-14 11:37:03 +00:00
|
|
|
inner,
|
2018-08-17 13:42:07 +00:00
|
|
|
object_ptr<Ui::VerticalLayout>(inner)));
|
|
|
|
const auto added = wrap->entity();
|
2018-08-20 12:40:41 +00:00
|
|
|
|
|
|
|
auto showIfError = false;
|
|
|
|
enumerateRows([&](
|
|
|
|
int i,
|
|
|
|
const Scheme::Row &row,
|
|
|
|
const ValueMap &fields) {
|
|
|
|
if (row.valueClass != Scheme::ValueClass::Additional) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto it = fields.fields.find(row.key);
|
|
|
|
if (it == end(fields.fields)) {
|
|
|
|
return;
|
|
|
|
} else if (!it->second.error.isEmpty()) {
|
|
|
|
showIfError = true;
|
|
|
|
} else if (it->second.text.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto fallbackIt = fields.fields.find(
|
|
|
|
row.additionalFallbackKey);
|
|
|
|
if (fallbackIt != end(fields.fields)
|
|
|
|
&& fallbackIt->second.text != it->second.text) {
|
|
|
|
showIfError = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
const auto shown = [=](const QString &code) {
|
|
|
|
using Result = Scheme::AdditionalVisibility;
|
|
|
|
const auto value = _scheme.additionalShown(code);
|
|
|
|
return (value == Result::Shown)
|
|
|
|
|| (value == Result::OnlyIfError && showIfError);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto title = row->value(
|
|
|
|
) | rpl::filter(
|
|
|
|
shown
|
|
|
|
) | rpl::map([=](const QString &code) {
|
|
|
|
return _scheme.additionalHeader(code);
|
|
|
|
});
|
2018-08-17 13:42:07 +00:00
|
|
|
added->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
added,
|
2018-08-20 12:40:41 +00:00
|
|
|
std::move(title),
|
2018-08-17 13:42:07 +00:00
|
|
|
st::passportFormHeader),
|
|
|
|
st::passportNativeNameHeaderPadding);
|
|
|
|
|
|
|
|
enumerateRows([&](
|
|
|
|
int i,
|
|
|
|
const Scheme::Row &row,
|
|
|
|
const ValueMap &fields) {
|
|
|
|
if (row.valueClass == Scheme::ValueClass::Additional) {
|
|
|
|
createDetailsRow(added, i, row, fields, maxLabelWidth);
|
2018-08-14 11:37:03 +00:00
|
|
|
}
|
2018-08-17 13:42:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto description = row->value(
|
2018-08-20 12:40:41 +00:00
|
|
|
) | rpl::filter(
|
|
|
|
shown
|
|
|
|
) | rpl::map([=](const QString &code) {
|
2018-08-17 13:42:07 +00:00
|
|
|
return _scheme.additionalDescription(code);
|
|
|
|
});
|
|
|
|
added->add(
|
|
|
|
object_ptr<Ui::DividerLabel>(
|
|
|
|
added,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
added,
|
|
|
|
std::move(description),
|
|
|
|
st::boxDividerLabel),
|
|
|
|
st::passportFormLabelPadding),
|
|
|
|
st::passportNativeNameAboutMargin);
|
|
|
|
|
2018-08-20 12:40:41 +00:00
|
|
|
wrap->toggleOn(row->value() | rpl::map(shown));
|
2018-08-17 13:42:07 +00:00
|
|
|
wrap->finishAnimating();
|
2018-08-20 12:40:41 +00:00
|
|
|
|
|
|
|
row->value(
|
|
|
|
) | rpl::map(
|
|
|
|
shown
|
|
|
|
) | rpl::start_with_next([=](bool visible) {
|
|
|
|
_additionalShown = visible;
|
|
|
|
}, lifetime());
|
2018-08-17 13:42:07 +00:00
|
|
|
}
|
2018-03-31 01:45:40 +00:00
|
|
|
|
2018-08-14 06:42:06 +00:00
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(inner, st::passportDetailsSkip));
|
|
|
|
}
|
2018-04-13 16:43:17 +00:00
|
|
|
if (auto text = _controller->deleteValueLabel()) {
|
2018-04-13 16:48:59 +00:00
|
|
|
inner->add(
|
2018-04-13 16:43:17 +00:00
|
|
|
object_ptr<Info::Profile::Button>(
|
|
|
|
inner,
|
2019-06-17 16:59:43 +00:00
|
|
|
std::move(*text) | Ui::Text::ToUpper(),
|
2018-04-13 16:43:17 +00:00
|
|
|
st::passportDeleteButton),
|
2018-04-13 16:48:59 +00:00
|
|
|
st::passportUploadButtonPadding
|
|
|
|
)->addClickHandler([=] {
|
2018-04-13 16:43:17 +00:00
|
|
|
_controller->deleteValue();
|
|
|
|
});
|
|
|
|
}
|
2018-04-10 16:22:27 +00:00
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
return inner;
|
|
|
|
}
|
|
|
|
|
2018-08-17 13:42:07 +00:00
|
|
|
void PanelEditDocument::createDetailsRow(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
int i,
|
|
|
|
const Scheme::Row &row,
|
|
|
|
const ValueMap &fields,
|
|
|
|
int maxLabelWidth) {
|
|
|
|
const auto valueOrEmpty = [&](
|
2018-08-20 12:40:41 +00:00
|
|
|
const ValueMap &values,
|
|
|
|
const QString &key) {
|
2018-08-17 13:42:07 +00:00
|
|
|
const auto &fields = values.fields;
|
|
|
|
if (const auto i = fields.find(key); i != fields.end()) {
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
return ValueField();
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto current = valueOrEmpty(fields, row.key);
|
|
|
|
const auto [it, ok] = _details.emplace(
|
|
|
|
i,
|
|
|
|
container->add(PanelDetailsRow::Create(
|
|
|
|
container,
|
|
|
|
row.inputType,
|
|
|
|
_controller,
|
|
|
|
row.label,
|
|
|
|
maxLabelWidth,
|
|
|
|
current.text,
|
|
|
|
current.error,
|
|
|
|
row.lengthLimit)));
|
|
|
|
const bool details = (row.valueClass != Scheme::ValueClass::Scans);
|
|
|
|
it->second->value(
|
|
|
|
) | rpl::skip(1) | rpl::start_with_next([=] {
|
|
|
|
if (details) {
|
|
|
|
_fieldsChanged = true;
|
|
|
|
updateCommonError();
|
|
|
|
} else {
|
|
|
|
Assert(_editScans != nullptr);
|
|
|
|
_editScans->scanFieldsChanged(true);
|
|
|
|
}
|
|
|
|
}, it->second->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<PanelDetailsRow*> PanelEditDocument::findRow(
|
|
|
|
const QString &key) const {
|
|
|
|
for (auto i = 0, count = int(_scheme.rows.size()); i != count; ++i) {
|
|
|
|
const auto &row = _scheme.rows[i];
|
|
|
|
if (row.key == key) {
|
|
|
|
const auto it = _details.find(i);
|
|
|
|
Assert(it != end(_details));
|
|
|
|
return it->second.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Unexpected("Row not found in PanelEditDocument::findRow.");
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:37:03 +00:00
|
|
|
void PanelEditDocument::updateCommonError() {
|
|
|
|
if (_commonError) {
|
|
|
|
_commonError->toggle(!_fieldsChanged, anim::type::normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
void PanelEditDocument::focusInEvent(QFocusEvent *e) {
|
2018-04-13 05:11:53 +00:00
|
|
|
crl::on_main(this, [=] {
|
|
|
|
for (const auto [index, row] : _details) {
|
|
|
|
if (row->setFocusFast()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-05 17:01:22 +00:00
|
|
|
}
|
2018-04-13 05:11:53 +00:00
|
|
|
});
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
void PanelEditDocument::resizeEvent(QResizeEvent *e) {
|
2018-03-31 01:45:40 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:56:07 +00:00
|
|
|
bool PanelEditDocument::hasUnsavedChanges() const {
|
|
|
|
const auto result = collect();
|
|
|
|
return _controller->editScopeChanged(result.data, result.filesData);
|
|
|
|
}
|
|
|
|
|
2018-04-05 17:01:22 +00:00
|
|
|
void PanelEditDocument::updateControlsGeometry() {
|
2018-03-31 01:45:40 +00:00
|
|
|
const auto submitTop = height() - _done->height();
|
|
|
|
_scroll->setGeometry(0, 0, width(), submitTop);
|
|
|
|
_topShadow->resizeToWidth(width());
|
|
|
|
_topShadow->moveToLeft(0, 0);
|
|
|
|
_bottomShadow->resizeToWidth(width());
|
|
|
|
_bottomShadow->moveToLeft(0, submitTop - st::lineWidth);
|
|
|
|
_done->resizeToWidth(width());
|
|
|
|
_done->moveToLeft(0, submitTop);
|
|
|
|
|
|
|
|
_scroll->updateBars();
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:56:07 +00:00
|
|
|
PanelEditDocument::Result PanelEditDocument::collect() const {
|
|
|
|
auto result = Result();
|
2018-04-06 18:47:29 +00:00
|
|
|
for (const auto [i, field] : _details) {
|
2018-04-05 17:01:22 +00:00
|
|
|
const auto &row = _scheme.rows[i];
|
2018-08-17 13:42:07 +00:00
|
|
|
auto &fields = (row.valueClass == Scheme::ValueClass::Scans)
|
|
|
|
? result.filesData
|
|
|
|
: result.data;
|
2018-08-20 12:40:41 +00:00
|
|
|
if (row.valueClass == Scheme::ValueClass::Additional
|
|
|
|
&& !_additionalShown) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-15 15:06:53 +00:00
|
|
|
fields.fields[row.key].text = field->valueCurrent();
|
2018-04-05 17:01:22 +00:00
|
|
|
}
|
2018-08-20 12:40:41 +00:00
|
|
|
if (!_additionalShown) {
|
|
|
|
fillAdditionalFromFallbacks(result);
|
|
|
|
}
|
2018-04-09 17:56:07 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-20 12:40:41 +00:00
|
|
|
void PanelEditDocument::fillAdditionalFromFallbacks(Result &result) const {
|
|
|
|
for (const auto &row : _scheme.rows) {
|
|
|
|
if (row.valueClass != Scheme::ValueClass::Additional) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Assert(!row.additionalFallbackKey.isEmpty());
|
|
|
|
auto &fields = result.data;
|
|
|
|
const auto j = fields.fields.find(row.additionalFallbackKey);
|
|
|
|
Assert(j != end(fields.fields));
|
|
|
|
fields.fields[row.key] = j->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 10:10:09 +00:00
|
|
|
bool PanelEditDocument::validate() {
|
2018-08-14 11:37:03 +00:00
|
|
|
auto error = _editScans
|
2018-04-13 16:43:17 +00:00
|
|
|
? _editScans->validateGetErrorTop()
|
2018-09-21 16:28:46 +00:00
|
|
|
: std::nullopt;
|
2018-04-13 16:43:17 +00:00
|
|
|
if (error) {
|
2018-04-13 10:54:17 +00:00
|
|
|
const auto errortop = _editScans->mapToGlobal(QPoint(0, *error));
|
|
|
|
const auto scrolltop = _scroll->mapToGlobal(QPoint(0, 0));
|
|
|
|
const auto scrolldelta = errortop.y() - scrolltop.y();
|
|
|
|
_scroll->scrollToY(_scroll->scrollTop() + scrolldelta);
|
2018-08-14 11:37:03 +00:00
|
|
|
} else if (_commonError && !_fieldsChanged) {
|
|
|
|
const auto firsttop = _commonError->mapToGlobal(QPoint(0, 0));
|
|
|
|
const auto scrolltop = _scroll->mapToGlobal(QPoint(0, 0));
|
|
|
|
const auto scrolldelta = firsttop.y() - scrolltop.y();
|
|
|
|
_scroll->scrollToY(_scroll->scrollTop() + scrolldelta);
|
|
|
|
error = firsttop.y();
|
2018-04-13 10:54:17 +00:00
|
|
|
}
|
2018-04-13 10:10:09 +00:00
|
|
|
auto first = QPointer<PanelDetailsRow>();
|
2019-01-15 11:57:45 +00:00
|
|
|
for (const auto [i, field] : ranges::view::reverse(_details)) {
|
2018-04-13 10:10:09 +00:00
|
|
|
const auto &row = _scheme.rows[i];
|
2018-08-20 12:40:41 +00:00
|
|
|
if (row.valueClass == Scheme::ValueClass::Additional
|
|
|
|
&& !_additionalShown) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-15 13:35:59 +00:00
|
|
|
if (field->errorShown()) {
|
|
|
|
field->showError();
|
2018-04-13 10:10:09 +00:00
|
|
|
first = field;
|
2018-05-15 13:35:59 +00:00
|
|
|
} else if (row.error) {
|
|
|
|
if (const auto error = row.error(field->valueCurrent())) {
|
|
|
|
field->showError(error);
|
|
|
|
first = field;
|
|
|
|
}
|
2018-04-13 10:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-17 17:54:52 +00:00
|
|
|
if (error) {
|
|
|
|
return false;
|
|
|
|
} else if (!first) {
|
|
|
|
return true;
|
2018-04-13 10:10:09 +00:00
|
|
|
}
|
|
|
|
const auto firsttop = first->mapToGlobal(QPoint(0, 0));
|
|
|
|
const auto scrolltop = _scroll->mapToGlobal(QPoint(0, 0));
|
|
|
|
const auto scrolldelta = firsttop.y() - scrolltop.y();
|
|
|
|
_scroll->scrollToY(_scroll->scrollTop() + scrolldelta);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-09 17:56:07 +00:00
|
|
|
void PanelEditDocument::save() {
|
2018-04-13 10:10:09 +00:00
|
|
|
if (!validate()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-09 17:56:07 +00:00
|
|
|
auto result = collect();
|
|
|
|
_controller->saveScope(
|
|
|
|
std::move(result.data),
|
|
|
|
std::move(result.filesData));
|
2018-03-31 01:45:40 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 07:51:19 +00:00
|
|
|
object_ptr<BoxContent> RequestIdentityType(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit,
|
2018-04-10 07:51:19 +00:00
|
|
|
std::vector<QString> labels) {
|
|
|
|
return Box<RequestTypeBox>(
|
2019-06-18 15:00:55 +00:00
|
|
|
tr::lng_passport_identity_title(),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_identity_about(tr::now),
|
2018-04-10 07:51:19 +00:00
|
|
|
std::move(labels),
|
|
|
|
submit);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<BoxContent> RequestAddressType(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(int index)> submit,
|
2018-04-10 07:51:19 +00:00
|
|
|
std::vector<QString> labels) {
|
|
|
|
return Box<RequestTypeBox>(
|
2019-06-18 15:00:55 +00:00
|
|
|
tr::lng_passport_address_title(),
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_address_about(tr::now),
|
2018-04-10 07:51:19 +00:00
|
|
|
std::move(labels),
|
|
|
|
submit);
|
|
|
|
}
|
|
|
|
|
2018-04-13 16:43:17 +00:00
|
|
|
object_ptr<BoxContent> ConfirmDeleteDocument(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(bool withDetails)> submit,
|
2018-04-13 16:43:17 +00:00
|
|
|
const QString &text,
|
|
|
|
const QString &detailsCheckbox) {
|
|
|
|
return Box<DeleteDocumentBox>(text, detailsCheckbox, submit);
|
|
|
|
}
|
|
|
|
|
2018-03-31 01:45:40 +00:00
|
|
|
} // namespace Passport
|