forked from jcnetdev/jobberrails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/wlodars/jobberrails into wl…
…oards/master
- Loading branch information
Showing
52 changed files
with
991 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
class Admin::CategoriesController < ApplicationController | ||
before_filter :login_required | ||
layout 'admin' | ||
|
||
# GET /admin/categories | ||
def index | ||
@categories = Category.list | ||
end | ||
|
||
# GET /admin/categories/1 | ||
def show | ||
@category = Category.find_by_value(params[:id]) | ||
@jobs = @category.jobs.find_all_by_is_active(true, :order => "created_at DESC") | ||
end | ||
|
||
# POST /admin/categories | ||
def create | ||
max_position = Category.find_by_sql "SELECT MAX(position) as position FROM categories" | ||
max_id = Category.find_by_sql "SELECT MAX(id) as id FROM categories" | ||
@category = Category.new(:name => 'New category', :value => "newcategory#{max_id[0].id + 1}", :position => max_position[0].position + 1) | ||
@category.save | ||
flash_notice("Category has been added") | ||
|
||
respond_to do |format| | ||
format.html { redirect_to admin_categories_url } | ||
format.js # admin/categories/create.js.rjs | ||
end | ||
end | ||
|
||
# PUT /admin/categories/1 | ||
def update | ||
@category = Category.find(params[:id]) | ||
flash_notice("Category has been updated") | ||
|
||
respond_to do |format| | ||
if @category.update_attributes(:name => params[:name], :value => params[:url]) | ||
format.html { redirect_to admin_categories_url } | ||
format.js # admin/categories/update.js.rjs | ||
else | ||
format.html { redirect_to admin_categories_url } | ||
format.js { | ||
render :update do |page| | ||
@category.reload | ||
page.alert @category.errors.full_messages.join("\n") | ||
page.replace("category_#{@category.id}", :partial => 'admin/categories/category', :category => @category) | ||
page.sortable 'categoriesContainer', :tag => 'div', :url => saveorder_admin_categories_path | ||
end | ||
} | ||
end | ||
end | ||
end | ||
|
||
# PUT /admin/categories/saveorder | ||
def saveorder | ||
params[:categoriesContainer].each_with_index do |id, position| | ||
category = Category.find(id) | ||
category.update_attribute('position', position) | ||
end | ||
flash_notice("Categories order changed. Saving ...") | ||
|
||
respond_to do |format| | ||
format.html { redirect_to admin_categories_url } | ||
format.js # admin/categories/saveorder.js.rjs | ||
end | ||
end | ||
|
||
# DELETE /admin/categories/1 | ||
def destroy | ||
@category = Category.find(params[:id]) | ||
@category.destroy if @category.jobs.empty? | ||
flash_notice("Category has been deleted") | ||
|
||
respond_to do |format| | ||
format.html { redirect_to admin_categories_url } | ||
format.js # admin/categories/destroy.js.rjs | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Admin::JobsController < ApplicationController | ||
before_filter :login_required | ||
layout 'admin' | ||
|
||
# GET /admin/jobs | ||
def index | ||
@jobs = Job.find_all_by_is_active(false, :order => 'updated_at DESC') | ||
end | ||
|
||
# GET /admin/jobs/1 | ||
def show | ||
@job = Job.find(params[:id]) | ||
end | ||
|
||
# PUT /admin/jobs/1 | ||
def update | ||
@job = Job.find(params[:id]) | ||
flash_notice("Job has been activated/deactivated") | ||
|
||
respond_to do |format| | ||
if @job.update_attributes(:is_active => @job.is_active ? false : true) | ||
format.html { redirect_to admin_jobs_url } | ||
format.js # admin/jobs/update.js.rjs | ||
end | ||
end | ||
end | ||
|
||
# DELETE /admin/jobs/1 | ||
def destroy | ||
@job = Job.find(params[:id]) | ||
@job.destroy | ||
flash_notice("Job has been deleted") | ||
|
||
respond_to do |format| | ||
format.html { redirect_to admin_jobs_url } | ||
format.js # admin/jobs/destroy.js.rjs | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class SessionsController < ApplicationController | ||
layout 'admin' | ||
|
||
def new | ||
if session[:admin] | ||
redirect_to admin_url | ||
end | ||
end | ||
|
||
def create | ||
admin = Admin.authenticate(params[:login], params[:password]) | ||
if admin | ||
session[:admin] = admin | ||
flash[:notice] = "You are logged as #{admin.login}" | ||
redirect_to admin_url | ||
else | ||
flash[:error] = "Invalid login or password!" | ||
redirect_to login_url | ||
end | ||
end | ||
|
||
def destroy | ||
reset_session | ||
flash[:notice] = "You've been logged out." | ||
redirect_to login_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Admin::CategoriesHelper | ||
def admin_category_nav_item(category) | ||
category_nav_item(category, true) | ||
end | ||
|
||
def show_save_category(category_id) | ||
"Element.show('saveCategory#{category_id}')" | ||
end | ||
|
||
def link_to_delete_category(category_id) | ||
link_to_remote(image_tag("icon-delete.png", :alt => 'Delete') + " Delete", { | ||
:url => admin_category_url(category_id), | ||
:confirm => 'Are you sure you want to delete this category?', | ||
:method => :delete }, | ||
{ :class => 'deleteCategory'}) | ||
end | ||
|
||
def link_to_save_category(category_id) | ||
link_to_remote(image_tag("disk.png", :alt => 'Save') + " Save", { | ||
:url => admin_category_url(category_id), | ||
:method => :put, | ||
:with => "'name='+$F('name[#{category_id}]')+'&url='+$F('url[#{category_id}]')" }, | ||
{ :id => "saveCategory#{category_id}", | ||
:class => 'saveCategory', :style => 'display:none;' }) | ||
end | ||
|
||
def sortable_element_categories_container | ||
sortable_element "categoriesContainer", | ||
:url => saveorder_admin_categories_path, | ||
:tag => "div", | ||
:complete => visual_effect(:highlight, 'categoriesContainer') | ||
end | ||
|
||
def link_to_add_category | ||
link_to_remote image_tag("add.png", :alt => 'Add') + " Add new category", | ||
:url => admin_categories_path, | ||
:method => :post, | ||
:loading => "Element.show('overlay')", | ||
:complete => "Element.hide('overlay');" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Admin::JobsHelper | ||
def activation_image_tag(job) | ||
activate = "activate" | ||
unless job.is_active | ||
activate = "de" + activate | ||
end | ||
image_tag("icon_#{activate}.gif", | ||
:alt => activate.capitalize, | ||
:id => "activate_#{job.id}") | ||
end | ||
|
||
def link_to_activate_deactivate_job(job) | ||
link_to_remote(activation_image_tag(job), { | ||
:url => admin_job_url(job.id), | ||
:method => :put, | ||
:loading => "Element.hide('activ_butt_#{job.id}');Element.show('loading_#{job.id}')", | ||
:complete => "Element.hide('loading_#{job.id}');Element.show('activ_butt_#{job.id}')"}, | ||
{ :id => "activ_butt_#{job.id}"} ) | ||
end | ||
|
||
def link_to_delete_job(job_id) | ||
link_to_remote(image_tag("icon-delete.png", :alt => 'Delete'), | ||
:url => admin_job_url(job_id), | ||
:confirm => 'Are you sure you want to delete this post?', | ||
:method => :delete) | ||
end | ||
|
||
def saving_job_image_tag(job_id) | ||
image_tag("ajax-loader.gif", :alt => "Saving...", | ||
:style => 'display:none', | ||
:id => "loading_#{job_id}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module SessionsHelper | ||
# checks if user is logged in | ||
def logged_in? | ||
session[:admin] ? true : false | ||
end | ||
|
||
# returns currently logged admin | ||
def current_user | ||
session[:admin] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'digest/sha1' | ||
|
||
class Admin < ActiveRecord::Base | ||
validates_length_of :login, :within => 3..40 | ||
validates_length_of :password, :within => 5..40 | ||
validates_presence_of :login, :password | ||
validates_uniqueness_of :login | ||
|
||
attr_protected :id | ||
|
||
def self.authenticate(login, pass) | ||
a = find_by_login(login) | ||
a && Admin.encrypt(pass) == a.password ? a : nil | ||
end | ||
|
||
protected | ||
def self.encrypt(pass) | ||
Digest::SHA1.hexdigest(pass) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.categoryItem{:id => "category_#{category.id}"} | ||
.categoryHandle | ||
.categoryWrapper | ||
.categoryManagement{:style => 'float:right;width:10%;'} | ||
= link_to_delete_category(category.id) | ||
= link_to_save_category(category.id) | ||
%label | ||
%span Name: | ||
= text_field_tag "name[#{category.id}]", category.name, :size => 60 | ||
= observe_field "name[#{category.id}]", :frequency => 1, :function => show_save_category(category.id) | ||
%label | ||
%span URL: | ||
= text_field_tag "url[#{category.id}]", category.value, :size => 60 | ||
= observe_field "url[#{category.id}]", :frequency => 1, :function => show_save_category(category.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%ul | ||
- Category.list.each do |category| | ||
= admin_category_nav_item(category) | ||
= clear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
page.insert_html :bottom, 'categoriesContainer', :partial => 'admin/categories/category' | ||
page.sortable 'categoriesContainer', :tag => 'div', :url => saveorder_admin_categories_path, | ||
:complete => visual_effect(:highlight, 'categoriesContainer') | ||
@category = nil | ||
page.replace_html "categories", :partial => 'admin/categories/list' | ||
page.display_notice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if @category.jobs.empty? | ||
page["category_#{@category.id}"].visual_effect :fade, "category_#{@category.id}" | ||
page.delay(1) do | ||
page.remove "category_#{@category.id}" | ||
end | ||
page.replace_html "categories", :partial => 'admin/categories/list' | ||
page.display_notice | ||
else | ||
page.alert("You cannot delete this category because there are jobs in this category!") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%h2 Categories | ||
|
||
#categoriesContainer | ||
= partial @categories | ||
|
||
= sortable_element_categories_container | ||
|
||
#overlay{:style => "display: none; top: 145px; left: 157px;height: 72px;"} | ||
= image_tag("ajax-loader.gif", :alt => "Loading...") | ||
%p | ||
= link_to_add_category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
page.replace_html "categories", :partial => 'admin/categories/list' | ||
page.display_notice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.job-listings | ||
%h2= "Jobs for " + @category.name.pluralize | ||
= partial "admin/jobs/jobs_table", :jobs => @jobs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
page["category_#{@category.id}"].visual_effect :pulsate, "category_#{@category.id}" | ||
page.hide "saveCategory#{@category.id}" | ||
@category = nil | ||
page.replace_html "categories", :partial => 'admin/categories/list' | ||
page.display_notice |
Oops, something went wrong.