From be2a533f43f97276d6cd7ba6682c0e66415d5512 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Mon, 27 Oct 2014 17:58:12 -0200 Subject: [PATCH] Add link to create institution on admin panel --- controllers/mpog_software_plugin_controller.rb | 18 ++++++++++++++++-- lib/mpog_software_plugin.rb | 4 ++++ views/mpog_software_plugin/_institution.html.erb | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views/mpog_software_plugin/create_institution.html.erb | 103 +------------------------------------------------------------------------------------------------------ views/mpog_software_plugin/create_institution_admin.html.erb | 1 + 5 files changed, 124 insertions(+), 104 deletions(-) create mode 100644 views/mpog_software_plugin/_institution.html.erb create mode 100644 views/mpog_software_plugin/create_institution_admin.html.erb diff --git a/controllers/mpog_software_plugin_controller.rb b/controllers/mpog_software_plugin_controller.rb index ba4059e..7124a36 100644 --- a/controllers/mpog_software_plugin_controller.rb +++ b/controllers/mpog_software_plugin_controller.rb @@ -46,8 +46,19 @@ class MpogSoftwarePluginController < ApplicationController end end + def create_institution_admin + + end + + def split_http_referer http_referer + split_list = [] + split_list = http_referer.split("/") + return split_list.last + end + + def new_institution - if request.xhr? and !params[:community].nil? and !params[:institution].nil? + if !params[:community].nil? and !params[:institution].nil? response_message = {} institution = private_create_institution @@ -57,9 +68,12 @@ class MpogSoftwarePluginController < ApplicationController else {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} end - + if request.xhr? and (split_http_referer(request.referer()) != "create_institution_admin") render :json => response_message.to_json else + session[:notice] = response_message # consume the notice + end + else redirect_to "/" end end diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index 5b51814..e39026a 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -291,6 +291,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin percentege end + def admin_panel_links + [{:title => _('Create Institution'), :url => {:controller => 'mpog_software_plugin', :action => 'create_institution_admin'}}] + end + protected def create_url_to_edit_profile person diff --git a/views/mpog_software_plugin/_institution.html.erb b/views/mpog_software_plugin/_institution.html.erb new file mode 100644 index 0000000..399c05e --- /dev/null +++ b/views/mpog_software_plugin/_institution.html.erb @@ -0,0 +1,102 @@ +

<%= _('New Institution') %>

+ +<% if environment.enabled?('admin_must_approve_new_communities') %> +
+ <%= _("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 }%> +
+<%end %> + +<% unless @errors.blank? %> +
+

<%= _("Can`t create new Institution: #{@errors.length} errors") %>

+ +
+<% end %> + +
+ +
+ <%= labelled_form_for :community, :html => { :multipart => true, :id=>"institution_form" } do |f| %> + <%= required f.text_field(:name) %> + <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> + + <%= required select_country(_('Country'), f, 'country', {:class => 'type-select', :id => "community_country"}) %> + <%= required f.text_field(:state) %> + <%= required f.text_field(:city) %> + + <%= fields_for :institutions do |inst| %> + + +
+ <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> + <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> +
+
+ + +
+ <%= label_tag("type_PublicInstitution", _("Public Institution")) %> + <%= radio_button_tag(:type,"PublicInstitution", true)%> + <%= label_tag("type_PrivateInstitution", _("Private Institution")) %> + <%= radio_button_tag(:type,"PrivateInstitution")%> +
+
+ + +
+ <%= hidden_field_tag "acronym_translate", _("Acronym") %> + <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> + <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> + <%= inst.text_field(:acronym) %> +
+
+ + +
+ <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> + <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=>0})%> +
+
+ + +
+ <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> + <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>0})%> +
+
+ + +
+ <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> + <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> +
+
+ + +
+ <%= _("SISP?") %> + <% if @show_sisp_field %> + <%= inst.label("sisp" ,_("Yes")) %> + <%= inst.radio_button(:sisp, true) %> + <%= inst.label("sisp" ,_("No")) %> + <%= inst.radio_button(:sisp, false) %> + <% else %> + <%= inst.label("sisp", _("No")) %> + <% end %> +
+
+
+ +
+ <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %> +
+ <%= hidden_field_tag :institution_error_message, _("Could not send the form data to the server") %> + <% end %> + + <% end %> +
+<%= hidden_field_tag :loading_message, _("Creating institution") %> diff --git a/views/mpog_software_plugin/create_institution.html.erb b/views/mpog_software_plugin/create_institution.html.erb index c6e8cca..037140f 100644 --- a/views/mpog_software_plugin/create_institution.html.erb +++ b/views/mpog_software_plugin/create_institution.html.erb @@ -1,102 +1 @@ -

<%= _('New Institution') %>

- -<% if environment.enabled?('admin_must_approve_new_communities') %> -
- <%= _("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 }%> -
-<%end %> - -<% unless @errors.blank? %> -
-

<%= _("Can`t create new Institution: #{@errors.length} errors") %>

- -
-<% end %> - -
- -
- <%= labelled_form_for :community, :html => { :multipart => true, :id=>"institution_form" } do |f| %> - <%= required f.text_field(:name) %> - <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> - - <%= required select_country(_('Country'), f, 'country', {:class => 'type-select', :id => "community_country"}) %> - <%= required f.text_field(:state) %> - <%= required f.text_field(:city) %> - - <%= fields_for :institutions do |inst| %> - - -
- <%= inst.label("cnpj" ,_("CNPJ"), :class=>"formlabel") %> - <%= required inst.text_field(:cnpj, :placeholder=>"99.999.999/9999-99", :class=>"intitution_cnpj_field") %> -
-
- - -
- <%= label_tag("type_PublicInstitution", _("Public Institution")) %> - <%= radio_button_tag(:type,"PublicInstitution", true)%> - <%= label_tag("type_PrivateInstitution", _("Private Institution")) %> - <%= radio_button_tag(:type,"PrivateInstitution")%> -
-
- - -
- <%= hidden_field_tag "acronym_translate", _("Acronym") %> - <%= hidden_field_tag "fantasy_name_translate", _("Fantasy name") %> - <%= inst.label("acronym" ,_("Acronym"), :class=>"formlabel") %> - <%= inst.text_field(:acronym) %> -
-
- - -
- <%= inst.label("governmental_power_id" ,_("Governmental Power:"), :class=>"formlabel") %> - <%= inst.select(:governmental_power, [[_("Select a Governmental Power"), 0]]|GovernmentalPower.all.map {|g| [g.name, g.id]}, {:selected=>0})%> -
-
- - -
- <%= inst.label("governmental_sphere_id" ,_("Governmental Sphere:"), :class=>"formlabel") %> - <%= inst.select(:governmental_sphere, [[_("Select a Governmental Sphere"), 0]]|GovernmentalSphere.all.map {|s| [s.name, s.id]}, {:selected=>0})%> -
-
- - -
- <%= inst.label("juridical_nature_id" ,_("Juridical Nature:"), :class=>"formlabel") %> - <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> -
-
- - -
- <%= _("SISP?") %> - <% if @show_sisp_field %> - <%= inst.label("sisp" ,_("Yes")) %> - <%= inst.radio_button(:sisp, true) %> - <%= inst.label("sisp" ,_("No")) %> - <%= inst.radio_button(:sisp, false) %> - <% else %> - <%= inst.label("sisp", _("No")) %> - <% end %> -
-
-
- -
- <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %> -
- <%= hidden_field_tag :institution_error_message, _("Could not send the form data to the server") %> - <% end %> - - <% end %> -
-<%= hidden_field_tag :loading_message, _("Creating institution") %> +<%= render :partial => "institution" %> diff --git a/views/mpog_software_plugin/create_institution_admin.html.erb b/views/mpog_software_plugin/create_institution_admin.html.erb new file mode 100644 index 0000000..037140f --- /dev/null +++ b/views/mpog_software_plugin/create_institution_admin.html.erb @@ -0,0 +1 @@ +<%= render :partial => "institution" %> -- libgit2 0.21.2