Closed #35; various tweaks

- All form.aligned inputs got wrapped with special div for easy width control
- Fixed edit jump bug
This commit is contained in:
Marcin Kurczewski 2013-10-19 20:58:51 +02:00
parent 65df7f8752
commit c6754e5866
16 changed files with 107 additions and 59 deletions

View file

@ -62,10 +62,9 @@ retrievePost=anonymous
favoritePost=registered
editPostSafety.own=registered
editPostSafety.all=moderator
editPostTags.own=registered
editPostTags.all=registered
editPostThumb.own=moderator
editPostThumb.all=moderator
editPostTags=registered
editPostThumb=moderator
editPostSource=moderator
hidePost.own=moderator
hidePost.all=moderator
deletePost.own=moderator

View file

@ -1,35 +1,12 @@
form.auth {
margin: 0 auto;
display: table;
border-collapse:separate;
border-spacing: 0 0.5em;
width: 400px;
}
form.auth div {
display: table-row;
}
form.auth label.left {
display: table-cell;
float: left;
width: 144px;
}
form.auth input {
display: block;
}
form.auth input {
width: 156px;
padding: 5px;
margin: 0;
}
form.auth button {
display: block;
}
form.auth p {
text-align: center;
margin: 10px 0;

View file

@ -253,6 +253,16 @@ form.aligned input[type=checkbox] {
vertical-align: text-top;
}
.input-wrapper {
overflow: hidden;
display: block;
}
.input-wrapper ul.tagit,
.input-wrapper input,
.input-wrapper select {
width: 80%;
}
label {
display: inline-block;
}
@ -263,9 +273,11 @@ button {
font-family: inherit;
font-size: 11pt;
}
ul.tagit,
select,
input:not([type=radio]):not([type=checkbox]):not([type=file]) {
border: 1px solid #ccc;
border-radius: 3px;
}
ul.tagit input {
border: 0 !important;

View file

@ -19,19 +19,19 @@ embed {
color: silver;
}
nav {
#sidebar nav {
margin-bottom: 2em;
}
nav .left {
#sidebar nav .left {
float: left;
}
nav .right {
#sidebar nav .right {
float: right;
}
nav a.disabled {
#sidebar nav a.disabled {
color: silver;
}
nav a.disabled i[class*='icon-'] {
#sidebar nav a.disabled i[class*='icon-'] {
background-color: silver;
}

View file

@ -140,3 +140,7 @@ ul.tagit {
#theSubmit {
margin: 0 auto;
}
.post .form-wrapper {
overflow: hidden;
}

View file

@ -40,10 +40,15 @@
padding: 0;
}
form.aligned label.left {
form.edit label.left {
width: 10em;
}
form.edit .alert {
margin: 1em 0;
}
form.edit select,
form.edit input {
width: 16em;
}

View file

@ -23,7 +23,8 @@ $(function()
$('.tags input').tagit(tagItOptions);
e.preventDefault();
$('form.edit-post').slideDown();
var formDom = $('form.edit-post');
formDom.show().css('height', formDom.height()).hide().slideDown();
});
});

View file

@ -76,10 +76,12 @@ $(function()
var file = postDom.data('file');
var tags = postDom.find('[name=tags]').val();
var safety = postDom.find('[name=safety]:checked').val();
var source = postDom.find('[name=source]').val();
var fd = new FormData();
fd.append('file', file);
fd.append('tags', tags);
fd.append('safety', safety);
fd.append('source', source);
var ajaxData =
{

View file

@ -234,12 +234,15 @@ class PostController
$suppliedSafety = InputHelper::get('safety');
$suppliedSafety = Model_Post::validateSafety($suppliedSafety);
/* tags */
$suppliedTags = InputHelper::get('tags');
$suppliedTags = Model_Post::validateTags($suppliedTags);
$dbTags = Model_Tag::insertOrUpdate($suppliedTags);
/* source */
$suppliedSource = InputHelper::get('source');
$suppliedSource = Model_Post::validateSource($suppliedSource);
/* db storage */
$dbPost = R::dispense('post');
$dbPost->type = $postType;
@ -249,6 +252,7 @@ class PostController
$dbPost->file_size = filesize($suppliedFile['tmp_name']);
$dbPost->mime_type = $mimeType;
$dbPost->safety = $suppliedSafety;
$dbPost->source = $suppliedSource;
$dbPost->hidden = false;
$dbPost->upload_date = time();
$dbPost->image_width = $imageWidth;
@ -325,6 +329,17 @@ class PostController
}
/* source */
$suppliedSource = InputHelper::get('source');
if ($suppliedSource !== null)
{
PrivilegesHelper::confirmWithException(Privilege::EditPostSource, PrivilegesHelper::getIdentitySubPrivilege($post->uploader));
$suppliedSource = Model_Post::validateSource($suppliedSource);
$post->source = $suppliedSource;
$edited = true;
}
/* db storage */
if ($edited)
R::store($post);

View file

@ -28,6 +28,18 @@ class Model_Post extends RedBean_SimpleModel
return $safety;
}
public static function validateSource($source)
{
$source = trim($source);
$maxLength = 100;
if (strlen($source) > $maxLength)
throw new SimpleException('Source must have at most ' . $maxLength . ' characters');
return $source;
}
public static function validateTag($tag)
{
$tag = trim($tag);

View file

@ -9,6 +9,7 @@ class Privilege extends Enum
const EditPostSafety = 6;
const EditPostTags = 7;
const EditPostThumb = 8;
const EditPostSource = 26;
const HidePost = 9;
const DeletePost = 10;
const FeaturePost = 25;

View file

@ -6,12 +6,12 @@
<div>
<label class="left" for="name">User name:</label>
<input id="name" name="name"/>
<div class="input-wrapper"><input id="name" name="name"/></div>
</div>
<div>
<label class="left" for="password">Password:</label>
<input type="password" id="password" name="password"/>
<div class="input-wrapper"><input type="password" id="password" name="password"/></div>
</div>
<?php if (isset($this->context->transport->errorMessage)): ?>

View file

@ -35,9 +35,11 @@
</div>
<div id="post-template" class="post">
<form action="<?php echo \Chibi\UrlHelper::route('post', 'upload') ?>" method="post">
<p class="alert alert-error">Some kind of error</p>
<p class="alert alert-error">Some kind of error</p>
<img class="thumbnail" src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="Thumbnail"/>
<div class="form-wrapper">
<div class="ops">
<a class="move-up-trigger">
move up <span>&uarr;</span>
@ -52,8 +54,7 @@
</a>
</div>
<img class="thumbnail" src="<?php echo \Chibi\UrlHelper::absoluteUrl('/media/img/pixel.gif') ?>" alt="Thumbnail"/>
<div>
<form action="<?php echo \Chibi\UrlHelper::route('post', 'upload') ?>" method="post" class="aligned">
<div class="file-name">
<label class="left">File:</label>
<strong>filename.jpg</strong>
@ -68,11 +69,15 @@
<div class="tags">
<label class="left">Tags:</label>
<input type="text" name="tags" placeholder="enter some tags&hellip;"/>
<div class="input-wrapper"><input type="text" name="tags" placeholder="enter some tags&hellip;"/></div>
</div>
</div>
<div class="clear"></div>
</form>
<div class="source">
<label class="left">Source:</label>
<div class="input-wrapper"><input type="text" name="source" placeholder="where did you get this from? (optional)"/></div>
</div>
</form>
</div>
</div>
<div id="upload-no-posts">

View file

@ -84,6 +84,13 @@
</div>
<?php endif ?>
<div class="key-value source">
<span class="key">Source:</span>
<span class="value" title="<?php echo $val = htmlspecialchars($this->context->transport->post->source) ?>">
<?php echo $val ?>
</span>
</div>
<div class="permalink">
<a href="<?php echo \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $this->context->transport->post->name]) ?>" title="Download">
<i class="icon-dl"></i>
@ -140,6 +147,7 @@
Privilege::EditPostSafety,
Privilege::EditPostTags,
Privilege::EditPostThumb,
Privilege::EditPostSource,
];
$editPostPrivileges = array_fill_keys($editPostPrivileges, false);
foreach (array_keys($editPostPrivileges) as $privilege)
@ -225,15 +233,22 @@
<?php if ($editPostPrivileges[Privilege::EditPostTags]): ?>
<div class="tags">
<label class="left" for="tags">Tags:</label>
<input type="text" name="tags" id="tags" placeholder="enter some tags&hellip;" value="<?php echo join(',', array_map(function($tag) { return $tag->name; }, $this->context->transport->post->sharedTag)) ?>"/>
<div class="input-wrapper"><input type="text" name="tags" id="tags" placeholder="enter some tags&hellip;" value="<?php echo join(',', array_map(function($tag) { return $tag->name; }, $this->context->transport->post->sharedTag)) ?>"/></div>
</div>
<input type="hidden" name="tags-token" id="tags-token" value="<?php echo $this->context->transport->tagsToken ?>"/>
<?php endif ?>
<?php if ($editPostPrivileges[Privilege::EditPostSource]): ?>
<div class="source">
<label class="left" for="source">Source:</label>
<div class="input-wrapper"><input type="text" name="source" id="suorce" value="<?php echo $this->context->transport->post->source ?>"/></div>
</div>
<?php endif ?>
<?php if ($editPostPrivileges[Privilege::EditPostThumb]): ?>
<div class="thumb">
<label class="left" for="thumb">Thumb:</label>
<input type="file" name="thumb" id="thumb"/>
<div class="input-wrapper"><input type="file" name="thumb" id="thumb"/></div>
</div>
<?php endif ?>

View file

@ -16,22 +16,22 @@
<div>
<label class="left" for="name">User name:</label>
<input id="name" name="name" value="<?php echo $this->context->suppliedName ?>" placeholder="e.g. darth_vader" autocomplete="off"/>
<div class="input-wrapper"><input id="name" name="name" value="<?php echo $this->context->suppliedName ?>" placeholder="e.g. darth_vader" autocomplete="off"/></div>
</div>
<div>
<label class="left" for="password1">Password:</label>
<input type="password" id="password1" name="password1" value="<?php echo $this->context->suppliedPassword1 ?>" placeholder="e.g. <?php echo str_repeat('&#x25cf;', 8) ?>" autocomplete="off"/>
<div class="input-wrapper"><input type="password" id="password1" name="password1" value="<?php echo $this->context->suppliedPassword1 ?>" placeholder="e.g. <?php echo str_repeat('&#x25cf;', 8) ?>" autocomplete="off"/></div>
</div>
<div>
<label class="left" for="password2">Password (repeat):</label>
<input type="password" id="password2" name="password2" value="<?php echo $this->context->suppliedPassword2 ?>" placeholder="e.g. <?php echo str_repeat('&#x25cf;', 8) ?>" autocomplete="off"/>
<div class="input-wrapper"><input type="password" id="password2" name="password2" value="<?php echo $this->context->suppliedPassword2 ?>" placeholder="e.g. <?php echo str_repeat('&#x25cf;', 8) ?>" autocomplete="off"/></div>
</div>
<div>
<label class="left" for="email">E-mail address:</label>
<input id="email" name="email" value="<?php echo $this->context->suppliedEmail ?>" placeholder="e.g. vader@empire.gov" autocomplete="off"/>
<div class="input-wrapper"><input id="email" name="email" value="<?php echo $this->context->suppliedEmail ?>" placeholder="e.g. vader@empire.gov" autocomplete="off"/></div>
</div>
<div>

View file

@ -157,7 +157,7 @@
<?php if ($this->context->user->id == $this->context->transport->user->id): ?>
<div class="current-password">
<label class="left" for="current-password">Current password:</label>
<input type="password" name="current-password" id="current-password" placeholder="Current password"/>
<div class="input-wrapper"><input type="password" name="current-password" id="current-password" placeholder="Current password"/></div>
</div>
<hr>
<?php endif ?>
@ -165,32 +165,32 @@
<?php if (PrivilegesHelper::confirm(Privilege::ChangeUserName, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
<div class="nickname">
<label class="left" for="name">Name:</label>
<input type="text" name="name" id="name" placeholder="New name&hellip;" value="<?php echo $this->context->suppliedName ?>"/>
<div class="input-wrapper"><input type="text" name="name" id="name" placeholder="New name&hellip;" value="<?php echo $this->context->suppliedName ?>"/></div>
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(Privilege::ChangeUserEmail, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
<div class="email">
<label class="left" for="name">E-mail:</label>
<input type="text" name="email" id="email" placeholder="New e-mail&hellip;" value="<?php echo $this->context->suppliedEmail ?>"/>
<div class="input-wrapper"><input type="text" name="email" id="email" placeholder="New e-mail&hellip;" value="<?php echo $this->context->suppliedEmail ?>"/></div>
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(Privilege::ChangeUserPassword, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
<div class="password1">
<label class="left" for="password1">New password:</label>
<input type="password" name="password1" id="password1" placeholder="New password&hellip;" value="<?php echo $this->context->suppliedPassword1 ?>"/>
<div class="input-wrapper"><input type="password" name="password1" id="password1" placeholder="New password&hellip;" value="<?php echo $this->context->suppliedPassword1 ?>"/></div>
</div>
<div class="password2">
<label class="left" for="password2"></label>
<input type="password" name="password2" id="password2" placeholder="New password&hellip; (repeat)" value="<?php echo $this->context->suppliedPassword2 ?>"/>
<div class="input-wrapper"><input type="password" name="password2" id="password2" placeholder="New password&hellip; (repeat)" value="<?php echo $this->context->suppliedPassword2 ?>"/></div>
</div>
<?php endif ?>
<?php if (PrivilegesHelper::confirm(Privilege::ChangeUserAccessRank, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->user))): ?>
<div class="access-rank">
<label class="left" for="access-rank">Access rank:</label>
<select name="access-rank" id="access-rank">
<div class="input-wrapper"><select name="access-rank" id="access-rank">
<?php foreach (AccessRank::getAll() as $rank): ?>
<?php if ($rank == AccessRank::Nobody) continue ?>
<?php if (($this->context->suppliedAccessRank != '' and $rank == $this->context->suppliedAccessRank) or ($this->context->suppliedAccessRank == '' and $rank == $this->context->transport->user->access_rank)): ?>
@ -201,7 +201,7 @@
<?php echo TextHelper::camelCaseToHumanCase(AccessRank::toString($rank)) ?>
</option>
<?php endforeach ?>
</select>
</select></div>
</div>
<?php endif ?>
@ -223,7 +223,7 @@
<?php if ($this->context->user->id == $this->context->transport->user->id): ?>
<div class="current-password">
<label class="left" for="current-password">Current password:</label>
<input type="password" name="current-password" id="current-password" placeholder="Current password"/>
<div class="input-wrapper"><input type="password" name="current-password" id="current-password" placeholder="Current password"/></div>
</div>
<?php endif ?>