orange-more 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/README.markdown +17 -0
  2. data/lib/orange-more.rb +23 -0
  3. data/lib/orange-more/administration.rb +1 -0
  4. data/lib/orange-more/administration/assets/css/admin.css +286 -0
  5. data/lib/orange-more/administration/assets/css/blueprint-ie.css +35 -0
  6. data/lib/orange-more/administration/assets/css/blueprint-print.css +29 -0
  7. data/lib/orange-more/administration/assets/css/blueprint.css +257 -0
  8. data/lib/orange-more/administration/assets/js/jquery.js +152 -0
  9. data/lib/orange-more/administration/cartons/site.rb +7 -0
  10. data/lib/orange-more/administration/cartons/site_carton.rb +12 -0
  11. data/lib/orange-more/administration/cartons/user.rb +27 -0
  12. data/lib/orange-more/administration/middleware/access_control.rb +156 -0
  13. data/lib/orange-more/administration/middleware/site_load.rb +25 -0
  14. data/lib/orange-more/administration/plugin.rb +23 -0
  15. data/lib/orange-more/administration/resources/admin_resource.rb +27 -0
  16. data/lib/orange-more/administration/resources/site_resource.rb +10 -0
  17. data/lib/orange-more/administration/resources/user_resource.rb +40 -0
  18. data/lib/orange-more/administration/templates/admin.haml +25 -0
  19. data/lib/orange-more/administration/views/openid_login.haml +14 -0
  20. data/lib/orange-more/administration/views/users/create.haml +10 -0
  21. data/lib/orange-more/administration/views/users/edit.haml +15 -0
  22. data/lib/orange-more/adverts.rb +1 -0
  23. data/lib/orange-more/adverts/cartons/adverts_carton.rb +14 -0
  24. data/lib/orange-more/adverts/plugin.rb +13 -0
  25. data/lib/orange-more/adverts/resources/adverts_resource.rb +27 -0
  26. data/lib/orange-more/adverts/views/adverts/adverts.haml +2 -0
  27. data/lib/orange-more/analytics.rb +1 -0
  28. data/lib/orange-more/analytics/middleware/analytics.rb +30 -0
  29. data/lib/orange-more/analytics/plugin.rb +11 -0
  30. data/lib/orange-more/analytics/resources/analytics_resource.rb +42 -0
  31. data/lib/orange-more/assets.rb +1 -0
  32. data/lib/orange-more/assets/cartons/asset_carton.rb +27 -0
  33. data/lib/orange-more/assets/plugin.rb +13 -0
  34. data/lib/orange-more/assets/resources/asset_resource.rb +115 -0
  35. data/lib/orange-more/assets/views/assets/change.haml +1 -0
  36. data/lib/orange-more/assets/views/assets/create.haml +13 -0
  37. data/lib/orange-more/assets/views/assets/insert.haml +1 -0
  38. data/lib/orange-more/blog.rb +1 -0
  39. data/lib/orange-more/blog/cartons/blog.rb +8 -0
  40. data/lib/orange-more/blog/cartons/blog_post.rb +60 -0
  41. data/lib/orange-more/blog/plugin.rb +14 -0
  42. data/lib/orange-more/blog/resources/blog_post_resource.rb +54 -0
  43. data/lib/orange-more/blog/resources/blog_resource.rb +104 -0
  44. data/lib/orange-more/blog/views/blog/blog_archive_view.haml +6 -0
  45. data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +12 -0
  46. data/lib/orange-more/blog/views/blog/blog_post_view.haml +4 -0
  47. data/lib/orange-more/blog/views/blog/sitemap_row.haml +14 -0
  48. data/lib/orange-more/blog/views/blog_posts/edit.haml +8 -0
  49. data/lib/orange-more/blog/views/blog_posts/show.haml +4 -0
  50. data/lib/orange-more/cloud.rb +1 -0
  51. data/lib/orange-more/cloud/plugin.rb +10 -0
  52. data/lib/orange-more/cloud/resources/cloud_resource.rb +21 -0
  53. data/lib/orange-more/contactforms.rb +1 -0
  54. data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +15 -0
  55. data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +6240 -0
  56. data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +660 -0
  57. data/lib/orange-more/contactforms/assets/js/lib/jquery.js +4376 -0
  58. data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +122 -0
  59. data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +12 -0
  60. data/lib/orange-more/contactforms/plugin.rb +13 -0
  61. data/lib/orange-more/contactforms/resources/contactforms_resource.rb +56 -0
  62. data/lib/orange-more/contactforms/views/contactforms/contactform.haml +20 -0
  63. data/lib/orange-more/debugger.rb +1 -0
  64. data/lib/orange-more/debugger/assets/css/debug_bar.css +46 -0
  65. data/lib/orange-more/debugger/middleware/debugger.rb +50 -0
  66. data/lib/orange-more/debugger/plugin.rb +12 -0
  67. data/lib/orange-more/debugger/views/debug_bar.haml +87 -0
  68. data/lib/orange-more/disqus.rb +1 -0
  69. data/lib/orange-more/disqus/plugin.rb +11 -0
  70. data/lib/orange-more/disqus/resources/disqus_resource.rb +9 -0
  71. data/lib/orange-more/disqus/views/disqus/comment_thread.haml +7 -0
  72. data/lib/orange-more/donations.rb +1 -0
  73. data/lib/orange-more/donations/cartons/donation_carton.rb +9 -0
  74. data/lib/orange-more/donations/plugin.rb +12 -0
  75. data/lib/orange-more/donations/resources/donations_resource.rb +51 -0
  76. data/lib/orange-more/donations/views/donations/donate_form.haml +21 -0
  77. data/lib/orange-more/donations/views/donations/donate_thanks.haml +2 -0
  78. data/lib/orange-more/donations/views/donations/paypal_form.haml +13 -0
  79. data/lib/orange-more/events.rb +1 -0
  80. data/lib/orange-more/events/assets/js/events.js +55 -0
  81. data/lib/orange-more/events/cartons/orange_calendar.rb +8 -0
  82. data/lib/orange-more/events/cartons/orange_event.rb +60 -0
  83. data/lib/orange-more/events/plugin.rb +14 -0
  84. data/lib/orange-more/events/resources/calendar_resource.rb +33 -0
  85. data/lib/orange-more/events/resources/event_resource.rb +147 -0
  86. data/lib/orange-more/events/views/calendar/calendar.haml +8 -0
  87. data/lib/orange-more/events/views/events/create.haml +55 -0
  88. data/lib/orange-more/events/views/events/edit.haml +59 -0
  89. data/lib/orange-more/events/views/events/list.haml +13 -0
  90. data/lib/orange-more/events/views/events/show.haml +4 -0
  91. data/lib/orange-more/events/views/events/table_row.haml +17 -0
  92. data/lib/orange-more/members.rb +1 -0
  93. data/lib/orange-more/members/cartons/member_carton.rb +38 -0
  94. data/lib/orange-more/members/plugin.rb +13 -0
  95. data/lib/orange-more/members/resources/members_resource.rb +327 -0
  96. data/lib/orange-more/members/views/members/create.haml +12 -0
  97. data/lib/orange-more/members/views/members/edit.haml +15 -0
  98. data/lib/orange-more/members/views/members/live.show.haml +1 -0
  99. data/lib/orange-more/members/views/members/login.haml +17 -0
  100. data/lib/orange-more/members/views/members/logout.haml +1 -0
  101. data/lib/orange-more/members/views/members/profile.haml +50 -0
  102. data/lib/orange-more/members/views/members/register.haml +37 -0
  103. data/lib/orange-more/news.rb +1 -0
  104. data/lib/orange-more/news/cartons/news.rb +12 -0
  105. data/lib/orange-more/news/plugin.rb +13 -0
  106. data/lib/orange-more/news/resources/news_resource.rb +83 -0
  107. data/lib/orange-more/news/views/news/archive.haml +14 -0
  108. data/lib/orange-more/news/views/news/edit.haml +7 -0
  109. data/lib/orange-more/news/views/news/latest.haml +8 -0
  110. data/lib/orange-more/news/views/news/sitemap_row.haml +14 -0
  111. data/lib/orange-more/pages.rb +1 -0
  112. data/lib/orange-more/pages/cartons/page_carton.rb +14 -0
  113. data/lib/orange-more/pages/cartons/page_version_carton.rb +12 -0
  114. data/lib/orange-more/pages/plugin.rb +13 -0
  115. data/lib/orange-more/pages/resources/page_resource.rb +179 -0
  116. data/lib/orange-more/pages/views/pages/edit.haml +34 -0
  117. data/lib/orange-more/pages/views/pages/show.haml +6 -0
  118. data/lib/orange-more/sitemap.rb +1 -0
  119. data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
  120. data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
  121. data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
  122. data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
  123. data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
  124. data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
  125. data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
  126. data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
  127. data/lib/orange-more/sitemap/assets/js/sitemap.js +11 -0
  128. data/lib/orange-more/sitemap/cartons/route.rb +44 -0
  129. data/lib/orange-more/sitemap/middleware/flex_router.rb +25 -0
  130. data/lib/orange-more/sitemap/plugin.rb +17 -0
  131. data/lib/orange-more/sitemap/resources/sitemap_resource.rb +295 -0
  132. data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +30 -0
  133. data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +12 -0
  134. data/lib/orange-more/sitemap/views/sitemap/list.haml +4 -0
  135. data/lib/orange-more/sitemap/views/sitemap/one_level.haml +7 -0
  136. data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +15 -0
  137. data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +14 -0
  138. data/lib/orange-more/sitemap/views/sitemap/table_row.haml +30 -0
  139. data/lib/orange-more/sitemap/views/sitemap/two_level.haml +13 -0
  140. data/lib/orange-more/slices.rb +1 -0
  141. data/lib/orange-more/slices/middleware/radius_parser.rb +24 -0
  142. data/lib/orange-more/slices/plugin.rb +15 -0
  143. data/lib/orange-more/slices/resources/radius.rb +117 -0
  144. data/lib/orange-more/slices/resources/slices.rb +35 -0
  145. data/lib/orange-more/subsites.rb +1 -0
  146. data/lib/orange-more/subsites/cartons/subsite.rb +8 -0
  147. data/lib/orange-more/subsites/middleware/subsite_load.rb +29 -0
  148. data/lib/orange-more/subsites/plugin.rb +17 -0
  149. data/lib/orange-more/subsites/resources/subsite_resource.rb +54 -0
  150. data/lib/orange-more/subsites/views/subsites/index.haml +2 -0
  151. data/lib/orange-more/testimonials.rb +1 -0
  152. data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +15 -0
  153. data/lib/orange-more/testimonials/plugin.rb +13 -0
  154. data/lib/orange-more/testimonials/resources/testimonials_resource.rb +42 -0
  155. data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +4 -0
  156. data/spec/orange-core/application_spec.rb +183 -0
  157. data/spec/orange-core/carton_spec.rb +136 -0
  158. data/spec/orange-core/core_spec.rb +248 -0
  159. data/spec/orange-core/magick_spec.rb +96 -0
  160. data/spec/orange-core/middleware/base_spec.rb +38 -0
  161. data/spec/orange-core/middleware/globals_spec.rb +3 -0
  162. data/spec/orange-core/middleware/rerouter_spec.rb +3 -0
  163. data/spec/orange-core/middleware/restful_router_spec.rb +3 -0
  164. data/spec/orange-core/middleware/route_context_spec.rb +3 -0
  165. data/spec/orange-core/middleware/route_site_spec.rb +3 -0
  166. data/spec/orange-core/middleware/show_exceptions_spec.rb +3 -0
  167. data/spec/orange-core/middleware/static_file_spec.rb +3 -0
  168. data/spec/orange-core/middleware/static_spec.rb +3 -0
  169. data/spec/orange-core/mock/mock_app.rb +16 -0
  170. data/spec/orange-core/mock/mock_carton.rb +43 -0
  171. data/spec/orange-core/mock/mock_core.rb +2 -0
  172. data/spec/orange-core/mock/mock_middleware.rb +25 -0
  173. data/spec/orange-core/mock/mock_mixins.rb +19 -0
  174. data/spec/orange-core/mock/mock_model_resource.rb +47 -0
  175. data/spec/orange-core/mock/mock_pulp.rb +24 -0
  176. data/spec/orange-core/mock/mock_resource.rb +26 -0
  177. data/spec/orange-core/mock/mock_router.rb +10 -0
  178. data/spec/orange-core/orange_spec.rb +19 -0
  179. data/spec/orange-core/packet_spec.rb +203 -0
  180. data/spec/orange-core/resource_spec.rb +96 -0
  181. data/spec/orange-core/resources/mapper_spec.rb +5 -0
  182. data/spec/orange-core/resources/model_resource_spec.rb +246 -0
  183. data/spec/orange-core/resources/parser_spec.rb +5 -0
  184. data/spec/orange-core/resources/routable_resource_spec.rb +5 -0
  185. data/spec/orange-core/spec_helper.rb +53 -0
  186. data/spec/orange-core/stack_spec.rb +232 -0
  187. data/spec/stats.rb +182 -0
  188. metadata +312 -0
@@ -0,0 +1,9 @@
1
+ module Orange
2
+ class DisqusResource < Orange::Resource
3
+ call_me :disqus
4
+ def comment_thread(packet, opts = {})
5
+ opts.merge!(:resource => self)
6
+ orange[:parser].haml("comment_thread.haml", packet, opts)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ .disqus_comments
2
+ - if packet['orange.globals'][:development_mode]
3
+ %script{:type => 'text/javascript'} var disqus_developer = 1;
4
+ #disqus_thread
5
+ %script{:type => 'text/javascript', :src => 'http://disqus.com/forums/orangesparkleball/embed.js'}
6
+ %noscript
7
+ %a{:href => 'http://disqus.com/forums/orangesparkleball/?url=ref'} View the discussion thread
@@ -0,0 +1 @@
1
+ require File.join('orange-more', 'donations', 'plugin')
@@ -0,0 +1,9 @@
1
+ class OrangeDonation < Orange::Carton
2
+ id
3
+ admin do
4
+ title :donor_name, :length => 255
5
+ text :donor_company, :length => 255
6
+ text :donor_email, :length => 255
7
+ text :donation_amount
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
2
+ Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
3
+
4
+ module Orange::Plugins
5
+ class Donations < Base
6
+ views_dir File.join(File.dirname(__FILE__), 'views')
7
+
8
+ resource Orange::DonationsResource.new
9
+ end
10
+ end
11
+
12
+ Orange.plugin(Orange::Plugins::Donations.new)
@@ -0,0 +1,51 @@
1
+ module Orange
2
+ class DonationsResource < Orange::ModelResource
3
+ use OrangeDonation
4
+ call_me :donations
5
+ def stack_init
6
+ orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Donations')
7
+ orange[:radius].define_tag "donations" do |tag|
8
+ template = tag.attr["template"] || "donate_form"
9
+ orange[:donations].form(tag.locals.packet, {:template => template})
10
+ end
11
+ end
12
+
13
+ def form(packet, opts = {})
14
+ template = opts[:template].to_sym || :donate_form
15
+ packet['route.return_path'] = packet.request.path.to_s
16
+ do_view(packet, template, opts)
17
+ end
18
+
19
+ def donate_cancel(packet, opts = {})
20
+ id = packet.session['donation_id']
21
+ m = model_class.get(id)
22
+ m.destroy!
23
+ packet.flash['error'] = "There was an issue completing the process on Paypal."
24
+ packet.reroute((packet.flash('reroute.to') || '/'))
25
+ end
26
+
27
+ def process(packet, opts = {})
28
+ params = packet.request.params
29
+ route = params.delete('r')
30
+ params['donation_amount'] = params['donation_amount'].sub(/\$/, '')
31
+ if params['donor_phone'] == '' && packet.request.post? && params['donation_amount'] != '' && params['donation_amount'].to_f > 0
32
+ template = "paypal_form"
33
+ params.delete('donor_phone')
34
+ obj = self.new(packet, {:no_reroute => true, :params => params})
35
+ packet.session['donation_id'] = obj.id
36
+ packet.flash['reroute.to'] = route
37
+ opts[:donation_amount] = params['donation_amount']
38
+ opts[:paypal_id] = orange.options['paypal_id'] || ''
39
+ do_view(packet, template, opts)
40
+ else
41
+ packet.flash['error'] = "An error has occurred. Please try your submission again."
42
+ packet.reroute(route)
43
+ end
44
+ end
45
+
46
+ def donate_success(packet, opts = {})
47
+ template = "donate_thanks"
48
+ do_view(packet, template, opts)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ :javascript
2
+ $(function(){
3
+ $('#donate_form').validate();
4
+ });
5
+ %p
6
+ - if(flash['error'])
7
+ .error= flash('error')
8
+ %form{ :class => 'donate_form', :id => 'donate_form', :action => route_to(:donations, :process), :method => 'POST' }
9
+ %label{ :for => 'donor_name'} Your Name
10
+ %input{ :type => 'text', :minlength => '4', :maxlength => '80', :id => 'donor_name', :name => 'donor_name', :class => 'required' }
11
+ %div.donor_phone
12
+ %label{ :for => 'donor_phone'} Your Phone
13
+ %input{ :type => 'text', :minlength => '4', :maxlength => '80', :id => 'donor_phone', :name => 'donor_phone', :value => '' }
14
+ %label{ :for => 'donor_company'} Your Company
15
+ %input{ :type => 'text', :minlength => '4', :maxlength => '180', :id => 'donor_company', :name => 'donor_company', :value => '' }
16
+ %label{ :for => 'donor_email'} Your E-mail
17
+ %input{ :type => 'text', :class => 'email', :id => 'donor_email', :name => 'donor_email' }
18
+ %label{ :for => 'donation_amount'} Donation Amount: $
19
+ %input{ :type => 'text', :class => 'donation_amount', :id => 'donation_amount', :name => 'donation_amount' }
20
+ %input{ :type => 'submit', :value => 'Submit' }
21
+ %input{ :type => 'hidden', :id => 'r', :name => 'r', :value => packet['route.return_path'] }
@@ -0,0 +1,2 @@
1
+ %h3 Thank You!
2
+ %p Thanks for your donation!
@@ -0,0 +1,13 @@
1
+ %h3 Redirecting to PayPal...
2
+ %form{ :id => 'pform', :name => '_xclick', :action => 'https://www.paypal.com/cgi-bin/webscr', :method => "post" }
3
+ %input{ :type => 'hidden', :name => 'cmd', :value => "_donations" }
4
+ %input{ :type => 'hidden', :name => 'business', :value => paypal_id }
5
+ %input{ :type => 'hidden', :name => 'item_name', :value => "WNSF Donation" }
6
+ %input{ :type => 'hidden', :name => 'currency_code', :value => "USD" }
7
+ %input{ :type => 'hidden', :name => 'amount', :value => donation_amount }
8
+ %input{ :type => 'hidden', :name => 'return', :value => 'http://'+packet['route.site_url'] + route_to(:donations, :donate_success) }
9
+ %input{ :type => 'hidden', :name => 'cancel_return', :value => 'http://'+packet['route.site_url'] + route_to(:donations, :donate_cancel)}
10
+ :javascript
11
+ $(function(){
12
+ $('#pform').submit();
13
+ })
@@ -0,0 +1 @@
1
+ require File.join('orange-more', 'events', 'plugin')
@@ -0,0 +1,55 @@
1
+ $(function(){
2
+ $('.new-venue').hide();
3
+ $('.show-venue-details').toggle(venue_details_show, venue_details_hide);
4
+ $("#events-venue").change(function(){
5
+ if($(this).val() == "new"){
6
+ venue_details_blank();
7
+ if($('.new-venue').css('display') == 'none') $('.show-venue-details').click();
8
+ }
9
+ else{
10
+ load_venue_details($(this).val());
11
+ }
12
+ });
13
+ $('input[name*=link_to_eventbrite]').change(function(){
14
+ if($(this).attr('checked')){
15
+ $('p.eventbrite-link').show();
16
+ }
17
+ else{
18
+ $('p.eventbrite-link').hide();
19
+ }
20
+ });
21
+ $('#events-eventbrite-id').change(function(){
22
+ load_event_details($(this).val());
23
+ });
24
+ $("input[name*='location']").change(function(){$("#events-venue").val("new")});
25
+ });
26
+
27
+ function venue_details_show(){
28
+ $('.show-venue-details').text('Hide');
29
+ $('.new-venue').show();
30
+ }
31
+
32
+ function venue_details_hide(){
33
+ $('.show-venue-details').text('(Details)');
34
+ $('.new-venue').hide();
35
+ }
36
+
37
+ function load_venue_details(id){
38
+ var obj = venues[id];
39
+ $("input[name*=location_name]").val(obj.name);
40
+ $("input[name*=location_address]").val(obj.address);
41
+ $("input[name*=location_address2]").val(obj.address_2);
42
+ $("input[name*=location_city]").val(obj.city);
43
+ $("input[name*=location_state]").val(obj.region);
44
+ $("input[name*=location_zip]").val(obj.postal_code);
45
+ }
46
+
47
+ function load_event_details(id){
48
+ var obj = events[id];
49
+ $("input[name*='events[name]']").val(obj.title);
50
+ $("textarea[name*=description]").val(obj.description);
51
+ }
52
+
53
+ function venue_details_blank(){
54
+ $("input[name*='location']").val('');
55
+ }
@@ -0,0 +1,8 @@
1
+ class OrangeCalendar < Orange::SiteCarton
2
+ id
3
+ admin do
4
+ title :name
5
+ boolean :main, :default => false, :display_name =>'Main Calendar?'
6
+ end
7
+ has n, :events, "OrangeEvent"
8
+ end
@@ -0,0 +1,60 @@
1
+ class OrangeEvent < Orange::Carton
2
+ id
3
+ admin do
4
+ title :name
5
+ text :location_name
6
+ text :location_address
7
+ text :location_address2
8
+ text :location_city
9
+ text :location_state
10
+ text :location_zip
11
+ boolean :link_to_eventbrite, :default => false
12
+ text :eventbrite_id
13
+ fulltext :blurb
14
+ fulltext :description
15
+ end
16
+ orange do
17
+ time :starts
18
+ time :ends
19
+ end
20
+
21
+ def starts_time
22
+ self.starts.strftime("%I:%M %p")
23
+ end
24
+ def starts_date
25
+ self.starts.strftime("%m/%d/%Y")
26
+ end
27
+ def ends_time
28
+ self.ends.strftime("%I:%M %p")
29
+ end
30
+ def ends_date
31
+ self.ends.strftime("%m/%d/%Y")
32
+ end
33
+ def date_attr(attribute, datestr = false)
34
+ time_attr(attribute, false, datestr)
35
+ end
36
+
37
+ def attribute_time_get(attribute)
38
+ attribute_get(attribute) || Time.now
39
+ end
40
+ def time_attr(attribute, timestr = false, datestr = false)
41
+ date = datestr || attribute_time_get(attribute).strftime("%m/%d/%Y")
42
+ time = timestr || attribute_time_get(attribute).strftime("%I:%M %p")
43
+ attribute_set(attribute, Time.parse(date + " " + time))
44
+ end
45
+
46
+ def starts_time=(time)
47
+ time_attr(:starts, time)
48
+ end
49
+ def starts_date=(date)
50
+ date_attr(:starts, date)
51
+ end
52
+ def ends_time=(time)
53
+ time_attr(:ends, time)
54
+ end
55
+ def ends_date=(date)
56
+ date_attr(:ends, date)
57
+ end
58
+
59
+ belongs_to :calendar, "OrangeCalendar", :child_key => [:orange_calendar_id]
60
+ end
@@ -0,0 +1,14 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
2
+ Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
3
+
4
+ module Orange::Plugins
5
+ class Events < Base
6
+ views_dir File.join(File.dirname(__FILE__), 'views')
7
+ assets_dir File.join(File.dirname(__FILE__), 'assets')
8
+ resource Orange::CalendarResource.new
9
+ resource Orange::EventResource.new
10
+ end
11
+ end
12
+
13
+ Orange.plugin(Orange::Plugins::Events.new)
14
+
@@ -0,0 +1,33 @@
1
+ module Orange
2
+ class CalendarResource < ModelResource
3
+ use OrangeCalendar
4
+ call_me :calendar
5
+ def stack_init
6
+ orange[:admin, true].add_link("Settings", :resource => @my_orange_name, :text => 'Calendars')
7
+ orange[:radius].define_tag "calendar" do |tag|
8
+ template = tag.attr["template"] || false
9
+ if tag.attr["name"]
10
+ calendars = tag.attr["name"].split.map{|x| model_class.first(:name => x)}
11
+ unless tag.attr["main"] && tag.attr["main"] == "false"
12
+ calendars << model_class.all(:main => true)
13
+ end
14
+ else
15
+ calendars = model_class.all
16
+ end
17
+ events = OrangeEvent.all(:calendar => calendars, :starts.gt => Time.now, :order => [:starts.asc])
18
+ orange[:calendar].calendar(tag.locals.packet, {:list => events, :template => template})
19
+ end
20
+ end
21
+
22
+ def calendar(packet, opts = {})
23
+ template = (opts[:template] || "calendar").to_sym
24
+ do_list_view(packet, template, opts)
25
+ end
26
+
27
+ def afterNew(packet, obj, opts = {})
28
+ obj.orange_site = packet['site'] unless obj.orange_site
29
+ end
30
+
31
+
32
+ end
33
+ end
@@ -0,0 +1,147 @@
1
+ require 'eventbright'
2
+ require 'json'
3
+ module Orange
4
+ class EventResource < ModelResource
5
+ # For integration with Eventbrite. Application key needs user
6
+ # key for full access.
7
+ ORANGE_EVENTBRITE_KEY = "ODQ5MDMzZWQwOWRl"
8
+
9
+ use OrangeEvent
10
+ call_me :events
11
+
12
+ def stack_init
13
+ orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Events')
14
+ EventBright.setup(ORANGE_EVENTBRITE_KEY)
15
+ options[:eventbrite_key] = orange.options['eventbrite_key'] || false
16
+ end
17
+
18
+ def eventbrite_user
19
+ return false unless options[:eventbrite_key]
20
+ begin
21
+ @eventbrite_user = EventBright::User.new(options[:eventbrite_key])
22
+ rescue # If EventBright gem throws error, we're probably having issues connecting
23
+ false
24
+ end
25
+ end
26
+
27
+ def find_extras(packet, mode, opts = {})
28
+ extras = {:calendars => OrangeCalendar.all}
29
+ case mode
30
+ when :create, :edit
31
+ ev = eventbrite_venues
32
+ ee = eventbrite_events
33
+ ev_json = {} if ev
34
+ ev.each{|v| ev_json[v.id] = v.attributes.merge(:id => v.id)} if ev
35
+ ee_json = {} if ee
36
+ ee.each{|v| ee_json[v.id] = v.attributes.merge(:id => v.id).reject{|k,v| [:venue, :organizer].include? k}} if ee
37
+ extras.merge!(:eventbrite_venues => ev, :venues_json => ev_json.to_json,
38
+ :eventbrite_events => ee, :events_json => ee_json.to_json
39
+ ) if options[:eventbrite_key]
40
+
41
+ end
42
+ extras
43
+ end
44
+
45
+ def synchronize_attendees(packet, params = {})
46
+ no_reroute = params.delete(:no_reroute)
47
+ params = params.with_defaults(:resource_id => packet['route.resource_id'])
48
+ if packet.request.post? && orange.loaded?(:members) &&
49
+ event_orange = model_class.get(params[:resource_id])
50
+ event = eventbrite_user.events.select{|e| e.id.to_s == event_orange.eventbrite_id}.first
51
+ orange[:members, true].add_attendee_group(packet, "Eventbrite Attendee", "#{event.title} - #{event.id}")
52
+ emails = event.attendees.map{|a| a.email}
53
+ orange[:members, true].batch_update_interest_mailchimp(packet, emails, "Eventbrite Attendee", "#{event.title} - #{event.id}")
54
+ end
55
+ packet.reroute(@my_orange_name, :orange, packet['route.resource_id'], 'edit') unless no_reroute
56
+ end
57
+
58
+ # Todo - eventbrite crashes when date in past
59
+ def beforeNew(packet, params = {})
60
+ eventbrite_synchronize(packet, params)
61
+ true
62
+ end
63
+
64
+ # Todo - eventbrite crashes when date in past
65
+ def beforeSave(packet, model, params = {})
66
+ eventbrite_synchronize(packet, params)
67
+ true
68
+ end
69
+
70
+ def eventbrite_synchronize(packet, params = {})
71
+ venue_id = params.delete('orange_venue_id')
72
+ if params['link_to_eventbrite'] != "0"
73
+ if venue_id == "new"
74
+ v = EventBright::Venue.new(eventbrite_user)
75
+ v.organizer_id = eventbrite_user.organizers.first.id
76
+ else
77
+ v = eventbrite_user.venues.select{|v| v.id == venue_id.to_i }.first
78
+ end
79
+ update_venue(v, params)
80
+ if params['eventbrite_id'] == "new"
81
+ e = EventBright::Event.new(eventbrite_user)
82
+ e.organizer = eventbrite_user.organizers.first
83
+ else
84
+ e = eventbrite_user.events.select{|e| e.id == params['eventbrite_id'].to_i }.first
85
+ end
86
+ params['eventbrite_id'] = update_event(e, params, v)
87
+ else
88
+ params['eventbrite_id'] = nil
89
+ end
90
+ params
91
+ end
92
+
93
+ def update_event(event, params, venue)
94
+ event.venue = venue
95
+ event.title = params["name"]
96
+ event.description = params["description"]
97
+ event.start_date = params["starts_date"] + " " + params["starts_time"]
98
+ event.end_date = params["ends_date"] + " " + params["ends_time"]
99
+ if(event.start_date > event.end_date)
100
+ raise "An event can't end before it starts."
101
+ else
102
+ event.status = "live"
103
+ event.save
104
+ end
105
+ return event.id
106
+ end
107
+
108
+ def update_venue(venue, params)
109
+ venue.name = params["location_name"]
110
+ venue.address = params["location_address"]
111
+ venue.address_2 = params["location_address2"]
112
+ venue.city = params["location_city"]
113
+ venue.region = params["location_state"]
114
+ venue.postal_code = params["location_zip"]
115
+ venue.country_code = "US"
116
+ venue.save
117
+ end
118
+
119
+ def find_list(packet, mode, opts = {})
120
+ model_class.all(:order => [:starts.desc]) || []
121
+ end
122
+
123
+ def post_to_eventbrite
124
+
125
+ end
126
+
127
+ def eventbrite_venues
128
+ list = []
129
+ begin
130
+ list = eventbrite_user.venues
131
+ rescue
132
+ return false
133
+ end
134
+ list
135
+ end
136
+
137
+ def eventbrite_events
138
+ list = []
139
+ begin
140
+ list = eventbrite_user.events
141
+ rescue
142
+ return false
143
+ end
144
+ list
145
+ end
146
+ end
147
+ end