cp.scripts.js.go 5.9 KB

123
  1. package assets
  2. var CpScriptsJs = []byte(`!function(window,$){var fave=function(window,$){var FormDataWasChanged=!1;function GetModalAlertTmpl(t,a,e){return'<div class="alert alert-'+(e?"danger":"success")+' alert-dismissible fade show" role="alert"><strong>'+t+"</strong> "+a+'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button></div>'}function ShowSystemMsg(t,a,e){var s=$(".modal.show .sys-messages");s.length||(s=$("form.alert-here .sys-messages")),s.length&&s.html(GetModalAlertTmpl(t,a,e))}function AjaxDone(data){try{eval(data)}catch(t){t instanceof SyntaxError&&(console.log(data),console.log("Error: JavaScript code eval error",t.message))}}function AjaxFail(t,a,e){console.log("Error: data sending error, page will be reloaded",t,a,e),setTimeout(function(){window.location.reload(!1)},1e3)}function FormToAjax(e){e.submit(function(t){if(e.hasClass("loading"))t.preventDefault();else{e.addClass("loading").addClass("alert-here");var a=e.find("button[type=submit]");a.addClass("progress-bar-striped").addClass("progress-bar-animated"),""!=a.attr("data-target")&&$("#"+a.attr("data-target")).addClass("progress-bar-striped").addClass("progress-bar-animated"),e.find(".sys-messages").html(""),$.ajax({type:"POST",url:e.attr("action"),data:e.serialize()}).done(function(t){FormDataWasChanged=!1,AjaxDone(t)}).fail(function(t,a,e){AjaxFail(t.responseText,a,e)}).always(function(){setTimeout(function(){e.removeClass("loading").removeClass("alert-here"),a.removeClass("progress-bar-striped").removeClass("progress-bar-animated"),""!=a.attr("data-target")&&$("#"+a.attr("data-target")).removeClass("progress-bar-striped").removeClass("progress-bar-animated")},100)}),t.preventDefault()}});var t=e.find("button[type=submit]");""!=t.attr("data-target")&&$("#"+t.attr("data-target")).click(function(){t.click()}),e.hasClass("prev-data-lost")&&e.find("input, textarea, select").on("input",function(){FormDataWasChanged||(FormDataWasChanged=!0)})}function AllFormsToAjax(){$("form").each(function(){FormToAjax($(this))})}function BindWindowBeforeUnload(){$(window).bind("beforeunload",function(){if(FormDataWasChanged)return"Some data was changed and not saved. Are you sure want to leave page?"})}function Initialize(){"function"==typeof $?(AllFormsToAjax(),BindWindowBeforeUnload()):console.log("Error: jQuery is not loaded!")}return window.addEventListener?window.addEventListener("load",Initialize,!1):window.attachEvent&&window.attachEvent("onload",Initialize),{ShowMsgSuccess:function(t,a){ShowSystemMsg(t,a,!1)},ShowMsgError:function(t,a){ShowSystemMsg(t,a,!0)},ModalUserProfile:function(){var t='<div class="modal fade" id="sys-modal-user-settings" tabindex="-1" role="dialog" aria-labelledby="sysModalUserSettingsLabel" aria-hidden="true"> \t\t\t\t\t<div class="modal-dialog modal-dialog-centered" role="document"> \t\t\t\t\t\t<div class="modal-content"> \t\t\t\t\t\t\t<form class="form-user-settings" action="/cp/" method="post" autocomplete="off"> \t\t\t\t\t\t\t\t<input type="hidden" name="action" value="index-user-update-profile"> \t\t\t\t\t\t\t\t<div class="modal-header"> \t\t\t\t\t\t\t\t\t<h5 class="modal-title" id="sysModalUserSettingsLabel">My profile</h5> \t\t\t\t\t\t\t\t\t<button type="button" class="close" data-dismiss="modal" aria-label="Close"> \t\t\t\t\t\t\t\t\t\t<span aria-hidden="true">&times;</span> \t\t\t\t\t\t\t\t\t</button> \t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t\t<div class="modal-body text-left"> \t\t\t\t\t\t\t\t\t<div class="form-group"> \t\t\t\t\t\t\t\t\t\t<label for="first_name">First name</label> \t\t\t\t\t\t\t\t\t\t<input type="text" class="form-control" id="first_name" name="first_name" value="'+window.CurrentUserProfileData.first_name+'" placeholder="User first name" autocomplete="off"> \t\t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t\t\t<div class="form-group"> \t\t\t\t\t\t\t\t\t\t<label for="last_name">Last name</label> \t\t\t\t\t\t\t\t\t\t<input type="text" class="form-control" id="last_name" name="last_name" value="'+window.CurrentUserProfileData.last_name+'" placeholder="User last name" autocomplete="off"> \t\t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t\t\t<div class="form-group"> \t\t\t\t\t\t\t\t\t\t<label for="email">Email</label> \t\t\t\t\t\t\t\t\t\t<input type="email" class="form-control" id="email" name="email" value="'+window.CurrentUserProfileData.email+'" placeholder="User email" autocomplete="off" required> \t\t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t\t\t<div class="form-group"> \t\t\t\t\t\t\t\t\t\t<label for="password">New password</label> \t\t\t\t\t\t\t\t\t\t<input type="password" class="form-control" id="password" aria-describedby="passwordHelp" name="password" value="" placeholder="User new password" autocomplete="off"> \t\t\t\t\t\t\t\t\t\t<small id="passwordHelp" class="form-text text-muted">Leave this field empty if you don\'t want change your password</small> \t\t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t\t\t<div class="sys-messages"></div> \t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t\t<div class="modal-footer"> \t\t\t\t\t\t\t\t\t<button type="submit" class="btn btn-primary">Save</button> \t\t\t\t\t\t\t\t\t<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> \t\t\t\t\t\t\t\t</div> \t\t\t\t\t\t\t</form> \t\t\t\t\t\t</div> \t\t\t\t\t</div> \t\t\t\t</div>';$("#sys-modal-user-settings-placeholder").html(t),$("#sys-modal-user-settings").modal({backdrop:"static",keyboard:!1,show:!1}),$("#sys-modal-user-settings").on("hidden.bs.modal",function(t){$("#sys-modal-user-settings-placeholder").html("")}),FormToAjax($("#sys-modal-user-settings form")),$("#sys-modal-user-settings").modal("show")},ActionLogout:function(t){confirm(t)&&$.ajax({type:"POST",url:"/cp/",data:{action:"index-user-logout"}}).done(function(t){AjaxDone(t)}).fail(function(t,a,e){AjaxFail(t.responseText,a,e)})},ActionDataTableDelete:function(t,a,e,s){confirm(s)&&$.ajax({type:"POST",url:"/cp/",data:{action:a,id:e}}).done(function(t){AjaxDone(t)}).fail(function(t,a,e){AjaxFail(t.responseText,a,e)})}}}(window,$);window.fave=fave}(window,jQuery);`)