示例#1
0
文件: Admin.java 项目: nateki/yabe
 public static void save(Long id, String title, String content, String tags) {
   Post post;
   if (id == null) {
     // Create post
     User author = User.find("byEmail", Security.connected()).first();
     post = new Post(author, title, content);
   } else {
     // Retrieve post
     post = Post.findById(id);
     // Edit
     post.title = title;
     post.content = content;
     post.tags.clear();
   }
   // Set tags list
   for (String tag : tags.split("\\s+")) {
     if (tag.trim().length() > 0) {
       post.tags.add(Tag.findOrCreateByName(tag));
     }
   }
   // Validate
   validation.valid(post);
   if (validation.hasErrors()) {
     render("@form", post);
   }
   // Save
   post.save();
   index();
 }
示例#2
0
文件: Admin.java 项目: nateki/yabe
 public static void form(Long id) {
   if (id != null) {
     Post post = Post.findById(id);
     render(post);
   }
   render();
 }
示例#3
0
文件: Admin.java 项目: nateki/yabe
 public static void index() {
   String user = Security.connected();
   List<Post> posts = Post.find("author.email", user).fetch();
   render(posts);
 }