summaryrefslogtreecommitdiff
path: root/src/preview
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-18 12:07:33 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-18 12:07:33 (GMT)
commita8e4221f38edefb5b342f470407b1f100d0248a3 (patch)
tree39f9d8036358c6150d5f7f6285a29e48a8c16882 /src/preview
parent78c4aba468a35166bf4ef5056b8e15be4098ba07 (diff)
downloadpowder-a8e4221f38edefb5b342f470407b1f100d0248a3.zip
powder-a8e4221f38edefb5b342f470407b1f100d0248a3.tar.gz
Working comment submission
Diffstat (limited to 'src/preview')
-rw-r--r--src/preview/PreviewController.cpp20
-rw-r--r--src/preview/PreviewController.h1
-rw-r--r--src/preview/PreviewView.cpp29
-rw-r--r--src/preview/PreviewView.h2
4 files changed, 52 insertions, 0 deletions
diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp
index d5e1a93..a922bc6 100644
--- a/src/preview/PreviewController.cpp
+++ b/src/preview/PreviewController.cpp
@@ -60,6 +60,26 @@ void PreviewController::Update()
}
}
+void PreviewController::SubmitComment(std::string comment)
+{
+ if(comment.length() < 4)
+ {
+ new ErrorMessage("Error", "Comment is too short");
+ }
+ else
+ {
+ RequestStatus status = Client::Ref().AddComment(saveId, comment);
+ if(status != RequestOkay)
+ {
+ new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError());
+ }
+ else
+ {
+ previewModel->UpdateComments(1);
+ }
+ }
+}
+
void PreviewController::ShowLogin()
{
loginWindow = new LoginController();
diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h
index 81c457b..e6b8caa 100644
--- a/src/preview/PreviewController.h
+++ b/src/preview/PreviewController.h
@@ -38,6 +38,7 @@ public:
PreviewView * GetView() { return previewView; }
void Update();
void FavouriteSave();
+ void SubmitComment(std::string comment);
void NextCommentPage();
void PrevCommentPage();
diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp
index d7c44b3..79d2cdd 100644
--- a/src/preview/PreviewView.cpp
+++ b/src/preview/PreviewView.cpp
@@ -28,6 +28,17 @@ public:
}
};
+class PreviewView::SubmitCommentAction: public ui::ButtonAction
+{
+ PreviewView * v;
+public:
+ SubmitCommentAction(PreviewView * v_){ v = v_; }
+ virtual void ActionCallback(ui::Button * sender)
+ {
+ v->submitComment();
+ }
+};
+
class PreviewView::AutoCommentSizeAction: public ui::TextboxAction
{
PreviewView * v;
@@ -361,6 +372,23 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
}
}
+void PreviewView::submitComment()
+{
+ if(addCommentBox)
+ {
+ std::string comment = std::string(addCommentBox->GetText());
+ submitCommentButton->Enabled = false;
+ addCommentBox->SetText("");
+ addCommentBox->SetPlaceholder("Submitting comment");
+ FocusComponent(NULL);
+
+ c->SubmitComment(comment);
+
+ addCommentBox->SetPlaceholder("Add comment");
+ submitCommentButton->Enabled = true;
+ }
+}
+
void PreviewView::displayComments(int yOffset)
{
for(int i = 0; i < commentComponents.size(); i++)
@@ -441,6 +469,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(addCommentBox);
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
+ submitCommentButton->SetActionCallback(new SubmitCommentAction(this));
//submitCommentButton->Enabled = false;
AddComponent(submitCommentButton);
}
diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h
index 7b85ea5..2e94b85 100644
--- a/src/preview/PreviewView.h
+++ b/src/preview/PreviewView.h
@@ -21,6 +21,7 @@
class PreviewModel;
class PreviewController;
class PreviewView: public ui::Window {
+ class SubmitCommentAction;
class LoginAction;
class AutoCommentSizeAction;
PreviewController * c;
@@ -56,6 +57,7 @@ class PreviewView: public ui::Window {
void displayComments(int yOffset);
void commentBoxAutoHeight();
+ void submitComment();
public:
void AttachController(PreviewController * controller) { c = controller;}
PreviewView();