diff options
| author | Luc Donnet | 2014-07-25 09:13:48 +0200 |
|---|---|---|
| committer | Luc Donnet | 2014-07-25 09:13:48 +0200 |
| commit | 8262842ac7872cf8cd082da92e7a1be6076c2dd8 (patch) | |
| tree | 1bf6a6c85ef95fb785d596031bb0b43e234ff6f1 | |
| parent | 0b4da4bba14d0e9f45a8186e3d325051a76509bc (diff) | |
| download | chouette-core-8262842ac7872cf8cd082da92e7a1be6076c2dd8.tar.bz2 | |
Finish to add javascript tags for time_table edit Refs #0026833
| -rw-r--r-- | Gemfile | 3 | ||||
| -rw-r--r-- | Gemfile.lock | 16 | ||||
| -rw-r--r-- | app/assets/javascripts/application.js | 2 | ||||
| -rw-r--r-- | app/assets/stylesheets/application.css.scss.erb | 1 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 6 | ||||
| -rw-r--r-- | app/views/time_tables/_form.erb | 54 | ||||
| -rw-r--r-- | config/locales/time_tables.yml | 4 | ||||
| -rw-r--r-- | config/routes.rb | 1 |
8 files changed, 55 insertions, 32 deletions
@@ -48,7 +48,8 @@ gem 'font-awesome-sass' gem 'will_paginate-bootstrap' gem 'simple_form' gem 'tagmanager-rails', '~> 3.0.1.0' -gem 'typeahead-rails', '~> 0.10.1' +#gem 'typeahead-rails', '~> 0.10.1' +gem "twitter-typeahead-rails", :git => "https://github.com/ldonnet/twitter-typeahead-rails" # Format Output gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index a9d669982..c9796a062 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,14 @@ GIT - remote: https://github.com/afimb/ninoxe.git - revision: ea581b1a6e49ccdc98019a6c382f9ce35a63dcb7 - branch: sismo + remote: https://github.com/ldonnet/twitter-typeahead-rails + revision: 97466061dc7999ba1c7d153fba7ced8df846431a + specs: + twitter-typeahead-rails (0.10.2) + actionpack (>= 3.1) + jquery-rails + railties (>= 3.1) + +PATH + remote: ~/projects/ninoxe specs: ninoxe (1.1.0) activerecord (~> 3.2.13) @@ -338,7 +345,6 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - typeahead-rails (0.10.1) tzinfo (0.3.40) uglifier (1.2.7) execjs (>= 0.3.0) @@ -425,7 +431,7 @@ DEPENDENCIES tagmanager-rails (~> 3.0.1.0) therubyracer (~> 0.10.2) therubyrhino - typeahead-rails (~> 0.10.1) + twitter-typeahead-rails! uglifier (>= 1.0.3) warbler will_paginate (~> 3.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 7a7d16d08..c8ccab68e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,6 @@ //= require raphael //= require morris //= require bootstrap -//= require typeahead +//= require twitter/typeahead.min //= require tagmanager //= require_directory . diff --git a/app/assets/stylesheets/application.css.scss.erb b/app/assets/stylesheets/application.css.scss.erb index 27ba87a84..df34755cf 100644 --- a/app/assets/stylesheets/application.css.scss.erb +++ b/app/assets/stylesheets/application.css.scss.erb @@ -24,6 +24,7 @@ $body-bg: #eee; @import "jquery.ui.all"; @import "morris"; @import "formtastic"; +@import "twitter-typeahead-rails"; @import "vendor/openlayers_style"; @import "vendor/openlayers_ie6-style"; diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index b7598301b..11bb0c7f2 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -49,6 +49,12 @@ class TimeTablesController < ChouetteController redirect_to edit_referential_time_table_path(@referential, @time_table) end + def tags + @tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:tag]}%") + respond_to do |format| + format.json { render :json => @tags.map{|t| {:id => t.id, :name => t.name }} } + end + end protected diff --git a/app/views/time_tables/_form.erb b/app/views/time_tables/_form.erb index ddae4a793..252b3f6f2 100644 --- a/app/views/time_tables/_form.erb +++ b/app/views/time_tables/_form.erb @@ -1,27 +1,19 @@ <%= semantic_form_for [@referential, @time_table] do |form| %> <%= form.inputs do %> <%= form.input :comment %> - <%= form.input :version %> + <%= form.input :version %> + + <%= form.input :tag_search, :input_html => { class: "tm-input typeahead", :placeholder => "Blabla" } %> + <%= form.input :tag_list, :as => :hidden, :input_html => { :id => "tag_list" } %> + + <%= form.input :objectid, :required => !@time_table.new_record? %> <% end %> - <%= form.inputs :class => 'day_type' do %> - <label class="day_type_label"><%= @time_table.human_attribute_name("peculiarities") %></label> + <%= form.inputs :name => "Advanced" do %> + <label class="label"><%= @time_table.human_attribute_name("peculiarities") %></label> <%= form.input :school_holliday, :as => :boolean, :class => "others" %> <%= form.input :public_holliday, :as => :boolean %> <% end %> - <%= form.inputs do %> - <%= form.label :tag_list %> - <%= text_field_tag 'tag_input', nil, class: "tm-input", autocomplete: "off", data:{provide: "typeahead"} %> - <%= hidden_field_tag 'time_table[tag_list]', nil , autocomplete: "off" %> - <%= javascript_tag "var items = #{ @time_table.tag_list.to_json };" %> - <%= javascript_tag "var autocomplete_items = #{ @autocomplete_items.to_json };" %> - <% end %> - - - <%= form.inputs do %> - <%= form.input :objectid, :required => !@time_table.new_record? %> - <% end %> - <h3 class="time_table_periods"> <a class="periods"><%= @time_table.human_attribute_name("periods") %> <%= image_tag("icons/plus.png" , :class => "switcher", :style => "display: none;") %> @@ -95,14 +87,30 @@ <% end %> <% end %> +<%= javascript_tag "var items = #{ @time_table.tag_list.to_a };" %> + <script> -$(".tm-input").tagsManager( - { - prefilled: items, - output: '#time_table_tag_list' - - }); - + $(".tm-input").tagsManager( + { + prefilled: items, + output: '#tag_list' + }); + + var time_tables_tag_list = new Bloodhound({ + datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'), + queryTokenizer: Bloodhound.tokenizers.whitespace, + prefetch: '<%= tags_referential_time_tables_path(@referential, :format => 'json') %>', + remote: '<%= tags_referential_time_tables_path(@referential, :format => 'json') %>?tag=%QUERY', + }); + + time_tables_tag_list.initialize(); + + $(".typeahead").typeahead(null, { + name: 'time_tables_tag_list', + displayKey: 'name', + source: time_tables_tag_list.ttAdapter() + }); + </script> diff --git a/config/locales/time_tables.yml b/config/locales/time_tables.yml index e19eaaf57..7e62e2d2f 100644 --- a/config/locales/time_tables.yml +++ b/config/locales/time_tables.yml @@ -72,7 +72,7 @@ en: periods: "Application periods" period_start: "From" period_end: "to" - + tag_search: "Tags" formtastic: hints: time_table: @@ -152,7 +152,7 @@ fr: periods: "Périodes d'application" period_start: "Du" period_end: "au" - + tag_search: "Tags" formtastic: hints: time_table: diff --git a/config/routes.rb b/config/routes.rb index e4241a62d..a14f09b48 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -126,6 +126,7 @@ ChouetteIhm::Application.routes.draw do resources :time_tables do collection do get :comment_filter + get :tags end member do get 'duplicate' |
