-
Notifications
You must be signed in to change notification settings - Fork 1
/
PageEdit.cpp
68 lines (59 loc) · 1.92 KB
/
PageEdit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* =====================================================================================
*
* Filename: PageEdit.cpp
*
* Description: Code for editing the web pages
*
* Version: 1.0
* Created: 06/03/2011 09:44:37 AM
* Revision: none
* Compiler: gcc
*
* Author: Matthew Sherborne (), msherborne@gmail.com
* Company:
*
* =====================================================================================
*/
#include "PageEdit.hpp"
#include "App.hpp"
#include <string>
#include <Wt/WLineEdit>
#include <Wt/WLabel>
#include <Wt/WTextEdit>
#include <Wt/WDialog>
#include "EditButtonBar.hpp"
using std::string;
using Wt::WDialog;
using mongo::BSONObj;
namespace vidanueva {
PageEdit::PageEdit(WContainerWidget* parent) : MoreAwesomeTemplate(parent) {
setUpWidgets();
}
PageEdit::PageEdit(WDialog& dialog) : MoreAwesomeTemplate(dialog.contents()) {
setUpWidgets();
_nameEdit->escapePressed().connect(&dialog, &WDialog::reject);
_titleEdit->escapePressed().connect(&dialog, &WDialog::reject);
}
void PageEdit::setUpWidgets() {
setTemplateText(tr("page-edit-template"));
setStyleClass("form");
bindAndCreateField(_titleLabel, _titleEdit, "title");
bindAndCreateField(_nameLabel, _nameEdit, "name");
bindAndCreateField(_bodyLabel, _bodyEdit, "body");
bindWidget("buttons", _buttons = new EditButtonBar());
_buttons->okHit()->connect(this, &PageEdit::saveChanges);
_nameEdit->setFocus();
}
/**
* @brief Saves any changes made to the DB then navigates to the page
*/
void PageEdit::saveChanges() {
VidaApp* app = getApp();
string name =_nameEdit->text().toUTF8();
PageData data(name, _titleEdit->text().toUTF8(), _bodyEdit->text().toUTF8());
app->pages().save(data);
app->setInternalPath("/page/" + name, true); // Navigate to the new page
app->mainWindow()->setStatusText(tr("Page Saved")); // Update the status text
}
}