Commit d7d222b8a9b5be26cf3f947e70d3764f558d85f9

Authored by Leandro Santos
2 parents 379c7653 9aac75fc

Merge branch 'task_taggable' into production

app/controllers/my_profile/tasks_controller.rb
... ... @@ -117,7 +117,6 @@ class TasksController < MyProfileController
117 117 end
118 118  
119 119 def save_tags
120   -
121 120 if request.post? && params[:tag_list]
122 121 result = {
123 122 success: false,
... ... @@ -126,7 +125,7 @@ class TasksController < MyProfileController
126 125  
127 126 ActsAsTaggableOn.remove_unused_tags = true
128 127  
129   - task = profile.tasks.find_by_id params[:task_id]
  128 + task = Task.to(profile).find_by_id params[:task_id]
130 129 save = user.tag(task, with: params[:tag_list], on: :tags)
131 130  
132 131 if save
... ... @@ -137,15 +136,20 @@ class TasksController < MyProfileController
137 136 render json: result
138 137 end
139 138  
140   - #FIXME make this test
  139 + # FIXME make this test
141 140 # Should not search for article tasks
142 141 # Should not search for other profile tags
143 142 # Should search only task tags
144 143 # Should check the permissions
  144 +
145 145 def search_tags
  146 +
146 147 arg = params[:term].downcase
  148 +
147 149 result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"])
  150 +
148 151 render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json'
  152 +
149 153 end
150 154  
151 155 end
... ...
app/views/tasks/index.html.erb
... ... @@ -101,53 +101,7 @@
101 101 <%= javascript_include_tag 'tasks' %>
102 102  
103 103 <script type="text/javascript">
104   -
105   - jQuery('.filter-tags').inputosaurus({
106   - hideInput: true
107   - });
108   -
109   - $('#filter-add-tag').change(function(){
110   -
111   - if($(this).val() != ''){
112   - jQuery('.filter-tags').inputosaurus('addTags',$(this).children(':selected').text());
113   - }
114   - });
115   -
116   - jQuery('.tag-list').inputosaurus({
117   - autoCompleteSource: <%= "'/myprofile/#{profile.identifier}/tasks/search_tags'," %>
118   - activateFinalResult: true,
119   - submitTags: {
120   - url: <%= "'/myprofile/#{profile.identifier}/tasks/save_tags'" %>,
121   - beforeSend: function(){
122   - this.element.parents('.task_box')
123   - .prev('.fg-state-error')
124   - .remove();
125   - },
126   - success: function(response){
127   -
128   - this.element.parents('.task_box')
129   - .prev('.fg-state-error')
130   - .remove();
131   -
132   - if(!response.success){
133   -
134   - var errorIcon = $('<span/>',{
135   - 'class':'ui-icon ui-icon-alert',
136   - style:'float: left; margin-right: .3em;'
137   - });
138   -
139   - var content = $('<p/>',{
140   - html:'<strong>'+response.message+'</strong>'
141   - }).prepend(errorIcon);
142   -
143   - var div = $('<div/>',{
144   - 'class':'alert fg-state-error ui-state-error'
145   - }).append(content);
146   -
147   - this.element.parents('.task_box').before(div);
148   - }
149   -
150   - }
151   - }
  104 + Task.showTags({
  105 + profileIdentifier: <%= "'#{profile.identifier}'" %>
152 106 })
153 107 </script>
... ...
public/images/ok.png 0 → 100644

870 Bytes

public/javascripts/tasks.js
1 1 (function($) {
2 2  
  3 + /**
  4 + * @class Task singleton created with module pattern
  5 + */
  6 + Task = (function(){
  7 +
  8 + var _showError = function(context,response){
  9 +
  10 + var errorIcon = $('<span/>',{
  11 + 'class':'ui-icon ui-icon-alert',
  12 + style:'float: left; margin-right: .3em;'
  13 + });
  14 +
  15 + var content = $('<p/>',{
  16 + html:'<strong>'+response.message+'</strong>'
  17 + }).prepend(errorIcon);
  18 +
  19 + var div = $('<div/>',{
  20 + 'class':'alert fg-state-error ui-state-error'
  21 + }).append(content);
  22 +
  23 + context.element.parents('.task_box').before(div);
  24 +
  25 + };
  26 +
  27 + var _showSuccess = function(context,response){
  28 + _addIcon(context,'ok');
  29 +
  30 + setTimeout(function(){
  31 + $('.ok').parent().remove();
  32 + },1000);
  33 + };
  34 +
  35 + var _addIcon = function(context,className){
  36 + $('.'+className).parent().remove();
  37 +
  38 + var item = $('<li/>',{
  39 + 'class':'inputosaurus-input tag-saved',
  40 + html:'<i class="'+className+'"></i>'
  41 + });
  42 +
  43 + if(className == 'ok'){
  44 + $('.loading').parent().remove();
  45 + }
  46 + context.elements.input.parent().before(item);
  47 + }
  48 +
  49 + return {
  50 +
  51 + /**
  52 + * @see inputosaurus#_sendTags The 'this' context here is the jquery ui widget component
  53 + */
  54 + onAddTag: function(response){
  55 + this.element.parents('.task_box')
  56 + .prev('.fg-state-error')
  57 + .remove();
  58 +
  59 + if(response.success){
  60 +
  61 + _showSuccess(this,response);
  62 + }else{
  63 +
  64 + _showError(this,response);
  65 + }
  66 + },
  67 + showTags: function(cfg){
  68 +
  69 + jQuery('.filter-tags').inputosaurus({
  70 + hideInput: true
  71 + });
  72 +
  73 + $('#filter-add-tag').change(function(){
  74 +
  75 + if($(this).val() != ''){
  76 + jQuery('.filter-tags').inputosaurus('addTags',$(this).children(':selected').text());
  77 + }
  78 + });
  79 +
  80 + jQuery('.tag-list').inputosaurus({
  81 + autoCompleteSource: '/myprofile/'+cfg.profileIdentifier+'/tasks/search_tags',
  82 + activateFinalResult: true,
  83 + submitTags: {
  84 + url: '/myprofile/'+cfg.profileIdentifier+'/tasks/save_tags',
  85 + beforeSend: function(){
  86 +
  87 + $('.ok').parent().remove();
  88 +
  89 + this.element.parents('.task_box')
  90 + .prev('.fg-state-error')
  91 + .remove();
  92 +
  93 + _addIcon(this,'loading');
  94 +
  95 + //Add loading here!
  96 + },
  97 + success: this.onAddTag
  98 + }
  99 + });
  100 +
  101 + }
  102 +
  103 + };
  104 +
  105 + })();
  106 +
3 107 $("input.task_accept_radio").click(function(){
4 108 task_id = this.getAttribute("task_id");
5 109 $('#on-accept-information-' + task_id).show('fast');
... ... @@ -78,4 +182,3 @@ function change_task_responsible(el) {
78 182 }
79 183 });
80 184 }
81   -
... ...
public/stylesheets/tasks.css
... ... @@ -61,8 +61,9 @@
61 61 margin: 0 5px 0 10px;
62 62 }
63 63  
64   -.formfieldline .inputosaurus-container {
  64 +.inputosaurus-container {
65 65 vertical-align: middle;
  66 + margin-top: -2px;
66 67 }
67 68  
68 69 .tag-list-fields input {
... ... @@ -73,3 +74,23 @@
73 74 background: url('/images/loading-small.gif') right center no-repeat !important;
74 75 background-color: #fff !important;
75 76 }
  77 +
  78 +.tag-saved {
  79 + width: 24px;
  80 + height: 24px;
  81 + background: none !important;
  82 +}
  83 +
  84 +.ok {
  85 + position: absolute;
  86 + width: 24px;
  87 + height: 24px;
  88 + background: url('/images/ok.png') right center no-repeat
  89 +}
  90 +
  91 +.loading {
  92 + position: absolute;
  93 + width: 24px;
  94 + height: 24px;
  95 + background: url('/images/loading-small.gif') right center no-repeat
  96 +}
... ...
test/functional/tasks_controller_test.rb
... ... @@ -715,6 +715,9 @@ class TasksControllerTest &lt; ActionController::TestCase
715 715  
716 716 assert_not_includes task_one.tags_from(nil), 'test'
717 717 end
  718 +#region_validators_controller_test.rb: give_permission('ze', 'manage_environment_validators', environment)
  719 +#profile_editor_controller_test.rb: user2.stubs(:has_permission?).with('edit_profile', anything).returns(true)
  720 +#profile_editor_controller_test.rb: user2.expects(:has_permission?).with(:manage_friends, anything).returns(true)
718 721  
719 722 should 'not tag task with permission but another user' do
720 723 requestor = fast_create(Person)
... ...