main.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. function BxInvMain(oOptions) {
  2. this._sActionsUri = oOptions.sActionUri;
  3. this._sActionsUrl = oOptions.sActionUrl;
  4. this._sObjName = oOptions.sObjName == undefined ? 'oInvMain' : oOptions.sObjName;
  5. this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
  6. this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
  7. this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'fade' : oOptions.sAnimationEffect;
  8. this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
  9. this._sObjNameGrid = oOptions.sObjNameGrid;
  10. this._sParamsDivider = oOptions.sParamsDivider == undefined ? '#-#' : oOptions.sParamsDivider;
  11. }
  12. BxInvMain.prototype.initRequestForm = function(sFormId) {
  13. var oForm = $('#' + sFormId);
  14. if(!oForm.length)
  15. return;
  16. oForm.ajaxForm({
  17. dataType: 'json',
  18. beforeSubmit: function (formData, jqForm, options) {
  19. bx_loading(oForm, true);
  20. },
  21. success: function (oData) {
  22. bx_loading(oForm, false);
  23. processJsonData(oData);
  24. }
  25. });
  26. };
  27. BxInvMain.prototype.onRequestFormSubmit = function(oData) {
  28. var $this = this;
  29. if(!oData || !oData.content || !oData.content_id)
  30. return;
  31. $('#' + oData.content_id).bx_anim('hide', this._sAnimationEffect, this._iAnimationSpeed, function() {
  32. $(this).replaceWith(oData.content);
  33. $this.initRequestForm(oData.content_id);
  34. });
  35. };
  36. BxInvMain.prototype.initAcceptForm = function(sFormId) {
  37. var oForm = $('#' + sFormId);
  38. if(!oForm.length)
  39. return;
  40. oForm.ajaxForm({
  41. dataType: 'json',
  42. beforeSubmit: function (formData, jqForm, options) {
  43. bx_loading(oForm, true);
  44. },
  45. success: function (oData) {
  46. bx_loading(oForm, false);
  47. processJsonData(oData);
  48. }
  49. });
  50. };
  51. BxInvMain.prototype.showLinkPopup = function(oElement) {
  52. var $this = this;
  53. this.loadingInButton(oElement, true);
  54. jQuery.get(
  55. this._sActionsUrl + 'get_link/',
  56. this._getDefaultData(),
  57. function(oData) {
  58. $this.loadingInButton(oElement, false);
  59. if(oData && oData.popup != undefined) {
  60. var oPopup = $(oData.popup);
  61. var sPopupId = oPopup.attr('id');
  62. var oClipboard = null;
  63. $('#' + sPopupId).remove();
  64. oPopup.hide().prependTo('body').dolPopup({
  65. onShow: function () {
  66. oClipboard = new ClipboardJS('#' + $this._aHtmlIds['link_popup'] + ' .bx-btn[name = "clipboard"]', {
  67. target: function(oTrigger) {
  68. return $('#' + sPopupId).find('[name = "link"]').get(0);
  69. }
  70. });
  71. oClipboard.on('success', function(oObject) {
  72. $this.hideLinkPopup();
  73. });
  74. },
  75. onHide: function () {
  76. if(oClipboard)
  77. oClipboard.destroy();
  78. }
  79. });
  80. }
  81. if(oData && oData.message != undefined)
  82. bx_alert(oData.message);
  83. },
  84. 'json'
  85. );
  86. };
  87. BxInvMain.prototype.showCodePopup = function(oElement) {
  88. var $this = this;
  89. this.loadingInButton(oElement, true);
  90. jQuery.get(
  91. this._sActionsUrl + 'get_code/',
  92. this._getDefaultData(),
  93. function(oData) {
  94. $this.loadingInButton(oElement, false);
  95. if(oData && oData.popup != undefined) {
  96. var oPopup = $(oData.popup);
  97. var sPopupId = oPopup.attr('id');
  98. var oClipboard = oClipboardLink = null;
  99. $('#' + sPopupId).remove();
  100. oPopup.hide().prependTo('body').dolPopup({
  101. onShow: function () {
  102. oClipboard = new ClipboardJS('#' + $this._aHtmlIds['code_popup'] + ' .bx-btn[name = "clipboard"]', {
  103. target: function(oTrigger) {
  104. return $('#' + sPopupId).find('[name = "code"]').get(0);
  105. }
  106. });
  107. oClipboard.on('success', function(oObject) {
  108. $this.hideCodePopup();
  109. });
  110. oClipboardLink = new ClipboardJS('#' + $this._aHtmlIds['code_popup'] + ' .bx-btn[name = "clipboard_link"]', {
  111. target: function(oTrigger) {
  112. return $('#' + sPopupId).find('[name = "link"]').get(0);
  113. }
  114. });
  115. oClipboardLink.on('success', function(oObject) {
  116. $this.hideCodePopup();
  117. });
  118. },
  119. onHide: function () {
  120. if(oClipboard)
  121. oClipboard.destroy();
  122. if(oClipboardLink)
  123. oClipboardLink.destroy();
  124. }
  125. });
  126. }
  127. if(oData && oData.message != undefined)
  128. bx_alert(oData.message);
  129. },
  130. 'json'
  131. );
  132. };
  133. BxInvMain.prototype.hideLinkPopup = function() {
  134. $('#' + this._aHtmlIds['link_popup']).dolPopupHide();
  135. };
  136. BxInvMain.prototype.hideCodePopup = function() {
  137. $('#' + this._aHtmlIds['code_popup']).dolPopupHide();
  138. };
  139. BxInvMain.prototype.loadingInButton = function(e, bShow) {
  140. if($(e).length)
  141. bx_loading_btn($(e), bShow);
  142. else
  143. bx_loading($('body'), bShow);
  144. };
  145. BxInvMain.prototype._loading = function(e, bShow) {
  146. var oParent = $(e).length ? $(e) : $('body');
  147. bx_loading(oParent, bShow);
  148. };
  149. BxInvMain.prototype._getDefaultData = function () {
  150. var oDate = new Date();
  151. return jQuery.extend({}, this._oRequestParams, {_t:oDate.getTime()});
  152. };
  153. BxInvMain.prototype.onChangeFilter = function (oFilter) {
  154. var $this = this;
  155. var oFilter1 = $('#bx-grid-filter1-' + this._sObjNameGrid);
  156. var sValueFilter1 = oFilter1.length > 0 ? oFilter1.val() : '';
  157. var oSearch = $('#bx-grid-search-' + this._sObjNameGrid);
  158. var sValueSearch = oSearch.length > 0 ? oSearch.val() : '';
  159. if(sValueSearch == _t('_sys_grid_search'))
  160. sValueSearch = '';
  161. clearTimeout($this._iSearchTimeoutId);
  162. $this._iSearchTimeoutId = setTimeout(function () {
  163. glGrids[$this._sObjNameGrid].setFilter(sValueFilter1 + $this._sParamsDivider + sValueSearch, true);
  164. }, 500);
  165. };
  166. BxInvMain.prototype.setFilter = function (sFilter, isReload) {
  167. if (this._sFilter == sFilter)
  168. return;
  169. this._sFilter = sFilter;
  170. if (isReload) {
  171. if (sFilter.length > 0)
  172. this.reload(0);
  173. else
  174. this.reload();
  175. }
  176. };