BxDolFeature.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 BxDolFeature(options)
  9. {
  10. this._sObjName = undefined == options.sObjName ? 'oFeature' : 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 = 'feature.php';
  15. this._sActionsUrl = options.sRootUrl + this._sActionsUri; // actions url address
  16. this._sAnimationEffect = 'fade';
  17. this._iAnimationSpeed = 'slow';
  18. this._sSP = undefined == options.sStylePrefix ? 'bx-feature' : options.sStylePrefix;
  19. this._aHtmlIds = options.aHtmlIds;
  20. this._oParent = null;
  21. }
  22. BxDolFeature.prototype.feature = function(oLink) {
  23. var $this = this;
  24. var oData = this._getDefaultParams();
  25. oData['action'] = 'Feature';
  26. this._oParent = oLink;
  27. $.get(
  28. this._sActionsUrl,
  29. oData,
  30. function(oData) {
  31. $this.processJson(oData, oLink);
  32. },
  33. 'json'
  34. );
  35. };
  36. BxDolFeature.prototype.onFeature = function(oData, oElement)
  37. {
  38. var fContinue = function() {
  39. if(oData && oData.code != 0)
  40. return;
  41. if(oData && oData.label_icon)
  42. $(oElement).find('.sys-action-do-icon .sys-icon').attr('class', 'sys-icon ' + oData.label_icon);
  43. if(oData && oData.label_title) {
  44. $(oElement).attr('title', oData.label_title);
  45. $(oElement).find('.sys-action-do-text').html(oData.label_title);
  46. }
  47. if(oData && oData.disabled)
  48. $(oElement).removeAttr('onclick').addClass($(oElement).hasClass('bx-btn') ? 'bx-btn-disabled' : 'bx-feature-disabled');
  49. };
  50. if(oData && oData.msg != undefined && oData.msg.length > 0)
  51. bx_alert(oData.msg, fContinue);
  52. else
  53. fContinue();
  54. };
  55. BxDolFeature.prototype.processJson = function(oData, oElement) {
  56. oElement = oElement != undefined ? oElement : this._oParent;
  57. var fContinue = function() {
  58. //--- Show Popup
  59. if(oData && oData.popup != undefined) {
  60. $('#' + oData.popup_id).remove();
  61. $(oData.popup).hide().prependTo('body').dolPopup({
  62. pointer: {
  63. el: oElement
  64. },
  65. fog: {
  66. color: '#fff',
  67. opacity: .7
  68. }
  69. });
  70. }
  71. //--- Evaluate JS code
  72. if (oData && oData.eval != undefined)
  73. eval(oData.eval);
  74. };
  75. //--- Show Message
  76. if(oData && oData.message != undefined)
  77. bx_alert(oData.message, fContinue);
  78. else
  79. fContinue();
  80. };
  81. BxDolFeature.prototype._getButtons = function(oElement) {
  82. if($(oElement).hasClass(this._sSP))
  83. return $(oElement).find('.' + this._sSP + '-button');
  84. else
  85. return $(oElement).parents('.' + this._sSP + ':first').find('.' + this._sSP + '-button');
  86. };
  87. BxDolFeature.prototype._loadingInButton = function(e, bShow) {
  88. if($(e).length)
  89. bx_loading_btn($(e), bShow);
  90. else
  91. bx_loading($('body'), bShow);
  92. };
  93. BxDolFeature.prototype._getDefaultParams = function() {
  94. var oDate = new Date();
  95. return {
  96. sys: this._sSystem,
  97. object_id: this._iObjId,
  98. _t: oDate.getTime()
  99. };
  100. };
  101. /** @} */