Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added notes to tasks

  • Loading branch information...
commit 7afa751407e5c4239a7e0a0ef55698d2ff2851c6 1 parent 33baf28
@kcalmes kcalmes authored
View
5 app/controllers/short_term_goals_controller.rb
@@ -74,6 +74,7 @@ def edit
# POST /short_term_goals
# POST /short_term_goals.xml
def create
+=begin
params[:short_term_goal][:tasks] = Array.new
tasks_array = Array.new
if params[:task]
@@ -84,6 +85,7 @@ def create
tasks_array.each do |task|
params[:short_term_goal][:tasks] << Task.create(:name => task) if task != nil
end
+=end
@short_term_goal = ShortTermGoal.new(params[:short_term_goal])
respond_to do |format|
if @short_term_goal.save
@@ -100,6 +102,7 @@ def create
# PUT /short_term_goals/1.xml
def update
@short_term_goal = ShortTermGoal.find(params[:id])
+=begin
@short_term_goal.tasks.each do |task|
task.destroy
end
@@ -113,7 +116,7 @@ def update
tasks_array.each do |task|
params[:short_term_goal][:tasks] << Task.create(:name => task) if task != nil
end
-
+=end
respond_to do |format|
if @short_term_goal.update_attributes(params[:short_term_goal])
format.html { redirect_to(myguide_path(@current_user), :notice => 'Short term goal was successfully updated.') }
View
2  app/controllers/tasks_controller.rb
@@ -1,4 +1,4 @@
-class TasksController < ApplicationController
+ class TasksController < ApplicationController
before_filter :set_section
View
5 app/models/short_term_goal.rb
@@ -4,10 +4,13 @@ class ShortTermGoal < ActiveRecord::Base
belongs_to :tag
belongs_to :user
+ accepts_nested_attributes_for :tasks, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
+
def display_long_term_goals
self.long_term_goals.select(:name).map{|obj| obj.name}.join(',')
end
# TOKEN PROCESSING FOR AUTO-COMPLETE
+=begin
def set_long_term_goals=(ids)
self.long_term_goal_ids = ids.split(",")
end
@@ -17,5 +20,5 @@ def set_tasks=(ids)
def set_tags=(ids)
self.tag_ids = ids.split(",")
end
-
+=end
end
View
2  app/views/provider_types/index.html.erb
@@ -27,7 +27,7 @@
<% end %>
</td>
<td>
- <%= link_to provider_type, :confirm => 'Are you sure?', :method => :delete do%>
+ <%= link_to provider_type, :confirm => 'Are you sure?', :method => :delete do %>
<button class="skin_colour round_all">
<img alt="Delete this provider_type" src="<%= icon_path %>/Trashcan.png" />
</button>
View
288 app/views/short_term_goals/_form.html.erb
@@ -1,153 +1,161 @@
<script>
- var number_of_tasks = 100;
- $(function(){
-
- $(".add_new_task").click(function(){
- $(".field .tasks_input").append('<div id="task['+number_of_tasks+']" class="task_wrapper clearfix"><input class="task" name="task['+number_of_tasks+']" size="180" type="text" /><img src="http://humadvisement.byu.edu/sites/default/files/menu_icons/Delete_64x64.png" width="15"></div>');
- setDeleteClick();
- number_of_tasks++;
- return false;
- });
- setDeleteClick();
- $(".add_img").attr('src','http://humadvisement.byu.edu/sites/default/files/menu_icons/Add-Button_64x64.png');
- $(".add_img").click(function(){
- addNew($(this).attr('model'));
- });
+ /*var number_of_tasks = 100;
+ $(function(){
+
+ $(".add_new_task").click(function(){
+ $(".field .tasks_input").append('<div id="task['+number_of_tasks+']" class="task_wrapper clearfix"><input class="task" name="task['+number_of_tasks+']" size="180" type="text" /><img src="http://humadvisement.byu.edu/sites/default/files/menu_icons/Delete_64x64.png" width="15"></div>');
+ setDeleteClick();
+ number_of_tasks++;
+ return false;
+ });
+ setDeleteClick();
+ $(".add_img").attr('src','http://humadvisement.byu.edu/sites/default/files/menu_icons/Add-Button_64x64.png');
+ $(".add_img").click(function(){
+ addNew($(this).attr('model'));
+ });
+ });
+ function setDeleteClick(){
+ $(".task_wrapper img").unbind('click');
+ $(".task_wrapper img").click(function(){
+ $(this).parent().remove();
+ });
+ }
+ */
+$(function(){
+ //Add another task
+ $("#add_another_task").click(function(){
+ html = $("#new_task").html();
+ html = html.replace(/new/g, ""+new Date().getTime()+"");
+ $(this).siblings("ul").append("<li>" + html + "</li>");
+ });
+ $("#add_another_task").trigger("click");
+
+ $('.new_short_term_goal, .edit_short_term_goal').submit(function(){
+ $("#new_task").remove();
+ });
+
+ //Remove a task
+ $(".remove_button").click(function(){
+ $(this).parents(".task_fields").find("input[type=hidden]").val(true);
+ $(this).parents(".task_fields").fadeOut();
+ return false;
});
- function setDeleteClick(){
- $(".task_wrapper img").unbind('click');
- $(".task_wrapper img").click(function(){
- $(this).parent().remove();
- });
- }
- function addNew(model){
- var dialog = "";
- $.ajax({
- type: "GET",
- url: "/" + model + "/new",
- data: {'dialog':true},
- success: function(data){
- dialog = '<div id="dialog">' + data + '</div>';
- $('body').append(dialog);
- $( "#dialog" ).dialog({width: 800, height: 500, close: function(event, ui) {
- $("#dialog").dialog('destroy');
- $("#dialog").remove();
- model_singular = model.substring(0,model.length-1);
- $.ajax({
- url: '/' + model + '.json',
- data: {},
- dataType: 'json',
- success: function(data){
- $.each(data, function(index){
- console.log(data[index][name]);
- });
- }
- });
- }});
- },
- error: function(){
- alert( "ERROR!");
- }
- });
- }
+});
</script>
<style>
- .add_img{
- float: right;
- width: 25px;
- margin-top: -35px;
- cursor: pointer;
- }
- .field label{
- clear: both;
- }
- .add_img.select{
- float: none;
- }
- .task_wrapper{
- cursor: pointer;
- }
- .task_wrapper input{
- float: left;
- }
- .task_wrapper img{
- float: left;
- margin: 5px 10px;
- }
+ .add_img{
+ float: right;
+ width: 25px;
+ margin-top: -35px;
+ cursor: pointer;
+ }
+ .field label{
+ clear: both;
+ }
+ .add_img.select{
+ float: none;
+ }
+ .task_wrapper{
+ cursor: pointer;
+ }
+ .task_wrapper input{
+ float: left;
+ }
+ .task_wrapper img{
+ float: left;
+ margin: 5px 10px;
+ }
+
+
+ ul{
+ list-style: none;
+ }
+ #new_task{
+ display: none;
+ }
+ #add_another_task{
+ margin-bottom: 20px;
+ cursor: pointer;
+ }
+ #add_another_ingredient:hover{
+ text-decoration: underline;
+ }
+
+ .box .block textarea.no_editor {
+ width: 500px;
+ height: 50px;
+ }
</style>
<%= form_for(@short_term_goal) do |f| %>
- <% if @short_term_goal.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@short_term_goal.errors.count, "error") %> prohibited this short_term_goal from being saved:</h2>
-
- <ul>
- <% @short_term_goal.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
+ <% if @short_term_goal.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@short_term_goal.errors.count, "error") %> prohibited this short_term_goal from being saved:</h2>
+ <ul>
+ <% @short_term_goal.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
</ul>
</div>
<% end %>
-
- <div class="actions grid_16">
- <% content_tag :button, :type => :submit, :class => "green round_all" do %>
- <%= image_tag "icons/small/white/Bended%20Arrow%20Right.png" %>
- <span>Save this Short Term Goal!</span>
- <% end %>
- </div>
- <%= theme_box(8, "", false) do %>
- <div class="field">
- <%= f.label :long_term_goals, "Attach to the following Long Term Goals..." %>
- <div class="input_group">
- <%= f.collection_select :long_term_goal_ids, LongTermGoal.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
- </div>
- </div>
- <div class="field">
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </div>
- <div class="field">
- <%= f.label :description %><br />
- <%= f.text_area :description %>
- </div>
- <div class="field">
- <%= f.label :school_year %><br />
- <%= f.select :school_year, %w{1 2 3 4} %>
- </div>
- <div class="field">
- <label>Tasks</label><br/>
- <div class="tasks_input">
- <% count = 0 %>
- <% @short_term_goal.tasks.each do |task| %>
- <div id="task[<%= count %>]" class="task_wrapper clearfix">
- <input class="task" name="task[<%= count %>]" size="180" type="text" value="<%= task.name %>" />
- <img src="http://humadvisement.byu.edu/sites/default/files/menu_icons/Delete_64x64.png" width="15">
- </div>
- <% count += 1 %>
- <% end %>
- </div>
- <br /><a href="#" class="add_new_task">Add New Task</a>
- </div>
+
+ <div class="actions grid_16">
+ <%= content_tag :button, :type => :submit, :class => "green round_all" do %>
+ <%= image_tag "icons/small/white/Bended%20Arrow%20Right.png" %>
+ <span>Save this Short Term Goal!</span>
+ <% end %>
+ </div>
+ <%= theme_box(8, "Goal", true) do %>
+ <div class="field">
+ <%= f.label :long_term_goals, "Attach to the following Long Term Goals..." %>
+ <div class="input_group">
+ <%= f.collection_select :long_term_goal_ids, LongTermGoal.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
+ </div>
+ </div>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :description %><br />
+ <%= f.text_area :description %>
+ </div>
+ <div class="field">
+ <%= f.label :school_year %><br />
+ <%= f.select :school_year, %w{1 2 3 4} %>
+ </div>
+
+ <div class="field">
+ <%= f.label :tag_id %><br />
+ <%= f.collection_select :tag_id, Tag.order(:name), :id, :name, {}, {:class => 'chosen'} %>
+ </div>
+ <% if can? :manage, :users %>
+ <div class="field">
+ <label>Owner</label>
+ <div class="input_group">
+ <%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @short_term_goal.user.id}, {:class => 'chosen'} %>
+ </div>
+ </div>
+ <% else %>
+ <%= f.hidden_field :user_id %>
+ <% end %>
+ <% end %>
+ <%= theme_box(8, "Tasks", true) do %>
<div class="field">
- <%= f.label :tag_id %><br />
- <%= f.collection_select :tag_id, Tag.order(:name), :id, :name, {}, {:class => 'chosen'} %>
- </div>
- <% if can? :manage, :users %>
- <div class="field">
- <label>Net Id</label>
- <div class="input_group">
- <%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @short_term_goal.user.id}, {:class => 'chosen'} %>
- </div>
- </div>
- <% else %>
- <%= f.hidden_field :user_id %>
- <% end %>
- </div>
- <% end %>
+ <ul>
+ <%= f.fields_for :tasks do |builder| %>
+ <li><%= render "task_fields", :f => builder %></li>
+ <% end %>
+ </ul>
+ <div id="new_task">
+ <%= f.fields_for :tasks, f.object.tasks.new, :child_index => "new" do |builder| %>
+ <%= render 'task_fields', :f => builder %>
+ <% end %>
+ </div>
+ <div id="add_another_task">
+ + Add Another Task
+ </div>
+ </div>
+ <% end %>
<% end %>
-<script>
- $(function(){
- $(".as-selections").width($(".as-selections").width() - 30);
- });
-</script>
View
14 app/views/short_term_goals/_task_fields.html.erb
@@ -0,0 +1,14 @@
+<div class="task_fields clearfix">
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ <%= f.label :description %>
+ <%= f.text_area :description, :class => 'no_editor' %>
+
+<%= f.hidden_field :_destroy %>
+<br />
+<%= content_tag :button, :class => "red round_all remove_button" do %>
+ <%= image_tag "icons/small/white/Trashcan.png" %>
+ <span>Delete Task</span>
+<% end %>
+
+</div>
View
7 app/views/short_term_goals/edit.html.erb
@@ -5,4 +5,11 @@
</span>
</div><br />
<%= render 'form' %>
+
+ <%= link_to @short_term_goal, :confirm => 'Are you sure?', :method => :delete do %>
+ <% content_tag :button, :class => "red round_all remove_button" do %>
+ <%= image_tag "icons/small/white/Trashcan.png" %>
+ <span>Delete Short Term Goal</span>
+ <% end %>
+ <% end %>
</div>
View
3  public/javascripts/application.js
@@ -85,7 +85,8 @@
var tiny_params = {
width:500,
height:175,
- mode: 'textareas',
+ mode: 'specific_textareas',
+ editor_deselector : "no_editor",
cssclass:'te',
controlclass:'tecontrol',
rowclass:'teheader',
Please sign in to comment.
Something went wrong with that request. Please try again.