-
Notifications
You must be signed in to change notification settings - Fork 77
/
ui-grid.edit.min.js
6 lines (6 loc) · 11.2 KB
/
ui-grid.edit.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.edit",["ui.grid"]);e.constant("uiGridEditConstants",{EDITABLE_CELL_TEMPLATE:/EDITABLE_CELL_TEMPLATE/g,EDITABLE_CELL_DIRECTIVE:/editable_cell_directive/g,events:{BEGIN_CELL_EDIT:"uiGridEventBeginCellEdit",END_CELL_EDIT:"uiGridEventEndCellEdit",CANCEL_CELL_EDIT:"uiGridEventCancelCellEdit"}}),e.service("uiGridEditService",["$q","uiGridConstants","gridUtil",function(o,i,l){var t={initializeGrid:function(e){t.defaultGridOptions(e.options),e.registerColumnBuilder(t.editColumnBuilder),e.edit={};e.api.registerEventsFromObject({edit:{afterCellEdit:function(e,i,t,n){},beginCellEdit:function(e,i,t){},cancelCellEdit:function(e,i){}}})},defaultGridOptions:function(e){e.cellEditableCondition=void 0===e.cellEditableCondition||e.cellEditableCondition,e.enableCellEditOnFocus=void 0!==e.enableCellEditOnFocus&&e.enableCellEditOnFocus},editColumnBuilder:function(i,t,e){var n=[];return i.enableCellEdit=void 0===i.enableCellEdit?void 0===e.enableCellEdit?"object"!==i.type:e.enableCellEdit:i.enableCellEdit,i.cellEditableCondition=(void 0===i.cellEditableCondition?e:i).cellEditableCondition,i.enableCellEdit&&(i.editableCellTemplate=i.editableCellTemplate||e.editableCellTemplate||"ui-grid/cellEditor",n.push(l.getTemplate(i.editableCellTemplate).then(function(e){t.editableCellTemplate=e},function(e){throw new Error("Couldn't fetch/use colDef.editableCellTemplate '"+i.editableCellTemplate+"'")}))),i.enableCellEditOnFocus=(void 0===i.enableCellEditOnFocus?e:i).enableCellEditOnFocus,o.all(n)},isStartEditKey:function(e){return!(e.metaKey||e.keyCode===i.keymap.ESC||e.keyCode===i.keymap.SHIFT||e.keyCode===i.keymap.CTRL||e.keyCode===i.keymap.ALT||e.keyCode===i.keymap.WIN||e.keyCode===i.keymap.CAPSLOCK||e.keyCode===i.keymap.LEFT||e.keyCode===i.keymap.TAB&&e.shiftKey||e.keyCode===i.keymap.RIGHT||e.keyCode===i.keymap.TAB||e.keyCode===i.keymap.UP||e.keyCode===i.keymap.ENTER&&e.shiftKey||e.keyCode===i.keymap.DOWN||e.keyCode===i.keymap.ENTER)}};return t}]),e.directive("uiGridEdit",["gridUtil","uiGridEditService",function(e,o){return{replace:!0,priority:0,require:"^uiGrid",scope:!1,compile:function(){return{pre:function(e,i,t,n){o.initializeGrid(n.grid)},post:function(e,i,t,n){}}}}}]),e.directive("uiGridViewport",["uiGridEditConstants",function(l){return{replace:!0,priority:-99998,require:["^uiGrid","^uiGridRenderContainer"],scope:!1,compile:function(){return{post:function(e,i,t,n){var o=n[0];o.grid.api.edit&&o.grid.api.cellNav&&"body"===n[1].containerId&&(e.$on(l.events.CANCEL_CELL_EDIT,function(){o.focus()}),e.$on(l.events.END_CELL_EDIT,function(){o.focus()}))}}}}}]),e.directive("uiGridCell",["$compile","$injector","$timeout","uiGridConstants","uiGridEditConstants","gridUtil","$parse","uiGridEditService","$rootScope","$q",function(L,e,b,T,k,h,w,_,I,G){return e.has("uiGridCellNavService")&&e.get("uiGridCellNavService"),{priority:-100,restrict:"A",scope:!1,require:"?^uiGrid",link:function(d,c,e,n){var a,u,s,i,E,t,o,l,r,f=!1;function p(){c.on("dblclick",m),c.on("touchstart",C),n&&n.grid.api.cellNav&&(o=n.grid.api.cellNav.on.viewPortKeyDown(d,function(e,i){null===i||i.row!==d.row||i.col!==d.col||d.col.colDef.enableCellEditOnFocus||v(e)}),t=n.grid.api.cellNav.on.navigate(d,function(e,i,t){!d.col.colDef.enableCellEditOnFocus||e.row!==d.row||e.col!==d.col||null!==t&&(!t||"click"!==t.type&&"keydown"!==t.type)||b(function(){m(t)})})),d.beginEditEventsWired=!0}function C(e){void 0!==e.originalEvent&&void 0!==e.originalEvent&&(e=e.originalEvent),c.on("touchend",g),(i=b(function(){},500)).then(function(){setTimeout(m,0),c.off("touchend",g)}).catch(angular.noop)}function g(){b.cancel(i),c.off("touchend",g)}function y(){c.off("dblclick",m),c.off("keydown",v),c.off("touchstart",C),t(),o(),d.beginEditEventsWired=!1}function v(e){_.isStartEditKey(e)&&m(e)}function m(r){d.grid.api.core.scrollToIfNecessary(d.row,d.col).then(function(){var e=r;if(!f&&function(e,i,t){return!i.isSaving&&(angular.isFunction(e.colDef.cellEditableCondition)?e.colDef.cellEditableCondition(d,t):e.colDef.cellEditableCondition)}(d.col,d.row,e)){var i=d.row.getQualifiedColField(d.col),i=(d.col.colDef.editModelField&&(i=h.preEval("row.entity."+d.col.colDef.editModelField)),s=w(i),u=s(d),a=(a=(a=d.col.editableCellTemplate).replace(T.MODEL_COL_FIELD,i)).replace(T.COL_FIELD,"grid.getCellValue(row, col)"),d.col.colDef.editDropdownFilter?"|"+d.col.colDef.editDropdownFilter:""),t=(a=a.replace(T.CUSTOM_FILTERS,i),"text");switch(d.col.colDef.type){case"boolean":t="checkbox";break;case"number":t="number";break;case"date":t="date"}a=a.replace("INPUT_TYPE",t);var i=d.col.colDef.editDropdownOptionsFunction,i=(i?G.when(i(d.row.entity,d.col.colDef)).then(function(e){d.editDropdownOptionsArray=e}):(i=d.col.colDef.editDropdownRowEntityOptionsArrayPath,d.editDropdownOptionsArray=i?function(e,i){var t=(i=(i=i.replace(/\[(\w+)\]/g,".$1")).replace(/^\./,"")).split(".");for(;t.length;){var n=t.shift();if(!(n in e))return;e=e[n]}return e}(d.row.entity,i):d.col.colDef.editDropdownOptionsArray),d.editDropdownIdLabel=d.col.colDef.editDropdownIdLabel||"id",d.editDropdownValueLabel=d.col.colDef.editDropdownValueLabel||"value",function(){f=!0,y();var e=angular.element(a);c.append(e),E=d.$new(),L(e)(E),angular.element(c.children()[0]).addClass("ui-grid-cell-contents-hidden")}),n=(I.$$phase?i():d.$apply(i),d.col.grid.api.core.on.scrollBegin(d,function(){d.grid.disableScrolling||(D(),d.grid.api.edit.raise.afterCellEdit(d.row.entity,d.col.colDef,s(d),u),n(),o(),l())})),o=d.$on(k.events.END_CELL_EDIT,function(){D(),d.grid.api.edit.raise.afterCellEdit(d.row.entity,d.col.colDef,s(d),u),o(),n(),l()}),l=d.$on(k.events.CANCEL_CELL_EDIT,function(){d.grid.disableScrolling=!1,f&&(s.assign(d,u),d.$apply(),d.grid.api.edit.raise.cancelCellEdit(d.row.entity,d.col.colDef),D()),l(),n(),o()});d.$broadcast(k.events.BEGIN_CELL_EDIT,e),b(function(){d.grid.api.edit.raise.beginCellEdit(d.row.entity,d.col.colDef,e)})}})}function D(){if(d.grid.disableScrolling=!1,f){n&&n.grid.api.cellNav&&n.focus();for(var e=angular.element(c.children()[0]),i=(E.$destroy(),c.children()),t=1;t<i.length;t++)angular.element(i[t]).remove();e.removeClass("ui-grid-cell-contents-hidden"),f=!1,p(),d.grid.api.core.notifyDataChange(T.dataChange.EDIT)}}d.col.colDef.enableCellEdit&&(t=function(){},o=function(){},(l=function(){d.col.colDef.enableCellEdit&&!1!==d.row.enableCellEdit?d.beginEditEventsWired||p():d.beginEditEventsWired&&y()})(),r=d.$watch("row",function(e,i){e!==i&&l()}),d.$on("$destroy",function(){r(),c.off()}))}}}]),e.directive("uiGridEditor",["gridUtil","uiGridConstants","uiGridEditConstants","$timeout","uiGridEditService",function(e,d,c,a,u){return{scope:!0,require:["?^uiGrid","?^uiGridRenderContainer","ngModel"],compile:function(){return{pre:function(e,i,t){},post:function(i,t,e,n){var o,l,r;n[0]&&(o=n[0]),n[1]&&(l=n[1]),n[2]&&(r=n[2]),i.$on(c.events.BEGIN_CELL_EDIT,function(){var n;a(function(){if(t[0].focus(),!t[0].select||!i.col.colDef.enableCellEditOnFocus&&o&&o.grid.api.cellNav)try{t[0].setSelectionRange(t[0].value.length,t[0].value.length)}catch(e){}else t[0].select()}),o&&o.grid.api.cellNav&&(n=o.grid.api.cellNav.on.viewPortKeyPress(i,function(e,i){var t;u.isStartEditKey(e)&&0<(t="number"==typeof e.which?e.which:e.keyCode)&&(r.$setViewValue(String.fromCharCode(t),e),r.$render()),n()})),t.on("mousedown",function(e){"checkbox"===t[0].type&&(t.off("blur",i.stopEdit),a(function(){t[0].focus(),t.on("blur",i.stopEdit)}))}),t[0]&&t[0].focus(),t.on("blur",i.stopEdit)}),i.deepEdit=!1,i.stopEdit=function(e){i.inputForm&&!i.inputForm.$valid?(e.stopPropagation(),i.$emit(c.events.CANCEL_CELL_EDIT)):i.$emit(c.events.END_CELL_EDIT),i.deepEdit=!1},t.on("click",function(e){"checkbox"!==t[0].type&&(i.deepEdit=!0,i.$applyAsync(function(){i.grid.disableScrolling=!0}))}),t.on("keydown",function(e){if(e.keyCode===d.keymap.ESC&&(e.stopPropagation(),i.$emit(c.events.CANCEL_CELL_EDIT)),!i.deepEdit||e.keyCode!==d.keymap.LEFT&&e.keyCode!==d.keymap.RIGHT&&e.keyCode!==d.keymap.UP&&e.keyCode!==d.keymap.DOWN)if(o&&o.grid.api.cellNav)e.uiGridTargetRenderContainerId=l.containerId,null!==o.cellNav.handleKeyDown(e)&&i.stopEdit(e);else switch(e.keyCode){case d.keymap.ENTER:case d.keymap.TAB:e.stopPropagation(),e.preventDefault(),i.stopEdit(e)}else e.stopPropagation();return!0}),i.$on("$destroy",function(){t.off()})}}}}}]),e.directive("uiGridEditor",["$filter",function(o){return{priority:-100,require:"?ngModel",link:function(e,i,t,n){2===angular.version.minor&&t.type&&"date"===t.type&&n&&(n.$formatters.push(function(e){return n.$setValidity(null,!e||!isNaN(e.getTime())),o("date")(e,"yyyy-MM-dd")}),n.$parsers.push(function(e){var i,t;return e&&0<e.length?(i=void 0===(e=e)||""===e||3!==(e=e.split("-")).length||(i=parseInt(e[0],10),t=parseInt(e[1],10),e=parseInt(e[2],10),t<1)||i<1||e<1?null:new Date(i,t-1,e),n.$setValidity(null,i&&!isNaN(i.getTime())),i):(n.$setValidity(null,!0),null)}))}}}]),e.directive("uiGridEditDropdown",["uiGridConstants","uiGridEditConstants","$timeout",function(r,d,c){return{require:["?^uiGrid","?^uiGridRenderContainer"],scope:!0,compile:function(){return{pre:function(e,i,t){},post:function(i,e,t,n){var o=n[0],l=n[1];i.$on(d.events.BEGIN_CELL_EDIT,function(){c(function(){e[0].focus()}),e[0].style.width=e[0].parentElement.offsetWidth-1+"px",e.on("blur",function(e){i.stopEdit(e)})}),i.stopEdit=function(e){i.$emit(d.events.END_CELL_EDIT)},e.on("keydown",function(e){if(e.keyCode===r.keymap.ESC&&(e.stopPropagation(),i.$emit(d.events.CANCEL_CELL_EDIT)),o&&o.grid.api.cellNav)e.uiGridTargetRenderContainerId=l.containerId,null!==o.cellNav.handleKeyDown(e)&&i.stopEdit(e);else switch(e.keyCode){case r.keymap.ENTER:case r.keymap.TAB:e.stopPropagation(),e.preventDefault(),i.stopEdit(e)}return!0}),i.$on("$destroy",function(){e.off()})}}}}}]),e.directive("uiGridEditFileChooser",["gridUtil","uiGridConstants","uiGridEditConstants",function(o,e,l){return{scope:!0,require:["?^uiGrid","?^uiGridRenderContainer"],compile:function(){return{pre:function(e,i,t){},post:function(t,n){n[0].addEventListener("change",function e(i){i=i.srcElement||i.target;i&&i.files&&0<i.files.length?("function"==typeof t.col.colDef.editFileChooserCallback?t.col.colDef.editFileChooserCallback(t.row,t.col,i.files):o.logError("You need to set colDef.editFileChooserCallback to use the file chooser"),i.form.reset(),t.$emit(l.events.END_CELL_EDIT)):t.$emit(l.events.CANCEL_CELL_EDIT),n[0].removeEventListener("change",e,!1)},!1),t.$on(l.events.BEGIN_CELL_EDIT,function(){n[0].focus(),n[0].select(),n.on("blur",function(){t.$emit(l.events.END_CELL_EDIT),n.off()})})}}}}}])}(),angular.module("ui.grid.edit").run(["$templateCache",function(e){"use strict";e.put("ui-grid/cellEditor",'<div><form name="inputForm"><input type="INPUT_TYPE" ng-class="\'colt\' + col.uid" ui-grid-editor ng-model="MODEL_COL_FIELD"></form></div>'),e.put("ui-grid/dropdownEditor",'<div><form name="inputForm"><select ng-class="\'colt\' + col.uid" ui-grid-edit-dropdown ng-model="MODEL_COL_FIELD" ng-options="field[editDropdownIdLabel] as field[editDropdownValueLabel] CUSTOM_FILTERS for field in editDropdownOptionsArray"></select></form></div>'),e.put("ui-grid/fileChooserEditor",'<div><form name="inputForm"><input ng-class="\'colt\' + col.uid" ui-grid-edit-file-chooser type="file" id="files" name="files[]" ng-model="MODEL_COL_FIELD"></form></div>')}]);