| 70 | 70 |  | 
  | 71 | 71 |         @subjects = '' | 
  | 72 | 72 |         @lines = '' | 
  |  | 73 |         @calendars = '' | 
  | 73 | 74 |         @number_of_rows = nil | 
  | 74 | 75 |  | 
  | 75 | 76 |         @issue_ancestors = [] | 
  | ... | ... |  | 
  | 129 | 130 |         @lines | 
  | 130 | 131 |       end | 
  | 131 | 132 |  | 
  |  | 133 |       # Renders the calendars of the Gantt chart, the right side | 
  |  | 134 |       def calendars(options={}) | 
  |  | 135 |         render(options.merge(:only => :calendars)) unless @calendars_rendered | 
  |  | 136 |         @calendars | 
  |  | 137 |       end | 
  |  | 138 |  | 
  | 132 | 139 |       # Returns issues that will be rendered | 
  | 133 | 140 |       def issues | 
  | 134 | 141 |         @issues ||= @query.issues( | 
  | ... | ... |  | 
  | 175 | 182 |         options = {:top => 0, :top_increment => 20, :indent_increment => 20, :render => :subject, :format => :html}.merge(options) | 
  | 176 | 183 |         indent = options[:indent] || 4 | 
  | 177 | 184 |  | 
  | 178 |  |         @subjects = '' unless options[:only] == :lines | 
  | 179 |  |         @lines = '' unless options[:only] == :subjects | 
  |  | 185 |         if options[:format] == :html | 
  |  | 186 |           @subjects = '' unless options[:only] == :lines && options[:only] == :calendars | 
  |  | 187 |           @lines = '' unless options[:only] == :subjects && options[:only] == :calendars | 
  |  | 188 |           @calendars = '' unless options[:only] == :lines && options[:only] == :subjects | 
  |  | 189 |         else | 
  |  | 190 |           @subjects = '' unless options[:only] == :lines | 
  |  | 191 |           @lines = '' unless options[:only] == :subjects | 
  |  | 192 |         end | 
  |  | 193 |  | 
  | 180 | 194 |         @number_of_rows = 0 | 
  | 181 | 195 |  | 
  | 182 | 196 |         Project.project_tree(projects) do |project, level| | 
  | ... | ... |  | 
  | 185 | 199 |           break if abort? | 
  | 186 | 200 |         end | 
  | 187 | 201 |  | 
  | 188 |  |         @subjects_rendered = true unless options[:only] == :lines | 
  | 189 |  |         @lines_rendered = true unless options[:only] == :subjects | 
  |  | 202 |         #pstart | 
  |  | 203 |         if options[:format] == :html | 
  |  | 204 |           @subjects_rendered = true unless options[:only] == :lines && options[:only] == :calendars | 
  |  | 205 |           @lines_rendered = true unless options[:only] == :subjects && options[:only] == :calendars | 
  |  | 206 |           @calendars_rendered = true unless options[:only] == :lines && options[:only] == :subjects | 
  |  | 207 |         else | 
  |  | 208 |           @subjects_rendered = true unless options[:only] == :lines | 
  |  | 209 |           @lines_rendered = true unless options[:only] == :subjects | 
  |  | 210 |         end | 
  |  | 211 |         #pend | 
  | 190 | 212 |  | 
  | 191 | 213 |         render_end(options) | 
  | 192 | 214 |       end | 
  | 193 | 215 |  | 
  | 194 | 216 |       def render_project(project, options={}) | 
  | 195 |  |         subject_for_project(project, options) unless options[:only] == :lines | 
  | 196 |  |         line_for_project(project, options) unless options[:only] == :subjects | 
  |  | 217 |  | 
  |  | 218 |         #pstart | 
  |  | 219 |         if options[:format] == :html | 
  |  | 220 |           subject_for_project(project, options) unless options[:only] == :lines && options[:only] == :calendars | 
  |  | 221 |           line_for_project(project, options) unless options[:only] == :subjects && options[:only] == :calendars | 
  |  | 222 |           calendar_for_project(project, options) unless options[:only] == :lines && options[:only] == :subjects | 
  |  | 223 |         else | 
  |  | 224 |           subject_for_project(project, options) unless options[:only] == :lines | 
  |  | 225 |           line_for_project(project, options) unless options[:only] == :subjects | 
  |  | 226 |         end | 
  |  | 227 |         #pend | 
  | 197 | 228 |  | 
  | 198 | 229 |         options[:top] += options[:top_increment] | 
  | 199 | 230 |         options[:indent] += options[:indent_increment] | 
  | ... | ... |  | 
  | 220 | 251 |         @issue_ancestors = [] | 
  | 221 | 252 |  | 
  | 222 | 253 |         issues.each do |i| | 
  | 223 |  |           subject_for_issue(i, options) unless options[:only] == :lines | 
  | 224 |  |           line_for_issue(i, options) unless options[:only] == :subjects | 
  |  | 254 |  | 
  |  | 255 |           #pstart | 
  |  | 256 |           if options[:format] == :html | 
  |  | 257 |             subject_for_issue(i, options) unless options[:only] == :lines && options[:only] == :calendars | 
  |  | 258 |             line_for_issue(i, options) unless options[:only] == :subjects && options[:only] == :calendars | 
  |  | 259 |             calendar_for_issue(i, options) unless options[:only] == :lines && options[:only] == :subjects | 
  |  | 260 |           else | 
  |  | 261 |             subject_for_issue(i, options) unless options[:only] == :lines | 
  |  | 262 |             line_for_issue(i, options) unless options[:only] == :subjects | 
  |  | 263 |           end | 
  |  | 264 |           #pend | 
  | 225 | 265 |  | 
  | 226 | 266 |           options[:top] += options[:top_increment] | 
  | 227 | 267 |           @number_of_rows += 1 | 
  | ... | ... |  | 
  | 233 | 273 |  | 
  | 234 | 274 |       def render_version(project, version, options={}) | 
  | 235 | 275 |         # Version header | 
  | 236 |  |         subject_for_version(version, options) unless options[:only] == :lines | 
  | 237 |  |         line_for_version(version, options) unless options[:only] == :subjects | 
  |  | 276 |  | 
  |  | 277 |           #pstart | 
  |  | 278 |           if options[:format] == :html | 
  |  | 279 |             subject_for_version(version, options) unless options[:only] == :lines && options[:only] == :calendars | 
  |  | 280 |             line_for_version(version, options) unless options[:only] == :subjects && options[:only] == :calendars | 
  |  | 281 |             calendar_for_version(version, options) unless options[:only] == :lines && options[:only] == :subjects | 
  |  | 282 |           else | 
  |  | 283 |             subject_for_version(version, options) unless options[:only] == :lines | 
  |  | 284 |             line_for_version(version, options) unless options[:only] == :subjects | 
  |  | 285 |           end | 
  |  | 286 |           #pend | 
  | 238 | 287 |  | 
  | 239 | 288 |         options[:top] += options[:top_increment] | 
  | 240 | 289 |         @number_of_rows += 1 | 
  | ... | ... |  | 
  | 283 | 332 |  | 
  | 284 | 333 |           case options[:format] | 
  | 285 | 334 |           when :html | 
  | 286 |  |             html_task(options, coords, :css => "project task", :label => label, :markers => true) | 
  |  | 335 |  | 
  |  | 336 |             #pstart | 
  |  | 337 |             html_task(options, coords, :css => "project task", :label => label, :markers => true, :id => project.id, :kind => "p") | 
  |  | 338 |             #pend | 
  |  | 339 |  | 
  | 287 | 340 |           when :image | 
  | 288 | 341 |             image_task(options, coords, :label => label, :markers => true, :height => 3) | 
  | 289 | 342 |           when :pdf | 
  | ... | ... |  | 
  | 322 | 375 |  | 
  | 323 | 376 |           case options[:format] | 
  | 324 | 377 |           when :html | 
  | 325 |  |             html_task(options, coords, :css => "version task", :label => label, :markers => true) | 
  |  | 378 |  | 
  |  | 379 |             #pstart | 
  |  | 380 |             html_task(options, coords, :css => "version task", :label => label, :markers => true, :id => version.id, :kind => "v") | 
  |  | 381 |             #pend | 
  |  | 382 |  | 
  | 326 | 383 |           when :image | 
  | 327 | 384 |             image_task(options, coords, :label => label, :markers => true, :height => 3) | 
  | 328 | 385 |           when :pdf | 
  | ... | ... |  | 
  | 376 | 433 |           coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) | 
  | 377 | 434 |           label = "#{ issue.status.name } #{ issue.done_ratio }%" | 
  | 378 | 435 |  | 
  |  | 436 |           #pstart | 
  |  | 437 |           if !issue.due_date && issue.fixed_version | 
  |  | 438 |             if options[:format] == :html | 
  |  | 439 |               label += "- <strong>#{h(issue.fixed_version.name)}</strong>" | 
  |  | 440 |             else | 
  |  | 441 |               label += "-#{h(issue.fixed_version.name)}" | 
  |  | 442 |             end | 
  |  | 443 |           end | 
  |  | 444 |           #pend | 
  |  | 445 |  | 
  | 379 | 446 |           case options[:format] | 
  | 380 | 447 |           when :html | 
  | 381 |  |             html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?) | 
  |  | 448 |  | 
  |  | 449 |             #pstart | 
  |  | 450 |             html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?, :id => issue.id, :kind => "i") | 
  |  | 451 |             #pend | 
  |  | 452 |  | 
  | 382 | 453 |           when :image | 
  | 383 | 454 |             image_task(options, coords, :label => label) | 
  | 384 | 455 |           when :pdf | 
  | ... | ... |  | 
  | 618 | 689 |         pdf.Output | 
  | 619 | 690 |       end | 
  | 620 | 691 |  | 
  |  | 692 |       #pstart | 
  |  | 693 |       def edit(pms) | 
  |  | 694 |         id = pms[:id] | 
  |  | 695 |         kind = id.slice!(0).chr | 
  |  | 696 |         begin | 
  |  | 697 |           case kind | 
  |  | 698 |           when 'i' | 
  |  | 699 |             @issue = Issue.find(pms[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) | 
  |  | 700 |           when 'p' | 
  |  | 701 |             @issue = Project.find(pms[:id]) | 
  |  | 702 |           when 'v' | 
  |  | 703 |             @issue = Version.find(pms[:id], :include => [:project]) | 
  |  | 704 |           end | 
  |  | 705 |         rescue ActiveRecord::RecordNotFound | 
  |  | 706 |           return "issue not found : #{pms[:id]}", 400 | 
  |  | 707 |         end | 
  |  | 708 |  | 
  |  | 709 |         if !@issue.start_date || !@issue.due_before | 
  |  | 710 |           #render :text=>l(:notice_locking_conflict), :status=>400 | 
  |  | 711 |           return l(:notice_locking_conflict), 400 | 
  |  | 712 |         end | 
  |  | 713 |         @issue.init_journal(User.current) | 
  |  | 714 |         date_from = Date.parse(pms[:date_from]) | 
  |  | 715 |         old_start_date = @issue.start_date | 
  |  | 716 |         o = get_issue_position(@issue, pms[:zoom]) | 
  |  | 717 |         text_for_revert = "#{kind}#{id}=#{format_date(@issue.start_date)},#{@issue.start_date},#{format_date(@issue.due_before)},#{@issue.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}" | 
  |  | 718 |  | 
  |  | 719 |         if pms[:day] | 
  |  | 720 |           #bar moved | 
  |  | 721 |           day = pms[:day].to_i | 
  |  | 722 |           duration = @issue.due_before - @issue.start_date | 
  |  | 723 |           @issue.start_date = date_from + day | 
  |  | 724 |           @issue.due_date = @issue.start_date + duration.to_i if @issue.due_date | 
  |  | 725 |         elsif pms[:start_date] | 
  |  | 726 |           #start date changed | 
  |  | 727 |           start_date = Date.parse(pms[:start_date]) | 
  |  | 728 |           if @issue.start_date == start_date | 
  |  | 729 |             #render :text=>"" | 
  |  | 730 |             return "", 200 #nothing has changed | 
  |  | 731 |           end | 
  |  | 732 |           @issue.start_date = start_date | 
  |  | 733 |           @issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date | 
  |  | 734 |         elsif pms[:due_date] | 
  |  | 735 |           #due date changed | 
  |  | 736 |           due_date = Date.parse(pms[:due_date]) | 
  |  | 737 |           if @issue.due_date == due_date | 
  |  | 738 |             #render :text=>"" | 
  |  | 739 |             return "", 200 #nothing has changed | 
  |  | 740 |           end | 
  |  | 741 |           @issue.due_date = due_date | 
  |  | 742 |           @issue.start_date = due_date if due_date < @issue.start_date | 
  |  | 743 |         end | 
  |  | 744 |         fv = @issue.fixed_version | 
  |  | 745 |         if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date | 
  |  | 746 |           @issue.start_date = old_start_date | 
  |  | 747 |         end | 
  |  | 748 |  | 
  |  | 749 |         begin | 
  |  | 750 |           @issue.save! | 
  |  | 751 |           o = get_issue_position(@issue, pms[:zoom]) | 
  |  | 752 |           text = "#{kind}#{id}=#{format_date(@issue.start_date)},#{@issue.start_date},#{format_date(@issue.due_before)},#{@issue.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}" | 
  |  | 753 |  | 
  |  | 754 |           prj_map = {} | 
  |  | 755 |           text = set_project_data(@issue.project, pms[:zoom], text, prj_map) | 
  |  | 756 |           version_map = {} | 
  |  | 757 |           text = set_version_data(@issue.fixed_version, pms[:zoom], text, version_map) | 
  |  | 758 |  | 
  |  | 759 |           #check dependencies | 
  |  | 760 |           issues = @issue.all_precedes_issues | 
  |  | 761 |           issues.each do |i| | 
  |  | 762 |             o = get_issue_position(i, pms[:zoom]) | 
  |  | 763 |             text += "|i#{i.id}=#{format_date(i.start_date)},#{i.start_date},#{format_date(i.due_before)},#{i.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}" | 
  |  | 764 |             text = set_project_data(i.project, pms[:zoom], text, prj_map) | 
  |  | 765 |             text = set_version_data(i.fixed_version, pms[:zoom], text, version_map) | 
  |  | 766 |           end | 
  |  | 767 |  | 
  |  | 768 |           #check parent | 
  |  | 769 |           is = @issue | 
  |  | 770 |           while | 
  |  | 771 |             pid = is.parent_issue_id | 
  |  | 772 |             break if !pid | 
  |  | 773 |             i = Issue.find(pid) | 
  |  | 774 |             o = get_issue_position(i, pms[:zoom]) | 
  |  | 775 |             text += "|i#{i.id}=#{format_date(i.start_date)},#{i.start_date},#{format_date(i.due_before)},#{i.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}" | 
  |  | 776 |             text = set_project_data(i.project, pms[:zoom], text, prj_map) | 
  |  | 777 |             text = set_version_data(i.fixed_version, pms[:zoom], text, version_map) | 
  |  | 778 |             is = i | 
  |  | 779 |           end | 
  |  | 780 |           #render :text=>text | 
  |  | 781 |           return text, 200 | 
  |  | 782 |         rescue => e | 
  |  | 783 |           #render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert  , :status=>400 | 
  |  | 784 |           if @issue.errors.full_messages.to_s == "" | 
  |  | 785 |             return e.to_s + "\n" + [$!,$@.join("\n")].join("\n") + "\n" + @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400 | 
  |  | 786 |           else | 
  |  | 787 |             return @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400 | 
  |  | 788 |           end | 
  |  | 789 |         end | 
  |  | 790 |       end | 
  |  | 791 |       #pend | 
  |  | 792 |  | 
  | 621 | 793 |       private | 
  | 622 | 794 |  | 
  | 623 | 795 |       def coordinates(start_date, end_date, progress, zoom=nil) | 
  | ... | ... |  | 
  | 737 | 909 |         output = '' | 
  | 738 | 910 |         # Renders the task bar, with progress and late | 
  | 739 | 911 |         if coords[:bar_start] && coords[:bar_end] | 
  | 740 |  |           output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'> </div>".html_safe | 
  |  | 912 |           #pstart | 
  |  | 913 |           i_width = coords[:bar_end] - coords[:bar_start] - 2 | 
  |  | 914 |           output << "<div id='ev_#{options[:kind]}#{options[:id]}' style='position:absolute;left:#{coords[:bar_start]}px;top:#{params[:top]}px;padding-top:3px;height:18px;width:#{ i_width + 100}px;' #{options[:kind] == 'i' ? "class='handle'" : ""}>".html_safe | 
  |  | 915 |           output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ i_width}px;' class='#{options[:css]} task_todo'> </div>".html_safe | 
  |  | 916 |           #pend | 
  | 741 | 917 |  | 
  | 742 | 918 |           if coords[:bar_late_end] | 
  | 743 |  |             output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'> </div>".html_safe | 
  |  | 919 |             #pstart | 
  |  | 920 |             l_width = coords[:bar_late_end] - coords[:bar_start] - 2 | 
  |  | 921 |             output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ l_width}px;' class='#{ l_width == 0 ? options[:css] + " task_none" : options[:css] + " task_late"}'> </div>".html_safe | 
  |  | 922 |           else | 
  |  | 923 |             output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe | 
  |  | 924 |             #pend | 
  | 744 | 925 |           end | 
  | 745 | 926 |           if coords[:bar_progress_end] | 
  | 746 |  |             output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'> </div>".html_safe | 
  |  | 927 |             #pstart | 
  |  | 928 |             d_width = coords[:bar_progress_end] - coords[:bar_start] - 2 | 
  |  | 929 |             output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ d_width}px;' class='#{ d_width == 0 ? options[:css] + " task_none" : options[:css] + " task_done"}'> </div>".html_safe | 
  |  | 930 |           else | 
  |  | 931 |             output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe | 
  |  | 932 |             #pend | 
  | 747 | 933 |           end | 
  |  | 934 |           #pstart | 
  |  | 935 |           output << "</div>".html_safe | 
  |  | 936 |         else | 
  |  | 937 |           output << "<div id='ev_#{options[:kind]}#{options[:id]}' style='position:absolute;left:0px;top:#{params[:top]}px;padding-top:3px;height:18px;width:0px;' #{options[:kind] == 'i' ? "class='handle'" : ""}>".html_safe | 
  |  | 938 |           output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css]} task_todo'> </div>".html_safe | 
  |  | 939 |           output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe | 
  |  | 940 |           output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe | 
  |  | 941 |           output << "</div>".html_safe | 
  |  | 942 |         #pend | 
  | 748 | 943 |         end | 
  | 749 | 944 |         # Renders the markers | 
  | 750 | 945 |         if options[:markers] | 
  | 751 | 946 |           if coords[:start] | 
  | 752 |  |             output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>".html_safe | 
  |  | 947 |             #pstart | 
  |  | 948 |             output << "<div id='marker_start_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>".html_safe | 
  |  | 949 |             #pend | 
  | 753 | 950 |           end | 
  | 754 | 951 |           if coords[:end] | 
  | 755 |  |             output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'> </div>".html_safe | 
  |  | 952 |             #pstart | 
  |  | 953 |             output << "<div id='marker_end_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'> </div>".html_safe | 
  |  | 954 |             #pend | 
  | 756 | 955 |           end | 
  |  | 956 |         #pstart | 
  |  | 957 |         else | 
  |  | 958 |           output << view.draggable_element("ev_#{options[:kind]}#{options[:id]}", :revert =>false, :scroll=>"'gantt-container'", :constraint => "'horizontal'", :snap=>params[:zoom],:onEnd=>'function( draggable, event )  {issue_moved(draggable.element);}')         #pend | 
  | 757 | 959 |         end | 
  | 758 | 960 |         # Renders the label on the right | 
  | 759 | 961 |         if options[:label] | 
  | 760 |  |           output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe | 
  |  | 962 |           #psrat | 
  |  | 963 |           output << "<div id='label_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe | 
  |  | 964 |           #pend | 
  | 761 | 965 |           output << options[:label] | 
  | 762 | 966 |           output << "</div>".html_safe | 
  | 763 | 967 |         end | 
  | 764 | 968 |         # Renders the tooltip | 
  | 765 | 969 |         if options[:issue] && coords[:bar_start] && coords[:bar_end] | 
  | 766 |  |           output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>".html_safe | 
  |  | 970 |           #pstart | 
  |  | 971 |           output << "<div id='tt_#{options[:kind]}#{options[:id]}' class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>".html_safe | 
  |  | 972 |           #pend | 
  | 767 | 973 |           output << '<span class="tip">'.html_safe | 
  | 768 | 974 |           output << view.render_issue_tooltip(options[:issue]).html_safe | 
  | 769 | 975 |           output << "</span></div>".html_safe | 
  | ... | ... |  | 
  | 855 | 1061 |           params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label]) | 
  | 856 | 1062 |         end | 
  | 857 | 1063 |       end | 
  |  | 1064 |  | 
  |  | 1065 |       #pstart | 
  |  | 1066 |       ## | 
  |  | 1067 |       ##  for edit gantt | 
  |  | 1068 |       ## | 
  |  | 1069 |       def set_project_data(prj, zoom, text, prj_map = {}) | 
  |  | 1070 |         if !prj | 
  |  | 1071 |           return text | 
  |  | 1072 |         end | 
  |  | 1073 |         if !prj_map[prj.id] | 
  |  | 1074 |           o = get_project_position(prj, zoom) | 
  |  | 1075 |           text += "|p#{prj.id}=#{format_date(prj.start_date)},#{prj.start_date},#{format_date(prj.due_date)},#{prj.due_date},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}" | 
  |  | 1076 |           prj_map[prj.id] = prj | 
  |  | 1077 |         end | 
  |  | 1078 |         text = set_project_data(prj.parent, zoom, text, prj_map) | 
  |  | 1079 |       end | 
  |  | 1080 |  | 
  |  | 1081 |       def set_version_data(version, zoom, text, version_map = {}) | 
  |  | 1082 |         if !version | 
  |  | 1083 |           return text | 
  |  | 1084 |         end | 
  |  | 1085 |         if !version_map[version.id] | 
  |  | 1086 |           o = get_version_position(version, zoom) | 
  |  | 1087 |           text += "|v#{version.id}=#{format_date(version.start_date)},#{version.start_date},#{format_date(version.due_date)},#{version.due_date},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}" | 
  |  | 1088 |           version_map[version.id] = version | 
  |  | 1089 |         end | 
  |  | 1090 |         return text | 
  |  | 1091 |       end | 
  |  | 1092 |  | 
  |  | 1093 |       def get_pos(coords) | 
  |  | 1094 |         i_left = 0 | 
  |  | 1095 |         i_width = 0 | 
  |  | 1096 |         l_width = 0 | 
  |  | 1097 |         d_width = 0 | 
  |  | 1098 |         if coords[:bar_start] | 
  |  | 1099 |           i_left = coords[:bar_start] | 
  |  | 1100 |           if coords[:bar_end] | 
  |  | 1101 |             i_width = coords[:bar_end] - coords[:bar_start] - 2 | 
  |  | 1102 |             i_width = 0 if i_width < 0 | 
  |  | 1103 |           end | 
  |  | 1104 |           if coords[:bar_late_end] | 
  |  | 1105 |             l_width = coords[:bar_late_end] - coords[:bar_start] - 2 | 
  |  | 1106 |           end | 
  |  | 1107 |           if coords[:bar_progress_end] | 
  |  | 1108 |             d_width = coords[:bar_progress_end] - coords[:bar_start] - 2 | 
  |  | 1109 |           end | 
  |  | 1110 |         end | 
  |  | 1111 |         return i_left, i_width, l_width, d_width | 
  |  | 1112 |       end | 
  |  | 1113 |  | 
  |  | 1114 |       def get_issue_position(issue, zoom_str) | 
  |  | 1115 |         z = zoom_str.to_i | 
  |  | 1116 |         zoom = 1 | 
  |  | 1117 |         z.times { zoom = zoom * 2} | 
  |  | 1118 |         id = issue.due_before | 
  |  | 1119 |         if id && @date_to < id | 
  |  | 1120 |           id = @date_to | 
  |  | 1121 |         end | 
  |  | 1122 |         coords = coordinates(issue.start_date, id, issue.done_ratio, zoom) | 
  |  | 1123 |  | 
  |  | 1124 |         i_left, i_width, l_width, d_width = get_pos(coords) | 
  |  | 1125 |         if coords[:end] | 
  |  | 1126 |           return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom | 
  |  | 1127 |         else | 
  |  | 1128 |           return i_left, i_width, l_width, d_width, coords[:start], nil | 
  |  | 1129 |         end | 
  |  | 1130 |       end | 
  |  | 1131 |  | 
  |  | 1132 |       def get_project_position(project, zoom_str) | 
  |  | 1133 |         z = zoom_str.to_i | 
  |  | 1134 |         zoom = 1 | 
  |  | 1135 |         z.times { zoom = zoom * 2} | 
  |  | 1136 |         pd = project.due_date | 
  |  | 1137 |         if pd && @date_to < pd | 
  |  | 1138 |           pd = @date_to | 
  |  | 1139 |         end | 
  |  | 1140 |         coords = coordinates(project.start_date, pd, nil, zoom) | 
  |  | 1141 |         i_left, i_width, l_width, d_width = get_pos(coords) | 
  |  | 1142 |         if coords[:end] | 
  |  | 1143 |           return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom | 
  |  | 1144 |         else | 
  |  | 1145 |           return i_left, i_width, l_width, d_width, coords[:start], nil | 
  |  | 1146 |         end | 
  |  | 1147 |       end | 
  |  | 1148 |  | 
  |  | 1149 |       def get_version_position(version, zoom_str) | 
  |  | 1150 |         z = zoom_str.to_i | 
  |  | 1151 |         zoom = 1 | 
  |  | 1152 |         z.times { zoom = zoom * 2} | 
  |  | 1153 |         vd = version.due_date | 
  |  | 1154 |         if vd &&  @date_to < vd | 
  |  | 1155 |           vd = @date_to | 
  |  | 1156 |         end | 
  |  | 1157 |         coords = coordinates(version.start_date, vd, version.completed_pourcent, zoom) | 
  |  | 1158 |         i_left, i_width, l_width, d_width = get_pos(coords) | 
  |  | 1159 |         if coords[:end] | 
  |  | 1160 |           return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom | 
  |  | 1161 |         else | 
  |  | 1162 |           return i_left, i_width, l_width, d_width, coords[:start], nil | 
  |  | 1163 |         end | 
  |  | 1164 |       end | 
  |  | 1165 |  | 
  |  | 1166 |       def calendar_for_issue(issue, options) | 
  |  | 1167 |         # Skip issues that don't have a due_before (due_date or version's due_date) | 
  |  | 1168 |         if issue.is_a?(Issue) && issue.due_before | 
  |  | 1169 |  | 
  |  | 1170 |           case options[:format] | 
  |  | 1171 |           when :html | 
  |  | 1172 |             @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>" | 
  |  | 1173 |             start_date = issue.start_date | 
  |  | 1174 |             if start_date | 
  |  | 1175 |               @calendars << "<span id='i#{issue.id}_start_date_str'>" | 
  |  | 1176 |               @calendars << format_date(start_date) | 
  |  | 1177 |               @calendars << "</span>" | 
  |  | 1178 |               @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_start_date' value='#{start_date}' />" | 
  |  | 1179 |               if issue.leaf? | 
  |  | 1180 |                 @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />#{view.g_calendar_for('i' + issue.id.to_s + '_start_date')}" | 
  |  | 1181 |               else | 
  |  | 1182 |                 @calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />   " | 
  |  | 1183 |               end | 
  |  | 1184 |               @calendars << observe_date_field("i#{issue.id}", 'start') | 
  |  | 1185 |             end | 
  |  | 1186 |             due_date = issue.due_date | 
  |  | 1187 |             if due_date | 
  |  | 1188 |               @calendars << "<span id='i#{issue.id}_due_date_str'>" | 
  |  | 1189 |               @calendars << format_date(due_date) | 
  |  | 1190 |               @calendars << "</span>" | 
  |  | 1191 |               @calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{due_date}' />" | 
  |  | 1192 |               if issue.leaf? | 
  |  | 1193 |                 @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />#{view.g_calendar_for('i' + issue.id.to_s + '_due_date')}" | 
  |  | 1194 |               else | 
  |  | 1195 |                 @calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />" | 
  |  | 1196 |               end | 
  |  | 1197 |               @calendars << observe_date_field("i#{issue.id}", 'due') | 
  |  | 1198 |             end | 
  |  | 1199 |             @calendars << "</div>" | 
  |  | 1200 |           when :image | 
  |  | 1201 |             #nop | 
  |  | 1202 |           when :pdf | 
  |  | 1203 |             #nop | 
  |  | 1204 |           end | 
  |  | 1205 |         else | 
  |  | 1206 |           ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" | 
  |  | 1207 |           '' | 
  |  | 1208 |         end | 
  |  | 1209 |       end | 
  |  | 1210 |  | 
  |  | 1211 |       def calendar_for_version(version, options) | 
  |  | 1212 |         # Skip version that don't have a due_before (due_date or version's due_date) | 
  |  | 1213 |         if version.is_a?(Version) && version.start_date && version.due_date | 
  |  | 1214 |  | 
  |  | 1215 |           case options[:format] | 
  |  | 1216 |           when :html | 
  |  | 1217 |             @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>" | 
  |  | 1218 |             @calendars << "<span id='v#{version.id}_start_date_str'>" | 
  |  | 1219 |             @calendars << format_date(version.effective_date) | 
  |  | 1220 |             @calendars << "</span>" | 
  |  | 1221 |             @calendars << "</div>" | 
  |  | 1222 |           when :image | 
  |  | 1223 |             #nop | 
  |  | 1224 |           when :pdf | 
  |  | 1225 |             #nop | 
  |  | 1226 |           end | 
  |  | 1227 |         else | 
  |  | 1228 |           ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" | 
  |  | 1229 |           '' | 
  |  | 1230 |         end | 
  |  | 1231 |       end | 
  |  | 1232 |  | 
  |  | 1233 |       def calendar_for_project(project, options) | 
  |  | 1234 |         case options[:format] | 
  |  | 1235 |         when :html | 
  |  | 1236 |           @calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>" | 
  |  | 1237 |           @calendars << "<span id='p#{project.id}_start_date_str'>" | 
  |  | 1238 |           @calendars << format_date(project.start_date) if project.start_date | 
  |  | 1239 |           @calendars << "</span>" | 
  |  | 1240 |           @calendars << "   " | 
  |  | 1241 |           @calendars << "<span id='p#{project.id}_due_date_str'>" | 
  |  | 1242 |           @calendars << format_date(project.due_date) if project.due_date | 
  |  | 1243 |           @calendars << "</span>" | 
  |  | 1244 |           @calendars << "</div>" | 
  |  | 1245 |         when :image | 
  |  | 1246 |           # nop | 
  |  | 1247 |         when :pdf | 
  |  | 1248 |           # nop | 
  |  | 1249 |         end | 
  |  | 1250 |       end | 
  |  | 1251 |  | 
  |  | 1252 |       def observe_date_field(id, type) | 
  |  | 1253 |         output = '' | 
  |  | 1254 |         prj_id = '' | 
  |  | 1255 |         prj_id = @project.to_param if @project | 
  |  | 1256 |         output << "<script type='text/javascript'>\n" | 
  |  | 1257 |         output << "//<![CDATA[\n" | 
  |  | 1258 |         output << "new Form.Element.Observer('#{id}_#{type}_date', 0.25,\n" | 
  |  | 1259 |         output << "  function(element, value) {\n" | 
  |  | 1260 |         output << "    if (value == document.getElementById('#{id}_hidden_#{type}_date').value) {\n" | 
  |  | 1261 |         output << "      return ;\n" | 
  |  | 1262 |         output << "    }\n" | 
  |  | 1263 |         output << "    new Ajax.Request('#{view.url_for(:controller=>:gantts, :action => :edit_gantt, :id=>id, :date_from=>self.date_from.strftime("%Y-%m-%d"), :date_to=>self.date_to.strftime("%Y-%m-%d"), :zoom=>self.zoom, :escape => false, :project_id=>prj_id)}', {asynchronous:true, evalScripts:true, onFailure:function(request){handle_failure(request.responseText)}, onSuccess:function(request){change_dates(request.responseText)}, parameters:'#{type}_date=' + encodeURIComponent(value)});" | 
  |  | 1264 |         output << "  })\n" | 
  |  | 1265 |         output << "//]]>\n" | 
  |  | 1266 |         output << "</script>" | 
  |  | 1267 |       end | 
  |  | 1268 |     #pend | 
  |  | 1269 |  | 
  | 858 | 1270 |     end | 
  | 859 | 1271 |   end | 
  | 860 | 1272 | end |