OSDN Git Service

add settings
authorAkira Saito <akrstjp@users.sourceforge.jp>
Tue, 14 Apr 2015 12:22:05 +0000 (21:22 +0900)
committerAkira Saito <akrstjp@users.sourceforge.jp>
Tue, 14 Apr 2015 12:22:05 +0000 (21:22 +0900)
app/helpers/application_helper.rb
app/views/hooks/_quick_edit_context.html.erb
app/views/quick_edit_issues/_input_dialog.html.erb
app/views/quick_edit_issues/_settings.html.erb [new file with mode: 0644]
init.rb

index 92af536..4b3e464 100644 (file)
@@ -85,5 +85,17 @@ module ApplicationHelper
         :date
      end
   end
+
+  def parse_size(size, width_range, width_default, height_range, height_default)
+     size = size.split(",")
+     size[0] = width_default if size.length != 2 || !size[0].match(/\d{1,9}/)
+     size[1] = height_default if size.length != 2 || !size[1].match(/\d{1,9}/)
+     size[0] = size[0].to_i
+     size[1] = size[1].to_i
+     size[0] = width_default unless width_range.include?(size[0])
+     size[1] = height_default unless height_range.include?(size[1])
+
+     size
+  end
 end
 
index 9512231..71ec075 100644 (file)
@@ -1,8 +1,11 @@
 <%
    extend ApplicationHelper
    extend IssueRelationsHelper
+
+   excludes = Setting.plugin_quick_edit['custom_field_exclude_names'].split(/,/).map {|v| Regexp.new(v)}
+
    custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
-     %w(string date int text link float).include?(f.field_format)
+     %w{string date int text link float}.include?(f.field_format) && ( excludes.empty? || excludes.none? {|ex| ex.match(f.name)} )
    end
 
    first_issue = @issues.first
index 010acf5..3e9ae23 100644 (file)
@@ -1,3 +1,12 @@
+<%
+  dialog_size = parse_size(Setting.plugin_quick_edit['input_dialog_base_size'], 480...2048, 480, 280...2048,280)
+  dialog_size[0] += 227 if @dialog_params[:field_type] == :text || @dialog_params[:field_type] == :string
+  dialog_size[1] += 134 if @dialog_params[:field_type] == :text
+  dialog_size[1] += 31 if @dialog_params[:attribute_name]==:description
+  dialog_size[1] += 50 unless @dialog_params[:description].nil?
+
+  textarea_size = parse_size(Setting.plugin_quick_edit['textarea_size'], 10...256, 80, 10...256, 10)
+%>
 <div id="quick_edit_input_dialog" title="Quick Edit - <%= @dialog_params[:caption] %>" style="background-color: white;">
   <%= form_tag({:controller=>'issues', :action=>:bulk_update}) do %>
   <div style="padding-top: 9px; padding-bottom: 15px; padding-left: 10px;">
@@ -5,8 +14,8 @@
     <span style="vertical-align: middle; font-size: 0.85em;">for: <% @issues.each do |issue| %><%= "\##{issue.id}" %>&nbsp;<% end %></span>
   </div>
   <div class="box" style="font-size: 0.9em; font-weight: normal; padding-left: 10px; padding-right: 10px; padding-bottom: 12px; margin-bottom:0px;">
-  <div>
-    <span><%= @dialog_params[:caption] %>:</span></div>
+  <span><%= @dialog_params[:caption] %>:</span>
+  <div style="text-align: middle;">
     <% case @dialog_params[:field_type] %>
     <% when :date %>
     <input id="new_value"
@@ -28,8 +37,8 @@
     <% when :text %>
     <textarea id="new_value"
            name="<%= @dialog_params[:target_specifier] %>"
-           cols="80"
-           rows="10"
+           cols="<%= textarea_size[0] %>"
+           rows="<%= textarea_size[1] %>"
            style="vertical-align:middle;"><%= @dialog_params[:default_value] %></textarea>
     <% if @dialog_params[:attribute_name].to_sym == :description %>
     <%= wikitoolbar_for 'new_value' %>
 <script>
 //<![CDATA[
   $(".ui-autocomplete").css("z-index",200);
-  var width = <%= (@dialog_params[:field_type] == :int || @dialog_params[:field_type] == :date) ? 480 : 707 %>;
-  var height = <%= ((@dialog_params[:field_type] == :text) ? 414 : 280) + ((@dialog_params[:description].nil?) ? 0 : 50) + ((@dialog_params[:attribute_name]==:description)?31:0)%>;
   $("#quick_edit_input_dialog").dialog({
      modal: true,
      closeOnEscape: false,
-     width: width,
-     height: height,
+     width: <%= dialog_size[0] %>,
+     height: <%= dialog_size[1] %>,
      buttons: {
         "Submit" : quick_edit_input_dialog_submit,
         "Cancel" : quick_edit_input_dialog_cancel
@@ -74,6 +81,6 @@
      close: quick_edit_input_dialog_close
   });
 
-  quick_edit_log("input_dialog open.");
+  quick_edit_log("input_dialog open. size=<%=dialog_size[0]%>,<%=dialog_size[1]%>");
 //]]>
 </script>
diff --git a/app/views/quick_edit_issues/_settings.html.erb b/app/views/quick_edit_issues/_settings.html.erb
new file mode 100644 (file)
index 0000000..c7c859e
--- /dev/null
@@ -0,0 +1,26 @@
+<table>
+       <tr>
+               <th>Dialog base size:</th>
+    <td>
+    <input type="text" id="settings_input_dialog_base_size" name="settings[input_dialog_base_size]" value="<%= settings['input_dialog_base_size'] %>"></input>
+    </td>
+    <td>
+    </td>
+       </tr>
+       <tr>
+               <th>Textarea size:</th>
+    <td>
+    <input type="text" id="settings_textarea_size" name="settings[textarea_size]" value="<%= settings['textarea_size'] %>"></input>
+    </td>
+    <td>
+    </td>
+       </tr>
+       <tr>
+               <th>Pattern of name for exclude custom fields:</th>
+    <td>
+    <input type="text" id="settings_custom_field_exclude_names" name="settings[custom_field_exclude_names]" value="<%= settings['custom_field_exclude_names'] %>"></input>
+    </td>
+    <td>
+    </td>
+       </tr>
+</table>
diff --git a/init.rb b/init.rb
index 47a2309..8ec94e4 100644 (file)
--- a/init.rb
+++ b/init.rb
@@ -6,7 +6,7 @@ require_dependency File.expand_path('../hooks', __FILE__)
 
 # plugin name depends to plugin directory
 plugin_name = File.dirname(File.expand_path(__FILE__))
-plugin_name = File.basename(plugin_name)
+plugin_name = File.basename(plugin_name).to_sym
 
 Redmine::Plugin.register plugin_name do
   name 'Quick Edit plugin'
@@ -15,4 +15,9 @@ Redmine::Plugin.register plugin_name do
   version '0.0.7.1'
 
   permission :manage_quick_edit_relations, {:quick_edit_relations => [:create, :destroy]}, :public => true
+
+  settings :default => {'custom_field_exclude_names'=>'',
+                        'textarea_size'=>'80,10',
+                        'input_dialog_base_size'=>'480,280'},
+           :partial => 'quick_edit_issues/settings'
 end