Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit a7a5584a6f1fc69e215fbbebda82b39c37bb3a36 1 parent 3df0941
@dimianstudio authored
Showing with 11,147 additions and 0 deletions.
  1. +64 −0 .autotest
  2. +39 −0 .gitignore
  3. +243 −0 README
  4. +10 −0 Rakefile
  5. +57 −0 app/controllers/application_controller.rb
  6. +47 −0 app/controllers/backend/activities_controller.rb
  7. +60 −0 app/controllers/backend/associations_controller.rb
  8. +95 −0 app/controllers/backend/categories_controller.rb
  9. +7 −0 app/controllers/backend/favorites_controller.rb
  10. +19 −0 app/controllers/backend/images_controller.rb
  11. +24 −0 app/controllers/backend/inbox_controller.rb
  12. +21 −0 app/controllers/backend/index_controller.rb
  13. +16 −0 app/controllers/backend/maps_controller.rb
  14. +120 −0 app/controllers/backend/orgs_controller.rb
  15. +65 −0 app/controllers/backend/phones_controller.rb
  16. +224 −0 app/controllers/backend/requests_controller.rb
  17. +49 −0 app/controllers/backend/rewiews_controller.rb
  18. +53 −0 app/controllers/backend/roles_controller.rb
  19. +6 −0 app/controllers/backend/search_controller.rb
  20. +13 −0 app/controllers/backend/settings_controller.rb
  21. +56 −0 app/controllers/backend/streets_controller.rb
  22. +67 −0 app/controllers/backend/tags_controller.rb
  23. +56 −0 app/controllers/backend/towns_controller.rb
  24. +79 −0 app/controllers/backend/users_controller.rb
  25. +30 −0 app/controllers/backend_controller.rb
  26. +61 −0 app/controllers/frontend/activities_controller.rb
  27. +23 −0 app/controllers/frontend/categories_controller.rb
  28. +63 −0 app/controllers/frontend/favorites_controller.rb
  29. +39 −0 app/controllers/frontend/images_controller.rb
  30. +9 −0 app/controllers/frontend/index_controller.rb
  31. +38 −0 app/controllers/frontend/maps_controller.rb
  32. +84 −0 app/controllers/frontend/orgs_controller.rb
  33. +89 −0 app/controllers/frontend/phones_controller.rb
  34. +14 −0 app/controllers/frontend/profile_controller.rb
  35. +12 −0 app/controllers/frontend/requests_controller.rb
  36. +60 −0 app/controllers/frontend/rewiews_controller.rb
  37. +12 −0 app/controllers/frontend/search_controller.rb
  38. +29 −0 app/controllers/frontend/service_controller.rb
  39. +41 −0 app/controllers/frontend/sessions_controller.rb
  40. +52 −0 app/controllers/frontend/tags_controller.rb
  41. +70 −0 app/controllers/frontend/users_controller.rb
  42. +20 −0 app/controllers/frontend_controller.rb
  43. +352 −0 app/helpers/application_helper.rb
  44. +2 −0  app/helpers/backend/images_helper.rb
  45. +2 −0  app/helpers/backend/maps_helper.rb
  46. +2 −0  app/helpers/frontend/images_helper.rb
  47. +2 −0  app/helpers/frontend/maps_helper.rb
  48. +93 −0 app/helpers/frontend/users_helper.rb
  49. +32 −0 app/models/activity.rb
  50. +15 −0 app/models/association.rb
  51. +28 −0 app/models/category.rb
  52. +26 −0 app/models/favorite.rb
  53. +19 −0 app/models/image.rb
  54. +12 −0 app/models/marker.rb
  55. +64 −0 app/models/org.rb
  56. +10 −0 app/models/phone.rb
  57. +30 −0 app/models/request.rb
  58. +36 −0 app/models/rewiew.rb
  59. +6 −0 app/models/right.rb
  60. +13 −0 app/models/role.rb
  61. +10 −0 app/models/street.rb
  62. +31 −0 app/models/tag.rb
  63. +10 −0 app/models/town.rb
  64. +70 −0 app/models/user.rb
  65. +4 −0 app/models/user_base_connection.rb
  66. +20 −0 app/sweepers/association_sweeper.rb
  67. +32 −0 app/sweepers/category_sweeper.rb
  68. +12 −0 app/sweepers/favorite_sweeper.rb
  69. +13 −0 app/sweepers/image_sweeper.rb
  70. +15 −0 app/sweepers/rewiew_sweeper.rb
  71. +30 −0 app/sweepers/street_sweeper.rb
  72. +25 −0 app/sweepers/tag_sweeper.rb
  73. +30 −0 app/sweepers/town_sweeper.rb
  74. +53 −0 app/views/backend/activities/index.html.haml
  75. +10 −0 app/views/backend/associations/_association.html.haml
  76. +21 −0 app/views/backend/associations/index.html.haml
  77. +40 −0 app/views/backend/associations/show.html.haml
  78. +21 −0 app/views/backend/associations/tag.html.haml
  79. +21 −0 app/views/backend/associations/user.html.haml
  80. +8 −0 app/views/backend/categories/_categories.html.haml
  81. +8 −0 app/views/backend/categories/_category.html.haml
  82. +6 −0 app/views/backend/categories/_error.rjs
  83. +8 −0 app/views/backend/categories/_show.rjs
  84. +2 −0  app/views/backend/categories/_show_output.html.haml
  85. +14 −0 app/views/backend/categories/_subcategory.html.haml
  86. +7 −0 app/views/backend/categories/_success.rjs
  87. +18 −0 app/views/backend/categories/edit.html.haml
  88. +20 −0 app/views/backend/categories/index.html.haml
  89. +23 −0 app/views/backend/categories/show.html.haml
  90. +26 −0 app/views/backend/favorites/index.html.haml
  91. +26 −0 app/views/backend/images/show.html.haml
  92. +39 −0 app/views/backend/index/index.html.haml
  93. +24 −0 app/views/backend/maps/index.html.haml
  94. +12 −0 app/views/backend/orgs/_org.html.haml
  95. +23 −0 app/views/backend/orgs/index.html.haml
  96. +82 −0 app/views/backend/orgs/new.html.haml
  97. +70 −0 app/views/backend/orgs/show.html.haml
  98. +17 −0 app/views/backend/phones/edit.html.haml
  99. +44 −0 app/views/backend/phones/index.html.haml
  100. +13 −0 app/views/backend/requests/_request.html.haml
  101. +21 −0 app/views/backend/requests/index.html.haml
  102. +22 −0 app/views/backend/requests/show.html.haml
  103. +21 −0 app/views/backend/requests/templates/activity_add.html.haml
  104. +24 −0 app/views/backend/requests/templates/activity_delete.html.haml
  105. +63 −0 app/views/backend/requests/templates/org_add.html.haml
  106. +24 −0 app/views/backend/requests/templates/org_delete.html.haml
  107. +53 −0 app/views/backend/requests/templates/org_edit.html.haml
  108. +25 −0 app/views/backend/requests/templates/phone_add.html.haml
  109. +24 −0 app/views/backend/requests/templates/phone_delete.html.haml
  110. +28 −0 app/views/backend/requests/templates/phone_edit.html.haml
  111. +8 −0 app/views/backend/rewiews/_rewiew.html.haml
  112. +10 −0 app/views/backend/rewiews/edit.html.haml
  113. +13 −0 app/views/backend/rewiews/index.html.haml
  114. +14 −0 app/views/backend/rewiews/show.html.haml
  115. +10 −0 app/views/backend/roles/edit.html.haml
  116. +33 −0 app/views/backend/roles/index.html.haml
  117. +32 −0 app/views/backend/roles/show.html.haml
  118. +23 −0 app/views/backend/search/index.html.haml
  119. +13 −0 app/views/backend/settings/index.html.haml
  120. +10 −0 app/views/backend/streets/edit.html.haml
  121. +39 −0 app/views/backend/streets/index.html.haml
  122. +23 −0 app/views/backend/streets/show.html.haml
  123. +13 −0 app/views/backend/tags/_tag.html.haml
  124. +10 −0 app/views/backend/tags/edit.html.haml
  125. +29 −0 app/views/backend/tags/index.html.haml
  126. +23 −0 app/views/backend/tags/show.html.haml
  127. +22 −0 app/views/backend/tags/user.html.haml
  128. +11 −0 app/views/backend/towns/edit.html.haml
  129. +40 −0 app/views/backend/towns/index.html.haml
  130. +23 −0 app/views/backend/towns/show.html.haml
  131. +9 −0 app/views/backend/users/_user.html.haml
  132. +22 −0 app/views/backend/users/index.html.haml
  133. +24 −0 app/views/backend/users/orgs.html.haml
  134. +22 −0 app/views/backend/users/requests.html.haml
  135. +14 −0 app/views/backend/users/rewiews.html.haml
  136. +37 −0 app/views/backend/users/rights.html.haml
  137. +32 −0 app/views/backend/users/show.html.haml
  138. +19 −0 app/views/frontend/activities/destroy.html.haml
  139. +50 −0 app/views/frontend/activities/index.html.haml
  140. +3 −0  app/views/frontend/categories/_categories.rjs
  141. +9 −0 app/views/frontend/categories/_items.html.haml
  142. +18 −0 app/views/frontend/categories/show.html.haml
  143. +6 −0 app/views/frontend/favorites/_error.rjs
  144. +16 −0 app/views/frontend/favorites/_favorite.html.haml
  145. +6 −0 app/views/frontend/favorites/_success.rjs
  146. +16 −0 app/views/frontend/favorites/index.html.haml
  147. +28 −0 app/views/frontend/images/index.html.haml
  148. +15 −0 app/views/frontend/index/index.html.haml
  149. +21 −0 app/views/frontend/maps/index.html.haml
  150. +18 −0 app/views/frontend/orgs/destroy.html.haml
  151. +63 −0 app/views/frontend/orgs/edit.html.haml
  152. +92 −0 app/views/frontend/orgs/new.html.haml
  153. +63 −0 app/views/frontend/orgs/show.html.haml
  154. +20 −0 app/views/frontend/phones/destroy.html.haml
  155. +19 −0 app/views/frontend/phones/edit.html.haml
  156. +36 −0 app/views/frontend/phones/index.html.haml
  157. +12 −0 app/views/frontend/profile/index.html.haml
  158. +25 −0 app/views/frontend/profile/settings.html.haml
  159. +46 −0 app/views/frontend/requests/index.html.haml
  160. +5 −0 app/views/frontend/rewiews/_error.rjs
  161. +5 −0 app/views/frontend/rewiews/_rewiew.html.haml
  162. +8 −0 app/views/frontend/rewiews/_success.rjs
  163. +22 −0 app/views/frontend/rewiews/index.html.haml
  164. +11 −0 app/views/frontend/search/index.html.haml
  165. +9 −0 app/views/frontend/service/advertising.html.haml
  166. +11 −0 app/views/frontend/service/contact_us.html.haml
  167. +16 −0 app/views/frontend/service/emergency_phones.html.haml
  168. +31 −0 app/views/frontend/service/help.html.haml
  169. +40 −0 app/views/frontend/service/help_phones.html.haml
  170. +27 −0 app/views/frontend/service/terms.html.haml
  171. +17 −0 app/views/frontend/sessions/new.html.haml
  172. +22 −0 app/views/frontend/tags/index.html.haml
  173. +16 −0 app/views/frontend/tags/show.html.haml
  174. +25 −0 app/views/frontend/users/new.html.haml
  175. +23 −0 app/views/layouts/backend/index.html.haml
  176. +36 −0 app/views/layouts/frontend/index.html.haml
  177. +4 −0 app/views/shared/bars/_admin_search.html.haml
  178. +3 −0  app/views/shared/bars/_search.html.haml
  179. +33 −0 app/views/shared/bars/_user.html.haml
  180. +6 −0 app/views/shared/elements_form/_enter_phones.html.haml
  181. +9 −0 app/views/shared/elements_form/_group_select.html.haml
  182. +11 −0 app/views/shared/elements_form/_select_category.html.haml
  183. +20 −0 app/views/shared/elements_page/_categories.html.haml
  184. +14 −0 app/views/shared/elements_page/_tree_categories_and_subcategories.html.haml
  185. +28 −0 app/views/shared/menus/_admin.html.haml
  186. +12 −0 app/views/shared/menus/_admin_org.html.haml
  187. +8 −0 app/views/shared/menus/_admin_user.html.haml
  188. +13 −0 app/views/shared/menus/_org.html.haml
  189. +7 −0 app/views/shared/menus/_user.html.haml
  190. +12 −0 app/views/shared/messages/_flash.html.haml
  191. +13 −0 app/views/shared/partials/_org.html.haml
  192. +1 −0  app/views/shared/partials/_spacer.html.haml
  193. +110 −0 config/boot.rb
  194. +4 −0 config/config.yml
  195. +42 −0 config/development.sphinx.conf
  196. +47 −0 config/environment.rb
  197. +23 −0 config/environments/development.rb
  198. +30 −0 config/environments/production.rb
  199. +31 −0 config/environments/test.rb
  200. +7 −0 config/initializers/backtrace_silencers.rb
  201. +10 −0 config/initializers/inflections.rb
  202. +1 −0  config/initializers/load_config.rb
  203. +5 −0 config/initializers/mime_types.rb
  204. +21 −0 config/initializers/new_rails_defaults.rb
  205. +15 −0 config/initializers/session_store.rb
  206. +38 −0 config/initializers/site_keys.rb
  207. +5 −0 config/locales/en.yml
  208. +27 −0 config/locales/ru.yml
  209. +151 −0 config/routes.rb
  210. +8 −0 config/schedule.rb
  211. +12 −0 db/migrate/20100126171254_create_roles.rb
  212. +27 −0 db/migrate/20100126175801_create_orgs.rb
  213. +13 −0 db/migrate/20100126175941_create_towns.rb
  214. +13 −0 db/migrate/20100126175954_create_streets.rb
  215. +16 −0 db/migrate/20100126180058_create_phones.rb
  216. +15 −0 db/migrate/20100126180330_create_categories.rb
  217. +15 −0 db/migrate/20100126180454_create_tags.rb
  218. +18 −0 db/migrate/20100126180545_create_rewiews.rb
  219. +20 −0 db/migrate/20100126180634_create_associations.rb
  220. +17 −0 db/migrate/20100126180839_create_activities.rb
  221. +19 −0 db/migrate/20100130200253_create_rights.rb
  222. +24 −0 db/migrate/20100130210621_create_requests.rb
  223. +17 −0 db/migrate/20100214184448_create_favorites.rb
  224. +16 −0 db/migrate/20100217185638_create_mails.rb
  225. +21 −0 db/migrate/20100219124578_create_users.rb
  226. +16 −0 db/migrate/20100219184714_create_sessions.rb
  227. +15 −0 db/migrate/20100711171222_add_attachments_image_to_org.rb
  228. +18 −0 db/migrate/20100723191108_create_images.rb
  229. +17 −0 db/migrate/20100727165643_create_markers.rb
  230. +7 −0 db/seeds.rb
  231. +193 −0 lib/authenticated_system.rb
  232. +11 −0 lib/authenticated_test_helper.rb
  233. +27 −0 lib/expire_cache.rb
  234. +72 −0 lib/hijacker.rb
  235. +146 −0 lib/role_requirement_system.rb
  236. +86 −0 lib/role_requirement_test_helper.rb
  237. +144 −0 lib/tasks/rspec.rake
  238. +27 −0 public/404.html
  239. +27 −0 public/422.html
  240. +27 −0 public/500.html
  241. +5 −0 public/robots.txt
  242. +4 −0 script/about
  243. +6 −0 script/autospec
  244. +3 −0  script/console
  245. +3 −0  script/dbconsole
  246. +3 −0  script/destroy
  247. +3 −0  script/generate
  248. +3 −0  script/performance/benchmarker
  249. +3 −0  script/performance/profiler
  250. +3 −0  script/plugin
  251. +3 −0  script/runner
  252. +3 −0  script/server
  253. +10 −0 script/spec
  254. +89 −0 spec/controllers/access_control_spec.rb
  255. +102 −0 spec/controllers/authenticated_system_spec.rb
  256. +227 −0 spec/controllers/frontend/activities_controller_spec.rb
  257. +73 −0 spec/controllers/frontend/categories_controller_spec.rb
  258. +123 −0 spec/controllers/frontend/favorites_controller_spec.rb
  259. +11 −0 spec/controllers/frontend/index_controller_spec.rb
  260. +343 −0 spec/controllers/frontend/orgs_controller_spec.rb
  261. +346 −0 spec/controllers/frontend/phones_controller_spec.rb
  262. +56 −0 spec/controllers/frontend/profile_controller_spec.rb
  263. +38 −0 spec/controllers/frontend/requests_controller_spec.rb
  264. +213 −0 spec/controllers/frontend/rewiews_controller_spec.rb
  265. +10 −0 spec/controllers/frontend/search_controller_spec.rb
  266. +68 −0 spec/controllers/frontend/service_controller_spec.rb
  267. +126 −0 spec/controllers/frontend/sessions_controller_spec.rb
  268. +156 −0 spec/controllers/frontend/tags_controller_spec.rb
  269. +127 −0 spec/controllers/frontend/users_controller_spec.rb
  270. +44 −0 spec/factories.rb
  271. +31 −0 spec/fixtures/users.yml
  272. +163 −0 spec/helpers/application_helper_spec.rb
  273. +141 −0 spec/helpers/frontend/users_helper_spec.rb
  274. +2 −0  spec/rcov.opts
  275. +4 −0 spec/spec.opts
  276. +79 −0 spec/spec_helper.rb
  277. +30 −0 spec/views/frontend/activities/destroy.html.haml_spec.rb
  278. +67 −0 spec/views/frontend/activities/index.html.haml_spec.rb
  279. +9 −0 spec/views/frontend/index/index.html.haml_spec.rb
  280. +25 −0 spec/views/frontend/orgs/destroy.html.haml_spec.rb
  281. +50 −0 spec/views/frontend/orgs/edit.html.haml_spec.rb
  282. +73 −0 spec/views/frontend/orgs/new.html.haml_spec.rb
  283. +128 −0 spec/views/frontend/orgs/show.html.haml_spec.rb
  284. +29 −0 spec/views/frontend/phones/destroy.html.haml_spec.rb
  285. +29 −0 spec/views/frontend/phones/edit.html.haml_spec.rb
  286. +93 −0 spec/views/frontend/phones/index.html.haml_spec.rb
  287. +101 −0 spec/views/frontend/rewiews/index.html.haml_spec.rb
  288. +50 −0 spec/views/frontend/tags/index.html.html_spec.rb
  289. +70 −0 spec/views/frontend/tags/show.html.haml_spec.rb
  290. +10 −0 spec/views/shared/elements_page/_back_link.html.haml_spec.rb
  291. +15 −0 spec/views/shared/menus/_admin.html.haml_spec.rb
  292. +25 −0 spec/views/shared/menus/_admin_org.html.haml_rspec.rb
  293. +24 −0 spec/views/shared/menus/_admin_user.html.haml_rspec.rb
  294. +26 −0 spec/views/shared/menus/_org.html.haml_spec.rb
  295. +15 −0 spec/views/shared/menus/_user.html.haml_rspec.rb
  296. +13 −0 spec/views/shared/shared/_auth.html.haml_spec.rb
  297. BIN  sql_dump.bz2
  298. +26 −0 vendor/plugins/acts_as_tree/README
  299. +22 −0 vendor/plugins/acts_as_tree/Rakefile
  300. +1 −0  vendor/plugins/acts_as_tree/init.rb
Sorry, we could not display the entire diff because too many files (1,399) changed.
View
64 .autotest
@@ -0,0 +1,64 @@
+# NOTE Copy this to your home folder as .autotest
+#
+# Originally from http://wincent.com/knowledge-base/Setti … _use_Growl
+#
+# Modifications:
+# * Minor refactoring to use .autotest_images directory
+# [Geoffrey Grosenbach http://peepcode.com]
+# * Test::Unit compatibility [Pat Nakajima]
+#
+module Autotest::Growl
+
+AUTOTEST_IMAGE_ROOT = "/volumes/SERVER/growl_images/"
+
+def self.growl title, msg, img, pri=0, sticky=""
+ system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
+end
+
+def self.growl_fail(output)
+ growl "FAIL", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/rails_fail.png", 2
+end
+
+def self.growl_pending(output)
+ growl "PENDING", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/pending.png", 2
+end
+
+def self.growl_pass(output)
+ growl "PASS", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/rails_ok.png"
+end
+
+Autotest.add_hook(:initialize) {|at|
+ at.add_exception %r{^\.git} # ignore Version Control System
+ at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
+ at.clear_mappings # take out the default (test/test*rb)
+ at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
+ Dir['spec/**/*.rb']
+ }
+ nil
+}
+
+Autotest.add_hook :ran_command do |at|
+
+ results = [at.results].flatten.join("\n")
+
+ if results.include? 'tests'
+ output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
+ if output
+ $~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
+ end
+ else
+ # output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
+ output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
+ if output =~ /[1-9]\sfailures?/
+ growl_fail(output)
+ elsif output =~ /[1-9]\spending?/
+ growl_pending(output)
+ else
+ growl_pass(output)
+ end
+ # if output
+ # $~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
+ # end
+ end
+end
+end
View
39 .gitignore
@@ -0,0 +1,39 @@
+db/*.sqlite3
+log/*.*
+tmp/**/*
+tmp/*
+config/deploy
+config/deploy/*
+config/deploy.rb
+Capfile
+._*
+log/*.pid
+db/*.db
+db/schema.rb
+.DS_Store
+Thumbs.db
+doc/api
+doc/app
+config/database.yml
+config/database.mongo.yml
+config/mongoid.yml
+autotest_result.html
+coverage
+public/stylesheets/app
+public/stylesheets/app/ie
+public/stylesheets/app/*.css
+public/attachments
+public/audio
+backups/
+public/backup_db.sql.gz
+vendor/bundle/ruby
+bin
+assets/**/*
+*~
+**/*.*~
+Procfile
+.rvmrc
+.bundle
+*~
+nbproject/**/*
+doc/*
View
243 README
@@ -0,0 +1,243 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb" templates
+that are primarily responsible for inserting pre-built data in between HTML tags.
+The model contains the "smart" domain objects (such as Account, Product, Person,
+Post) that holds all the business logic and knows how to persist themselves to
+a database. The controller handles the incoming requests (such as Save New Account,
+Update Product, Show Post) by manipulating the model and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
+ and your application name. Ex: rails myapp
+2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
+3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
+4. Follow the guidelines to start developing your application
+
+
+== Web Servers
+
+By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
+with a variety of other web servers.
+
+Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
+suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
+getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
+More info at: http://mongrel.rubyforge.org
+
+Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
+Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
+FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
+
+== Apache .htaccess example for FCGI/CGI
+
+# General Apache options
+AddHandler fastcgi-script .fcgi
+AddHandler cgi-script .cgi
+Options +FollowSymLinks +ExecCGI
+
+# If you don't want Rails to look in certain directories,
+# use the following rewrite rules so that Apache won't rewrite certain requests
+#
+# Example:
+# RewriteCond %{REQUEST_URI} ^/notrails.*
+# RewriteRule .* - [L]
+
+# Redirect all requests not available on the filesystem to Rails
+# By default the cgi dispatcher is used which is very slow
+#
+# For better performance replace the dispatcher with the fastcgi one
+#
+# Example:
+# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
+RewriteEngine On
+
+# If your Rails application is accessed via an Alias directive,
+# then you MUST also set the RewriteBase in this htaccess file.
+#
+# Example:
+# Alias /myrailsapp /path/to/myrailsapp/public
+# RewriteBase /myrailsapp
+
+RewriteRule ^$ index.html [QSA]
+RewriteRule ^([^.]+)$ $1.html [QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
+
+# In case Rails experiences terminal errors
+# Instead of displaying this message you can supply a file here which will be rendered instead
+#
+# Example:
+# ErrorDocument 500 /500.html
+
+ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands running
+on the server.log and development.log. Rails will automatically display debugging
+and runtime information to these files. Debugging info will also be shown in the
+browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code using
+the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
+
+* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two online (and free) books will bring you up to speed on the Ruby language
+and also on programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your Mongrel or
+Webrick server with --debugger. This means that you can break out of execution at any point
+in the code, investigate and change the model, AND then resume execution!
+You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
+Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.find(:all)
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better is that you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you enter "cont"
+
+
+== Console
+
+You can interact with the domain model by starting the console through <tt>script/console</tt>.
+Here you'll have all parts of the application configured, just like it is when the
+application is running. You can inspect domain models, change values, and save to the
+database. Starting the script without arguments will launch it in the development environment.
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
+
+To reload your controllers and models after launching the console run <tt>reload!</tt>
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
+You would be connected to the database with the credentials defined in database.yml.
+Starting the script without arguments will connect you to the development database. Passing an
+argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
+Currently works for mysql, postgresql and sqlite.
+
+== Description of Contents
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from ApplicationController
+ which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb.
+ Most models will descend from ActiveRecord::Base.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
+ syntax.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the common
+ header/footer method of wrapping views. In your views, define a layout using the
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
+ call <% yield %> to render the view using this layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
+ for you automatically when using script/generate for controllers. Helpers can be used to
+ wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all
+ the sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when generated
+ using <tt>rake doc:app</tt>
+
+lib
+ Application specific libraries. Basically, any kind of custom code that doesn't
+ belong under controllers, models, or helpers. This directory is in the load path.
+
+public
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
+ set as the DOCUMENT_ROOT of your web server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
+ test files will be generated for you and placed in this directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins subdirectory.
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
+ This directory is in the load path.
View
10 Rakefile
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
View
57 app/controllers/application_controller.rb
@@ -0,0 +1,57 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+ # protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # rescue_from Exception, :with => :render_404
+ # rescue_from ActiveRecord::RecordNotFound, :with => :render_404
+ # rescue_from ActionController::RoutingError, :with => :render_404
+ # rescue_from ActionController::UnknownController, :with => :render_404
+ # rescue_from ActionController::UnknownAction, :with => :render_404
+
+ include CacheableFlash
+
+ # Be sure to include AuthenticationSystem in Application Controller instead
+ include AuthenticatedSystem
+
+ # You can move this into a different controller, if you wish. This module gives you the require_role helpers, and others.
+ include RoleRequirementSystem
+
+ # Scrub sensitive parameters from your log
+ filter_parameter_logging :password
+
+ def default_url_options(options = { :value => true })
+ { :format => "html" }
+ end
+
+ def render_optional_error_file(status)
+ render_404
+ end
+
+ def access_denied
+ respond_to do |format|
+ format.html do
+ store_location
+ redirect_to new_session_path
+ end
+ format.js do
+ render :inline => 'error'
+ end
+ # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
+ # Add any other API formats here. (Some browsers, notably IE6, send Accept: */* and trigger
+ # the 'format.any' block incorrectly. See http://bit.ly/ie6_borken or http://bit.ly/ie6_borken2
+ # for a workaround.)
+ format.any(:json, :xml) do
+ request_http_basic_authentication 'Web Password'
+ end
+ end
+ end
+
+ private
+
+ def render_404
+ render :file => "#{RAILS_ROOT}/public/404.html",:status => 404
+ end
+end
View
47 app/controllers/backend/activities_controller.rb
@@ -0,0 +1,47 @@
+class Backend::ActivitiesController < BackendController
+
+ # Filters
+ before_filter :init_org
+
+ # GET /backend/orgs/1/activities.html ----------------------------- HTML
+ def index
+ @activities = @org.activities.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/orgs/1/activities.html ---------------------------- HTML
+ def create
+ params[:activities].each do |activity|
+ activity = @org.activities.build(:category_id => activity)
+ activity.save!
+ end
+ expire_cache(params[:org_id])
+ respond_success "Вид деятельности успешно добавлен"
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/orgs/1/activities/1.html ------------------------ HTML
+ def destroy
+ expire_cache(params[:org_id])
+ Activity.delete(params[:id])
+ respond_success "Вид деятельности успешно удален"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+
+ def expire_cache(id)
+ org = Org.find(id)
+ expire_file("orgs/#{id}.html")
+ expire_file("orgs/#{id}/activities.html")
+ org.categories.collect{ |c| [c.id] }.each do |category|
+ expire_files("categories/#{category}.html")
+ expire_dirs("categories/#{category}/")
+ end
+ end
+end
View
60 app/controllers/backend/associations_controller.rb
@@ -0,0 +1,60 @@
+class Backend::AssociationsController < BackendController
+
+ # Filters
+ before_filter :init_org, :only => [:show, :create]
+
+ # Sweepers
+ cache_sweeper :association_sweeper, :only => [:create, :destroy]
+
+ # GET /backend/associations.html ---------------------------------- HTML
+ def index
+ @associations = Association.find(:all, :order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/orgs/1/associations.html --------------------------- HTML
+ def show
+ @associations = @org.associations.find(:all, :order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/orgs/1/associations.html -------------------------- HTML
+ def create
+ raise Tag::NoRequiredFields if params[:tag][:string].blank?
+ tags = params[:tag][:string].downcase.split(",").reject(&:blank?).map(&:strip).uniq
+ user = current_user.id
+ tags.each do |tag|
+ Tag.transaction do
+ new_tag = Tag.find_or_add(tag, user)
+ Association.find_or_add(@org.id, new_tag.id, user)
+ end
+ end
+ respond_success("Ассоциация(-и) успешно добавлена(-ы)")
+ rescue Tag::NoRequiredFields => e
+ respond_error e.message
+ end
+
+ # GET /backend/associations/1/tag.html ---------------------------- HTML
+ def tag
+ @tag = Tag.find(params[:id])
+ @associations = @tag.associations(:order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/associations/1/user.html --------------------------- HTML
+ def user
+ @user = User.find(params[:id])
+ @associations = @user.associations(:order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # DELETE /backend/association.html -------------------------------- HTML
+ def destroy
+ Association.delete(params[:id])
+ respond_success "Ассоциация успешно удалена"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:id])
+ end
+end
View
95 app/controllers/backend/categories_controller.rb
@@ -0,0 +1,95 @@
+class Backend::CategoriesController < BackendController
+
+ # Filters
+ before_filter :init_category, :only => [:show, :edit, :update, :restructure]
+
+ # Sweepers
+ cache_sweeper :category_sweeper, :only => [:create, :update, :restructure, :destroy]
+
+ # GET /backend/categories.html ------------------------------------ HTML
+ def index
+ end
+
+ # GET /backend/categories/1.html ---------------------------------- HTML
+ # GET /backend/categories/1.js ------------------------------------ AJAX
+ def show
+ respond_to do |format|
+ format.html {
+ @orgs = @category.orgs.paginate(:page => params[:page], :per_page => 10)
+ }
+ format.js {
+ @categories = @category.children
+ render :partial => 'show', :layout => false, :locals => {:categories => @categories, :category_id => params[:id]}
+ }
+ end
+ end
+
+ # POST /backend/categories.html ----------------------------------- HTML
+ def create
+ category = Category.new
+ category.name = params[:category][:name]
+ category.parent_id = params[:category][:parent_id].to_i
+ category.save!
+ output_success "Категория успешно создана"
+ rescue
+ output_failure
+ end
+
+ # GET /backend/categories/1/edit.html ----------------------------- HTML
+ def edit
+ session[:back] = request.env["HTTP_REFERER"]
+ end
+
+ # PUT /backend/categories/1.html ---------------------------------- HTML
+ def update
+ @category.name = params[:category][:name]
+ @category.parent_id = params[:category][:parent_id]
+ @category.save!
+ output_success "Категория успешно отредактированна", session[:back]
+ rescue
+ output_failure
+ end
+
+ # POST /backend/categories/restructure?category_id=1&format=js ----- AJAX
+ def restructure
+ @category.parent_id = params[:category_id]
+ @category.save!
+ output_success("Категория успешно перемещена", params[:id])
+ rescue
+ output_failure
+ end
+
+ # DELETE /backend/categories/1.html ------------------------------ HTML
+ def destroy
+ Category.delete(params[:id])
+ output_success "Категория успешно удалена"
+ rescue
+ output_failure
+ end
+
+ private
+
+ def init_category
+ @category = Category.find(params[:id])
+ end
+
+ def output_success(msg, id = 0)
+ respond_to do |format|
+ format.html {
+ flash[:notice] = msg
+ redirect_to backend_categories_url
+ }
+ format.js { render :partial => 'success', :layout => false , :locals => {:id => id}}
+ end
+ end
+
+ def output_failure(msg = "Извините, произошла ошибка!!!")
+ respond_to do |format|
+ format.html {
+ flash[:error] = msg
+ redirect_to backend_categories_url
+ }
+ format.js { render :partial => 'error', :layout => false }
+ end
+ end
+end
View
7 app/controllers/backend/favorites_controller.rb
@@ -0,0 +1,7 @@
+class Backend::FavoritesController < BackendController
+
+ # GET backend/favorites.html -------------------------------------- HTML
+ def index
+ @favorites = Favorite.find(:all, :order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+end
View
19 app/controllers/backend/images_controller.rb
@@ -0,0 +1,19 @@
+class Backend::ImagesController < BackendController
+
+ # Filters
+ before_filter :init_org
+
+ # GET /backend/orgs/1/images.html --------------------------------- HTML
+ def index
+ end
+
+ # GET /backend/orgs/1/images.html --------------------------------- HTML
+ def show
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:id])
+ end
+end
View
24 app/controllers/backend/inbox_controller.rb
@@ -0,0 +1,24 @@
+class Backend::InboxController < BackendController
+
+ def index
+ @mails = Mail.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ def destroy
+ Mail.destroy(params[:id])
+ output_success("Письмо успешно удалено")
+ rescue
+ output_failure
+ end
+
+ def output_success(msg)
+ flash[:notice] = msg
+ redirect_to :back
+ end
+
+ def output_failure(msg = "Извините, произошла ошибка!!!")
+ flash[:error] = msg
+ redirect_to :back
+ end
+
+end
View
21 app/controllers/backend/index_controller.rb
@@ -0,0 +1,21 @@
+class Backend::IndexController < BackendController
+
+ # GET /backend.html ----------------------------------------------- HTML
+ def index
+ # @data = ga_get_data
+ # @users = User.find(:all, :order => "created_at DESC", :limit => 5)
+ # @rewiews = Rewiew.find(:all, :order => "created_at DESC", :limit => 5)
+ # @requests = Request.find(:all, :order => "created_at DESC", :limit => 5)
+ end
+
+private
+
+ def ga_get_data
+ Garb::Session.login('tokmakcity@gmail.com', 'dimian17041987')
+ profile = Garb::Profile.first('UA-17022263-3')
+ report = Garb::Report.new(profile, :start_date => (Date.today - 15), :end_date => Date.today)
+ report.metrics :visits, :pageviews
+ report.dimensions :date
+ report.results
+ end
+end
View
16 app/controllers/backend/maps_controller.rb
@@ -0,0 +1,16 @@
+class Backend::MapsController < BackendController
+
+ # Filters
+ before_filter :init_org
+
+ # GET /backend/orgs/1/maps.html ----------------------------------- HTML
+ def index
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+
+end
View
120 app/controllers/backend/orgs_controller.rb
@@ -0,0 +1,120 @@
+class Backend::OrgsController < BackendController
+
+ # Filters
+ before_filter :init_org, :only => [:update, :show, :destroy, :delete_image]
+
+ # GET /backend/orgs.html ------------------------------------------ HTML
+ def index
+ @orgs = Org.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/orgs/1.html ---------------------------------------- HTML
+ def show
+ session[:back] = "show"
+ end
+
+ # GET /backend/orgs/new.html -------------------------------------- HTML
+ def new
+ end
+
+ # POST /backend/orgs.html ----------------------------------------- HTML
+ def create
+ Org.transaction do
+ @org = Org.new
+ @org.name = params[:org][:name]
+ @org.description = params[:org][:description]
+ @org.user_id = current_user.id
+ @org.town_id = params[:org][:town_id]
+ @org.street_id = params[:org][:street_id]
+ @org.house = params[:org][:house]
+ @org.email = params[:org][:email]
+ @org.www = params[:org][:www]
+ @org.save!
+
+ if params[:activities]
+ params[:activities].each do |activity|
+ @activity = Activity.new
+ @activity.org_id = @org.id
+ @activity.category_id = activity
+ @activity.save
+ end
+ end
+
+ unless params[:phones].empty?
+ params[:phones].each do |phone|
+ @phone = Phone.new
+ @phone.org_id = @org.id
+ @phone.department = phone[:department]
+ @phone.number = phone[:number]
+ @phone.save
+ end
+ end
+ end
+ expire_cache(@org.id)
+ respond_success "Организация успешно добавлена", backend_org_path(@org)
+ rescue
+ flash[:error] = "Извините, произошла ошибка!!!"
+ render :action => "new"
+ end
+
+ # PUT /backend/org/1.html ----------------------------------------- HTML
+ def update
+ @org.update_attributes!(params[:org])
+ expire_cache(params[:id])
+ respond_success "Информация об организации успешно изменена"
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/orgs/1.html ------------------------------------- HTML
+ def destroy
+ expire_cache(params[:id])
+ Org.destroy(params[:id])
+ if session[:back] == "show"
+ session[:back] = nil
+ respond_success "Организация успешно удалена", backend_orgs_path
+ else
+ respond_success "Организация успешно удалена"
+ end
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/orgs/1/delete_image.html ------------------------ HTML
+ def delete_image
+ @org.image.clear
+ @org.image_file_name = nil
+ @org.image_content_type = nil
+ @org.image_file_size = nil
+ @org.image_updated_at = nil
+ @org.save
+ expire_cache(params[:id])
+ respond_success "Фотка успешно удалена"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:id])
+ end
+
+ def expire_cache(id)
+ org = Org.find(id)
+ expire_file("orgs/#{id}.html")
+ expire_dirs("orgs/#{id}/")
+ org.categories.collect{ |c| [c.id] }.each do |category|
+ expire_files("categories/#{category}.html")
+ expire_dirs("categories/#{category}/")
+ end
+ org.tags.collect{ |t| [t.id] }.each do |tag|
+ expire_files("tag/#{tag}.html")
+ expire_dirs("tag/#{tag}/")
+ end
+ org.favorites.collect{ |u| [u.user_id]}.each do |user|
+ expire_fragment(%r{favorite/user_#{user}/page_*})
+ end
+ expire_fragment(%r{service_stat})
+ end
+end
View
65 app/controllers/backend/phones_controller.rb
@@ -0,0 +1,65 @@
+class Backend::PhonesController < BackendController
+
+ # Filters
+ before_filter :init_org, :only => [:index, :create]
+ before_filter :init_phone, :only => [:edit, :update]
+ after_filter :expire_cache, :only => [:create, :update, :destroy]
+
+ # GET /backend/orgs/1/phones.html --------------------------------- HTML
+ def index
+ @phones = @org.phones.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/orgs/1/phones.html -------------------------------- HTML
+ def create
+ phone = @org.phones.build(params[:phone])
+ phone.save!
+ respond_success "Телефон успешно добавлен"
+ rescue
+ respond_error
+ end
+
+ # GET /backend/orgs/1/phones/1/edit.html -------------------------- HTML
+ def edit
+ session[:back] = request.env["HTTP_REFERER"]
+ end
+
+ # PUT /backend/orgs/1/phones/1.html ------------------------------- HTML
+ def update
+ @phone.update_attributes!(params[:phone])
+ respond_success "Телефон успешно изменен", session[:back]
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/orgs/1/phones/1.html ---------------------------- HTML
+ def destroy
+ Phone.delete(params[:id])
+ respond_success "Телефон успешно удален"
+ rescue
+ respond_error
+ end
+
+ # GET /backend/phones/add_row.html -------------------------------- AJAX
+ def add_row
+ render :update do |page|
+ page.insert_html :bottom, "phones", render(:partial => "shared/elements_form/enter_phones")
+ end
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+
+ def init_phone
+ @org = Org.find(params[:org_id])
+ @phone = @org.phones.find(params[:id])
+ end
+
+ def expire_cache
+ expire_file("orgs/#{params[:org_id]}/phones.html")
+ expire_dirs("orgs/#{params[:org_id]}/phones/")
+ end
+end
View
224 app/controllers/backend/requests_controller.rb
@@ -0,0 +1,224 @@
+class Object
+ def metaclass; class << self; self; end end
+end
+
+class Hash
+ def to_obj
+ hash = self
+ metaclass.class_eval do
+ hash.each_pair do |key, value|
+ define_method key do
+ value
+ end
+ end
+ end
+ end
+end
+
+class Backend::RequestsController < BackendController
+
+ # Filters
+ before_filter :init_org, :only => :show
+
+ # GET /backend/requests.html -------------------------------------- HTML
+ def index
+ @requests = Request.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/orgs/1/requests.html ------------------------------- HTML
+ def show
+ @requests = @org.requests.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/requests/1/edit.html ------------------------------- HTML
+ def edit
+ @request = Request.find(params[:id])
+ case @request.object
+ when "org" then
+ case @request.action
+ when "add" then
+ @org = @request.content[:new_record][:org].to_obj
+ @phones = @request.content[:new_record][:phones]
+ @activities = @request.content[:new_record][:activities]
+ render :template => "backend/requests/templates/org_add"
+ when "edit" then
+ @org_editable = @request.content[:edit_record].to_hash.to_obj
+ render :template => "backend/requests/templates/org_edit"
+ when "delete" then
+ @org = Org.find(@request.content[:delete_record_id])
+ render :template => "backend/requests/templates/org_delete"
+ end
+ when "phone" then
+ case @request.action
+ when "add" then
+ @phones = @request.content[:phones]
+ render :template => "backend/requests/templates/phone_add"
+ when "edit" then
+ @phone = Phone.find(@request.content[:original_record_id])
+ @phone_editable = @request.content[:edit_record].to_obj
+ render :template => "backend/requests/templates/phone_edit"
+ when "delete" then
+ @phone = Phone.find(@request.content[:delete_record_id])
+ render :template => "backend/requests/templates/phone_delete"
+ end
+ when "activity" then
+ case @request.action
+ when "add" then
+ @activities = @request.content[:new_record]
+ render :template => "backend/requests/templates/activity_add"
+ when "delete" then
+ @activity = Category.find(@request.content[:delete_record_id])
+ render :template => "backend/requests/templates/activity_delete"
+ end
+ end
+ session[:back] = request.env["HTTP_REFERER"]
+ rescue ActiveRecord::RecordNotFound => e
+ respond_error "Наверное объект запроса уже удален"
+ rescue
+ respond_error
+ end
+
+ # PUT /backend/requests/1.html ------------------------------------ HTML
+ def update
+ @request = Request.find(params[:id])
+ unless params[:request][:comment].blank?
+ unless @request.approved
+ if params[:request][:approved] == "1"
+ case @request.object
+ when "org" then
+ case @request.action
+ when "add" then
+ Org.transaction do
+ @org = Org.create!(
+ :name => params[:org][:name],
+ :description => params[:org][:description],
+ :user_id => @request.user_id,
+ :town_id => params[:org][:town_id],
+ :street_id => params[:org][:street_id],
+ :house => params[:org][:house],
+ :email => params[:org][:email],
+ :www => params[:org][:www]
+ )
+ if params[:activities]
+ params[:activities].each do |activity|
+ Activity.create(
+ :org_id => @org.id,
+ :category_id => activity
+ )
+ end
+ end
+ unless params[:phones].empty?
+ params[:phones].each do |phone|
+ Phone.create(
+ :org_id => @org.id,
+ :department => phone[:department],
+ :number => phone[:number]
+ )
+ end
+ end
+ expire_cache_org(@org.id)
+ end
+ when "edit" then
+ @org = Org.find(@request.org_id)
+ @org.update_attributes!(params[:org_editable])
+ expire_cache_org(@request.org_id)
+ when "delete" then
+ expire_cache_org(@request.org_id)
+ Org.destroy(@request.org_id)
+ end
+ when "phone" then
+ case @request.action
+ when "add" then
+ unless params[:phones].empty?
+ params[:phones].each do |phone|
+ Phone.create(
+ :org_id => @request.org_id,
+ :department => phone[:department],
+ :number => phone[:number]
+ )
+ end
+ end
+ expire_cache_phones(@request.org_id)
+ when "edit" then
+ phone = Phone.find(@request.content[:original_record_id])
+ phone.update_attributes!(params[:phone_editable])
+ expire_cache_phones(@request.org_id)
+ when "delete" then
+ expire_cache_phones(@request.org_id)
+ Phone.destroy(@request.content[:delete_record_id])
+ end
+ when "activity" then
+ case @request.action
+ when "add" then
+ params[:activities].each do |activity|
+ Activity.create(
+ :org_id => @request.org_id,
+ :category_id => activity
+ )
+ expire_cache_activities(@request.org_id)
+ end
+ when "delete" then
+ expire_cache_activities(@request.org_id)
+ Activity.delete_all(['org_id = ? AND category_id = ?', @request.org_id, @request.content[:delete_record_id]])
+ end
+ end
+ @request.approval(params[:request][:comment], params[:request][:approved])
+ respond_success "Запрос успешно обработан", session[:back]
+ else
+ @request.approval(params[:request][:comment], params[:request][:approved])
+ respond_success "Запрос не обработан"
+ end
+ else
+ @request.approval(params[:request][:comment], params[:request][:approved])
+ respond_success "Данные запроса успешно изменены"
+ end
+ else
+ respond_error "Введите комментарий к запросу"
+ end
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/requests/1.html --------------------------------- HTML
+ def destroy
+ Request.delete(params[:id])
+ respond_success "Запрос успешно удален"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:id])
+ end
+
+ def expire_cache_org(id)
+ org = Org.find(id)
+ expire_file("orgs/#{id}.html")
+ expire_dirs("orgs/#{id}/")
+ org.categories.collect{ |c| [c.id] }.each do |category|
+ expire_files("categories/#{category}.html")
+ expire_dirs("categories/#{category}/")
+ end
+ org.tags.collect{ |t| [t.id] }.each do |tag|
+ expire_files("tag/#{tag}.html")
+ expire_dirs("tag/#{tag}/")
+ end
+ end
+
+ def expire_cache_phones(id)
+ expire_files("orgs/#{id}/phones.html")
+ expire_dirs("orgs/#{id}/phones/")
+ end
+
+ def expire_cache_activities(id)
+ org = Org.find(id)
+ expire_file("orgs/#{id}.html")
+ expire_files("orgs/#{id}/activities.html")
+ org.categories.collect{ |c| [c.id] }.each do |category|
+ expire_files("categories/#{category}.html")
+ expire_dirs("categories/#{category}/")
+ end
+ end
+end
View
49 app/controllers/backend/rewiews_controller.rb
@@ -0,0 +1,49 @@
+class Backend::RewiewsController < BackendController
+
+ # Filters
+ before_filter :init_rewiew, :only => [:edit, :update]
+
+ # Sweepers
+ cache_sweeper :rewiew_sweeper, :only => :destroy
+
+ # GET /backend/rewiews.html --------------------------------------- HTML
+ def index
+ @rewiews = Rewiew.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 5)
+ end
+
+ # GET /backend/rewiews/1.html ------------------------------------- HTML
+ def show
+ @org = Org.find(params[:id])
+ @rewiews = @org.rewiews.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 5)
+ rescue
+ respond_error "Такой организации нет :(", backend_orgs_path
+ end
+
+ # GET /backend/rewiews/1/edit.html -------------------------------- HTML
+ def edit
+ session[:back] = request.env["HTTP_REFERER"]
+ end
+
+ # PUT /backend/rewiews/1.html ------------------------------------- HTML
+ def update
+ @rewiew.text = params[:rewiew][:text]
+ @rewiew.save!
+ respond_success "Комментарий успешно отредактирован", session[:back]
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/rewiews/1.html ---------------------------------- HTML
+ def destroy
+ Rewiew.destroy(params[:id])
+ respond_success "Комментарий успешно удален"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_rewiew
+ @rewiew = Rewiew.find(params[:id])
+ end
+end
View
53 app/controllers/backend/roles_controller.rb
@@ -0,0 +1,53 @@
+class Backend::RolesController < BackendController
+
+ # Filters
+ before_filter :init_role, :only => [:show, :edit, :update]
+
+ # GET /backend/roles.html ----------------------------------------- HTML
+ def index
+ @roles = Role.find(:all, :order => "name ASC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/roles/1.html --------------------------------------- HTML
+ def show
+ @users = @role.users.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/roles.html ---------------------------------------- HTML
+ def create
+ role = Role.new
+ role.name = params[:role][:name]
+ role.save!
+ respond_success "Роль успешно создана"
+ rescue
+ respond_error
+ end
+
+ # GET /backend/roles/1/edit.html ---------------------------------- HTML
+ def edit
+ session[:back] = request.env['HTTP_REFERER']
+ end
+
+ # PUT /backend/roles/1.html --------------------------------------- HTML
+ def update
+ @role.name = params[:role][:name]
+ @role.save!
+ respond_success "Роль успешно отредактированна", session[:back]
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/roles/1.html ------------------------------------ HTML
+ def destroy
+ Role.delete(params[:id])
+ respond_success "Роль успешно удалена"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_role
+ @role = Role.find(params[:id])
+ end
+end
View
6 app/controllers/backend/search_controller.rb
@@ -0,0 +1,6 @@
+class Backend::SearchController < BackendController
+
+ def index
+ @results = Org.search params[:query], :page => params[:page], :per_page => 10, :match_mode => :boolean
+ end
+end
View
13 app/controllers/backend/settings_controller.rb
@@ -0,0 +1,13 @@
+class Backend::SettingsController < BackendController
+
+ def index
+ @settings = APP_CONFIG
+ end
+
+ def update
+ File.open( "#{RAILS_ROOT}/config/config.yml", 'w' ) do |out|
+ YAML.dump( params[:setting], out )
+ end
+ redirect_to backend_settings_path
+ end
+end
View
56 app/controllers/backend/streets_controller.rb
@@ -0,0 +1,56 @@
+class Backend::StreetsController < BackendController
+
+ # Filters
+ before_filter :init_street, :only => [:edit, :update, :show]
+
+ # Sweepers
+ cache_sweeper :street_sweeper, :only => [:create, :update, :destroy]
+
+ # GET /backend/streets.html --------------------------------------- HTML
+ def index
+ @streets = Street.find(:all, :order => "name ASC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/streets/1.html ------------------------------------- HTML
+ def show
+ @orgs = @street.orgs.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/streets.html -------------------------------------- HTML
+ def create
+ street = Street.new
+ street.name = params[:street][:name]
+ street.save!
+ respond_success "Улица успешно добавлена"
+ rescue
+ respond_error
+ end
+
+ # GET /backend/streets/1/edit.html -------------------------------- HTML
+ def edit
+ session[:back] = request.env["HTTP_REFERER"]
+ end
+
+ # PUT /backend/streets/1.html ------------------------------------- HTML
+ def update
+ @street.name = params[:street][:name]
+ @street.save!
+ respond_success "Улица успешно отредактирована", session[:back]
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/streets/1.html ---------------------------------- HTML
+ def destroy
+ Street.delete(params[:id])
+ respond_success "Улица успешно удалена"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_street
+ @street = Street.find(params[:id])
+ end
+end
View
67 app/controllers/backend/tags_controller.rb
@@ -0,0 +1,67 @@
+class Backend::TagsController < BackendController
+
+ # Filters
+ before_filter :init_tag, :only => [:edit, :update, :show]
+
+ # Sweepers
+ cache_sweeper :tag_sweeper, :only => [:create, :update, :destroy]
+
+ # GET /backend/tags.html ------------------------------------------ HTML
+ def index
+ @tags = Tag.find(:all, :order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/tags/1.html ---------------------------------------- HTML
+ def show
+ @orgs = @tag.orgs.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/tags.html ----------------------------------------- HTML
+ def create
+ raise Tag::NoRequiredFields if params[:tag][:string].blank?
+ tags = params[:tag][:string].downcase.split(",").reject(&:blank?).map(&:strip).uniq
+ user = current_user.id
+ Tag.transaction do
+ tags.each do |tag|
+ Tag.find_or_add(tag, user)
+ end
+ end
+ respond_success "Тэг(-и) успешно добавлен(-ы)"
+ rescue Tag::NoRequiredFields => e
+ respond_error e.message
+ end
+
+ # GET /backend/tags/1/edit.html ----------------------------------- HTML
+ def edit
+ session[:back] = request.env['HTTP_REFERER']
+ end
+
+ # PUT /backend/tags/1.html ---------------------------------------- HTML
+ def update
+ @tag.name = params[:tag][:name]
+ @tag.save!
+ respond_success "Тэг успешно отредактирован", session[:back]
+ rescue
+ respond_error
+ end
+
+ # GET /backend/tags/1/user.html ----------------------------------- HTML
+ def user
+ @user = User.find(params[:id])
+ @tags = @user.tags(:order => 'created_at DESC').paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # DELETE /backend/tags/1.html ------------------------------------- HTML
+ def destroy
+ Tag.destroy(params[:id])
+ respond_success "Тэг успешно удален"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_tag
+ @tag = Tag.find(params[:id])
+ end
+end
View
56 app/controllers/backend/towns_controller.rb
@@ -0,0 +1,56 @@
+class Backend::TownsController < BackendController
+
+ # Filters
+ before_filter :init_town, :only => [:edit, :update, :show]
+
+ # Sweepers
+ cache_sweeper :town_sweeper, :only => [:create, :update, :destroy]
+
+ # GET /backend/towns.html ----------------------------------------- HTML
+ def index
+ @towns = Town.find(:all, :order => "name ASC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/towns/1.html --------------------------------------- HTML
+ def show
+ @orgs = @town.orgs.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/towns.html ---------------------------------------- HTML
+ def create
+ town = Town.new
+ town.name = params[:town][:name]
+ town.save!
+ respond_success "Населенный пункт успешно добавлен"
+ rescue
+ respond_error
+ end
+
+ # GET /backend/towns/1/edit.html ---------------------------------- HTML
+ def edit
+ session[:back] = request.env["HTTP_REFERER"]
+ end
+
+ # PUT /backend/towns/1.html -------------------------------------- HTML
+ def update
+ @town.name = params[:town][:name]
+ @town.save!
+ respond_success "Населенный пункт успешно отредактирован", session[:back]
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/towns/1.html ------------------------------------ HTML
+ def destroy
+ Town.delete(params[:id])
+ respond_success "Населенный пункт успешно удален"
+ rescue
+ respond_error
+ end
+
+private
+
+ def init_town
+ @town = Town.find(params[:id])
+ end
+end
View
79 app/controllers/backend/users_controller.rb
@@ -0,0 +1,79 @@
+class Backend::UsersController < BackendController
+
+ # Filters and sweepers
+ before_filter :init_user, :only => [:update, :show, :rewiews, :orgs, :requests, :rights, :add_right]
+
+ # GET /backend/users.html ----------------------------------------- HTML
+ def index
+ @users = User.find(:all, :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/users/1.html --------------------------------------- HTML
+ def show
+ end
+
+ # PUT /backend/users/1.html --------------------------------------- HTML
+ def update
+ user = User.find(params[:id])
+ unless params[:user][:password].blank?
+ if params[:user][:password] == params[:user][:password_confirmation]
+ user.update_attributes!(params[:user])
+ respond_success "Ваши изменения успешно сохранены"
+ else
+ respond_error "Пароли не совпадают"
+ end
+ else
+ user.update_attributes!(:name => params[:user][:name], :email => params[:user][:email])
+ respond_success "Ваши изменения успешно сохранены"
+ end
+ end
+
+ # GET /backend/users/1/rights.html -------------------------------- HTML
+ def rights
+ @rights = @user.rights.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # POST /backend/users/1/add_right.html ---------------------------- HTML
+ def add_right
+ @rights = @user.rights.collect{ |r| r.role_id }.to_a
+ unless @rights.include?(params[:right][:id].to_i)
+ @right = Right.create!( :role_id => params[:right][:id].to_i)
+ @user.rights << @right
+ @user.save!
+ respond_success "Роль успешно присвоена"
+ else
+ respond_success "Роль успешно присвоена"
+ end
+ rescue
+ respond_error
+ end
+
+ # DELETE /backend/users/1/delete_right/1.html --------------------- HTML
+ def delete_right
+ Right.destroy(params[:right_id])
+ respond_success "Роль успешно удалена"
+ rescue
+ respond_error
+ end
+
+ # GET /backend/users/1/orgs.html ---------------------------------- HTML
+ def orgs
+ @orgs = @user.orgs.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/users/1/requests.html ------------------------------ HTML
+ def requests
+ @requests = @user.requests.paginate(:page => params[:page], :per_page => 10)
+ end
+
+ # GET /backend/users/1/rewiews.html ------------------------------- HTML
+ def rewiews
+ @rewiews = @user.rewiews.paginate(:page => params[:page], :per_page => 5)
+ end
+
+private
+
+ def init_user
+ @user = User.find(params[:id])
+ end
+end
View
30 app/controllers/backend_controller.rb
@@ -0,0 +1,30 @@
+class BackendController < ApplicationController
+
+ # TODO: запрет гостям и пользователям вообще видеть любую страницу при запросе к админке просто выдавать 404 страницу
+
+ layout "backend/index"
+
+ # Include libs
+ include ExpireCache
+
+ # Access only admin
+ require_role "admin"
+
+ alias_method :base_redirect_to, :redirect_to
+
+ def redirect_to(options = {}, response_status = {})
+ session[:back] = nil
+ base_redirect_to options
+ end
+
+ def respond_success(msg, return_url = :back)
+ flash[:notice] = msg
+ redirect_to return_url
+ end
+
+ def respond_error(msg = "Извините, произошла ошибка!!!", return_url = :back)
+ flash[:error] = msg
+ redirect_to return_url
+ end
+
+end
View
61 app/controllers/frontend/activities_controller.rb
@@ -0,0 +1,61 @@
+class Frontend::ActivitiesController < FrontendController
+
+ # Access
+ # - all :index
+ # - admin and user :create, :destroy, :delete
+ require_role ["admin", "user"], :only => [:create, :destroy, :delete]
+
+ # Filters
+ before_filter :init_org, :only => [:index, :destroy]
+
+ # Caching index as page
+ caches_page :index
+
+ # GET /orgs/1/activities.html ------------------------------------- HTML
+ def index
+ @categories = @org.categories
+ end
+
+ # POST /orgs/1/activities.html ------------------------------------ HTML
+ # POST /orgs/1/activities/create.html ----------------------------- HTML /for passenger/
+ def create
+ raise Request::NoRequiredFields unless params[:activities]
+ Request.add( params[:org_id], current_user, "activity", "add", { :new_record => params[:activities][0..4] } )
+ respond_success "Спасибо, Ваш запрос отправлен", requests_path
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
+ respond_error
+ rescue Request::NoRequiredFields => e
+ respond_error e.message
+ end
+
+ # DELETE /orgs/1/activities/1.html -------------------------------- HTML
+ def destroy
+ @activity = Activity.get(params[:org_id], params[:id])
+ session[:back] = request.env["HTTP_REFERER"]
+ rescue Activity::RecordNotFound => e
+ respond_error e.message, org_activities_path(params[:org_id])
+ end
+
+ # DELETE /orgs/1/activities/1/delete.html ------------------------- HTML
+ def delete
+ raise Request::NoRequiredFields if !params[:request] || params[:request][:msg].blank?
+ Request.add( params[:org_id], current_user, "activity", "delete", { :delete_record_id => params[:id], :msg => params[:request][:msg]} )
+ respond_success "Спасибо, Ваш запрос отправлен", requests_path
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
+ respond_error "Извините, произошла ошибка!!!", org_activities_path(params[:org_id])
+ rescue Request::NoRequiredFields => e
+ respond_error e.message, org_activities_path(params[:org_id])
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+
+ def respond_success(msg, return_url = :back)
+ init_session_variable
+ flash[:notice] = msg
+ redirect_to return_url
+ end
+end
View
23 app/controllers/frontend/categories_controller.rb
@@ -0,0 +1,23 @@
+class Frontend::CategoriesController < FrontendController
+
+ # Caching show action as page
+ caches_page :show
+
+ # GET /categories/1.html ---------------------------------------- HTML
+ # GET /categories/1.js ------------------------------------------ AJAX
+ # GET /categories/1/page/1.html --------------------------------- HTML
+ def show
+ @current_category = Category.find(params[:id])
+ respond_to do |format|
+ format.html {
+ @orgs = @current_category.orgs.paginate(:page => params[:page], :per_page => 10, :order => "recommended DESC", :include => [:town,:street, :rewiews])
+ }
+ format.js {
+ @categories = @current_category.children
+ render :partial => 'categories',
+ :layout => false,
+ :locals => {:categories => @categories, :categories_size => Category.count_parent_categories-1, :category_id => params[:id]}
+ }
+ end
+ end
+end
View
63 app/controllers/frontend/favorites_controller.rb
@@ -0,0 +1,63 @@
+class Frontend::FavoritesController < FrontendController
+
+ # Access
+ # - admin and user :index, :create, :destroy
+ require_role ["admin", "user"]
+
+ # Filters
+ before_filter :init_org, :only => :create
+
+ # Cache sweepers
+ cache_sweeper :favorite_sweeper, :only => [:create, :destroy]
+
+ # GET /profile/favorites.html ------------------------------------- HTML
+ # GET /profile/favorites/page/1.html ------------------------------ HTML
+ def index
+ unless read_fragment("favorite/user_#{current_user.id}/page_#{params[:page] || 1}")
+ @favorites = Favorite.find(:all, :conditions => ["user_id = ?", current_user.id], :order => "created_at DESC").paginate(:page => params[:page], :per_page => 10)
+ end
+ end
+
+ # TODO: Сделать возможным добавление в избранное без включенного JS
+ # POST /orgs/1/favorites.js --------------------------------------- AJAX
+ def create
+ Favorite.add!( params[:org_id], current_user.id )
+ respond_success "Организация успешно добавлена в Избранное"
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
+ respond_error
+ rescue Favorite::RecordExist => e
+ respond_error e.message
+ end
+
+ # DELETE /orgs/1/favorites/1.html --------------------------------- HTML
+ def destroy
+ Favorite.delete_all( ["org_id = ? AND user_id = ?", params[:org_id], params[:id]] )
+ respond_success "Организация успешно удалена из Избранного"
+ end
+
+ private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+
+ def respond_success(msg)
+ respond_to do |format|
+ format.html {
+ flash[:notice] = msg
+ redirect_to :back
+ }
+ format.js { render :partial => "success", :layout => false, :locals => {:msg => msg}}
+ end
+ end
+
+ def respond_error(msg = "Извините произошла ошибка!!!")
+ respond_to do |format|
+ format.html {
+ flash[:notice] = msg
+ redirect_to :back
+ }
+ format.js { render :partial => 'error', :layout => false, :locals => {:msg => msg}}
+ end
+ end
+end
View
39 app/controllers/frontend/images_controller.rb
@@ -0,0 +1,39 @@
+class Frontend::ImagesController < FrontendController
+
+ # Access
+ # - all :index
+ # - admin and user :create
+ require_role ["admin", "user"], :only => :create
+
+ # Cache sweepers
+ cache_sweeper :image_sweeper, :only => :create
+
+ # Filters
+ before_filter :init_org
+
+ # Caching index action as page
+ caches_page :index
+
+ # GET /orgs/1/images.html -------------------------------------------- HTML
+ def index
+ @images = @org.images
+ end
+
+ # POST /orgs/1/images.html ------------------------------------------- HTML
+ # POST /orgs/1/images/create.html ------------------------------------ HTML /for passenger/
+ def create
+ raise Image::NoRequiredFields if params[:image].blank?
+ @org.images.create!(params[:image])
+ respond_success "Спасибо, Ваш запрос отправлен"
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
+ respond_error
+ rescue Image::NoRequiredFields => e
+ respond_error e.message
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+end
View
9 app/controllers/frontend/index_controller.rb
@@ -0,0 +1,9 @@
+class Frontend::IndexController < FrontendController
+
+ # Caching index action as page
+ caches_page :index
+
+ # GET / ----------------------------------------------------------- HTML
+ def index
+ end
+end
View
38 app/controllers/frontend/maps_controller.rb
@@ -0,0 +1,38 @@
+class Frontend::MapsController < FrontendController
+
+ # Access
+ # - all :index
+ # - admin and user :index, :create
+ require_role ["admin", "user"], :only => [:index, :create]
+
+ # Filters
+ before_filter :init_org
+
+ # Caching index action as page
+ # caches_page :index
+
+ # GET /orgs/1/map.html -------------------------------------------- HTML
+ def index
+ end
+
+ # POST /orgs/1/map.html ------------------------------------------- HTMl
+ # POST /orgs/1/map/create.html ------------------------------------ HTML /for passenger/
+ def create
+ raise Marker::NoRequiredFields if params[:markers].blank?
+ # params[:markers].each do |marker|
+ # @org.markers.create!(marker)
+ # end
+ Request.add( params[:org_id], current_user, "marker", "add", { :markers => params[:markers][0..2] })
+ respond_success "Спасибо, Ваш запрос отправлен"
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved => e
+ respond_error
+ rescue Marker::NoRequiredFields => e
+ respond_error e.message
+ end
+
+private
+
+ def init_org
+ @org = Org.find(params[:org_id])
+ end
+end
View
84 app/controllers/frontend/orgs_controller.rb
@@ -0,0 +1,84 @@
+class Frontend::OrgsController < FrontendController
+
+ layout "frontend/index"
+
+ # Access
+ # - all :show
+ # - admin and user :create, :new, :update, :edit, :destroy, :delete
+ require_role ["admin", "user"], :except => :show
+
+ # Filters
+ before_filter :init_org, :only => [:show, :edit, :update, :destroy, :delete]