diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 3fcee17..3992d63 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -4,6 +4,12 @@ class CmsController < MyProfileController include ArticleHelper + def search_tags + arg = params[:term].downcase + result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) + render :text => prepare_to_token_input2(result).to_json + end + def self.protect_if(*args) before_filter(*args) do |c| user, profile = c.send(:user), c.send(:profile) diff --git a/app/helpers/article_helper.rb b/app/helpers/article_helper.rb index 26bc18d..afcc572 100644 --- a/app/helpers/article_helper.rb +++ b/app/helpers/article_helper.rb @@ -83,6 +83,10 @@ module ArticleHelper array.map { |object| {:id => object.id, :name => object.name} } end + def prepare_to_token_input2(array) + array.map { |object| {:label => object.name, :value => object.name} } + end + def cms_label_for_new_children _('New article') end diff --git a/app/views/cms/edit.html.erb b/app/views/cms/edit.html.erb index c38af1c..ba4ed80 100644 --- a/app/views/cms/edit.html.erb +++ b/app/views/cms/edit.html.erb @@ -31,8 +31,18 @@ <%= select_categories(:article, _('Categorize your article')) %> +
+ + <%= stylesheet_link_tag('inputosaurus') %> + <%= f.text_field('tag_list', :size => 64) %> - <%= content_tag( 'small', _('Separate tags with commas') ) %> + +
<%= options_for_article(@article, @tokenized_children) %> diff --git a/app/views/layouts/_javascript.html.erb b/app/views/layouts/_javascript.html.erb index 33c05d4..f33bdc4 100644 --- a/app/views/layouts/_javascript.html.erb +++ b/app/views/layouts/_javascript.html.erb @@ -4,7 +4,7 @@ 'jquery-ui-1.10.4/js/jquery-ui-1.10.4.min', 'jquery.scrollTo', 'jquery.form.js', 'jquery-validation/jquery.validate', 'jquery.cookie', 'jquery.ba-bbq.min.js', 'reflection', 'jquery.tokeninput', 'add-and-join', 'report-abuse', 'catalog', 'manage-products', 'autogrow', -'jquery-timepicker-addon/dist/jquery-ui-timepicker-addon', 'application.js', 'rails.js', :cache => 'cache/application' %> +'jquery-timepicker-addon/dist/jquery-ui-timepicker-addon', 'application.js', 'rails.js', 'inputosaurus.js', :cache => 'cache/application' %> <% language = FastGettext.locale %> <% %w{messages methods}.each do |type| %> diff --git a/public/javascripts/inputosaurus.js b/public/javascripts/inputosaurus.js new file mode 100644 index 0000000..999d1a0 --- /dev/null +++ b/public/javascripts/inputosaurus.js @@ -0,0 +1,523 @@ +/** + * Inputosaurus Text + * + * Must be instantiated on an element + * Allows multiple input items. Each item is represented with a removable tag that appears to be inside the input area. + * + * @requires: + * + * jQuery 1.7+ + * jQueryUI 1.8+ Core + * + * @version 0.1.6 + * @author Dan Kielp + * @created October 3,2012 + * + */ + + +(function($) { + + var inputosaurustext = { + + version: "0.1.6", + + eventprefix: "inputosaurus", + + options: { + + // bindable events + // + // 'change' - triggered whenever a tag is added or removed (should be similar to binding the the change event of the instantiated input + // 'keyup' - keyup event on the newly created input + + // while typing, the user can separate values using these delimiters + // the value tags are created on the fly when an inputDelimiter is detected + inputDelimiters : [',', ';'], + + // this separator is used to rejoin all input items back to the value of the original + outputDelimiter : ',', + + allowDuplicates : false, + + parseOnBlur : false, + + // optional wrapper for widget + wrapperElement : null, + + width : null, + + // simply passing an autoComplete source (array, string or function) will instantiate autocomplete functionality + autoCompleteSource : '', + + // When forcing users to select from the autocomplete list, allow them to press 'Enter' to select an item if it's the only option left. + activateFinalResult : false, + + // manipulate and return the input value after parseInput() parsing + // the array of tag names is passed and expected to be returned as an array after manipulation + parseHook : null, + + // define a placeholder to display when the input is empty + placeholder: null, + + // when you check for duplicates it check for the case + caseSensitiveDuplicates: false + }, + + _create: function() { + var widget = this, + els = {}, + o = widget.options, + placeholder = o.placeholder || this.element.attr('placeholder') || null; + + this._chosenValues = []; + + // Create the elements + els.ul = $('