var wdtCustomUploader=null;var inlineEditClass=function(tableDescription,dataTableOptions,$){var obj={params:{tableId:tableDescription.tableId,currentCell:'',editInputId:'dt_cell_edit',editSelector:'#dt_cell_edit',validationPopover:'<div class="wpDataTablesPopover editError"></div>',value:'',table:'',cellData:'',cellInfo:'',rowId:'',columnId:'',columnType:'',inputType:'',columnHeader:'',notNull:'',code:'',expandButton:'',valid:!0,additionalValid:!0,dateFormat:tableDescription.datepickFormat.replace(/y/g,'yy').replace(/Y/g,'yyyy').replace(/M/g,'mmm'),timeFormat:tableDescription.timeFormat},datePicker:'',timePicker:'',removeSelection:function(){if(document.selection&&document.selection.empty){document.selection.empty()}else if(window.getSelection){var sel=window.getSelection();sel.removeAllRanges()}},setErrorPopoverPosition:function(element,popover){var position='';var offset=element.offset();var width=element.outerWidth(!0);var height=element.outerHeight(!0);var centerX=offset.left+(width/2)-(popover.width/2);var centerY=offset.top-(popover.height);position={"top":centerY,"left":centerX};return position},parseLink:function(){if(obj.params.value!==null){if(obj.params.value.indexOf('<a ')!==-1){var $link=$(obj.params.value);if($.inArray(obj.params.columnType,['link','email'])!==-1){if($link.attr('href').indexOf($link.html())===-1){obj.params.value=$link.attr('href').replace('mailto:','')+'||'+$link.html()}else{obj.params.value=$link.html()}}else if($.inArray(obj.params.columnType,['icon'])!==-1){var $linkthumb=$($link.html());if($link.attr('href').indexOf($link.html())===-1){obj.params.value=$link.attr('href')+'||'+$linkthumb.attr('src')}else{obj.params.value=$link.html()}}}else if(obj.params.value.indexOf('<img ')!==-1){$link=$(obj.params.value);obj.params.value=$link.attr('src')}}},saveData:function(val,rowId,columnId){if($.inArray(obj.params.columnHeader,['wdt_created_by','wdt_created_at','wdt_last_edited_by','wdt_last_edited_at'])!==-1){obj.params.currentCell.empty().html(wpdatatables_frontend_strings.cannot_be_edit);$(document).click(function(){$this.html($value)})}else{$(tableDescription.selector).addClass('overlayed');wpDataTables[obj.params.tableId].fnUpdate(val,rowId,columnId,0,0);var data=wpDataTables[obj.params.tableId].fnGetData(rowId);wpDataTablesFunctions[obj.params.tableId].applyData(data);wpDataTablesFunctions[obj.params.tableId].saveTableData(!0,!1,!1);$(tableDescription.selector).find('td').removeClass('editing')}},fieldValidation:function(type,element){if(obj.params.value!=''){if(type=='email'){var field_valid=wdtValidateEmail(obj.params.value);var message=wpdatatables_inline_strings.invalid_email}else if(type=='link'){var field_valid=wdtValidateURL(obj.params.value);var message=wpdatatables_inline_strings.invalid_link}
if(!field_valid){if(!element.closest('td').hasClass('error')){element.closest('td').addClass('error');$('body').prepend(obj.params.validationPopover);$('.wpDataTablesPopover.editError').html(message);var popoverSize={"width":$('.wpDataTablesPopover.editError').outerWidth(),"height":$('.wpDataTablesPopover.editError').outerHeight()+7};$('.wpDataTablesPopover.editError').css(obj.setErrorPopoverPosition(element,popoverSize));setTimeout(function(){$('.wpDataTablesPopover.editError').animateFadeOut('300',function(){$(this).remove();element.closest('td').removeClass('error')})},2000)}
obj.params.valid=!1;obj.params.additionalValid=!1}else{$(this).closest('td').removeClass('error');obj.params.valid=!0;obj.params.additionalValid=!0}}else{obj.params.valid=!0;obj.params.additionalValid=!0}},mandatoryFieldValidation:function(element){if(obj.params.value==''||!obj.params.additionalValid){if(!element.closest('td').hasClass('error')){element.closest('td').addClass('error');$('body').prepend(obj.params.validationPopover);$('.wpDataTablesPopover.editError').html(wpdatatables_inline_strings.cannot_be_empty);var popoverSize={"width":$('.wpDataTablesPopover.editError').outerWidth(),"height":$('.wpDataTablesPopover.editError').outerHeight()+7};$('.wpDataTablesPopover.editError').css(obj.setErrorPopoverPosition(element,popoverSize));setTimeout(function(){$('.wpDataTablesPopover.editError').animateFadeOut('300',function(){$(this).remove();element.closest('td').removeClass('error')})},2000);obj.params.valid=!1}}else{element.closest('td').removeClass('error');obj.params.valid=!0}},validateAndSave:function($this){var type_array=['email','link'];if($.inArray(obj.params.inputType,type_array)!==-1&&obj.params.columnType!='icon'){obj.fieldValidation(obj.params.inputType,$this);if(obj.params.notNull){obj.mandatoryFieldValidation($this)}}else{if(obj.params.notNull){obj.mandatoryFieldValidation($this)}}
if(obj.params.valid){$.when(obj.saveData(obj.params.value,obj.params.rowId,obj.params.columnId)).then(obj.params.currentCell.prepend(obj.params.expandButton))}},FieldTypeMethods:{noneditableCell:function(){obj.params.currentCell.removeClass('editing');var $this=obj.params.currentCell;var $value=obj.params.currentCell.html();obj.params.currentCell.empty().html(wpdatatables_inline_strings.cannot_be_edit);$(document).click(function(){$this.html($value)})},textCell:function(){obj.parseLink();var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':'&quot;',"'":'&#39;',"/":'&#x2F;'};function escapeHtml(string){return String(string).replace(/[&<>"'\/]/g,function(s){return entityMap[s]})}
var value=obj.params.value==null?'':escapeHtml(obj.params.value);obj.params.code='<input type="text" data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" value="'+value+'" />';obj.params.currentCell.empty().append(obj.params.code);$(obj.params.editSelector).focus();$(obj.params.editSelector).blur(function(){obj.params.value=$(this).val();obj.validateAndSave($(this))})},textareaCell:function(){obj.parseLink();if(obj.params.value==null){obj.params.value=''}else if(obj.params.value.indexOf('<br/>')!=-1){obj.params.value=(obj.params.value).replace(/<br\/>/g,"\n")}
obj.params.code='<textarea data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" rows="3" columns="50">'+obj.params.value+'</textarea>';obj.params.currentCell.empty().append(obj.params.code);$(obj.params.editSelector).focus();$(obj.params.editSelector).blur(function(){obj.params.value=$(this).val();obj.validateAndSave($(this))})},tinymceCell:function(){obj.parseLink();if(obj.params.value.indexOf('<br/>')!=-1){obj.params.value=(obj.params.value).replace(/<br\/>/g,"\n")}
obj.params.code='<textarea class="wpdt-tiny-mce" data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" rows="3" columns="50">'+obj.params.value+'</textarea>';obj.params.currentCell.empty().append(obj.params.code);tinymce.init({selector:obj.params.editSelector,auto_focus:obj.params.editInputId,menubar:!1,plugins:'link image media lists hr colorpicker fullscreen textcolor code',toolbar:'undo redo formatselect bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent blockquote | hr fullscreen | link unlink image | forecolor backcolor removeformat | code',init_instance_callback:function(editor){editor.on('blur',function(e){tinymce.triggerSave();obj.params.value=$(obj.params.editSelector).val();obj.validateAndSave($(obj.params.editSelector))})}})},linkCell:function(){obj.parseLink();if(obj.params.value==null){obj.params.value=''}
obj.params.code='<input type="text" data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" value="'+obj.params.value+'" />';obj.params.currentCell.empty().append(obj.params.code);$(obj.params.editSelector).focus();$(obj.params.editSelector).blur(function(){if(obj.params.columnType=='icon'){obj.params.value='<img src="'+$(this).val()+'" />'}else{obj.params.value=$(this).val()}
obj.validateAndSave($(this))})},dateCell:function(){obj.params.code='<input type="text" class="wdt-datepicker" data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" value="'+obj.params.value+'" />';obj.params.currentCell.empty().append(obj.params.code);$(obj.params.editSelector).focus();var hasFired=!1;$(obj.params.editSelector).blur(function(){if(!hasFired){hasFired=!0;obj.params.value=$(this).val();obj.validateAndSave($(this))}})},timeCell:function(){obj.params.code='<input type="text" class="wdt-timepicker" data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" value="'+obj.params.value+'" />';obj.params.currentCell.empty().append(obj.params.code);$(obj.params.editSelector).focus();var hasFired=!1;$(obj.params.editSelector).blur(function(){if(!hasFired){hasFired=!0;obj.params.value=$(this).val();obj.validateAndSave($(this))}})},datetimeCell:function(){obj.params.code='<input type="text" class="wdt-datetimepicker" data-input_type="'+obj.params.inputType+'" id="'+obj.params.editInputId+'" value="'+obj.params.value+'" />';obj.params.currentCell.empty().append(obj.params.code);$(obj.params.editSelector).focus();var hasFired=!1;$(obj.params.editSelector).blur(function(){if(!hasFired){hasFired=!0;obj.params.value=$(this).val();obj.validateAndSave($(this))}})},selectboxCell:function(){obj.params.code=$('#'+tableDescription.tableId+'_'+obj.params.columnHeader).clone();obj.params.currentCell.empty().append(obj.params.code.attr('id',obj.params.editInputId).removeClass('selecter-element'));if(obj.params.possibleValuesAjax===-1){if(obj.params.value!==null){$.each(obj.params.value.split(", "),function(i,e){$(obj.params.editSelector+' option[value="'+e+'"]').prop("selected",!0)})}}
$(obj.params.editSelector).selectpicker();if(obj.params.possibleValuesAjax!==-1){$(obj.params.editSelector).html('');$(obj.params.editSelector).selectpicker('val','').selectpicker('refresh');function loadAllPossibleValues(){$.ajax({url:tableDescription.adminAjaxBaseUrl,method:'POST',data:{wdtNonce:$('#wdtNonce').val(),action:'wpdatatables_get_column_possible_values',tableId:tableDescription.tableWpId,originalHeader:obj.params.columnHeader},success:function(data){data=JSON.parse(data);if(obj.params.inputType==='multi-selectbox'){var uniqueValues=[...new Set(data.map(item=>item.value.split(', ').map(val=>val.trim())).flat())]}
$(obj.params.editSelector).empty();if(obj.params.inputType==='multi-selectbox'){$.each(uniqueValues,function(index,item){var selected=obj.params.value!==null&&obj.params.value.includes(item);$(obj.params.editSelector).append('<option value="'+item+'"'+(selected?' selected':'')+'>'+item+'</option>')})}else{$.each(data,function(index,item){$(obj.params.editSelector).append('<option value="'+item.value+'">'+item.value+'</option>')})}
if(obj.params.value!==null&&obj.params.inputType==='selectbox'){$(obj.params.editSelector).append('<option selected value="'+obj.params.value+'">'+obj.params.value+'</option>')}
$(obj.params.editSelector).on('changed.bs.select',function(){if(obj.params.inputType==='selectbox'){$(obj.params.editSelector).data('changed',!0);obj.params.value=$(this).val();if($.type(obj.params.value)==='array'){obj.params.value=obj.params.value.join(', ')}
obj.validateAndSave($(this))}});$(obj.params.editSelector).selectpicker('refresh')}})}
$(obj.params.editSelector).on('show.bs.select',function(e){if(!tableDescription.advancedEditingOptions.aoColumns[obj.params.columnId].searchInSelectBoxEditing&&$(obj.params.editSelector).closest('.bootstrap-select').find('.bs-searchbox').length){$(obj.params.editSelector).closest('.bootstrap-select').find('.bs-searchbox')[0].style.display='none'}
setTimeout(function(){$(obj.params.editSelector).closest('.bootstrap-select').find('.bs-searchbox .form-control').val('').trigger('keyup')},500);loadAllPossibleValues()})}
obj.params.currentCell.css({'overflow':'initial'});$(obj.params.editSelector).selectpicker('toggle');if(obj.params.possibleValuesAjax===-1){if(obj.params.inputType==='selectbox'){$(obj.params.editSelector).on('changed.bs.select',function(){$(obj.params.editSelector).data('changed',!0);obj.params.value=$(this).val();if($.type(obj.params.value)==='array'){obj.params.value=obj.params.value.join(', ')}
obj.validateAndSave($(this))})}}
$(obj.params.editSelector).on('hidden.bs.select',function(){obj.params.value=$('#'+obj.params.editInputId).val();if($.type(obj.params.value)==='array'){obj.params.value=obj.params.value.join(', ')}
obj.validateAndSave($(this))})},attachmentCell:function(){obj.params.value='';var src='';if(obj.params.currentCell.find('img').length>0){if(obj.params.currentCell.find('img').attr('src').length>0){src=obj.params.currentCell.find('img').attr('src')}}else if(obj.params.currentCell.find('a').length>0){if(obj.params.currentCell.find('a').attr('href').length>0){src=obj.params.currentCell.find('a').attr('href')}}else{src=obj.params.currentCell.html()}
var fileName=src.substring(src.lastIndexOf('/')+1);obj.params.code='<span class="btn btn-primary m-r-10 fileupload_row_edit_'+tableDescription.tableId+'" '+'id="row_edit_'+tableDescription.tableId+'_sets_button" '+'data-column_type="icon" '+'data-rel_input="row_edit_'+tableDescription.tableId+'_sets">'+'<span class="fileinput-new">'+wpdatatables_inline_strings.selectFileAttachment+'</span>'+'<span class="fileinput-exists">'+wpdatatables_inline_strings.changeFileAttachment+'</span>'+'<input type="hidden" '+'id="row_edit_'+tableDescription.tableId+'_sets" '+'data-key="sets" '+'data-input_type="attachment" '+'value="'+src+'" '+'class="editDialogInput" '+'/>'+'</span>'+'<button class="btn btn-primary fileinput-save m-r-10">'+wpdatatables_inline_strings.saveFileAttachment+'</button>'+'<button class="btn btn-danger fileinput-exists wdt-detach-attachment-file-inline m-r-10" data-dismiss="fileinput">'+wpdatatables_inline_strings.removeFileAttachment+'</button>'+'<span class="fileinput-filename"></span>';obj.params.currentCell.empty().append(obj.params.code);obj.fileUploadInit('row_edit_'+tableDescription.tableId);var $inputElement=$('#row_edit_'+tableDescription.tableId+'_sets');if(fileName!=''){$inputElement.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');$inputElement.parent().parent().find('.fileinput-filename').text(fileName)}else{$inputElement.parent().parent().removeClass('fileinput-exists').addClass('fileinput-new');$inputElement.parent().parent().find('.fileinput-filename').text('')}
$('.fileinput-save').click(function(){obj.params.value=$('#row_edit_'+tableDescription.tableId+'_sets').val();obj.params.value='<a href="'+obj.params.value+'"></a>';$('#row_edit_'+tableDescription.tableId+'_sets').closest('td').empty().html(obj.params.value);obj.validateAndSave($(this))})}},fileUploadInit:function(selector){if($('.fileupload_'+selector).length){var attachment=null;wdtCustomUploader=wp.media({title:wpdatatables_inline_strings.select_upload_file,button:{text:wpdatatables_inline_strings.choose_file},multiple:!1});$('.fileupload_'+selector).click(function(e){e.preventDefault();var $button=$(this);var $relInput=$('#'+$button.data('rel_input'));if(obj.params.columnType=='icon'){wdtCustomUploader=wp.media({title:wpdatatables_inline_strings.select_upload_file,button:{text:wpdatatables_inline_strings.choose_file},multiple:!1,library:{type:'image'}});wdtCustomUploader.off('select').on('select',function(){attachment=wdtCustomUploader.state().get('selection').first().toJSON();var val=attachment.url;$relInput.parent().parent().parent().find('.fileinput-preview').html('<img src='+val+'>');$relInput.parent().parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');$relInput.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');if(attachment.sizes.thumbnail){val=attachment.sizes.thumbnail.url+'||'+val}
$relInput.val(val)})}else{wdtCustomUploader.off('select').on('select',function(){attachment=wdtCustomUploader.state().get('selection').first().toJSON();$relInput.val(attachment.url);$relInput.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');$relInput.parent().parent().find('.fileinput-filename').text(attachment.filename)})}
wdtCustomUploader.open()});$('.wdt-detach-attachment-file-inline').click(function(e){e.preventDefault();e.stopImmediatePropagation();if($(this).parent().find('span.fileupload-'+tableDescription.tableId).data('column_type')=='icon'){$(this).parent().find('input.editDialogInput').val('');$(this).parent().parent().find('.fileinput-preview').html('');$(this).parent().parent().removeClass('fileinput-exists').addClass('fileinput-new');$(this).parent().removeClass('fileinput-exists').addClass('fileinput-new')}else{$(this).parent().find('input.editDialogInput').val('');$(this).parent().find('.fileinput-filename').text('');$(this).parent().removeClass('fileinput-exists').addClass('fileinput-new')}})}},bindClickEvent:function(){$(tableDescription.selector+' tbody').on('dblclick','td',function(e){e.preventDefault();e.stopImmediatePropagation();var target=e.target||e.srcElement;var elementName=target.tagName.toLowerCase();if(elementName=='input'||elementName=='span'||!obj.params.valid||$(this).hasClass('editing')){return!1}
obj.removeSelection();if(!$(this).hasClass("dataTables_empty")){$(this).addClass('editing').attr('aria-label',wpdatatables_inline_strings.inlineEditing+$(this)[0].innerText)}
obj.params.table=$(tableDescription.selector).DataTable();if(wpDataTables[obj.params.tableId].fnSettings().fnRecordsTotal()==0){return!1}
obj.params.cellData=obj.params.table.cell(this).data();obj.params.cellInfo=obj.params.table.cell(this).index();obj.params.columnId=obj.params.cellInfo.column;obj.params.columnType=wpDataTables[obj.params.tableId].fnSettings().aoColumns[obj.params.columnId].wdtType;obj.params.rowId=obj.params.cellInfo.row;obj.params.inputType=dataTableOptions.aoColumnDefs[obj.params.columnId].InputType;obj.params.columnHeader=dataTableOptions.aoColumnDefs[obj.params.columnId].origHeader;obj.params.notNull=dataTableOptions.aoColumnDefs[obj.params.columnId].notNull;obj.params.value=obj.params.cellData;obj.params.currentCell=$(this);obj.params.possibleValuesAjax=tableDescription.advancedEditingOptions.aoColumns[obj.params.columnId].possibleValuesAjax;if($(this).children('.responsiveExpander')!=''){obj.params.expandButton=$(this).children('.responsiveExpander')}
switch(obj.params.inputType){case 'none':obj.FieldTypeMethods.noneditableCell();break;case 'text':obj.FieldTypeMethods.textCell();break;case 'textarea':obj.FieldTypeMethods.textareaCell();break;case 'mce-editor':obj.FieldTypeMethods.tinymceCell();break;case 'link':case 'email':obj.FieldTypeMethods.linkCell();break;case 'date':obj.FieldTypeMethods.dateCell();break;case 'time':obj.FieldTypeMethods.timeCell();break;case 'datetime':obj.FieldTypeMethods.datetimeCell();break;case 'multi-selectbox':case 'selectbox':obj.FieldTypeMethods.selectboxCell();break;case 'attachment':obj.FieldTypeMethods.attachmentCell();break}})}};obj.bindClickEvent()}
;