Просмотр исходного кода

Ticket #2754 - Reordering didn't work in Dynamicly loaded forms.

AntonLV 5 лет назад
Родитель
Сommit
1cc290dd2e
2 измененных файлов с 41 добавлено и 18 удалено
  1. 17 10
      inc/js/classes/BxDolUploader.js
  2. 24 8
      template/scripts/BxBaseFormView.php

+ 17 - 10
inc/js/classes/BxDolUploader.js

@@ -159,17 +159,24 @@ BxDolUploaderSimple.prototype.restoreGhosts = function (bInitReordering, onCompl
             $('#' + $this._sResultContainerId).bx_show_more_check_overflow();
 
             if(bInitReordering) {
-                $('#' + $this._sResultContainerId).sortable({
-                    items: '.bx-uploader-ghost', 
-                    start: function(oEvent, oUi) {
-                        oUi.item.addClass('bx-uploader-ghost-dragging');
-                    },
-                    stop: function(oEvent, oUi) {
-                        oUi.item.removeClass('bx-uploader-ghost-dragging');
+                var fInitReordering = function() {
+                    $('#' + $this._sResultContainerId).sortable({
+                        items: '.bx-uploader-ghost', 
+                        start: function(oEvent, oUi) {
+                            oUi.item.addClass('bx-uploader-ghost-dragging');
+                        },
+                        stop: function(oEvent, oUi) {
+                            oUi.item.removeClass('bx-uploader-ghost-dragging');
+
+                            $this.reorderGhosts(oUi.item);
+                        }
+                    });
+                };
 
-                        $this.reorderGhosts(oUi.item);
-                    }
-                });
+                if($.sortable !== undefined)
+                    fInitReordering();
+                else
+                    setTimeout(fInitReordering, 2000);
             }
         }
 

+ 24 - 8
template/scripts/BxBaseFormView.php

@@ -13,6 +13,7 @@ class BxBaseFormView extends BxDolForm
 
     protected static $_isCssJsAdded = false;
     protected static $_isCssJsUiAdded = false;
+    protected static $_isCssJsUiSortableAdded = false;
     protected static $_isCssJsMinicolorsAdded = false;
     protected static $_isCssJsLabelsAdded = false;
     protected static $_isCssJsTimepickerAdded = false;
@@ -1386,6 +1387,9 @@ BLAH;
      */
     function genInputFiles(&$aInput, $sInfo = '', $sError = '')
     {
+        if(empty($aInput['uploaders']) || !is_array($aInput['uploaders']))
+            return '';
+
         $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
 
         $sUploaders = '';
@@ -1413,15 +1417,15 @@ BLAH;
 
             $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams, $this->_bDynamicMode);
         }
+        
+        if(!$oUploader)
+            return '';
 
-        $bInitReordering = $oUploader && !empty($aInput['init_reordering']);
-        if($bInitReordering)
-            $this->oTemplate->addJs(array(
-                'jquery-ui/jquery.ui.core.min.js',
-                'jquery-ui/jquery.ui.widget.min.js',
-                'jquery-ui/jquery.ui.mouse.min.js',
-                'jquery-ui/jquery.ui.sortable.min.js',
-            ));
+        $bInitReordering = !empty($aInput['init_reordering']);
+        if($bInitReordering) {
+            $this->addCssJsUi();
+            $this->addCssJsUiSortable();
+        }
 
         return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
             'uploaders_buttons' => $sUploaders,
@@ -2083,6 +2087,18 @@ BLAH;
 
         self::$_isCssJsUiAdded = true;
     }
+    
+    function addCssJsUiSortable ()
+    {
+        if (self::$_isCssJsUiSortableAdded)
+            return;
+
+        $this->_addJs(array(
+            'jquery-ui/jquery.ui.sortable.min.js'
+        ), "'undefined' === typeof($.sortable)");
+
+        self::$_isCssJsUiSortableAdded = true;
+    }
 
     function addCssJsTimepicker ()
     {