Permalink
Browse files

Allow user to mark a record category as inactive

  • Loading branch information...
1 parent c4f6251 commit b0b3aa95227eb241c6678e8b26c69388e3419020 @sachac committed Jan 2, 2013
@@ -1,6 +1,6 @@
class RecordCategoriesController < ApplicationController
skip_authorization_check :only => [:autocomplete_record_category_full_name]
- autocomplete :record_category, :full_name, :full => true
+ autocomplete :record_category, :full_name, :full => true, :scopes => [:active]
respond_to :html, :json, :csv, :xml
# GET /record_categories
@@ -20,6 +20,11 @@ def index
def show
authorize! :view_time, current_account
@record_category = current_account.record_categories.find(params[:id])
+ if @record_category.active
+ @title = @record_category.name
+ else
+ @title = @record_category.name + " (" + I18n.t('general.inactive') + ")"
+ end
if request.format.html? or request.format.csv?
params[:order] ||= 'newest'
@order = params[:order]
@@ -7,6 +7,14 @@ class RecordCategory < ActiveRecord::Base
serialize :data
validates_presence_of :name
validates_presence_of :category_type
+
+ after_initialize do
+ if self.new_record?
+ # values will be available for new record forms.
+ self.active = true
+ end
+ end
+
def add_data
self.full_name = self_and_ancestors.reverse.map{ |c| c.name }.join(' - ').html_safe
end
@@ -177,7 +185,7 @@ def get_color
def self.search(account, string, options = {})
split = string.downcase.split
- list = account.record_categories
+ list = account.record_categories.active
split.each do |l|
list = list.where('LOWER(full_name) LIKE LOWER(?)', "%#{l.strip}%")
end
@@ -269,4 +277,6 @@ def category_records(options = {})
dotted_ids
data 'Data' do |data| data.to_json if data and data.size > 0 end
end
+
+ scope :active, where(:active => true)
end
@@ -19,4 +19,4 @@
- else
%li.track= link_to t('app.user.login'), new_user_session_path
%li.feedback{:class => active_menu('/feedback')}= feedback_link
-
+%div{:style => 'clear: both'}
@@ -9,6 +9,7 @@
= l Time.zone.parse(params[:timestamp]), :format => :short
= hidden_field_tag 'timestamp', params[:timestamp]
= f.input :name, :input_html => { :autofocus => true }
+ = f.input :active
- if show_parent and current_account.record_categories.where('id IS NOT NULL AND category_type = ?', 'list').length > 0
= f.input :parent, :collection => current_account.record_categories.where('category_type = ?', 'list').order('full_name').map { |x| [x.full_name, x.id] }
- else
@@ -26,6 +26,9 @@
= action_list(c)
%td
= link_to c.name, c
+ - if !c.active?
+ = surround ' (', ')' do
+ = t('general.inactive')
- if c.list?
&raquo;
- else
@@ -1,4 +1,4 @@
-= setup_page 'categories', @record_category.name, 'time/nav'
+= setup_page 'categories', @title, 'time/nav'
= render 'filters'
- if managing?
View
@@ -12,6 +12,7 @@ en:
delete: Delete
edit: Edit
are_you_sure: Are you sure?
+ inactive: Inactive
library:
request: Request items
time_log:
@@ -0,0 +1,7 @@
+class AddActiveToRecordCategories < ActiveRecord::Migration
+ def change
+ add_column :record_categories, :active, :boolean, :default => true
+ RecordCategory.update_all 'active=true'
+ change_column :record_categories, :active, :boolean, :null => false
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121226135854) do
+ActiveRecord::Schema.define(:version => 20130102150645) do
create_table "clothing", :force => true do |t|
t.string "name"
@@ -314,6 +314,7 @@
t.datetime "updated_at"
t.string "full_name"
t.string "color"
+ t.boolean "active", :default => true, :null => false
end
add_index "record_categories", ["dotted_ids"], :name => "index_record_categories_on_dotted_ids"

0 comments on commit b0b3aa9

Please sign in to comment.