app/views/views_widgets/_form.html.erb
<div class="tabs">
<!--<ul>-->
<!--<li><a href="#tabs-1"><%#= I18n.t(:views_widgets) %> </a></li>-->
<!--</ul>-->
<div id="tabs-1">
<%= simple_form_for(@views_widget, :remote => true) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :view_id, as: :hidden, :input_html => { value: @view_id } %>
<%= f.input :position_x, as: :hidden, :input_html => { value: @position_x } %>
<%= f.input :position_y, as: :hidden, :input_html => { value: @position_y } %>
<%= hidden_field_tag 'current_module_project_id', @module_project.id %>
<table>
<!--<tr><td><%#= f.association :widget, label: I18n.t(:label_widget) %></td></tr>-->
<tr>
<td><%= f.input :name, label: I18n.t(:name) %></td>
</tr>
<tr>
<td>
<!--<label class="checkbox"></label>-->
<%= f.input :show_name, label: I18n.t(:show_name) %>
</td>
<td><%= f.input :is_label_widget, label: "S'agit-il d'une vignette de titre ?", disabled: !@views_widget.new_record? %></td>
</tr>
<tr>
<td><%= f.association :pbs_project_element, label: I18n.t(:associate_pbs_element), collection: @project_pbs_project_elements, selected: @pbs_project_element_id, include_blank: false, input_html:{class: "inline_attr"} %></td>
<td><%= f.association :module_project, label: "Modules", collection: @project.module_projects.map{|i| [i, i.id]}, selected: @module_project.id, include_blank: false, input_html:{class: "inline_attr"} %></td>
</tr>
<tr>
<td><%= f.input :widget_type, collection: @views_widget_types, as: :grouped_select, group_method: :last, :group_label_method => :first, include_blank: false, input_html:{class: "inline_attr"} %></td>
<td><%= f.input :estimation_value_id, collection: @module_project_attributes, as: :grouped_select, group_method: :last, group_label_method: :first, label: I18n.t(:associated_attribute), input_html:{class: "inline_attr"}, include_blank: false %></td>
<!--<td><%#= select_tag 'views_widget[estimation_value_id]', grouped_options_for_select({I18n.t(:inputs) => @module_project_attributes_input, I18n.t(:outputs) => @module_project_attributes_output}, :selected => @views_widget.estimation_value_id), :prompt => false %></td>-->
</tr>
<tr>
<td>
<% if @views_widget.new_record? %>
<%= f.input :color, label: I18n.t(:status_color), input_html: {class: "basic", type: 'color', value: '#99ccff'} %>
<% else %>
<%= f.input :color, label: I18n.t(:status_color), input_html: {class: "basic", type: 'color'} %>
<% end %>
</td>
<td><%= f.input :icon_class, as: :select, collection: Projestimate::Application::ICON_CLASSES.sort() , label: I18n.t(:icon) %></td>
<td><div id="view_icon_class_image"></div></td>
</tr>
<tr>
<td>
<label class="checkbox"></label>
<%= f.input :show_min_max, as: :boolean, label: I18n.t(:show_min_max), input_html: {class: 'inline_attr'} %>
<% if @module_project.wbs_activity %>
<%= f.input :show_wbs_activity_ratio, as: :boolean, label: I18n.t(:show_wbs_activity_ratio) %>
<% end %>
</td>
<td>
<label><%= I18n.t :fields %></label>
<% selected = @views_widget.project_fields.first %>
<%= select_tag "field", options_for_select(@project.organization.fields.map{|i| [i.name, i.id] }, selected: selected.nil? ? '' : selected.field.id), prompt: "None", disabled: (!(@views_widget.widget_type == "text") || @views_widget.is_label_widget?) %>
</td>
</tr>
<!--<tr>-->
<!--<td><%#= I18n.t(:widget_size) %></td>-->
<!--<td>-->
<!--<div class="row-fluid" style="display: block">-->
<!--<div class="span6 height_width"><%#= f.input :width, as: :select, collection: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], label: I18n.t(:width), include_blank:false, input_html: {class: 'input-small'} %></div>-->
<!--<div class="span6 height_width"><%#= f.input :height, as: :select, collection: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], label: I18n.t(:height), include_blank:false, input_html: {class: 'input-small'} %></div>-->
<!--</div>-->
<!--</td>-->
<!--</tr>-->
</table>
</div>
<div class="actions">
<% if can?(:alter_estimation_plan, @project) || ( can?(:manage_estimation_widgets, @project) && @views_widget.project_fields.empty? ) %>
<%= submit_tag I18n.t('save'), :class => 'btn' %>
<% end %>
<button class="btn" data-dismiss="modal" aria-hidden="true"><%= I18n.t(:close) %></button>
</div>
<% end %>
</div>
</div>
<script>
// Update the view_widget show_min_max attribute according to the selected widget_type
var delete_min_max_on_widget_type = [ "line_chart", "bar_chart", "area_chart", "pie_chart", "timeline", "stacked_bar_chart", "histogram_effort_per_phase", "pie_chart_effort_per_phase", "histogram_cost_per_phase",
"pie_chart_cost_per_phase", "stacked_bar_chart_effort_per_phases_profiles", "stacked_bar_chart_cost_per_phases_profiles"]
var widget_type = $("#views_widget_widget_type").val();
if (widget_type !== ""){
if (jQuery.inArray( widget_type, delete_min_max_on_widget_type) !== -1){
$('#views_widget_show_min_max').attr('disabled','disabled');
$("#views_widget_widget_type").value = 0;
}
else{
$('#views_widget_show_min_max').removeAttr('disabled');
}
}
// Update the view_widget attribute according to the selected module
$("#views_widget_module_project_id").change(function() {
if ($(this).val() !== ""){
return $.ajax({
url: "/update_widget_module_project_data",
method: "GET",
data: "module_project_id=" + $(this).val()
});
}
});
$("#views_widget_widget_type").change(function() {
var widget_type = $(this).val();
if (widget_type !== ""){
if (jQuery.inArray( widget_type, delete_min_max_on_widget_type) !== -1){
$('#views_widget_show_min_max').attr('disabled','disabled');
$("#views_widget_widget_type").value = 0;
} else{
$('#views_widget_show_min_max').removeAttr('disabled');
}
}
});
//manage the label widget
$("#views_widget_is_label_widget").change(function(){
if($(this).is(':checked')){
//alert(1);
//$("#new_views_widget").closest("tr").find(":input.inline_attr").attr("disabled", 'disabled');
$("form#new_views_widget select.inline_attr, input:checkbox.inline_attr ").attr("disabled", 'disabled');
} else{
//alert(0);
$("form#new_views_widget select.inline_attr, input:checkbox.inline_attr ").removeAttr('disabled');
}
});
</script>