diff --git a/app/views/issues/_subtask_list_accordion_partial.html.erb b/app/views/issues/_subtask_list_accordion_partial.html.erb index d64a112..205cd6f 100644 --- a/app/views/issues/_subtask_list_accordion_partial.html.erb +++ b/app/views/issues/_subtask_list_accordion_partial.html.erb @@ -20,7 +20,7 @@ var _contextMenuShow = contextMenuShow; isHideMenuSla = false; contextMenuShow = function(event){ - if ($(event.target).parents("div[id='relations']").size() == 1 || !$("table.list > tbody > tr").is(".idnt-1")) + if ($(event.target).parents("div[id='relations']").length == 1 || !$("table.list > tbody > tr").is(".idnt-1")) { //hide this plugin menu isHideMenuSla = true; diff --git a/assets/javascripts/subtask_list_accordion.js b/assets/javascripts/subtask_list_accordion.js index 4a9a6d0..1d1d6d2 100644 --- a/assets/javascripts/subtask_list_accordion.js +++ b/assets/javascripts/subtask_list_accordion.js @@ -19,7 +19,7 @@ function childIssueShowOrHide(parentTR) function seletedTreeOpen() { var targetParents = slaTRs.filter("tr:has(td.checkbox > input:checked)"); - for (var i = 0; i < targetParents.size(); i++) + for (var i = 0; i < targetParents.length; i++) { var parentTR = targetParents.eq(i); if (!parentTR.hasClass("haschild")) @@ -39,7 +39,7 @@ function seletedTreeOpen() function seletedTreeClose() { var targetParents = slaTRs.filter("tr:has(td.checkbox > input:checked)"); - for (var i = 0; i < targetParents.size(); i++) + for (var i = 0; i < targetParents.length; i++) { var parentTR = targetParents.eq(i); if (!parentTR.hasClass("haschild")) @@ -59,7 +59,7 @@ function seletedTreeClose() function allExpandNext() { var parentTR = slaTRs.filter("tr:has(td.checkbox > input:checked)"); - if (parentTR.size() != 1) + if (parentTR.length != 1) { exit; } @@ -92,7 +92,7 @@ $(document).ready(function() slaTRs.show().filter(".haschild").removeClass("collapse").addClass("expand"); //for debug - if (slaTRs.filter("tr:visible").size() != slaTRs.size()) alert("NG"); + if (slaTRs.filter("tr:visible").length != slaTRs.length) alert("NG"); return false; }); diff --git a/assets/javascripts/subtask_list_accordion_client.js b/assets/javascripts/subtask_list_accordion_client.js index 7a46600..a015a72 100644 --- a/assets/javascripts/subtask_list_accordion_client.js +++ b/assets/javascripts/subtask_list_accordion_client.js @@ -19,7 +19,7 @@ function getParentIssue(startPos, rank, sameTreeOnly) var selectorC = nextAttr + ":first"; var pp = $(issuesSelector + selectorP + " + " + selectorC); - if (pp.size() != 1) + if (pp.length != 1) { //no parent return $(); @@ -99,7 +99,7 @@ function childIssueShowOrHide(parentTR) function setAccordion(parentPos, rank, isHiding, sameTreeOnly) { var parentTR = getParentIssue(parentPos, rank, sameTreeOnly); - if (parentTR.size() != 1) + if (parentTR.length != 1) { return false; } @@ -145,7 +145,7 @@ function setAccordion(parentPos, rank, isHiding, sameTreeOnly) function seletedTreeOpen() { var targetParents = slaTRs.filter("tr:has(td.checkbox > input:checked)"); - for (var i = 0; i < targetParents.size(); i++) + for (var i = 0; i < targetParents.length; i++) { var parentTR = targetParents.eq(i); if (!parentTR.hasClass("haschild")) @@ -178,7 +178,7 @@ function seletedTreeOpen() function seletedTreeClose() { var targetParents = slaTRs.filter("tr:has(td.checkbox > input:checked)"); - for (var i = 0; i < targetParents.size(); i++) + for (var i = 0; i < targetParents.length; i++) { var parentTR = targetParents.eq(i); if (!parentTR.hasClass("haschild")) @@ -198,7 +198,7 @@ function seletedTreeClose() function allExpandNext() { var parentTR = slaTRs.filter("tr:has(td.checkbox > input:checked)"); - if (parentTR.size() != 1) + if (parentTR.length != 1) { exit; } @@ -236,7 +236,7 @@ $(document).ready(function() var expandTreeAtFirst = window.subtaskListAccordionExpandTreeAtFirst; //make rank first time slaTRs = $("table.list > tbody > tr"); - slaTRsSize = slaTRs.size(); + slaTRsSize = slaTRs.length; var analyzeTo = expandTreeAtFirst ? 10 : 1; var isHiding = !expandTreeAtFirst; var isSameTreeOnly = isHiding; @@ -268,7 +268,7 @@ $(document).ready(function() slaTRs.show().filter(".haschild").removeClass("collapse").addClass("expand"); //for debug - if (slaTRs.filter("tr:visible").size() != slaTRsSize) + if (slaTRs.filter("tr:visible").length != slaTRsSize) { alert("NG"); } diff --git a/init.rb b/init.rb index 1efc84e..a701c2c 100644 --- a/init.rb +++ b/init.rb @@ -1,6 +1,6 @@ -require_dependency 'redmine_subtask_list_accordion/hooks/subtask_list_accordion_hook' -require_dependency 'redmine_subtask_list_accordion/patches/issues_helper_patch' -require_dependency 'redmine_subtask_list_accordion/patches/user_preference_patch' +require_dependency File.expand_path('../lib/redmine_subtask_list_accordion/hooks/subtask_list_accordion_hook', __FILE__) +require_dependency File.expand_path('../lib/redmine_subtask_list_accordion/patches/issues_helper_patch', __FILE__) +require_dependency File.expand_path('../lib/redmine_subtask_list_accordion/patches/user_preference_patch', __FILE__) reloader = defined?(ActiveSupport::Reloader) ? ActiveSupport::Reloader : ActionDispatch::Reloader reloader.to_prepare do diff --git a/lib/redmine_subtask_list_accordion/hooks/subtask_list_accordion_hook.rb b/lib/redmine_subtask_list_accordion/hooks/subtask_list_accordion_hook.rb index 5ba8353..3a31167 100644 --- a/lib/redmine_subtask_list_accordion/hooks/subtask_list_accordion_hook.rb +++ b/lib/redmine_subtask_list_accordion/hooks/subtask_list_accordion_hook.rb @@ -1,18 +1,22 @@ -class SubtaskListAccordionHook < Redmine::Hook::ViewListener - render_on :view_issues_show_description_bottom, :partial => 'issues/subtask_list_accordion_partial' - render_on :view_my_account_preferences, :partial => 'my/subtask_list_accordion_preferences' - - def view_issues_context_menu_start(context={}) - if isIssuePage?(context[:back]) - context[:controller].send(:render_to_string, { - :partial => "context_menus/accordion_menu", - :locals => context - }) +module RedmineSubtaskListAccordion + module Hooks + class SubtaskListAccordionHook < Redmine::Hook::ViewListener + render_on :view_issues_show_description_bottom, :partial => 'issues/subtask_list_accordion_partial' + render_on :view_my_account_preferences, :partial => 'my/subtask_list_accordion_preferences' + + def view_issues_context_menu_start(context={}) + if isIssuePage?(context[:back]) + context[:controller].send(:render_to_string, { + :partial => "context_menus/accordion_menu", + :locals => context + }) + end + end + + private + def isIssuePage?(path) + path =~ Regexp.new("issues/+[0-9]") + end end end - - private - def isIssuePage?(path) - path =~ Regexp.new("issues/+[0-9]") - end end diff --git a/lib/redmine_subtask_list_accordion/patches/issues_helper_patch.rb b/lib/redmine_subtask_list_accordion/patches/issues_helper_patch.rb index 77fd9b8..82a0f06 100644 --- a/lib/redmine_subtask_list_accordion/patches/issues_helper_patch.rb +++ b/lib/redmine_subtask_list_accordion/patches/issues_helper_patch.rb @@ -1,4 +1,4 @@ -require_dependency("issues_helper") +require_dependency 'issues_helper' module RedmineSubtaskListAccordion module Patches @@ -108,3 +108,5 @@ def sla_use_css end end end + +IssuesController.send :helper, RedmineSubtaskListAccordion::Patches::IssuesHelperPatch diff --git a/lib/redmine_subtask_list_accordion/patches/user_preference_patch.rb b/lib/redmine_subtask_list_accordion/patches/user_preference_patch.rb index 3df7e0b..249de7c 100644 --- a/lib/redmine_subtask_list_accordion/patches/user_preference_patch.rb +++ b/lib/redmine_subtask_list_accordion/patches/user_preference_patch.rb @@ -5,16 +5,22 @@ module Patches module UserPreferencePatch def self.prepended(base) + base.send(:include, InstanceMethods) base.class_eval do if defined? safe_attributes safe_attributes :subtasks_default_expand_limit_upper end end end - - def subtasks_default_expand_limit_upper; (self[:subtasks_default_expand_limit_upper] || 0).to_i; end - def subtasks_default_expand_limit_upper=(val); self[:subtasks_default_expand_limit_upper] = val; end - + + module InstanceMethods + def subtasks_default_expand_limit_upper; (self[:subtasks_default_expand_limit_upper] || 0).to_i; end + def subtasks_default_expand_limit_upper=(val); self[:subtasks_default_expand_limit_upper] = val; end + end end end end + +base = UserPreference +patch = RedmineSubtaskListAccordion::Patches::UserPreferencePatch +base.send(:prepend, patch) unless base.included_modules.include?(patch)