Commit be2a533f43f97276d6cd7ba6682c0e66415d5512
1 parent
27e1092c
Exists in
master
and in
5 other branches
Add link to create institution on admin panel
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
5 changed files
with
124 additions
and
104 deletions
Show diff stats
controllers/mpog_software_plugin_controller.rb
@@ -46,8 +46,19 @@ class MpogSoftwarePluginController < ApplicationController | @@ -46,8 +46,19 @@ class MpogSoftwarePluginController < ApplicationController | ||
46 | end | 46 | end |
47 | end | 47 | end |
48 | 48 | ||
49 | + def create_institution_admin | ||
50 | + | ||
51 | + end | ||
52 | + | ||
53 | + def split_http_referer http_referer | ||
54 | + split_list = [] | ||
55 | + split_list = http_referer.split("/") | ||
56 | + return split_list.last | ||
57 | + end | ||
58 | + | ||
59 | + | ||
49 | def new_institution | 60 | def new_institution |
50 | - if request.xhr? and !params[:community].nil? and !params[:institution].nil? | 61 | + if !params[:community].nil? and !params[:institution].nil? |
51 | response_message = {} | 62 | response_message = {} |
52 | 63 | ||
53 | institution = private_create_institution | 64 | institution = private_create_institution |
@@ -57,9 +68,12 @@ class MpogSoftwarePluginController < ApplicationController | @@ -57,9 +68,12 @@ class MpogSoftwarePluginController < ApplicationController | ||
57 | else | 68 | else |
58 | {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} | 69 | {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} |
59 | end | 70 | end |
60 | - | 71 | + if request.xhr? and (split_http_referer(request.referer()) != "create_institution_admin") |
61 | render :json => response_message.to_json | 72 | render :json => response_message.to_json |
62 | else | 73 | else |
74 | + session[:notice] = response_message # consume the notice | ||
75 | + end | ||
76 | + else | ||
63 | redirect_to "/" | 77 | redirect_to "/" |
64 | end | 78 | end |
65 | end | 79 | end |
lib/mpog_software_plugin.rb
@@ -291,6 +291,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -291,6 +291,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
291 | percentege | 291 | percentege |
292 | end | 292 | end |
293 | 293 | ||
294 | + def admin_panel_links | ||
295 | + [{:title => _('Create Institution'), :url => {:controller => 'mpog_software_plugin', :action => 'create_institution_admin'}}] | ||
296 | + end | ||
297 | + | ||
294 | protected | 298 | protected |
295 | 299 | ||
296 | def create_url_to_edit_profile person | 300 | def create_url_to_edit_profile person |
@@ -0,0 +1,102 @@ | @@ -0,0 +1,102 @@ | ||
1 | +<h1><%= _('New Institution') %></h1> | ||
2 | + | ||
3 | +<% if environment.enabled?('admin_must_approve_new_communities') %> | ||
4 | + <div class='explanation'> | ||
5 | + <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%> | ||
6 | + </div> | ||
7 | +<%end %> | ||
8 | + | ||
9 | +<% unless @errors.blank? %> | ||
10 | +<div class="errorExplanation" id="errorExplanation"> | ||
11 | + <h2> <%= _("Can`t create new Institution: #{@errors.length} errors") %> </h2> | ||
12 | + <ul> | ||
13 | + <% @errors.each do |error| %> | ||
14 | + <li> <%= error %> </li> | ||
15 | + <% end %> | ||
16 | + </ul> | ||
17 | +</div> | ||
18 | +<% end %> | ||
19 | + | ||
20 | +<div id = 'create_institution_errors' class='errorExplanation hide-field'></div> | ||
21 | + | ||
22 | +<div> | ||
23 | + <%= labelled_form_for :community, :html => { :multipart => true, :id=>"institution_form" } do |f| %> | ||
24 | + <%= required f.text_field(:name) %> | ||
25 | + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | ||
26 | + | ||
27 | + <%= required select_country(_('Country'), f, 'country', {:class => 'type-select', :id => "community_country"}) %> | ||
28 | + <%= required f.text_field(:state) %> | ||
29 | + <%= required f.text_field(:city) %> | ||
30 | + | ||
31 | + <%= fields_for :institutions do |inst| %> | ||
32 | + | ||
33 | + <span class='required-field'> | ||
34 | + <div class="formfield type-text"> | ||
35 | + <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | ||
36 | + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> | ||
37 | + </div> | ||
38 | + </span> | ||
39 | + | ||
40 | + <span class=''> | ||
41 | + <div class='formfield type-radio'> | ||
42 | + <%= label_tag("type_PublicInstitution", _("Public Institution")) %> | ||
43 | + <%= radio_button_tag(:type,"PublicInstitution", true)%> | ||
44 | + <%= label_tag("type_PrivateInstitution", _("Private Institution")) %> | ||
45 | + <%= radio_button_tag(:type,"PrivateInstitution")%> | ||
46 | + </div> | ||
47 | + </span> | ||
48 | + | ||
49 | + <span class='optional-field'> | ||
50 | + <div class="formfield type-text"> | ||
51 | + <%= hidden_field_tag "acronym_translate", _("Acronym") %> | ||
52 | + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> | ||
53 | + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> | ||
54 | + <%= inst.text_field(:acronym) %> | ||
55 | + </div> | ||
56 | + </span> | ||
57 | + | ||
58 | + <span class='required-field public-institutions-fields'> | ||
59 | + <div class="formfield type-text"> | ||
60 | + <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | ||
61 | + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=>0})%> | ||
62 | + </div> | ||
63 | + </span> | ||
64 | + | ||
65 | + <span class='required-field public-institutions-fields'> | ||
66 | + <div class="formfield type-text"> | ||
67 | + <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | ||
68 | + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>0})%> | ||
69 | + </div> | ||
70 | + </span> | ||
71 | + | ||
72 | + <span class='required-field public-institutions-fields'> | ||
73 | + <div class="formfield type-text"> | ||
74 | + <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | ||
75 | + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> | ||
76 | + </div> | ||
77 | + </span> | ||
78 | + | ||
79 | + <span class='required-field public-institutions-fields'> | ||
80 | + <div class="formfield type-text"> | ||
81 | + <%= _("SISP?") %> | ||
82 | + <% if @show_sisp_field %> | ||
83 | + <%= inst.label("sisp" ,_("Yes")) %> | ||
84 | + <%= inst.radio_button(:sisp, true) %> | ||
85 | + <%= inst.label("sisp" ,_("No")) %> | ||
86 | + <%= inst.radio_button(:sisp, false) %> | ||
87 | + <% else %> | ||
88 | + <%= inst.label("sisp", _("No")) %> | ||
89 | + <% end %> | ||
90 | + </div> | ||
91 | + </span> | ||
92 | + <br /> | ||
93 | + | ||
94 | + <div> | ||
95 | + <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %> | ||
96 | + </div> | ||
97 | + <%= hidden_field_tag :institution_error_message, _("Could not send the form data to the server") %> | ||
98 | + <% end %> | ||
99 | + | ||
100 | + <% end %> | ||
101 | +</div> | ||
102 | +<%= hidden_field_tag :loading_message, _("Creating institution") %> |
views/mpog_software_plugin/create_institution.html.erb
1 | -<h1><%= _('New Institution') %></h1> | ||
2 | - | ||
3 | -<% if environment.enabled?('admin_must_approve_new_communities') %> | ||
4 | - <div class='explanation'> | ||
5 | - <%= _("Note that the creation of communities in this environment is restricted. Your request to create this new community will be sent to %{environment} administrators and will be approved or rejected according to their methods and criteria.") % { :environment => environment.name }%> | ||
6 | - </div> | ||
7 | -<%end %> | ||
8 | - | ||
9 | -<% unless @errors.blank? %> | ||
10 | -<div class="errorExplanation" id="errorExplanation"> | ||
11 | - <h2> <%= _("Can`t create new Institution: #{@errors.length} errors") %> </h2> | ||
12 | - <ul> | ||
13 | - <% @errors.each do |error| %> | ||
14 | - <li> <%= error %> </li> | ||
15 | - <% end %> | ||
16 | - </ul> | ||
17 | -</div> | ||
18 | -<% end %> | ||
19 | - | ||
20 | -<div id = 'create_institution_errors' class='errorExplanation hide-field'></div> | ||
21 | - | ||
22 | -<div> | ||
23 | - <%= labelled_form_for :community, :html => { :multipart => true, :id=>"institution_form" } do |f| %> | ||
24 | - <%= required f.text_field(:name) %> | ||
25 | - <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | ||
26 | - | ||
27 | - <%= required select_country(_('Country'), f, 'country', {:class => 'type-select', :id => "community_country"}) %> | ||
28 | - <%= required f.text_field(:state) %> | ||
29 | - <%= required f.text_field(:city) %> | ||
30 | - | ||
31 | - <%= fields_for :institutions do |inst| %> | ||
32 | - | ||
33 | - <span class='required-field'> | ||
34 | - <div class="formfield type-text"> | ||
35 | - <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> | ||
36 | - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> | ||
37 | - </div> | ||
38 | - </span> | ||
39 | - | ||
40 | - <span class=''> | ||
41 | - <div class='formfield type-radio'> | ||
42 | - <%= label_tag("type_PublicInstitution", _("Public Institution")) %> | ||
43 | - <%= radio_button_tag(:type,"PublicInstitution", true)%> | ||
44 | - <%= label_tag("type_PrivateInstitution", _("Private Institution")) %> | ||
45 | - <%= radio_button_tag(:type,"PrivateInstitution")%> | ||
46 | - </div> | ||
47 | - </span> | ||
48 | - | ||
49 | - <span class='optional-field'> | ||
50 | - <div class="formfield type-text"> | ||
51 | - <%= hidden_field_tag "acronym_translate", _("Acronym") %> | ||
52 | - <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> | ||
53 | - <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> | ||
54 | - <%= inst.text_field(:acronym) %> | ||
55 | - </div> | ||
56 | - </span> | ||
57 | - | ||
58 | - <span class='required-field public-institutions-fields'> | ||
59 | - <div class="formfield type-text"> | ||
60 | - <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> | ||
61 | - <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=>0})%> | ||
62 | - </div> | ||
63 | - </span> | ||
64 | - | ||
65 | - <span class='required-field public-institutions-fields'> | ||
66 | - <div class="formfield type-text"> | ||
67 | - <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> | ||
68 | - <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>0})%> | ||
69 | - </div> | ||
70 | - </span> | ||
71 | - | ||
72 | - <span class='required-field public-institutions-fields'> | ||
73 | - <div class="formfield type-text"> | ||
74 | - <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> | ||
75 | - <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> | ||
76 | - </div> | ||
77 | - </span> | ||
78 | - | ||
79 | - <span class='required-field public-institutions-fields'> | ||
80 | - <div class="formfield type-text"> | ||
81 | - <%= _("SISP?") %> | ||
82 | - <% if @show_sisp_field %> | ||
83 | - <%= inst.label("sisp" ,_("Yes")) %> | ||
84 | - <%= inst.radio_button(:sisp, true) %> | ||
85 | - <%= inst.label("sisp" ,_("No")) %> | ||
86 | - <%= inst.radio_button(:sisp, false) %> | ||
87 | - <% else %> | ||
88 | - <%= inst.label("sisp", _("No")) %> | ||
89 | - <% end %> | ||
90 | - </div> | ||
91 | - </span> | ||
92 | - <br /> | ||
93 | - | ||
94 | - <div> | ||
95 | - <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %> | ||
96 | - </div> | ||
97 | - <%= hidden_field_tag :institution_error_message, _("Could not send the form data to the server") %> | ||
98 | - <% end %> | ||
99 | - | ||
100 | - <% end %> | ||
101 | -</div> | ||
102 | -<%= hidden_field_tag :loading_message, _("Creating institution") %> | 1 | +<%= render :partial => "institution" %> |
views/mpog_software_plugin/create_institution_admin.html.erb
0 → 100644
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +<%= render :partial => "institution" %> |