Permalink
Browse files

Added ajax for getting subCat when choosing cat in newTransaction.

Started playing with jQuery Modal for newTransaction.
  • Loading branch information...
1 parent 34dbdeb commit 8a4bab482b1b41b6f8df1350d52947808d7ba170 @ivik committed Nov 11, 2012
@@ -1,3 +1,8 @@
+//$("a[data-toggle=modal]").click(function (e) {
+// lv_target = $(this).attr('data-target')
+// lv_url = $(this).attr('href')
+// $(lv_target).load(lv_url)})
+
$(document).ready(function() {
$('#transaction_category').bind('change', function(event) {
@@ -6,7 +11,8 @@ $(document).ready(function() {
//alert(category_id);
$.ajax({
- url: "new",
+ url: "/transactions/get_sub_categories",
+ //url: "new",
type: "get",
data: "category_id="+category_id,
dataType: 'json',
@@ -22,8 +28,8 @@ $(document).ready(function() {
s_container = document.getElementById('sub_category_container');
var s = document.createElement("select");
- s.id = "sub_category_id";
- s.name = "transaction[sub_category]";
+ s.id = "sub_category_id";
+ s.name = "transaction[sub_category]";
var o = document.createElement("option");
o.text = "Please Select";
@@ -33,7 +39,7 @@ $(document).ready(function() {
for(var i=0; i<sub_categories.length; i++) {
var o = document.createElement("option");
- o.text = sub_categories[i]['name'];
+ o.text = sub_categories[i]['name'];
o.value = sub_categories[i]['id'];
s.appendChild(o)
}
@@ -3,7 +3,9 @@ class TransactionsController < ApplicationController
before_filter :get_user_categories, only: [:new, :edit]
def get_sub_categories
- params.o
+ #params.o
+ @sub_categories = SubCategory.find_all_by_category_id(params[:category_id])
+ render json: @sub_categories
end
@@ -16,20 +18,26 @@ def show
end
def new
- respond_to do |format|
- format.html do
- @transaction = Transaction.new
- end
- format.json do
- @sub_categories = SubCategory.find_all_by_category_id(params[:category_id])
- @sub_categories.o
- render json: @sub_categories
-
- #render 'new', :formats => [:js]
- end
- end
+ @transaction = Transaction.new
+ render layout: false
+ #render json: @transaction
end
+ #def new
+ # respond_to do |format|
+ # format.html do
+ # @transaction = Transaction.new
+ # end
+ # format.json do
+ # @sub_categories = SubCategory.find_all_by_category_id(params[:category_id])
+ # #@sub_categories.o
+ # render json: @sub_categories
+ #
+ # #render 'new', :formats => [:js]
+ # end
+ # end
+ #end
+
def create
#Todo
@@ -1,29 +0,0 @@
-%h4 Latest logs
-.center
- = link_to "Create New", new_transaction_path(@month)
-%br
-- if @transactions.any?
- %table.table.table-striped.table-condensed
- %thead
- %tr
- %th
- .center Date
- %th Category
- %th Sub Category
- %th Amount
- %tbody
- - @transactions.each do |transaction|
- %tr
- %td
- .center
- -#= transaction.date
- = link_to transaction.date, edit_transaction_path(transaction)
- %td
- -#= link_to return_category_name(transaction.category_id), edit_transaction_path(transaction)
- = return_category_name(transaction.category_id)
- %td
- - if !transaction.sub_category_id.blank?
- -#= link_to return_sub_category_name(transaction.sub_category_id), edit_sub_category_path(transaction)
- = return_sub_category_name(transaction.sub_category_id)
- %td
- = convert_to_swedish_money_output(transaction.amount)
@@ -0,0 +1,42 @@
+%h4 Latest logs
+.center
+ = link_to "Create New - Standard", new_transaction_path(@month), {remote: true}
+ %br
+ = link_to "Create New", new_transaction_path(@month), {"data-target" => "#newTransactionModal", "data-toggle" => "modal"}
+ %br
+ -#%a.btn{"data-target" => "#newTransactionModal", "data-toggle" => "modal", :href => "#{new_transaction_path(@month)}"} Create New
+%br
+- if @transactions.any?
+ %table.table.table-striped.table-condensed
+ %thead
+ %tr
+ %th
+ .center Date
+ %th Category
+ %th Sub Category
+ %th Amount
+ %tbody
+ - @transactions.each do |transaction|
+ %tr
+ %td
+ .center
+ -#= transaction.date
+ = link_to transaction.date, edit_transaction_path(transaction)
+ %td
+ -#= link_to return_category_name(transaction.category_id), edit_transaction_path(transaction)
+ = return_category_name(transaction.category_id)
+ %td
+ - if !transaction.sub_category_id.blank?
+ -#= link_to return_sub_category_name(transaction.sub_category_id), edit_sub_category_path(transaction)
+ = return_sub_category_name(transaction.sub_category_id)
+ %td
+ = convert_to_swedish_money_output(transaction.amount)
+
+#newTransactionModal.modal.hide.fade{"aria-hidden" => "true", "aria-labelledby" => "newTransactionModalLabel", :role => "dialog", :tabindex => "-1"}
+ .modal-header
+ %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
+ %h3#newTransactionModalLabel New Transaction
+ .modal-body
+ .modal-footer
+ %button.btn{"aria-hidden" => "true", "data-dismiss" => "modal"} Close
+ %button.btn.btn-primary Save changes
@@ -2,9 +2,9 @@
.row
.span6
%section
- = render 'shared/home_yearbooks'
+ = render 'static_pages/home_yearbooks'
%br
%section
- = render 'shared/home_categories'
+ = render 'static_pages/home_categories'
.span6
- = render 'shared/home_transactions'
+ = render 'static_pages/home_transactions'
@@ -1 +1,3 @@
-$("#sub_category_container").prepend(" <%= escape_javascript(render(:partial => @sub_categories)) %>")
+$('#myModal').html("<%= escape_javascript(render(@transaction)) %>");
+
+
@@ -0,0 +1,13 @@
+$("#sub_category_container").html("<%= escape_javascript(render(:partial => @sub_categories)) %>")
+$("#sub_category_container").html("<%= escape_javascript(render('transactions/sub_categories')) %>")
+
+
+$('#myModal').html("<%= escape_javascript(render :partial => 'transactions/form', :object => @transaction) %>");
+$('.modal').html("<%= escape_javascript(render(@event)) %>");
+
+
+$('.modal').html("<%= escape_javascript(render(@transaction)) %>");
+
+
+$('#myModal').modal('toggle')
+$('#myModal').html("<%=j render @transaction %>");
View
@@ -30,7 +30,7 @@
end
-
+ match '/transactions/get_sub_categories', to: 'transactions#get_sub_categories'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'

0 comments on commit 8a4bab4

Please sign in to comment.