Skip to content

Commit

Permalink
adding post edit mode with simple test (refs #347, fixes #384)
Browse files Browse the repository at this point in the history
  • Loading branch information
makeusabrew committed Sep 20, 2011
1 parent 8dc6896 commit 5ee941a
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 7 deletions.
24 changes: 24 additions & 0 deletions apps/admin/controllers/admin.php
Expand Up @@ -37,4 +37,28 @@ public function login() {
public function index() {
$this->assign('posts', $this->adminUser->getAllPosts());
}

public function edit_post() {
$post = Table::factory('Posts')->read($this->getMatch('id'));
if ($post == false || $this->adminUser->owns($post) == false) {
return $this->redirectAction("index", "You cannot edit this post");
}
$this->assign('object', $post);
$this->assign('columns', $post->getColumns());
if ($this->request->isPost()) {
$data = array(
"title" => $this->request->getVar('title'),
"url" => $this->request->getVar('url'),
"status" => $this->request->getVar('status'),
"published" => $this->request->getVar('published'),
"content" => $this->request->getVar('content'),
"tags" => $this->request->getVar('tags'),
);
if ($post->setValues($data)) {
$post->save();
return $this->redirectAction("index", "Post updated");
}
$this->setErrors($post->getErrors());
}
}
}
3 changes: 2 additions & 1 deletion apps/admin/paths.php
@@ -1,5 +1,6 @@
<?php
PathManager::loadPaths(
array("/admin/login", "login"),
array("/admin", "index")
array("/admin", "index"),
array("/admin/posts/edit/(?P<id>\d+)", "edit_post")
);
11 changes: 11 additions & 0 deletions apps/admin/views/base.tpl
Expand Up @@ -4,8 +4,19 @@
<meta charset="utf-8">
<title>{block name='title'}{setting value="site.title"}{/block}</title>
<link rel="stylesheet" href="/css/bootstrap-1.2.0.min.css" />
<link rel="stylesheet" href="/css/main.css" />
</head>
<body>
<div class='topbar'>
<div class='topbar-inner'>
<div class='container'>
<h3><a href='/admin'>Administration</a></h3>
<ul class='nav'>
<li><a href="/admin">Home</a></li>
</ul>
</div>
</div>
</div>
{block name='body'}
{/block}
</body>
Expand Down
14 changes: 14 additions & 0 deletions apps/admin/views/edit_post.tpl
@@ -0,0 +1,14 @@
{extends file='admin/views/base.tpl'}
{block name='body'}
<form action="{$current_url}" method="post">
{include file='default/views/helpers/field.tpl' field='title'}
{include file='default/views/helpers/field.tpl' field='url'}
{include file='default/views/helpers/field.tpl' field='status'}
{include file='default/views/helpers/field.tpl' field='published'}
{include file='default/views/helpers/field.tpl' field='content' fclass="editcontent"}
{include file='default/views/helpers/field.tpl' field='tags'}
<div class="actions">
<input type="submit" value="Save" class="btn primary" />
</div>
</form>
{/block}
2 changes: 1 addition & 1 deletion apps/admin/views/login.tpl
Expand Up @@ -5,7 +5,7 @@
{include file="default/views/helpers/field.tpl" field="email"}
{include file="default/views/helpers/field.tpl" field="password"}
<div class="actions">
<input type="submit" value="Send" class="btn primary" />
<input type="submit" value="Login" class="btn primary" />
</div>
</form>
{/block}
6 changes: 3 additions & 3 deletions apps/blog/models/posts.php
Expand Up @@ -74,9 +74,9 @@ class Posts extends Table {
'status' => array(
'type' => 'select',
'options' => array(
'DRAFT',
'PUBLISHED',
'DELETED',
'DRAFT' => 'Draft',
'PUBLISHED' => 'Published',
'DELETED' => 'Deleted',
),
),
'tags' => array(
Expand Down
17 changes: 16 additions & 1 deletion apps/default/views/helpers/field.tpl
Expand Up @@ -25,9 +25,15 @@
{/if}
{/if}
{* simplify if necessary *}
{if $type == "date"}
{if $type == "date" || $type == "datetime"}
{assign var="type" value="text"}
{/if}
{* extra processing *}
{if $type == "select"}
{if !isset($seloptions)}
{assign var="seloptions" value=$coldata.options}
{/if}
{/if}
{* field title please *}
{if !isset($title)}
{if isset($coldata.title)}
Expand Down Expand Up @@ -58,6 +64,14 @@
<div class="input">
{if $type == "textarea"}
<textarea{if isset($placeholder)} placeholder="{$placeholder}"{/if}{if isset($disabled)} disabled=""{/if} id="{$field}" name="{$field}" class="xlarge{if $error} error{/if}"{if $required} required=""{/if}>{if isset($value)}{$value|htmlentities8}{/if}</textarea>
{elseif $type == "select" && isset($seloptions)}
<select{if isset($disabled)} disabled=""{/if} id="{$field}" name="{$field}" class="select{if $error} error{/if}"{if $required} required=""{/if}>
{foreach from=$seloptions item="selopt" key="selkey"}
<option value="{$selkey}"{if isset($value) && $value == $selkey} selected=""{/if}>{$selopt}</option>
{/foreach}
{assign var="selopt" value=null}
{assign var="selkey" value=null}
</select>
{else}
<input{if isset($placeholder)} placeholder="{$placeholder}"{/if}{if isset($disabled)} disabled=""{/if} type="{$type}" id="{$field}" name="{$field}" class="text{if $error} error{/if}" value="{if isset($value)}{$value|htmlentities8}{/if}"{if $required} required=""{/if} />
{/if}
Expand All @@ -73,3 +87,4 @@
{assign var="force_value" value=null}
{assign var="disabled" value=null}
{assign var="required" value=null}
{assign var="seloptions" value=null}
2 changes: 1 addition & 1 deletion jaoss
Submodule jaoss updated 2 files
+4 −0 library/object.php
+8 −0 library/validate.php
5 changes: 5 additions & 0 deletions public/css/main.css
Expand Up @@ -86,3 +86,8 @@ a {
a:hover {
color:#7D001D;
}

.editcontent textarea {
width:800px;
height:400px;
}
13 changes: 13 additions & 0 deletions tests/selenium/AdminTest.php
Expand Up @@ -43,4 +43,17 @@ public function testAdminIndexShowsUsersPosts() {
// make sure we can't see others' posts
$this->assertTextNotPresent("Another Test Post");
}

// @todo need more accurate selectors to verify edited content
public function testAdminEditProcess() {
$this->doValidLogin();
$this->open("/admin/posts/edit/1");
$this->type("id=title", "Test Post (Edited)");
$this->select("id=status", "Draft");
$this->type("id=published", "2011-09-01 12:34:56");
$this->submit("//form");
$this->waitForPageToLoad(10000);
$this->assertTextPresent("Test Post (Edited");
$this->assertTextPresent("2011-09-01 12:34:56");
}
}

0 comments on commit 5ee941a

Please sign in to comment.