OSDN Git Service

add selenium test code.
[quickedit/quick_edit.git] / app / helpers / application_helper.rb
1 #coding: utf-8
2
3 module ApplicationHelper
4   def redmine_version()
5     Redmine::VERSION::MAJOR * 10 + Redmine::VERSION::MINOR
6   end
7
8   def editable(attribute_name, can, readonly_fields)
9     if readonly_fields.include?(attribute_name.to_s)
10       return false
11     end
12
13     if redmine_version() >= 30
14       return can[:edit]
15     else
16       return can[:update]
17     end
18   end
19
20   def editable_custom_field(custom_field, can, readonly_fields)
21     if readonly_fields.include?(custom_field.id.to_s)
22       return false
23     end
24
25     if redmine_version() >= 30
26       return can[:edit]
27     else
28       return can[:update]
29     end
30   end
31
32   def quick_edit_link_to(issue_ids, caption, attribute_name, additional_index, back_url, disabled)
33      target_specifier = build_target_specifier(attribute_name, additional_index)
34
35      ajax_url = quick_edit_issues_edit_path(:ids => issue_ids, :target_specifier => target_specifier, :back_url => back_url)
36
37      html_id = "quick_edit_context_#{attribute_name}"
38      html_id += "_#{additional_index}" unless additional_index.nil?
39
40      sprintf("<li id='#{html_id}'>%s</li>",
41         context_menu_link(
42            h(caption),
43            ajax_url,
44            :class => 'quick_edit icon-edit',
45            :disabled => disabled,
46            :remote => true
47         )
48      ).html_safe()
49   end   
50
51   def build_target_specifier(attribute_name, additional_index)
52     target = "issue[#{attribute_name}]"
53     target += "[#{additional_index}]" unless additional_index.nil?
54     target
55   end
56
57   def parse_target_specifier(target_specifier)
58     /^issue\[(.+?)\].*/ =~ target_specifier
59     if Regexp.last_match.nil?
60       return nil
61     end
62
63     attribute_name = Regexp.last_match(1)
64
65     /^issue\[.+?\]\[(\d+)\]$/ =~ target_specifier
66     if Regexp.last_match.nil?
67       additional_index = nil
68       result = [attribute_name]
69     else
70       additional_index = Regexp.last_match(1)
71       result = [attribute_name, additional_index]
72     end
73
74     result
75   end
76
77   def get_attribute_caption(attribute_name)
78      case attribute_name.to_sym
79      when :subject
80         l(:field_subject)
81      when :description
82         l(:field_description)
83      when :parent_issue_id
84         l(:field_parent_issue)
85      when :start_date
86         l(:field_start_date)
87      when :due_date
88         l(:field_due_date)
89      end
90   end
91
92
93   def get_attribute_type(attribute_name)
94      case attribute_name.to_sym
95      when :subject
96         :string
97      when :description
98         :text
99      when :parent_issue_id
100         :int
101      when :start_date
102         :date
103      when :due_date
104         :date
105      end
106   end
107
108   def parse_size(size, width_range, width_default, height_range, height_default)
109      size = size.split(",")
110      size[0] = width_default if size.length != 2 || !size[0].match(/\d{1,9}/)
111      size[1] = height_default if size.length != 2 || !size[1].match(/\d{1,9}/)
112      size[0] = size[0].to_i
113      size[1] = size[1].to_i
114      size[0] = width_default unless width_range.include?(size[0])
115      size[1] = height_default unless height_range.include?(size[1])
116
117      size
118   end
119 end
120