-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathui-grid.selection.min.js
6 lines (6 loc) · 13.6 KB
/
ui-grid.selection.min.js
1
2
3
4
5
6
/*!
* ui-grid - v4.12.7 - 2024-04-12
* http://ui-grid.info/
* Copyright (c) 2024 ; License: MIT
*/
!function(){"use strict";var e=angular.module("ui.grid.selection",["ui.grid"]);e.constant("uiGridSelectionConstants",{featureName:"selection",selectionRowHeaderColName:"selectionRowHeaderCol"}),angular.module("ui.grid").config(["$provide",function(e){e.decorator("GridRow",["$delegate",function(e){return e.prototype.setSelected=function(e){e!==this.isSelected&&(this.isSelected=e,this.grid.selection.selectedCount+=e?1:-1)},e.prototype.setFocused=function(e){e!==this.isFocused&&(this.grid.selection.focusedRow&&(this.grid.selection.focusedRow.isFocused=!1),this.grid.selection.focusedRow=e?this:null,this.isFocused=e)},e}])}]),e.service("uiGridSelectionService",function(){var r={initializeGrid:function(l){l.selection={lastSelectedRow:null,focusedRow:null,selectAll:!1},l.selection.selectedCount=0,r.defaultGridOptions(l.options);var e={selection:{rowFocusChanged:function(e,t,i){},rowSelectionChanged:function(e,t,i){},rowSelectionChangedBatch:function(e,t,i){}}},t={selection:{toggleRowSelection:function(e,t){e=l.getRow(e);null!=e&&null!==e&&r.toggleRowSelection(l,e,t,l.options.multiSelect,l.options.noUnselect,!0)},selectRow:function(e,t){e=l.getRow(e);null==e||null===e||e.isSelected||r.toggleRowSelection(l,e,t,l.options.multiSelect,l.options.noUnselect,!0)},selectRowByVisibleIndex:function(e,t){e=l.renderContainers.body.visibleRowCache[e];null==e||e.isSelected||r.toggleRowSelection(l,e,t,l.options.multiSelect,l.options.noUnselect,!1)},selectRowByKey:function(e,t,i,o,n){e=l.findRowByKey(e,t,i,n);null==e||e.isSelected||r.toggleRowSelection(l,e,o,l.options.multiSelect,l.options.noUnselect,!1)},unSelectRow:function(e,t){e=l.getRow(e);null!=e&&null!==e&&e.isSelected&&r.toggleRowSelection(l,e,t,l.options.multiSelect,l.options.noUnselect,!0)},unSelectRowByVisibleIndex:function(e,t){e=l.renderContainers.body.visibleRowCache[e];null!=e&&null!=e&&e.isSelected&&r.toggleRowSelection(l,e,t,l.options.multiSelect,l.options.noUnselect,!1)},unSelectRowByKey:function(e,t,i,o,n){e=l.findRowByKey(e,t,i,n);null!=e&&null!=e&&e.isSelected&&r.toggleRowSelection(l,e,o,l.options.multiSelect,l.options.noUnselect,!1)},selectAllRows:function(t){var i;!1!==l.options.multiSelect&&(i=[],l.rows.forEach(function(e){e.isSelected||!1===e.enableSelection||!1===l.options.isRowSelectable(e)||(e.setSelected(!0),r.decideRaiseSelectionEvent(l,e,i,t))}),l.selection.selectAll=!0,r.decideRaiseSelectionBatchEvent(l,i,t))},selectAllVisibleRows:function(t){var i;!1!==l.options.multiSelect&&(i=[],l.rows.forEach(function(e){e.visible?e.isSelected||!1===e.enableSelection||!1===l.options.isRowSelectable(e)||(e.setSelected(!0),r.decideRaiseSelectionEvent(l,e,i,t)):e.isSelected&&(e.setSelected(!1),r.decideRaiseSelectionEvent(l,e,i,t))}),l.selection.selectAll=!0,r.decideRaiseSelectionBatchEvent(l,i,t))},clearSelectedRows:function(e){r.clearSelectedRows(l,e)},getSelectedRows:function(){return r.mapAndFilterRowsByEntity(r.getSelectedRows(l))},getUnSelectedRows:function(){return r.mapAndFilterRowsByEntity(r.getUnSelectedRows(l))},getSelectedGridRows:function(){return r.getSelectedRows(l)},getUnSelectedGridRows:function(){return r.getUnSelectedRows(l)},getSelectedCount:function(){return l.selection.selectedCount},setMultiSelect:function(e){l.options.multiSelect=e},setModifierKeysToMultiSelect:function(e){l.options.modifierKeysToMultiSelect=e},getSelectAllState:function(){return l.selection.selectAll}}};l.api.registerEventsFromObject(e),l.api.registerMethodsFromObject(t)},defaultGridOptions:function(e){e.enableRowSelection=!1!==e.enableRowSelection,e.multiSelect=!1!==e.multiSelect,e.noUnselect=!0===e.noUnselect,e.modifierKeysToMultiSelect=!0===e.modifierKeysToMultiSelect,e.enableRowHeaderSelection=!1!==e.enableRowHeaderSelection,void 0===e.enableFullRowSelection&&(e.enableFullRowSelection=!e.enableRowHeaderSelection),e.enableFocusRowOnRowHeaderClick=!1!==e.enableFocusRowOnRowHeaderClick||!e.enableRowHeaderSelection,e.enableSelectRowOnFocus=!1!==e.enableSelectRowOnFocus,e.enableSelectAll=!1!==e.enableSelectAll,e.enableSelectionBatchEvent=!1!==e.enableSelectionBatchEvent,e.selectionRowHeaderWidth=angular.isDefined(e.selectionRowHeaderWidth)?e.selectionRowHeaderWidth:30,e.enableFooterTotalSelected=!1!==e.enableFooterTotalSelected,e.isRowSelectable=angular.isDefined(e.isRowSelectable)?e.isRowSelectable:angular.noop},toggleRowSelection:function(e,t,i,o,n,l){var c;!1===t.enableSelection||(void 0===l&&(l=!0),c=t.isSelected,o||(c?1<r.getSelectedRows(e).length&&(c=!1,r.clearSelectedRows(e,i)):r.clearSelectedRows(e,i)),c&&n)||!l&&!t.visible||(t.setSelected(!c),!0===t.isSelected&&(e.selection.lastSelectedRow=t),e.selection.selectAll=e.rows.length===r.getSelectedRows(e).length,e.api.selection.raise.rowSelectionChanged(t,i))},shiftSelect:function(e,t,i,o){if(o){for(var o=0<r.getSelectedRows(e).length?e.renderContainers.body.visibleRowCache.indexOf(e.selection.lastSelectedRow):0,n=e.renderContainers.body.visibleRowCache.indexOf(t),l=(n<o&&(t=o,o=n,n=t),[]),c=o;c<=n;c++){var s=e.renderContainers.body.visibleRowCache[c];!s||s.isSelected||!1===s.enableSelection||(s.setSelected(!0),e.selection.lastSelectedRow=s,r.decideRaiseSelectionEvent(e,s,l,i))}r.decideRaiseSelectionBatchEvent(e,l,i)}},getSelectedRows:function(e){return e.rows.filter(function(e){return e.isSelected})},getUnSelectedRows:function(e){return e.rows.filter(function(e){return!e.isSelected})},mapAndFilterRowsByEntity:function(e){return"function"==typeof e.reduce?e.reduce(function(e,t){return!t.entity.hasOwnProperty("$$hashKey")&&angular.isObject(t.entity)||e.push(t.entity),e},[]):e.filter(function(e){return e.entity.hasOwnProperty("$$hashKey")||!angular.isObject(e.entity)}).map(function(e){return e.entity})},clearSelectedRows:function(t,i){var o=[];r.getSelectedRows(t).forEach(function(e){e.isSelected&&!1!==e.enableSelection&&(e.setSelected(!1),r.decideRaiseSelectionEvent(t,e,o,i))}),t.selection.selectAll=!1,t.selection.selectedCount=0,r.decideRaiseSelectionBatchEvent(t,o,i)},decideRaiseSelectionEvent:function(e,t,i,o){e.options.enableSelectionBatchEvent?i.push(t):e.api.selection.raise.rowSelectionChanged(t,o)},decideRaiseSelectionBatchEvent:function(e,t,i){0<t.length&&e.api.selection.raise.rowSelectionChangedBatch(t,i)}};return r}),e.directive("uiGridSelection",["i18nService","uiGridSelectionConstants","uiGridSelectionService","uiGridConstants",function(r,d,a,u){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,t,i,o){function n(e){return e.forEach(function(e){e.enableSelection=o.grid.options.isRowSelectable(e)}),e}function l(){o.grid.options.isRowSelectable!==angular.noop&&!0!==c&&(o.grid.registerRowsProcessor(n,500),c=!0)}a.initializeGrid(o.grid),o.grid.options.enableRowHeaderSelection&&(s={name:d.selectionRowHeaderColName,displayName:r.getSafeText("selection.displayName"),width:o.grid.options.selectionRowHeaderWidth,minWidth:10,cellTemplate:"ui-grid/selectionRowHeader",headerCellTemplate:"ui-grid/selectionHeaderCell",enableColumnResizing:!1,enableColumnMenu:!1,exporterSuppressExport:!0,allowCellFocus:!0},o.grid.addRowHeaderColumn(s,0));var c=!1,s=(l(),o.grid.registerDataChangeCallback(l,[u.dataChange.OPTIONS]));e.$on("$destroy",s)},post:function(e,t,i,o){}}}}}]),e.directive("uiGridSelectionRowHeaderButtons",["$templateCache","uiGridSelectionService","gridUtil",function(e,c,s){return{replace:!0,restrict:"E",template:e.get("ui-grid/selectionRowHeaderButtons"),scope:!0,require:"^uiGrid",link:function(e,t,i,o){var n=o.grid;function l(e,t){if(t.stopPropagation(),t.shiftKey)c.shiftSelect(n,e,t,n.options.multiSelect);else if(t.ctrlKey||t.metaKey)c.toggleRowSelection(n,e,t,n.options.multiSelect,n.options.noUnselect,!1);else if(e.groupHeader){c.toggleRowSelection(n,e,t,n.options.multiSelect,n.options.noUnselect,!1);for(var i=0;i<e.treeNode.children.length;i++)c.toggleRowSelection(n,e.treeNode.children[i].row,t,n.options.multiSelect,n.options.noUnselect,!1)}else c.toggleRowSelection(n,e,t,n.options.multiSelect&&!n.options.modifierKeysToMultiSelect,n.options.noUnselect,!1);n.options.enableFocusRowOnRowHeaderClick&&e.setFocused(!e.isFocused)&&n.api.selection.raise.rowFocusChanged(e,t)}e.selectButtonClick=l,e.selectButtonKeyDown=function(e,t){32!==t.keyCode&&13!==t.keyCode||(t.preventDefault(),l(e,t))},"ie"===s.detectBrowser()&&t.on("mousedown",function(e){(e.ctrlKey||e.shiftKey)&&(e.target.onselectstart=function(){return!1},window.setTimeout(function(){e.target.onselectstart=null},0))}),e.$on("$destroy",function(){t.off()})}}}]),e.directive("uiGridSelectionSelectAllButtons",["$templateCache","uiGridSelectionService",function(e,o){return{replace:!0,restrict:"E",template:e.get("ui-grid/selectionSelectAllButtons"),scope:!1,link:function(t){var i=t.col.grid;t.headerButtonKeyDown=function(e){32!==e.keyCode&&13!==e.keyCode||(e.preventDefault(),t.headerButtonClick(e))},t.headerButtonClick=function(e){i.selection.selectAll?(o.clearSelectedRows(i,e),i.options.noUnselect&&i.api.selection.selectRowByVisibleIndex(0,e),i.selection.selectAll=!1):i.options.multiSelect&&(i.api.selection.selectAllVisibleRows(e),i.selection.selectAll=!0)}}}}]),e.directive("uiGridViewport",function(){return{priority:-200,scope:!1,compile:function(e){var e=angular.element(e[0].querySelector(".ui-grid-canvas:not(.ui-grid-empty-base-layer-container)").children[0]),t="'ui-grid-row-selected': row.isSelected, 'ui-grid-row-focused': row.isFocused}",i=e.attr("ng-class"),t=i?i.slice(0,-1)+","+t:"{"+t;return e.attr("ng-class",t),{pre:function(e,t,i,o){},post:function(e,t,i,o){}}}}}),e.directive("uiGridCell",["uiGridConstants","uiGridSelectionService",function(g,S){return{priority:-200,restrict:"A",require:"?^uiGrid",scope:!1,link:function(i,n,e,t){function o(e){l=(new Date).getTime(),c=e.changedTouches[0],n.off("click",d)}var l=0,c={},s=300,r=100,d=(t.grid.api.cellNav&&t.grid.api.cellNav.on.viewPortKeyDown(i,function(e,t){null!==t&&t.row===i.row&&t.col===i.col&&e.keyCode===g.keymap.SPACE&&"selectionRowHeaderCol"===i.col.colDef.name&&(e.preventDefault(),S.toggleRowSelection(i.grid,i.row,e,i.grid.options.multiSelect&&!i.grid.options.modifierKeysToMultiSelect,i.grid.options.noUnselect,!1),i.$apply())}),function(e){"ui-grid-icon-minus-squared"!==e.target.className&&"ui-grid-icon-plus-squared"!==e.target.className&&(n.off("touchend",a),e.shiftKey?S.shiftSelect(i.grid,i.row,e,i.grid.options.multiSelect):e.ctrlKey||e.metaKey?S.toggleRowSelection(i.grid,i.row,e,i.grid.options.multiSelect,i.grid.options.noUnselect,!1):i.grid.options.enableSelectRowOnFocus&&S.toggleRowSelection(i.grid,i.row,e,i.grid.options.multiSelect&&!i.grid.options.modifierKeysToMultiSelect,i.grid.options.noUnselect,!1),i.row.setFocused(!i.row.isFocused),i.grid.api.selection.raise.rowFocusChanged(i.row,e),i.$apply(),window.setTimeout(function(){n.on("touchend",a)},s))}),a=function(e){var t=(new Date).getTime(),i=e.changedTouches[0],t=t-l,o=Math.abs(c.clientX-i.clientX),i=Math.abs(c.clientY-i.clientY);o<r&&i<r&&t<s&&d(e),window.setTimeout(function(){n.on("click",d)},s)};function u(){i.grid.options.enableRowSelection&&i.grid.options.enableFullRowSelection&&"selectionRowHeaderCol"!==i.col.colDef.name&&(n.addClass("ui-grid-disable-selection"),n.on("touchstart",o),n.on("touchend",a),n.on("click",d),i.registered=!0)}u();t=i.grid.registerDataChangeCallback(function(){i.grid.options.enableRowSelection&&i.grid.options.enableFullRowSelection&&!i.registered?u():i.grid.options.enableRowSelection&&i.grid.options.enableFullRowSelection||!i.registered||i.registered&&(n.removeClass("ui-grid-disable-selection"),n.off("touchstart",o),n.off("touchend",a),n.off("click",d),i.registered=!1)},[g.dataChange.OPTIONS]);n.on("$destroy",t)}}}]),e.directive("uiGridGridFooter",["$compile","gridUtil",function(n,l){return{restrict:"EA",replace:!0,priority:-1e3,require:"^uiGrid",scope:!0,compile:function(){return{pre:function(t,i,e,o){o.grid.options.showGridFooter&&l.getTemplate("ui-grid/gridFooterSelectedItems").then(function(e){e=angular.element(e),e=n(e)(t);angular.element(i[0].getElementsByClassName("ui-grid-grid-footer")[0]).append(e)})},post:function(e,t,i,o){}}}}}])}(),angular.module("ui.grid.selection").run(["$templateCache",function(e){"use strict";e.put("ui-grid/gridFooterSelectedItems",'<span ng-if="grid.selection.selectedCount !== 0 && grid.options.enableFooterTotalSelected">({{"search.selectedItems" | t}} {{grid.selection.selectedCount}})</span>'),e.put("ui-grid/selectionHeaderCell",'<div>\x3c!-- <div class="ui-grid-vertical-bar"> </div> --\x3e<div class="ui-grid-cell-contents" col-index="renderIndex"><ui-grid-selection-select-all-buttons ng-if="grid.options.enableSelectAll" role="checkbox" ng-model="grid.selection.selectAll"></ui-grid-selection-select-all-buttons></div></div>'),e.put("ui-grid/selectionRowHeader",'<div class="ui-grid-cell-contents ui-grid-disable-selection clickable"><ui-grid-selection-row-header-buttons></ui-grid-selection-row-header-buttons></div>'),e.put("ui-grid/selectionRowHeaderButtons",'<div class="ui-grid-selection-row-header-buttons ui-grid-icon-ok clickable" ng-class="{\'ui-grid-row-selected\': row.isSelected}" tabindex="0" ng-click="selectButtonClick(row, $event)" ng-keydown="selectButtonKeyDown(row, $event)" ng-attr-aria-label="{{(\'selection.aria.row\' | t) + \' \' + (row.index + 1) + \', \' + col.displayName}}" aria-checked="{{row.isSelected}}" role="checkbox" ng-model="row.isSelected"> </div>'),e.put("ui-grid/selectionSelectAllButtons",'<div role="checkbox" tabindex="0" class="ui-grid-selection-row-header-buttons ui-grid-icon-ok" ui-grid-one-bind-aria-label="\'selection.selectAll\' | t" aria-checked="{{grid.selection.selectAll}}" ng-class="{\'ui-grid-all-selected\': grid.selection.selectAll}" ng-click="headerButtonClick($event)" ng-keydown="headerButtonKeyDown($event)"></div>')}]);