Skip to content
Permalink
Browse files
Add permission management; fix #13 -- pretty metadata
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jan 6, 2015
1 parent c5b6605 commit e80f7c9c0ab87b5ad5d7bf6c9b4721b98f27eb7e

Large diffs are not rendered by default.

@@ -0,0 +1,29 @@
/*
* Copyright © 2014-2015 Roberto Alsina, Henry Hirsch, Chris Warrick.
*
* Permission is hereby granted, free of charge, to any
* person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice
* shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

.save-btn, .save-icon {
transition: all 0.5s ease;
}
@@ -0,0 +1,44 @@
/*
* Copyright © 2014-2015 Roberto Alsina, Henry Hirsch, Chris Warrick.
*
* Permission is hereby granted, free of charge, to any
* person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice
* shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
* KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

function save_anim() {
$(".save-btn").removeClass("btn-primary").addClass("btn-success");
$(".save-icon").removeClass("fa-save").addClass("fa-check");
setTimeout(function() {
$(".save-btn").removeClass("btn-success").addClass("btn-primary");
$(".save-icon").removeClass("fa-check").addClass("fa-save");
}, 2000);
}

function save_fail_anim() {
$(".save-btn").removeClass("btn-primary").addClass("btn-danger");
$(".save-icon").removeClass("fa-save").addClass("fa-times");
setTimeout(function() {
$(".save-btn").removeClass("btn-danger").addClass("btn-primary");
$(".save-icon").removeClass("fa-times").addClass("fa-save");
}, 2000);
}

@@ -1,6 +1,10 @@
{% extends 'base.tmpl' %}
{% block extra_head %}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
{% block extra_js %}
{% if action == 'save' %}
<script>$(document).ready(function() { save_anim(); });</script>
{% elif action == 'save_fail' %}
<script>$(document).ready(function() { save_fail_anim();});</script>
{% endif %}
{% endblock %}
{% block content %}
<h1 class="title">Account <tt>{{ current_user.username }}</tt></h1>
@@ -42,21 +46,25 @@
<h3 class="panel-title">Preferences</h3>
</div>
<div class="panel-body">
<div class="checkbox"><label><input type="checkbox" name="wants_see_others_posts"
{% if current_user.can_see_others_posts and current_user.wants_see_others_posts %}
<div class="checkbox"><label><input type="checkbox" name="wants_all_posts"
{% if current_user.can_edit_all_posts and current_user.wants_all_posts %}
checked
{% endif %}
{% if not current_user.can_see_others_posts %}
{% if not current_user.can_edit_all_posts %}
disabled
{% endif %}
> Show me posts of other users
> Show me posts of other users by default
</label></div>
</div>
</div>

{% if current_user.is_admin %}
<p class="text-muted">You can edit your permissions in the <a
href="/users/permissions">permissions panel</a>.
{% endif %}

<div style="text-align: center;">
<button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> Save</button>
<button type="submit" class="btn btn-primary btn-lg save-btn"><i class="fa fa-save fa-fw save-icon"></i> Save</button>
</div>
</form>

@@ -1,7 +1,5 @@
{% extends 'base.tmpl' %}
{% block extra_head %}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

<style>
.list-group {
margin-top: 10px;
@@ -1,6 +1,5 @@
{% extends 'base.tmpl' %}
{% block extra_head %}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<style>
.form-signin {
max-width: 330px;
@@ -1,88 +1,86 @@
{% extends 'base.tmpl' %}
{% block extra_head %}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

<style>
#toolbar, #post-meta-panel, #content-area {
#post-meta-line, #toolbar, #post-meta-panel, #content-area {
margin-top: 10px;
}
#save-btn, #save-icon {
transition: all 0.5s ease;

#post-meta-line {
padding-left: 0px;
padding-right: 0px;
}

#post-meta-line .input-group-addon {
border-radius: 0;
width: 1%;
}

@-webkit-keyframes fa-unspin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(-359deg);
transform: rotate(-359deg);
}
#post-meta-line .form-control {
border-right: 0;
border-radius: 0;
}

@keyframes fa-unspin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(-359deg);
transform: rotate(-359deg);
}
#post-meta-line .input-group:first-child .input-group-addon {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}

.comet-fa-spin {
-webkit-animation: fa-spin 0.7s infinite linear;
animation: fa-spin 0.7s infinite linear;
#post-meta-line .input-group:last-child .form-control {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
border-right: 1px solid #ccc;
}

.comet-fa-unspin {
-webkit-animation: fa-unspin 0.7s infinite linear;
animation: fa-unspin 0.7s infinite linear;
#post-meta-line .input-group:last-child .form-control:focus {
border-color: #66afe9;
}
</style>
{% endblock %}
{% block extra_js %}
{% if action == 'save' %}
<script>
$(document).ready(function() {
$("#save-btn").removeClass("btn-primary").addClass("btn-success");
$("#save-icon").removeClass("fa-save").addClass("fa-check");
setTimeout(function() {
$("#save-btn").removeClass("btn-success").addClass("btn-primary");
$("#save-icon").removeClass("fa-check").addClass("fa-save");
}, 2000);
});

$('#post-meta').on('show.bs.collapse', function () {
$("#meta-icon").addClass("comet-fa-spin");
})

$('#post-meta').on('hide.bs.collapse', function () {
$("#meta-icon").addClass("comet-fa-unspin");
})

$('#post-meta').on('shown.bs.collapse', function () {
$("#meta-icon").removeClass("comet-fa-spin");
})

$('#post-meta').on('hidden.bs.collapse', function () {
$("#meta-icon").removeClass("comet-fa-unspin");
})
</script>
<script>$(document).ready(function() { save_anim(); });</script>
{% endif %}
{% endblock %}
{% block content %}
<form method="POST" class="form-horizontal" role="form" id="form" action="/edit/{{ post.source_path }}">
<input name="title" value="{{ post.title() }}" class="form-control title input-lg" placeholder="Title">

<div id="post-meta-line" class="metadata form-inline container-fluid"><div class="row">
<div class="input-group col-md-3">
<span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span>
<input class="form-control" name="date" placeholder="Date" value="{{ post.meta('date') }}">
</div><div class="input-group col-md-3">
<span class="input-group-addon"><i class="fa fa-user fa-fw"></i></span>
<select class="form-control" name="author.uid"
{% if not current_user.can_transfer_post_authorship %}
disabled
{% endif %}
>
{% for auid, aname in USERS %}
<option
{% if auid == current_auid %}
selected
{% endif %}
value="{{ auid }}">{{ aname }}</option>
{% endfor %}
</select>
</div><div class="input-group col-md-3">
<span class="input-group-addon"><i class="fa fa-tags fa-fw"></i></span>
<input class="form-control" name="tags" type="text" placeholder="Tags" value="{{ post.meta('tags') }}">
</div><div class="input-group col-md-3">
<span class="input-group-addon"><i class="fa fa-archive fa-fw"></i></span>
<input class="form-control" name="category" type="text" placeholder="Category" value="{{ post.meta('category') }}">
</div>
</div></div>

{% for k,v in post.meta['en'].items() %}
{% if k not in ['title', 'date', 'tags', 'category', 'author', 'author.uid'] %}
<input type="hidden" name="{{ k }}" value="{{ v }}">
{% endif %}
{% endfor %}

<div id="toolbar" class="btn-toolbar">
<div class="btn-group">
<button type="submit" class="btn btn-sm btn-primary" id="save-btn"><i id="save-icon" class="fa fa-save fa-fw"></i> Save</button>
<button class="btn btn-sm btn-info" type="button" data-toggle="collapse"
data-target="#post-meta" aria-expanded="false"
aria-controls="post-meta" id="meta-btn"><i id="meta-icon" class="fa fa-cog fa-fw"></i> Edit metadata</button>
</div>
<div class="btn-group"><button type="submit" class="btn btn-sm btn-primary save-btn"><i id="fa fa-save fa-fw save-icon"></i> Save</button></div>

<div class="btn-group">
<a class="btn btn-default btn-sm" data-wysihtml5-command="bold" title="CTRL+B"><i class="fa fa-bold"></i></a>
@@ -136,32 +134,6 @@ $('#post-meta').on('hidden.bs.collapse', function () {
</label>
</div>
</div>
<div class="collapse" id="post-meta">
<div class="panel panel-info" id="post-meta-panel">
<div class="panel-heading">
<h3 class="panel-title">Metadata</h3>
</div>
<div class="panel-body">
<input name="author.uid" value="{{ _author_uid_get(post) }}" type="hidden">
<div class="form-group">
<label for="author" class="col-sm-2 control-label">Author</label>
<div class="col-sm-10">
<input name="author" value="{{ _author_get(post) }}" class="form-control">
</div>
</div>
{% for k,v in post.meta['en'].items() %}
{% if k not in ['title', 'author', 'author.uid'] %}
<div class="form-group">
<label for="{{ k }}" class="col-sm-2 control-label">{{ k }}</label>
<div class="col-sm-10">
<input name="{{ k }}" value="{{ v }}" class="form-control">
</div>
</div>
{% endif %}
{% endfor %}
</div>
</div>
</div>

<textarea name="content" id="content-area" class="form-control" rows="24">{{ post_content }}</textarea>
</form>

0 comments on commit e80f7c9

Please sign in to comment.