Skip to content

Commit

Permalink
issue #27 - job/unjob posts
Browse files Browse the repository at this point in the history
  • Loading branch information
sic2 committed Oct 15, 2016
1 parent 14fa28f commit eef1189
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
12 changes: 12 additions & 0 deletions webapp/app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def make_post_active
post.save
end

def make_post_unjob
post = Post.find(params[:postid])
post.tags = ''
post.save
end

def make_post_job
post = Post.find(params[:postid])
post.tags = 'job'
post.save
end

def ban_user
user = User.find(params[:userid])
user.banned = true
Expand Down
45 changes: 44 additions & 1 deletion webapp/app/views/admin/_poststable.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<table class="table table-hover table-condensed" id="posts-table">
<thead>
<tr>
<th></th>
<th>Author</th>
<th>Content</th>
<th colspan="2">Actions</th>
<th colspan="3">Actions</th>
</tr>
</thead>

<tbody>
<% posts.each do |post| %>
<tr>
<td><i class="fa <%= post_icon post.post_type %>"></i></td>
<td><%= post.author_name %></td>
<td><%= truncate(post.content) if post.content %></td>
<td>SHOW</td>
Expand All @@ -19,6 +21,12 @@
<% else %>
<button id="state-post" data-post-id="<%= post.id %>" class="btn btn-outline-success activate-post-btn btn-sm">Show</button>
<% end %>
<% if post.tags == 'job' %>
<button data-post-job-id="<%= post.id %>" class="btn btn-outline-warning deactivate-post-job-btn btn-sm">Un-Job</button>
<% else %>
<button id="state-post" data-post-job-id="<%= post.id %>" class="btn btn-outline-primary activate-post-job-btn btn-sm">Job</button>
<% end %>
</td>
</tr>
<% end %>
Expand Down Expand Up @@ -60,5 +68,40 @@
console.log("Error: " + e);
})
});

$("#posts-table").on("click", ".deactivate-post-job-btn", function () {
var $this = $(this);
var postid = $this.attr("data-post-job-id");

$.ajax({
url: "/admin/make_post_unjob",
type: 'PUT',
data: {
postid: postid
}
}).done(function () {
$this.text("Job").removeClass("btn-outline-warning deactivate-post-job-btn").addClass("btn-outline-primary activate-post-job-btn");
}).fail(function (e) {
console.log("errore" + e);
})
});

$("#posts-table").on("click", ".activate-post-job-btn", function () {
var $this = $(this);
var postid = $this.attr("data-post-job-id");

$.ajax({
url: "/admin/make_post_job",
type: 'PUT',
data: {
postid: postid
}
}).done(function () {
$this.text("Un-Job").removeClass("btn-outline-primary activate-post-job-btn").addClass("btn-outline-warning deactivate-post-job-btn");
}).fail(function (e) {
console.log("Error: " + e);
})
});
});
</script>

2 changes: 2 additions & 0 deletions webapp/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
delete 'admin/delete_page', to: 'admin#delete_page'
put 'admin/make_post_active', to: 'admin#make_post_active'
put 'admin/make_post_inactive', to: 'admin#make_post_inactive'
put 'admin/make_post_job', to: 'admin#make_post_job'
put 'admin/make_post_unjob', to: 'admin#make_post_unjob'
put 'admin/ban_user', to: 'admin#ban_user'
put 'admin/unban_user', to: 'admin#unban_user'

Expand Down

0 comments on commit eef1189

Please sign in to comment.