Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added better loading support of subCat when editing a transaction.

  • Loading branch information...
commit ece2d81df89854a636f97f73a7502ff815216d15 1 parent 0633d89
@ivik authored
View
53 app/assets/javascripts/transactions.js
@@ -19,7 +19,7 @@ $(document).ready(function() {
// update transaction modal footer button
$('#update_transaction_button').live('click', function() {
- document.forms["update_transaction"].submit();
+ document.forms[".edit_transaction"].submit();
});
// get sub_category when category changes
@@ -30,6 +30,44 @@ $(document).ready(function() {
get_sub_categories_ajax(category_id);
});
});
+
+ // check if loaded category has sub categories
+// if($('#transaction_category').length != 0) {
+//
+// var category_id = $('#transaction_category').val();
+// //alert("1 - "+category_id);
+//
+// if(category_id != "") {
+//
+// get_sub_categories_ajax(category_id);
+// }
+// }
+
+
+ // in order to use same modal on multiple dynamic links
+// $('#updateTransactionModal').bind('show', function() {
+// var category_id = $('#transaction_category').val()
+// alert("2 - "+category_id);
+// });
+//
+// $('#updateTransactionLink').bind('click', function() {
+//
+// var category_id = $('#transaction_category').val();
+// alert("3 - "+category_id);
+// if(category_id != "") {
+//
+// //get_sub_categories_ajax(category_id);
+// }
+// else {
+//
+// $("#transaction_category option:selected").each(function () {
+// var category_id = $(this).val();
+//
+// alert("4 - "+category_id);
+// //get_sub_categories_ajax(category_id);
+// });
+// }
+// });
});
// Add datepicker to the transaction date field
@@ -37,15 +75,7 @@ $(document).ready(function() {
// $("#transaction_date").datepicker({ dateFormat: 'yy-mm-dd' });
//});
-// check if loaded category has sub categories
-if($('#transaction_category').length != 0) {
- var category_id = $('#transaction_category').val()
- if(category_id != "") {
-
- get_sub_categories_ajax(category_id);
- }
-}
function get_sub_categories_ajax(category_id) {
@@ -53,6 +83,9 @@ function get_sub_categories_ajax(category_id) {
return false;
}
+ // Check if the form is a EDIT form, if so, make sure to give the transactionID to the ajax function
+ // so that it will tag which sub_category has already been chosen.
+
$.ajax({
url: "/transactions/get_sub_categories",
type: "get",
@@ -89,6 +122,8 @@ function get_sub_categories_ajax(category_id) {
}
else {
+ $("#sub_category_container").html('');
+
//alert("No Sub Category, soon u can create one here!");
}
}
View
4 app/controllers/transactions_controller.rb
@@ -87,7 +87,11 @@ def create
def edit
@transaction = Transaction.find(params[:id])
+ @sub_categories = SubCategory.find_all_by_category_id(@transaction.category_id)
+
#@transaction.o
+ #@categories.o
+ #@sub_categories.o
@display_molad = params[:display_molad]
if @display_molad == "1"
View
2  app/views/static_pages/_home_transactions.html.haml
@@ -23,7 +23,7 @@
.center
-#= transaction.date
-#= link_to transaction.date, edit_transaction_path(transaction)
- = link_to transaction.date, edit_transaction_path(transaction, display_molad: "1"), {"data-target" => "#updateTransactionModal", "data-toggle" => "modal"}
+ = link_to transaction.date, edit_transaction_path(transaction, display_molad: "1"), {id: "updateTransactionLink", "data-target" => "#updateTransactionModal", "data-toggle" => "modal"}
%td
-#= link_to return_category_name(transaction.category_id), edit_transaction_path(transaction)
= return_category_name(transaction.category_id)
View
10 app/views/transactions/_form.html.haml
@@ -1,9 +1,15 @@
= f.label :date
= f.text_field :date
= f.label :category
-= f.select :category, @categories.map { |cat| [cat.name, cat.id] }
+-#= f.select :category, @categories.map { |cat| [cat.name, cat.id] }
+= f.collection_select(:category, @categories.all, :id, :name, :prompt => 'Please Select', selected: @transaction.category_id)
#sub_category_container
+ - if(!@sub_categories.nil?)
+ = f.label :sub_category
+ = f.collection_select(:sub_category, @sub_categories.map, :id, :name, :prompt => 'Please Select', selected: @transaction.sub_category_id)
= f.label :amount
= f.text_field :amount
= f.label "Expense or Income"
-= f.select :is_expense, [["Expense", true], ["Income", false]]
+= f.select :is_expense, [["Expense", true], ["Income", false]]
+%script
+ $("#transaction_date").datepicker({ dateFormat: 'yy-mm-dd' });
View
3  app/views/transactions/edit.html.haml
@@ -12,5 +12,4 @@
= render 'shared/error_messages', object: f.object
= render 'form', :f => f
= f.submit "Save Changes", class: "btn btn-large btn-primary"
-%script
- $("#transaction_date").datepicker({ dateFormat: 'yy-mm-dd' });
+-#%script{:src => "/assets/transactions.js", :type => "text/javascript"}
View
4 app/views/transactions/new.html.haml
@@ -11,6 +11,4 @@
= form_for(@transaction) do |f|
= render 'shared/error_messages', object: f.object
= render 'form', :f => f
- = f.submit "Create Transaction", class: "btn btn-large btn-primary"
-%script
- $("#transaction_date").datepicker({ dateFormat: 'yy-mm-dd' });
+ = f.submit "Create Transaction", class: "btn btn-large btn-primary"
Please sign in to comment.
Something went wrong with that request. Please try again.