cama_subscriber 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/controllers/plugins/cama_subscriber/admin_controller.rb +13 -0
  5. data/app/controllers/plugins/cama_subscriber/front_controller.rb +101 -0
  6. data/app/controllers/plugins/cama_subscriber/groups_controller.rb +46 -0
  7. data/app/controllers/plugins/cama_subscriber/items_controller.rb +56 -0
  8. data/app/controllers/plugins/cama_subscriber/promotions_controller.rb +94 -0
  9. data/app/helpers/plugins/cama_subscriber/main_helper.rb +35 -0
  10. data/app/models/plugins/cama_subscriber/group.rb +5 -0
  11. data/app/models/plugins/cama_subscriber/group_item.rb +4 -0
  12. data/app/models/plugins/cama_subscriber/item.rb +43 -0
  13. data/app/models/plugins/cama_subscriber/promotion.rb +27 -0
  14. data/app/models/plugins/cama_subscriber/promotion_group.rb +4 -0
  15. data/app/models/plugins/cama_subscriber/promotion_item.rb +11 -0
  16. data/app/models/plugins/cama_subscriber.rb +13 -0
  17. data/app/views/plugins/cama_subscriber/admin/index.html.erb +9 -0
  18. data/app/views/plugins/cama_subscriber/admin/settings.html.erb +27 -0
  19. data/app/views/plugins/cama_subscriber/front/index.html.erb +2 -0
  20. data/app/views/plugins/cama_subscriber/groups/form.html.erb +17 -0
  21. data/app/views/plugins/cama_subscriber/groups/index.html.erb +124 -0
  22. data/app/views/plugins/cama_subscriber/items/form.html.erb +27 -0
  23. data/app/views/plugins/cama_subscriber/items/index.html.erb +52 -0
  24. data/app/views/plugins/cama_subscriber/items/show.html.erb +25 -0
  25. data/app/views/plugins/cama_subscriber/layouts/readme.txt +2 -0
  26. data/app/views/plugins/cama_subscriber/promotions/form.html.erb +65 -0
  27. data/app/views/plugins/cama_subscriber/promotions/form_test.html.erb +18 -0
  28. data/app/views/plugins/cama_subscriber/promotions/index.html.erb +55 -0
  29. data/app/views/plugins/cama_subscriber/promotions/show.html.erb +25 -0
  30. data/config/camaleon_plugin.json +19 -0
  31. data/config/initializers/custom_models.rb +7 -0
  32. data/config/locales/en.yml +5 -0
  33. data/config/locales/es.yml +112 -0
  34. data/config/routes.rb +39 -0
  35. data/db/migrate/20160319112345_subscriber_structure.rb +65 -0
  36. data/lib/1x1.png +0 -0
  37. data/lib/cama_subscriber/engine.rb +4 -0
  38. data/lib/cama_subscriber/version.rb +3 -0
  39. data/lib/cama_subscriber.rb +4 -0
  40. data/lib/tasks/cama_subscriber_tasks.rake +4 -0
  41. metadata +112 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dadd5b701cc1df1e221c0cfc057b31cb93285ed
4
+ data.tar.gz: 36ea9a87a70856348cdfc1b82249caeb1a9710c4
5
+ SHA512:
6
+ metadata.gz: df58980a90d0b462c03eb49e752cbd8dec0b34fdaa6d3d6ffbae5b5d2c96ad9c15251c8914d54be8ee739756129be27af1adf8222a2e6f29d5024dfc25c671b3
7
+ data.tar.gz: 0fdcde8825c8478adc1f81e52d9bbe1e0fe469948c9428d931d5b7c5cd55a1318fec307176702a29071f0274a040c2bd64c74c562ffc6cb135d5997d229253de
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Owen Peredo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'CamaSubscriber'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ class Plugins::CamaSubscriber::AdminController < CamaleonCms::Apps::PluginsAdminController
2
+ include Plugins::CamaSubscriber::MainHelper
3
+ add_breadcrumb(I18n.t("plugins.cama_subscriber.title"), default: 'Newsletters')
4
+ def settings
5
+ add_breadcrumb(t(".settings", default: 'Settings'))
6
+ end
7
+
8
+ def save_settings
9
+ @plugin.set_multiple_options(params[:settings])
10
+ flash[:notice] = t('.saved_settings', default: 'Settings saved')
11
+ redirect_to action: :settings
12
+ end
13
+ end
@@ -0,0 +1,101 @@
1
+ class Plugins::CamaSubscriber::FrontController < CamaleonCms::Apps::PluginsFrontController
2
+ include Plugins::CamaSubscriber::MainHelper
3
+ before_action :init_flash
4
+
5
+ def subscribe
6
+ msg = nil
7
+ error = []
8
+ unless params[:email].present?
9
+ error = t(".email_required", default: 'Your email is required to subscribe for this newsletter')
10
+ end
11
+
12
+ group = params[:group_id].present? ? current_site.subscriber_groups.find(params[:group_id]) : current_site.subscriber_groups.first
13
+ group = current_site.subscriber_groups.create!(name: 'Default Group', key: 'default_group') unless group.present?
14
+
15
+ if group.items.where(email: params[:email]).present?
16
+ error << t(".already_registered", default: 'You have already subscribed to this newsletter')
17
+ end
18
+
19
+ if error.present?
20
+ respond_to do |format|
21
+ format.html { flash[:cama_subscriber][:error] = error.join("<br>"); redirect_to cama_root_url }
22
+ format.json{ render json: {message: error.join("<br>"), error: true} }
23
+ end
24
+ return
25
+ end
26
+
27
+ item = current_site.subscriber_items.where(email: params[:email]).first
28
+ unless item.present?
29
+ item = current_site.subscriber_items.new(name: params[:name], email: params[:email])
30
+ item.status = 'pending' if @plugin.get_option('needs_confirmation') == 1
31
+ item.save!
32
+ item.extra_values(params[:extra_values]) if params[:extra_values].present?
33
+ if @plugin.get_option('needs_confirmation') == 1
34
+ cama_send_email(params[:email], @plugin.get_option('welcome_subject'), {content: @plugin.get_option('welcome_msg') + "<a href='#{plugins_cama_subscriber_verify_url(key: '')}'></a>"})
35
+ msg = t(".please_confirm_email", default: 'Your subscription is pending, please confirm your subscription from your email')
36
+ end
37
+ end
38
+
39
+ group.item_groups.create(item_id: item.id)
40
+ msg = msg || t('.you_have_subscribed', default: 'You have been subscribed successfully')
41
+ respond_to do |format|
42
+ format.html { flash[:cama_subscriber][:notice] = msg; redirect_to cama_root_url }
43
+ format.json{ render json: {message: msg, error: false} }
44
+ end
45
+ end
46
+
47
+ # confirm subscriber
48
+ def verify
49
+ xxx, xx, id_item = Base64.decode64(params[:key]).split('/')
50
+ current_site.subscriber_items.find(id_item).update(status: 'approved')
51
+ flash[:cama_subscriber][:notice] = t(".success_confirm", default: 'Your subscription was successfully confirmed.')
52
+ redirect_to cama_root_url
53
+ end
54
+
55
+ def image_email
56
+ response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
57
+ response.headers["Pragma"] = "no-cache"
58
+ response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
59
+
60
+ promotion_id, sent_promo_id = Base64.decode64(params[:key]).split('/')
61
+ begin
62
+ promotion = current_site.subscriber_promotions.find(promotion_id)
63
+ promotion.sent_promo_items.find(sent_promo_id).increment!
64
+ rescue
65
+ end
66
+ send_file File.join(@plugin.settings['path'], 'lib', '1x1.png'), type: "image/png", disposition: "inline"
67
+ end
68
+
69
+ # unsubscribe from promotion
70
+ def unsubscribe
71
+ begin
72
+ promotion_id, sent_promo_id = Base64.decode64(params[:key]).split('/')
73
+ promotion = current_site.subscriber_promotions.find(promotion_id)
74
+ item = promotion.sent_promo_items.find(sent_promo_id).item
75
+ item.item_groups.where(group_id: promotion.groups.pluck(:id)).destroy_all
76
+ rescue
77
+ end
78
+
79
+ flash[:cama_subscriber][:notice] = t('.you_have_unsubscribed', default: 'You have been unsubscribed successfully')
80
+ redirect_to cama_root_url
81
+ end
82
+
83
+ # unsubscribe from all
84
+ def unsubscribe_all
85
+ begin
86
+ promotion_id, sent_promo_id = Base64.decode64(params[:key]).split('/')
87
+ promotion = current_site.subscriber_promotions.find(promotion_id)
88
+ item = promotion.sent_promo_items.find(sent_promo_id).item
89
+ item.unsubscribe!
90
+ item.item_groups.destroy_all
91
+ rescue
92
+ end
93
+
94
+ flash[:cama_subscriber][:notice] = t('.you_have_unsubscribed', default: 'You have been unsubscribed successfully')
95
+ redirect_to cama_root_url
96
+ end
97
+
98
+ def init_flash
99
+ flash[:cama_subscriber] = {}
100
+ end
101
+ end
@@ -0,0 +1,46 @@
1
+ class Plugins::CamaSubscriber::GroupsController < Plugins::CamaSubscriber::AdminController
2
+ def index
3
+ @items = current_site.subscriber_groups
4
+ end
5
+
6
+ def new
7
+ @item = current_site.subscriber_groups.new
8
+ render 'form', layout: false
9
+ end
10
+
11
+ def create
12
+ @item = current_site.subscriber_groups.create(item_params)
13
+ flash[:notice] = t('.saved', default: 'The group was saved')
14
+ redirect_to action: :index
15
+ end
16
+
17
+ def edit
18
+ @item ||= current_site.subscriber_groups.find(params[:id])
19
+ render 'form', layout: false
20
+ end
21
+
22
+ def update
23
+ @item = current_site.subscriber_groups.find(params[:id]).update(item_params)
24
+ flash[:notice] = t('.updated', default: 'The group was udpated')
25
+ redirect_to action: :index
26
+ end
27
+
28
+ def show
29
+ @item = current_site.subscriber_groups.find(params[:id])
30
+ render layout: false
31
+ end
32
+
33
+ def destroy
34
+ @item = current_site.subscriber_groups.find(params[:id]).destroy
35
+ flash[:notice] = t('.destroyed', default: 'The group was destroyed')
36
+ redirect_to action: :index
37
+ end
38
+
39
+ private
40
+ def item_params
41
+ params.require(:plugins_cama_subscriber_group).permit(
42
+ :name,
43
+ :key
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,56 @@
1
+ class Plugins::CamaSubscriber::ItemsController < Plugins::CamaSubscriber::AdminController
2
+ def index
3
+ if params[:group].present?
4
+ @group = current_site.subscriber_groups.find(params[:group])
5
+ @items = @group.items
6
+ else
7
+ @items = current_site.subscriber_items
8
+ end
9
+ @items = @items.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
10
+ end
11
+
12
+ def new
13
+ @item = current_site.subscriber_items.new
14
+ render 'form', layout: false
15
+ end
16
+
17
+ def create
18
+ @item = current_site.subscriber_items.create(item_params)
19
+ @item.add_groups(params[:groups])
20
+ flash[:notice] = t('.saved', default: 'The subscription was saved')
21
+ redirect_to action: :index
22
+ end
23
+
24
+ def edit
25
+ @item ||= current_site.subscriber_items.find(params[:id])
26
+ render 'form', layout: false
27
+ end
28
+
29
+ def update
30
+ @item = current_site.subscriber_items.find(params[:id])
31
+ @item.update(item_params)
32
+ @item.add_groups(params[:groups])
33
+ flash[:notice] = t('.updated', default: 'The subscription was udpated')
34
+ redirect_to action: :index
35
+ end
36
+
37
+ def show
38
+ @item = current_site.subscriber_items.find(params[:id])
39
+ render layout: false
40
+ end
41
+
42
+ def destroy
43
+ @item = current_site.subscriber_items.find(params[:id]).destroy
44
+ flash[:notice] = t('.destroyed', default: 'The subscription was destroyed')
45
+ redirect_to action: :index
46
+ end
47
+
48
+ private
49
+ def item_params
50
+ params.require(:plugins_cama_subscriber_item).permit(
51
+ :name,
52
+ :email,
53
+ :status
54
+ )
55
+ end
56
+ end
@@ -0,0 +1,94 @@
1
+ class Plugins::CamaSubscriber::PromotionsController < Plugins::CamaSubscriber::AdminController
2
+ def index
3
+ @items = current_site.subscriber_promotions
4
+ end
5
+
6
+ def new
7
+ @item = current_site.subscriber_promotions.new
8
+ render 'form', layout: false
9
+ end
10
+
11
+ def create
12
+ @item = current_site.subscriber_promotions.create(item_params)
13
+ @item.add_groups(params[:groups])
14
+ flash[:notice] = t('.saved', default: 'The promotions was saved')
15
+ redirect_to action: :index
16
+ end
17
+
18
+ def edit
19
+ @item ||= current_site.subscriber_promotions.find(params[:id])
20
+ render 'form', layout: false
21
+ end
22
+
23
+ def update
24
+ @item = current_site.subscriber_promotions.find(params[:id])
25
+ @item.update(item_params)
26
+ @item.add_groups(params[:groups])
27
+ flash[:notice] = t('.updated', default: 'The promotion was udpated')
28
+ redirect_to action: :index
29
+ end
30
+
31
+ def show
32
+ @item = current_site.subscriber_promotions.find(params[:id])
33
+ render layout: false
34
+ end
35
+
36
+ def destroy
37
+ @item = current_site.subscriber_promotions.find(params[:id]).destroy
38
+ flash[:notice] = t('.destroyed', default: 'The promotion was destroyed')
39
+ redirect_to action: :index
40
+ end
41
+
42
+ # send the campaign to items of the groups
43
+ def send_campaign
44
+ promotion = current_site.subscriber_promotions.find(params[:promotion_id])
45
+ if promotion.groups.present?
46
+ i = 0
47
+ promotion.items.active.uniq.each do |item|
48
+ sent_promo = promotion.sent_promo_items.create(item_id: item.id)
49
+ key = Base64.encode64("#{promotion.id}/#{sent_promo.id}")
50
+ cama_send_email(item.email, promotion.subject, {
51
+ from: promotion.email_from,
52
+ cc_to: promotion.email_cc.split(","),
53
+ template: promotion.template,
54
+ layout_name: promotion.layout,
55
+ content: promotion.content.to_s.gsub('unsubscribe_url', plugins_cama_subscriber_unsubscribe_url(key: key)).gsub('unsubscribe_all_url', plugins_cama_subscriber_unsubscribe_all_url(key: key)) + "<img src='#{plugins_cama_subscriber_image_email_url(key: key)}'>"
56
+ })
57
+ i += 1
58
+ end
59
+ flash[:notice] = t('.success_send', default: "The campaign was sent successfully to #{i} subscribers", qty: i)
60
+ promotion.sent!
61
+ else
62
+ flash[:error] = t('.error_send', default: 'You need to define at least one group')
63
+ end
64
+ redirect_to action: :index
65
+ end
66
+
67
+ def form_test
68
+ @promotion = current_site.subscriber_promotions.find(params[:promotion_id])
69
+ render layout: false
70
+ end
71
+
72
+ def send_test
73
+ promotion = current_site.subscriber_promotions.find(params[:promotion_id])
74
+ cama_send_email(params[:email], promotion.subject, {from: promotion.email_from, cc_to: promotion.email_cc.split(","), template: promotion.template, layout_name: promotion.layout, content: promotion.content})
75
+ flash[:notice] = t('.success_test_send', default: 'The test campaign was sent successfully')
76
+ redirect_to action: :index
77
+ end
78
+
79
+ private
80
+ def item_params
81
+ params.require(:plugins_cama_subscriber_promotion).permit(
82
+ :name,
83
+ :layout,
84
+ :template,
85
+ :content,
86
+ :key,
87
+ :email_from,
88
+ :email_cc,
89
+ :subject,
90
+ :content,
91
+ :status
92
+ )
93
+ end
94
+ end
@@ -0,0 +1,35 @@
1
+ module Plugins::CamaSubscriber::MainHelper
2
+ def self.included(klass)
3
+ # klass.helper_method [:my_helper_method] rescue "" # here your methods accessible from views
4
+ end
5
+
6
+ # here all actions on going to active
7
+ # you can run sql commands like this:
8
+ # results = ActiveRecord::Base.connection.execute(query);
9
+ # plugin: plugin model
10
+ def cama_subscriber_on_active(plugin)
11
+ end
12
+
13
+ # here all actions on going to inactive
14
+ # plugin: plugin model
15
+ def cama_subscriber_on_inactive(plugin)
16
+ end
17
+
18
+ # here all actions to upgrade for a new version
19
+ # plugin: plugin model
20
+ def cama_subscriber_on_upgrade(plugin)
21
+ end
22
+
23
+ def cama_subscriber_plugin_options(args)
24
+ # args[:links] << link_to(t('plugins.cama_subscriber.settings', default: 'Settings'), admin_plugins_cama_subscriber_settings_url).to_s
25
+ end
26
+
27
+ def cama_subscriber_before_admin
28
+ items = []
29
+ items << {icon: "group", title: t('plugins.cama_subscriber.items.title', default: 'Subscribers'), url: admin_plugins_cama_subscriber_items_path}
30
+ items << {icon: "object-ungroup", title: t('plugins.cama_subscriber.groups.title', default: 'Groups'), url: admin_plugins_cama_subscriber_groups_path}
31
+ items << {icon: "newspaper-o", title: t('plugins.cama_subscriber.promotions.title', default: 'Campaigns'), url: admin_plugins_cama_subscriber_promotions_path}
32
+ items << {icon: "gear", title: t('plugins.cama_subscriber.settings', default: 'Settings'), url: admin_plugins_cama_subscriber_settings_url}
33
+ admin_menu_insert_menu_before('settings', 'plugin_subscriber', {icon: "envelope-o", title: t('plugins.cama_subscriber.title', default: 'Subscriptions'), url: '', items: items})
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ class Plugins::CamaSubscriber::Group < ActiveRecord::Base
2
+ belongs_to :site, class_name: "CamleonCms::Site", foreign_key: :site_id
3
+ has_many :item_groups, class_name: 'Plugins::CamaSubscriber::GroupItem'
4
+ has_many :items, class_name: 'Plugins::CamaSubscriber::Item', through: :item_groups
5
+ end
@@ -0,0 +1,4 @@
1
+ class Plugins::CamaSubscriber::GroupItem < ActiveRecord::Base
2
+ belongs_to :group, class_name: 'Plugins::CamaSubscriber::Group'
3
+ belongs_to :item, class_name: 'Plugins::CamaSubscriber::Item'
4
+ end
@@ -0,0 +1,43 @@
1
+ class Plugins::CamaSubscriber::Item < ActiveRecord::Base
2
+ STATUS = ['approved', 'pending', 'unsubscribed']
3
+ include CamaleonCms::Metas
4
+ belongs_to :site, class_name: "CamleonCms::Site", foreign_key: :site_id
5
+ has_many :item_groups, class_name: 'Plugins::CamaSubscriber::GroupItem'
6
+ has_many :groups, class_name: 'Plugins::CamaSubscriber::Group', through: :item_groups
7
+ before_save :check_unsubscribed_status
8
+
9
+ scope :active, ->{ where(status: 'approved') }
10
+ scope :pending, ->{ where(status: 'pending') }
11
+ scope :unsubscribed, ->{ where(status: 'unsubscribed') }
12
+
13
+ # values: (Hash)
14
+ # sample: {company: 'camaleon cms', city: 'Cochabamba'}
15
+ def extra_values(values)
16
+ self.set_multiple_options(values, 'custom_values')
17
+ end
18
+
19
+ # add this item into groups
20
+ def add_groups(group_ids = [])
21
+ g = self.groups.pluck(:id)
22
+ self.item_groups.where(group_id: g - group_ids).destroy_all
23
+ (group_ids - g).each do |g_id|
24
+ self.item_groups.create(group_id: g_id)
25
+ end
26
+ end
27
+
28
+ # unsubscribe user from all groups
29
+ def unsubscribe!
30
+ self.update(status: 'unsubscribed')
31
+ end
32
+
33
+ private
34
+ def check_unsubscribed_status
35
+ if self.status_changed?
36
+ if self.status == 'unsubscribed'
37
+ self.unsubscribed_at = Time.current
38
+ else
39
+ self.unsubscribed_at = nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ class Plugins::CamaSubscriber::Promotion < ActiveRecord::Base
2
+ belongs_to :site, class_name: "CamleonCms::Site", foreign_key: :site_id
3
+ has_many :promotion_groups, class_name: 'Plugins::CamaSubscriber::PromotionGroup'
4
+ has_many :groups, class_name: 'Plugins::CamaSubscriber::Group', through: :promotion_groups
5
+ has_many :items, class_name: 'Plugins::CamaSubscriber::Item', through: :groups
6
+
7
+ has_many :sent_promo_items, class_name: 'Plugins::CamaSubscriber::PromotionItem'
8
+ has_many :sent_items, class_name: 'Plugins::CamaSubscriber::Item', through: :sent_promo_items, source: :item
9
+
10
+ # add this item into groups
11
+ def add_groups(group_ids = [])
12
+ g = self.groups.pluck(:id)
13
+ self.promotion_groups.where(group_id: g - group_ids).destroy_all
14
+ (group_ids - g).each do |g_id|
15
+ self.promotion_groups.create(group_id: g_id)
16
+ end
17
+ end
18
+
19
+ # boolean sent or pending campaign
20
+ def sent?
21
+ self.status == 'sent'
22
+ end
23
+
24
+ def sent!
25
+ self.update(status: 'sent')
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ class Plugins::CamaSubscriber::PromotionGroup < ActiveRecord::Base
2
+ belongs_to :promotion, class_name: 'Plugins::CamaSubscriber::Promotion'
3
+ belongs_to :group, class_name: 'Plugins::CamaSubscriber::Group'
4
+ end
@@ -0,0 +1,11 @@
1
+ class Plugins::CamaSubscriber::PromotionItem < ActiveRecord::Base
2
+ belongs_to :promotion, class_name: 'Plugins::CamaSubscriber::Promotion'
3
+ belongs_to :item, class_name: 'Plugins::CamaSubscriber::Item'
4
+ scope :open, ->{ where.not(qty_opened: 0) }
5
+ scope :no_open, ->{ where(qty_opened: 0) }
6
+ # scope :open, ->{ where('last_open_at is not null') }
7
+
8
+ def increment!
9
+ self.update(qty_opened: self.qty_opened + 1)
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ =begin
2
+ Camaleon CMS is a content management system
3
+ Copyright (C) 2015 by Owen Peredo Diaz
4
+ Email: owenperedo@gmail.com
5
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
+ See the GNU Affero General Public License (GPLv3) for more details.
8
+ =end
9
+ module Plugins::CamaSubscriber
10
+ def self.table_name_prefix
11
+ 'plugins_subscriber_'
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ <%#= javascript_include_tag plugin_asset("my_file.js") %>
2
+ <div class="panel panel-default">
3
+ <div class="panel-heading">
4
+ <h4>My Title</h4>
5
+ </div>
6
+ <div class="panel-body">
7
+ <p>Plugin ready to use in admin panel!.</p>
8
+ </div>
9
+ </div>
@@ -0,0 +1,27 @@
1
+ <%= form_tag url_for(action: :save_settings) do |f| %>
2
+ <div class="panel panel-default">
3
+ <div class="panel-heading">
4
+ <h4><%= t('.title') %></h4>
5
+ </div>
6
+ <div class="panel-body">
7
+ <%= fields_for :settings, OpenStruct.new(@plugin.options) do |f2| %>
8
+ <div class="form-group">
9
+ <label><%= t('.needs_confirmation', default: 'Email subscription needs conrfirmation?') %></label><br>
10
+ <%= f2.check_box :needs_confirmation %>
11
+ </div>
12
+ <div class="form-group">
13
+ <label><%= t('.welcome_subject', default: 'Welcome Subject') %></label><br>
14
+ <%= f2.text_field :welcome_subject, class: 'translated form-control' %>
15
+ </div>
16
+ <div class="form-group">
17
+ <label><%= t('.welcome_msg', default: 'Welcome Message') %></label><br>
18
+ <%= f2.text_area :welcome_msg, class: 'translated form-control' %>
19
+ </div>
20
+ <% end %>
21
+ </div>
22
+ <div class="panel-footer">
23
+ <a class="btn btn-default" role="back" href="<%= admin_plugins_cama_subscriber_items_path %>"><%= t('camaleon_cms.admin.button.back') %></a>
24
+ <button class="btn btn-primary pull-right" type="submit"><%= t('camaleon_cms.admin.button.submit') %></button>
25
+ </div>
26
+ </div>
27
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <%#= javascript_include_tag plugin_gem_asset("js/my_file.js") %>
2
+ Plugin ready to use! in frontend.
@@ -0,0 +1,17 @@
1
+ <%= form_for [:admin, @item], class: 'validate' do |f| %>
2
+ <div class="panel panel-default">
3
+ <div class="panel-body">
4
+ <div class="form-group">
5
+ <label><%= t('plugins.cama_subscriber.groups.index.name') %></label><br>
6
+ <%= f.text_field :name, class: 'form-control required' %>
7
+ </div>
8
+ <div class="form-group">
9
+ <label><%= t('plugins.cama_subscriber.groups.index.key') %></label><br>
10
+ <%= f.text_field :key, class: 'form-control' %>
11
+ </div>
12
+ </div>
13
+ <div class="panel-footer text-right">
14
+ <button class="btn btn-primary" type="submit"><%= t('camaleon_cms.admin.button.submit') %></button>
15
+ </div>
16
+ </div>
17
+ <% end %>