Skip to content

Commit

Permalink
Add colorPicker for jstoolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
HaTrinh authored and HaTrinh committed Jul 14, 2010
1 parent 559363c commit fc09f21
Show file tree
Hide file tree
Showing 22 changed files with 5,611 additions and 31 deletions.
30 changes: 30 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module ApplicationHelper

def add_color_picker_lib()
stylesheet_link_tag('colorpicker', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/prototype', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/scriptaculous', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/builder', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/effects', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/dragdrop', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/controls', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/slider', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/yahoo', :plugin => 'redmine_daily_todos') +
javascript_include_tag('color_picker/colorpicker', :plugin => 'redmine_daily_todos')
end

def wikitoolbar_with_color_for(field_id, color_picker_text_id)
url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html"

help_link = l(:setting_text_formatting) + ': ' +
link_to(l(:label_help), url,
:onclick => "window.open(\"#{ url }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;")

javascript_tag("var colorPickerTextId = '#{color_picker_text_id}';") +
javascript_include_tag('jstoolbar/jstoolbar', :plugin => 'redmine_daily_todos') +
javascript_include_tag('jstoolbar/textile', :plugin => 'redmine_daily_todos') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_tag("var wikiToolbar = new jsToolBar($('#{field_id}')); wikiToolbar.setColorPickerTextId('#{color_picker_text_id}') ; wikiToolbar.setHelpLink('#{help_link}'); wikiToolbar.draw();") +
javascript_tag("new Control.ColorPicker('#{color_picker_text_id}', { IMAGE_BASE : '/javascripts/color_picker/' });")
end
end
4 changes: 2 additions & 2 deletions app/views/daily_todo_comments/_form.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
</div>
<% end %>
<%= wikitoolbar_for 'daily_todo_comment_body' %>

<%= add_color_picker_lib %>
<%= wikitoolbar_with_color_for('daily_todo_comment_body','colorTextCommentBody') %>
5 changes: 3 additions & 2 deletions app/views/daily_todo_entries/_form.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<% end %>
<% end %>
<%= wikitoolbar_for 'daily_todo_entry_plan' %>
<%= wikitoolbar_for 'daily_todo_entry_result' %>
<%= add_color_picker_lib %>
<%= wikitoolbar_with_color_for('daily_todo_entry_plan','colorTextPlan') %>
<%= wikitoolbar_with_color_for('daily_todo_entry_result','colorTextResult') %>
54 changes: 28 additions & 26 deletions app/views/daily_todos/one_user.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
<% @todos.each do |todo| %>
<hr />

<div <% if todo.date == @date %>
style="background-color: #FEFEF3;"
<%end%> >
<% if todo.lunch %>
<div <% if todo.date == @date %>
style="background-color: #FEFEF3;"
<%end%> >
<% if todo.lunch %>
<p>
<b><%= format_date_with_weekday(todo.date) %></b>
<% if @user == User.current %>
<b>
<%= link_to_remote(
l(:'daily_todos.delete'),
:url => daily_todo_path(todo),
:method => :delete,
:confirm => l(:'daily_todos.delete_confirm')) %>
l(:'daily_todos.delete'),
:url => daily_todo_path(todo),
:method => :delete,
:confirm => l(:'daily_todos.delete_confirm')) %>
</b>
<% end %>
</p>
Expand Down Expand Up @@ -64,25 +64,27 @@
<%= daily_todo_entry.end.strftime("%H:%M") if daily_todo_entry.end %><br />
</td>
<td style="vertical-align:middle;width:35%;"><%= textilizable daily_todo_entry.plan %></td>
<td style="vertical-align:middle;width:35%;"><%= textilizable daily_todo_entry.result %></td>
<td style="vertical-align:middle;width:35%;">
<%= textilizable daily_todo_entry.result %>
</td>
<% if @user == User.current %>
<td style="vertical-align:middle;width:15%;" align="center">
<% if todo.new_record? %>
<%= link_to(l(:'daily_todos.new'), {:action => 'new', :date => todo.date}) %>
<% else %>
<%= link_to(l(:'daily_todos.edit'), edit_daily_todo_entry_path(daily_todo_entry.id)) %>
<%= button_to_remote(l(:'daily_todos.delete'),
:controller => 'daily_todo_entries',
:url => daily_todo_entry_path(daily_todo_entry),
:method => :delete,
:confirm => l(:'daily_todos.delete_confirm')) %>
<%= button_to_remote(l(:'daily_todos.delete'),
:controller => 'daily_todo_entries',
:url => daily_todo_entry_path(daily_todo_entry),
:method => :delete,
:confirm => l(:'daily_todos.delete_confirm')) %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</table>
</table>

<% if todo.user_id == User.current.id %>
<div align="right"><%= link_to(l(:'daily_todos.entry.add'), todo_entry_new_path(todo.id))%></div>
Expand All @@ -94,11 +96,11 @@
<b><%= comment.user.name %></b>
<% if comment.user_id == User.current.id %>
<%= link_to(l(:'daily_todos.edit'), todo_comment_edit_path(todo.id,comment.id)) %>
<%= link_to_remote(l(:'daily_todos.delete'),
:controller => 'daily_todo_comments',
:url => daily_todo_comment_path(comment),
:method => :delete,
:confirm => l(:'daily_todos.delete_confirm')) %>
<%= link_to_remote(l(:'daily_todos.delete'),
:controller => 'daily_todo_comments',
:url => daily_todo_comment_path(comment),
:method => :delete,
:confirm => l(:'daily_todos.delete_confirm')) %>
<% end %><br />
<%= textilizable comment.body %>
<hr />
Expand All @@ -111,16 +113,16 @@
<% else %>
<% if @user == User.current %>
<b><%= format_date_with_weekday(todo.date) %>:</b>
<%= link_to_remote(
l(:'daily_todos.create_link'),
:url => {:action => 'create_todo', :date => todo.date.to_s}) %>
<%= link_to_remote(
l(:'daily_todos.create_link'),
:url => {:action => 'create_todo', :date => todo.date.to_s}) %>
<br />
<br />
<br />
<% else %>
<b> <%= format_date_with_weekday(todo.date) %>:
</b>
<%= l(:'daily_todos.no_todo') %>
<br /><br />
<br /><br />
<% end %>
<% end %>
</div>
Expand Down
Binary file added assets/images/color_picker/hline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/color_picker/hue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/color_picker/pickerbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/color_picker/select.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/jstoolbar/bt_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions assets/javascripts/color_picker/builder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//
// See scriptaculous.js for full license.

var Builder = {
NODEMAP: {
AREA: 'map',
CAPTION: 'table',
COL: 'table',
COLGROUP: 'table',
LEGEND: 'fieldset',
OPTGROUP: 'select',
OPTION: 'select',
PARAM: 'object',
TBODY: 'table',
TD: 'table',
TFOOT: 'table',
TH: 'table',
THEAD: 'table',
TR: 'table'
},
// note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
// due to a Firefox bug
node: function(elementName) {
elementName = elementName.toUpperCase();

// try innerHTML approach
var parentTag = this.NODEMAP[elementName] || 'div';
var parentElement = document.createElement(parentTag);
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
} catch(e) {}
var element = parentElement.firstChild || null;

// see if browser added wrapping tags
if(element && (element.tagName != elementName))
element = element.getElementsByTagName(elementName)[0];

// fallback to createElement approach
if(!element) element = document.createElement(elementName);

// abort if nothing could be created
if(!element) return;

// attributes (or text)
if(arguments[1])
if(this._isStringOrNumber(arguments[1]) ||
(arguments[1] instanceof Array)) {
this._children(element, arguments[1]);
} else {
var attrs = this._attributes(arguments[1]);
if(attrs.length) {
try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
parentElement.innerHTML = "<" +elementName + " " +
attrs + "></" + elementName + ">";
} catch(e) {}
element = parentElement.firstChild || null;
// workaround firefox 1.0.X bug
if(!element) {
element = document.createElement(elementName);
for(attr in arguments[1])
element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
}
if(element.tagName != elementName)
element = parentElement.getElementsByTagName(elementName)[0];
}
}

// text, or array of children
if(arguments[2])
this._children(element, arguments[2]);

return element;
},
_text: function(text) {
return document.createTextNode(text);
},
_attributes: function(attributes) {
var attrs = [];
for(attribute in attributes)
attrs.push((attribute=='className' ? 'class' : attribute) +
'="' + attributes[attribute].toString().escapeHTML() + '"');
return attrs.join(" ");
},
_children: function(element, children) {
if(typeof children=='object') { // array can hold nodes and text
children.flatten().each( function(e) {
if(typeof e=='object')
element.appendChild(e)
else
if(Builder._isStringOrNumber(e))
element.appendChild(Builder._text(e));
});
} else
if(Builder._isStringOrNumber(children))
element.appendChild(Builder._text(children));
},
_isStringOrNumber: function(param) {
return(typeof param=='string' || typeof param=='number');
}
}
Loading

0 comments on commit fc09f21

Please sign in to comment.