##// END OF EJS Templates
Added i18n support to the jstoolbar (only english and french are actually translated)....
Jean-Philippe Lang -
r1060:32b9bf0ef265
parent child
Show More
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Gras';
3 jsToolBar.strings['Italic'] = 'Italique';
4 jsToolBar.strings['Underline'] = 'SoulignΓ©';
5 jsToolBar.strings['Deleted'] = 'RayΓ©';
6 jsToolBar.strings['Inline quote'] = 'Citation';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Titre niveau 1';
9 jsToolBar.strings['Heading 2'] = 'Titre niveau 2';
10 jsToolBar.strings['Heading 3'] = 'Titre niveau 3';
11 jsToolBar.strings['Unordered list'] = 'Liste Γ  puces';
12 jsToolBar.strings['Ordered list'] = 'Liste numΓ©rotΓ©e';
13 jsToolBar.strings['Preformatted text'] = 'Texte prΓ©formatΓ©';
14 jsToolBar.strings['Wiki link'] = 'Lien vers une page Wiki';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -0,0 +1,15
1 jsToolBar.strings = {};
2 jsToolBar.strings['Strong'] = 'Strong';
3 jsToolBar.strings['Italic'] = 'Italic';
4 jsToolBar.strings['Underline'] = 'Underline';
5 jsToolBar.strings['Deleted'] = 'Deleted';
6 jsToolBar.strings['Inline quote'] = 'Inline quote';
7 jsToolBar.strings['Code'] = 'Code';
8 jsToolBar.strings['Heading 1'] = 'Heading 1';
9 jsToolBar.strings['Heading 2'] = 'Heading 2';
10 jsToolBar.strings['Heading 3'] = 'Heading 3';
11 jsToolBar.strings['Unordered list'] = 'Unordered list';
12 jsToolBar.strings['Ordered list'] = 'Ordered list';
13 jsToolBar.strings['Preformatted text'] = 'Preformatted text';
14 jsToolBar.strings['Wiki link'] = 'Link to a Wiki page';
15 jsToolBar.strings['Image'] = 'Image';
@@ -1,448 +1,450
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module ApplicationHelper
18 module ApplicationHelper
19 include Redmine::WikiFormatting::Macros::Definitions
19 include Redmine::WikiFormatting::Macros::Definitions
20
20
21 def current_role
21 def current_role
22 @current_role ||= User.current.role_for_project(@project)
22 @current_role ||= User.current.role_for_project(@project)
23 end
23 end
24
24
25 # Return true if user is authorized for controller/action, otherwise false
25 # Return true if user is authorized for controller/action, otherwise false
26 def authorize_for(controller, action)
26 def authorize_for(controller, action)
27 User.current.allowed_to?({:controller => controller, :action => action}, @project)
27 User.current.allowed_to?({:controller => controller, :action => action}, @project)
28 end
28 end
29
29
30 # Display a link if user is authorized
30 # Display a link if user is authorized
31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
33 end
33 end
34
34
35 def link_to_signin
35 def link_to_signin
36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
37 end
37 end
38
38
39 def link_to_signout
39 def link_to_signout
40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
41 end
41 end
42
42
43 # Display a link to user's account page
43 # Display a link to user's account page
44 def link_to_user(user)
44 def link_to_user(user)
45 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
45 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
46 end
46 end
47
47
48 def link_to_issue(issue)
48 def link_to_issue(issue)
49 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
49 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
50 end
50 end
51
51
52 def toggle_link(name, id, options={})
52 def toggle_link(name, id, options={})
53 onclick = "Element.toggle('#{id}'); "
53 onclick = "Element.toggle('#{id}'); "
54 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
54 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
55 onclick << "return false;"
55 onclick << "return false;"
56 link_to(name, "#", :onclick => onclick)
56 link_to(name, "#", :onclick => onclick)
57 end
57 end
58
58
59 def show_and_goto_link(name, id, options={})
59 def show_and_goto_link(name, id, options={})
60 onclick = "Element.show('#{id}'); "
60 onclick = "Element.show('#{id}'); "
61 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
61 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
62 onclick << "location.href='##{id}-anchor'; "
62 onclick << "location.href='##{id}-anchor'; "
63 onclick << "return false;"
63 onclick << "return false;"
64 link_to(name, "#", options.merge(:onclick => onclick))
64 link_to(name, "#", options.merge(:onclick => onclick))
65 end
65 end
66
66
67 def image_to_function(name, function, html_options = {})
67 def image_to_function(name, function, html_options = {})
68 html_options.symbolize_keys!
68 html_options.symbolize_keys!
69 tag(:input, html_options.merge({
69 tag(:input, html_options.merge({
70 :type => "image", :src => image_path(name),
70 :type => "image", :src => image_path(name),
71 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
71 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
72 }))
72 }))
73 end
73 end
74
74
75 def prompt_to_remote(name, text, param, url, html_options = {})
75 def prompt_to_remote(name, text, param, url, html_options = {})
76 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
76 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
77 link_to name, {}, html_options
77 link_to name, {}, html_options
78 end
78 end
79
79
80 def format_date(date)
80 def format_date(date)
81 return nil unless date
81 return nil unless date
82 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
82 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
83 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
83 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
84 date.strftime(@date_format)
84 date.strftime(@date_format)
85 end
85 end
86
86
87 def format_time(time, include_date = true)
87 def format_time(time, include_date = true)
88 return nil unless time
88 return nil unless time
89 time = time.to_time if time.is_a?(String)
89 time = time.to_time if time.is_a?(String)
90 zone = User.current.time_zone
90 zone = User.current.time_zone
91 if time.utc?
91 if time.utc?
92 local = zone ? zone.adjust(time) : time.getlocal
92 local = zone ? zone.adjust(time) : time.getlocal
93 else
93 else
94 local = zone ? zone.adjust(time.getutc) : time
94 local = zone ? zone.adjust(time.getutc) : time
95 end
95 end
96 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
96 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
97 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
97 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
98 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
98 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
99 end
99 end
100
100
101 def authoring(created, author)
101 def authoring(created, author)
102 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
102 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
103 l(:label_added_time_by, author || 'Anonymous', time_tag)
103 l(:label_added_time_by, author || 'Anonymous', time_tag)
104 end
104 end
105
105
106 def day_name(day)
106 def day_name(day)
107 l(:general_day_names).split(',')[day-1]
107 l(:general_day_names).split(',')[day-1]
108 end
108 end
109
109
110 def month_name(month)
110 def month_name(month)
111 l(:actionview_datehelper_select_month_names).split(',')[month-1]
111 l(:actionview_datehelper_select_month_names).split(',')[month-1]
112 end
112 end
113
113
114 def pagination_links_full(paginator, count=nil, options={})
114 def pagination_links_full(paginator, count=nil, options={})
115 page_param = options.delete(:page_param) || :page
115 page_param = options.delete(:page_param) || :page
116 url_param = params.dup
116 url_param = params.dup
117 # don't reuse params if filters are present
117 # don't reuse params if filters are present
118 url_param.clear if url_param.has_key?(:set_filter)
118 url_param.clear if url_param.has_key?(:set_filter)
119
119
120 html = ''
120 html = ''
121 html << link_to_remote(('&#171; ' + l(:label_previous)),
121 html << link_to_remote(('&#171; ' + l(:label_previous)),
122 {:update => "content", :url => url_param.merge(page_param => paginator.current.previous)},
122 {:update => "content", :url => url_param.merge(page_param => paginator.current.previous)},
123 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
123 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
124
124
125 html << (pagination_links_each(paginator, options) do |n|
125 html << (pagination_links_each(paginator, options) do |n|
126 link_to_remote(n.to_s,
126 link_to_remote(n.to_s,
127 {:url => {:params => url_param.merge(page_param => n)}, :update => 'content'},
127 {:url => {:params => url_param.merge(page_param => n)}, :update => 'content'},
128 {:href => url_for(:params => url_param.merge(page_param => n))})
128 {:href => url_for(:params => url_param.merge(page_param => n))})
129 end || '')
129 end || '')
130
130
131 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
131 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
132 {:update => "content", :url => url_param.merge(page_param => paginator.current.next)},
132 {:update => "content", :url => url_param.merge(page_param => paginator.current.next)},
133 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
133 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
134
134
135 unless count.nil?
135 unless count.nil?
136 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
136 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
137 end
137 end
138
138
139 html
139 html
140 end
140 end
141
141
142 def per_page_links(selected=nil)
142 def per_page_links(selected=nil)
143 url_param = params.dup
143 url_param = params.dup
144 url_param.clear if url_param.has_key?(:set_filter)
144 url_param.clear if url_param.has_key?(:set_filter)
145
145
146 links = Setting.per_page_options_array.collect do |n|
146 links = Setting.per_page_options_array.collect do |n|
147 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
147 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
148 {:href => url_for(url_param.merge(:per_page => n))})
148 {:href => url_for(url_param.merge(:per_page => n))})
149 end
149 end
150 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
150 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
151 end
151 end
152
152
153 def html_title(*args)
153 def html_title(*args)
154 if args.empty?
154 if args.empty?
155 title = []
155 title = []
156 title << @project.name if @project
156 title << @project.name if @project
157 title += @html_title if @html_title
157 title += @html_title if @html_title
158 title << Setting.app_title
158 title << Setting.app_title
159 title.compact.join(' - ')
159 title.compact.join(' - ')
160 else
160 else
161 @html_title ||= []
161 @html_title ||= []
162 @html_title += args
162 @html_title += args
163 end
163 end
164 end
164 end
165
165
166 ACCESSKEYS = {:edit => 'e',
166 ACCESSKEYS = {:edit => 'e',
167 :preview => 'r',
167 :preview => 'r',
168 :quick_search => 'f',
168 :quick_search => 'f',
169 :search => '4',
169 :search => '4',
170 }.freeze unless const_defined?(:ACCESSKEYS)
170 }.freeze unless const_defined?(:ACCESSKEYS)
171
171
172 def accesskey(s)
172 def accesskey(s)
173 ACCESSKEYS[s]
173 ACCESSKEYS[s]
174 end
174 end
175
175
176 # Formats text according to system settings.
176 # Formats text according to system settings.
177 # 2 ways to call this method:
177 # 2 ways to call this method:
178 # * with a String: textilizable(text, options)
178 # * with a String: textilizable(text, options)
179 # * with an object and one of its attribute: textilizable(issue, :description, options)
179 # * with an object and one of its attribute: textilizable(issue, :description, options)
180 def textilizable(*args)
180 def textilizable(*args)
181 options = args.last.is_a?(Hash) ? args.pop : {}
181 options = args.last.is_a?(Hash) ? args.pop : {}
182 case args.size
182 case args.size
183 when 1
183 when 1
184 obj = nil
184 obj = nil
185 text = args.shift || ''
185 text = args.shift || ''
186 when 2
186 when 2
187 obj = args.shift
187 obj = args.shift
188 text = obj.send(args.shift)
188 text = obj.send(args.shift)
189 else
189 else
190 raise ArgumentError, 'invalid arguments to textilizable'
190 raise ArgumentError, 'invalid arguments to textilizable'
191 end
191 end
192
192
193 # when using an image link, try to use an attachment, if possible
193 # when using an image link, try to use an attachment, if possible
194 attachments = options[:attachments]
194 attachments = options[:attachments]
195 if attachments
195 if attachments
196 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
196 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
197 style = $1
197 style = $1
198 filename = $6
198 filename = $6
199 rf = Regexp.new(filename, Regexp::IGNORECASE)
199 rf = Regexp.new(filename, Regexp::IGNORECASE)
200 # search for the picture in attachments
200 # search for the picture in attachments
201 if found = attachments.detect { |att| att.filename =~ rf }
201 if found = attachments.detect { |att| att.filename =~ rf }
202 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
202 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
203 "!#{style}#{image_url}!"
203 "!#{style}#{image_url}!"
204 else
204 else
205 "!#{style}#{filename}!"
205 "!#{style}#{filename}!"
206 end
206 end
207 end
207 end
208 end
208 end
209
209
210 text = (Setting.text_formatting == 'textile') ?
210 text = (Setting.text_formatting == 'textile') ?
211 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
211 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
212 simple_format(auto_link(h(text)))
212 simple_format(auto_link(h(text)))
213
213
214 # different methods for formatting wiki links
214 # different methods for formatting wiki links
215 case options[:wiki_links]
215 case options[:wiki_links]
216 when :local
216 when :local
217 # used for local links to html files
217 # used for local links to html files
218 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
218 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
219 when :anchor
219 when :anchor
220 # used for single-file wiki export
220 # used for single-file wiki export
221 format_wiki_link = Proc.new {|project, title| "##{title}" }
221 format_wiki_link = Proc.new {|project, title| "##{title}" }
222 else
222 else
223 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
223 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
224 end
224 end
225
225
226 project = options[:project] || @project
226 project = options[:project] || @project
227
227
228 # Wiki links
228 # Wiki links
229 #
229 #
230 # Examples:
230 # Examples:
231 # [[mypage]]
231 # [[mypage]]
232 # [[mypage|mytext]]
232 # [[mypage|mytext]]
233 # wiki links can refer other project wikis, using project name or identifier:
233 # wiki links can refer other project wikis, using project name or identifier:
234 # [[project:]] -> wiki starting page
234 # [[project:]] -> wiki starting page
235 # [[project:|mytext]]
235 # [[project:|mytext]]
236 # [[project:mypage]]
236 # [[project:mypage]]
237 # [[project:mypage|mytext]]
237 # [[project:mypage|mytext]]
238 text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m|
238 text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m|
239 link_project = project
239 link_project = project
240 esc, all, page, title = $1, $2, $3, $5
240 esc, all, page, title = $1, $2, $3, $5
241 if esc.nil?
241 if esc.nil?
242 if page =~ /^([^\:]+)\:(.*)$/
242 if page =~ /^([^\:]+)\:(.*)$/
243 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
243 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
244 page = $2
244 page = $2
245 title ||= $1 if page.blank?
245 title ||= $1 if page.blank?
246 end
246 end
247
247
248 if link_project && link_project.wiki
248 if link_project && link_project.wiki
249 # check if page exists
249 # check if page exists
250 wiki_page = link_project.wiki.find_page(page)
250 wiki_page = link_project.wiki.find_page(page)
251 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
251 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
252 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
252 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
253 else
253 else
254 # project or wiki doesn't exist
254 # project or wiki doesn't exist
255 title || page
255 title || page
256 end
256 end
257 else
257 else
258 all
258 all
259 end
259 end
260 end
260 end
261
261
262 # Redmine links
262 # Redmine links
263 #
263 #
264 # Examples:
264 # Examples:
265 # Issues:
265 # Issues:
266 # #52 -> Link to issue #52
266 # #52 -> Link to issue #52
267 # Changesets:
267 # Changesets:
268 # r52 -> Link to revision 52
268 # r52 -> Link to revision 52
269 # Documents:
269 # Documents:
270 # document#17 -> Link to document with id 17
270 # document#17 -> Link to document with id 17
271 # document:Greetings -> Link to the document with title "Greetings"
271 # document:Greetings -> Link to the document with title "Greetings"
272 # document:"Some document" -> Link to the document with title "Some document"
272 # document:"Some document" -> Link to the document with title "Some document"
273 # Versions:
273 # Versions:
274 # version#3 -> Link to version with id 3
274 # version#3 -> Link to version with id 3
275 # version:1.0.0 -> Link to version named "1.0.0"
275 # version:1.0.0 -> Link to version named "1.0.0"
276 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
276 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
277 # Attachments:
277 # Attachments:
278 # attachment:file.zip -> Link to the attachment of the current object named file.zip
278 # attachment:file.zip -> Link to the attachment of the current object named file.zip
279 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
279 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
280 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
280 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
281 link = nil
281 link = nil
282 if esc.nil?
282 if esc.nil?
283 if prefix.nil? && sep == 'r'
283 if prefix.nil? && sep == 'r'
284 if project && (changeset = project.changesets.find_by_revision(oid))
284 if project && (changeset = project.changesets.find_by_revision(oid))
285 link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
285 link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
286 :title => truncate(changeset.comments, 100))
286 :title => truncate(changeset.comments, 100))
287 end
287 end
288 elsif sep == '#'
288 elsif sep == '#'
289 oid = oid.to_i
289 oid = oid.to_i
290 case prefix
290 case prefix
291 when nil
291 when nil
292 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
292 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
293 link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
293 link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
294 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
294 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
295 link = content_tag('del', link) if issue.closed?
295 link = content_tag('del', link) if issue.closed?
296 end
296 end
297 when 'document'
297 when 'document'
298 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
298 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
299 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
299 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
300 end
300 end
301 when 'version'
301 when 'version'
302 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
302 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
303 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
303 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
304 end
304 end
305 end
305 end
306 elsif sep == ':'
306 elsif sep == ':'
307 # removes the double quotes if any
307 # removes the double quotes if any
308 name = oid.gsub(%r{^"(.*)"$}, "\\1")
308 name = oid.gsub(%r{^"(.*)"$}, "\\1")
309 case prefix
309 case prefix
310 when 'document'
310 when 'document'
311 if project && document = project.documents.find_by_title(name)
311 if project && document = project.documents.find_by_title(name)
312 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
312 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
313 end
313 end
314 when 'version'
314 when 'version'
315 if project && version = project.versions.find_by_name(name)
315 if project && version = project.versions.find_by_name(name)
316 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
316 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
317 end
317 end
318 when 'attachment'
318 when 'attachment'
319 if attachments && attachment = attachments.detect {|a| a.filename == name }
319 if attachments && attachment = attachments.detect {|a| a.filename == name }
320 link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment'
320 link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment'
321 end
321 end
322 end
322 end
323 end
323 end
324 end
324 end
325 leading + (link || "#{prefix}#{sep}#{oid}")
325 leading + (link || "#{prefix}#{sep}#{oid}")
326 end
326 end
327
327
328 text
328 text
329 end
329 end
330
330
331 # Same as Rails' simple_format helper without using paragraphs
331 # Same as Rails' simple_format helper without using paragraphs
332 def simple_format_without_paragraph(text)
332 def simple_format_without_paragraph(text)
333 text.to_s.
333 text.to_s.
334 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
334 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
335 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
335 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
336 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
336 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
337 end
337 end
338
338
339 def error_messages_for(object_name, options = {})
339 def error_messages_for(object_name, options = {})
340 options = options.symbolize_keys
340 options = options.symbolize_keys
341 object = instance_variable_get("@#{object_name}")
341 object = instance_variable_get("@#{object_name}")
342 if object && !object.errors.empty?
342 if object && !object.errors.empty?
343 # build full_messages here with controller current language
343 # build full_messages here with controller current language
344 full_messages = []
344 full_messages = []
345 object.errors.each do |attr, msg|
345 object.errors.each do |attr, msg|
346 next if msg.nil?
346 next if msg.nil?
347 msg = msg.first if msg.is_a? Array
347 msg = msg.first if msg.is_a? Array
348 if attr == "base"
348 if attr == "base"
349 full_messages << l(msg)
349 full_messages << l(msg)
350 else
350 else
351 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
351 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
352 end
352 end
353 end
353 end
354 # retrieve custom values error messages
354 # retrieve custom values error messages
355 if object.errors[:custom_values]
355 if object.errors[:custom_values]
356 object.custom_values.each do |v|
356 object.custom_values.each do |v|
357 v.errors.each do |attr, msg|
357 v.errors.each do |attr, msg|
358 next if msg.nil?
358 next if msg.nil?
359 msg = msg.first if msg.is_a? Array
359 msg = msg.first if msg.is_a? Array
360 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
360 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
361 end
361 end
362 end
362 end
363 end
363 end
364 content_tag("div",
364 content_tag("div",
365 content_tag(
365 content_tag(
366 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
366 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
367 ) +
367 ) +
368 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
368 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
369 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
369 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
370 )
370 )
371 else
371 else
372 ""
372 ""
373 end
373 end
374 end
374 end
375
375
376 def lang_options_for_select(blank=true)
376 def lang_options_for_select(blank=true)
377 (blank ? [["(auto)", ""]] : []) +
377 (blank ? [["(auto)", ""]] : []) +
378 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
378 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
379 end
379 end
380
380
381 def label_tag_for(name, option_tags = nil, options = {})
381 def label_tag_for(name, option_tags = nil, options = {})
382 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
382 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
383 content_tag("label", label_text)
383 content_tag("label", label_text)
384 end
384 end
385
385
386 def labelled_tabular_form_for(name, object, options, &proc)
386 def labelled_tabular_form_for(name, object, options, &proc)
387 options[:html] ||= {}
387 options[:html] ||= {}
388 options[:html].store :class, "tabular"
388 options[:html].store :class, "tabular"
389 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
389 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
390 end
390 end
391
391
392 def check_all_links(form_name)
392 def check_all_links(form_name)
393 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
393 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
394 " | " +
394 " | " +
395 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
395 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
396 end
396 end
397
397
398 def progress_bar(pcts, options={})
398 def progress_bar(pcts, options={})
399 pcts = [pcts, pcts] unless pcts.is_a?(Array)
399 pcts = [pcts, pcts] unless pcts.is_a?(Array)
400 pcts[1] = pcts[1] - pcts[0]
400 pcts[1] = pcts[1] - pcts[0]
401 pcts << (100 - pcts[1] - pcts[0])
401 pcts << (100 - pcts[1] - pcts[0])
402 width = options[:width] || '100px;'
402 width = options[:width] || '100px;'
403 legend = options[:legend] || ''
403 legend = options[:legend] || ''
404 content_tag('table',
404 content_tag('table',
405 content_tag('tr',
405 content_tag('tr',
406 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
406 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
407 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
407 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
408 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
408 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
409 ), :class => 'progress', :style => "width: #{width};") +
409 ), :class => 'progress', :style => "width: #{width};") +
410 content_tag('p', legend, :class => 'pourcent')
410 content_tag('p', legend, :class => 'pourcent')
411 end
411 end
412
412
413 def context_menu_link(name, url, options={})
413 def context_menu_link(name, url, options={})
414 options[:class] ||= ''
414 options[:class] ||= ''
415 if options.delete(:selected)
415 if options.delete(:selected)
416 options[:class] << ' icon-checked disabled'
416 options[:class] << ' icon-checked disabled'
417 options[:disabled] = true
417 options[:disabled] = true
418 end
418 end
419 if options.delete(:disabled)
419 if options.delete(:disabled)
420 options.delete(:method)
420 options.delete(:method)
421 options.delete(:confirm)
421 options.delete(:confirm)
422 options.delete(:onclick)
422 options.delete(:onclick)
423 options[:class] << ' disabled'
423 options[:class] << ' disabled'
424 url = '#'
424 url = '#'
425 end
425 end
426 link_to name, url, options
426 link_to name, url, options
427 end
427 end
428
428
429 def calendar_for(field_id)
429 def calendar_for(field_id)
430 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
430 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
431 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
431 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
432 end
432 end
433
433
434 def wikitoolbar_for(field_id)
434 def wikitoolbar_for(field_id)
435 return '' unless Setting.text_formatting == 'textile'
435 return '' unless Setting.text_formatting == 'textile'
436 javascript_include_tag('jstoolbar') + javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
436 javascript_include_tag('jstoolbar/jstoolbar') +
437 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
438 javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
437 end
439 end
438
440
439 def content_for(name, content = nil, &block)
441 def content_for(name, content = nil, &block)
440 @has_content ||= {}
442 @has_content ||= {}
441 @has_content[name] = true
443 @has_content[name] = true
442 super(name, content, &block)
444 super(name, content, &block)
443 end
445 end
444
446
445 def has_content?(name)
447 def has_content?(name)
446 (@has_content && @has_content[name]) || false
448 (@has_content && @has_content[name]) || false
447 end
449 end
448 end
450 end
@@ -1,521 +1,525
1 /* ***** BEGIN LICENSE BLOCK *****
1 /* ***** BEGIN LICENSE BLOCK *****
2 * This file is part of DotClear.
2 * This file is part of DotClear.
3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
3 * Copyright (c) 2005 Nicolas Martin & Olivier Meunier and contributors. All
4 * rights reserved.
4 * rights reserved.
5 *
5 *
6 * DotClear is free software; you can redistribute it and/or modify
6 * DotClear is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
9 * (at your option) any later version.
10 *
10 *
11 * DotClear is distributed in the hope that it will be useful,
11 * DotClear is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
14 * GNU General Public License for more details.
15 *
15 *
16 * You should have received a copy of the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with DotClear; if not, write to the Free Software
17 * along with DotClear; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
19 *
20 * ***** END LICENSE BLOCK *****
20 * ***** END LICENSE BLOCK *****
21 */
21 */
22
22
23 /* Modified by JP LANG for textile formatting */
23 /* Modified by JP LANG for textile formatting */
24
24
25 function jsToolBar(textarea) {
25 function jsToolBar(textarea) {
26 if (!document.createElement) { return; }
26 if (!document.createElement) { return; }
27
27
28 if (!textarea) { return; }
28 if (!textarea) { return; }
29
29
30 if ((typeof(document["selection"]) == "undefined")
30 if ((typeof(document["selection"]) == "undefined")
31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
31 && (typeof(textarea["setSelectionRange"]) == "undefined")) {
32 return;
32 return;
33 }
33 }
34
34
35 this.textarea = textarea;
35 this.textarea = textarea;
36
36
37 this.editor = document.createElement('div');
37 this.editor = document.createElement('div');
38 this.editor.className = 'jstEditor';
38 this.editor.className = 'jstEditor';
39
39
40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
40 this.textarea.parentNode.insertBefore(this.editor,this.textarea);
41 this.editor.appendChild(this.textarea);
41 this.editor.appendChild(this.textarea);
42
42
43 this.toolbar = document.createElement("div");
43 this.toolbar = document.createElement("div");
44 this.toolbar.className = 'jstElements';
44 this.toolbar.className = 'jstElements';
45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
45 this.editor.parentNode.insertBefore(this.toolbar,this.editor);
46
46
47 // Dragable resizing (only for gecko)
47 // Dragable resizing (only for gecko)
48 if (this.editor.addEventListener)
48 if (this.editor.addEventListener)
49 {
49 {
50 this.handle = document.createElement('div');
50 this.handle = document.createElement('div');
51 this.handle.className = 'jstHandle';
51 this.handle.className = 'jstHandle';
52 var dragStart = this.resizeDragStart;
52 var dragStart = this.resizeDragStart;
53 var This = this;
53 var This = this;
54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
54 this.handle.addEventListener('mousedown',function(event) { dragStart.call(This,event); },false);
55 // fix memory leak in Firefox (bug #241518)
55 // fix memory leak in Firefox (bug #241518)
56 window.addEventListener('unload',function() {
56 window.addEventListener('unload',function() {
57 var del = This.handle.parentNode.removeChild(This.handle);
57 var del = This.handle.parentNode.removeChild(This.handle);
58 delete(This.handle);
58 delete(This.handle);
59 },false);
59 },false);
60
60
61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
61 this.editor.parentNode.insertBefore(this.handle,this.editor.nextSibling);
62 }
62 }
63
63
64 this.context = null;
64 this.context = null;
65 this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni
65 this.toolNodes = {}; // lorsque la toolbar est dessinΓ©e , cet objet est garni
66 // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils.
66 // de raccourcis vers les Γ©lΓ©ments DOM correspondants aux outils.
67 }
67 }
68
68
69 function jsButton(title, fn, scope, className) {
69 function jsButton(title, fn, scope, className) {
70 this.title = title || null;
70 if(typeof jsToolBar.strings == 'undefined') {
71 this.title = title || null;
72 } else {
73 this.title = jsToolBar.strings[title] || title || null;
74 }
71 this.fn = fn || function(){};
75 this.fn = fn || function(){};
72 this.scope = scope || null;
76 this.scope = scope || null;
73 this.className = className || null;
77 this.className = className || null;
74 }
78 }
75 jsButton.prototype.draw = function() {
79 jsButton.prototype.draw = function() {
76 if (!this.scope) return null;
80 if (!this.scope) return null;
77
81
78 var button = document.createElement('button');
82 var button = document.createElement('button');
79 button.setAttribute('type','button');
83 button.setAttribute('type','button');
80 if (this.className) button.className = this.className;
84 if (this.className) button.className = this.className;
81 button.title = this.title;
85 button.title = this.title;
82 var span = document.createElement('span');
86 var span = document.createElement('span');
83 span.appendChild(document.createTextNode(this.title));
87 span.appendChild(document.createTextNode(this.title));
84 button.appendChild(span);
88 button.appendChild(span);
85
89
86 if (this.icon != undefined) {
90 if (this.icon != undefined) {
87 button.style.backgroundImage = 'url('+this.icon+')';
91 button.style.backgroundImage = 'url('+this.icon+')';
88 }
92 }
89 if (typeof(this.fn) == 'function') {
93 if (typeof(this.fn) == 'function') {
90 var This = this;
94 var This = this;
91 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
95 button.onclick = function() { try { This.fn.apply(This.scope, arguments) } catch (e) {} return false; };
92 }
96 }
93 return button;
97 return button;
94 }
98 }
95
99
96 function jsSpace(id) {
100 function jsSpace(id) {
97 this.id = id || null;
101 this.id = id || null;
98 this.width = null;
102 this.width = null;
99 }
103 }
100 jsSpace.prototype.draw = function() {
104 jsSpace.prototype.draw = function() {
101 var span = document.createElement('span');
105 var span = document.createElement('span');
102 if (this.id) span.id = this.id;
106 if (this.id) span.id = this.id;
103 span.appendChild(document.createTextNode(String.fromCharCode(160)));
107 span.appendChild(document.createTextNode(String.fromCharCode(160)));
104 span.className = 'jstSpacer';
108 span.className = 'jstSpacer';
105 if (this.width) span.style.marginRight = this.width+'px';
109 if (this.width) span.style.marginRight = this.width+'px';
106
110
107 return span;
111 return span;
108 }
112 }
109
113
110 function jsCombo(title, options, scope, fn, className) {
114 function jsCombo(title, options, scope, fn, className) {
111 this.title = title || null;
115 this.title = title || null;
112 this.options = options || null;
116 this.options = options || null;
113 this.scope = scope || null;
117 this.scope = scope || null;
114 this.fn = fn || function(){};
118 this.fn = fn || function(){};
115 this.className = className || null;
119 this.className = className || null;
116 }
120 }
117 jsCombo.prototype.draw = function() {
121 jsCombo.prototype.draw = function() {
118 if (!this.scope || !this.options) return null;
122 if (!this.scope || !this.options) return null;
119
123
120 var select = document.createElement('select');
124 var select = document.createElement('select');
121 if (this.className) select.className = className;
125 if (this.className) select.className = className;
122 select.title = this.title;
126 select.title = this.title;
123
127
124 for (var o in this.options) {
128 for (var o in this.options) {
125 //var opt = this.options[o];
129 //var opt = this.options[o];
126 var option = document.createElement('option');
130 var option = document.createElement('option');
127 option.value = o;
131 option.value = o;
128 option.appendChild(document.createTextNode(this.options[o]));
132 option.appendChild(document.createTextNode(this.options[o]));
129 select.appendChild(option);
133 select.appendChild(option);
130 }
134 }
131
135
132 var This = this;
136 var This = this;
133 select.onchange = function() {
137 select.onchange = function() {
134 try {
138 try {
135 This.fn.call(This.scope, this.value);
139 This.fn.call(This.scope, this.value);
136 } catch (e) { alert(e); }
140 } catch (e) { alert(e); }
137
141
138 return false;
142 return false;
139 }
143 }
140
144
141 return select;
145 return select;
142 }
146 }
143
147
144
148
145 jsToolBar.prototype = {
149 jsToolBar.prototype = {
146 base_url: '',
150 base_url: '',
147 mode: 'wiki',
151 mode: 'wiki',
148 elements: {},
152 elements: {},
149
153
150 getMode: function() {
154 getMode: function() {
151 return this.mode;
155 return this.mode;
152 },
156 },
153
157
154 setMode: function(mode) {
158 setMode: function(mode) {
155 this.mode = mode || 'wiki';
159 this.mode = mode || 'wiki';
156 },
160 },
157
161
158 switchMode: function(mode) {
162 switchMode: function(mode) {
159 mode = mode || 'wiki';
163 mode = mode || 'wiki';
160 this.draw(mode);
164 this.draw(mode);
161 },
165 },
162
166
163 button: function(toolName) {
167 button: function(toolName) {
164 var tool = this.elements[toolName];
168 var tool = this.elements[toolName];
165 if (typeof tool.fn[this.mode] != 'function') return null;
169 if (typeof tool.fn[this.mode] != 'function') return null;
166 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
170 var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_'+toolName);
167 if (tool.icon != undefined) b.icon = tool.icon;
171 if (tool.icon != undefined) b.icon = tool.icon;
168 return b;
172 return b;
169 },
173 },
170 space: function(toolName) {
174 space: function(toolName) {
171 var tool = new jsSpace(toolName)
175 var tool = new jsSpace(toolName)
172 if (this.elements[toolName].width !== undefined)
176 if (this.elements[toolName].width !== undefined)
173 tool.width = this.elements[toolName].width;
177 tool.width = this.elements[toolName].width;
174 return tool;
178 return tool;
175 },
179 },
176 combo: function(toolName) {
180 combo: function(toolName) {
177 var tool = this.elements[toolName];
181 var tool = this.elements[toolName];
178 var length = tool[this.mode].list.length;
182 var length = tool[this.mode].list.length;
179
183
180 if (typeof tool[this.mode].fn != 'function' || length == 0) {
184 if (typeof tool[this.mode].fn != 'function' || length == 0) {
181 return null;
185 return null;
182 } else {
186 } else {
183 var options = {};
187 var options = {};
184 for (var i=0; i < length; i++) {
188 for (var i=0; i < length; i++) {
185 var opt = tool[this.mode].list[i];
189 var opt = tool[this.mode].list[i];
186 options[opt] = tool.options[opt];
190 options[opt] = tool.options[opt];
187 }
191 }
188 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
192 return new jsCombo(tool.title, options, this, tool[this.mode].fn);
189 }
193 }
190 },
194 },
191 draw: function(mode) {
195 draw: function(mode) {
192 this.setMode(mode);
196 this.setMode(mode);
193
197
194 // Empty toolbar
198 // Empty toolbar
195 while (this.toolbar.hasChildNodes()) {
199 while (this.toolbar.hasChildNodes()) {
196 this.toolbar.removeChild(this.toolbar.firstChild)
200 this.toolbar.removeChild(this.toolbar.firstChild)
197 }
201 }
198 this.toolNodes = {}; // vide les raccourcis DOM/**/
202 this.toolNodes = {}; // vide les raccourcis DOM/**/
199
203
200 // Draw toolbar elements
204 // Draw toolbar elements
201 var b, tool, newTool;
205 var b, tool, newTool;
202
206
203 for (var i in this.elements) {
207 for (var i in this.elements) {
204 b = this.elements[i];
208 b = this.elements[i];
205
209
206 var disabled =
210 var disabled =
207 b.type == undefined || b.type == ''
211 b.type == undefined || b.type == ''
208 || (b.disabled != undefined && b.disabled)
212 || (b.disabled != undefined && b.disabled)
209 || (b.context != undefined && b.context != null && b.context != this.context);
213 || (b.context != undefined && b.context != null && b.context != this.context);
210
214
211 if (!disabled && typeof this[b.type] == 'function') {
215 if (!disabled && typeof this[b.type] == 'function') {
212 tool = this[b.type](i);
216 tool = this[b.type](i);
213 if (tool) newTool = tool.draw();
217 if (tool) newTool = tool.draw();
214 if (newTool) {
218 if (newTool) {
215 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
219 this.toolNodes[i] = newTool; //mémorise l'accès DOM pour usage éventuel ultérieur
216 this.toolbar.appendChild(newTool);
220 this.toolbar.appendChild(newTool);
217 }
221 }
218 }
222 }
219 }
223 }
220 },
224 },
221
225
222 singleTag: function(stag,etag) {
226 singleTag: function(stag,etag) {
223 stag = stag || null;
227 stag = stag || null;
224 etag = etag || stag;
228 etag = etag || stag;
225
229
226 if (!stag || !etag) { return; }
230 if (!stag || !etag) { return; }
227
231
228 this.encloseSelection(stag,etag);
232 this.encloseSelection(stag,etag);
229 },
233 },
230
234
231 encloseLineSelection: function(prefix, suffix, fn) {
235 encloseLineSelection: function(prefix, suffix, fn) {
232 this.textarea.focus();
236 this.textarea.focus();
233
237
234 prefix = prefix || '';
238 prefix = prefix || '';
235 suffix = suffix || '';
239 suffix = suffix || '';
236
240
237 var start, end, sel, scrollPos, subst, res;
241 var start, end, sel, scrollPos, subst, res;
238
242
239 if (typeof(document["selection"]) != "undefined") {
243 if (typeof(document["selection"]) != "undefined") {
240 sel = document.selection.createRange().text;
244 sel = document.selection.createRange().text;
241 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
245 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
242 start = this.textarea.selectionStart;
246 start = this.textarea.selectionStart;
243 end = this.textarea.selectionEnd;
247 end = this.textarea.selectionEnd;
244 scrollPos = this.textarea.scrollTop;
248 scrollPos = this.textarea.scrollTop;
245 // go to the start of the line
249 // go to the start of the line
246 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
250 start = this.textarea.value.substring(0, start).replace(/[^\r\n]*$/g,'').length;
247 // go to the end of the line
251 // go to the end of the line
248 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
252 end = this.textarea.value.length - this.textarea.value.substring(end, this.textarea.value.length).replace(/^[^\r\n]*/, '').length;
249 sel = this.textarea.value.substring(start, end);
253 sel = this.textarea.value.substring(start, end);
250 }
254 }
251
255
252 if (sel.match(/ $/)) { // exclude ending space char, if any
256 if (sel.match(/ $/)) { // exclude ending space char, if any
253 sel = sel.substring(0, sel.length - 1);
257 sel = sel.substring(0, sel.length - 1);
254 suffix = suffix + " ";
258 suffix = suffix + " ";
255 }
259 }
256
260
257 if (typeof(fn) == 'function') {
261 if (typeof(fn) == 'function') {
258 res = (sel) ? fn.call(this,sel) : fn('');
262 res = (sel) ? fn.call(this,sel) : fn('');
259 } else {
263 } else {
260 res = (sel) ? sel : '';
264 res = (sel) ? sel : '';
261 }
265 }
262
266
263 subst = prefix + res + suffix;
267 subst = prefix + res + suffix;
264
268
265 if (typeof(document["selection"]) != "undefined") {
269 if (typeof(document["selection"]) != "undefined") {
266 document.selection.createRange().text = subst;
270 document.selection.createRange().text = subst;
267 var range = this.textarea.createTextRange();
271 var range = this.textarea.createTextRange();
268 range.collapse(false);
272 range.collapse(false);
269 range.move('character', -suffix.length);
273 range.move('character', -suffix.length);
270 range.select();
274 range.select();
271 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
275 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
272 this.textarea.value = this.textarea.value.substring(0, start) + subst +
276 this.textarea.value = this.textarea.value.substring(0, start) + subst +
273 this.textarea.value.substring(end);
277 this.textarea.value.substring(end);
274 if (sel) {
278 if (sel) {
275 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
279 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
276 } else {
280 } else {
277 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
281 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
278 }
282 }
279 this.textarea.scrollTop = scrollPos;
283 this.textarea.scrollTop = scrollPos;
280 }
284 }
281 },
285 },
282
286
283 encloseSelection: function(prefix, suffix, fn) {
287 encloseSelection: function(prefix, suffix, fn) {
284 this.textarea.focus();
288 this.textarea.focus();
285
289
286 prefix = prefix || '';
290 prefix = prefix || '';
287 suffix = suffix || '';
291 suffix = suffix || '';
288
292
289 var start, end, sel, scrollPos, subst, res;
293 var start, end, sel, scrollPos, subst, res;
290
294
291 if (typeof(document["selection"]) != "undefined") {
295 if (typeof(document["selection"]) != "undefined") {
292 sel = document.selection.createRange().text;
296 sel = document.selection.createRange().text;
293 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
297 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
294 start = this.textarea.selectionStart;
298 start = this.textarea.selectionStart;
295 end = this.textarea.selectionEnd;
299 end = this.textarea.selectionEnd;
296 scrollPos = this.textarea.scrollTop;
300 scrollPos = this.textarea.scrollTop;
297 sel = this.textarea.value.substring(start, end);
301 sel = this.textarea.value.substring(start, end);
298 }
302 }
299
303
300 if (sel.match(/ $/)) { // exclude ending space char, if any
304 if (sel.match(/ $/)) { // exclude ending space char, if any
301 sel = sel.substring(0, sel.length - 1);
305 sel = sel.substring(0, sel.length - 1);
302 suffix = suffix + " ";
306 suffix = suffix + " ";
303 }
307 }
304
308
305 if (typeof(fn) == 'function') {
309 if (typeof(fn) == 'function') {
306 res = (sel) ? fn.call(this,sel) : fn('');
310 res = (sel) ? fn.call(this,sel) : fn('');
307 } else {
311 } else {
308 res = (sel) ? sel : '';
312 res = (sel) ? sel : '';
309 }
313 }
310
314
311 subst = prefix + res + suffix;
315 subst = prefix + res + suffix;
312
316
313 if (typeof(document["selection"]) != "undefined") {
317 if (typeof(document["selection"]) != "undefined") {
314 document.selection.createRange().text = subst;
318 document.selection.createRange().text = subst;
315 var range = this.textarea.createTextRange();
319 var range = this.textarea.createTextRange();
316 range.collapse(false);
320 range.collapse(false);
317 range.move('character', -suffix.length);
321 range.move('character', -suffix.length);
318 range.select();
322 range.select();
319 // this.textarea.caretPos -= suffix.length;
323 // this.textarea.caretPos -= suffix.length;
320 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
324 } else if (typeof(this.textarea["setSelectionRange"]) != "undefined") {
321 this.textarea.value = this.textarea.value.substring(0, start) + subst +
325 this.textarea.value = this.textarea.value.substring(0, start) + subst +
322 this.textarea.value.substring(end);
326 this.textarea.value.substring(end);
323 if (sel) {
327 if (sel) {
324 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
328 this.textarea.setSelectionRange(start + subst.length, start + subst.length);
325 } else {
329 } else {
326 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
330 this.textarea.setSelectionRange(start + prefix.length, start + prefix.length);
327 }
331 }
328 this.textarea.scrollTop = scrollPos;
332 this.textarea.scrollTop = scrollPos;
329 }
333 }
330 },
334 },
331
335
332 stripBaseURL: function(url) {
336 stripBaseURL: function(url) {
333 if (this.base_url != '') {
337 if (this.base_url != '') {
334 var pos = url.indexOf(this.base_url);
338 var pos = url.indexOf(this.base_url);
335 if (pos == 0) {
339 if (pos == 0) {
336 url = url.substr(this.base_url.length);
340 url = url.substr(this.base_url.length);
337 }
341 }
338 }
342 }
339
343
340 return url;
344 return url;
341 }
345 }
342 };
346 };
343
347
344 /** Resizer
348 /** Resizer
345 -------------------------------------------------------- */
349 -------------------------------------------------------- */
346 jsToolBar.prototype.resizeSetStartH = function() {
350 jsToolBar.prototype.resizeSetStartH = function() {
347 this.dragStartH = this.textarea.offsetHeight + 0;
351 this.dragStartH = this.textarea.offsetHeight + 0;
348 };
352 };
349 jsToolBar.prototype.resizeDragStart = function(event) {
353 jsToolBar.prototype.resizeDragStart = function(event) {
350 var This = this;
354 var This = this;
351 this.dragStartY = event.clientY;
355 this.dragStartY = event.clientY;
352 this.resizeSetStartH();
356 this.resizeSetStartH();
353 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
357 document.addEventListener('mousemove', this.dragMoveHdlr=function(event){This.resizeDragMove(event);}, false);
354 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
358 document.addEventListener('mouseup', this.dragStopHdlr=function(event){This.resizeDragStop(event);}, false);
355 };
359 };
356
360
357 jsToolBar.prototype.resizeDragMove = function(event) {
361 jsToolBar.prototype.resizeDragMove = function(event) {
358 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
362 this.textarea.style.height = (this.dragStartH+event.clientY-this.dragStartY)+'px';
359 };
363 };
360
364
361 jsToolBar.prototype.resizeDragStop = function(event) {
365 jsToolBar.prototype.resizeDragStop = function(event) {
362 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
366 document.removeEventListener('mousemove', this.dragMoveHdlr, false);
363 document.removeEventListener('mouseup', this.dragStopHdlr, false);
367 document.removeEventListener('mouseup', this.dragStopHdlr, false);
364 };
368 };
365
369
366 // Elements definition ------------------------------------
370 // Elements definition ------------------------------------
367
371
368 // strong
372 // strong
369 jsToolBar.prototype.elements.strong = {
373 jsToolBar.prototype.elements.strong = {
370 type: 'button',
374 type: 'button',
371 title: 'Strong emphasis',
375 title: 'Strong',
372 fn: {
376 fn: {
373 wiki: function() { this.singleTag('*') }
377 wiki: function() { this.singleTag('*') }
374 }
378 }
375 }
379 }
376
380
377 // em
381 // em
378 jsToolBar.prototype.elements.em = {
382 jsToolBar.prototype.elements.em = {
379 type: 'button',
383 type: 'button',
380 title: 'Emphasis',
384 title: 'Italic',
381 fn: {
385 fn: {
382 wiki: function() { this.singleTag("_") }
386 wiki: function() { this.singleTag("_") }
383 }
387 }
384 }
388 }
385
389
386 // ins
390 // ins
387 jsToolBar.prototype.elements.ins = {
391 jsToolBar.prototype.elements.ins = {
388 type: 'button',
392 type: 'button',
389 title: 'Inserted',
393 title: 'Underline',
390 fn: {
394 fn: {
391 wiki: function() { this.singleTag('+') }
395 wiki: function() { this.singleTag('+') }
392 }
396 }
393 }
397 }
394
398
395 // del
399 // del
396 jsToolBar.prototype.elements.del = {
400 jsToolBar.prototype.elements.del = {
397 type: 'button',
401 type: 'button',
398 title: 'Deleted',
402 title: 'Deleted',
399 fn: {
403 fn: {
400 wiki: function() { this.singleTag('-') }
404 wiki: function() { this.singleTag('-') }
401 }
405 }
402 }
406 }
403
407
404 // quote
408 // quote
405 jsToolBar.prototype.elements.quote = {
409 jsToolBar.prototype.elements.quote = {
406 type: 'button',
410 type: 'button',
407 title: 'Inline quote',
411 title: 'Inline quote',
408 fn: {
412 fn: {
409 wiki: function() { this.singleTag('??') }
413 wiki: function() { this.singleTag('??') }
410 }
414 }
411 }
415 }
412
416
413 // code
417 // code
414 jsToolBar.prototype.elements.code = {
418 jsToolBar.prototype.elements.code = {
415 type: 'button',
419 type: 'button',
416 title: 'Code',
420 title: 'Code',
417 fn: {
421 fn: {
418 wiki: function() { this.singleTag('@') }
422 wiki: function() { this.singleTag('@') }
419 }
423 }
420 }
424 }
421
425
422 // spacer
426 // spacer
423 jsToolBar.prototype.elements.space1 = {type: 'space'}
427 jsToolBar.prototype.elements.space1 = {type: 'space'}
424
428
425 // headings
429 // headings
426 jsToolBar.prototype.elements.h1 = {
430 jsToolBar.prototype.elements.h1 = {
427 type: 'button',
431 type: 'button',
428 title: 'Heading 1',
432 title: 'Heading 1',
429 fn: {
433 fn: {
430 wiki: function() {
434 wiki: function() {
431 this.encloseLineSelection('h1. ', '',function(str) {
435 this.encloseLineSelection('h1. ', '',function(str) {
432 str = str.replace(/^h\d+\.\s+/, '')
436 str = str.replace(/^h\d+\.\s+/, '')
433 return str;
437 return str;
434 });
438 });
435 }
439 }
436 }
440 }
437 }
441 }
438 jsToolBar.prototype.elements.h2 = {
442 jsToolBar.prototype.elements.h2 = {
439 type: 'button',
443 type: 'button',
440 title: 'Heading 2',
444 title: 'Heading 2',
441 fn: {
445 fn: {
442 wiki: function() {
446 wiki: function() {
443 this.encloseLineSelection('h2. ', '',function(str) {
447 this.encloseLineSelection('h2. ', '',function(str) {
444 str = str.replace(/^h\d+\.\s+/, '')
448 str = str.replace(/^h\d+\.\s+/, '')
445 return str;
449 return str;
446 });
450 });
447 }
451 }
448 }
452 }
449 }
453 }
450 jsToolBar.prototype.elements.h3 = {
454 jsToolBar.prototype.elements.h3 = {
451 type: 'button',
455 type: 'button',
452 title: 'Heading 3',
456 title: 'Heading 3',
453 fn: {
457 fn: {
454 wiki: function() {
458 wiki: function() {
455 this.encloseLineSelection('h3. ', '',function(str) {
459 this.encloseLineSelection('h3. ', '',function(str) {
456 str = str.replace(/^h\d+\.\s+/, '')
460 str = str.replace(/^h\d+\.\s+/, '')
457 return str;
461 return str;
458 });
462 });
459 }
463 }
460 }
464 }
461 }
465 }
462
466
463 // spacer
467 // spacer
464 jsToolBar.prototype.elements.space2 = {type: 'space'}
468 jsToolBar.prototype.elements.space2 = {type: 'space'}
465
469
466 // ul
470 // ul
467 jsToolBar.prototype.elements.ul = {
471 jsToolBar.prototype.elements.ul = {
468 type: 'button',
472 type: 'button',
469 title: 'Unordered list',
473 title: 'Unordered list',
470 fn: {
474 fn: {
471 wiki: function() {
475 wiki: function() {
472 this.encloseLineSelection('','',function(str) {
476 this.encloseLineSelection('','',function(str) {
473 str = str.replace(/\r/g,'');
477 str = str.replace(/\r/g,'');
474 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
478 return str.replace(/(\n|^)[#-]?\s*/g,"$1* ");
475 });
479 });
476 }
480 }
477 }
481 }
478 }
482 }
479
483
480 // ol
484 // ol
481 jsToolBar.prototype.elements.ol = {
485 jsToolBar.prototype.elements.ol = {
482 type: 'button',
486 type: 'button',
483 title: 'Ordered list',
487 title: 'Ordered list',
484 fn: {
488 fn: {
485 wiki: function() {
489 wiki: function() {
486 this.encloseLineSelection('','',function(str) {
490 this.encloseLineSelection('','',function(str) {
487 str = str.replace(/\r/g,'');
491 str = str.replace(/\r/g,'');
488 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
492 return str.replace(/(\n|^)[*-]?\s*/g,"$1# ");
489 });
493 });
490 }
494 }
491 }
495 }
492 }
496 }
493
497
494 // pre
498 // pre
495 jsToolBar.prototype.elements.pre = {
499 jsToolBar.prototype.elements.pre = {
496 type: 'button',
500 type: 'button',
497 title: 'Preformatted text',
501 title: 'Preformatted text',
498 fn: {
502 fn: {
499 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
503 wiki: function() { this.encloseLineSelection('<pre>\n', '\n</pre>') }
500 }
504 }
501 }
505 }
502
506
503 // spacer
507 // spacer
504 jsToolBar.prototype.elements.space3 = {type: 'space'}
508 jsToolBar.prototype.elements.space3 = {type: 'space'}
505
509
506 // wiki page
510 // wiki page
507 jsToolBar.prototype.elements.link = {
511 jsToolBar.prototype.elements.link = {
508 type: 'button',
512 type: 'button',
509 title: 'Wiki Page Link',
513 title: 'Wiki link',
510 fn: {
514 fn: {
511 wiki: function() { this.encloseSelection("[[", "]]") }
515 wiki: function() { this.encloseSelection("[[", "]]") }
512 }
516 }
513 }
517 }
514 // image
518 // image
515 jsToolBar.prototype.elements.img = {
519 jsToolBar.prototype.elements.img = {
516 type: 'button',
520 type: 'button',
517 title: 'Inline image',
521 title: 'Image',
518 fn: {
522 fn: {
519 wiki: function() { this.encloseSelection("!", "!") }
523 wiki: function() { this.encloseSelection("!", "!") }
520 }
524 }
521 }
525 }
General Comments 0
You need to be logged in to leave comments. Login now