TIF_E41201544/public/assets/libs/datatables.net-autofill/js/dataTables.autoFill.min.mjs

4 lines
12 KiB
JavaScript

/*! AutoFill 2.5.3
* ©2008-2023 SpryMedia Ltd - datatables.net/license
*/
import $ from"jquery";import DataTable from"datatables.net";var _instance=0,AutoFill=function(t,e){if(!DataTable.versionCheck||!DataTable.versionCheck("1.10.8"))throw"Warning: AutoFill requires DataTables 1.10.8 or greater";this.c=$.extend(!0,{},DataTable.defaults.autoFill,AutoFill.defaults,e),this.s={dt:new DataTable.Api(t),namespace:".autoFill"+_instance++,scroll:{},scrollInterval:null,handle:{height:0,width:0},enabled:!1},this.dom={closeButton:$('<div class="dtaf-popover-close">x</div>'),handle:$('<div class="dt-autofill-handle"/>'),select:{top:$('<div class="dt-autofill-select top"/>'),right:$('<div class="dt-autofill-select right"/>'),bottom:$('<div class="dt-autofill-select bottom"/>'),left:$('<div class="dt-autofill-select left"/>')},background:$('<div class="dt-autofill-background"/>'),list:$('<div class="dt-autofill-list">'+this.s.dt.i18n("autoFill.info","")+"<ul/></div>"),dtScroll:null,offsetParent:null},this._constructor()},Api=($.extend(AutoFill.prototype,{enabled:function(){return this.s.enabled},enable:function(t){var e=this;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1}),$(window).on("resize",function(){0<$("div.dt-autofill-handle").length&&void 0!==e.dom.attachedTo&&e._attach(e.dom.attachedTo)});function o(){e.s.handle={height:!1,width:!1},$(e.dom.handle).css({height:"",width:""}),void 0!==e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return $(window).on("orientationchange",function(){setTimeout(function(){o(),setTimeout(o,150)},50)}),this},disable:function(){return this.s.enabled=!1,this._focusListenerRemove(),this},_constructor:function(){var t=this,e=this.s.dt,o=$("div.dataTables_scrollBody",this.s.dt.table().container());e.settings()[0].autoFill=this,o.length&&"static"===(this.dom.dtScroll=o).css("position")&&o.css("position","relative"),!1!==this.c.enable&&this.enable(),e.on("destroy.autoFill",function(){t._focusListenerRemove()})},_attach:function(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=$(e.table().node()).offsetParent()),l.height&&l.width||(i.appendTo("body"),l.height=i.outerHeight(),l.width=i.outerWidth()),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height,left:o.left+t.offsetWidth-l.width}).appendTo(this.dom.offsetParent)):this._detach()},_actionSelector:function(o){var t,i,l=this,n=this.s.dt,s=AutoFill.actions,a=[];$.each(s,function(t,e){e.available(n,o)&&a.push(t)}),1===a.length&&!1===this.c.alwaysAsk?(t=s[a[0]].execute(n,o),this._update(t,o)):1<a.length&&(i=this.dom.list.children("ul").empty(),a.push("cancel"),$.each(a,function(t,e){i.append($("<li/>").append('<div class="dt-autofill-question">'+s[e].option(n,o)+"<div>").append($('<div class="dt-autofill-button">').append($('<button class="'+AutoFill.classes.btn+'">'+n.i18n("autoFill.button","&gt;")+"</button>"))).on("click",function(){var t=s[e].execute(n,o,$(this).closest("li"));l._update(t,o),l.dom.background.remove(),l.dom.list.remove()}))}),this.dom.background.appendTo("body"),this.dom.background.one("click",function(){l.dom.background.remove(),l.dom.list.remove()}),this.dom.list.appendTo("body"),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).addClass(AutoFill.classes.closeable),this.dom.closeButton.on("click",function(){return l.dom.background.click()})),this.dom.list.css("margin-top",this.dom.list.outerHeight()/2*-1))},_detach:function(){this.dom.attachedTo=null,this.dom.handle.detach()},_drawSelection:function(t,e){var o,i=this.s.dt,l=this.s.start,n=$(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?$(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=$(i.cell(a.index(),s).node());i.cell(a).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.outerHeight()-i,a=this._getPosition(l.get(0)).left+l.outerWidth()-o,(n=this.dom.select).top.css({top:i,left:o,width:a}),n.left.css({top:i,left:o,height:t}),n.bottom.css({top:i+t,left:o,width:a}),n.right.css({top:i,left:o+a,height:t}))},_editor:function(t){var e=this.s.dt,o=this.c.editor;if(o){for(var i={},l=[],n=o.fields(),s=0,a=t.length;s<a;s++)for(var d=0,c=t[s].length;d<c;d++){var r=t[s][d],u=e.settings()[0].aoColumns[r.index.column],h=u.editField;if(void 0===h)for(var f=u.mData,m=0,p=n.length;m<p;m++){var v=o.field(n[m]);if(v.dataSrc()===f){h=v.name();break}}if(!h)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";i[h]||(i[h]={});u=e.row(r.index.row).id();i[h][u]=r.set,l.push(r.index)}o.bubble(l,!1).multiSet(i).submit()}},_emitEvent:function(o,i){this.s.dt.iterator("table",function(t,e){$(t.nTable).triggerHandler(o+".dt",i)})},_focusListener:function(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?($(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),$(document.body).on("click"+t,function(t){$(t.target).parents().filter(e.table().body()).length||i._detach()})):$(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){$(t.relatedTarget).hasClass("dt-autofill-handle")||i._detach()})},_focusListenerRemove:function(){var t=this.s.dt;t.off(".autoFill"),$(t.table().body()).off(this.s.namespace),$(document.body).off(this.s.namespace)},_getPosition:function(t,e){var o=t,i=0,l=0;e=e||$($(this.s.dt.table().node())[0].offsetParent);do{var n=o.offsetTop,s=o.offsetLeft,a=$(o.offsetParent)}while((i+=n+ +parseInt(a.css("border-top-width")||0),l+=s+ +parseInt(a.css("border-left-width")||0),"body"!==o.nodeName.toLowerCase())&&(o=a.get(0),a.get(0)!==e.get(0)));return{top:i,left:l}},_mousedown:function(t){var e=this,o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf($(this.dom.start).parent()[0]),column:$(this.dom.start).index()},$(document.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&$(document.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=$(o.table().node()).offsetParent(),i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:$(window).height(),windowWidth:$(window).width(),dtTop:i?i.offset().top:null,dtLeft:i?i.offset().left:null,dtHeight:i?i.outerHeight():null,dtWidth:i?i.outerWidth():null}},_mousemove:function(t){var e=t.touches&&t.touches.length?document.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))},_mouseup:function(t){$(document.body).off(".autoFill");var e=this,l=this.s.dt,o=this.dom.select,o=(o.top.remove(),o.left.remove(),o.right.remove(),o.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(o.row!==i.row||o.column!==i.column){var n,s=l.cell(":eq("+o.row+")",o.column+":visible",{page:"current"});if($("div.DTE",s.node()).length)(n=l.editor()).on("submitSuccess.dtaf close.dtaf",function(){n.off(".dtaf"),setTimeout(function(){e._mouseup(t)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){n.off(".dtaf")}),n.submit();else{for(var a=this._range(o.row,i.row),d=this._range(o.column,i.column),c=[],r=l.settings()[0],u=r.aoColumns,h=l.columns(this.c.columns).indexes(),f=0;f<a.length;f++)c.push($.map(d,function(t){var e=l.row(":eq("+a[f]+")",{page:"current"}),e=l.cell(e.index(),t+":visible"),t=e.data(),o=e.index(),i=u[o.column].editField;if(void 0!==i&&(t=r.oApi._fnGetObjectDataFn(i)(l.row(o.row).data())),-1!==h.indexOf(o.column))return{cell:e,data:t,label:e.data(),index:o}}));this._actionSelector(c),clearInterval(this.s.scrollInterval),this.s.scrollInterval=null}}},_range:function(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i},_shiftScroll:function(t){var e,o,i,l,n=this,s=(this.s.dt,this.s.scroll),a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-window.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-window.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;window.scrollTo(window.scrollX+(s.windowHoriz||0),window.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&(t=n.dom.dtScroll[0],s.dtVert&&(t.scrollTop+=s.dtVert),s.dtHoriz&&(t.scrollLeft+=s.dtHoriz))},20))},_update:function(t,e){if(!1!==t){var o,t=this.s.dt,i=t.columns(this.c.columns).indexes();if(this._emitEvent("preAutoFill",[t,e]),this._editor(e),null!==this.c.update?this.c.update:!this.c.editor){for(var l=0,n=e.length;l<n;l++)for(var s=0,a=e[l].length;s<a;s++)o=e[l][s],-1!==i.indexOf(o.index.column)&&o.cell.data(o.set);t.draw(!1)}this._emitEvent("autoFill",[t,e])}}}),AutoFill.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,e,o){for(var i=+e[0][0].data,l=+$("input",o).val(),n=0,s=e.length;n<s;n++)for(var a=0,d=e[n].length;a<d;a++)e[n][a].set=i,i+=l}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,e,o){for(var i=e[0][0].data,l=0,n=e.length;l<n;l++)for(var s=0,a=e[l].length;s<a;s++)e[l][s].set=i}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,e,o){for(var i=0,l=e.length;i<l;i++)for(var n=0,s=e[i].length;n<s;n++)e[i][n].set=e[i][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,e,o){for(var i=0,l=e.length;i<l;i++)for(var n=0,s=e[i].length;n<s;n++)e[i][n].set=e[0][n].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},AutoFill.version="2.5.3",AutoFill.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:null,editor:null,vertical:!0,horizontal:!0},AutoFill.classes={btn:"btn",closeable:"dtaf-popover-closeable"},$.fn.dataTable.Api);Api.register("autoFill()",function(){return this}),Api.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),Api.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),Api.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),$(document).on("preInit.dt.autofill",function(t,e,o){var i;"dt"===t.namespace&&(t=e.oInit.autoFill,i=DataTable.defaults.autoFill,(t||i)&&(i=$.extend({},t,i),!1!==t&&new AutoFill(e,i)))}),DataTable.AutoFill=AutoFill,$.fn.DataTable.AutoFill=AutoFill;export default DataTable;