-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditButtonBar.hpp
78 lines (71 loc) · 2.24 KB
/
EditButtonBar.hpp
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
69
70
71
72
73
74
75
76
77
78
/*
* =====================================================================================
*
* Filename: EditButtonBar.hpp
*
* Description: Gives you save/add/cancel buttons in a nice row.
*
* Version: 1.0
* Created: 06/04/2011 09:49:11 AM
* Revision: none
* Compiler: gcc
*
* Author: Matthew Sherborne (), [email protected]
* Company:
*
* =====================================================================================
*/
#ifndef EDIT_BUTTON_BAR_HPP
#define EDIT_BUTTON_BAR_HPP
#include <Wt/WString>
#include <Wt/WPushButton>
#include <Wt/WSignal>
#include <Wt/WMessageBox>
#include "App.hpp"
#include "ButtonBar.hpp"
using Wt::WString;
using Wt::WPushButton;
using Wt::WMessageBox;
namespace vidanueva {
/**
* @brief A nice 'Save'/'Create' 'Cancel' button pair.
*
* Cancel will navigate the app back to "/".
* OK will trigger the 'onOk' event
*/
class EditButtonBar : public ButtonBar {
private:
Wt::Signal<>* _okHit;
/// Handles when cancel button is hit. Prompts the user, then navigates back to home page
void handleCancel() {
Wt::StandardButton result = WMessageBox::show(tr("Discard Edits"), tr("you-want-discard"), Wt::Ok | Wt::Cancel);
if (result == Wt::Ok)
getApp()->goHome();
}
/// Handles when ok button is hit. Prompts the user, then triggers the okHit() signal
void handleOk() {
Wt::StandardButton result = WMessageBox::show(tr("Save Changes"), tr("you-want-save"), Wt::Ok | Wt::Cancel);
if (result == Wt::Ok) {
_okHit->emit();
}
}
public:
/**
* @brief Gives you a nice button bar for saving a new or existing resource
*
* @param parent Parent Widget
*/
EditButtonBar(WContainerWidget* parent=0) : ButtonBar(WString::tr("Save"), WString::tr("cancel"), parent) {
_okHit = new Wt::Signal<>(this);
// OK/Save Button
_btn1->clicked().connect(this, &EditButtonBar::handleOk);
// Cancel Button
_btn2->clicked().connect(this, &EditButtonBar::handleCancel);
}
/**
* @brief Connect to this event for when the OK button is hit and confirmed
*/
Wt::Signal<>* okHit() { return _okHit; }
};
}
#endif // EDIT_BUTTON_BAR_HPP