Commit 72ec6ae54faf8e48b8dee6c3a99ac89a7e4af722
1 parent
f5aeac9a
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Refactor in tasks.js to create a singleton 'Task', show success icon after save …
…each tag and tasks.css changes
Showing
5 changed files
with
140 additions
and
53 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
@@ -94,7 +94,6 @@ class TasksController < MyProfileController | @@ -94,7 +94,6 @@ class TasksController < MyProfileController | ||
94 | end | 94 | end |
95 | 95 | ||
96 | def save_tags | 96 | def save_tags |
97 | - | ||
98 | if request.post? && params[:tag_list] | 97 | if request.post? && params[:tag_list] |
99 | result = { | 98 | result = { |
100 | success: false, | 99 | success: false, |
@@ -103,7 +102,7 @@ class TasksController < MyProfileController | @@ -103,7 +102,7 @@ class TasksController < MyProfileController | ||
103 | 102 | ||
104 | ActsAsTaggableOn.remove_unused_tags = true | 103 | ActsAsTaggableOn.remove_unused_tags = true |
105 | 104 | ||
106 | - task = profile.tasks.find_by_id params[:task_id] | 105 | + task = Task.to(profile).find_by_id params[:task_id] |
107 | save = user.tag(task, with: params[:tag_list], on: :tags) | 106 | save = user.tag(task, with: params[:tag_list], on: :tags) |
108 | 107 | ||
109 | if save | 108 | if save |
@@ -114,15 +113,22 @@ class TasksController < MyProfileController | @@ -114,15 +113,22 @@ class TasksController < MyProfileController | ||
114 | render json: result | 113 | render json: result |
115 | end | 114 | end |
116 | 115 | ||
117 | - #FIXME make this test | 116 | + # FIXME make this test |
118 | # Should not search for article tasks | 117 | # Should not search for article tasks |
119 | # Should not search for other profile tags | 118 | # Should not search for other profile tags |
120 | # Should search only task tags | 119 | # Should search only task tags |
121 | # Should check the permissions | 120 | # Should check the permissions |
121 | + | ||
122 | def search_tags | 122 | def search_tags |
123 | + | ||
123 | arg = params[:term].downcase | 124 | arg = params[:term].downcase |
125 | + | ||
124 | result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) | 126 | result = ActsAsTaggableOn::Tag.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) |
127 | + | ||
125 | render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' | 128 | render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' |
129 | + | ||
126 | end | 130 | end |
127 | 131 | ||
132 | + end | ||
133 | + | ||
128 | end | 134 | end |
app/views/tasks/index.html.erb
@@ -94,53 +94,7 @@ | @@ -94,53 +94,7 @@ | ||
94 | <%= javascript_include_tag 'tasks' %> | 94 | <%= javascript_include_tag 'tasks' %> |
95 | 95 | ||
96 | <script type="text/javascript"> | 96 | <script type="text/javascript"> |
97 | - | ||
98 | - jQuery('.filter-tags').inputosaurus({ | ||
99 | - hideInput: true | ||
100 | - }); | ||
101 | - | ||
102 | - $('#filter-add-tag').change(function(){ | ||
103 | - | ||
104 | - if($(this).val() != ''){ | ||
105 | - jQuery('.filter-tags').inputosaurus('addTags',$(this).children(':selected').text()); | ||
106 | - } | ||
107 | - }); | ||
108 | - | ||
109 | - jQuery('.tag-list').inputosaurus({ | ||
110 | - autoCompleteSource: <%= "'/myprofile/#{profile.identifier}/tasks/search_tags'," %> | ||
111 | - activateFinalResult: true, | ||
112 | - submitTags: { | ||
113 | - url: <%= "'/myprofile/#{profile.identifier}/tasks/save_tags'" %>, | ||
114 | - beforeSend: function(){ | ||
115 | - this.element.parents('.task_box') | ||
116 | - .prev('.fg-state-error') | ||
117 | - .remove(); | ||
118 | - }, | ||
119 | - success: function(response){ | ||
120 | - | ||
121 | - this.element.parents('.task_box') | ||
122 | - .prev('.fg-state-error') | ||
123 | - .remove(); | ||
124 | - | ||
125 | - if(!response.success){ | ||
126 | - | ||
127 | - var errorIcon = $('<span/>',{ | ||
128 | - 'class':'ui-icon ui-icon-alert', | ||
129 | - style:'float: left; margin-right: .3em;' | ||
130 | - }); | ||
131 | - | ||
132 | - var content = $('<p/>',{ | ||
133 | - html:'<strong>'+response.message+'</strong>' | ||
134 | - }).prepend(errorIcon); | ||
135 | - | ||
136 | - var div = $('<div/>',{ | ||
137 | - 'class':'alert fg-state-error ui-state-error' | ||
138 | - }).append(content); | ||
139 | - | ||
140 | - this.element.parents('.task_box').before(div); | ||
141 | - } | ||
142 | - | ||
143 | - } | ||
144 | - } | 97 | + Task.showTags({ |
98 | + profileIdentifier: <%= "'#{profile.identifier}'" %> | ||
145 | }) | 99 | }) |
146 | </script> | 100 | </script> |
public/javascripts/tasks.js
1 | (function($) { | 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 | $("input.task_accept_radio").click(function(){ | 107 | $("input.task_accept_radio").click(function(){ |
4 | task_id = this.getAttribute("task_id"); | 108 | task_id = this.getAttribute("task_id"); |
5 | $('#on-accept-information-' + task_id).show('fast'); | 109 | $('#on-accept-information-' + task_id).show('fast'); |
@@ -62,4 +166,3 @@ function change_task_responsible(el) { | @@ -62,4 +166,3 @@ function change_task_responsible(el) { | ||
62 | } | 166 | } |
63 | }); | 167 | }); |
64 | } | 168 | } |
65 | - |
public/stylesheets/tasks.css
@@ -61,8 +61,9 @@ | @@ -61,8 +61,9 @@ | ||
61 | margin: 0 5px 0 10px; | 61 | margin: 0 5px 0 10px; |
62 | } | 62 | } |
63 | 63 | ||
64 | -.formfieldline .inputosaurus-container { | 64 | +.inputosaurus-container { |
65 | vertical-align: middle; | 65 | vertical-align: middle; |
66 | + margin-top: -2px; | ||
66 | } | 67 | } |
67 | 68 | ||
68 | .tag-list-fields input { | 69 | .tag-list-fields input { |
@@ -73,3 +74,23 @@ | @@ -73,3 +74,23 @@ | ||
73 | background: url('/images/loading-small.gif') right center no-repeat !important; | 74 | background: url('/images/loading-small.gif') right center no-repeat !important; |
74 | background-color: #fff !important; | 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
@@ -684,6 +684,9 @@ class TasksControllerTest < ActionController::TestCase | @@ -684,6 +684,9 @@ class TasksControllerTest < ActionController::TestCase | ||
684 | 684 | ||
685 | assert_not_includes task_one.tags_from(nil), 'test' | 685 | assert_not_includes task_one.tags_from(nil), 'test' |
686 | end | 686 | end |
687 | +#region_validators_controller_test.rb: give_permission('ze', 'manage_environment_validators', environment) | ||
688 | +#profile_editor_controller_test.rb: user2.stubs(:has_permission?).with('edit_profile', anything).returns(true) | ||
689 | +#profile_editor_controller_test.rb: user2.expects(:has_permission?).with(:manage_friends, anything).returns(true) | ||
687 | 690 | ||
688 | should 'not tag task with permission but another user' do | 691 | should 'not tag task with permission but another user' do |
689 | requestor = fast_create(Person) | 692 | requestor = fast_create(Person) |