BxDolPrivacy.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 BxDolPrivacy(oOptions) {
  9. this.BX_DOL_PG_FRIENDS_SELECTED = 6;
  10. this.BX_DOL_PG_RELATIONS_SELECTED = 8;
  11. this._sObject = oOptions.sObject;
  12. this._sObjName = oOptions.sObjName == undefined ? 'oBxDolPrivacy' : oOptions.sObjName;
  13. this._sRootUrl = oOptions.sRootUrl == undefined ? sUrlRoot : oOptions.sRootUrl;
  14. this._sActionsUri = 'privacy.php';
  15. this._sActionsUrl = this._sRootUrl + this._sActionsUri; // actions url address
  16. this._aGroupSettings = oOptions.aGroupSettings == undefined ? {} : oOptions.aGroupSettings;
  17. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  18. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  19. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  20. this._iProfileId = 0;
  21. this._iContentId = 0;
  22. }
  23. BxDolPrivacy.prototype.loadGroupCustom = function(aParams)
  24. {
  25. var $this = this;
  26. aParams = aParams || {};
  27. if(aParams && aParams.iProfileId != undefined)
  28. this._iProfileId = parseInt(aParams.iProfileId);
  29. if(aParams && aParams.iContentId != undefined)
  30. this._iContentId = parseInt(aParams.iContentId);
  31. if(aParams && aParams.aHtmlIds != undefined)
  32. this._aHtmlIds = $.extend({}, this._aHtmlIds, aParams.aHtmlIds);
  33. $(document).ready(function() {
  34. var oElement = $this._getSelectGroupElement();
  35. var iGroupId = 0;
  36. if(aParams && aParams.iGroupId != undefined)
  37. iGroupId = parseInt(aParams.iGroupId);
  38. if(!iGroupId && oElement && oElement.length > 0)
  39. iGroupId = parseInt($(oElement).val());
  40. if(!iGroupId || !$this._aGroupSettings[iGroupId])
  41. return;
  42. var oData = $.extend({}, $this._getDefaultParams(), {
  43. action: 'load_group_custom',
  44. profile_id: this._iProfileId,
  45. content_id: this._iContentId,
  46. group_id: iGroupId
  47. });
  48. $this._loadingInFormElement(oElement, true);
  49. $.get(
  50. $this._sActionsUrl,
  51. oData,
  52. function(oData) {
  53. $this._loadingInFormElement(oElement, false);
  54. processJsonData(oData);
  55. },
  56. 'json'
  57. );
  58. });
  59. };
  60. BxDolPrivacy.prototype.selectGroup = function(oElement)
  61. {
  62. $('#' + this._aHtmlIds['group_custom_element']).remove();
  63. var iGroupId = parseInt($(oElement).val());
  64. if(!this._aGroupSettings[iGroupId] || !this._aGroupSettings[iGroupId]['js_method_create_group'])
  65. return;
  66. var sMethodCreateGroup = 'selectMembers';
  67. if(this._aGroupSettings[iGroupId]['js_method_create_group'])
  68. sMethodCreateGroup = this._aGroupSettings[iGroupId]['js_method_create_group'];
  69. this[sMethodCreateGroup](oElement, iGroupId);
  70. };
  71. BxDolPrivacy.prototype.onSelectGroup = function(oData)
  72. {
  73. var oElement = this._getSelectGroupElement();
  74. if(oData && oData.content != undefined && oElement.length > 0)
  75. oElement.after(oData.content);
  76. };
  77. BxDolPrivacy.prototype.editGroup = function(oElement)
  78. {
  79. var iGroupId = parseInt($(oElement).parents('.bx-form-element:first').find('.sys-privacy-group').val());
  80. var sMethodCreateGroup = 'selectMembers';
  81. if(this._aGroupSettings[iGroupId]['js_method_create_group'])
  82. sMethodCreateGroup = this._aGroupSettings[iGroupId]['js_method_create_group'];
  83. this[sMethodCreateGroup](oElement, iGroupId, {
  84. popup_only: 1
  85. });
  86. };
  87. BxDolPrivacy.prototype.selectMembers = function(oElement, iGroupId, aParams)
  88. {
  89. var $this = this;
  90. var oData = $.extend({}, $this._getDefaultParams(), {action: 'select_members', group_id: iGroupId}, (aParams || {}));
  91. this._loadingInFormElement(oElement, true);
  92. $.get(
  93. this._sActionsUrl,
  94. oData,
  95. function(oData) {
  96. $this._loadingInFormElement(oElement, false);
  97. processJsonData(oData);
  98. },
  99. 'json'
  100. );
  101. };
  102. BxDolPrivacy.prototype.onSelectUsers = function(oData)
  103. {
  104. $('#' + this._aHtmlIds['group_custom_element']).remove();
  105. this.onSelectGroup(oData);
  106. };
  107. BxDolPrivacy.prototype.selectMemberships = function(oElement, iGroupId, aParams)
  108. {
  109. var $this = this;
  110. var oData = $.extend({}, $this._getDefaultParams(), {action: 'select_memberships', group_id: iGroupId}, (aParams || {}));
  111. this._loadingInFormElement(oElement, true);
  112. $.get(
  113. this._sActionsUrl,
  114. oData,
  115. function(oData) {
  116. $this._loadingInFormElement(oElement, false);
  117. processJsonData(oData);
  118. },
  119. 'json'
  120. );
  121. };
  122. BxDolPrivacy.prototype.onSelectMemberships = function(oData)
  123. {
  124. $('#' + this._aHtmlIds['group_custom_element']).remove();
  125. this.onSelectGroup(oData);
  126. };
  127. BxDolPrivacy.prototype._loading = function(e, bShow)
  128. {
  129. var oParent = $(e).length ? $(e) : $('body');
  130. bx_loading(oParent, bShow);
  131. };
  132. BxDolPrivacy.prototype._loadingInBlock = function(e, bShow)
  133. {
  134. var oParent = $(e).length ? $(e).parents('.bx-db-content:first') : $('body');
  135. bx_loading(oParent, bShow);
  136. };
  137. BxDolPrivacy.prototype._loadingInFormElement = function(e, bShow)
  138. {
  139. var oParent = $(e).length ? $(e).parents('.bx-form-element:first') : $('body');
  140. bx_loading(oParent, bShow);
  141. };
  142. BxDolPrivacy.prototype._getSelectGroupElement = function()
  143. {
  144. return $('#' + this._aHtmlIds['form'] + ' #' + this._aHtmlIds['group_element'] + ' .sys-privacy-group');
  145. };
  146. BxDolPrivacy.prototype._getDefaultParams = function()
  147. {
  148. var oDate = new Date();
  149. return {
  150. profile_id: this._iProfileId,
  151. content_id: this._iContentId,
  152. object: this._sObject,
  153. _t: oDate.getTime()
  154. };
  155. };
  156. /** @} */