Search in sources :

Example 1 with FeaturedModule

use of models.FeaturedModule in project modules.playframework.org by playframework.

the class FeaturedModules method delete.

public static Result delete() {
    Map<String, String[]> postParams = request().body().asFormUrlEncoded();
    String[] ids = postParams.get("id");
    Result result;
    if (ids.length != 1) {
        result = badRequest("A featured module must be defined");
    } else {
        FeaturedModule featuredModule = FeaturedModule.FIND.byId(Long.parseLong(ids[0]));
        featuredModule.delete();
        ObjectNode node = Json.newObject();
        node.put("id", featuredModule.id);
        result = ok(node);
    }
    return result;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) FeaturedModule(models.FeaturedModule) Result(play.mvc.Result)

Example 2 with FeaturedModule

use of models.FeaturedModule in project modules.playframework.org by playframework.

the class FeaturedModules method addNewFeaturedModule.

public static Result addNewFeaturedModule() {
    Result result;
    Form<FeaturedModule> form = form(FeaturedModule.class).bindFromRequest();
    if (form.hasErrors()) {
        result = badRequest(featuredModules.render(currentUser(), FeaturedModule.getAll(), form));
    } else {
        FeaturedModule featuredModule = form.get();
        Ebean.refresh(featuredModule.playModule);
        if (StringUtils.isEmpty(featuredModule.description)) {
            featuredModule.description = featuredModule.playModule.description;
        }
        featuredModule.creationDate = new Date();
        featuredModule.save();
        result = redirect(routes.FeaturedModules.showFeaturedModules());
    }
    return result;
}
Also used : FeaturedModule(models.FeaturedModule) Date(java.util.Date) Result(play.mvc.Result)

Example 3 with FeaturedModule

use of models.FeaturedModule in project modules.playframework.org by playframework.

the class FeaturedModules method update.

public static Result update() {
    Result result;
    Form<FeaturedModule> form = form(FeaturedModule.class).bindFromRequest();
    if (form.hasErrors()) {
        result = badRequest(form.errorsAsJson());
    } else {
        FeaturedModule incoming = form.get();
        FeaturedModule storedVersion = FeaturedModule.FIND.byId(incoming.id);
        storedVersion.description = StringUtils.isEmpty(incoming.description) ? storedVersion.playModule.description : incoming.description;
        storedVersion.sticky = incoming.sticky;
        storedVersion.save();
        // Annoying - converting storedVersion directly to JSON results in a cycle according to Jackson
        // Buggered if I can see why though
        ObjectNode node = Json.newObject();
        node.put("id", storedVersion.id);
        node.put("description", storedVersion.description);
        node.put("sticky", storedVersion.sticky);
        result = ok(node);
    }
    return result;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) FeaturedModule(models.FeaturedModule) Result(play.mvc.Result)

Aggregations

FeaturedModule (models.FeaturedModule)3 Result (play.mvc.Result)3 ObjectNode (org.codehaus.jackson.node.ObjectNode)2 Date (java.util.Date)1