Wt::WPushButton *createColorButton(const char *className, const Wt::WString& text)
{
  Wt::WPushButton *button = new Wt::WPushButton();
  button->setTextFormat(Wt::XHTMLText);
  button->setText(text);
  button->addStyleClass(className);
  return button;
}
Esempio n. 2
0
void studentPasswords::create() {
  Wt::WPanel * panel = new Wt::WPanel(this);
  
  panel->setStyleClass("panel panel-primary");
  panel->setTitle("<h3>Wachtwoorden Administratie</h3>");
  panel->setMinimumSize(800, 800);
  panel->setMaximumSize(800, Wt::WLength::Auto);
  panel->setMargin("0 auto");
  
  Wt::WContainerWidget * content = new Wt::WContainerWidget();
  panel->setCentralWidget(content);
  content->setPadding("1%");
  
  buttons = new Wt::WContainerWidget(content);
  Wt::WHBoxLayout * buttonLayout = new Wt::WHBoxLayout();
  buttons->setLayout(buttonLayout);
  
  Wt::WPopupMenu * popup = new Wt::WPopupMenu();
  Wt::WPushButton * button = new Wt::WPushButton();
  button->setMenu(popup);
  button->setText("Selecteer een klas");
  buttonLayout->addWidget(button);
  
  Wt::WPushButton * button2 = new Wt::WPushButton();
  button2->setText("Selectie Aanpassen");
  button2->setStyleClass("btn btn-success");
  buttonLayout->addWidget(button2);
  button2->clicked().connect(this, &studentPasswords::changePasswords);
  
  Wt::WContainerWidget * tableContent = new Wt::WContainerWidget(content);
  table = new Wt::WTable(tableContent);
  
  // add classes
  Wt::WPopupMenu * subMenu[7];
  
  for(int i = 0; i < 7; i++) {
    subMenu[i] = new Wt::WPopupMenu();
    if(i == 0) {
      popup->addMenu("1ste jaar", subMenu[i]);
    } else {
      string s = string(i+1) + "de jaar";
      popup->addMenu(s.wt(), subMenu[i]);
    }
  }
  
  CLASSES & classes = server->getClasses();
  
  for(int i = 0; i < classes.elms(); i++) {
    string name = classes[i].cn().get();
    if(name.empty()) continue;
    
    int year = -1;
    switch(name[0]) {
      case '1': year = 0; break;
      case '2': year = 1; break;
      case '3': year = 2; break;
      case '4': year = 3; break;
      case '5': year = 4; break;
      case '6': year = 5; break;
      case '7': year = 6; break;
    }
    if(year < 0) continue;
    
    subMenu[year]->addItem(name.wt())->triggered().connect(std::bind([=] () {
      showClass(name);
    }));
  }
  
  progress = new Wt::WProgressBar(content);
  progress->hide();
  
  anchor = new Wt::WAnchor(Wt::WLink(&pfile), "Download passwords", content);
  anchor->setTarget(Wt::TargetNewWindow);
  anchor->clicked().connect(this, &studentPasswords::reset);
  anchor->hide();
}
// Updates all ranks
void RecentMatchesContainer::update()
{
    this->clear();
    
    std::vector<RecentMatch> recent_matches = Spartan_->getRecentMatches();
    
    // Create halo api with an api key (get api key from 343i api site)
    //HaloAPI halo_api("05cdc66c52ca4465b0b6e3c56bb87b71");
    
    for (int i = 0; i < recent_matches.size() && i < 10; i++)
    {
        // CUSTOM CONTAINERS
        Wt::WContainerWidget *myContainer = new Wt::WContainerWidget();
        myContainer->decorationStyle().setBorder(Wt::WBorder(Wt::WBorder::Style::Solid, Wt::WBorder::Width::Thin, Wt::WColor(0, 0, 0)));
        myContainer->decorationStyle().setBackgroundColor(Wt::WColor(240, 240, 240));
        myContainer->setPadding(3);
        myContainer->setMargin(3, Wt::Bottom);
        
        std::string title_string = "<b>" + getNameFromHopper(recent_matches[i].hopper_id_) + " / </b>" + getNameFromBaseVariant(recent_matches[i].base_variant_) + "<b> / </b>" + getNameFromMap(recent_matches[i].map_id_) + "";
        Wt::WText *someText = new Wt::WText(title_string, myContainer);
        
        Wt::WPushButton *myButton = new Wt::WPushButton(" + ", myContainer);
        myButton->setFloatSide(Wt::Right);
        
        std::string game_time = time_from_double(recent_matches[i].match_length_);
        Wt::WText *someMoreText = new Wt::WText(game_time, myContainer);
        someMoreText->setFloatSide(Wt::Right);
        
        Wt::WStackedWidget *myStack = new Wt::WStackedWidget(myContainer);
        Wt::WText *text1 = new Wt::WText("text1", myStack);

        
        myButton->clicked().connect(std::bind([=]()
        {
            if (myStack->currentIndex() == 0)
            {
                myButton->setText(" - ");
                Wt::WContainerWidget *stats_table = new Wt::WContainerWidget(myStack);
                Wt::WTable *table = new Wt::WTable(stats_table);
                table->setHeaderCount(1);
                table->elementAt(0, 0)->addWidget(new Wt::WText("Gamertag"));
                HaloAPI halo_api("05cdc66c52ca4465b0b6e3c56bb87b71");
                std::vector<std::string> gamertags;
                
                std::string json_data = halo_api.getPostGameCarnageArena(recent_matches[i].match_id_);
                Json::Value root;   // will contains the root value after parsing.
                Json::Reader reader;
                bool parsingSuccessful = reader.parse( json_data, root );
                if ( !parsingSuccessful )
                {
                    // report to the user the failure and their locations in the document.
                    std::cout  << "Failed to parse configuration\n"
                    << reader.getFormattedErrorMessages();
                }
                const Json::Value plugins = root;
                
                for (int j = 0; j < plugins["PlayerStats"].size(); j++)
                {
                    std::string tag(
                                    plugins["PlayerStats"][j]["Player"]["Gamertag"].asString()
                                    );
                    gamertags.push_back(tag);
                    table->elementAt(j+1, 0)->addWidget(new Wt::WText(tag));
                }
                table->addStyleClass("table table-condensed");
                myStack->setCurrentIndex(1);
            } else
            {
                delete myStack->currentWidget();
                myStack->setCurrentIndex(0);
                myButton->setText(" + ");
            }
        }));
        this->addWidget(myContainer);
    }
}