Procházet zdrojové kódy

Ticket #5688 - Improve JS 'bx_alert' to have a lite version without [OK] confirmation.

AntonLV před 3 týdny
rodič
revize
987ff9d5b7

+ 4 - 0
inc/js/classes/BxDolGrid.js

@@ -352,6 +352,10 @@ BxDolGrid.prototype.processJson = function (oData, sAction, isDisableLoading) {
         	fContinue();
         });
     }
+    else if (oData && undefined != oData.toast) {
+        bx_toast(oData.toast);
+        fContinue();
+    }
     else
     	fContinue();
 };

+ 28 - 0
inc/js/functions.js

@@ -57,6 +57,10 @@ function processJsonData(oData) {
 		bx_alert(oData.msg, function() {
 			fContinue(oData);
 		});
+    else if(oData && oData.toast != undefined && oData.toast.length != 0) {
+        bx_toast(oData.toast);
+        fContinue(oData);
+    }
 	else
 		fContinue(oData);
 };
@@ -1651,6 +1655,30 @@ function bx_prompt(sMessage, sValue, fOnClickOk, fOnClickCancel, oParams)
     });
 }
 
+function bx_toast(sMessage, oParams)
+{
+    var oDate = new Date();
+    var sId = 'bx-popup-toast';
+    var sIdClone = sId + '-' + oDate.getTime();
+
+    var oHolder = $('#' + sId + '-holder');
+    var oAlert = oHolder.find('#' + sId).clone();
+    oAlert.attr('id', sIdClone).find('.bx-pt-text').html(sMessage);
+    oHolder.append(oAlert.bx_anim('show', 'fade', 'slow', function() {
+        if(oParams && typeof(oParams.onShow) == 'function')
+            oParams.onShow();
+    }));
+
+    setTimeout(function() {
+        $('#' + sIdClone).bx_anim('hide', 'fade', 'slow', function() {
+            $(this).remove();
+
+            if(oParams && typeof(oParams.onHide) == 'function')
+                oParams.onHide();
+        })
+    }, 1000 * (oParams && oParams.autoHide !== undefined ? parseInt(oParams.autoHide) : 3));
+};
+
 function bx_is_color_scheme_dark()
 {
     return localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches);

+ 1 - 0
template/popup_trans_toast_cnt.html

@@ -0,0 +1 @@
+<div class="bx-pt-text p-2 text-center"></div>

+ 1 - 0
template/popup_trans_toast_holder.html

@@ -0,0 +1 @@
+<div id="__html_id__" class="fixed right-0 bottom-0 w-64 m-2 space-y-2">__sample__</div>

+ 10 - 2
template/scripts/BxBaseFunctions.php

@@ -832,6 +832,15 @@ class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
         )), true);
     }
 
+    public function getPopupToast()
+    {
+        $sHtmlId = 'bx-popup-toast';
+        return $this->_oTemplate->parseHtmlByName('popup_trans_toast_holder.html', [
+            'html_id' => $sHtmlId . '-holder',
+            'sample' => $this->transBox($sHtmlId, $this->_oTemplate->parseHtmlByName('popup_trans_toast_cnt.html', []), true)
+        ]);
+    }
+
     /**
      * Output time wrapped in <time> tag in HTML.
      * Then time is autoformatted using JS upon page load, this is aumatically converted to user's timezone and
@@ -980,11 +989,10 @@ class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
     protected function getInjFooterPopups() 
     {
         $sContent = '';
-
         $sContent .= $this->getPopupAlert();
         $sContent .= $this->getPopupConfirm();
         $sContent .= $this->getPopupPrompt();
-
+        $sContent .= $this->getPopupToast();
         return $sContent;
     }