Commit 2e31814423f4c087ad8a406e3787dfc1ee4ef0ca
1 parent
418a9a7c
Exists in
master
and in
5 other branches
Create a generic institution transaction method.
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: David Calos <ddavidcarlos1392@gmail.com>
Showing
1 changed file
with
8 additions
and
19 deletions
Show diff stats
lib/mpog_software_plugin.rb
| @@ -300,26 +300,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -300,26 +300,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
| 300 | def institution_transaction | 300 | def institution_transaction |
| 301 | institution.date_modification = DateTime.now | 301 | institution.date_modification = DateTime.now |
| 302 | institution.save | 302 | institution.save |
| 303 | + institution_models = %w(governmental_power governmental_sphere juridical_nature) | ||
| 303 | 304 | ||
| 304 | - if context.params.has_key?(:governmental_power) | ||
| 305 | - context.profile.institution.governmental_power_id = | ||
| 306 | - context.params[:governmental_power] | ||
| 307 | - | ||
| 308 | - context.profile.institution.save! | ||
| 309 | - end | ||
| 310 | - | ||
| 311 | - if context.params.has_key?(:governmental_sphere) | ||
| 312 | - context.profile.institution.governmental_sphere_id = | ||
| 313 | - context.params[:governmental_sphere] | ||
| 314 | - | ||
| 315 | - context.profile.institution.save! | ||
| 316 | - end | ||
| 317 | - | ||
| 318 | - if context.params.has_key?(:juridical_nature) | ||
| 319 | - context.profile.institution.juridical_nature_id = | ||
| 320 | - context.params[:juridical_nature] | ||
| 321 | - | ||
| 322 | - context.profile.institution.save! | 305 | + institution_models.each do |model| |
| 306 | + call_institution_transaction(model) | ||
| 323 | end | 307 | end |
| 324 | 308 | ||
| 325 | if context.params.has_key?(:institution) | 309 | if context.params.has_key?(:institution) |
| @@ -455,4 +439,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -455,4 +439,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
| 455 | def call_model_transaction(model,name) | 439 | def call_model_transaction(model,name) |
| 456 | send(name + '_transaction') if context.params.has_key?(model.to_sym) | 440 | send(name + '_transaction') if context.params.has_key?(model.to_sym) |
| 457 | end | 441 | end |
| 442 | + | ||
| 443 | + def call_institution_transaction(model) | ||
| 444 | + context.profile.institution.send(model + '_id = ', context.params[model.to_sym]) | ||
| 445 | + context.profile.institution.save! | ||
| 446 | + end | ||
| 458 | end | 447 | end |