Ejemplo n.º 1
0
App::App(const WEnvironment& environment) :
    BaseApp(environment, my_appCookieName) {
    // Set up the db
    string postgresConnectionString;
    readConfigurationProperty("DB", postgresConnectionString);
    postgres.connect(postgresConnectionString);
    dbSession().setConnection(postgres);
    log("notice") << "Mapping classes";
    mapModels(dbSession());
    // Load the message bundles
    messageResourceBundle().use(appRoot() + "messages/App");
    messageResourceBundle().use(appRoot() + "messages/MainWindow");
    messageResourceBundle().use(appRoot() + "messages/LoginWindow");
    messageResourceBundle().use(appRoot() + "messages/ButtonBar");
    messageResourceBundle().use(appRoot() + "messages/AdminIndex", false);
    messageResourceBundle().use(appRoot() + "messages/UserList", false);
    messageResourceBundle().use(appRoot() + "messages/UserEdit", false);
    // Set up our signals
    _userChanged = new UserChangedSignal(this);
    _statusTextChanged = new MessageSignal(this);
    internalPathChanged().connect(this, &App::rememberHistory);
    // Set up the general URL handling
    _url2ActionMapper = new URL2Action(this);
    // Set up the UI
    useStyleSheet(resourcesUrl() + "/themes/" + cssTheme() + "/forms.css");
    useStyleSheet(resourcesUrl() + "/themes/" + cssTheme() + "/fonts.css");
    useStyleSheet(resourcesUrl() + "/themes/" + cssTheme() + "/controlPanel.css");
    setTitle(WString::tr("main-title"));
    _mainWindow = new MainWindow(root());
    _statusTextChanged->connect(_mainWindow, &MainWindow::setStatusText);
    setBodyClass("yui-skin-sam");
    // Fire an internal path changed event off as user may have navigated straight here
    internalPathChanged().emit(app()->internalPath());
}
Ejemplo n.º 2
0
void Extension::handleURLChange() {
    // Find the page
    IGui* gui = IGui::instance();
    Wt::WApplication* app = Wt::WApplication::instance();
    std::string pageName = "/";
    std::string action = "view";
    if (app->internalPathMatches("/page/")) {
        pageName = app->internalPathNextPart("/page/");
        std::string pagePath = "/page/" + pageName + "/";
        if (app->internalPathMatches(pagePath))
            action = app->internalPathNextPart(pagePath);
    }
    dbo::Session& s = dbSession();
    dbo::Transaction t(s);
    dbo::ptr<Model> page = s.find<Model>().where("name=?").bind(pageName);
    // Use it
    if (page) {
        ActionMap::const_iterator found = actionMap.find(action);
        if (found != actionMap.end()) {
            ((this)->*(found->second))(*page); // Call the action .. view/edit etc..
        } else {
            Wt::WApplication::instance()->log("ERROR") <<
                    "No valid action for page " << page->getName() << " - " <<
                    "Action name " << action;
            // Default to view maybe ?
            gui->setBody("ERROR: No such action " + action );
        }
    } else {
        gui->setBody("PAGE NOT FOUND: " + pageName);
    }
    t.commit();
}
Ejemplo n.º 3
0
/// Called every time an app is created
Extension::Extension(WObject* parent) : WObject(parent) {
    IURLs* urlManager = IURLs::instance();
    if (urlManager != 0)
        urlManager->urlSignal("/page").connect(this, &Extension::handleURLChange);
    dbSession().mapClass<Model>("page");
    actionMap.insert(ActionPair("view", &Extension::view));
    actionMap.insert(ActionPair("edit", &Extension::edit));
}