Plugin Directory

Changeset 2606867


Ignore:
Timestamp:
09/29/2021 03:11:39 PM (5 years ago)
Author:
apogi
Message:

Update to version 1.1.0 from GitHub

Location:
gf-sort-export
Files:
2 deleted
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • gf-sort-export/tags/1.1.0/gf-sort-export.php

    r2586143 r2606867  
    88 * License:         GPL2
    99 * License URI:     https://www.gnu.org/licenses/gpl-2.0.html
    10  * Version:         1.0.0
     10 * Version:         1.1.0
    1111 */
    1212
     
    2222
    2323add_action('gform_loaded', static function () {
    24 // start plugin
    2524    new SortExportPlugin();
    2625});
  • gf-sort-export/tags/1.1.0/public/js/gf-sort-export.jquery.js

    r2586143 r2606867  
    66    /**
    77     * Sorts the list items by moving active items to the top.
     8     * @since 1.0.0
     9     * @param form_id The form id.
     10     * @param $list The items list element.
    811     */
    9     function sortItems(list) {
    10         var items = $('li', list);
     12    function sortItems(form_id, $list) {
     13        var items = $('li', $list);
    1114        items.sort(function (a, b) {
    1215            // select all always on top.
     
    2023            return a === b ? 0 : (a < b ? 1 : -1);
    2124        });
    22         list.append(items);
    23         list.sortable('refresh');
     25        $list.append(items);
     26        $list.sortable('refresh');
     27
     28        storeOrder(form_id, $list);
     29    }
     30
     31    /**
     32     * Stores the current sort order for the form.
     33     * @since 1.1.0
     34     * @param form_id The form id.
     35     * @param $list The items list element.
     36     */
     37    function storeOrder(form_id, $list) {
     38        if (ajaxurl === undefined) {
     39            return;
     40        }
     41
     42        $.post(ajaxurl, {
     43            action: 'gf-sort-export-store-order',
     44            form_id: form_id,
     45            order: $list.sortable('toArray', {attribute: 'rel'})
     46        });
     47    }
     48
     49    /**
     50     * Sorts the list based on the stored order.
     51     * @since 1.1.0
     52     * @param form_id The form id.
     53     * @param $list The items list element.
     54     */
     55    function setListOrder(form_id, $list) {
     56        if (ajaxurl === undefined) {
     57            return;
     58        }
     59
     60        $.get(ajaxurl, {
     61            action: 'gf-sort-export-get-order',
     62            form_id: form_id,
     63            dataType: 'json'
     64        }, function (order) {
     65            if (order.length === 0) {
     66                // Do nothing if we have no stored order.
     67                return;
     68            }
     69
     70            var $items = $('li', $list);
     71            // Select all stored values
     72            $items.find('input[type=checkbox]').each(function () {
     73                if (order.includes($(this).val())) {
     74                    $(this).attr('checked', true).trigger('change', true);
     75                }
     76            });
     77
     78            // Reset the stored order
     79            $items.sort(function (a, b) {
     80                // select all always on top.
     81                if ($(b).find('#select_all').length > 0) {
     82                    return 1;
     83                }
     84
     85                // Get sort index. Will be -1 if the item is not in the order array.
     86                a = order.indexOf($(a).attr('rel'));
     87                b = order.indexOf($(b).attr('rel'));
     88
     89                // No need to sort
     90                if (a === b) {
     91                    return 0;
     92                }
     93
     94                // Left or right is not in the array. Push them to the bottom.
     95                if (a === -1 || b === -1) {
     96                    return a === -1 ? 1 : -1;
     97                }
     98
     99                // regular sort based on the index
     100                return a < b ? -1 : 1;
     101            });
     102            $list.append($items);
     103        });
    24104    }
    25105
    26106    $(function () {
    27         var $list = $('#export_field_list');
    28         var timeout;
     107        var $list = $('#export_field_list'),
     108            $export_form = $('#export_form'),
     109            updating = false,
     110            timeout;
     111
     112        $export_form
     113            .on('change', function () {
     114                // Keep track of whether we are updating the list.
     115                updating = true;
     116            });
     117
     118        $list.on('DOMSubtreeModified', function () {
     119            if (!updating) {
     120                // Prevent endless loop. If we aren't updating don't trigger this event.
     121                return;
     122            }
     123
     124            // If the list is empty, we wait for it to fill up.
     125            if ($list.find('li').length > 0) {
     126                updating = false;
     127                setListOrder($export_form.val(), $list);
     128            }
     129        });
    29130
    30131        $list
    31132            // Only sort active items, and not the header.
    32             .sortable({items: "> li:not(:first-child).active"})
     133            .sortable({
     134                items: "> li:not(:first-child).active",
     135                cancel: "> li:not(.active)",
     136                update: function () {
     137                    storeOrder($export_form.val(), $list)
     138                }
     139            })
    33140            // Add active class for selected items.
    34141            .on('change', 'input[type=checkbox]', function (e, is_propagated) {
    35                 $(this).parent('li').toggleClass('active', $(this).is(':checked'));
     142                $parent = $(this).parent('li');
     143                $parent.toggleClass('active', $(this).is(':checked'));
     144                $parent.attr('rel', $(this).is(':checked') ? $(this).val() : null);
    36145
    37146                // Trigger change event on all fields to update class.
     
    45154                    clearTimeout(timeout);
    46155                    timeout = setTimeout(function () {
    47                         sortItems($list);
     156                        sortItems($export_form.val(), $list);
    48157                    }, 1250);
    49158                }
  • gf-sort-export/tags/1.1.0/public/js/gf-sort-export.jquery.min.js

    r2586143 r2606867  
    1 (function($){function sortItems(list){var items=$("li",list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});list.append(items);list.sortable("refresh")}$(function(){var $list=$("#export_field_list");var timeout;$list.sortable({items:"> li:not(:first-child).active"}).on("change","input[type=checkbox]",function(e,is_propagated){$(this).parent("li").toggleClass("active",$(this).is(":checked"));if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($list)},1250)}})})})(jQuery);
     1(function($){function sortItems(form_id,$list){var items=$("li",$list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});$list.append(items);$list.sortable("refresh");storeOrder(form_id,$list)}function storeOrder(form_id,$list){if(ajaxurl===undefined){return}$.post(ajaxurl,{action:"gf-sort-export-store-order",form_id:form_id,order:$list.sortable("toArray",{attribute:"rel"})})}function setListOrder(form_id,$list){if(ajaxurl===undefined){return}$.get(ajaxurl,{action:"gf-sort-export-get-order",form_id:form_id,dataType:"json"},function(order){if(order.length===0){return}var $items=$("li",$list);$items.find("input[type=checkbox]").each(function(){if(order.includes($(this).val())){$(this).attr("checked",true).trigger("change",true)}});$items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=order.indexOf($(a).attr("rel"));b=order.indexOf($(b).attr("rel"));if(a===b){return 0}if(a===-1||b===-1){return a===-1?1:-1}return a<b?-1:1});$list.append($items)})}$(function(){var $list=$("#export_field_list"),$export_form=$("#export_form"),updating=false,timeout;$export_form.on("change",function(){updating=true});$list.on("DOMSubtreeModified",function(){if(!updating){return}if($list.find("li").length>0){updating=false;setListOrder($export_form.val(),$list)}});$list.sortable({items:"> li:not(:first-child).active",cancel:"> li:not(.active)",update:function(){storeOrder($export_form.val(),$list)}}).on("change","input[type=checkbox]",function(e,is_propagated){$parent=$(this).parent("li");$parent.toggleClass("active",$(this).is(":checked"));$parent.attr("rel",$(this).is(":checked")?$(this).val():null);if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($export_form.val(),$list)},1250)}})})})(jQuery);
  • gf-sort-export/tags/1.1.0/readme.txt

    r2588276 r2606867  
    33Plugin URI: https://apogi.dev/
    44Donate link: https://www.paypal.me/doekenorg
    5 Tags: apogi, gravity forms, export, csv, sort, order, drag, drop
     5Tags: apogi, gravity forms, export, csv, sort, order, drag, drop, store
    66Requires at least: 4.0
    77Requires PHP: 7.1
    88Tested up to: 5.8
    9 Stable tag: 1.0.0
     9Stable tag: 1.1.0
    1010License: GPLv2
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212
    13 Control the order of the fields during the export of entries.
     13Control (and persist) the order of the fields during the export of entries.
    1414
    1515== Description ==
     
    1919After selecting the fields you wish to export, the plugin will group these fields, after which you can drag & drop them in the desired order. Then click "Download Export File". The fields in the CSV output will now be in that order.
    2020
     21The provided sort order is also persisted for every form. So you don't have to resort it for every export.
     22
    2123To limit visual clutter, this plugin also removes all disabled subfields from the export list.
    2224
     
    2527
    2628== Changelog ==
     29= 1.1.0 - 2021-09-29 =
     30* Feature: Store the export sort order for every form.
     31
    2732= 1.0.0 - 2021-08-18
    2833* Feature: Drag & sort the export fields.
  • gf-sort-export/tags/1.1.0/src/SortExportPlugin.php

    r2586143 r2606867  
    1515    public function __construct()
    1616    {
    17         add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'load_scripts']));
    18         add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disable_inactive_subfields']));
     17        add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'loadScripts']));
     18        add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disableInactiveSubfields']));
     19        add_action('wp_ajax_gf-sort-export-store-order', \Closure::fromCallable([$this, 'storeOrder']));
     20        add_action('wp_ajax_gf-sort-export-get-order', \Closure::fromCallable([$this, 'getOrder']));
    1921    }
    2022
     
    2325     * @since 1.0.0
    2426     */
    25     private function load_scripts(): void
     27    private function loadScripts(): void
    2628    {
    2729        if (rgget('page') !== 'gf_export' || !in_array(rgget('view'), ['', 'export_entry'], true)) {
     
    5052     * @return mixed[] The updated form object.
    5153     */
    52     private function disable_inactive_subfields(array $form): array
     54    private function disableInactiveSubfields(array $form): array
    5355    {
    5456        foreach ($form['fields'] as $i => $field) {
     
    6264        return $form;
    6365    }
     66
     67    /**
     68     * Returns the stored order (if any) for a specific form.
     69     * @since 1.1.0
     70     */
     71    private function getOrder(): void
     72    {
     73        $option = sprintf('gf-sort-export-order-%d', $_GET['form_id'] ?? 0);
     74        wp_send_json(get_option($option, []));
     75    }
     76
     77    /**
     78     * Stores the sort order for the provided form.
     79     * @since 1.1.0
     80     */
     81    private function storeOrder(): void
     82    {
     83        $allowed_fields = ['form_id', 'order'];
     84        $data = array_intersect_key($_POST, array_flip($allowed_fields));
     85
     86        $form = \GFAPI::get_form($form_id = $data['form_id'] ?? 0);
     87        if (!$form) {
     88            wp_send_json_error(null, 404);
     89
     90            return;
     91        }
     92
     93        $option = sprintf('gf-sort-export-order-%d', $form_id);
     94        update_option($option, $data['order'] ?: [], false);
     95
     96        wp_send_json_success();
     97    }
    6498}
  • gf-sort-export/trunk/gf-sort-export.php

    r2586143 r2606867  
    88 * License:         GPL2
    99 * License URI:     https://www.gnu.org/licenses/gpl-2.0.html
    10  * Version:         1.0.0
     10 * Version:         1.1.0
    1111 */
    1212
     
    2222
    2323add_action('gform_loaded', static function () {
    24 // start plugin
    2524    new SortExportPlugin();
    2625});
  • gf-sort-export/trunk/public/js/gf-sort-export.jquery.js

    r2586143 r2606867  
    66    /**
    77     * Sorts the list items by moving active items to the top.
     8     * @since 1.0.0
     9     * @param form_id The form id.
     10     * @param $list The items list element.
    811     */
    9     function sortItems(list) {
    10         var items = $('li', list);
     12    function sortItems(form_id, $list) {
     13        var items = $('li', $list);
    1114        items.sort(function (a, b) {
    1215            // select all always on top.
     
    2023            return a === b ? 0 : (a < b ? 1 : -1);
    2124        });
    22         list.append(items);
    23         list.sortable('refresh');
     25        $list.append(items);
     26        $list.sortable('refresh');
     27
     28        storeOrder(form_id, $list);
     29    }
     30
     31    /**
     32     * Stores the current sort order for the form.
     33     * @since 1.1.0
     34     * @param form_id The form id.
     35     * @param $list The items list element.
     36     */
     37    function storeOrder(form_id, $list) {
     38        if (ajaxurl === undefined) {
     39            return;
     40        }
     41
     42        $.post(ajaxurl, {
     43            action: 'gf-sort-export-store-order',
     44            form_id: form_id,
     45            order: $list.sortable('toArray', {attribute: 'rel'})
     46        });
     47    }
     48
     49    /**
     50     * Sorts the list based on the stored order.
     51     * @since 1.1.0
     52     * @param form_id The form id.
     53     * @param $list The items list element.
     54     */
     55    function setListOrder(form_id, $list) {
     56        if (ajaxurl === undefined) {
     57            return;
     58        }
     59
     60        $.get(ajaxurl, {
     61            action: 'gf-sort-export-get-order',
     62            form_id: form_id,
     63            dataType: 'json'
     64        }, function (order) {
     65            if (order.length === 0) {
     66                // Do nothing if we have no stored order.
     67                return;
     68            }
     69
     70            var $items = $('li', $list);
     71            // Select all stored values
     72            $items.find('input[type=checkbox]').each(function () {
     73                if (order.includes($(this).val())) {
     74                    $(this).attr('checked', true).trigger('change', true);
     75                }
     76            });
     77
     78            // Reset the stored order
     79            $items.sort(function (a, b) {
     80                // select all always on top.
     81                if ($(b).find('#select_all').length > 0) {
     82                    return 1;
     83                }
     84
     85                // Get sort index. Will be -1 if the item is not in the order array.
     86                a = order.indexOf($(a).attr('rel'));
     87                b = order.indexOf($(b).attr('rel'));
     88
     89                // No need to sort
     90                if (a === b) {
     91                    return 0;
     92                }
     93
     94                // Left or right is not in the array. Push them to the bottom.
     95                if (a === -1 || b === -1) {
     96                    return a === -1 ? 1 : -1;
     97                }
     98
     99                // regular sort based on the index
     100                return a < b ? -1 : 1;
     101            });
     102            $list.append($items);
     103        });
    24104    }
    25105
    26106    $(function () {
    27         var $list = $('#export_field_list');
    28         var timeout;
     107        var $list = $('#export_field_list'),
     108            $export_form = $('#export_form'),
     109            updating = false,
     110            timeout;
     111
     112        $export_form
     113            .on('change', function () {
     114                // Keep track of whether we are updating the list.
     115                updating = true;
     116            });
     117
     118        $list.on('DOMSubtreeModified', function () {
     119            if (!updating) {
     120                // Prevent endless loop. If we aren't updating don't trigger this event.
     121                return;
     122            }
     123
     124            // If the list is empty, we wait for it to fill up.
     125            if ($list.find('li').length > 0) {
     126                updating = false;
     127                setListOrder($export_form.val(), $list);
     128            }
     129        });
    29130
    30131        $list
    31132            // Only sort active items, and not the header.
    32             .sortable({items: "> li:not(:first-child).active"})
     133            .sortable({
     134                items: "> li:not(:first-child).active",
     135                cancel: "> li:not(.active)",
     136                update: function () {
     137                    storeOrder($export_form.val(), $list)
     138                }
     139            })
    33140            // Add active class for selected items.
    34141            .on('change', 'input[type=checkbox]', function (e, is_propagated) {
    35                 $(this).parent('li').toggleClass('active', $(this).is(':checked'));
     142                $parent = $(this).parent('li');
     143                $parent.toggleClass('active', $(this).is(':checked'));
     144                $parent.attr('rel', $(this).is(':checked') ? $(this).val() : null);
    36145
    37146                // Trigger change event on all fields to update class.
     
    45154                    clearTimeout(timeout);
    46155                    timeout = setTimeout(function () {
    47                         sortItems($list);
     156                        sortItems($export_form.val(), $list);
    48157                    }, 1250);
    49158                }
  • gf-sort-export/trunk/public/js/gf-sort-export.jquery.min.js

    r2586143 r2606867  
    1 (function($){function sortItems(list){var items=$("li",list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});list.append(items);list.sortable("refresh")}$(function(){var $list=$("#export_field_list");var timeout;$list.sortable({items:"> li:not(:first-child).active"}).on("change","input[type=checkbox]",function(e,is_propagated){$(this).parent("li").toggleClass("active",$(this).is(":checked"));if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($list)},1250)}})})})(jQuery);
     1(function($){function sortItems(form_id,$list){var items=$("li",$list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});$list.append(items);$list.sortable("refresh");storeOrder(form_id,$list)}function storeOrder(form_id,$list){if(ajaxurl===undefined){return}$.post(ajaxurl,{action:"gf-sort-export-store-order",form_id:form_id,order:$list.sortable("toArray",{attribute:"rel"})})}function setListOrder(form_id,$list){if(ajaxurl===undefined){return}$.get(ajaxurl,{action:"gf-sort-export-get-order",form_id:form_id,dataType:"json"},function(order){if(order.length===0){return}var $items=$("li",$list);$items.find("input[type=checkbox]").each(function(){if(order.includes($(this).val())){$(this).attr("checked",true).trigger("change",true)}});$items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=order.indexOf($(a).attr("rel"));b=order.indexOf($(b).attr("rel"));if(a===b){return 0}if(a===-1||b===-1){return a===-1?1:-1}return a<b?-1:1});$list.append($items)})}$(function(){var $list=$("#export_field_list"),$export_form=$("#export_form"),updating=false,timeout;$export_form.on("change",function(){updating=true});$list.on("DOMSubtreeModified",function(){if(!updating){return}if($list.find("li").length>0){updating=false;setListOrder($export_form.val(),$list)}});$list.sortable({items:"> li:not(:first-child).active",cancel:"> li:not(.active)",update:function(){storeOrder($export_form.val(),$list)}}).on("change","input[type=checkbox]",function(e,is_propagated){$parent=$(this).parent("li");$parent.toggleClass("active",$(this).is(":checked"));$parent.attr("rel",$(this).is(":checked")?$(this).val():null);if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($export_form.val(),$list)},1250)}})})})(jQuery);
  • gf-sort-export/trunk/readme.txt

    r2588276 r2606867  
    33Plugin URI: https://apogi.dev/
    44Donate link: https://www.paypal.me/doekenorg
    5 Tags: apogi, gravity forms, export, csv, sort, order, drag, drop
     5Tags: apogi, gravity forms, export, csv, sort, order, drag, drop, store
    66Requires at least: 4.0
    77Requires PHP: 7.1
    88Tested up to: 5.8
    9 Stable tag: 1.0.0
     9Stable tag: 1.1.0
    1010License: GPLv2
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1212
    13 Control the order of the fields during the export of entries.
     13Control (and persist) the order of the fields during the export of entries.
    1414
    1515== Description ==
     
    1919After selecting the fields you wish to export, the plugin will group these fields, after which you can drag & drop them in the desired order. Then click "Download Export File". The fields in the CSV output will now be in that order.
    2020
     21The provided sort order is also persisted for every form. So you don't have to resort it for every export.
     22
    2123To limit visual clutter, this plugin also removes all disabled subfields from the export list.
    2224
     
    2527
    2628== Changelog ==
     29= 1.1.0 - 2021-09-29 =
     30* Feature: Store the export sort order for every form.
     31
    2732= 1.0.0 - 2021-08-18
    2833* Feature: Drag & sort the export fields.
  • gf-sort-export/trunk/src/SortExportPlugin.php

    r2586143 r2606867  
    1515    public function __construct()
    1616    {
    17         add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'load_scripts']));
    18         add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disable_inactive_subfields']));
     17        add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'loadScripts']));
     18        add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disableInactiveSubfields']));
     19        add_action('wp_ajax_gf-sort-export-store-order', \Closure::fromCallable([$this, 'storeOrder']));
     20        add_action('wp_ajax_gf-sort-export-get-order', \Closure::fromCallable([$this, 'getOrder']));
    1921    }
    2022
     
    2325     * @since 1.0.0
    2426     */
    25     private function load_scripts(): void
     27    private function loadScripts(): void
    2628    {
    2729        if (rgget('page') !== 'gf_export' || !in_array(rgget('view'), ['', 'export_entry'], true)) {
     
    5052     * @return mixed[] The updated form object.
    5153     */
    52     private function disable_inactive_subfields(array $form): array
     54    private function disableInactiveSubfields(array $form): array
    5355    {
    5456        foreach ($form['fields'] as $i => $field) {
     
    6264        return $form;
    6365    }
     66
     67    /**
     68     * Returns the stored order (if any) for a specific form.
     69     * @since 1.1.0
     70     */
     71    private function getOrder(): void
     72    {
     73        $option = sprintf('gf-sort-export-order-%d', $_GET['form_id'] ?? 0);
     74        wp_send_json(get_option($option, []));
     75    }
     76
     77    /**
     78     * Stores the sort order for the provided form.
     79     * @since 1.1.0
     80     */
     81    private function storeOrder(): void
     82    {
     83        $allowed_fields = ['form_id', 'order'];
     84        $data = array_intersect_key($_POST, array_flip($allowed_fields));
     85
     86        $form = \GFAPI::get_form($form_id = $data['form_id'] ?? 0);
     87        if (!$form) {
     88            wp_send_json_error(null, 404);
     89
     90            return;
     91        }
     92
     93        $option = sprintf('gf-sort-export-order-%d', $form_id);
     94        update_option($option, $data['order'] ?: [], false);
     95
     96        wp_send_json_success();
     97    }
    6498}
Note: See TracChangeset for help on using the changeset viewer.