Exemple #1
0
void
ShareCreated::refresh(void)
{
	if (!wApp->internalPathMatches("/share-created"))
		return;

	clear();

	std::string editUUID = wApp->internalPathNextPart("/share-created/");

	Wt::Dbo::Transaction transaction(FsApp->getDboSession());

	Database::Share::pointer share = Database::Share::getByEditUUID(FsApp->getDboSession(), editUUID);
	if (!share)
	{
		FS_LOG(UI, ERROR) << "Edit UUID '" << editUUID << "' not found";
		Wt::WTemplate *t = addNew<Wt::WTemplate>(tr("template-share-not-found"));
		t->addFunction("tr", &Wt::WTemplate::Functions::tr);
		return;
	}

	Wt::WTemplate *t = addNew<Wt::WTemplate>(tr("template-share-created"));
	t->addFunction("tr", &Wt::WTemplate::Functions::tr);

	t->bindWidget("download-link", createShareDownloadAnchor(share));
	t->bindWidget("edit-link", createShareEditAnchor(share));
}
Exemple #2
0
void
ShareEdit::displayNotFound(void)
{
	clear();

	Wt::WTemplate *t = addNew<Wt::WTemplate>(tr("template-share-not-found"));
	t->addFunction("tr", &Wt::WTemplate::Functions::tr);
}
Exemple #3
0
void
ShareEdit::displayRemoved(void)
{
	clear();

	Wt::WTemplate *t = addNew<Wt::WTemplate>(tr("template-share-removed"));
	t->addFunction("tr", &Wt::WTemplate::Functions::tr);
}
Exemple #4
0
void
ShareEdit::refresh(void)
{
	if (!wApp->internalPathMatches("/share-edit"))
		return;

	clear();

	std::string editUUID = wApp->internalPathNextPart("/share-edit/");

	Wt::Dbo::Transaction transaction(FsApp->getDboSession());

	Database::Share::pointer share = Database::Share::getByEditUUID(FsApp->getDboSession(), editUUID);
	if (!share || !boost::filesystem::exists(share->getPath()))
	{
		FS_LOG(UI, ERROR) << "Edit UUID '" << editUUID << "' not found";
		displayNotFound();
		return;
	}

	FS_LOG(UI, INFO) << "[" << share->getDownloadUUID() << "] Editing share from " << wApp->environment().clientAddress();

	Wt::WTemplate *t = addNew<Wt::WTemplate>(tr("template-share-edit"));
	t->addFunction("tr", &Wt::WTemplate::Functions::tr);

	if (!share->getDesc().empty())
	{
		t->setCondition("if-desc", true);
		t->bindString("file-desc", Wt::WString::fromUTF8(share->getDesc()));
	}
	t->bindString("file-name", Wt::WString::fromUTF8(share->getFileName()));
	t->bindString("file-size", sizeToString(share->getFileSize()));
	t->bindString("expiry-date-time", share->getExpiryTime().toString() + " UTC");

	auto hits = std::to_string(share->getHits());
	if (share->getMaxHits() > 0)
		hits += " / " + std::to_string(share->getMaxHits());
	t->bindString("hits", hits);

	t->bindWidget("download-link", createShareDownloadAnchor(share));

	Wt::WPushButton* deleteBtn = t->bindNew<Wt::WPushButton>("delete-btn", tr("msg-delete"));

	deleteBtn->clicked().connect([=] ()
	{
		auto messageBox = deleteBtn->addChild(std::make_unique<Wt::WMessageBox>(tr("msg-share-delete"),
			tr("msg-confirm-action"),
			 Wt::Icon::Question,
			 Wt::StandardButton::Yes | Wt::StandardButton::No));

		messageBox->setModal(true);

		messageBox->buttonClicked().connect([=] (Wt::StandardButton btn)
		{
			if (btn == Wt::StandardButton::Yes)
			{
				Wt::Dbo::Transaction transaction(FsApp->getDboSession());

				Database::Share::pointer share = Database::Share::getByEditUUID(FsApp->getDboSession(), editUUID);

				if (share)
				{
					FS_LOG(UI, INFO) << "[" << share->getDownloadUUID() << "] Deleting share from " << wApp->environment().clientAddress();
					share.modify()->destroy();
					share.remove();
				}

				displayRemoved();
			}
			deleteBtn->removeChild(messageBox);
		});

		messageBox->show();
	});

}