Skip to content

Commit

Permalink
Edit field type only can be done through select list
Browse files Browse the repository at this point in the history
  • Loading branch information
clbustos committed Mar 6, 2018
1 parent f621ece commit 90621e2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,5 @@ en:
"yes": "yes"
You_re_the_administrator_of_this_systematic_review: "You’re the administrator of this systematic review"
References_count_to_canonical: "<strong>Canonical references:</strong> cited by %{in} / reference to %{out} / %{in_sta} cited by STA"
create_new_field: "Create new personalized field"
create_new_field: "Create new personalized field"
Select_an_option: "Select an option"
3 changes: 2 additions & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,5 @@ es:
"yes": ""
You_re_the_administrator_of_this_systematic_review: "Usted es el administrador de esta revisión sistemática"
References_count_to_canonical: "<strong>Referencias canónicas:</strong> citado por %{in} / referencia a %{out} / %{in_sta} citado por TTR "
create_new_field: "Create new personalized field"
create_new_field: "Create new personalized field"
Select_an_option: "Seleccione una opción"
2 changes: 2 additions & 0 deletions controllers/reviews/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
raise Buhos::NoReviewIdError, rs_id if !@review

@campos=@review.fields

@xselect=get_xeditable_select(SrField.types_hash, "/review/edit_field/nil/type", 'select-type')
haml %s{systematic_reviews/fields}
end

Expand Down
6 changes: 6 additions & 0 deletions model/rs_campo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class SrField < Sequel::Model
def self.is_valid_type?(type)
AVAILABLE_TYPES.include? type.to_s.chomp.to_sym
end
def self.types_hash
AVAILABLE_TYPES.inject({}) {|ac,v|
ac[v]=I18n::t("fields.#{v}")
ac
}
end
def self.types_a_sequel(campo)
if campo[:type] == 'text'
[campo[:name].to_sym, String, null: true]
Expand Down
40 changes: 24 additions & 16 deletions views/systematic_reviews/fields.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@
%a{:href=>url("/review/#{@review.id}")}[email protected]
%li{:class=>:active}=t(:Fields)

:javascript
#{@xselect.javascript}

- if @campos.empty?
%p
%em=t(:No_fields)
- else
%ul.list-group
-@campos.each do |campo|
%li.list-group-item
=a_editable(campo[:id], 'campo-order', "/review/edit_field/#{campo[:id]}/order", campo[:order])
%span=".-"
=a_editable(campo[:id], 'campo-name', "/review/edit_field/#{campo[:id]}/name", campo[:name])
%span=":"
=a_textarea_editable(campo[:id], 'campo-description', "/review/edit_field/#{campo[:id]}/description", campo[:description])
%span=". #{t(:Type)}: "
=a_editable(campo[:id], 'campo-type', "/review/edit_field/#{campo[:id]}/type", campo[:type])
%span=". #{t(:Options)}: "
=a_textarea_editable(campo[:id], 'campo-options', "/review/edit_field/#{campo[:id]}/options", campo[:options])
.btn-group.btn-group-sm
%a.btn.btn-danger{:href=>"/review/#{@review[:id]}/field/#{campo[:id]}/delete"}
%span.glyphicon.glyphicon-remove
=t(:Delete)
%table.table.table-bordered
%thead
%tr
%th=t(:Order)
%th=t(:Description)
%th=t("fields.code")
%th=t(:Type)
%th=t(:Options)
%th=t(:Delete)
%tbody
-@campos.each do |campo|
%tr
%td=a_editable(campo[:id], 'campo-order', "/review/edit_field/#{campo[:id]}/order", campo[:order])
%td=a_textarea_editable(campo[:id], 'campo-description', "/review/edit_field/#{campo[:id]}/description", campo[:description])
%td=a_editable(campo[:id], 'campo-name', "/review/edit_field/#{campo[:id]}/name", campo[:name])
%td=@xselect.html(campo[:id], campo[:type])
%td=a_textarea_editable(campo[:id], 'campo-options', "/review/edit_field/#{campo[:id]}/options", campo[:options])
%td
.btn-group.btn-group-sm
%a.btn.btn-danger{:href=>"/review/#{@review[:id]}/field/#{campo[:id]}/delete"}
%span.glyphicon.glyphicon-remove
=t(:Delete)

%a.btn.btn-primary{:href=>"/review/#{@review[:id]}/update_field_table"}=t("fields.update_fields_table")

Expand Down

0 comments on commit 90621e2

Please sign in to comment.