Permalink
Browse files

super_tags controller, views and features

  • Loading branch information...
1 parent 5c41daf commit 93e1c37d412cf4bafd5ce8c5c9f78a6a2301616c @warp warp committed Aug 11, 2010
Showing with 662 additions and 337 deletions.
  1. +27 −55 app/controllers/admin/customfields_controller.rb
  2. +218 −0 app/controllers/admin/super_tags_controller.rb
  3. +0 −242 app/helpers/application_helper.rb
  4. +28 −27 app/models/customfield.rb
  5. +8 −0 app/views/admin/super_tags/_create.html.haml
  6. +9 −0 app/views/admin/super_tags/_edit.html.haml
  7. +12 −0 app/views/admin/super_tags/_options.html.haml
  8. +2 −0 app/views/admin/super_tags/_sidebar_index.html.haml
  9. +3 −0 app/views/admin/super_tags/_sidebar_show.html.haml
  10. +10 −0 app/views/admin/super_tags/_sort_by.html.haml
  11. +13 −0 app/views/admin/super_tags/_super_tag.html.haml
  12. +9 −0 app/views/admin/super_tags/_top_section.html.haml
  13. +13 −0 app/views/admin/super_tags/create.js.rjs
  14. +7 −0 app/views/admin/super_tags/destroy.js.rjs
  15. +34 −0 app/views/admin/super_tags/edit.js.rjs
  16. +18 −0 app/views/admin/super_tags/index.html.haml
  17. +6 −0 app/views/admin/super_tags/index.js.rjs
  18. +9 −0 app/views/admin/super_tags/new.js.rjs
  19. +10 −0 app/views/admin/super_tags/options.js.rjs
  20. +19 −0 app/views/admin/super_tags/show.html.haml
  21. +15 −0 app/views/admin/super_tags/update.js.rjs
  22. +4 −4 app/views/common/_empty.html.haml
  23. +8 −0 config/cucumber.yml
  24. +4 −2 config/routes.rb
  25. +2 −1 db/migrate/001_create_customfields.rb
  26. +77 −0 features/manage_super_tags.feature
  27. +13 −0 features/step_definitions/super_tag_steps.rb
  28. +7 −0 features/super_tags.feature
  29. +5 −0 features/support/plugin.rb
  30. +7 −6 init.rb
  31. +31 −0 lib/factories.rb
  32. +34 −0 lib/super_tag.rb
@@ -1,16 +1,16 @@
# Fat Free CRM
# Copyright (C) 2008-2009 by Michael Dvorkin
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------------
@@ -19,34 +19,13 @@
##
# custom fields - work in progress, shouldnt be used in any case until further development is completed, Please do not use.
##
-## TODO close link, re align the directory due to admin/ folder - not working
-## TODO make a log file for importing the customfield changes, i.e. the cf table should reflect migration files, so when the db is dropped you can quickly import the
-## list of migrations that were generated from customfields will be back into the custom fields table
## TODO - choosen not to have auto complete search, but enable this
####
class Admin::CustomfieldsController < Admin::ApplicationController
before_filter :require_user
before_filter :set_current_tab, :only => [ :index, :show ]
before_filter :auto_complete, :only => :auto_complete
- before_filter :check_for_needed_migrations
-
-
-
-
- # GET /customfields
- # GET /customfields.xml AJAX and HTML
- #----------------------------------------------------------------------------
- def index
- @customfields = get_customfields(:page => params[:page])
- #@current_schema=ActiveRecord::Migrator.current_version
- #@migration_file_count=Dir.glob("db/migrate/*").size
- respond_to do |format|
- format.html # index.html.haml
- format.js # index.js.rjs
- format.xml { render :xml => @customfields }
- end
- end
# GET /customfields/1
# GET /customfields/1.xml HTML
@@ -66,11 +45,11 @@ def show
# GET /customfields/new.xml AJAX
#----------------------------------------------------------------------------
def new
- @customfield = Customfield.new(:user => @current_user)
- @table_name=%w(Account Contact Opportunity)
- @type=%w(Integer Decimal Float String Date Text)
- @users = User.except(@current_user).all
- @disabled=false
+ @customfield = Customfield.new(:user => @current_user, :tag_id => params[:tag_id])
+ @table_name = %w(Account Contact Opportunity)
+ @type = %w(Integer Decimal Float String Date Text)
+ @users = User.except(@current_user).all
+ @disabled = false
#@customfield.user=@current_user
respond_to do |format|
format.js # new.js.rjs
@@ -84,15 +63,15 @@ def new
# GET /customfields/1/edit AJAX
#----------------------------------------------------------------------------
def edit
- @customfield = Customfield.find(params[:id])
- @table_name=%w(Account Contact Opportunity)
- @type=%w(Integer Decimal Float String Date Text)
- @disabled=:disabled
+ @customfield = Customfield.find(params[:id])
+ @table_name = %w(Account Contact Opportunity)
+ @type = %w(Integer Decimal Float String Date Text)
+ @disabled = :disabled
if params[:previous] =~ /(\d+)\z/
@previous = Customfield.find($1)
end
-
+
rescue ActiveRecord::RecordNotFound
@previous ||= $1.to_i
respond_to_not_found(:js) unless @customfield
@@ -102,20 +81,23 @@ def edit
# POST /customfields.xml AJAX
#----------------------------------------------------------------------------
def create
- @table_name=%w(Account Contact Opportunity)
- @type=%w(Integer Decimal Float String Date Text)
+ @table_name = %w(Account Contact Opportunity)
+ @type = %w(Integer Decimal Float String Date Text)
@customfield = Customfield.new(params[:customfield])
- @disabled=false
+ @disabled = false
respond_to do |format|
if @customfield.save
- @customfields = get_customfields if called_from_index_page?
- set_migration_info
- format.js # create.js.rjs
- format.xml { render :xml => @customfield, :status => :created, :location => @customfield }
- else
- format.js # create.js.rjs
- format.xml { render :xml => @customfield.errors, :status => :unprocessable_entity }
+ @customfields = if params[:customfield][:tag_id]
+ ActsAsTaggableOn::Tag.find(params[:customfield][:tag_id]).customfields
+ elsif called_from_index_page?
+ get_customfields
+ end
+ format.js # create.js.rjs
+ format.xml { render :xml => @customfield, :status => :created, :location => @customfield }
+ else
+ format.js # create.js.rjs
+ format.xml { render :xml => @customfield.errors, :status => :unprocessable_entity }
end
end
end
@@ -187,20 +169,10 @@ def redraw
@current_user.pref[:customfields_outline] = params[:outline] if params[:outline]
@current_user.pref[:customfields_sort_by] = Customfield::SORT_BY[params[:sort_by]] if params[:sort_by]
@customfields = get_customfields(:page => 1) # Start one the first page.
-
+
render :action => :index
end
-
- def check_for_needed_migrations
- @current_schema=ActiveRecord::Migrator.current_version
- @migration_file_count=ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations.size
- end
- def set_migration_info
- #@current_schema=%x{rake.bat db:version}.split(' ').last.to_i
- #@migration_file_count=Dir.glob("db/migrate/*").size
- end
-
private
#----------------------------------------------------------------------------
def get_customfields(options = { :page => nil, :query => nil })
@@ -0,0 +1,218 @@
+# Fat Free CRM
+# Copyright (C) 2008-2009 by Michael Dvorkin
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#------------------------------------------------------------------------------
+
+class Admin::SuperTagsController < Admin::ApplicationController
+ before_filter :require_user
+ before_filter :set_current_tab, :only => [ :index, :show ]
+ before_filter :auto_complete, :only => :auto_complete
+
+ # GET /super_tags
+ # GET /super_tags.xml AJAX and HTML
+ #----------------------------------------------------------------------------
+ def index
+ @super_tags = get_super_tags(:page => params[:page])
+
+ respond_to do |format|
+ format.html # index.html.haml
+ format.js # index.js.rjs
+ format.xml { render :xml => @super_tags }
+ end
+ end
+
+ # GET /super_tags/1
+ # GET /super_tags/1.xml HTML
+ #----------------------------------------------------------------------------
+ def show
+ @super_tag = ActsAsTaggableOn::Tag.find(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @super_tag }
+ end
+
+ rescue ActiveRecord::RecordNotFound
+ respond_to_not_found(:html, :xml)
+ end
+
+ # GET /super_tags/new
+ # GET /super_tags/new.xml AJAX
+ #----------------------------------------------------------------------------
+ def new
+ @super_tag = ActsAsTaggableOn::Tag.new
+ @disabled = false
+
+ respond_to do |format|
+ format.js # new.js.rjs
+ format.xml { render :xml => @super_tag }
+ end
+
+ rescue ActiveRecord::RecordNotFound # Kicks in if related asset was not found.
+ respond_to_not_found(:html, :xml)
+ end
+
+ # GET /super_tags/1/edit AJAX
+ #----------------------------------------------------------------------------
+ def edit
+ @super_tag = ActsAsTaggableOn::Tag.find(params[:id])
+ @disabled = :disabled
+
+ if params[:previous] =~ /(\d+)\z/
+ @previous = ActsAsTaggableOn::Tag.find($1)
+ end
+
+ rescue ActiveRecord::RecordNotFound
+ @previous ||= $1.to_i
+ respond_to_not_found(:js) unless @super_tag
+ end
+
+ # POST /super_tags
+ # POST /super_tags.xml AJAX
+ #----------------------------------------------------------------------------
+ def create
+ @super_tag = ActsAsTaggableOn::Tag.new(params[:acts_as_taggable_on_tag])
+ @disabled = false
+
+ respond_to do |format|
+ if @super_tag.save
+ @super_tags = get_super_tags if called_from_index_page?
+ format.js # create.js.rjs
+ format.xml { render :xml => @super_tag, :status => :created, :location => @super_tag }
+ else
+ format.js # create.js.rjs
+ format.xml { render :xml => @super_tag.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /super_tags/1
+ # PUT /super_tags/1.xml AJAX
+ #----------------------------------------------------------------------------
+ def update
+ @super_tag = ActsAsTaggableOn::Tag.find(params[:id])
+ respond_to do |format|
+ if @super_tag.update_attributes(params[:acts_as_taggable_on_tag])
+ format.js
+ format.xml { head :ok }
+ else
+ format.js
+ format.xml { render :xml => @super_tag.errors, :status => :unprocessable_entity }
+ end
+ end
+
+ rescue ActiveRecord::RecordNotFound
+ respond_to_not_found(:js, :xml)
+ end
+
+ # DELETE /super_tags/1
+ # DELETE /super_tags/1.xml HTML and AJAX
+ #----------------------------------------------------------------------------
+ def destroy
+ @super_tag = ActsAsTaggableOn::Tag.find(params[:id])
+ @super_tag.destroy if @super_tag
+ respond_to do |format|
+ format.html { respond_to_destroy(:html) }
+ format.js { respond_to_destroy(:ajax) }
+ format.xml { head :ok }
+ end
+ rescue ActiveRecord::RecordNotFound
+ respond_to_not_found(:html, :js, :xml)
+ end
+
+ # GET /super_tags/search/query AJAX
+ #----------------------------------------------------------------------------
+ def search
+ @super_tags = get_super_tags(:query => params[:query], :page => 1)
+
+ respond_to do |format|
+ format.js { render :action => :index }
+ format.xml { render :xml => @super_tags.to_xml }
+ end
+ end
+
+ # POST /super_tags/auto_complete/query AJAX
+ #----------------------------------------------------------------------------
+ # Handled by before_filter :auto_complete, :only => :auto_complete
+
+ # GET /super_tags/options AJAX
+ #----------------------------------------------------------------------------
+ def options
+ unless params[:cancel] == "true"
+ @per_page = @current_user.pref[:super_tags_per_page] || ActsAsTaggableOn::Tag.per_page
+ @outline = @current_user.pref[:super_tags_outline] || ActsAsTaggableOn::Tag.outline
+ @sort_by = @current_user.pref[:super_tags_sort_by] || ActsAsTaggableOn::Tag.sort_by
+ @sort_by = ActsAsTaggableOn::Tag::SORT_BY.invert[@sort_by]
+ end
+ end
+
+ # POST /super_tags/redraw AJAX
+ #----------------------------------------------------------------------------
+ def redraw
+ @current_user.pref[:super_tags_per_page] = params[:per_page] if params[:per_page]
+ @current_user.pref[:super_tags_outline] = params[:outline] if params[:outline]
+ @current_user.pref[:super_tags_sort_by] = ActsAsTaggableOn::Tag::SORT_BY[params[:sort_by]] if params[:sort_by]
+ @super_tags = get_super_tags(:page => 1) # Start one the first page.
+
+ render :action => :index
+ end
+
+ private
+ #----------------------------------------------------------------------------
+ def get_super_tags(options = { :page => nil, :query => nil })
+ self.current_page = options[:page] if options[:page]
+ self.current_query = options[:query] if options[:query]
+
+ records = {
+ :user => @current_user,
+ :order => @current_user.pref[:super_tags_sort_by] || ActsAsTaggableOn::Tag.sort_by
+ }
+ pages = {
+ :page => current_page,
+ :per_page => @current_user.pref[:super_tags_per_page]
+ }
+
+ # Call :get_super_tags hook and return its output if any.
+ super_tags = hook(:get_super_tags, self, :records => records, :pages => pages)
+ return super_tags.last unless super_tags.empty?
+
+ # Default processing if no :get_super_tags hooks are present.
+ if current_query.blank?
+ ActsAsTaggableOn::Tag.find(:all)
+ else
+ ActsAsTaggableOn::Tag.search(current_query)
+ end.paginate(pages)
+ end
+
+ #----------------------------------------------------------------------------
+ def respond_to_destroy(method)
+ if method == :ajax
+ if called_from_index_page?
+ @super_tags = get_super_tags
+ if @super_tags.blank?
+ @super_tags = get_super_tags(:page => current_page - 1) if current_page > 1
+ render :action => :index and return
+ end
+ else
+ self.current_page = 1
+ end
+ # At this point render destroy.js.rjs
+ else
+ self.current_page = 1
+ flash[:notice] = "#{@super_tag.name} has beed deleted."
+ redirect_to(admin_super_tags_path)
+ end
+ end
+
+end
Oops, something went wrong.

0 comments on commit 93e1c37

Please sign in to comment.