subscriptions.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup Payment Payment
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. function BxPaymentSubscriptions(oOptions) {
  11. this.init(oOptions);
  12. }
  13. BxPaymentSubscriptions.prototype = new BxPaymentMain();
  14. BxPaymentSubscriptions.prototype.init = function(oOptions) {
  15. if($.isEmptyObject(oOptions))
  16. return;
  17. this._sActionsUrl = oOptions.sActionUrl;
  18. this._sObjName = oOptions.sObjName == undefined ? 'oPmtSubscriptions' : oOptions.sObjName;
  19. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  20. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  21. };
  22. BxPaymentSubscriptions.prototype.getDetails = function(oLink, iId) {
  23. this._performRequest(oLink, iId, 'subscription_get_details');
  24. };
  25. BxPaymentSubscriptions.prototype.changeDetails = function(oLink, iId) {
  26. this._performRequest(oLink, iId, 'subscription_change_details');
  27. };
  28. BxPaymentSubscriptions.prototype.getBilling = function(oLink, iId) {
  29. this._performRequest(oLink, iId, 'subscription_get_billing');
  30. };
  31. BxPaymentSubscriptions.prototype.changeBilling = function(oLink, iId) {
  32. this._performRequest(oLink, iId, 'subscription_change_billing');
  33. };
  34. BxPaymentSubscriptions.prototype.requestCancelation = function(oLink, iId) {
  35. this._performRequest(oLink, iId, 'subscription_cancelation');
  36. };
  37. BxPaymentSubscriptions.prototype.onSubmitCancelationReason = function(oForm) {
  38. oForm = $(oForm);
  39. if(oForm.find("[name = 'items']:checked").val() == 'rc_0' && oForm.find("[name = 'other']").val() == '') {
  40. oForm.find(".bx-payment-cs-other .bx-form-warn").html(_t('_bx_payment_form_input_err')).show();
  41. return false;
  42. }
  43. return true;
  44. };
  45. BxPaymentSubscriptions.prototype.onChangeCancelationReason = function(oElement) {
  46. var bOther = $(oElement).val() == 'rc_0';
  47. var oOther = $(oElement).parents('.bx-form-element-wrapper:first').siblings('.bx-payment-cs-other');
  48. oOther.toggleClass('bx-payment-cs-hidden', !bOther);
  49. if(!bOther)
  50. oOther.find("[name = 'other']").val('');
  51. };
  52. BxPaymentSubscriptions.prototype.cancel = function(oLink, iId, sGrid, iConfirm) {
  53. var $this = this;
  54. var oParams = {};
  55. if(sGrid != undefined)
  56. oParams.grid = sGrid;
  57. var fPerformYes = function() {
  58. $this._performRequest(oLink, iId, 'subscription_cancel', oParams);
  59. };
  60. if(iConfirm != undefined && parseInt(iConfirm) == 0)
  61. fPerformYes();
  62. else
  63. bx_confirm(_t('_bx_payment_msg_confirm_cancelation'), fPerformYes, function() {}, {
  64. yes: {
  65. title: _t('_bx_payment_txt_unsubscribe_yes')
  66. },
  67. no: {
  68. title: _t('_bx_payment_txt_unsubscribe_no')
  69. }
  70. });
  71. };
  72. BxPaymentSubscriptions.prototype._performRequest = function(oLink, iId, sUri, oParams) {
  73. var $this = this;
  74. var oDate = new Date();
  75. this.loadingInPopup(oLink, true);
  76. $.post(
  77. this._sActionsUrl + sUri + '/' + iId,
  78. $.extend({}, {_t:oDate.getTime()}, oParams),
  79. function(oData){
  80. $this.loadingInPopup(oLink, false);
  81. $(".bx-popup-applied:visible").dolPopupHide();
  82. processJsonData(oData);
  83. },
  84. 'json'
  85. );
  86. };
  87. /** @} */