function JDialog(options) { var element=options.element; if (($(element).hasClass("ui-dialog-content"))&&($(element.dialog("isOpen")))) return; var parentElement=options.element.parent(); $(element).css('zIndex',9999); element.data("parentElement",parentElement); if (options.closebutton) { if (options.buttons==null) options.buttons={}; options.buttons["closeBtn"]={ class:"btn btn-danger btn-37", html:" Закрыть", click:function(){ var dlg=$(this).parents("div.ui-dialog").attr("aria-describedby"); $("#"+dlg).dialog("close"); }, mouseover:function(){ $(this).parent().find("button").not(this).find(".btntext").hide(200); $(this).find(".btntext").show(200); } } } if (options.acceptbutton!=null) { if (options.buttons==null) options.buttons={}; options.buttons["acceptBtn"]={ class:"btn btn-success btn-37", html:" Внести", click:options.acceptbutton, mouseover:function(){ $(this).parent().find("button").not(this).find(".btntext").hide(200); $(this).find(".btntext").show(200); } }; element.off("keypress"); element.keypress(function(e) { if (e.keyCode == $.ui.keyCode.ENTER) { if (!$(e.target).hasClass("filterelement")) options.acceptbutton(); } }); } var appendto=null; if (document.fullscreenElement) appendto="#tdmain"; if (options.appendto!=null) appendto=options.appendto; if ((options.class!=null)&&(options.classes==null)) options.classes={ "ui-dialog":"ui-corner-all","ui-dialog-titlebar":'ui-corner-all bg-'+options.class }; element.dialog({ height:(options.height==null)?"auto":options.height, width:(options.width==null)?"auto":options.width, modal:(options.modal==null)?true:options.modal, autoOpen:(options.autoOpen==null)?true:options.autoOpen, classes:options.classes, resizable:(options.resizable==true), draggable:(options.draggable!==null)?options.draggable:true, autoResize:true, responsive:true, appendTo:appendto, position:(options.position!=null)?options.position:{my:'top',at:'top+150'}, title:options.title, buttons:options.buttons, close:function(){ element.dialog("destroy"); element.appendTo(parentElement); if (options.close!=null) options.close.apply(this); // options.close(); }, open: function () { var ui_dialog_interaction = $.ui.dialog.prototype._allowInteraction; $.ui.dialog.prototype._allowInteraction = function (e) { if ($(e.target).is(".allowinteraction")) return true; if ($(e.target).closest('.select2-search__field,.select2-dropdown').length) return true; return ui_dialog_interaction.apply(this, arguments); }; $.ui.dialog.prototype._allowInteractionRemapped = true; if (options.open!=null) options.open(); setTimeout(function(){ $(".ui-dialog").draggable({ cancel:".ui-dialog-content" }); },1000); }, _allowInteraction: function (event) { return !!($(event.target).is(".select2-input")||($(event.target).is(".allowinteraction"))) || this._super(event); } }); } function JDButton(opts) { return { class:"btn btn-37 "+(opts.class!=null)?opts.class:"", html:" "+opts.text+"", click:opts.action, mouseover:function(){ $(this).parent().find("button").not(this).find(".btntext").hide(200); $(this).find(".btntext").show(200); } }; } function JDialogPost(dlg,data,callback) { obj={ dialog:dlg, callback:callback, data:data }; dlg.JDialog("waitbuttons"); $.ajax({ url: "/headless.php", type: "post", data: data, context:obj }).done(processReturn(function(d){ if (this.callback!=null) this.callback.apply(this,[d]); this.dialog.dialog("close"); },{ funcrevert:function(){ this.dialog.JDialog("returnbuttons"); } })); } $.fn.JDialog=function(options) { if ( typeof options === 'object') { options["element"]=$(this); JDialog(options); return; } else { params=arguments[1]; switch(options) { case "isopen": return ($(this).hasClass("ui-dialog-content")); case "recenter": recenter($(this)); break; case "checkTablers": return checkTablers($(this)); case "waitbuttons": $(this).data("tabler_buttons",$(this).dialog("option","buttons")); $(this).dialog("option","buttons",{ "Ожидайте...":function(){} });break; case "returnbuttons": $(this).dialog("option","buttons",$(this).data("tabler_buttons")); break; case "post": return JDialogPost($(this),params,arguments[2]); } } } function isFormValid(el,zerosnotallowed,addfunction) { var str; checkRequiredForm(el,zerosnotallowed,addfunction); str=""; $(el).find(".has-error").each(function(){ var title=$(this).find(".inputrequired,.erroreditem").attr("title"); if (title==null) { title=$(this).prev().text().replace(":",""); } str+=title+" "; }); if (str!="") { $.snackbar({ content:"

Ошибка в полях:

"+str, htmlAllowed:true, timeout:4000 }); return false; } return true; } $.fn.isFormValid=function(options) { var zerosnotallowed=null,addfunction=null; var el=$(this); if (options!=null) { zerosnotallowed=options.zerosnotallowed; addfunction=options.addfunction; } return isFormValid(el,zerosnotallowed,addfunction); } function actInDialog(options) { i=0; $("body").find("div.actionDialog").each(function(){ dialogId=parseInt($(this).attr("dialogId")); if (i"); dlg.addClass("dialog").addClass("actionDialog"); dlg.attr("dialogId",i); $("body").append(dlg); if (options.width!=null) dlg.css("min-width",options.width); dlg.html(""); data=options.data; if (data==null) data={}; data.action=options.action; var uuid=guid(); dlg.attr("indialog",uuid); data.indialog=uuid; dlg.data("options",options); $.ajax({ url:"headless.php?action="+options.action, type:"post", data:data, context:dlg, success:function(data) { this.html(data); this.dialog('widget').position({ my: "center top", at: "center top", of: window }); this.dialog("option","position","top"); let opts=this.data("options"); if (opts.draggable==null) this.dialog({ draggable:false}).parent().draggable(); } }); dlg.data("dlgoptions",options); dlg.JDialog({ title:options.title, buttons:options.buttons, modal:options.modal??true, class:options.class, acceptbutton:options.acceptbutton, closebutton:options.closebutton, draggable:(options.draggable!==null)?options.draggable:{ handle: ".ui-dialog-titlebar", cancel: ".ui-dialog-content, .ui-dialog-titlebar-close" }, close:function(){ if (options.close!=null) options.close(); if (options.noremove!=1) $(this).remove(); } }); return dlg; } function myAlert(text) { $.alert({ icon:"glyphicon glyphicon-exclamation-sign", type:"red", title:"Ошибка!", content:text, container:$("#tdmain") }); } function myConfirm(text,funcconfirm,funcrevert) { if (funcrevert!=null) buttons={ " Да":funcconfirm, " Нет":funcrevert } else buttons={ " Да":funcconfirm, " Нет":function(){} }; $.confirm({ icon:"glyphicon glyphicon-question-sign", type:"orange", title:"Требуется подверждение:", content:text, keyboardEnabled : true, escapeKey:" Нет", theme:"bootstrap", buttons:buttons, container:$("#tdmain") }); } function myPrompt(text,funcconfirm,funcrevert) { if (funcrevert!=null) buttons={ " Внести":funcconfirm, " Отменить":funcrevert } else buttons={ " Внести":funcconfirm, " Отменить":function(){} }; $.confirm({ icon:"glyphicon glyphicon-question-sign", type:"green", title:"Требуется ввод:", content:text, keyboardEnabled : true, theme:"bootstrap", buttons:buttons, container:$("#tdmain") }); } function dlgButton(options){ let str=""; if (options.glyph!=null) str+=" "; str+=" "+options.text+""; return { class:"btn btn-37 "+options.class, html:str, click:options.action, mouseover:function(){ $(this).parent().find("button").not(this).find(".btntext").hide(200); $(this).find(".btntext").show(200); } } }