entry.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Ads Ads
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxAdsEntry(oOptions) {
  11. this._sActionsUri = oOptions.sActionUri;
  12. this._sActionsUrl = oOptions.sActionUrl;
  13. this._sObjName = oOptions.sObjName == undefined ? 'oBxAdsEntry' : oOptions.sObjName;
  14. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'slide' : oOptions.sAnimationEffect;
  15. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  16. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  17. this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
  18. }
  19. BxAdsEntry.prototype.interested = function(oElement, iContentId) {
  20. this._performAction(oElement, 'interested', iContentId);
  21. };
  22. BxAdsEntry.prototype.show = function(oElement, iContentId) {
  23. this._performAction(oElement, 'show', iContentId);
  24. };
  25. BxAdsEntry.prototype.hide = function(oElement, iContentId) {
  26. this._performAction(oElement, 'hide', iContentId);
  27. };
  28. BxAdsEntry.prototype.makeOffer = function(oElement, iContentId) {
  29. this._performAction(oElement, 'make_offer', iContentId, 'content_id');
  30. };
  31. BxAdsEntry.prototype.onMakeOffer = function(oData) {};
  32. BxAdsEntry.prototype.viewOffer = function(oElement, iOfferId) {
  33. this._performAction(oElement, 'view_offer', iOfferId);
  34. };
  35. BxAdsEntry.prototype.acceptOffer = function(oElement, iOfferId) {
  36. var $this = this;
  37. bx_confirm('', function() {
  38. $this._performAction(oElement, 'accept_offer', iOfferId);
  39. });
  40. };
  41. BxAdsEntry.prototype.declineOffer = function(oElement, iOfferId) {
  42. var $this = this;
  43. bx_confirm('', function() {
  44. $this._performAction(oElement, 'decline_offer', iOfferId);
  45. });
  46. };
  47. BxAdsEntry.prototype.cancelOffer = function(oElement, iOfferId) {
  48. var $this = this;
  49. bx_confirm('', function() {
  50. $this._performAction(oElement, 'cancel_offer', iOfferId);
  51. });
  52. };
  53. BxAdsEntry.prototype.payOffer = function(oElement, iOfferId) {
  54. this._performAction(oElement, 'pay_offer', iOfferId);
  55. };
  56. BxAdsEntry.prototype.shipped = function(oElement, iContentId) {
  57. this._performAction(oElement, 'shipped', iContentId);
  58. };
  59. BxAdsEntry.prototype.received = function(oElement, iContentId) {
  60. this._performAction(oElement, 'received', iContentId);
  61. };
  62. BxAdsEntry.prototype.loadingInButton = function(e, bShow) {
  63. if($(e).length)
  64. bx_loading_btn($(e), bShow);
  65. else
  66. bx_loading($('body'), bShow);
  67. };
  68. BxAdsEntry.prototype.loadingInBox = function(e, bShow) {
  69. var oParent = $(e).length ? $(e).parents('.bx-base-text-poll:first') : $('body');
  70. bx_loading(oParent, bShow);
  71. };
  72. BxAdsEntry.prototype._performAction = function(oElement, sAction, iContentId, sContentIdKey) {
  73. var $this = this;
  74. var oParams = this._getDefaultData();
  75. oParams[sContentIdKey ? sContentIdKey : 'id'] = iContentId;
  76. if(oElement)
  77. this.loadingInButton(oElement, true);
  78. jQuery.get (
  79. this._sActionsUrl + sAction,
  80. oParams,
  81. function(oData) {
  82. if(oElement)
  83. $this.loadingInButton(oElement, false);
  84. processJsonData(oData);
  85. },
  86. 'json'
  87. );
  88. };
  89. BxAdsEntry.prototype._getDefaultData = function() {
  90. var oDate = new Date();
  91. return jQuery.extend({}, this._oRequestParams, {_t:oDate.getTime()});
  92. };
  93. /** @} */