Permalink
Browse files

Merge branch 'master' of github.com:tadzik/TIN

  • Loading branch information...
2 parents 6f4674a + 6fcd69a commit d6e38261765a38c384a9af4b7fee49d682a4c0eb Karolina committed May 31, 2012
Showing with 81 additions and 13 deletions.
  1. +0 −6 Skunk.cpp
  2. +65 −0 Skunk.hpp
  3. +0 −7 dispatcher_test.cpp
  4. +16 −0 skunk_test.cpp
View
@@ -31,12 +31,6 @@ std::string urldecoder(std::string coded){
typedef std::map<std::string, std::string> StringMap;
-std::string itoa(int i) {
- std::stringstream str;
- str << i;
- return str.str();
-}
-
int Skunk::Server::addWidget(Skunk::Widget *w) {
widgets_.push_back(w);
w->id_ = nextID_;
View
@@ -6,6 +6,12 @@
#include "csgi.hpp"
+static std::string itoa(int i) {
+ std::stringstream str;
+ str << i;
+ return str.str();
+}
+
namespace Skunk {
struct Widget {
@@ -68,6 +74,65 @@ struct TextField : Widget {
}
};
+struct RadioButton : Widget {
+ std::vector<std::string> listaWyboru;
+ int index;
+ std::string title;
+
+ RadioButton() : title("Ratio Button:") { }
+
+ virtual void setValue(int) { };
+
+ virtual bool isDefault(int i){
+ if(i == index) return true;
+ else return false;
+ }
+
+ virtual int getElemsNum(){
+ return listaWyboru.size();
+ }
+
+ virtual std::string getValue() {
+ return listaWyboru[index];
+ }
+
+ virtual std::string getValue(int indx) {
+ return listaWyboru[indx];
+ }
+
+ virtual void addChoice(std::string choice){
+ listaWyboru.push_back(choice);
+ }
+
+ virtual void setTitle(std::string title_){
+ title = title_;
+ }
+
+ virtual std::string GET() {
+ std::stringstream id_str;
+ id_str << this ->id_;
+ std::string html = "";
+ html.append("<b>"+ title +"</b><br />\n");
+ for(int i=0; i<this->getElemsNum(); i++){
+ html.append("<input type='radio' name='");
+ html.append("id"+id_str.str());
+ html.append("'");
+ html.append(" value='");
+ html.append(""+ itoa(i));
+ html.append("' ");
+ if(this->isDefault(i)) html.append("checked ");
+ html.append("/>");
+ html.append(this->getValue(i));
+ html.append("<br />\n");
+ }
+ return html;
+ }
+
+ virtual void POST(std::string& s) {
+ this->setValue(atoi(s.c_str()));
+ }
+};
+
class Server : CSGI::Application {
std::vector<Widget *> widgets_;
std::map<std::string, Widget*> widgets_map_;
View
@@ -3,13 +3,6 @@
#include <sstream>
#include <iostream>
-std::string itoa(int i)
-{
- std::stringstream out;
- out << i;
- return out.str();
-}
-
class SimpleResponder : public CSGI::Application {
public:
SimpleResponder(std::string msg) : msg_(msg) { }
View
@@ -1,5 +1,6 @@
#include "Skunk.hpp"
#include <string>
+#include <vector>
class PoleTekstowe : public Skunk::TextField {
std::string wartosc_;
@@ -16,6 +17,15 @@ class PoleTekstowe : public Skunk::TextField {
}
};
+class PoleRadiowe : public Skunk::RadioButton {
+public:
+
+ virtual void setValue(int neu) {
+ index = neu;
+ }
+
+};
+
class WielkiNapis : public Skunk::Widget {
virtual std::string GET() {
return "<h1><b>LOL WTF</b></h1>";
@@ -28,6 +38,12 @@ int main(void) {
srv->addWidget(new WielkiNapis());
srv->addWidget(new PoleTekstowe("dupa"));
srv->addWidget(new PoleTekstowe("cycki"));
+ PoleRadiowe *pr = new PoleRadiowe();
+ srv->addWidget(pr);
+ pr->setTitle("Preferencje dupczane");
+ pr->addChoice("dupeczka");
+ pr->addChoice("dupcia");
+ pr->addChoice("dupiszon");
Skunk::SimpleAuth *auth = new Skunk::SimpleAuth();
auth->addUser("admin", "dupa.8");

0 comments on commit d6e3826

Please sign in to comment.