BxDolCreatePost.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 BxDolCreatePost(oOptions) {
  9. this._sObjName = oOptions.sObjName == undefined ? 'oBxDolCreatePost' : oOptions.sObjName;
  10. this._sRootUrl = oOptions.sRootUrl == undefined ? sUrlRoot : oOptions.sRootUrl;
  11. this._sDefault = oOptions.sDefault == undefined ? '' : oOptions.sDefault;
  12. this._iContextId = oOptions.iContextId == undefined ? 0 : oOptions.iContextId;
  13. this._oPreloadingList = oOptions.oPreloadingList == undefined ? [] : oOptions.oPreloadingList;
  14. this._oCustom = oOptions.oCustom == undefined ? {} : oOptions.oCustom;
  15. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  16. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  17. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  18. var $this = this;
  19. $(document).ready(function() {
  20. $this.init();
  21. });
  22. }
  23. BxDolCreatePost.prototype.init = function () {
  24. var oDate = new Date();
  25. for(var sKey in this._oPreloadingList) {
  26. var sForm = '.sys-cpf-form.sys-cpf-' + sKey;
  27. if($(sForm).length != 0)
  28. continue;
  29. $.get(
  30. this._sRootUrl + 'modules/?r=' + this._oPreloadingList[sKey] + '/get_create_post_form/', {
  31. ajax_mode: true,
  32. dynamic_mode: true,
  33. absolute_action_url: true,
  34. context_id: this._iContextId,
  35. custom: this._oCustom,
  36. _t:oDate.getTime()
  37. },
  38. function(oData) {
  39. if(!oData || !oData.content)
  40. return;
  41. $('.sys-cpf-close').before($('<div class="sys-cpf-form sys-cpf-' + oData.module + '">' + oData.content + '</div>').hide());
  42. },
  43. 'json'
  44. );
  45. }
  46. };
  47. BxDolCreatePost.prototype.getForm = function (sModuleName, sModuleUri, oElement) {
  48. var $this = this;
  49. var oTab = $(oElement);
  50. var sTabActive = 'bx-menu-tab-active';
  51. oTab.parents('.bx-db-menu:first').find('li.' + sTabActive).removeClass(sTabActive);
  52. oTab.parents('li:first').addClass(sTabActive);
  53. oTab.parents('.bx-popup-applied:visible').dolPopupHide();
  54. $('.sys-cpf-form:visible').hide({
  55. duration: 0,
  56. complete: function() {
  57. $('.sys-cpf-close:visible').hide();
  58. if(!$('.sys-cpf-form.sys-cpf-' + sModuleName + ' form').length) {
  59. var oDate = new Date();
  60. $this._placeholderInBlock(oElement, true);
  61. $.get(
  62. $this._sRootUrl + 'modules/?r=' + sModuleUri + '/get_create_post_form/', {
  63. ajax_mode: true,
  64. dynamic_mode: true,
  65. absolute_action_url: true,
  66. context_id: $this._iContextId,
  67. custom: $this._oCustom,
  68. _t: oDate.getTime()
  69. },
  70. function(oData) {
  71. $this._placeholderInBlock(oElement, false);
  72. if(!oData || !oData.content)
  73. return;
  74. var sForm = '.sys-cpf-form.sys-cpf-' + oData.module;
  75. if($(sForm).length == 0)
  76. $('.sys-cpf-close').before($('<div class="sys-cpf-form sys-cpf-' + oData.module + '"></div>').hide());
  77. $(sForm).html(oData.content).show().bxProcessHtml().siblings('.sys-cpf-close:hidden').show();
  78. },
  79. 'json'
  80. );
  81. }
  82. else
  83. $('.sys-cpf-form.sys-cpf-' + sModuleName).show().bxProcessHtml().siblings('.sys-cpf-close:hidden').show();
  84. }
  85. });
  86. return false;
  87. };
  88. BxDolCreatePost.prototype.hideForm = function(oElement) {
  89. $(oElement).parents('.sys-cpf-close:first').hide();
  90. var sTabActive = 'bx-menu-tab-active';
  91. var sTabDefault = 'bx-menu-item-' + this._sDefault;
  92. var oMiActive = $(oElement).parents('.bx-db-container:first').find('ul > li.' + sTabActive);
  93. var bMiChange = !oMiActive.hasClass(sTabDefault);
  94. if(bMiChange)
  95. oMiActive.removeClass(sTabActive);
  96. $('.sys-cpf-form:visible').hide({
  97. duration: 0,
  98. complete: function() {
  99. $('.sys-cpf-form.sys-cpf-default').show();
  100. if(bMiChange)
  101. $('.' + sTabDefault).addClass(sTabActive);
  102. }
  103. });
  104. };
  105. BxDolCreatePost.prototype._loading = function(e, bShow) {
  106. var oParent = $(e).length ? $(e) : $('body');
  107. bx_loading(oParent, bShow);
  108. };
  109. BxDolCreatePost.prototype._loadingInBlock = function(e, bShow) {
  110. var oParent = $(e).length ? $(e).parents('.bx-db-container:first') : $('body');
  111. bx_loading(oParent, bShow);
  112. };
  113. BxDolCreatePost.prototype._placeholderInBlock = function(e, bShow) {
  114. var oPlaceholder = null;
  115. if($(e).length)
  116. oPlaceholder = $(e).parents('.bx-db-container:first').find('.sys-cpf-form.sys-cpf-loading');
  117. if(!oPlaceholder)
  118. return _loadingInBlock(e, bShow);
  119. if(bShow)
  120. oPlaceholder.show();
  121. else
  122. oPlaceholder.hide();
  123. };
  124. /** @} */