mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-12 10:24:22 +01:00
refactor sidebar and finish migration of notes
This commit is contained in:
parent
94b5aa2346
commit
ea1ca130f1
18 changed files with 138 additions and 97 deletions
|
|
@ -26,24 +26,18 @@ class NotesController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
note = current_user.notes.build
|
||||
note.attributes = params["note"]
|
||||
@note = current_user.notes.build
|
||||
@note.attributes = params["note"]
|
||||
|
||||
saved = note.save
|
||||
@saved = @note.save
|
||||
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
if note.save
|
||||
render :partial => 'notes_summary', :object => note
|
||||
else
|
||||
render :text => ''
|
||||
end
|
||||
end
|
||||
format.js
|
||||
format.xml do
|
||||
if saved
|
||||
head :created, :location => note_url(note), :text => "new note with id #{note.id}"
|
||||
if @saved
|
||||
head :created, :location => note_url(@note), :text => "new note with id #{@note.id}"
|
||||
else
|
||||
render_failure note.errors.full_messages.join(', ')
|
||||
render_failure @note.errors.full_messages.join(', ')
|
||||
end
|
||||
end
|
||||
format.html do
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ class ProjectsController < ApplicationController
|
|||
@next_project = current_user.projects.next_from(@project)
|
||||
@previous_project = current_user.projects.previous_from(@project)
|
||||
@default_tags = @project.default_tags
|
||||
@new_note = current_user.notes.build
|
||||
@new_note.project_id = @project.id
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.m &render_project_mobile
|
||||
|
|
|
|||
|
|
@ -246,4 +246,21 @@ module ApplicationHelper
|
|||
note = Sanitize.clean(note, Sanitize::Config::RELAXED)
|
||||
return note
|
||||
end
|
||||
|
||||
def sidebar_html_for_titled_list (list, title)
|
||||
return content_tag(:h3, title+" (#{list.length})") +
|
||||
content_tag(:ul, sidebar_html_for_list(list))
|
||||
end
|
||||
|
||||
def sidebar_html_for_list(list)
|
||||
if list.empty?
|
||||
return content_tag(:li, t('sidebar.list_empty'))
|
||||
else
|
||||
return list.inject("") do |html, item|
|
||||
link = (item.class == "Project") ? link_to_project( item ) : link_to_context(item)
|
||||
html << content_tag(:li, link + " (" + count_undone_todos_phrase(item,"actions")+")")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
<% submit_text ||= t('common.update') -%>
|
||||
<% form_for(note_edit_form, :html => {
|
||||
:id => dom_id(note_edit_form, 'edit_form'),
|
||||
:class => "inline-form edit-note-form",
|
||||
:method => :put }) do |f|
|
||||
:method => :post }) do |f|
|
||||
-%>
|
||||
|
||||
<div id="error_status"><%= error_messages_for("note") %></div>
|
||||
|
|
@ -13,7 +14,7 @@
|
|||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="<%= dom_id(note_edit_form, 'submit') %>" tabindex="15">
|
||||
<%=image_tag("accept.png", :alt => "") %>
|
||||
<%= t 'common.update' %>
|
||||
<%= submit_text %>
|
||||
</button>
|
||||
<a href="" class="negative" id="neg_<%=dom_id(note_edit_form, 'edit_form')%>">
|
||||
<%=image_tag("cancel.png", :alt => "") %>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
<% note = notes_summary -%>
|
||||
<div class="note_wrapper" id="<%= dom_id(note) %>">
|
||||
<%= link_to( image_tag("blank.png", :border => 0), note_path(note), :title => t('notes.show_note_title'), :class => "link_to_notes icon") %>
|
||||
<%= link_to(
|
||||
image_tag("blank.png", :border => 0),
|
||||
note_path(note),
|
||||
:title => t('notes.show_note_title'),
|
||||
:class => "link_to_notes icon",
|
||||
:id => dom_id(note, "link")) %>
|
||||
<%= rendered_note(note) %>
|
||||
</div>
|
||||
<% note = nil -%>
|
||||
|
|
|
|||
25
app/views/notes/create.js.erb
Normal file
25
app/views/notes/create.js.erb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<% if @saved -%>
|
||||
TracksForm.hide_errors();
|
||||
add_note();
|
||||
clear_form();
|
||||
<% else -%>
|
||||
TracksForm.show_errors(html_for_error_messages());
|
||||
<% end -%>
|
||||
|
||||
function add_note() {
|
||||
$('div#notes').append(html_for_note_summary());
|
||||
$('#empty-n').hide();
|
||||
}
|
||||
|
||||
function clear_form() {
|
||||
$('#new-note').hide();
|
||||
$('#edit-note-form').clearForm();
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(error_messages_for('project')) %>";
|
||||
}
|
||||
|
||||
function html_for_note_summary() {
|
||||
return "<%= @saved ? escape_javascript(render(:partial => 'notes_summary', :object => @note)) : "" %>";
|
||||
}
|
||||
|
|
@ -4,14 +4,9 @@
|
|||
replace_note_form_with_updated_note();
|
||||
|
||||
<% else -%>
|
||||
show_errors();
|
||||
TracksForm.show_errors(html_for_error_messages());
|
||||
<% end %>
|
||||
|
||||
function show_errors() {
|
||||
$('div#edit_error_status').html(html_for_error_messages());
|
||||
$('div#edit_error_status').show();
|
||||
}
|
||||
|
||||
function replace_note_form_with_updated_note() {
|
||||
$('#<%= dom_id(@note, 'edit')%>').fadeOut(250, function() {
|
||||
$('#<%= dom_id(@note, 'edit')%>').html(html_for_updated_note_form());
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<div class="container">
|
||||
<div id="notes">
|
||||
<div class="add_note_link"><%= link_to t('projects.add_note'), '#' %> </div>
|
||||
<div class="add_note_link"><%= link_to t('projects.add_note'), '#' %> </div>
|
||||
<h2>Notes</h2>
|
||||
<div id="empty-n" style="display:<%= @project.notes.empty? ? 'block' : 'none'%>;">
|
||||
<%= render :partial => "shared/empty",
|
||||
|
|
@ -22,18 +22,9 @@
|
|||
</div>
|
||||
|
||||
<div id="new-note" style="display:none;">
|
||||
<% form_remote_tag :url => notes_path,
|
||||
:method => :post,
|
||||
:update => "notes",
|
||||
:position => "bottom",
|
||||
:complete => "$('#notes').effect('highlight', 1000);$('#empty-n').hide();$('#new-note form').clearForm();",
|
||||
:html => {:id=>'form-new-note', :class => 'inline-form'} do %>
|
||||
<%= hidden_field( "note", "project_id", "value" => "#{@project.id}" ) %>
|
||||
<%= text_area( "note", "body", "cols" => 50, "rows" => 3, "tabindex" => 1 ) %>
|
||||
<br /><br />
|
||||
<input type="submit" value="<%= t('projects.add_note_submit') %>" name="add-new-note" tabindex="2" />
|
||||
<% end -%>
|
||||
<%= render :partial => "notes/note_edit_form", :object => @new_note, :locals => {:submit_text => t('projects.add_note_submit')} %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="input_box">
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
<li><%= link_to_context( context ) + " (" + count_undone_todos_phrase(context,"actions") + ")"%></li>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<h3><%= list_name %> (<%= contexts.length %>)</h3>
|
||||
<ul>
|
||||
<% if contexts.empty? -%>
|
||||
<li><%= t('sidebar.list_empty') %></li>
|
||||
<% else -%>
|
||||
<%= render :partial => "sidebar/context", :collection => contexts -%>
|
||||
<% end -%>
|
||||
</ul>
|
||||
|
|
@ -1 +0,0 @@
|
|||
<li><%= link_to_project( project ) + " (" + count_undone_todos_phrase(project,"actions") + ")" %></li>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<h3><%= list_name %> (<%= projects.length %>)</h3>
|
||||
<ul>
|
||||
<% if projects.empty? %>
|
||||
<li><%= t('sidebar.list_empty') %></li>
|
||||
<% else %>
|
||||
<%= render :partial => "sidebar/project", :collection => projects %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
|
@ -1,30 +1,13 @@
|
|||
<div id="sidebar">
|
||||
<% # show active items before hidden / completed items -%>
|
||||
|
||||
<%= render :partial => "sidebar/project_list",
|
||||
:locals => { :list_name => t('sidebar.list_name_active_projects'),
|
||||
:projects => @active_projects } -%>
|
||||
|
||||
<%= render :partial => "sidebar/context_list",
|
||||
:locals => { :list_name => t('sidebar.list_name_active_contexts'),
|
||||
:contexts => @active_contexts } -%>
|
||||
|
||||
<%= sidebar_html_for_titled_list(@active_projects, t('sidebar.list_name_active_projects'))%>
|
||||
<%= sidebar_html_for_titled_list(@active_contexts, t('sidebar.list_name_active_contexts'))%>
|
||||
<% if prefs.show_hidden_projects_in_sidebar -%>
|
||||
<%= render :partial => "sidebar/project_list",
|
||||
:locals => { :list_name => t('sidebar.list_name_hidden_projects'),
|
||||
:projects => @hidden_projects } -%>
|
||||
<%= sidebar_html_for_titled_list(@hidden_projects, t('sidebar.list_name_hidden_projects'))%>
|
||||
<% end -%>
|
||||
|
||||
<% if prefs.show_completed_projects_in_sidebar -%>
|
||||
<%= render :partial => "sidebar/project_list",
|
||||
:locals => { :list_name => t('sidebar.list_name_completed_projects'),
|
||||
:projects => @completed_projects } -%>
|
||||
<%= sidebar_html_for_titled_list(@completed_projects, t('sidebar.list_name_completed_projects'))%>
|
||||
<% end -%>
|
||||
|
||||
<% if prefs.show_hidden_contexts_in_sidebar -%>
|
||||
<%= render :partial => "sidebar/context_list",
|
||||
:locals => { :list_name => t('sidebar.list_name_hidden_contexts'),
|
||||
:contexts => @hidden_contexts } -%>
|
||||
<%= sidebar_html_for_titled_list(@hidden_contexts, t('sidebar.list_name_hidden_contexts'))%>
|
||||
<% end -%>
|
||||
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue