--- /dev/null
+class QuickEditIssuesController < ApplicationController
+ include ApplicationHelper
+ before_filter :find_issues
+ before_filter :check_first_issue
+ before_filter :check_target_specifier
+
+ def edit
+ @dialog_params = nil
+ @issue.available_custom_fields.each do |f|
+ custom_field_name = 'issue[custom_field_values][%d]' % f.id
+ if custom_field_name == @target_specifier
+ @dialog_params = get_input_dialog_params_for_custom_fields(@issue, @target_specifier, f)
+ end
+ end
+ if @dialog_params.nil?
+ @dialog_params = get_input_dialog_params_for_core_fields(@issue, @target_specifier)
+ end
+
+ @dialog_params[:issue_ids] = params[:ids]
+ @dialog_params[:back_url] = params[:back_url]
+ end
+
+private
+ # rails filter
+ def check_first_issue
+ if @issues.empty?
+ logger.warn "### quick edit ### issues not found."
+ render_404
+ end
+
+ @issue = @issues[0]
+ end
+
+ # rails filter
+ def check_target_specifier
+ @target_specifier = params[:target_specifier]
+ parsed = parse_target_specifier(@target_specifier)
+ if parsed.nil? || parsed.empty?
+ logger.warn "### quick edit ### invalid target specifier. target_specifier=" + @target_specifier
+ render_404
+ end
+
+ attribute_name = parsed[0]
+ unless @issue.safe_attribute_names.include?(attribute_name)
+ logger.warn "### quick edit ### no safe attribute. target_specifier=" + @target_specifier
+ render_404
+ end
+ end
+
+# def get_input_dialog_base_params(issue, target_specifier)
+# issue.available_custom_fields.each do |f|
+# custom_field_name = 'issue[custom_field_values][%d]' % f.id
+# if custom_field_name == target_specifier
+# return get_input_dialog_params_for_custom_fields(issue, target_specifier, f)
+# end
+# end
+#
+# v = get_input_dialog_params_for_core_fields(issue, target_specifier)
+# v
+# end
+#
+ def get_input_dialog_params_for_core_fields(issue, target_specifier)
+ attribute_name = parse_target_specifier(target_specifier)[0]
+
+ caption = get_attribute_caption(attribute_name)
+ field_type = get_attribute_type(attribute_name)
+ default_value = issue[attribute_name]
+ default_value = "" if default_value.nil?
+ validation_pattern = get_field_validation_pattern(field_type)
+ help_message = get_field_help_message(field_type)
+
+ ret =
+ { :caption => caption,
+ :target_specifier => target_specifier,
+ :field_type => field_type,
+ :default_value => default_value,
+ :validation_pattern => validation_pattern,
+ :help_message => help_message
+ }
+ end
+
+ def get_input_dialog_params_for_custom_fields(issue, target_specifier, custom_field)
+ caption = custom_field.name
+ field_type = custom_field.field_format
+ default_value = issue.editable_custom_field_values.detect {|v| v.custom_field_id == custom_field.id}
+ default_value = "" if default_value.nil?
+ validation_pattern = get_field_validation_pattern(field_type)
+ help_message = get_field_help_message(field_type)
+
+ ret =
+ { :caption => caption,
+ :target_specifier => target_specifier,
+ :field_type => field_type,
+ :default_value => default_value,
+ :validation_pattern => validation_pattern,
+ :help_message => help_message
+ }
+ end
+
+ def get_field_validation_pattern(field_type)
+ case field_type.to_sym
+ when :string
+ pattern = ''
+ when :int
+ pattern = '\d+'
+ when :date
+ pattern = '\d{4}-\d{2}-\d{2}'
+ end
+ end
+
+ def get_field_help_message(field_type)
+ help_message= l(:text_edit_confirm)
+ help_message += " (yyyy-mm-dd)" if field_type == :date
+ help_message
+ end
+
+end
#coding: utf-8
module ApplicationHelper
- def quick_edit_link_to(bulk_update_url, issue_ids, caption, target_field, field_type, default_value, disabled)
- help_message= l(:text_edit_confirm)
-
- case field_type.to_s
- when "string", "text"
- pattern = ''
- when "int"
- pattern = '\d+'
- when "date"
- pattern = '\d{4}-\d{2}-\d{2}'
- help_message += " (yyyy-mm-dd)"
- end
-
- pattern = h(pattern.gsub(/\\/,'\\\\\\\\'))
-
- bulk_update_url_escaped = URI.encode_www_form_component(bulk_update_url)
-
- issue_ids_js_string = "[" + @issue_ids.join(",") + "]"
-
- sprintf('<li>%s%s</li>',
- context_menu_link(
- h(caption),
- "javascript:quick_edit_show_input_dialog('#{bulk_update_url_escaped}', #{issue_ids_js_string}, '#{caption}', '#{target_field}', '#{field_type}', '#{pattern}', '#{help_message}', '#{default_value}')",
- :class => 'icon-edit',
- :disabled => disabled
- ),
- context_menu_link(
- h(:dummy),
- '#',
- :id => 'context_edit_update_link_%s' % target_field.to_s().tr('[]','__'),
- :style=>'display:none',
- :method => :post,
- )
- ).html_safe()
- end
+ def quick_edit_link_to(issue_ids, caption, attribute_name, additional_index, back_url, disabled)
+ target_specifier = build_target_specifier(attribute_name, additional_index)
+
+ ajax_url = quick_edit_issues_edit_path(:ids => issue_ids, :target_specifier => target_specifier, :back_url => back_url)
+
+ sprintf('<li>%s</li>',
+ context_menu_link(
+ h(caption),
+ ajax_url,
+ :class => 'icon-edit',
+ :disabled => disabled,
+ :remote => true
+ )
+ ).html_safe()
+ end
+
+ def build_target_specifier(attribute_name, additional_index)
+ target = "issue[#{attribute_name}]"
+ target += "[#{additional_index}]" unless additional_index.nil?
+ target
+ end
+
+ def parse_target_specifier(target_specifier)
+ /^issue\[(.+?)\].*/ =~ target_specifier
+ if Regexp.last_match.nil?
+ return nil
+ end
+
+ attribute_name = Regexp.last_match(1)
+
+ /^issue\[.+?\]\[(\d+)\]$/ =~ target_specifier
+ if Regexp.last_match.nil?
+ additional_index = nil
+ result = [attribute_name]
+ else
+ additional_index = Regexp.last_match(1)
+ result = [attribute_name, additional_index]
+ end
+
+ result
+ end
+
+ def get_attribute_caption(attribute_name)
+ case attribute_name.to_sym
+ when :subject
+ l(:field_subject)
+ when :parent_issue_id
+ l(:field_parent_issue)
+ when :start_date
+ l(:field_start_date)
+ when :due_date
+ l(:field_due_date)
+ end
+ end
+
+
+ def get_attribute_type(attribute_name)
+ case attribute_name.to_sym
+ when :subject
+ :string
+ when :parent_issue_id
+ :int
+ when :start_date
+ :date
+ when :due_date
+ :date
+ end
+ end
end
-<%
- extend ApplicationHelper
-%>
- <div id="quick_edit_input_dialog" style="display:none;" title="Quick Edit">
- <p id="quick_edit_input_dialog_message"></p>
- <form>
- <fieldset id="text_fields" style="border: none; margin:none; padding: none;">
- <input id="quick_edit_input_dialog_new_value" type="text" size="40" style="vertical-align:middle;"></input>
- </fieldset>
- <fieldset id="date_fields" style="border: none; margin:none; padding: none;">
- <input id="quick_edit_input_dialog_new_date_value" type="text" size="40" style="vertical-align:middle;"></input>
- <%= calendar_for('quick_edit_input_dialog_new_date_value') %>
- </fieldset>
- <input id="quick_edit_input_dialog_bulk_update_url" type="hidden"></input>
- <input id="quick_edit_input_dialog_issue_ids" type="hidden"></input>
- <input id="quick_edit_input_dialog_target" type="hidden"></input>
- <input id="quick_edit_input_dialog_field_type" type="hidden"></input>
- <input id="quick_edit_input_dialog_pattern" type="hidden"></input>
- <input id="quick_edit_input_dialog_dummy" type="text" style="display:none"></input>
- </form>
- </div>
+<div id="quick_edit_input_dialogs"></div>
<script>
//<![CDATA[
-function quick_edit_get_value_element(field_type) {
- if (field_type == 'date') {
- return $('#quick_edit_input_dialog_new_date_value');
- } else {
- return $('#quick_edit_input_dialog_new_value');
- }
-}
-
-function quick_edit_show_input_dialog(bulk_update_url,ids,field_name,target,field_type,pattern,message,default_value){
- if (field_type == 'date') {
- $("#quick_edit_input_dialog > form > #text_fields").css("display", "none");
- $("#quick_edit_input_dialog > form > #date_fields").css("display", "block");
- } else {
- $("#quick_edit_input_dialog > form > #text_fields").css("display", "block");
- $("#quick_edit_input_dialog > form > #date_fields").css("display", "none");
- }
-
- quick_edit_get_value_element(field_type).val(default_value);
-
- $("#quick_edit_input_dialog").attr('title','Quick Edit - ' + field_name);
- $("#quick_edit_input_dialog_bulk_update_url").val(bulk_update_url);
- $("#quick_edit_input_dialog_issue_ids").val(ids);
- $("#quick_edit_input_dialog_target").val(target);
- $("#quick_edit_input_dialog_field_type").val(field_type);
- $("#quick_edit_input_dialog_pattern").val(pattern);
- $("#quick_edit_input_dialog_message").html(message);
- $("#quick_edit_input_dialog").dialog({
- modal: true,
- closeOnEscape: false,
- width: 500,
- height: 210,
- buttons: {
- "Ok" : quick_edit_input_dialog_ok,
- "Cancel" : quick_edit_input_dialog_cancel
- },
- close: quick_edit_input_dialog_close
- });
-}
-
function quick_edit_input_dialog_close(){
+ $("#quick_edit_input_dialog").remove();
}
function quick_edit_input_dialog_cancel(){
}
function quick_edit_input_dialog_ok(){
- var field_type = $("#quick_edit_input_dialog_field_type").val();
- var new_value = quick_edit_get_value_element(field_type).val();
+ var new_value = $("#quick_edit_input_dialog > form > #new_value").val();
if(new_value === null) return;
- var target = $("#quick_edit_input_dialog_target").val();
- var pattern = new RegExp($("#quick_edit_input_dialog_pattern").val());
+ var pattern = new RegExp($("#quick_edit_input_dialog > form > #validation_pattern").val());
if(new_value == "") {
alert('<%=l(:text_is_required)%>');
}
}
- var issue_ids = $("#quick_edit_input_dialog_issue_ids").val();
+ var issue_ids = $("#quick_edit_input_dialog > form > #ids").val();
if(issue_ids.length>1){
if(!confirm('<%=l(:text_multiple_update_confirm)%>')) return;
}
- var additional_index;
- var match = /(.*)\[([0-9]+)\]/.exec(target);
- if(match){
- target_name = match[1];
- additional_index = match[2];
- }else{
- target_name = target;
- additional_index = null;
- }
-
- var bulk_update_html_id = '';
- var bulk_update_url = $("#quick_edit_input_dialog_bulk_update_url").val();
- if (additional_index === null) {
- bulk_update_html_id = '#context_edit_update_link_' + target_name;
- bulk_update_url += encodeURI('&issue['+target_name+']='+new_value);
- } else {
- bulk_update_html_id = '#context_edit_update_link_' + target_name + '_'+additional_index+'_';
- bulk_update_url += encodeURI('&issue['+target_name+']['+additional_index+']='+new_value);
- }
-
- jQuery(bulk_update_html_id)
- .attr('href',bulk_update_url)
- .click();
+ $("#quick_edit_input_dialog > form").submit();
}
function quick_edit_show_new_relation_dialog(first_issue_id, second_issue_id, back_url){
<% include_calendar_headers_tags %>
+<% heads_for_wiki_formatter %>
back_url = @back
end
- bulk_update_url = bulk_update_issues_path(:ids => @issue_ids, :back_url => back_url);
%>
<li class="folder">
<a href="#" class="submenu"><%= l(:button_quick_edit) %></a>
<ul>
- <%= quick_edit_link_to(bulk_update_url, @issue_ids, l(:field_subject), :subject, :string, first_issue.subject, !@can[:update]) %>
- <%= quick_edit_link_to(bulk_update_url, @issue_ids, l(:field_parent_issue), :parent_issue_id, :int, first_issue.parent_id, !@can[:update]) %>
-
-
+ <%= quick_edit_link_to(@issue_ids, get_attribute_caption(:subject), :subject, nil, back_url, !@can[:update]) %>
+ <%= quick_edit_link_to(@issue_ids, get_attribute_caption(:parent_issue_id), :parent_issue_id, nil, back_url, !@can[:update]) %>
<% unless @issues.any? {|issue| issue.disabled_core_fields.include?('start_date') } %>
- <%= quick_edit_link_to(bulk_update_url, @issue_ids, l(:field_start_date), :start_date, :date, first_issue.start_date, !@can[:update]) %>
+ <%= quick_edit_link_to(@issue_ids, get_attribute_caption(:start_date), :start_date, nil, back_url, !@can[:update]) %>
<% end %>
<% unless @issues.any? {|issue| issue.disabled_core_fields.include?('due_date') } %>
- <%= quick_edit_link_to(bulk_update_url, @issue_ids, l(:field_due_date), :due_date, :date, first_issue.due_date, !@can[:update]) %>
+ <%= quick_edit_link_to(@issue_ids, get_attribute_caption(:due_date), :due_date, nil, back_url, !@can[:update]) %>
<% end %>
<% custom_fields.each do |f| %>
- <%= quick_edit_link_to(bulk_update_url, @issue_ids, f.name, 'custom_field_values[%d]' % f.id, f.field_format, first_issue.editable_custom_field_values.detect {|v| v.custom_field_id == f.id}, !@can[:update]) %>
+ <%= quick_edit_link_to(@issue_ids, f.name, 'custom_field_values', f.id, back_url, !@can[:update]) %>
<% end %>
<% if @issues.size <= 2 %>
--- /dev/null
+<div id="quick_edit_input_dialog" title="Quick Edit - <%= @dialog_params[:caption] %>">
+ <p><%= @dialog_params[:help_message] %></p>
+ <%= form_tag({:controller=>'issues', :action=>:bulk_update}) do %>
+ <% case @dialog_params[:field_type] %>
+ <% when "date" %>
+ <input id="new_value"
+ name="<%= @dialog_params[:target_specifier] %>"
+ type="text"
+ size="40"
+ style="vertical-align:middle;"
+ value="<%= @dialog_params[:default_value] %>"></input>
+ <%= calendar_for('new_value') %>
+ <% else %>
+ <input id="new_value"
+ name="<%= @dialog_params[:target_specifier] %>"
+ type="text"
+ size="40"
+ style="vertical-align:middle;"
+ value="<%= @dialog_params[:default_value] %>"></input>
+ <% end %>
+ <% @dialog_params[:issue_ids].each do |id| %>
+ <input id="ids" name="ids[]" type="hidden" value="<%= id %>"></input>
+ <% end %>
+ <input id="back_url" name="back_url" type="hidden" value="<%= @dialog_params[:back_url] %>"></input>
+ <input id="validation_pattern" type="hidden" value="<%= @dialog_params[:validation_pattern] %>"></input>
+ <% end %>
+</div>
+
+<script>
+//<![CDATA[
+ var height = 210;
+ $("#quick_edit_input_dialog").dialog({
+ modal: true,
+ closeOnEscape: false,
+ width: 600,
+ height: height,
+ buttons: {
+ "Ok" : quick_edit_input_dialog_ok,
+ "Cancel" : quick_edit_input_dialog_cancel
+ },
+ close: quick_edit_input_dialog_close
+ });
+//]]>
+</script>
--- /dev/null
+$("#quick_edit_input_dialogs").html(
+ "<%= escape_javascript(render :partial => 'input_dialog', :layout => false ) %>"
+);
resources :quick_edit_relations, :controller => 'quick_edit_relations', :only => [:create, :destroy]
end
end
+
+ get 'quick_edit_issues/edit', :controller => 'quick_edit_issues', :action => 'edit'
end