view app/controllers/Application.java @ 9:87c015a99196 draft

add jquery.tools-1.2.5.toolbox
author e085711
date Thu, 13 Sep 2012 11:06:17 +0900
parents 84e51aafdfed
children
line wrap: on
line source

package controllers;

import play.*;
import play.data.validation.Required;
import play.mvc.*;

import java.util.*;

import models.*;

public class Application extends Controller {

	@Before
	static void addDefaults() {
		renderArgs.put("blogTitle",Play.configuration.getProperty("blog.title"));
		renderArgs.put("blogBaseline",Play.configuration.getProperty("blog.baseline"));
	}
	
    public static void index() {
    	Post frontPost = Post.find("order by postedAt desc").first();
    	List<Post> olderPosts = Post.find("order by postedAt desc").from(1).fetch(10);
    	render(frontPost,olderPosts);
    }
    
    public static void createTask(String title) {
    	Task task = new Task(title).save();
    	renderJSON(task);
    }
    
    public static void changeStatus(Long id, boolean done) {
    	Task task = Task.findById(id);
    	task.done = done;
    	task.save();
    	renderJSON(task);
    }
    
    public static void dimolto() {
    	ArrayList list = new ArrayList();
    	list.add("message 1");
    	list.add("message 2");
    	list.add("message 3");
    	
    	render(list);

  	}
    
    public static void show(Long id) {
    	Post post = Post.findById(id);
    	render(post);
    }
    
    public static void postComment(Long postId, @Required String author, @Required String content) {
    	Post post = Post.findById(postId);
    	if (validation.hasErrors()) {
    		render("Application/show.html",post);
    	}
    	post.addComment(author, content);
    	show(postId);
    }
    
    
    
}