BxDolReport.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * Copyright (c) UNA, Inc - https://una.io
  3. * MIT License - https://opensource.org/licenses/MIT
  4. *
  5. * @defgroup UnaCore UNA Core
  6. * @{
  7. */
  8. function BxDolReport(options)
  9. {
  10. this._sObjName = undefined == options.sObjName ? 'oReport' : options.sObjName; // javascript object name, to run current object instance from onTimer
  11. this._sSystem = options.sSystem; // current comment system
  12. this._iAuthorId = options.iAuthorId; // this comment's author ID.
  13. this._iObjId = options.iObjId; // this object id comments
  14. this._sActionsUri = 'report.php';
  15. this._sActionsUrl = options.sRootUrl + this._sActionsUri; // actions url address
  16. this._sAnimationEffect = 'fade';
  17. this._iAnimationSpeed = 'slow';
  18. this._sSP = options.sStylePrefix == undefined ? 'bx-report' : options.sStylePrefix;
  19. this._aHtmlIds = options.aHtmlIds;
  20. this._oRequestParams = options.oRequestParams == undefined ? {} : options.oRequestParams;
  21. this._sUnreportConfirm = options.sUnreportConfirm == undefined ? _t('_Are_you_sure') : options.sUnreportConfirm;
  22. this._oParent = null;
  23. }
  24. BxDolReport.prototype.toggleByPopup = function(oLink) {
  25. var $this = this;
  26. var oData = this._getDefaultParams();
  27. oData['action'] = 'GetReportedBy';
  28. $(oLink).dolPopupAjax({
  29. id: this._aHtmlIds['by_popup'],
  30. url: bx_append_url_params(this._sActionsUri, oData)
  31. });
  32. };
  33. BxDolReport.prototype.report = function(oLink) {
  34. var $this = this;
  35. this._oParent = $(oLink);
  36. var fPerform = function() {
  37. var oData = $this._getDefaultParams();
  38. oData['action'] = 'Report';
  39. $.get(
  40. $this._sActionsUrl,
  41. oData,
  42. function(oData) {
  43. $this.processJson(oData, $this._oParent);
  44. },
  45. 'json'
  46. );
  47. };
  48. if(this._oParent.hasClass('bx-report-reported'))
  49. bx_confirm(this._sUnreportConfirm, fPerform);
  50. else
  51. fPerform();
  52. };
  53. BxDolReport.prototype.onReport = function(oData, oElement)
  54. {
  55. var $this = this;
  56. var fPerform = function() {
  57. if(oData && oData.code != 0)
  58. return;
  59. if(oData && oData.reported != undefined)
  60. $(oElement).toggleClass('bx-report-reported', oData.reported);
  61. if(oData && oData.disabled)
  62. $(oElement).removeAttr('onclick').addClass($(oElement).hasClass('bx-btn') ? 'bx-btn-disabled' : 'bx-report-disabled');
  63. if(oData && oData.label_icon)
  64. $(oElement).find('.sys-action-do-icon .sys-icon').attr('class', 'sys-icon ' + oData.label_icon);
  65. if(oData && oData.label_title) {
  66. $(oElement).attr('title', oData.label_title);
  67. $(oElement).find('.sys-action-do-text').html(oData.label_title);
  68. }
  69. var oCounter = $this._getCounter(oElement);
  70. if(oCounter && oCounter.length > 0) {
  71. oCounter.html(oData.countf);
  72. oCounter.parents('.' + $this._sSP + '-counter-holder:first').bx_anim(oData.count > 0 ? 'show' : 'hide');
  73. }
  74. };
  75. if(oData && oData.msg != undefined)
  76. bx_alert(oData.msg, fPerform);
  77. else
  78. fPerform();
  79. };
  80. BxDolReport.prototype.processJson = function(oData, oElement) {
  81. oElement = oElement != undefined ? oElement : this._oParent;
  82. var fContinue = function() {
  83. //--- Show Popup
  84. if(oData && oData.popup != undefined) {
  85. $('#' + oData.popup_id).remove();
  86. var oPopup = null;
  87. var oOptions = {
  88. pointer: {
  89. el: oElement
  90. },
  91. fog: {
  92. color: '#fff',
  93. opacity: .7
  94. },
  95. closeOnOuterClick: false
  96. };
  97. if(typeof(oData.popup) == 'object') {
  98. oOptions = $.extend({}, oOptions, oData.popup.options);
  99. oPopup = $(oData.popup.html);
  100. }
  101. else
  102. oPopup = $(oData.popup);
  103. oPopup.hide().prependTo('body').dolPopup(oOptions);
  104. }
  105. //--- Evaluate JS code
  106. if (oData && oData.eval != undefined)
  107. eval(oData.eval);
  108. };
  109. //--- Show Message
  110. if(oData && oData.message != undefined)
  111. bx_alert(oData.message, fContinue);
  112. else
  113. fContinue();
  114. };
  115. BxDolReport.prototype._getButtons = function(oElement) {
  116. if($(oElement).hasClass(this._sSP))
  117. return $(oElement).find('.' + this._sSP + '-button');
  118. else
  119. return $(oElement).parents('.' + this._sSP + ':first').find('.' + this._sSP + '-button');
  120. };
  121. BxDolReport.prototype._getCounter = function(oElement) {
  122. if($(oElement).hasClass(this._sSP))
  123. return $(oElement).find('.' + this._sSP + '-counter');
  124. else
  125. return $(oElement).parents('.' + this._sSP + ':first').find('.' + this._sSP + '-counter');
  126. };
  127. BxDolReport.prototype._loadingInButton = function(e, bShow) {
  128. if($(e).length)
  129. bx_loading_btn($(e), bShow);
  130. else
  131. bx_loading($('body'), bShow);
  132. };
  133. BxDolReport.prototype._getDefaultParams = function() {
  134. var oDate = new Date();
  135. return jQuery.extend({
  136. sys: this._sSystem,
  137. object_id: this._iObjId
  138. }, this._oRequestParams, {
  139. _t: oDate.getTime()
  140. });
  141. };
  142. /** @} */