Commit fd1f7b2b2030a587159b886052bf551d89011b01
Exists in
master
and in
3 other branches
Merge branch 'html_classes_revision' into 'master'
Html classes revision See merge request !1
Showing
18 changed files
with
170 additions
and
20 deletions
Show diff stats
db/migrate/20150714123613_add_institution_to_comments.rb
0 → 100644
db/migrate/20150814192230_add_institution_id_to_create_community_rating_comment.rb
0 → 100644
features/steps_definitions/gov_user_steps.rb
@@ -66,7 +66,6 @@ Given /^the following public institutions?$/ do |table| | @@ -66,7 +66,6 @@ Given /^the following public institutions?$/ do |table| | ||
66 | end | 66 | end |
67 | end | 67 | end |
68 | 68 | ||
69 | - | ||
70 | Given /^I sleep for (\d+) seconds$/ do |time| | 69 | Given /^I sleep for (\d+) seconds$/ do |time| |
71 | sleep time.to_i | 70 | sleep time.to_i |
72 | end | 71 | end |
@@ -87,4 +86,5 @@ Given /^I am logged in as mpog_admin$/ do | @@ -87,4 +86,5 @@ Given /^I am logged in as mpog_admin$/ do | ||
87 | fill_in("Username", :with => user.login) | 86 | fill_in("Username", :with => user.login) |
88 | fill_in("Password", :with => '123456') | 87 | fill_in("Password", :with => '123456') |
89 | click_button("Log in") | 88 | click_button("Log in") |
90 | -end | ||
91 | \ No newline at end of file | 89 | \ No newline at end of file |
90 | +end | ||
91 | + |
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +require_dependency "comment" | ||
2 | + | ||
3 | +Comment.class_eval do | ||
4 | + attr_accessible :institution_id | ||
5 | + | ||
6 | + belongs_to :institution | ||
7 | + | ||
8 | + validate :verify_institution | ||
9 | + | ||
10 | + private | ||
11 | + | ||
12 | + def verify_institution | ||
13 | + if self.institution_id != nil | ||
14 | + institution = Institution.find_by_id self.institution_id | ||
15 | + self.errors.add :institution, _("not found") unless institution | ||
16 | + end | ||
17 | + end | ||
18 | +end |
lib/gov_user_plugin.rb
@@ -153,6 +153,7 @@ class GovUserPlugin < Noosfero::Plugin | @@ -153,6 +153,7 @@ class GovUserPlugin < Noosfero::Plugin | ||
153 | views/create-institution.js | 153 | views/create-institution.js |
154 | views/new-community.js | 154 | views/new-community.js |
155 | views/user-edit-profile.js | 155 | views/user-edit-profile.js |
156 | + views/gov-user-comments-extra-fields.js | ||
156 | initializer.js | 157 | initializer.js |
157 | app.js | 158 | app.js |
158 | ) | 159 | ) |
@@ -232,6 +233,24 @@ class GovUserPlugin < Noosfero::Plugin | @@ -232,6 +233,24 @@ class GovUserPlugin < Noosfero::Plugin | ||
232 | end | 233 | end |
233 | end | 234 | end |
234 | 235 | ||
236 | + def communities_ratings_plugin_comments_extra_fields | ||
237 | + Proc::new do render :file => 'comments_extra_field' end | ||
238 | + end | ||
239 | + | ||
240 | + def communities_ratings_plugin_extra_fields_show_data user_rating | ||
241 | + if logged_in? | ||
242 | + is_admin = environment.admins.include?(current_user.person) | ||
243 | + is_admin ||= user_rating.community.admins.include?(current_user.person) | ||
244 | + | ||
245 | + if is_admin and context.profile.software? | ||
246 | + Proc::new { | ||
247 | + render :file => 'communities_ratings_extra_fields_show_institution', | ||
248 | + :locals => {:user_rating => user_rating} | ||
249 | + } | ||
250 | + end | ||
251 | + end | ||
252 | + end | ||
253 | + | ||
235 | private | 254 | private |
236 | 255 | ||
237 | def call_model_transaction(model,name) | 256 | def call_model_transaction(model,name) |
lib/institution.rb
public/initializer.js
public/views/create-institution.js
@@ -395,6 +395,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -395,6 +395,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
395 | init: function() { | 395 | init: function() { |
396 | set_form_count_custom_data(); | 396 | set_form_count_custom_data(); |
397 | set_events(); | 397 | set_events(); |
398 | + }, | ||
399 | + | ||
400 | + institution_autocomplete: function(){ | ||
401 | + institution_autocomplete(); | ||
398 | } | 402 | } |
399 | }; | 403 | }; |
400 | }); | 404 | }); |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +modulejs.define("GovUserCommentsExtraFields", ['jquery','CreateInstitution'], function($,CreateInstitution) { | ||
2 | + | ||
3 | + function set_events() { | ||
4 | + CreateInstitution.institution_autocomplete(); | ||
5 | + } | ||
6 | + | ||
7 | + | ||
8 | + function prepend_to_additional_information() { | ||
9 | + var institution_comments = $("#input_institution_comments").remove(); | ||
10 | + | ||
11 | + $(".comments-software-extra-fields").prepend(institution_comments); | ||
12 | + } | ||
13 | + | ||
14 | + | ||
15 | + return { | ||
16 | + isCurrentPage: function() { | ||
17 | + return $(".star-rate-form").length === 1; | ||
18 | + }, | ||
19 | + | ||
20 | + init: function() { | ||
21 | + prepend_to_additional_information(); | ||
22 | + set_events(); | ||
23 | + } | ||
24 | + } | ||
25 | + | ||
26 | +}) |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | ||
3 | + | ||
4 | +class CommentTest < ActiveSupport::TestCase | ||
5 | + include PluginTestHelper | ||
6 | + | ||
7 | + should "validate institution if there an institution_id" do | ||
8 | + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" | ||
9 | + | ||
10 | + assert_equal true, private_institution.save | ||
11 | + | ||
12 | + comment = Comment.new :institution_id => 123456, :body => "simple body" | ||
13 | + comment.valid? | ||
14 | + | ||
15 | + assert_equal true, comment.errors[:institution].include?("not found") | ||
16 | + | ||
17 | + comment.institution = private_institution | ||
18 | + comment.valid? | ||
19 | + | ||
20 | + assert_equal false, comment.errors[:institution].include?("not found") | ||
21 | + end | ||
22 | + | ||
23 | + private | ||
24 | + | ||
25 | + def build_private_institution name, corporate_name, cnpj, country="AR" | ||
26 | + community = Community.new :name => name | ||
27 | + community.country = country | ||
28 | + | ||
29 | + institution = PrivateInstitution.new :name=> name | ||
30 | + institution.corporate_name = corporate_name | ||
31 | + institution.cnpj = cnpj | ||
32 | + institution.community = community | ||
33 | + | ||
34 | + institution | ||
35 | + end | ||
36 | +end | ||
37 | + |
test/unit/gov_user_person_test.rb
@@ -15,6 +15,7 @@ class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase | @@ -15,6 +15,7 @@ class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase | ||
15 | "user@email.com", | 15 | "user@email.com", |
16 | "123456", | 16 | "123456", |
17 | "123456", | 17 | "123456", |
18 | + "user2@email.com", | ||
18 | "Any State", | 19 | "Any State", |
19 | "Some City" | 20 | "Some City" |
20 | ) | 21 | ) |
test/unit/institution_test.rb
@@ -29,34 +29,35 @@ class InstitutionTest < ActiveSupport::TestCase | @@ -29,34 +29,35 @@ class InstitutionTest < ActiveSupport::TestCase | ||
29 | end | 29 | end |
30 | should "not save institutions without name" do | 30 | should "not save institutions without name" do |
31 | @institution.name = nil | 31 | @institution.name = nil |
32 | - assert !@institution.save | ||
33 | - assert @institution.errors.full_messages.include? "Name can't be blank" | 32 | + assert_equal false, @institution.save |
33 | + assert_equal true, @institution.errors.full_messages.include?("Name can't be blank") | ||
34 | end | 34 | end |
35 | 35 | ||
36 | should "not save if institution has invalid type" do | 36 | should "not save if institution has invalid type" do |
37 | invalid_msg = "Type invalid, only public and private institutions are allowed." | 37 | invalid_msg = "Type invalid, only public and private institutions are allowed." |
38 | @institution.type = "Other type" | 38 | @institution.type = "Other type" |
39 | - assert !@institution.save, 'Invalid type' | ||
40 | - assert @institution.errors.full_messages.include? invalid_msg | 39 | + assert_equal false, @institution.save |
40 | + assert_equal true, @institution.errors.full_messages.include?(invalid_msg) | ||
41 | end | 41 | end |
42 | 42 | ||
43 | should "not save without country" do | 43 | should "not save without country" do |
44 | @institution.community.country = nil | 44 | @institution.community.country = nil |
45 | - assert !@institution.save, "Country can't be blank" | ||
46 | - assert @institution.errors.full_messages.include? "Country can't be blank" | 45 | + assert_equal false, @institution.save |
46 | + assert_equal true, @institution.errors.full_messages.include?("Country can't be blank") | ||
47 | end | 47 | end |
48 | 48 | ||
49 | should "not save without state" do | 49 | should "not save without state" do |
50 | @institution.community.state = nil | 50 | @institution.community.state = nil |
51 | 51 | ||
52 | - assert !@institution.save, "State can't be blank" | ||
53 | - assert @institution.errors.full_messages.include? "State can't be blank" | 52 | + assert_equal false, @institution.save |
53 | + assert_equal true, @institution.errors.full_messages.include?("State can't be blank") | ||
54 | end | 54 | end |
55 | 55 | ||
56 | should "not save without city" do | 56 | should "not save without city" do |
57 | @institution.community.city = nil | 57 | @institution.community.city = nil |
58 | + @institution.community.state = "DF" | ||
58 | 59 | ||
59 | - assert !@institution.save, "City can't be blank" | ||
60 | - assert @institution.errors.full_messages.include? "City can't be blank" | 60 | + assert_equal false, @institution.save |
61 | + assert_equal true, @institution.errors.full_messages.include?("City can't be blank") | ||
61 | end | 62 | end |
62 | end | 63 | end |
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<div id="input_institution_comments"> | ||
2 | + <%= label_tag "input_institution", _("Organization name or Enterprise name")%> | ||
3 | + <span class="star-tooltip" title="Órgão ou Empresa que você representa e utiliza o software"></span> | ||
4 | + <input type="text" id="input_institution"> | ||
5 | + | ||
6 | + <%= content_tag(:div, _("No institution found"), | ||
7 | + :id=>"institution_empty_ajax_message", | ||
8 | + :class=>"errorExplanation hide-field") %> | ||
9 | + <%= hidden_field_tag "comments[institution_id]", "", id: "institution_selected" %> | ||
10 | +</div> |
views/communities_ratings_extra_fields_show_institution.html.erb
0 → 100644
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +<% if user_rating.comment and user_rating.comment.institution %> | ||
2 | +<div class="aditional-informations"> | ||
3 | + <div class="comments-user-institution"> | ||
4 | + <span>Institution :<span> <%= user_rating.comment.institution.name unless user_rating.comment.nil? %> | ||
5 | + </div> | ||
6 | +</div> | ||
7 | +<% end %> | ||
8 | + |
views/gov_user_plugin/_institution.html.erb
@@ -24,10 +24,7 @@ | @@ -24,10 +24,7 @@ | ||
24 | 24 | ||
25 | <div> | 25 | <div> |
26 | <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> | 26 | <%= labelled_form_for :community, :url => {:action=>"new_institution"}, :html => { :multipart => true, :id=>"institution_form" } do |f| %> |
27 | - <div class="fields-required"> | ||
28 | - <span class="errorExplanation"><%= required_fields_message %></span> | ||
29 | - </div> | ||
30 | - <br/> | 27 | + <%= required_fields_message %> |
31 | <%= hidden_field_tag "edit_institution_page", false %> | 28 | <%= hidden_field_tag "edit_institution_page", false %> |
32 | <%= fields_for :institutions do |inst| %> | 29 | <%= fields_for :institutions do |inst| %> |
33 | <span class=''> | 30 | <span class=''> |
@@ -114,7 +111,6 @@ | @@ -114,7 +111,6 @@ | ||
114 | <% end %> | 111 | <% end %> |
115 | </div> | 112 | </div> |
116 | </span> | 113 | </span> |
117 | - <br /> | ||
118 | 114 | ||
119 | <% if @url_token == "create_institution_admin" %> | 115 | <% if @url_token == "create_institution_admin" %> |
120 | <%= submit_button :save, _('Save') %> | 116 | <%= submit_button :save, _('Save') %> |
views/gov_user_plugin_myprofile/edit_institution.html.erb
@@ -23,7 +23,6 @@ | @@ -23,7 +23,6 @@ | ||
23 | <div class="fields-required"> | 23 | <div class="fields-required"> |
24 | <span class="errorExplanation"><%= _("All fields with (*) are mandatory") %></span> | 24 | <span class="errorExplanation"><%= _("All fields with (*) are mandatory") %></span> |
25 | </div> | 25 | </div> |
26 | - <br/> | ||
27 | <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %> | 26 | <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %> |
28 | <%= hidden_field_tag "edit_institution_page", true %> | 27 | <%= hidden_field_tag "edit_institution_page", true %> |
29 | <%= fields_for :institutions do |inst| %> | 28 | <%= fields_for :institutions do |inst| %> |
@@ -111,7 +110,6 @@ | @@ -111,7 +110,6 @@ | ||
111 | <% end %> | 110 | <% end %> |
112 | </div> | 111 | </div> |
113 | </span> | 112 | </span> |
114 | - <br /> | ||
115 | 113 | ||
116 | <%= submit_button :save, _('Save') %> | 114 | <%= submit_button :save, _('Save') %> |
117 | <% end %> | 115 | <% end %> |