functions.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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 processJsonData(oData) {
  9. var $this = this;
  10. if(oData && oData.message != undefined && oData.message.length != 0)
  11. alert(oData.message);
  12. if(oData && oData.reload != undefined && parseInt(oData.reload) == 1)
  13. document.location = document.location;
  14. if(oData && oData.popup != undefined) {
  15. var oPopup = null;
  16. var oOptions = {
  17. fog: {
  18. color: '#fff',
  19. opacity: .7
  20. },
  21. closeOnOuterClick: false
  22. };
  23. if(typeof(oData.popup) == 'object') {
  24. oOptions = $.extend({}, oOptions, oData.popup.options);
  25. oPopup = $(oData.popup.html);
  26. }
  27. else
  28. oPopup = $(oData.popup);
  29. $('#' + oPopup.attr('id')).remove();
  30. oPopup.hide().prependTo('body').dolPopup(oOptions);
  31. }
  32. if (oData && oData.eval != undefined)
  33. eval(oData.eval);
  34. };
  35. function getHtmlData( elem, url, callback, method , confirmation)
  36. {
  37. if ('undefined' != typeof(confirmation) && confirmation && !confirm(_t('_are you sure?')))
  38. return false;
  39. // in most cases it is element ID, in other cases - object of jQuery
  40. if (typeof elem == 'string')
  41. elem = '#' + elem; // create selector from ID
  42. var $block = $(elem);
  43. var blockPos = $block.css('position');
  44. $block.css('position', 'relative'); // set temporarily for displaying "loading icon"
  45. bx_loading_content($block, true);
  46. var $loadingDiv = $block.find('.bx-loading-ajax');
  47. var iLeftOff = parseInt(($block.innerWidth() / 2.0) - ($loadingDiv.outerWidth() / 2.0));
  48. var iTopOff = parseInt(($block.innerHeight() / 2.0) - ($loadingDiv.outerHeight()));
  49. if (iTopOff<0) iTopOff = 0;
  50. $loadingDiv.css({
  51. position: 'absolute',
  52. left: iLeftOff,
  53. top: iTopOff
  54. });
  55. if (undefined != method && (method == 'post' || method == 'POST')) {
  56. $.post(url, function(data) {
  57. $block.html(data);
  58. $block.css('position', blockPos).bxTime();
  59. if ($.isFunction($.fn.addWebForms))
  60. $block.addWebForms();
  61. bx_activate_anim_icons();
  62. if (typeof callback == 'function')
  63. callback.apply($block);
  64. });
  65. } else {
  66. $block.load(url + '&_r=' + Math.random(), function() {
  67. $(this).css('position', blockPos).bxTime();
  68. if ($.isFunction($.fn.addWebForms))
  69. $(this).addWebForms();
  70. bx_activate_anim_icons();
  71. if (typeof callback == 'function')
  72. callback.apply(this);
  73. });
  74. }
  75. }
  76. function loadDynamicBlockAutoPaginate (e, iStart, iPerPage, sAdditionalUrlParams) {
  77. sUrl = location.href;
  78. sUrl = sUrl.replace(/start=\d+/, '').replace(/per_page=\d+/, '').replace(/[&\?]+$/, '');
  79. sUrl = bx_append_url_params(sUrl, 'start=' + parseInt(iStart) + '&per_page=' + parseInt(iPerPage));
  80. if ('undefined' != typeof(sAdditionalUrlParams))
  81. sUrl = bx_append_url_params(sUrl, sAdditionalUrlParams);
  82. return loadDynamicBlockAuto(e, sUrl);
  83. }
  84. /**
  85. * This function reloads page block automatically,
  86. * just provide any element inside the block and this function will reload the block.
  87. * @param e - element inside the block
  88. * @return true on success, or false on error - particularly, if block isn't found
  89. */
  90. function loadDynamicBlockAuto(e, sUrl) {
  91. var oContainer = $(e).parents('.bx-page-block-container:first');
  92. var sId = oContainer.attr('id');
  93. if ('undefined' == typeof(sUrl))
  94. sUrl = location.href;
  95. if (!sId || !sId.length)
  96. return false;
  97. var aMatches = sId.match(/\-(\d+)$/);
  98. if (!aMatches || !aMatches[1])
  99. return false;
  100. var oPaginate = oContainer.find('.bx-paginate');
  101. if(oPaginate.length > 0) {
  102. var iStart = parseInt(oPaginate.attr('bx-data-start'));
  103. var iPerPage = parseInt(oPaginate.attr('bx-data-perpage'));
  104. if(!isNaN(iStart) && !isNaN(iPerPage) && sUrl.indexOf('start') == -1 && sUrl.indexOf('per_page') == -1)
  105. sUrl = bx_append_url_params(sUrl, 'start=' + iStart + '&per_page=' + iPerPage);
  106. }
  107. loadDynamicBlock(parseInt(aMatches[1]), sUrl);
  108. return true;
  109. }
  110. function loadDynamicBlock(iBlockID, sUrl) {
  111. getHtmlData($('#bx-page-block-' + iBlockID), bx_append_url_params(sUrl, 'dynamic=tab&pageBlock=' + iBlockID));
  112. return true;
  113. }
  114. function loadDynamicPopupBlock(iBlockID, sUrl) {
  115. if (!$('#dynamicPopup').length) {
  116. $('<div id="dynamicPopup" style="display:none;"></div>').prependTo('body');
  117. }
  118. $('#dynamicPopup').load(
  119. (sUrl + '&dynamic=popup&pageBlock=' + iBlockID),
  120. function() {
  121. $(this).dolPopup({
  122. left: 0,
  123. top: 0
  124. });
  125. }
  126. );
  127. }
  128. function closeDynamicPopupBlock() {
  129. $('#dynamicPopup').dolPopupHide();
  130. }
  131. /**
  132. * Translate string
  133. */
  134. function _t(s, arg0, arg1, arg2) {
  135. if (!window.aDolLang || !aDolLang[s])
  136. return s;
  137. cs = aDolLang[s];
  138. cs = cs.replace(/\{0\}/g, arg0);
  139. cs = cs.replace(/\{1\}/g, arg1);
  140. cs = cs.replace(/\{2\}/g, arg2);
  141. return cs;
  142. }
  143. function showPopupAnyHtml(sUrl, sId) {
  144. var oPopupOptions = {};
  145. if (!sId || !sId.length)
  146. sId = 'login_div';
  147. $('#' + sId).remove();
  148. $('<div id="' + sId + '" style="display: none;"></div>').prependTo('body').load(
  149. sUrl.match('^http[s]{0,1}:\/\/') ? sUrl : sUrlRoot + sUrl,
  150. function() {
  151. $(this).dolPopup(oPopupOptions);
  152. }
  153. );
  154. }
  155. function bx_loading_svg(sType, sClass) {
  156. sClass = sClass != undefined && sClass.length > 0 ? sClass : '';
  157. var s = '';
  158. s += '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 520 520" class="' + sClass + '" style="enable-background:new 0 0 520 520;" xml:space="preserve">';
  159. s += '<g class="' + sType + '">';
  160. s += '<g class="inner">';
  161. s += '<path class="p1" d="M152,260C152,260,152,260,152,260c0-59.8,48.4-108.4,108.1-108.4c43.3,0,80.9,25.6,97.9,62.4V107.3c-28-18.3-61.9-28.9-98.1-28.9C159.8,78.4,78.6,159.9,78.6,260c0,59.5,28.4,112.4,73.4,145.6V260z"/>';
  162. s += '<path class="p2" d="M368,114.4V260c0,59.8-48.4,108.4-108.1,108.4c-43.3,0-80.9-25.6-97.9-62.4v106.7c28,18.3,61.9,28.9,98.1,28.9c100.1,0,181.3-81.4,181.3-181.6C441.4,200.5,413,147.6,368,114.4z"/>';
  163. s += '</g>';
  164. s += '<g class="outer">';
  165. s += '<path class="p1" d="M146.9,106.7c-8.1-15-36.9-29.9-68.9-27.3v124.2C90,164.3,114.6,130.5,146.9,106.7z"/>';
  166. s += '<path class="p2" d="M373.1,413.3c8.1,15,36.7,29.9,68.9,27.3V316.4C429.8,355.7,405.4,389.5,373.1,413.3z"/>';
  167. s += '</g>';
  168. s += '</g>';
  169. s += '</svg>';
  170. return s;
  171. }
  172. function bx_loading_animate (e, aOptions) {
  173. e = $(e);
  174. if (!e.length)
  175. return false;
  176. if (e.find('.bx-sys-spinner').length)
  177. return false;
  178. return new Spinner(aOptions).spin(e.get(0));
  179. }
  180. function bx_loading_btn (oElement, bEnable) {
  181. var bUseSvg = true;
  182. var oButton = $(oElement);
  183. if (oButton.children('div').size())
  184. oButton = oButton.children('div').first();
  185. if(!bEnable)
  186. oButton.find('.bx-loading-ajax-btn').remove();
  187. else if (!oButton.find('.bx-loading-ajax-btn').length)
  188. oButton.append('<b class="bx-loading-ajax-btn bx-btn-height">' + (bUseSvg ? bx_loading_svg('colored', 'bx-btn-height') : '') + '</b>');
  189. if(!bUseSvg)
  190. bx_loading_animate(oButton.find('.bx-loading-ajax-btn'), aSpinnerSmallOpts);
  191. }
  192. function bx_loading_content (oElement, bEnable, isReplace) {
  193. var bUseSvg = true;
  194. var oBlock = $(oElement);
  195. var oLoading = $('<div class="bx-loading-ajax bx-def-z-index-front">' + (bUseSvg ? bx_loading_svg('colored') : '') + '</div>');
  196. if(!bEnable)
  197. oBlock.find(".bx-loading-ajax").remove();
  198. else if(!oBlock.find('.bx-loading-ajax').length) {
  199. if('undefined' != typeof(isReplace) && isReplace)
  200. oBlock.html(oLoading.addClass('static'));
  201. else
  202. oBlock.append(oLoading);
  203. if(!bUseSvg)
  204. bx_loading_animate(oBlock.find('.bx-loading-ajax'), aSpinnerOpts);
  205. }
  206. }
  207. function bx_loading (elem, b) {
  208. if (typeof elem == 'string')
  209. elem = '#' + elem;
  210. var block = $(elem);
  211. if (block.hasClass('bx-btn')) {
  212. bx_loading_btn (block, b);
  213. return;
  214. }
  215. if (1 == b || true == b) {
  216. bx_loading_content(block, b);
  217. e = block.find(".bx-loading-ajax");
  218. e.css('left', parseInt(block.width()/2.0 - e.width()/2.0));
  219. var he = e.outerHeight();
  220. var hc = block.outerHeight();
  221. if (block.css('position') != 'relative' && block.css('position') != 'absolute') {
  222. if (!block.data('css-save-position'))
  223. block.data('css-save-position', block.css('position'));
  224. block.css('position', 'relative');
  225. }
  226. if (hc > he) {
  227. e.css('top', parseInt(hc/2.0 - he/2.0));
  228. }
  229. if (hc < he) {
  230. if (!block.data('css-save-min-height'))
  231. block.data('css-save-min-height', block.css('min-height'));
  232. block.css('min-height', he);
  233. e.css('top', 0);
  234. }
  235. } else {
  236. if (block.data('css-save-position'))
  237. block.css('position', block.data('css-save-position'));
  238. if (block.data('css-save-min-height'))
  239. block.css('min-height', block.data('css-save-min-height'));
  240. bx_loading_content(block, b);
  241. }
  242. }
  243. /**
  244. * Center content with floating blocks.
  245. * sSel - jQuery selector of content to be centered
  246. * sBlockSel - jquery selector of blocks
  247. */
  248. function bx_center_content (sSel, sBlockStyle, bListenOnResize) {
  249. var sId;
  250. if ($(sSel).parent().hasClass('bx-center-content-wrapper')) {
  251. sId = $(sSel).parent().attr('id');
  252. } else {
  253. sId = 'id' + (new Date()).getTime();
  254. $(sSel).wrap('<div id="'+sId+'" class="bx-center-content-wrapper"></div>');
  255. }
  256. var eCenter = $('#' + sId);
  257. var iAll = $('#' + sId + ' ' + sBlockStyle).size();
  258. var iWidthUnit = $('#' + sId + ' ' + sBlockStyle + ':first').outerWidth(true);
  259. var iWidthContainer = eCenter.innerWidth();
  260. var iPerRow = parseInt(iWidthContainer/iWidthUnit);
  261. var iLeft = (iWidthContainer - (iAll > iPerRow ? iPerRow * iWidthUnit : iAll * iWidthUnit)) / 2;
  262. if (iWidthUnit > iWidthContainer)
  263. return;
  264. if ('undefined' != typeof(bListenOnResize) && bListenOnResize) {
  265. $(window).on('resize.bx-center-content', function () {
  266. bx_center_content(sSel, sBlockStyle);
  267. });
  268. }
  269. eCenter.css("padding-left", iLeft);
  270. }
  271. /**
  272. * Show pointer popup with menu from URL.
  273. * @param o - menu object name
  274. * @param e - element to show popup at
  275. * @param options - popup options
  276. * @param vars - additional GET variables
  277. */
  278. function bx_menu_popup (o, e, options, vars) {
  279. var options = options || {};
  280. var vars = vars || {};
  281. var o = $.extend({}, $.fn.dolPopupDefaultOptions, {id: o, url: bx_append_url_params('menu.php', $.extend({o:o}, vars))}, options);
  282. if ('undefined' == typeof(e))
  283. e = window;
  284. $(e).dolPopupAjax(o);
  285. }
  286. /**
  287. * Show pointer popup with menu from existing HTML.
  288. * @param jSel - jQuery selector for html to show in popup
  289. * @param e - element to show popup at
  290. * @param options - popup options
  291. */
  292. function bx_menu_popup_inline (jSel, e, options) {
  293. var options = options || {};
  294. var o = $.extend({}, $.fn.dolPopupDefaultOptions, options, {pointer:{el:$(e)}});
  295. if ($(jSel + ':visible').length)
  296. $(jSel).dolPopupHide();
  297. else
  298. $(jSel).dolPopup(o);
  299. }
  300. /**
  301. * Show pointer popup with menu from existing HTML.
  302. * @param jSel - jQuery selector for html to show in popup
  303. * @param e - element to click to open/close slider
  304. * @param sPosition - 'block' for sliding menu in blocks, 'site' - for sliding main menu
  305. */
  306. function bx_menu_slide (jSel, e, sPosition) {
  307. var options = options || {};
  308. var eSlider = $(jSel);
  309. if ('undefined' == typeof(e))
  310. e = eSlider.data('data-control-btn');
  311. var eIcon = $(e).find('.sys-icon-a');
  312. var fPositionBlock = function () {
  313. var eBlock = eSlider.parents('.bx-page-block-container');
  314. eSlider.css({
  315. position: 'absolute',
  316. top: eBlock.find('.bx-db-header').outerHeight(true),
  317. left: 0
  318. //width: eBlock.width() TODO: Commited to test. Remove if everything is OK.
  319. });
  320. };
  321. var fPositionSite = function () {
  322. var eToolbar = $('#bx-toolbar');
  323. eSlider.css({
  324. position: 'fixed',
  325. top: eToolbar.outerHeight(true),
  326. left: 0
  327. });
  328. };
  329. var fClose = function () {
  330. if (eIcon.length)
  331. (new Marka(eIcon[0])).set(eIcon.attr('data-icon-orig'));
  332. eSlider.slideUp()
  333. };
  334. var fOpen = function () {
  335. if (eIcon.length) {
  336. eIcon.attr('data-icon-orig', eIcon.attr('data-icon'));
  337. (new Marka(eIcon[0])).set('times');
  338. }
  339. if ('block' == sPosition)
  340. fPositionBlock();
  341. else
  342. fPositionSite();
  343. eSlider.slideDown();
  344. eSlider.data('data-control-btn', e);
  345. };
  346. if ('undefined' == typeof(sPosition))
  347. sPosition = 'block';
  348. if ($(jSel + ':visible').length) {
  349. fClose();
  350. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  351. $(window).off('resize.bx-sliding-menu');
  352. }
  353. else {
  354. bx_menu_slide_close_all_opened();
  355. $(document).off('click.bx-sliding-menu touchend.bx-sliding-menu');
  356. $(window).off('resize.bx-sliding-menu');
  357. fOpen();
  358. eSlider.find('a').each(function () {
  359. $(this).off('click.bx-sliding-menu');
  360. $(this).on('click.bx-sliding-menu', function () {
  361. fClose();
  362. });
  363. });
  364. setTimeout(function () {
  365. var iWidthPrev = $(window).width();
  366. $(window).on('resize.bx-sliding-menu', function () {
  367. if ($(this).width() == iWidthPrev)
  368. return;
  369. iWidthPrev = $(this).width();
  370. bx_menu_slide_close_all_opened();
  371. });
  372. $(document).on('click.bx-sliding-menu touchend.bx-sliding-menu', function (event) {
  373. if ($(event.target).parents('.bx-sliding-menu-main, .bx-popup-slide-wrapper, .bx-db-header').length || $(event.target).filter('.bx-sliding-menu-main, .bx-popup-slide-wrapper, .bx-db-header').length || e === event.target)
  374. event.stopPropagation();
  375. else
  376. bx_menu_slide_close_all_opened();
  377. });
  378. }, 10);
  379. }
  380. }
  381. /**
  382. * Close all opened sliding menus
  383. */
  384. function bx_menu_slide_close_all_opened () {
  385. $('.bx-sliding-menu-main:visible, .bx-popup-slide-wrapper:visible').each(function () {
  386. bx_menu_slide('#' + this.id);
  387. });
  388. }
  389. /*
  390. * Note. oData.count_old and oData.count_new are also available and can be checked or used in notification popup.
  391. */
  392. function bx_menu_show_live_update(oData) {
  393. //--- Update Child Menu Item
  394. if(oData.mi_child) {
  395. var oMenuItem = $('.bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item-' + oData.mi_child.menu_item);
  396. var oMenuItemAddon = oMenuItem.find('.bx-menu-item-addon');
  397. if(oMenuItemAddon.length > 0)
  398. oMenuItemAddon.html(oData.count_new);
  399. else
  400. oMenuItem.append(oData.code.replace('{count}', oData.count_new));
  401. }
  402. //--- Update Parent Menu Item
  403. if(oData.mi_parent) {
  404. var oMenuItem = $('.bx-menu-object-' + oData.mi_parent.menu_object + ' #bx-menu-toolbar-item-' + oData.mi_parent.menu_item);
  405. var oMenuItemAddon = oMenuItem.find('.bx-menu-item-addon');
  406. var iSum = 0;
  407. $('.bx-menu-object-' + oData.mi_child.menu_object + ' .bx-menu-item .bx-menu-item-addon').each(function() {
  408. iValue = parseInt($(this).html());
  409. if(iValue && iValue > 0)
  410. iSum += iValue;
  411. });
  412. if(oMenuItemAddon.length > 0)
  413. oMenuItemAddon.html(iSum);
  414. else
  415. oMenuItem.append(oData.code.replace('{count}', iSum));
  416. }
  417. }
  418. /**
  419. * Set ACL level for specified profile
  420. * @param iProfileId - profile id to set acl level for
  421. * @param iAclLevel - acl level id to assign to a given rofile
  422. */
  423. function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
  424. if ('undefined' != typeof(mixedLoadingElement))
  425. bx_loading($(mixedLoadingElement), true);
  426. $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', 'profile_id': iProfileId, 'acl_level_id': iAclLevel}, function(data) {
  427. if ('undefined' != typeof(mixedLoadingElement))
  428. bx_loading($(mixedLoadingElement), false);
  429. if (data.length) {
  430. alert(data);
  431. } else if ($(mixedLoadingElement).hasClass('bx-popup-applied')) {
  432. $(mixedLoadingElement).dolPopupHide().remove();
  433. }
  434. });
  435. }
  436. function validateLoginForm(eForm) {
  437. return true;
  438. }
  439. /**
  440. * convert <time> tags to human readable format
  441. * @param sLang - use sLang localization
  442. * @param isAutoupdate - for internal usage only
  443. */
  444. function bx_time(sLang, isAutoupdate, sRootSel) {
  445. if ('undefined' == typeof(sRootSel))
  446. sRootSel = 'body';
  447. var iAutoupdate = 22*60*60; // autoupdate time in realtime if less than 22 hours
  448. var sSel = 'time';
  449. if ('undefined' == typeof(sLang)) {
  450. sLang = glBxTimeLang;
  451. } else {
  452. glBxTimeLang = sLang;
  453. }
  454. if ('undefined' != typeof(isAutoupdate) && isAutoupdate)
  455. sSel += '.bx-time-autoupdate';
  456. $(sRootSel).find(sSel).each(function () {
  457. var s;
  458. var sTime = $(this).attr('datetime');
  459. var iSecondsDiff = moment(sTime).unix() - moment().unix();
  460. if (iSecondsDiff < 0)
  461. iSecondsDiff = -iSecondsDiff;
  462. if (iSecondsDiff < $(this).attr('data-bx-autoformat'))
  463. s = moment(sTime).locale(sLang).fromNow(); // 'time ago' format
  464. else
  465. s = moment(sTime).locale(sLang).format($(this).attr('data-bx-format')); // custom format
  466. if (iSecondsDiff < iAutoupdate)
  467. $(this).addClass('bx-time-autoupdate');
  468. else
  469. $(this).removeClass('bx-time-autoupdate');
  470. $(this).html(s);
  471. });
  472. if ($('time.bx-time-autoupdate').size()) {
  473. setTimeout(function () {
  474. bx_time(sLang, true);
  475. }, 20000);
  476. }
  477. }
  478. (function($) {
  479. $.fn.bxTime = function() {
  480. bx_time(undefined, undefined, this);
  481. return this;
  482. };
  483. } (jQuery));
  484. /**
  485. * Perform connections AJAX request.
  486. * In case of error - it shows js alert with error message.
  487. * In case of success - the page is reloaded.
  488. *
  489. * @param sObj - connections object
  490. * @param sAction - 'add', 'remove' or 'reject'
  491. * @param iContentId - content id, initiator is always current logged in user
  492. * @param bConfirm - show confirmation dialog
  493. */
  494. function bx_conn_action(e, sObj, sAction, iContentId, bConfirm, fOnComplete) {
  495. if ('undefined' != typeof(bConfirm) && bConfirm && !confirm(_t('_are you sure?')))
  496. return;
  497. var aParams = {
  498. obj: sObj,
  499. act: sAction,
  500. id: iContentId
  501. };
  502. var fCallback = function (data) {
  503. bx_loading_btn(e, 0);
  504. if ('object' != typeof(data))
  505. return;
  506. if (data.err) {
  507. alert(data.msg);
  508. } else {
  509. if ('function' == typeof(fOnComplete))
  510. fOnComplete(data, e);
  511. else if (!loadDynamicBlockAuto(e))
  512. location.reload();
  513. else
  514. $('#bx-popup-ajax-wrapper-bx_persons_view_actions_more').remove();
  515. }
  516. };
  517. bx_loading_btn(e, 1);
  518. $.ajax({
  519. dataType: 'json',
  520. url: sUrlRoot + 'conn.php',
  521. data: aParams,
  522. type: 'POST',
  523. success: fCallback
  524. });
  525. }
  526. function bx_append_url_params (sUrl, mixedParams) {
  527. var sParams = sUrl.indexOf('?') == -1 ? '?' : '&';
  528. if(mixedParams instanceof Array) {
  529. for(var i in mixedParams)
  530. sParams += i + '=' + mixedParams[i] + '&';
  531. sParams = sParams.substr(0, sParams.length-1);
  532. }
  533. else if(mixedParams instanceof Object) {
  534. $.each(mixedParams, function(sKey, sValue) {
  535. sParams += sKey + '=' + sValue + '&';
  536. });
  537. sParams = sParams.substr(0, sParams.length-1);
  538. }
  539. else
  540. sParams += mixedParams;
  541. return sUrl + sParams;
  542. }
  543. function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
  544. if ('undefined' != typeof(e) && 13 == e.keyCode) {
  545. $(sFormSel).find('input[name=live_search]').val(0);
  546. $(sFormSel).submit();
  547. return false;
  548. }
  549. if ('undefined' != typeof(glBxSearchTimeoutHandler) && glBxSearchTimeoutHandler)
  550. clearTimeout(glBxSearchTimeoutHandler);
  551. glBxSearchTimeoutHandler = setTimeout(function () {
  552. bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults);
  553. }, 500);
  554. return true;
  555. }
  556. function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
  557. if ('undefined' == typeof(sLoadingContSel))
  558. sLoadingContSel = sResultsContSel;
  559. if ('undefined' == typeof(bSortResults))
  560. bSortResults = false;
  561. var sQuery = $('input', sFormSel).serialize();
  562. bx_loading($(sLoadingContSel), true);
  563. $.post(sUrlRoot + 'searchKeywordContent.php', sQuery, function(data) {
  564. bx_loading($(sLoadingContSel), false);
  565. if (bSortResults) {
  566. var aSortedUnits = $(data).find(".bx-def-unit-live-search").toArray().sort(function (a, b) {
  567. return b.getAttribute('data-ts') - a.getAttribute('data-ts');
  568. });
  569. data = '';
  570. $.each(aSortedUnits.slice(0, n), function (i, e) {
  571. data += e.outerHTML;
  572. });
  573. }
  574. $(sResultsContSel).html(data).bxTime();
  575. });
  576. return false;
  577. }
  578. function on_filter_apply(e, sInputId, sFilterName)
  579. {
  580. var oRegExp = new RegExp("[&]{0,1}" + sFilterName + "=.*");
  581. var s = ('' + document.location).replace(oRegExp, ''); // remove filter
  582. s = s.replace(/page=\d+/, 'page=1'); // goto 1st page
  583. if (e.checked && $('#' + sInputId).val().length > 2)
  584. s += (-1 == s.indexOf('?') ? '?' : '&') + sFilterName + '=' + $('#' + sInputId).val(); // append filter
  585. document.location = s;
  586. }
  587. function on_filter_key_up (e, sCheckboxId)
  588. {
  589. if (13 == e.keyCode) {
  590. $('#' + sCheckboxId).click();
  591. return false;
  592. }
  593. else {
  594. $('#' + sCheckboxId).removeAttr('checked');
  595. return true;
  596. }
  597. }
  598. function bx_activate_anim_icons(sColor)
  599. {
  600. if ('undefined' == typeof(sColor))
  601. sColor = glBxAnimIconColor;
  602. else
  603. glBxAnimIconColor = sColor;
  604. $('.sys-icon-a').not('.marka').each(function () {
  605. var e = $(this);
  606. var m = new Marka(e.get(0)), r = e.attr('data-rotate'), c = e.attr('data-color');
  607. m.set(e.attr('data-icon')).rotate(r ? r : 'down').color(c ? c : sColor);
  608. });
  609. }
  610. function bx_get_style(sUrl)
  611. {
  612. $("head").append($("<link rel='stylesheet' href='" + sUrl + "' type='text/css' />"));
  613. }
  614. function bx_get_param(s) {
  615. if (!window.aDolOptions || !aDolOptions[s])
  616. return false;
  617. return aDolOptions[s];
  618. }
  619. function bx_autocomplete_fields(id, url, name, b_img){
  620. $('#' + id + ' input[type=text]').autocomplete({
  621. source: url,
  622. select: function(e, ui) {
  623. $(this).val(ui.item.label);
  624. $(this).trigger('superselect', ui.item);
  625. e.preventDefault();
  626. }
  627. });
  628. $('#' + id + ' input[type=text]').on('superselect', function(e, item) {
  629. $(this).hide();
  630. if ('undefined' != typeof(item))
  631. $(this).before('<b class="bx-def-color-bg-hl bx-def-round-corners">' + (b_img ? '<img class="bx-def-thumb bx-def-thumb-size bx-def-margin-sec-right" src="' + item.thumb + '">' : '') + item.label +'<input type="hidden" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" name="' + name + '[]" value="'+ item.value +'" /></b>');
  632. fAutoShrinkInput();
  633. $(this).show();
  634. this.value = '';
  635. }).on('keydown', function(e) {
  636. // if: comma,enter (delimit more keyCodes with | pipe)
  637. if (/(13)/.test(e.which))
  638. e.preventDefault();
  639. });
  640. $('#' + id).on('click', 'b', function() {
  641. $(this).remove();
  642. fAutoShrinkInput();
  643. });
  644. fAutoShrinkInput = function () {
  645. var iWidthCont = $('#' + id + '.bx-form-input-autotoken').innerWidth();
  646. var iWidthExisting = 0;
  647. $('#' + id + '.bx-form-input-autotoken b').each(function () {
  648. iWidthExisting += $(this).outerWidth(true);
  649. });
  650. $('#' + id + '.bx-form-input-autotoken input').width(parseInt(iWidthCont - iWidthExisting > 180 ? iWidthCont - iWidthExisting : 180) - 5);
  651. };
  652. fAutoShrinkInput();
  653. };
  654. /** @} */