moneyrail 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. data/.gitignore +5 -0
  2. data/.gitmodules +6 -0
  3. data/Changelog +21 -0
  4. data/README +1 -0
  5. data/Rakefile +32 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/accounts_controller.rb +99 -0
  8. data/app/controllers/application_controller.rb +10 -0
  9. data/app/controllers/categories_controller.rb +99 -0
  10. data/app/controllers/home_controller.rb +31 -0
  11. data/app/controllers/items_controller.rb +105 -0
  12. data/app/controllers/logs_controller.rb +20 -0
  13. data/app/helpers/accounts_helper.rb +2 -0
  14. data/app/helpers/application_helper.rb +3 -0
  15. data/app/helpers/categories_helper.rb +2 -0
  16. data/app/helpers/home_helper.rb +2 -0
  17. data/app/helpers/items_helper.rb +2 -0
  18. data/app/helpers/logs_helper.rb +42 -0
  19. data/app/models/account.rb +12 -0
  20. data/app/models/category.rb +26 -0
  21. data/app/models/expense.rb +2 -0
  22. data/app/models/income.rb +2 -0
  23. data/app/models/item.rb +31 -0
  24. data/app/models/move.rb +37 -0
  25. data/app/models/simple_item.rb +27 -0
  26. data/app/views/accounts/edit.html.erb +16 -0
  27. data/app/views/accounts/index.html.erb +24 -0
  28. data/app/views/accounts/new.html.erb +15 -0
  29. data/app/views/accounts/show.html.erb +8 -0
  30. data/app/views/categories/edit.html.erb +20 -0
  31. data/app/views/categories/index.html.erb +26 -0
  32. data/app/views/categories/new.html.erb +19 -0
  33. data/app/views/categories/show.html.erb +13 -0
  34. data/app/views/home/index.html.erb +15 -0
  35. data/app/views/items/edit.html.erb +45 -0
  36. data/app/views/items/index.html.erb +38 -0
  37. data/app/views/items/new.html.erb +40 -0
  38. data/app/views/items/show.html.erb +3 -0
  39. data/app/views/layouts/application.html.erb +37 -0
  40. data/app/views/logs/view.html.erb +120 -0
  41. data/config/boot.rb +110 -0
  42. data/config/database.yml +25 -0
  43. data/config/environment.rb +41 -0
  44. data/config/environments/cucumber.rb +21 -0
  45. data/config/environments/development.rb +17 -0
  46. data/config/environments/production.rb +28 -0
  47. data/config/environments/test.rb +28 -0
  48. data/config/initializers/backtrace_silencers.rb +7 -0
  49. data/config/initializers/inflections.rb +10 -0
  50. data/config/initializers/mime_types.rb +5 -0
  51. data/config/initializers/new_rails_defaults.rb +19 -0
  52. data/config/initializers/session_store.rb +15 -0
  53. data/config/locales/en.yml +5 -0
  54. data/config/routes.rb +80 -0
  55. data/db/migrate/20090802070406_create_accounts.rb +14 -0
  56. data/db/migrate/20090802073601_create_categories.rb +15 -0
  57. data/db/migrate/20090804065900_create_items.rb +26 -0
  58. data/db/production.sqlite3 +0 -0
  59. data/doc/README_FOR_APP +2 -0
  60. data/features/step_definitions/webrat_steps.rb +129 -0
  61. data/features/support/env.rb +37 -0
  62. data/features/support/paths.rb +27 -0
  63. data/lib/tasks/cucumber.rake +20 -0
  64. data/lib/tasks/rspec.rake +182 -0
  65. data/main.rb +5 -0
  66. data/moneyrail.gemspec +170 -0
  67. data/public/404.html +30 -0
  68. data/public/422.html +30 -0
  69. data/public/500.html +30 -0
  70. data/public/favicon.ico +0 -0
  71. data/public/images/rails.png +0 -0
  72. data/public/javascripts/application.js +2 -0
  73. data/public/javascripts/controls.js +963 -0
  74. data/public/javascripts/dragdrop.js +973 -0
  75. data/public/javascripts/editor.js +188 -0
  76. data/public/javascripts/effects.js +1128 -0
  77. data/public/javascripts/jquery-ui.js +160 -0
  78. data/public/javascripts/jquery.js +32 -0
  79. data/public/javascripts/prototype.js +4320 -0
  80. data/public/robots.txt +5 -0
  81. data/public/stylesheets/editor.less +67 -0
  82. data/public/stylesheets/scaffold.css +54 -0
  83. data/script/about +4 -0
  84. data/script/autospec +6 -0
  85. data/script/console +3 -0
  86. data/script/cucumber +8 -0
  87. data/script/dbconsole +3 -0
  88. data/script/destroy +3 -0
  89. data/script/generate +3 -0
  90. data/script/performance/benchmarker +3 -0
  91. data/script/performance/profiler +3 -0
  92. data/script/plugin +3 -0
  93. data/script/runner +3 -0
  94. data/script/server +3 -0
  95. data/script/spec +10 -0
  96. data/script/spec_server +9 -0
  97. data/spec/_fixtures/accounts.yml +5 -0
  98. data/spec/_fixtures/categories.yml +19 -0
  99. data/spec/_fixtures/incomes.yml +7 -0
  100. data/spec/_fixtures/items.yml +7 -0
  101. data/spec/fixtures/accounts.yml +11 -0
  102. data/spec/fixtures/categories.yml +24 -0
  103. data/spec/fixtures/items.yml +82 -0
  104. data/spec/helpers/accounts_helper_spec.rb +11 -0
  105. data/spec/helpers/categories_helper_spec.rb +11 -0
  106. data/spec/helpers/items_helper_spec.rb +11 -0
  107. data/spec/models/account_spec.rb +13 -0
  108. data/spec/models/category_spec.rb +9 -0
  109. data/spec/models/income_spec.rb +9 -0
  110. data/spec/models/item_spec.rb +13 -0
  111. data/spec/rcov.opts +2 -0
  112. data/spec/spec.opts +4 -0
  113. data/spec/spec_helper.rb +51 -0
  114. data/vendor/plugins/acts_as_list/README +23 -0
  115. data/vendor/plugins/acts_as_list/init.rb +3 -0
  116. data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
  117. data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
  118. data/vendor/plugins/less/LICENCE +20 -0
  119. data/vendor/plugins/less/README +52 -0
  120. data/vendor/plugins/less/init.rb +19 -0
  121. data/vendor/plugins/less/lib/less_for_rails.rb +37 -0
  122. data/vendor/plugins/less/test/less_for_rails_test.rb +15 -0
  123. metadata +202 -0
@@ -0,0 +1,188 @@
1
+ var $j = jQuery.noConflict();
2
+
3
+ var MoneyRail = MoneyRail || {};
4
+
5
+ MoneyRail.raise = function(){
6
+ if (console) {
7
+ $j.each(arguments, console.error);
8
+ }
9
+ throw arguments[0];
10
+ };
11
+
12
+ // refrection
13
+ MoneyRail.get_acount_id = function(input){
14
+ var table = $j(input).parents("table");
15
+ if(table.length == 0){
16
+ MoneyRail.raise("table not found:", input);
17
+ }
18
+ return $j(table).attr("title");
19
+ };
20
+ MoneyRail.get_date_and_position = function(elem){
21
+ var tr = $j(elem).parents("tr");
22
+ if(tr.length == 0){
23
+ MoneyRail.raise("tr not found:", elem);
24
+ }
25
+ var embeded = $j(tr).attr("title");
26
+ return embeded.split(/_/);
27
+ };
28
+ MoneyRail.get_category_id = function(input){
29
+ var td = $j(input).parent("td");
30
+ if(td.length == 0){
31
+ MoneyRail.raise("td not found:", input);
32
+ }
33
+ var type = $j(td).attr("class"); // shall be 'title' or 'amount'
34
+ var idx = $j(td).parent().children("td." + type).index(td);
35
+ return MoneyRail.category_ids[idx];
36
+ };
37
+
38
+ MoneyRail.insert_row = function(btn){
39
+ var make_tds = function(k){
40
+ return $R(1, k).map(function(i){
41
+ return [
42
+ "<td class='title'><input type='text'></td>",
43
+ "<td class='amount'><input type='text'></td>"
44
+ ];
45
+ });
46
+ };
47
+
48
+ var a = MoneyRail.get_date_and_position(btn);
49
+ var date = a[0], position = Number(a[1]);
50
+ var row = $j(btn).parents("tr");
51
+ var tr_class = ($j(row).attr("class") == "odd") ? "even" : "odd";
52
+
53
+ $j(btn).remove();
54
+ $j(row).after([
55
+ "<tr title='", date, "_", (position+1), "' class='", tr_class, "'>",
56
+ // Button
57
+ "<td class='inserts'>",
58
+ "<span class='pushable'>",
59
+ "▽",
60
+ "</span>",
61
+ "</td>",
62
+
63
+ // Date
64
+ "<td></td>",
65
+
66
+ // Inputs
67
+ MoneyRail.category_numbers.map(make_tds).flatten().join(""),
68
+ "</tr>"
69
+ ].join(""));
70
+ $j(row).next().find("span.pushable").click(MoneyRail.on_row_button_clicked);
71
+ };
72
+
73
+ // ajax
74
+
75
+ // Sets item[title], item[amount] and authenticity_token
76
+ MoneyRail.ajax_data = function(input, _data){
77
+ var data = _data || {};
78
+
79
+ if (input) {
80
+ var type = $j(input).parent("td").attr("class");
81
+ if (type == "title" || type == "amount") {
82
+ var key = "item[" + type + "]";
83
+ data[key] = $j(input).val();
84
+ }
85
+ else {
86
+ MoneyRail.raise("unknown type: " + type);
87
+ }
88
+ }
89
+
90
+ data["authenticity_token"] = MoneyRail.authenticity_token;
91
+ return data;
92
+ };
93
+
94
+ MoneyRail.destroy_item = function(input, item_id, after){
95
+ var data = MoneyRail.ajax_data(null, {_method: "delete"});
96
+
97
+ $j.post(MoneyRail.item_destroy_path(item_id), data, function(result){
98
+ if (result[0] == "ok"){
99
+ $j("td[title='"+item_id+"']").attr("title", "");
100
+
101
+ after();
102
+ }
103
+ }, "json");
104
+ };
105
+
106
+ MoneyRail.update_item = function(input, item_id, after){
107
+ var data = MoneyRail.ajax_data(input);
108
+
109
+ $j.post(MoneyRail.item_update_path(item_id), data, function(result){
110
+ if (result[0] == "ok") after();
111
+ }, "json");
112
+ };
113
+
114
+ MoneyRail.create_item = function(input, after){
115
+ var a = MoneyRail.get_date_and_position(input);
116
+ var data = MoneyRail.ajax_data(input, {
117
+ "item[date]": a[0],
118
+ "item[position]": a[1],
119
+ "item[account_id]": MoneyRail.get_acount_id(input),
120
+ "item[category_id]": MoneyRail.get_category_id(input),
121
+ });
122
+
123
+ $j.post(MoneyRail.item_create_path, data, function(result){
124
+ if (result[0] == "ok"){
125
+ var td = $j(input).parent("td");
126
+ td.attr("title", result[1]);
127
+ if (td.attr("class") == "title"){
128
+ td.next().attr("title", result[1]);
129
+ }
130
+ else {
131
+ td.prev().attr("title", result[1]);
132
+ }
133
+
134
+ after();
135
+ }
136
+ }, "json");
137
+ };
138
+
139
+ // event handlers
140
+ MoneyRail.on_input_changed = function(e){
141
+ var input = e.target;
142
+ var end_highlight = function(){
143
+ new Effect.Highlight(input, {
144
+ startcolor: "#ffff99", endcolor: "#ffffff", restorecolor: "#ffffff"
145
+ });
146
+ }
147
+ var is_delete = function(item_id){
148
+ var empty = /^(\s*)$/;
149
+ var title = $j("td[class='title'][title='"+item_id+"'] input").val();
150
+ var amount = $j("td[class='amount'][title='"+item_id+"'] input").val();
151
+
152
+ return empty.match(title) && empty.match(amount);
153
+ }
154
+
155
+ $j(input).css("background", "#ffff99");
156
+
157
+ var item_id = $j(input).parent("td").attr("title");
158
+ if (item_id) {
159
+ if (is_delete(item_id)){
160
+ MoneyRail.destroy_item(input, item_id, end_highlight);
161
+ }
162
+ else {
163
+ MoneyRail.update_item(input, item_id, end_highlight);
164
+ }
165
+ }
166
+ else {
167
+ MoneyRail.create_item(input, end_highlight);
168
+ }
169
+ };
170
+
171
+ MoneyRail.on_row_button_clicked = function(e){
172
+ MoneyRail.insert_row(e.target);
173
+ };
174
+
175
+ MoneyRail.register_events = function(){
176
+ // register input updated
177
+ $j.each($j("input"), function(input){
178
+ $j(input).change(MoneyRail.on_input_changed);
179
+ });
180
+ $j("span.pushable").click(MoneyRail.on_row_button_clicked);
181
+ };
182
+
183
+ $j(function(){
184
+ if(MoneyRail.editable){
185
+ MoneyRail.register_events();
186
+ }
187
+ });
188
+ <!-- この文字列は文字化け除けの文章です -->