Skip to content

Commit

Permalink
new version 1.3 - see CHANGELOG for details
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasklein committed Oct 18, 2010
1 parent cc4f7b3 commit 2b3128a
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 39 deletions.
74 changes: 65 additions & 9 deletions redmine2mite/app/helpers/mite_helper.rb
@@ -1,7 +1,58 @@
module MiteHelper

# Select helper for displaying unbinded and binded mite resources in a select box
# TODO: improve readability of code
#******************************
# Return a div container containing
# - possible option to deactivate attaching mite resources
# to a time entry (depending on the users preferences)
# - select box to a mite project
# - select box to a mite service
#
def self.mite_rsrcs_assignment_container(project_id, display_initially = true)

display = ""
display = style='display:none' if display_initially
new_fields = "<div id='mite_resources_wrapper' #{display}>"

# provide an option to hide the mite resource assignments
# if set in the users preferences
if User.current.preference.mite_omit_transmission_option

onclickAction = '
if ($("mite_resources").getStyle("display")=="block") {
$("mite_resources").setStyle({display:"none"});
$("time_entry_mite_project_id").setAttribute("name","");
$("time_entry_mite_service_id").setAttribute("name","");
}
else {
$("mite_resources").setStyle({display:"block"});
$("time_entry_mite_project_id").setAttribute("name","time_entry[mite_project_id]");
$("time_entry_mite_service_id").setAttribute("name","time_entry[mite_service_id]");
}';

new_fields +=
"<p><label for='time_entry_option_send_te_to_mite'>#{I18n.translate(:label_option_send_te_to_mite)}</label>" +
"<input type='checkbox' id='option_send_te_to_mite' value='1' checked='checked' onclick='#{onclickAction}' /></p>"
end

new_fields += "<div id='mite_resources'>"

# select box for mite.projects
new_fields += "<p><label for='time_entry_mite_project_id'>#{I18n.translate(:label_mite_project)}</label>" + self::select_binded_mite_rsrcs(:time_entry, :mite_project_id, MiteProject, project_id, :include_blank => I18n.translate(:none1_option_select_box), :has_at_most_one_binding => true) + "</p>"

# select box for mite.services
new_fields += "<p><label for='time_entry_mite_service_id'>#{I18n.translate(:label_mite_service)}</label>" + self::select_binded_mite_rsrcs(:time_entry, :mite_service_id, MiteService, project_id, :include_blank => I18n.translate(:none2_option_select_box), :optgroup_separator => I18n.translate(:label_option_group_other_services)) + "</p>"

new_fields += "</div><!-- mite_resources -->"
new_fields += "</div><!-- mite_resources_wrapper -->"

new_fields
end #mite_rsrcs_assignment_container


#******************************
# Select helper for displaying unbinded and binded mite resources in a select box
# TODO: improve readability of code
#
def self.select_binded_mite_rsrcs(namespace,field_name,rsrc_klass,project_id, options = {})

collection = {}
Expand Down Expand Up @@ -49,11 +100,14 @@ def self.select_binded_mite_rsrcs(namespace,field_name,rsrc_klass,project_id, op
end

"<select id='#{namespace}_#{field_name}' name='#{namespace}[#{field_name}]'>#{options_html}</select>"
end
end #select_binded_mite_rsrcs


# fills the global container for a flash message
# with a specific message for actions regarding
# the connections of the user accounts
#******************************
# fills the global container for a flash message
# with a specific message for actions regarding
# the connections of the user accounts
#
def fill_flash_msg(predefined_msg, msg_type, exception = "")

msg = ''
Expand Down Expand Up @@ -83,10 +137,12 @@ def fill_flash_msg(predefined_msg, msg_type, exception = "")
msg = predefined_msg if predefined_msg

flash[msg_type] = msg
end
end #fill_flash_msg


# Just another select helper
#******************************
# Just another select helper
#
def simple_select_with_label(label, name, entries, selected_entries, options = {}, html_options = {})

options_html = ''
Expand All @@ -101,6 +157,6 @@ def simple_select_with_label(label, name, entries, selected_entries, options = {

# return
"<label>#{label}</label><select name='#{name}' #{tag_options}>#{options_html}</select>"
end
end #simple_select_with_label

end
18 changes: 18 additions & 0 deletions redmine2mite/assets/javascripts/mite_edit_issue.js
@@ -0,0 +1,18 @@
document.observe("dom:loaded", function() {

// get the second fieldset with the class 'tabular'
// which contains the fields to append an time entry to the change
var o_fsBookEffort = $$('fieldset.tabular')[1];

// if it is does not exist, the user is most probably
// not allowed to create a time entry
if (o_fsBookEffort != null) {

// if it does exist, append the mite fields created in
// IssueDetailsLayoutHook.view_issues_form_details_bottom
// to the fieldset

$(o_fsBookEffort).insert($('mite_resources_wrapper'), content);
$('mite_resources_wrapper').setStyle({display: 'block'});
}
});
1 change: 1 addition & 0 deletions redmine2mite/init.rb
Expand Up @@ -6,6 +6,7 @@

# hooks
require_dependency 'time_log_entry_layout_hook.rb'
require_dependency 'issue_details_layout_hook.rb'

# extend the Redmine core
Dispatcher.to_prepare do
Expand Down
13 changes: 13 additions & 0 deletions redmine2mite/lib/issue_details_layout_hook.rb
@@ -0,0 +1,13 @@
class IssueDetailsLayoutHook < Redmine::Hook::ViewListener

#******************************
# Desc missing...
#
def view_issues_form_details_bottom(context = {})

issue = context[:issue]
new_fields = MiteHelper::mite_rsrcs_assignment_container(issue.project_id, false)
new_fields += javascript_include_tag('mite_edit_issue', :plugin => 'redmine2mite', :cache => false)
new_fields
end
end
31 changes: 1 addition & 30 deletions redmine2mite/lib/time_log_entry_layout_hook.rb
Expand Up @@ -14,36 +14,7 @@ def view_timelog_edit_form_bottom(context = {})

te = context[:time_entry]

new_fields = ""

if User.current.preference.mite_omit_transmission_option

onclickAction = '
if ($("mite_resources").getStyle("display")=="block") {
$("mite_resources").setStyle({display:"none"});
$("time_entry_mite_project_id").setAttribute("name","");
$("time_entry_mite_service_id").setAttribute("name","");
}
else {
$("mite_resources").setStyle({display:"block"});
$("time_entry_mite_project_id").setAttribute("name","time_entry[mite_project_id]");
$("time_entry_mite_service_id").setAttribute("name","time_entry[mite_service_id]");
}';

new_fields =
"<br /><p><label for='time_entry_option_send_te_to_mite'>#{l(:label_option_send_te_to_mite)}</label>" +
"<input type='checkbox' id='option_send_te_to_mite' value='1' checked='checked' onclick='#{onclickAction}' /></p>"
end

new_fields += "<div id='mite_resources'>"

# select box for mite.projects
new_fields += "<p><label for='time_entry_mite_project_id'>#{l(:label_mite_project)}</label>" + MiteHelper::select_binded_mite_rsrcs(:time_entry, :mite_project_id, MiteProject, te.project_id, :include_blank => l(:none1_option_select_box), :has_at_most_one_binding => true) + "</p>"

# select box for mite.services
new_fields += "<p><label for='time_entry_mite_service_id'>#{l(:label_mite_service)}</label>" + MiteHelper::select_binded_mite_rsrcs(:time_entry, :mite_service_id, MiteService, te.project_id, :include_blank => l(:none2_option_select_box), :optgroup_separator => l(:label_option_group_other_services)) + "</p>"

new_fields += "</div><!-- mite_resources -->"
new_fields = MiteHelper::mite_rsrcs_assignment_container(te.project_id)

new_fields
end
Expand Down

0 comments on commit 2b3128a

Please sign in to comment.