2018-03-29 23:49:31 +04: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-03-31 05:45:40 +04:00
|
|
|
#include "passport/passport_panel_controller.h"
|
2018-03-29 23:49:31 +04:00
|
|
|
|
|
|
|
#include "lang/lang_keys.h"
|
2018-04-05 21:01:22 +04:00
|
|
|
#include "passport/passport_panel_edit_document.h"
|
2018-04-06 15:54:01 +04:00
|
|
|
#include "passport/passport_panel_edit_contact.h"
|
2018-03-31 05:45:40 +04:00
|
|
|
#include "passport/passport_panel.h"
|
2018-03-29 23:49:31 +04:00
|
|
|
#include "boxes/confirm_box.h"
|
2018-03-31 05:45:40 +04:00
|
|
|
#include "layout.h"
|
2018-03-29 23:49:31 +04:00
|
|
|
|
|
|
|
namespace Passport {
|
2018-04-05 21:01:22 +04:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
PanelEditDocument::Scheme GetDocumentScheme(Scope::Type type) {
|
|
|
|
using Scheme = PanelEditDocument::Scheme;
|
|
|
|
|
|
|
|
const auto DontValidate = nullptr;
|
|
|
|
const auto NotEmptyValidate = [](const QString &value) {
|
|
|
|
return !value.isEmpty();
|
|
|
|
};
|
|
|
|
const auto DateValidate = [](const QString &value) {
|
|
|
|
return QRegularExpression(
|
|
|
|
"^\\d{2}\\.\\d{2}\\.\\d{4}$"
|
|
|
|
).match(value).hasMatch();
|
|
|
|
};
|
|
|
|
const auto DateOrEmptyValidate = [=](const QString &value) {
|
|
|
|
return value.isEmpty() || DateValidate(value);
|
|
|
|
};
|
|
|
|
const auto GenderValidate = [](const QString &value) {
|
|
|
|
return value == qstr("male") || value == qstr("female");
|
|
|
|
};
|
|
|
|
const auto CountryValidate = [](const QString &value) {
|
|
|
|
return QRegularExpression("^[A-Z]{2}$").match(value).hasMatch();
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case Scope::Type::Identity: {
|
|
|
|
auto result = Scheme();
|
2018-04-06 15:54:01 +04:00
|
|
|
result.rowsHeader = lang(lng_passport_personal_details);
|
2018-04-05 21:01:22 +04:00
|
|
|
result.rows = {
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("first_name"),
|
|
|
|
lang(lng_passport_first_name),
|
|
|
|
NotEmptyValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("last_name"),
|
|
|
|
lang(lng_passport_last_name),
|
|
|
|
DontValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("birth_date"),
|
|
|
|
lang(lng_passport_birth_date),
|
|
|
|
DateValidate,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("gender"),
|
|
|
|
lang(lng_passport_gender),
|
|
|
|
GenderValidate,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("country_code"),
|
|
|
|
lang(lng_passport_country),
|
|
|
|
CountryValidate,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Scans,
|
|
|
|
qsl("document_no"),
|
|
|
|
lang(lng_passport_document_number),
|
|
|
|
NotEmptyValidate,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Scans,
|
|
|
|
qsl("expiry_date"),
|
|
|
|
lang(lng_passport_expiry_date),
|
|
|
|
DateOrEmptyValidate,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Scope::Type::Address: {
|
|
|
|
auto result = Scheme();
|
2018-04-06 15:54:01 +04:00
|
|
|
result.rowsHeader = lang(lng_passport_address);
|
2018-04-05 21:01:22 +04:00
|
|
|
result.rows = {
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("street_line1"),
|
|
|
|
lang(lng_passport_street),
|
|
|
|
NotEmptyValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("street_line2"),
|
|
|
|
lang(lng_passport_street),
|
|
|
|
DontValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("city"),
|
|
|
|
lang(lng_passport_city),
|
|
|
|
NotEmptyValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("state"),
|
|
|
|
lang(lng_passport_state),
|
|
|
|
DontValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("country_code"),
|
|
|
|
lang(lng_passport_country),
|
|
|
|
CountryValidate
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Scheme::ValueType::Fields,
|
|
|
|
qsl("post_code"),
|
|
|
|
lang(lng_passport_postcode),
|
|
|
|
NotEmptyValidate
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
Unexpected("Type in GetDocumentScheme().");
|
|
|
|
}
|
|
|
|
|
2018-04-06 15:54:01 +04:00
|
|
|
PanelEditContact::Scheme GetContactScheme(Scope::Type type) {
|
|
|
|
using Scheme = PanelEditContact::Scheme;
|
|
|
|
switch (type) {
|
|
|
|
case Scope::Type::Phone: {
|
|
|
|
auto result = Scheme();
|
|
|
|
result.aboutExisting = lang(lng_passport_use_existing_phone);
|
|
|
|
result.newHeader = lang(lng_passport_new_phone);
|
|
|
|
result.aboutNew = lang(lng_passport_new_phone_code);
|
|
|
|
result.validate = [](const QString &value) {
|
|
|
|
return QRegularExpression(
|
|
|
|
"^\\d{2,12}$"
|
|
|
|
).match(value).hasMatch();
|
|
|
|
};
|
|
|
|
result.preprocess = [](const QString &value) {
|
|
|
|
return App::formatPhone(value);
|
|
|
|
};
|
|
|
|
result.postprocess = [](QString value) {
|
|
|
|
return value.replace(QRegularExpression("[^\\d]"), QString());
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case Scope::Type::Email: {
|
|
|
|
auto result = Scheme();
|
|
|
|
result.aboutExisting = lang(lng_passport_use_existing_email);
|
|
|
|
result.newHeader = lang(lng_passport_new_email);
|
|
|
|
result.newPlaceholder = langFactory(lng_passport_email_title);
|
|
|
|
result.aboutNew = lang(lng_passport_new_email_code);
|
|
|
|
result.validate = [](const QString &value) {
|
|
|
|
const auto at = value.indexOf('@');
|
|
|
|
const auto dot = value.lastIndexOf('.');
|
|
|
|
return (at > 0) && (dot > at);
|
|
|
|
};
|
|
|
|
result.preprocess = result.postprocess = [](const QString &value) {
|
|
|
|
return value.trimmed();
|
|
|
|
};
|
|
|
|
return result;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
Unexpected("Type in GetContactScheme().");
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:01:22 +04:00
|
|
|
} // namespace
|
2018-03-29 23:49:31 +04:00
|
|
|
|
|
|
|
BoxPointer::BoxPointer(QPointer<BoxContent> value)
|
|
|
|
: _value(value) {
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxPointer::BoxPointer(BoxPointer &&other)
|
|
|
|
: _value(base::take(other._value)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxPointer &BoxPointer::operator=(BoxPointer &&other) {
|
|
|
|
std::swap(_value, other._value);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxPointer::~BoxPointer() {
|
|
|
|
if (const auto strong = get()) {
|
|
|
|
strong->closeBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxContent *BoxPointer::get() const {
|
|
|
|
return _value.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxPointer::operator BoxContent*() const {
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxPointer::operator bool() const {
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxContent *BoxPointer::operator->() const {
|
|
|
|
return get();
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
PanelController::PanelController(not_null<FormController*> form)
|
2018-04-03 22:24:31 +04:00
|
|
|
: _form(form)
|
|
|
|
, _scopes(ComputeScopes(_form)) {
|
2018-03-31 05:45:40 +04:00
|
|
|
_form->secretReadyEvents(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (_panel) {
|
|
|
|
_panel->showForm();
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2018-04-03 22:24:31 +04:00
|
|
|
_scopes = ComputeScopes(_form);
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
not_null<UserData*> PanelController::bot() const {
|
2018-03-29 23:49:31 +04:00
|
|
|
return _form->bot();
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
QString PanelController::privacyPolicyUrl() const {
|
|
|
|
return _form->privacyPolicyUrl();
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
void PanelController::fillRows(
|
2018-03-29 23:49:31 +04:00
|
|
|
base::lambda<void(
|
|
|
|
QString title,
|
|
|
|
QString description,
|
|
|
|
bool ready)> callback) {
|
2018-04-03 22:24:31 +04:00
|
|
|
if (_scopes.empty()) {
|
|
|
|
_scopes = ComputeScopes(_form);
|
|
|
|
}
|
|
|
|
for (const auto &scope : _scopes) {
|
|
|
|
switch (scope.type) {
|
|
|
|
case Scope::Type::Identity:
|
2018-03-29 23:49:31 +04:00
|
|
|
callback(
|
|
|
|
lang(lng_passport_identity_title),
|
|
|
|
lang(lng_passport_identity_description),
|
|
|
|
false);
|
|
|
|
break;
|
2018-04-03 22:24:31 +04:00
|
|
|
case Scope::Type::Address:
|
2018-03-29 23:49:31 +04:00
|
|
|
callback(
|
|
|
|
lang(lng_passport_address_title),
|
|
|
|
lang(lng_passport_address_description),
|
|
|
|
false);
|
|
|
|
break;
|
2018-04-03 22:24:31 +04:00
|
|
|
case Scope::Type::Phone:
|
2018-03-29 23:49:31 +04:00
|
|
|
callback(
|
|
|
|
lang(lng_passport_phone_title),
|
2018-04-03 22:24:31 +04:00
|
|
|
lang(lng_passport_phone_description),
|
|
|
|
false);
|
2018-03-29 23:49:31 +04:00
|
|
|
break;
|
2018-04-03 22:24:31 +04:00
|
|
|
case Scope::Type::Email:
|
2018-03-29 23:49:31 +04:00
|
|
|
callback(
|
|
|
|
lang(lng_passport_email_title),
|
|
|
|
lang(lng_passport_email_description),
|
|
|
|
false);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-03 22:24:31 +04:00
|
|
|
}
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
void PanelController::submitPassword(const QString &password) {
|
2018-03-29 23:49:31 +04:00
|
|
|
_form->submitPassword(password);
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
rpl::producer<QString> PanelController::passwordError() const {
|
2018-03-29 23:49:31 +04:00
|
|
|
return _form->passwordError();
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
QString PanelController::passwordHint() const {
|
2018-03-29 23:49:31 +04:00
|
|
|
return _form->passwordHint();
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
QString PanelController::defaultEmail() const {
|
2018-03-29 23:49:31 +04:00
|
|
|
return _form->defaultEmail();
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
QString PanelController::defaultPhoneNumber() const {
|
2018-03-29 23:49:31 +04:00
|
|
|
return _form->defaultPhoneNumber();
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
void PanelController::uploadScan(QByteArray &&content) {
|
|
|
|
Expects(_editScope != nullptr);
|
|
|
|
Expects(_editScopeFilesIndex >= 0);
|
2018-03-29 23:49:31 +04:00
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
_form->uploadScan(
|
|
|
|
_editScope->files[_editScopeFilesIndex],
|
|
|
|
std::move(content));
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
void PanelController::deleteScan(int fileIndex) {
|
|
|
|
Expects(_editScope != nullptr);
|
|
|
|
Expects(_editScopeFilesIndex >= 0);
|
2018-03-29 23:49:31 +04:00
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
_form->deleteScan(
|
|
|
|
_editScope->files[_editScopeFilesIndex],
|
|
|
|
fileIndex);
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
void PanelController::restoreScan(int fileIndex) {
|
|
|
|
Expects(_editScope != nullptr);
|
|
|
|
Expects(_editScopeFilesIndex >= 0);
|
2018-03-31 05:45:40 +04:00
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
_form->restoreScan(
|
|
|
|
_editScope->files[_editScopeFilesIndex],
|
|
|
|
fileIndex);
|
2018-03-31 05:45:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<ScanInfo> PanelController::scanUpdated() const {
|
2018-03-29 23:49:31 +04:00
|
|
|
return _form->scanUpdated(
|
2018-04-03 22:24:31 +04:00
|
|
|
) | rpl::filter([=](not_null<const EditFile*> file) {
|
|
|
|
return (_editScope != nullptr)
|
|
|
|
&& (_editScopeFilesIndex >= 0)
|
|
|
|
&& (file->value == _editScope->files[_editScopeFilesIndex]);
|
|
|
|
}) | rpl::map([=](not_null<const EditFile*> file) {
|
2018-03-29 23:49:31 +04:00
|
|
|
return collectScanInfo(*file);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
ScanInfo PanelController::collectScanInfo(const EditFile &file) const {
|
2018-03-29 23:49:31 +04:00
|
|
|
const auto status = [&] {
|
2018-03-31 05:45:40 +04:00
|
|
|
if (file.fields.accessHash) {
|
2018-03-29 23:49:31 +04:00
|
|
|
if (file.fields.downloadOffset < 0) {
|
2018-03-31 05:45:40 +04:00
|
|
|
return lang(lng_attach_failed);
|
2018-03-29 23:49:31 +04:00
|
|
|
} else if (file.fields.downloadOffset < file.fields.size) {
|
2018-03-31 05:45:40 +04:00
|
|
|
return formatDownloadText(
|
|
|
|
file.fields.downloadOffset,
|
|
|
|
file.fields.size);
|
2018-03-29 23:49:31 +04:00
|
|
|
} else {
|
2018-03-31 05:45:40 +04:00
|
|
|
return lng_passport_scan_uploaded(
|
|
|
|
lt_date,
|
|
|
|
langDateTimeFull(ParseDateTime(file.fields.date)));
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
} else if (file.uploadData) {
|
|
|
|
if (file.uploadData->offset < 0) {
|
2018-03-31 05:45:40 +04:00
|
|
|
return lang(lng_attach_failed);
|
2018-03-29 23:49:31 +04:00
|
|
|
} else if (file.uploadData->fullId) {
|
2018-03-31 05:45:40 +04:00
|
|
|
return formatDownloadText(
|
|
|
|
file.uploadData->offset,
|
|
|
|
file.uploadData->bytes.size());
|
2018-03-29 23:49:31 +04:00
|
|
|
} else {
|
2018-03-31 05:45:40 +04:00
|
|
|
return lng_passport_scan_uploaded(
|
|
|
|
lt_date,
|
|
|
|
langDateTimeFull(ParseDateTime(file.fields.date)));
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
} else {
|
2018-03-31 05:45:40 +04:00
|
|
|
return formatDownloadText(0, file.fields.size);
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
}();
|
|
|
|
return {
|
|
|
|
FileKey{ file.fields.id, file.fields.dcId },
|
|
|
|
status,
|
2018-03-31 05:45:40 +04:00
|
|
|
file.fields.image,
|
|
|
|
file.deleted };
|
|
|
|
}
|
|
|
|
|
2018-04-06 15:54:01 +04:00
|
|
|
QString PanelController::getDefaultContactValue(Scope::Type type) const {
|
|
|
|
switch (type) {
|
|
|
|
case Scope::Type::Phone:
|
|
|
|
return _form->defaultPhoneNumber();
|
|
|
|
case Scope::Type::Email:
|
|
|
|
return _form->defaultEmail();
|
|
|
|
}
|
|
|
|
Unexpected("Type in PanelController::getDefaultContactValue().");
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
void PanelController::showAskPassword() {
|
|
|
|
ensurePanelCreated();
|
|
|
|
_panel->showAskPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelController::showNoPassword() {
|
|
|
|
ensurePanelCreated();
|
|
|
|
_panel->showNoPassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PanelController::showPasswordUnconfirmed() {
|
|
|
|
ensurePanelCreated();
|
|
|
|
_panel->showPasswordUnconfirmed();
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
void PanelController::ensurePanelCreated() {
|
|
|
|
if (!_panel) {
|
|
|
|
_panel = std::make_unique<Panel>(this);
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
void PanelController::editScope(int index) {
|
2018-03-31 05:45:40 +04:00
|
|
|
Expects(_panel != nullptr);
|
2018-04-03 22:24:31 +04:00
|
|
|
Expects(index >= 0 && index < _scopes.size());
|
|
|
|
|
|
|
|
_editScope = &_scopes[index];
|
2018-03-31 05:45:40 +04:00
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
// #TODO select type for files index
|
|
|
|
_editScopeFilesIndex = _scopes[index].files.empty() ? -1 : 0;
|
|
|
|
|
|
|
|
_form->startValueEdit(_editScope->fields);
|
|
|
|
if (_editScopeFilesIndex >= 0) {
|
|
|
|
_form->startValueEdit(_editScope->files[_editScopeFilesIndex]);
|
|
|
|
}
|
2018-03-29 23:49:31 +04:00
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
auto content = [&]() -> object_ptr<Ui::RpWidget> {
|
2018-04-03 22:24:31 +04:00
|
|
|
switch (_editScope->type) {
|
|
|
|
case Scope::Type::Identity:
|
2018-04-05 21:01:22 +04:00
|
|
|
case Scope::Type::Address:
|
|
|
|
return (_editScopeFilesIndex >= 0)
|
|
|
|
? object_ptr<PanelEditDocument>(
|
|
|
|
_panel.get(),
|
|
|
|
this,
|
|
|
|
std::move(GetDocumentScheme(_editScope->type)),
|
|
|
|
_editScope->fields->data.parsed,
|
|
|
|
_editScope->files[_editScopeFilesIndex]->data.parsed,
|
|
|
|
valueFiles(*_editScope->files[_editScopeFilesIndex]))
|
|
|
|
: object_ptr<PanelEditDocument>(
|
|
|
|
_panel.get(),
|
|
|
|
this,
|
|
|
|
std::move(GetDocumentScheme(_editScope->type)),
|
|
|
|
_editScope->fields->data.parsed);
|
2018-04-06 15:54:01 +04:00
|
|
|
case Scope::Type::Phone:
|
|
|
|
case Scope::Type::Email: {
|
|
|
|
const auto &fields = _editScope->fields->data.parsed.fields;
|
|
|
|
const auto valueIt = fields.find("value");
|
|
|
|
return object_ptr<PanelEditContact>(
|
|
|
|
_panel.get(),
|
|
|
|
this,
|
|
|
|
std::move(GetContactScheme(_editScope->type)),
|
|
|
|
(valueIt == end(fields)) ? QString() : valueIt->second,
|
|
|
|
getDefaultContactValue(_editScope->type));
|
|
|
|
} break;
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
2018-04-06 15:54:01 +04:00
|
|
|
Unexpected("Type in PanelController::editScope().");
|
2018-03-29 23:49:31 +04:00
|
|
|
}();
|
2018-03-31 05:45:40 +04:00
|
|
|
if (content) {
|
|
|
|
_panel->setBackAllowed(true);
|
|
|
|
_panel->backRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
2018-03-29 23:49:31 +04:00
|
|
|
cancelValueEdit(index);
|
2018-03-31 05:45:40 +04:00
|
|
|
_panel->setBackAllowed(false);
|
|
|
|
_panel->showForm();
|
|
|
|
}, content->lifetime());
|
|
|
|
_panel->showEditValue(std::move(content));
|
2018-03-29 23:49:31 +04:00
|
|
|
} else {
|
|
|
|
cancelValueEdit(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
std::vector<ScanInfo> PanelController::valueFiles(const Value &value) const {
|
2018-03-29 23:49:31 +04:00
|
|
|
auto result = std::vector<ScanInfo>();
|
|
|
|
for (const auto &file : value.filesInEdit) {
|
|
|
|
result.push_back(collectScanInfo(file));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
void PanelController::cancelValueEdit(int index) {
|
2018-04-03 22:24:31 +04:00
|
|
|
if (const auto scope = base::take(_editScope)) {
|
|
|
|
_form->startValueEdit(scope->fields);
|
|
|
|
const auto index = std::exchange(_editScopeFilesIndex, -1);
|
|
|
|
if (index >= 0) {
|
|
|
|
_form->startValueEdit(scope->files[index]);
|
|
|
|
}
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
void PanelController::saveScope(ValueMap &&data, ValueMap &&filesData) {
|
2018-03-31 05:45:40 +04:00
|
|
|
Expects(_panel != nullptr);
|
2018-04-03 22:24:31 +04:00
|
|
|
Expects(_editScope != nullptr);
|
2018-03-29 23:49:31 +04:00
|
|
|
|
2018-04-03 22:24:31 +04:00
|
|
|
const auto scope = base::take(_editScope);
|
|
|
|
_form->saveValueEdit(scope->fields, std::move(data));
|
|
|
|
const auto index = std::exchange(_editScopeFilesIndex, -1);
|
|
|
|
if (index >= 0) {
|
|
|
|
_form->saveValueEdit(scope->files[index], std::move(filesData));
|
|
|
|
} else {
|
|
|
|
Assert(filesData.fields.empty());
|
|
|
|
}
|
2018-03-29 23:49:31 +04:00
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
_panel->showForm();
|
2018-03-29 23:49:31 +04:00
|
|
|
}
|
|
|
|
|
2018-03-31 05:45:40 +04:00
|
|
|
void PanelController::cancelAuth() {
|
|
|
|
_form->cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::lifetime &PanelController::lifetime() {
|
|
|
|
return _lifetime;
|
|
|
|
}
|
|
|
|
|
2018-03-29 23:49:31 +04:00
|
|
|
} // namespace Passport
|