Skip to content

Commit

Permalink
Fleshing out forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Dec 17, 2008
1 parent a3137c4 commit b45bfc8
Show file tree
Hide file tree
Showing 36 changed files with 527 additions and 289 deletions.
2 changes: 1 addition & 1 deletion apps/blog/controllers/BlogHomeController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class BlogHomeController extends Controller {

/** !Route GET */
function home() {
function index() {

$this->flash = 'Welcome to your application!';

Expand Down
34 changes: 9 additions & 25 deletions apps/blog/controllers/NewPostController.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
Library::import('blog.models.Post');
Library::import('recess.framework.forms.Form');
Library::import('recess.framework.forms.ModelForm');

/**
* !View Native, Prefix: posts/
Expand All @@ -16,7 +16,7 @@ class NewPostController extends Controller {

function init() {
$this->post = new Post();
$this->_form = new ModelForm('post', $this->post, $this->request->var('post'));
$this->_form = new ModelForm('post', $this->request->data('post'), $this->post);
}

/** !Route GET */
Expand All @@ -32,15 +32,15 @@ function details($id) {

/** !Route GET, new */
function newForm() {
$this->form->for($this, 'insert');
$this->_form->to(Methods::POST, $this->urlTo('insert'));
return $this->ok('editForm');
}

/** !Route POST */
function insert() {
try {
$this->post->insert();
return $this->created($this->urlTo('details',$this->post->id));
return $this->created($this->urlTo('details', $this->post->id));
} catch(ModelValidationException $exception) {
$this->form->for('insert');
$this->form->handle($exception);
Expand All @@ -52,18 +52,18 @@ function insert() {
function editForm($id) {
$this->post->id = $id;
if($this->post->exists()) {
$this->form->for($this, 'update', $id);
$this->_form->to(Methods::PUT, $this->urlTo('update', $id));
} else {
return $this->forwardNotFound($this->urlTo('index'), 'Post does not exist.');
}
}

/** !Route PUT, $id */
function update($id) {
$this->post->id = $id;
if($this->post->exists()) {
$this->post->update();
return $this->forwardOk($this->urlTo('details',$this->post->id));
$oldPost = new Post($id);
if($oldPost->exists()) {
$oldPost->copy($this->post)->save();
return $this->forwardOk($this->urlTo('details', $id));
} else {
return $this->forwardNotFound($this->urlTo('index'), 'Post does not exist.');
}
Expand All @@ -78,21 +78,5 @@ function delete($id) {
return $this->forwardNotFound($this->urlTo('index'), 'Post does not exist.');
}
}


function getPostForm($method, $action, $fillValues = array()) {
Library::import('recess.framework.forms.Form');
$form = new Form();
$form->method = $method;
$form->action = $action;
$form->flash = "";
$form->inputs['title'] = new TextInput('post[title]', '', '','');
$form->inputs['body'] = new TextInput('post[body]', '', '','');
$form->inputs['isPublic'] = new TextInput('post[isPublic]', '', '','');
$form->inputs['modifiedAt'] = new TextInput('post[modifiedAt]', '', '','');
$form->inputs['createdOn'] = new TextInput('post[createdOn]', '', '','');
$form->fill($fillValues);
return $form;
}
}
?>
84 changes: 0 additions & 84 deletions apps/blog/controllers/PostController.class.php

This file was deleted.

14 changes: 1 addition & 13 deletions apps/blog/views/common/footer.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
</div>
<div class="span-5 last infobar">
<h3><span>Resources</span></h3>
<ul>
<li><a href="http://www.recessframework.com/">RecessFramework.com</a></li>
<li><a href="http://www.recessframework.com/docs/">Documentation</a></li>
<li><a href="http://www.recessframework.com/blog/">Recess! Blog</a></li>
<li><a href="http://www.krisjordan.com/">Kris' Blog</a></li>
<li><a href="http://groups.google.com/group/recess-framework">Mailing Group</a></li>
<li><a href="http://recess.lighthouseapp.com/">Report Bugs</a></li>
<li><a href="https://github.com/KrisJordan/recess/tree/master">Recess! Source</a></li>
</ul>
</div>
<div class="span-24 footer">
<p class="quiet bottom"><a href="http://<?php echo $_SERVER['SERVER_NAME'] . $_ENV['url.base'] . 'blog/'; ?>">Blog</a> is &copy; <?php echo date('Y'); ?>
{Insert Kick-ass App Developer Here}. All rights reserved.
{Insert Kick-ass App Developer Name Here}. All rights reserved.
</p>
</div>
</div>
Expand Down
28 changes: 26 additions & 2 deletions apps/blog/views/common/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,39 @@
<!--[if IE]>
<link rel="stylesheet" href="/css/blueprint/ie.css" type="text/css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" href="<?php echo $_ENV['url.content']; ?>css/recess.css" />
<!-- Syntax Highlighter -->
<link type="text/css" rel="stylesheet" href="<?php echo $_ENV['url.content']; ?>css/SyntaxHighlighter.css"></link>
<title><?php if(isset($title)) echo $title; else echo 'Recess!'; ?></title>

<style type="text/css">
.error,.notice,.success{ margin: 0 0 1em 0; padding: 0.8em; border: 2px solid #000; }
.error{ background: #FBE3E4; border-color: #FBC2C4; }
.error, .error a{ color: #8A1F11; }
.notice{ background: #FFF6BF; border-color: #FFD324; }
.notice, .notice a{ color: #514721; }
.success{ background: #E6EFC2; border-color: #C6D880; }
.success, .success a{ color: #264409; }
body { font-size: .8em; }
p { font-size: 1.2em; }
form{ margin: 0; padding: 0; }
fieldset{ margin: 0 0 1em 0; padding: 1em; border: 2px solid #a9b5c7; background: #f0f6fe; }
legend{ margin: 0; padding: 0 0.5em; font-size: 1.5em; font-weight: bold; color: #222; }
label{ font-weight: bold; color: #222; }

input.text,textarea{ width: 300px; padding: 3px; font-size: 14px; font-family: arial, verdana, sans-serif; color: #333; }
input.short{ width: 100px; }
input.long{ width: 500px; }
textarea{ width: 500px; height: 150px; }
.navigation { font-size: 1.6em; }
.navigation ul { margin: 0 0 1em 0; }
.navigation ul li { display: inline; background: #E6EFC2; border: 2px solid #C6D880; }
.navigation ul li a { color: #000; text-decoration: none; margin: .5em; }
</style>
</head>
<body>
<div class="container">
<div class="span-24">
<h1>Blog</h1>
</div>
<div class="span-19">
<div class="span-24 last">
<?php include_once($viewsDir . 'common/navigation.php'); ?>
17 changes: 12 additions & 5 deletions apps/blog/views/common/navigation.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<div class="span-19 navigation last">
<div class="navigation">
<ul>
<a href="">Navigation</a>
<a href="">Could</a>
<a href="">Go</a>
<a href="">Here</a>
<?php
// This is a really sketchy way of building up navigation.
// Please do not actually use this in a real app. Thx -Kris
Library::import('recess.lang.Inflector');
$app = $controller->application();
$controllers = $app->listControllers();
foreach($controllers as $controllerClass):
$navController = new $controllerClass($app);
?>
<li><a href="<?php echo $navController->urlTo('index'); ?>"><?php echo Inflector::toEnglish(str_replace('Controller','',$controllerClass)); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
25 changes: 25 additions & 0 deletions apps/blog/views/home/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
$title = 'Home';
include_once($viewsDir . 'common/header.php');
?>
<div class="span-24 last">
<div class="span-12 notice">
<p>Friends,</p>
<p>I appreciate your interest in Recess! I hope you'll find these bits (somewhat) functional and fun.</p>
<p>The Recess framework is early stage so please travel with caution.</p>
<p>Thanks and Enjoy!</p>
<p><a href="http://www.krisjordan.com/">Kris Jordan</a></p>
</div>
</div>

<h2>Welcome to your new Recess application!</h2>

<h3>Next steps?</h3>

<ul>
<li><a href="<?php echo $_ENV['url.base']; ?>recess/">Recess Tools</a></li>
</ul>

<h3>For more information visit <a href="http://www.recessframework.org/">http://www.recessframework.org/</a></h3>

<?php include_once($viewsDir . 'common/footer.php'); ?>
62 changes: 26 additions & 36 deletions apps/blog/views/posts/editForm.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
<?php include_once($viewsDir . 'common/header.php'); ?>

<?php

$form->begin();

echo '<br />';

echo 'Title: ';
$form->input('title');

echo '<br />';

echo 'Body: ';
$form->input('body');

echo '<br />';

echo 'Is Public: ';
$form->input('isPublic');

echo '<br />';

echo 'Modified: ';
$form->input('modifiedAt');

echo '<br />';

echo 'Created: ';
$form->input('createdOn');

echo '<br />';

echo '<input type="submit" />';

$form->end;

?>
<?php $_form->begin(); ?>
<fieldset>
<legend>Edit Post</legend>
<p>
<label for="title">Title</label><br />
<?php $_form->input('title'); ?>
</p>
<p>
<label for="body">Body</label><br />
<?php $_form->input('body'); ?>
</p>
<p>
<label for="title">Is Public</label><br />
<?php $_form->isPublic->render(); ?>
</p>
<p>
<label for="title">Modified At</label><br />
<?php $_form->input('modifiedAt'); ?>
</p>
<p>
<label for="title">Created On</label><br />
<?php $_form->input('createdOn'); ?>
</p>
<input type="submit" value="Save" />
</fieldset>
<?php $_form->end; ?>

<a href="<?php echo $controller->urlTo('index'); ?>">Show All Posts</a>

Expand Down
Loading

0 comments on commit b45bfc8

Please sign in to comment.