diff --git a/app/controllers/commissions_controller.rb b/app/controllers/commissions_controller.rb index b84aef6..9841d47 100644 --- a/app/controllers/commissions_controller.rb +++ b/app/controllers/commissions_controller.rb @@ -37,5 +37,7 @@ def pay session.delete(:sell_action_ids) session.delete(:commission) + + redirect_via_turbolinks_to links_path end end diff --git a/app/models/link.rb b/app/models/link.rb index 14f1b6a..782bfa9 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -4,6 +4,8 @@ class Link < ActiveRecord::Base has_many :open_actions has_many :sell_actions + delegate :email, to: :user, prefix: true, allow_nil: true + def self.get_by_code(code) Link.where(code: code).first end diff --git a/app/models/sell_action.rb b/app/models/sell_action.rb index 38d8768..fa7b7a7 100644 --- a/app/models/sell_action.rb +++ b/app/models/sell_action.rb @@ -3,6 +3,8 @@ class SellAction < ActiveRecord::Base before_create :set_approved_at + delegate :user_email, to: :link, allow_nil: true + enum payment_method: { transfer: 0, paypal: 1 } def self.getOrCreate(code, link, email, price) diff --git a/app/models/user.rb b/app/models/user.rb index 0558028..f6a94fd 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,7 +12,7 @@ class User < ActiveRecord::Base has_many :campaigns has_many :links has_one :billing_info - + accepts_nested_attributes_for :billing_info enum role: { merchant: 0, referer: 1 } @@ -24,7 +24,7 @@ def self.get_or_create_by_email(email, role) end user end - + after_initialize do |user| if user.merchant? && user.billing_info.blank? user.billing_info = BillingInfo.create! diff --git a/app/views/campaigns/partials/_show.html.erb b/app/views/campaigns/partials/_show.html.erb index 7a94a63..0be5629 100644 --- a/app/views/campaigns/partials/_show.html.erb +++ b/app/views/campaigns/partials/_show.html.erb @@ -30,7 +30,8 @@ Kód Email - Zaznamenie + Referer + Zaznamenané Cena (€) Provizia (%) Provizia (€) @@ -40,6 +41,7 @@ <%= record[:code] %> <%= record[:email] %> + <%= record.user_email %> <%= record[:created_at].strftime("%d.%m.%Y %H:%M") %> <%= record[:price] %> <%= record[:commission] %> @@ -57,4 +59,4 @@ $.get("<%= sell_actions_set_approve_path %>", {id: id, approve: isChecked}).done(function(data) {}); }); }); - \ No newline at end of file + diff --git a/app/views/links/index.html.erb b/app/views/links/index.html.erb index 8107264..ef9e5e3 100644 --- a/app/views/links/index.html.erb +++ b/app/views/links/index.html.erb @@ -33,7 +33,7 @@

- <%= @data[:links][:commission] %>€ provízia + <%= @data[:links][:eligible_commission] %>€ aktuálna provízia <% if eligible_for_payoff %><% end %>
diff --git a/public/sharee.js b/public/sharee.js index 6dbdb39..8791a3d 100644 --- a/public/sharee.js +++ b/public/sharee.js @@ -1,12 +1,3 @@ -$(function() { - var ready = function() { - new Sharee(); - }; - - $(document).ready(ready); - $(document).on('page:load', ready); -}); - window.Sharee = (function () { 'use strict'; @@ -72,17 +63,46 @@ window.Sharee = (function () { initShareeButtonFormsEvents(button); }); }); + + $(document).on('click', '.sharee-fb', function(e) { + e.preventDefault(); + var url = 'https://www.facebook.com/sharer/sharer.php?u=' + getShareeUrl(this); + window.open(url,'_blank','width=800,height=300'); + }); - appendScripts(); - appendStyles(); - }; + $(document).on('click', '.sharee-tw', function(e) { + e.preventDefault(); + var url = 'http://twitter.com/share?url=' + getShareeUrl(this) + '&text=Sharing'; + window.open(url,'_blank','width=800,height=300'); + }); - var appendScripts = function() { - var head = getDocumentHead(); - var script= document.createElement("script"); - script.type = "text/javascript"; - script.src= Sharee.getHost() + "/sharee/scripts.js"; - head.appendChild(script); + $(document).on('click', '.sharee-gp', function(e) { + e.preventDefault(); + var url = 'https://plus.google.com/share?url=' + getShareeUrl(this); + window.open(url,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=400,width=500'); + }); + + function isEmail(email) { + var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; + return regex.test(email); + } + + $( document ).ready(function() { + $('#sharee-submit-email').prop('disabled', true); + }); + + $('.sharee-button').on('input', '#sharee-input-email', function(){ + if(($(this).val().length != 0) && isEmail($(this).val())) + $('#sharee-submit-email').prop('disabled', false); + else + $('#sharee-submit-email').prop('disabled', true); + }); + + var getShareeUrl = function(sender) { + return $(sender).closest('.sharee-button-success-block').find('.sharee-link').val(); + }; + + appendStyles(); }; var appendStyles = function() { @@ -224,3 +244,10 @@ window.Sharee = (function () { return Sharee; })(); + +var ready = function() { + new Sharee(); +}; + +$(document).ready(ready); +$(document).on('page:load', ready); diff --git a/public/sharee/styles.css b/public/sharee/styles.css index 421e036..f07a668 100644 --- a/public/sharee/styles.css +++ b/public/sharee/styles.css @@ -4,7 +4,6 @@ .sharee-button { display: inline-block; - margin: 4px; } .sharee-button-block { @@ -188,4 +187,4 @@ .sharee-gp { border-color: rgb(215, 61, 50); background: rgb(215, 61, 50); -} \ No newline at end of file +}