Parcourir la source

增加 Grid::rowSelector()->idColumn() 方法

jqh il y a 4 ans
Parent
commit
84e7ffa626

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/adminlte/adminlte.js.map


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/css/dcat-app-blue-light.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/css/dcat-app-blue.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/css/dcat-app-green.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/css/dcat-app.css


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/extra/action.js.map


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/extra/grid-extend.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/extra/grid-extend.js.map


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/extra/select-table.js.map


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/js/dcat-app.js


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/js/dcat-app.js.map


+ 22 - 0
resources/dist/dcat/plugins/jquery.initialize/LICENSE

@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015-2016 Adam Pietrasiak
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+

+ 157 - 0
resources/dist/dcat/plugins/jquery.initialize/jquery.initialize.js

@@ -0,0 +1,157 @@
+/*!
+ * https://github.com/adampietrasiak/jquery.initialize
+ *
+ * Copyright (c) 2015-2016 Adam Pietrasiak
+ * Released under the MIT license
+ * https://github.com/timpler/jquery.initialize/blob/master/LICENSE
+ *
+ * This is based on MutationObserver
+ * https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
+ */
+;(function ($) {
+
+    "use strict";
+
+    var combinators = [' ', '>', '+', '~']; // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors#Combinators
+    var fraternisers = ['+', '~']; // These combinators involve siblings.
+    var complexTypes = ['ATTR', 'PSEUDO', 'ID', 'CLASS']; // These selectors are based upon attributes.
+
+    //Check if browser supports "matches" function
+    if (!Element.prototype.matches) {
+        Element.prototype.matches = Element.prototype.matchesSelector ||
+            Element.prototype.webkitMatchesSelector ||
+            Element.prototype.mozMatchesSelector ||
+            Element.prototype.msMatchesSelector;
+    }
+
+    // Understand what kind of selector the initializer is based upon.
+    function grok(msobserver) {
+        if (!$.find.tokenize) {
+            // This is an old version of jQuery, so cannot parse the selector.
+            // Therefore we must assume the worst case scenario. That is, that
+            // this is a complicated selector. This feature was available in:
+            // https://github.com/jquery/sizzle/issues/242
+            msobserver.isCombinatorial = true;
+            msobserver.isFraternal = true;
+            msobserver.isComplex = true;
+            return;
+        }
+
+        // Parse the selector.
+        msobserver.isCombinatorial = false;
+        msobserver.isFraternal = false;
+        msobserver.isComplex = false;
+        var token = $.find.tokenize(msobserver.selector);
+        for (var i = 0; i < token.length; i++) {
+            for (var j = 0; j < token[i].length; j++) {
+                if (combinators.indexOf(token[i][j].type) != -1)
+                    msobserver.isCombinatorial = true; // This selector uses combinators.
+
+                if (fraternisers.indexOf(token[i][j].type) != -1)
+                    msobserver.isFraternal = true; // This selector uses sibling combinators.
+
+                if (complexTypes.indexOf(token[i][j].type) != -1)
+                    msobserver.isComplex = true; // This selector is based on attributes.
+            }
+        }
+    }
+
+    // MutationSelectorObserver represents a selector and it's associated initialization callback.
+    var MutationSelectorObserver = function (selector, callback, options) {
+        this.selector = selector.trim();
+        this.callback = callback;
+        this.options = options;
+
+        grok(this);
+    };
+
+    // List of MutationSelectorObservers.
+    var msobservers = [];
+    msobservers.initialize = function (selector, callback, options) {
+
+        // Wrap the callback so that we can ensure that it is only
+        // called once per element.
+        var seen = [];
+        var callbackOnce = function () {
+            if (seen.indexOf(this) == -1) {
+                seen.push(this);
+                $(this).each(callback);
+            }
+        };
+
+        // See if the selector matches any elements already on the page.
+        $(options.target).find(selector).each(callbackOnce);
+
+        // Then, add it to the list of selector observers.
+        var msobserver = new MutationSelectorObserver(selector, callbackOnce, options)
+        this.push(msobserver);
+
+        // The MutationObserver watches for when new elements are added to the DOM.
+        var observer = new MutationObserver(function (mutations) {
+            var matches = [];
+
+            // For each mutation.
+            for (var m = 0; m < mutations.length; m++) {
+
+                // If this is an attributes mutation, then the target is the node upon which the mutation occurred.
+                if (mutations[m].type == 'attributes') {
+                    // Check if the mutated node matchs.
+                    if (mutations[m].target.matches(msobserver.selector))
+                        matches.push(mutations[m].target);
+
+                    // If the selector is fraternal, query siblings of the mutated node for matches.
+                    if (msobserver.isFraternal)
+                        matches.push.apply(matches, mutations[m].target.parentElement.querySelectorAll(msobserver.selector));
+                    else
+                        matches.push.apply(matches, mutations[m].target.querySelectorAll(msobserver.selector));
+                }
+
+                // If this is an childList mutation, then inspect added nodes.
+                if (mutations[m].type == 'childList') {
+                    // Search added nodes for matching selectors.
+                    for (var n = 0; n < mutations[m].addedNodes.length; n++) {
+                        if (!(mutations[m].addedNodes[n] instanceof Element)) continue;
+
+                        // Check if the added node matches the selector
+                        if (mutations[m].addedNodes[n].matches(msobserver.selector))
+                            matches.push(mutations[m].addedNodes[n]);
+
+                        // If the selector is fraternal, query siblings for matches.
+                        if (msobserver.isFraternal)
+                            matches.push.apply(matches, mutations[m].addedNodes[n].parentElement.querySelectorAll(msobserver.selector));
+                        else
+                            matches.push.apply(matches, mutations[m].addedNodes[n].querySelectorAll(msobserver.selector));
+                    }
+                }
+            }
+
+            // For each match, call the callback using jQuery.each() to initialize the element (once only.)
+            for (var i = 0; i < matches.length; i++) {
+                $(matches[i]).each(msobserver.callback);
+            }
+        });
+
+        // Observe the target element.
+        var defaultObeserverOpts = { childList: true, subtree: true, attributes: msobserver.isComplex };
+        observer.observe(options.target, options.observer || defaultObeserverOpts );
+
+        return observer;
+    };
+
+    // Deprecated API (does not work with jQuery >= 3.1.1):
+    $.fn.initialize = function (callback, options) {
+        return msobservers.initialize(this.selector, callback, $.extend({}, $.initialize.defaults, options));
+    };
+
+    // Supported API
+    $.initialize = function (selector, callback, options) {
+        return msobservers.initialize(selector, callback, $.extend({}, $.initialize.defaults, options));
+    };
+
+    // Options
+    $.initialize.defaults = {
+        target: document.documentElement, // Defaults to observe the entire document.
+        observer: null // MutationObserverInit: Defaults to internal configuration if not provided.
+    }
+
+})(jQuery);

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
resources/dist/dcat/plugins/jquery.initialize/jquery.initialize.min.js


+ 12 - 2
src/Grid/Tools/RowSelector.php

@@ -16,6 +16,8 @@ class RowSelector
 
     protected $rowClickable = false;
 
+    protected $idColumn;
+
     protected $titleColumn;
 
     public function __construct(Grid $grid)
@@ -44,6 +46,13 @@ class RowSelector
         return $this;
     }
 
+    public function idColumn(string $value)
+    {
+        $this->idColumn = $value;
+
+        return $this;
+    }
+
     public function titleColumn(string $value)
     {
         $this->titleColumn = $value;
@@ -63,9 +72,10 @@ HTML;
 
     public function renderColumn($row, $id)
     {
-        $this->setupScript();
+        $this->addScript();
         $title = $this->getTitle($row, $id);
         $title = e(is_array($title) ? json_encode($title) : $title);
+        $id = $this->idColumn ? Arr::get($row->toArray(), $this->idColumn) : $id;
 
         return <<<EOT
 <div class="vs-checkbox-con vs-checkbox-{$this->style} checkbox-grid checkbox-grid-column">
@@ -75,7 +85,7 @@ HTML;
 EOT;
     }
 
-    protected function setupScript()
+    protected function addScript()
     {
         $clickable = $this->rowClickable ? 'true' : 'false';
         $background = $this->background ?: Admin::color()->dark20();

+ 13 - 13
src/Support/helpers.php

@@ -436,19 +436,6 @@ if (! function_exists('admin_asset')) {
     }
 }
 
-if (! function_exists('admin_assets_require')) {
-
-    /**
-     * @param $alias
-     *
-     * @return void
-     */
-    function admin_assets_require(?string $alias)
-    {
-        Admin::asset()->collect($alias);
-    }
-}
-
 if (! function_exists('admin_api_route')) {
 
     /**
@@ -494,6 +481,19 @@ if (! function_exists('admin_color')) {
     }
 }
 
+if (! function_exists('admin_view')) {
+    /**
+     * @param string $view
+     * @param array  $data
+     *
+     * @throws \Throwable
+     */
+    function admin_view($view, array $data = [])
+    {
+        Admin::view($view, $data);
+    }
+}
+
 if (! function_exists('admin_js')) {
     /**
      * @param string|array $js

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff