Merge pull request #854 from opf/feature/unified_none_type

pull/872/head
Hagen Schink 11 years ago
commit 4c013e472a
  1. 143
      app/assets/javascripts/types_checkboxes.js
  2. 15
      app/helpers/application_helper.rb
  3. 2
      app/models/project.rb
  4. 4
      app/models/type.rb
  5. 3
      app/views/projects/_form.html.erb
  6. 99
      app/views/projects/form/_types.html.erb
  7. 1
      app/views/projects/settings/_types.html.erb

@ -0,0 +1,143 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
(function($) {
var TypesCheckboxes = function () {
this.init();
};
TypesCheckboxes.prototype = $.extend(TypesCheckboxes.prototype, {
init: function () {
this.append_checkbox_listeners();
this.append_check_uncheck_all_listeners();
if (this.everything_unchecked()) {
this.check_and_disable_standard_type();
}
},
append_checkbox_listeners: function () {
var self = this;
this.all_checkboxes().on("change", function () {
if (self.everything_unchecked()) {
self.check_and_disable_standard_type();
self.display_explanation();
} else {
self.hide_explanation();
self.enable_standard_type();
}
});
},
append_check_uncheck_all_listeners: function () {
var self = this;
$("#project_types #check_all_types").click(function (event) {
self.enable_all_checkboxes();
self.check(self.all_checkboxes());
self.hide_explanation();
event.preventDefault();
});
$("#project_types #uncheck_all_types").click(function (event) {
self.enable_all_checkboxes();
self.uncheck(self.all_except_standard());
self.check_and_disable_standard_type();
self.display_explanation();
event.preventDefault();
});
},
everything_unchecked: function () {
return !(this.all_except_standard().filter(":checked").length > 0);
},
check_and_disable_standard_type: function () {
var standard = this.standard_check_boxes();
this.check($(standard));
this.disable($(standard));
},
enable_standard_type: function () {
this.enable(this.standard_check_boxes());
},
enable_all_checkboxes: function () {
this.enable(this.all_checkboxes())
},
check: function (boxes) {
$(boxes).prop("checked", true);
},
uncheck: function (boxes) {
$(boxes).prop("checked", false);
},
disable: function (boxes) {
var self = this;
$(boxes).prop('disabled', true);
$(boxes).each(function (ix, item) {
self.hidden_type_field($(item)).prop("value", $(item).prop("value"));
});
},
enable: function (boxes) {
var self = this;
$(boxes).prop('disabled', false);
$(boxes).each(function (ix, item) {
self.hidden_type_field($(item)).prop("value", "");
});
},
display_explanation: function () {
$("#types_flash_notice").show();
},
hide_explanation: function () {
$("#types_flash_notice").hide();
},
all_checkboxes: function () {
return $(".types :input[type='checkbox']");
},
all_except_standard: function () {
return $(".types :input[type='checkbox'][data-standard='false']");
},
standard_check_boxes: function () {
return $(".types :input[type='checkbox'][data-standard='true']");
},
hidden_type_field: function (for_box) {
return $(".types :input[type='hidden'][data-for='" + $(for_box).prop("id") + "']");
}
});
$('document').ready(function () {
new TypesCheckboxes();
});
})(jQuery);

@ -269,11 +269,7 @@ module ApplicationHelper
# Renders flash messages
def render_flash_messages
if User.current.impaired?
flash.map { |k,v| content_tag('div', content_tag('a', join_flash_messages(v), :href => 'javascript:;'), :class => "flash #{k} icon icon-#{k}") }.join.html_safe
else
flash.map { |k,v| content_tag('div', join_flash_messages(v), :class => "flash #{k} icon icon-#{k}") }.join.html_safe
end
flash.map { |k,v| render_flash_message(k, v) }.join.html_safe
end
def join_flash_messages(messages)
@ -284,6 +280,15 @@ module ApplicationHelper
end
end
def render_flash_message(type, message, html_options = {})
html_options = {:class => "flash #{type} icon icon-#{type}"}.merge(html_options)
if User.current.impaired?
content_tag('div', content_tag('a', join_flash_messages(message), :href => 'javascript:;'), html_options)
else
content_tag('div', join_flash_messages(message), html_options)
end
end
# Renders tabs and their content
def render_tabs(tabs)
if tabs.any?

@ -239,7 +239,7 @@ class Project < ActiveRecord::Base
self.enabled_module_names = Setting.default_projects_modules
end
if !initialized.key?('types') && !initialized.key?('type_ids')
self.types = Type.where(is_default: true)
self.types = Type.default
end
end

@ -89,6 +89,10 @@ class Type < ActiveRecord::Base
Type.where(is_standard: true).first
end
def self.default
Type.where(is_default: true)
end
def statuses
return [] if new_record?
@statuses ||= Type.statuses([id])

@ -46,10 +46,7 @@ See doc/COPYRIGHT.rdoc for more details.
<% if (project.new_record? || project.module_enabled?('issue_tracking')) %>
<% if renderTypes %>
<fieldset class="box" id="project_types"><legend><%=l(:label_type_plural)%> <span style="font-size:0.9em">(<%= check_all_links 'project_types' %>)</span></legend>
<%= render :partial => 'projects/form/types', :locals => { :f => f, :project => project } %>
<%= hidden_field_tag 'project[type_ids][]', '' %>
</fieldset>
<% end %>
<% end %>

@ -27,45 +27,64 @@ See doc/COPYRIGHT.rdoc for more details.
++#%>
<table class='list'>
<thead>
<tr>
<th width="90px" class='center'><%= Type.human_attribute_name(:active) %></th>
<th><%= Type.human_attribute_name(:name) %></th>
<th class='center'><%= Type.human_attribute_name(:in_aggregation) %></th>
<th class='center'><%= Type.human_attribute_name(:is_in_roadmap) %></th>
<th class='center'><%= Type.human_attribute_name(:is_milestone) %></th>
</tr>
</thead>
<%= javascript_include_tag 'types_checkboxes' %>
<tbody>
<% Type.all.each do |type| %>
<tr class="<%= cycle('odd', 'even', :name => "pet_table") %>">
<td class='center'>
<%= check_box_tag "project[type_ids][]",
type.id,
project.types.include?(type),
:id => "project_planning_element_type_ids_#{type.id}" %>
<label class='hidden-for-sighted' for="project_planning_element_type_ids_<%= type.id %>">
<%= l('timelines.enable_type_in_project', :type => type.name) %>
</label>
</td>
<td>
<label for="project_planning_element_type_ids_<%= type.id %>">
<%= icon_for_type(type) %>
<%=h type.name %>
</label>
</td>
<td class='center'>
<%= checked_image(type.in_aggregation) %>
</td>
<td class='center'>
<%= checked_image(type.is_in_roadmap) %>
</td>
<td class='center'>
<%= checked_image(type.is_milestone) %>
</td>
<%= render_flash_message :notice,
l(:notice_automatic_set_of_standard_type),
style: "display:none;", id: "types_flash_notice" %>
<fieldset class="box" id="project_types">
<legend><%=l(:label_type_plural)%>
<span style="font-size:0.9em">
(<%= link_to(l(:button_check_all), "#", id: "check_all_types") +
' | ' +
link_to(l(:button_uncheck_all), "#", id: "uncheck_all_types")
%>)
</span>
</legend>
<table class='list types'>
<thead>
<tr>
<th width="90px" class='center'><%= Type.human_attribute_name(:active) %></th>
<th><%= Type.human_attribute_name(:name) %></th>
<th class='center'><%= Type.human_attribute_name(:in_aggregation) %></th>
<th class='center'><%= Type.human_attribute_name(:is_in_roadmap) %></th>
<th class='center'><%= Type.human_attribute_name(:is_milestone) %></th>
</tr>
<% end %>
</tbody>
</table>
</thead>
<tbody>
<% Type.all.each do |type| %>
<tr class="<%= cycle('odd', 'even', :name => "pet_table") %>">
<td class='center'>
<% type_id = "project_planning_element_type_ids_#{type.id}" %>
<%= check_box_tag "project[type_ids][]",
type.id,
project.types.include?(type),
:id => type_id,
:'data-standard' => type.is_standard %>
<%= hidden_field_tag 'project[type_ids][]', '', :'data-for' => type_id %>
<label class='hidden-for-sighted' for=<%= type_id %>>
<%= l('timelines.enable_type_in_project', :type => type.name) %>
</label>
</td>
<td>
<label for="project_planning_element_type_ids_<%= type.id %>">
<%= icon_for_type(type) %>
<%=h type.name %>
</label>
</td>
<td class='center'>
<%= checked_image(type.in_aggregation) %>
</td>
<td class='center'>
<%= checked_image(type.is_in_roadmap) %>
</td>
<td class='center'>
<%= checked_image(type.is_milestone) %>
</td>
</tr>
<% end %>
</tbody>
</table>
</fieldset>

@ -34,7 +34,6 @@ See doc/COPYRIGHT.rdoc for more details.
:url => { :action => 'types', :id => @project },
:method => :put,
:html => {:id => 'types-form'} do |f| %>
<%=l(:label_type_plural)%> <span style="font-size:0.9em">(<%= check_all_links 'project_types' %>)</span>
<%= render :partial => 'projects/form/types', :locals => { :f => f, :project => @project } %>
<p><%= submit_tag l(:button_save) %></p>

Loading…
Cancel
Save