# HG changeset patch # User Thierry Florac # Date 1573206669 -3600 # Node ID 644d0f6f65038e7305721cb92e749aa50664df32 # Parent de3ef58c6be87070d0a97603b4771fac72a03070 Added form events and "data-ams-form-reset-before-submit" attribute support diff -r de3ef58c6be8 -r 644d0f6f6503 src/pyams_skin/resources/js/myams-form.js --- a/src/pyams_skin/resources/js/myams-form.js Wed Oct 16 19:34:20 2019 +0200 +++ b/src/pyams_skin/resources/js/myams-form.js Fri Nov 08 10:51:09 2019 +0100 @@ -330,14 +330,22 @@ data: formData, dataType: data.amsFormDatatype, beforeSerialize: function(/*form, options*/) { + form.trigger('myams.form.before-serialize'); if (typeof (globals.tinyMCE) !== 'undefined') { globals.tinyMCE.triggerSave(); } }, beforeSubmit: function(data, form /*, options*/) { + form.trigger('myams.form.before-submit', [data]); form.data('submitted', true); + if (form.data('ams-form-reset-before-submit')) { + setTimeout(function() { + ams.form.resetAfterSubmit(form); + }, 250); + } }, error: function(request, status, error, form) { + form.trigger('myams.form.submit-error', [request, status, error]); if (target) { ams.executeFunctionByName(data.amsFormSubmitError || 'MyAMS.form.finalizeSubmitOnError', form, target); } @@ -359,6 +367,7 @@ iframe: true, iframeTarget: iframe, success: function(result, status, request, form) { + form.trigger('myams.form.after-submit', [result, status, request]); var modal = $(form).parents('.modal-dialog'); if (modal.exists()) { ams.dialog && ams.dialog.close(form); @@ -389,8 +398,9 @@ ams.form.resetAfterSubmit(form); }, success: function(result, status, request, form) { - var callback; - var button = form.data('ams-submit-button'); + form.trigger('myams.form.after-submit', [result, status, request]); + var callback, + button = form.data('ams-submit-button'); if (button) { callback = button.data('ams-form-submit-callback'); } @@ -480,15 +490,18 @@ * @param form: the submitted form */ resetAfterSubmit: function(form) { - if (form.is(':visible')) { - var button = form.data('ams-submit-button'); - if (button) { - button.button('reset'); + if (form.data('submitted')) { + if (form.is(':visible')) { + var button = form.data('ams-submit-button'); + if (button) { + button.button('reset'); + } + ams.form.finalizeSubmitFooter.call(form); } - ams.form.finalizeSubmitFooter.call(form); + form.data('submitted', false); + form.removeData('ams-submit-button'); + form.trigger('myams.form.after-reset'); } - form.data('submitted', false); - form.removeData('ams-submit-button'); }, /** diff -r de3ef58c6be8 -r 644d0f6f6503 src/pyams_skin/resources/js/myams-form.min.js --- a/src/pyams_skin/resources/js/myams-form.min.js Wed Oct 16 19:34:20 2019 +0200 +++ b/src/pyams_skin/resources/js/myams-form.min.js Fri Nov 08 10:51:09 2019 +0100 @@ -1,1 +1,1 @@ -!function(e,a){var t=a.MyAMS;t.form={init:function(a){e("FORM",a).each(function(){var a=e(this);e('INPUT.select2[type="hidden"]',a).each(function(){var a=e(this);a.data("ams-select2-input-value",a.val())})});(t.warnOnFormChange?e('FORM[data-ams-warn-on-change!="false"]',a):e('FORM[data-ams-warn-on-change="true"]',a)).each(function(){var a=e(this);e('INPUT[type="text"], INPUT[type="checkbox"], INPUT[type="radio"], SELECT, TEXTAREA, [data-ams-changed-event]',a).each(function(){var a=e(this);if(!0!==a.data("ams-ignore-change")){var r=a.data("ams-changed-event")||"change";a.on(r,function(){t.form.setChanged(e(this).parents("FORM"))})}}),a.on("reset",function(){t.form.resetChanged(e(this))})})},setFocus:function(a){var t=e("[data-ams-focus-target]",a).first();t.exists()||(t=e("input, select",a).first()),t.exists()&&(t.hasClass("select2-input")&&(t=t.parents(".select2")),t.hasClass("select2")?setTimeout(function(){t.select2("focus"),!0===t.data("ams-focus-open")&&t.select2("open")},100):t.focus())},checkBeforeUnload:function(){if(e('FORM[data-ams-form-changed="true"]').exists())return t.i18n.FORM_CHANGED_WARNING},confirmChangedForm:function(r,s,i){"function"==typeof r&&(s=r,r=void 0),e('FORM[data-ams-form-changed="true"]',r).exists()?i?a.confirm(t.i18n.FORM_CHANGED_WARNING,t.i18n.WARNING)?s.call(r):i.call(r):t.skin&&t.skin.bigBox({title:t.i18n.WARNING,content:'  '+t.i18n.FORM_CHANGED_WARNING,buttons:t.i18n.BTN_OK_CANCEL},function(e){e===t.i18n.BTN_OK&&s.call(r)}):s.call(r)},setChanged:function(e){e.attr("data-ams-form-changed",!0)},resetChanged:function(a){void 0!==a&&e(a).removeAttr("data-ams-form-changed")},submit:function(r,s,i){if(!(r=e(r)).exists())return!1;if("object"==typeof s&&(i=s,s=void 0),r.data("submitted"))return r.data("ams-form-hide-submitted")||t.skin&&t.skin.messageBox("warning",{title:t.i18n.WAIT,content:t.i18n.FORM_SUBMITTED,icon:"fa fa-save shake animated",timeout:r.data("ams-form-alert-timeout")||5e3}),!1;if(t.form&&!t.form._checkSubmitValidators(r))return!1;e(".alert-danger, SPAN.state-error",r).not(".persistent").remove(),e(".state-error",r).removeClassPrefix("state-");var n=e(r.data("ams-submit-button"));return n&&!n.data("ams-form-hide-loading")&&(n.data("ams-progress-content",n.html()),n.button("loading")),t.ajax&&t.ajax.check(e.fn.ajaxSubmit,t.baseURL+"ext/jquery-form-3.49"+t.devext+".js",function(){function n(r,n){var o,m,l,u,c,f,d,g,b,h=r.data(),v=h.amsFormOptions;if(i&&(c=i.formDataInitCallback),c?delete i.formDataInitCallback:c=h.amsFormDataInitCallback,c){var p={};if(u=t.executeFunctionByName(c,r,p),p.veto)return(o=r.data("ams-submit-button"))&&o.button("reset"),t.form.finalizeSubmitFooter.call(r),!1}else u=h.amsFormData||{};(o=e(r.data("ams-submit-button")))&&o.exists()?l=(m=o.data()).amsFormSubmitTarget:m={};var x,C=s||m.amsFormHandler||h.amsFormHandler||"";if(C.startsWith(window.location.protocol))x=C;else{var S=m.amsFormAction||r.attr("action").replace(/#/,"");x=S.startsWith(window.location.protocol)?S:t.ajax&&t.ajax.getAddr()+S,x+=C}f=m.amsProgressHandler||h.amsProgressHandler||"",d=m.amsProgressInterval||h.amsProgressInterval||1e3,g=m.amsProgressCallback||h.amsProgressCallback,b=m.amsProgressEndCallback||h.amsProgressEndCallback;var F=null;i&&i.initSubmitTarget?t.executeFunctionByName(i.initSubmitTarget,r):h.amsFormInitSubmitTarget?(F=e(l||h.amsFormSubmitTarget||"#content"),t.executeFunctionByName(h.amsFormInitSubmit||"MyAMS.form.initSubmit",r,F)):h.amsFormHideSubmitFooter||t.executeFunctionByName(h.amsFormInitSubmit||"MyAMS.form.initSubmitFooter",r),i&&(u=e.extend({},u,i.form_data));var R;f?u.progress_id=t.generateUUID():(R=void 0!==n.uuid)&&(x.indexOf("X-Progress-ID")<0&&(x+="?X-Progress-ID="+n.uuid),delete n.uuid);var y={url:x,type:"post",cache:!1,data:u,dataType:h.amsFormDatatype,beforeSerialize:function(){void 0!==a.tinyMCE&&a.tinyMCE.triggerSave()},beforeSubmit:function(e,a){a.data("submitted",!0)},error:function(e,a,r,s){F&&t.executeFunctionByName(h.amsFormSubmitError||"MyAMS.form.finalizeSubmitOnError",s,F),t.form.resetAfterSubmit(s)},iframe:R},k=i&&i.downloadTarget||h.amsFormDownloadTarget;if(k){var N=e('iframe[name="'+k+'"]');N.exists()||(N=e("").hide().attr("name",k).appendTo(e("body"))),y=e.extend({},y,{iframe:!0,iframeTarget:N,success:function(a,r,s,i){if(e(i).parents(".modal-dialog").exists())t.dialog&&t.dialog.close(i);else{var n,o=i.data("ams-submit-button");o&&(n=o.data("ams-form-submit-callback")),n||(n=t.getFunctionByName(h.amsFormSubmitCallback)||t.form._submitCallback);try{n.call(i,a,r,s,i)}finally{t.form.resetAfterSubmit(i),t.form.resetChanged(i)}}}})}else y=e.extend({},y,{error:function(e,a,r,s){F&&t.executeFunctionByName(h.amsFormSubmitError||"MyAMS.form.finalizeSubmitOnError",s,F),t.form.resetAfterSubmit(s)},success:function(e,a,r,s){var i,n=s.data("ams-submit-button");n&&(i=n.data("ams-form-submit-callback")),i||(i=t.getFunctionByName(h.amsFormSubmitCallback)||t.form._submitCallback);try{i.call(s,e,a,r,s)}finally{t.form.resetAfterSubmit(s),t.form.resetChanged(s)}},iframe:R});var O=e.extend({},y,n,v,i);if(f&&function(e,a){function s(){clearTimeout(n),t.form.resetAfterSubmit(r,o),o.html(o.data("ams-progress-content")),t.executeFunctionByName(b,r,o),t.form.resetChanged(r)}function i(){t.ajax&&t.ajax.post(e,{progress_id:a},{error:s},t.getFunctionByName(g)||function(e,a){if("success"===a)if("running"===e.status){if(e.message)o.text(e.message);else{var r=o.data("ams-progress-text")||t.i18n.PROGRESS;e.current?r+=": "+e.current+"/ "+(e.length||100):r+="...",o.text(r)}n=setTimeout(i,d)}else"finished"===e.status&&s();else s()})}var n;o.button("loading"),n=setTimeout(i,d)}(f,u.progress_id),e(r).ajaxSubmit(O),k){var E=e(r).parents(".modal-dialog"),A=E.exists()&&o.exists()&&o.data("ams-keep-modal");E.exists()&&!0!==A?t.dialog&&t.dialog.close(r):f||setTimeout(function(){t.form.resetAfterSubmit(r,o),t.form.resetChanged(r)},o.data("ams-form-reset-timeout")||2e3)}}if(!0!==r.data("ams-form-ignore-uploads")&&e('INPUT[type="file"]',r).length>0){t.ajax&&t.ajax.check(e.progressBar,t.baseURL+"ext/jquery-progressbar"+t.devext+".js");var o=e.extend({},{uuid:e.progressBar.submit(r)});n(r,o)}else n(r,{})}),!1},initSubmit:function(a,t){var r=e(this),s='';t||(t=r.data("ams-form-submit-message")),t&&(s+=""+t+""),e(a).html('
'+s+"
"),e(a).parents(".hidden").removeClass("hidden")},resetAfterSubmit:function(e){if(e.is(":visible")){var a=e.data("ams-submit-button");a&&a.button("reset"),t.form.finalizeSubmitFooter.call(e)}e.data("submitted",!1),e.removeData("ams-submit-button")},finalizeSubmitOnError:function(a){e("i",a).removeClass("fa-spin").removeClass("fa-gear").addClass("fa-ambulance")},initSubmitFooter:function(a){var t=e(this),r='';a||(a=e(this).data("ams-form-submit-message")),a&&(r+=''+a+"");var s=e("footer",t);e("button",s).hide(),s.append('
'+r+"
")},finalizeSubmitFooter:function(){var a=e(this),t=e("footer",a);t&&(e(".row",t).remove(),e("button",t).show())},_submitCallback:function(a,r,s,i){var n;i.is(":visible")&&(t.form.finalizeSubmitFooter.call(i),(n=i.data("ams-submit-button"))&&n.button("reset"));var o,m=i.data();if(m.amsFormDatatype)o=m.amsFormDatatype;else{var l=t.ajax&&t.ajax.getResponse(s);l&&(o=l.contentType,a=l.data)}var u;switch(u=e(n?n.data("ams-form-submit-target")||m.amsFormSubmitTarget||"#content":m.amsFormSubmitTarget||"#content"),o){case"json":t.ajax&&t.ajax.handleJSON(a,i,u);break;case"script":case"xml":break;case"html":case"text":default:t.form.resetChanged(i),n&&!0!==n.data("ams-keep-modal")&&t.dialog&&t.dialog.close(i),u.exists()||(u=e("body")),u.parents(".hidden").removeClass("hidden"),e(".alert",u.parents(".alerts-container")).remove(),u.css({opacity:"0.0"}).html(a).delay(50).animate({opacity:"1.0"},300),t.initContent&&t.initContent(u),t.form.setFocus(u)}var c=s.getResponseHeader("X-AMS-Callback");if(c){var f=s.getResponseHeader("X-AMS-Callback-Options");t.executeFunctionByName(c,i,void 0===f?{}:JSON.parse(f),s)}},_getSubmitValidators:function(a){var t=[],r=a.data("ams-form-validator");return r&&t.push([a,r]),e("[data-ams-form-validator]",a).each(function(){var a=e(this);t.push([a,a.data("ams-form-validator")])}),t},_checkSubmitValidators:function(e){var a=t.form._getSubmitValidators(e);if(!a.length)return!0;for(var r=[],s=!0,i=0;i0&&(r=r.concat(s))}if(r.length>0){var u=1===r.length?t.i18n.ERROR_OCCURED:t.i18n.ERRORS_OCCURED;return t.skin&&t.skin.alert(e,"danger",u,r),!1}return s},showErrors:function(a,r){var s;if("string"==typeof r)t.skin&&t.skin.alert(a,"error",t.i18n.ERROR_OCCURED,r);else if(r instanceof Array)s=1===r.length?t.i18n.ERROR_OCCURED:t.i18n.ERRORS_OCCURED,t.skin&&t.skin.alert(a,"error",s,r);else{e(".state-error",a).removeClass("state-error"),s=r.error_header||(r.widgets&&r.widgets.length>1?t.i18n.ERRORS_OCCURED:t.i18n.ERROR_OCCURED);var i,n=[];if(r.messages)for(i=0;i"+o.header+"
"+o.message):n.push(o.message||o)}if(r.widgets)for(i=0;i'+m.message+""):m.label&&n.push(m.label+" : "+m.message);var u=l.parents(".tab-pane").index()+1;if(u>0){var c=e(".nav-tabs",e(l).parents(".tabforms"));e("li:nth-child("+u+")",c).removeClassPrefix("state-").addClass("state-error"),e("li.state-error:first a",a).click()}}t.skin&&t.skin.alert(e(".form-group:first",a),r.error_level||"error",s,n,r.error_message)}}}}(jQuery,this); +!function(e,t){var a=t.MyAMS;a.form={init:function(t){e("FORM",t).each((function(){var t=e(this);e('INPUT.select2[type="hidden"]',t).each((function(){var t=e(this);t.data("ams-select2-input-value",t.val())}))})),(a.warnOnFormChange?e('FORM[data-ams-warn-on-change!="false"]',t):e('FORM[data-ams-warn-on-change="true"]',t)).each((function(){var t=e(this);e('INPUT[type="text"], INPUT[type="checkbox"], INPUT[type="radio"], SELECT, TEXTAREA, [data-ams-changed-event]',t).each((function(){var t=e(this);if(!0!==t.data("ams-ignore-change")){var r=t.data("ams-changed-event")||"change";t.on(r,(function(){a.form.setChanged(e(this).parents("FORM"))}))}})),t.on("reset",(function(){a.form.resetChanged(e(this))}))}))},setFocus:function(t){var a=e("[data-ams-focus-target]",t).first();a.exists()||(a=e("input, select",t).first()),a.exists()&&(a.hasClass("select2-input")&&(a=a.parents(".select2")),a.hasClass("select2")?setTimeout((function(){a.select2("focus"),!0===a.data("ams-focus-open")&&a.select2("open")}),100):a.focus())},checkBeforeUnload:function(){if(e('FORM[data-ams-form-changed="true"]').exists())return a.i18n.FORM_CHANGED_WARNING},confirmChangedForm:function(r,s,i){"function"==typeof r&&(s=r,r=void 0),e('FORM[data-ams-form-changed="true"]',r).exists()?i?t.confirm(a.i18n.FORM_CHANGED_WARNING,a.i18n.WARNING)?s.call(r):i.call(r):a.skin&&a.skin.bigBox({title:a.i18n.WARNING,content:'  '+a.i18n.FORM_CHANGED_WARNING,buttons:a.i18n.BTN_OK_CANCEL},(function(e){e===a.i18n.BTN_OK&&s.call(r)})):s.call(r)},setChanged:function(e){e.attr("data-ams-form-changed",!0)},resetChanged:function(t){void 0!==t&&e(t).removeAttr("data-ams-form-changed")},submit:function(r,s,i){if(!(r=e(r)).exists())return!1;if("object"==typeof s&&(i=s,s=void 0),r.data("submitted"))return r.data("ams-form-hide-submitted")||a.skin&&a.skin.messageBox("warning",{title:a.i18n.WAIT,content:a.i18n.FORM_SUBMITTED,icon:"fa fa-save shake animated",timeout:r.data("ams-form-alert-timeout")||5e3}),!1;if(a.form&&!a.form._checkSubmitValidators(r))return!1;e(".alert-danger, SPAN.state-error",r).not(".persistent").remove(),e(".state-error",r).removeClassPrefix("state-");var n=e(r.data("ams-submit-button"));return n&&!n.data("ams-form-hide-loading")&&(n.data("ams-progress-content",n.html()),n.button("loading")),a.ajax&&a.ajax.check(e.fn.ajaxSubmit,a.baseURL+"ext/jquery-form-3.49"+a.devext+".js",(function(){function n(r,n){var o,m,u,f,l,c,d,g,b,h,v=r.data(),p=v.amsFormOptions;if(i&&(l=i.formDataInitCallback),l?delete i.formDataInitCallback:l=v.amsFormDataInitCallback,l){var x={};if(f=a.executeFunctionByName(l,r,x),x.veto)return(o=r.data("ams-submit-button"))&&o.button("reset"),a.form.finalizeSubmitFooter.call(r),!1}else f=v.amsFormData||{};(o=e(r.data("ams-submit-button")))&&o.exists()?u=(m=o.data()).amsFormSubmitTarget:m={};var C=s||m.amsFormHandler||v.amsFormHandler||"";if(C.startsWith(window.location.protocol))h=C;else{var S=m.amsFormAction||r.attr("action").replace(/#/,"");h=S.startsWith(window.location.protocol)?S:a.ajax&&a.ajax.getAddr()+S,h+=C}c=m.amsProgressHandler||v.amsProgressHandler||"",d=m.amsProgressInterval||v.amsProgressInterval||1e3,g=m.amsProgressCallback||v.amsProgressCallback,b=m.amsProgressEndCallback||v.amsProgressEndCallback;var F,y=null;i&&i.initSubmitTarget?a.executeFunctionByName(i.initSubmitTarget,r):v.amsFormInitSubmitTarget?(y=e(u||v.amsFormSubmitTarget||"#content"),a.executeFunctionByName(v.amsFormInitSubmit||"MyAMS.form.initSubmit",r,y)):v.amsFormHideSubmitFooter||a.executeFunctionByName(v.amsFormInitSubmit||"MyAMS.form.initSubmitFooter",r),i&&(f=e.extend({},f,i.form_data)),c?f.progress_id=a.generateUUID():(F=void 0!==n.uuid)&&(h.indexOf("X-Progress-ID")<0&&(h+="?X-Progress-ID="+n.uuid),delete n.uuid);var R={url:h,type:"post",cache:!1,data:f,dataType:v.amsFormDatatype,beforeSerialize:function(){r.trigger("myams.form.before-serialize"),void 0!==t.tinyMCE&&t.tinyMCE.triggerSave()},beforeSubmit:function(e,t){t.trigger("myams.form.before-submit",[e]),t.data("submitted",!0),t.data("ams-form-reset-before-submit")&&setTimeout((function(){a.form.resetAfterSubmit(t)}),250)},error:function(e,t,r,s){s.trigger("myams.form.submit-error",[e,t,r]),y&&a.executeFunctionByName(v.amsFormSubmitError||"MyAMS.form.finalizeSubmitOnError",s,y),a.form.resetAfterSubmit(s)},iframe:F},k=i&&i.downloadTarget||v.amsFormDownloadTarget;if(k){var N=e('iframe[name="'+k+'"]');N.exists()||(N=e("").hide().attr("name",k).appendTo(e("body"))),R=e.extend({},R,{iframe:!0,iframeTarget:N,success:function(t,r,s,i){if(i.trigger("myams.form.after-submit",[t,r,s]),e(i).parents(".modal-dialog").exists())a.dialog&&a.dialog.close(i);else{var n,o=i.data("ams-submit-button");o&&(n=o.data("ams-form-submit-callback")),n||(n=a.getFunctionByName(v.amsFormSubmitCallback)||a.form._submitCallback);try{n.call(i,t,r,s,i)}finally{a.form.resetAfterSubmit(i),a.form.resetChanged(i)}}}})}else R=e.extend({},R,{error:function(e,t,r,s){y&&a.executeFunctionByName(v.amsFormSubmitError||"MyAMS.form.finalizeSubmitOnError",s,y),a.form.resetAfterSubmit(s)},success:function(e,t,r,s){s.trigger("myams.form.after-submit",[e,t,r]);var i,n=s.data("ams-submit-button");n&&(i=n.data("ams-form-submit-callback")),i||(i=a.getFunctionByName(v.amsFormSubmitCallback)||a.form._submitCallback);try{i.call(s,e,t,r,s)}finally{a.form.resetAfterSubmit(s),a.form.resetChanged(s)}},iframe:F});var O=e.extend({},R,n,p,i);if(c&&function(e,t){var s;function i(){clearTimeout(s),a.form.resetAfterSubmit(r,o),o.html(o.data("ams-progress-content")),a.executeFunctionByName(b,r,o),a.form.resetChanged(r)}o.button("loading"),s=setTimeout((function r(){a.ajax&&a.ajax.post(e,{progress_id:t},{error:i},a.getFunctionByName(g)||function(e,t){if("success"===t)if("running"===e.status){if(e.message)o.text(e.message);else{var n=o.data("ams-progress-text")||a.i18n.PROGRESS;e.current?n+=": "+e.current+"/ "+(e.length||100):n+="...",o.text(n)}s=setTimeout(r,d)}else"finished"===e.status&&i();else i()})}),d)}(c,f.progress_id),e(r).ajaxSubmit(O),k){var E=e(r).parents(".modal-dialog"),A=E.exists()&&o.exists()&&o.data("ams-keep-modal");E.exists()&&!0!==A?a.dialog&&a.dialog.close(r):c||setTimeout((function(){a.form.resetAfterSubmit(r,o),a.form.resetChanged(r)}),o.data("ams-form-reset-timeout")||2e3)}}if(!0!==r.data("ams-form-ignore-uploads")&&e('INPUT[type="file"]',r).length>0){a.ajax&&a.ajax.check(e.progressBar,a.baseURL+"ext/jquery-progressbar"+a.devext+".js");var o=e.extend({},{uuid:e.progressBar.submit(r)});n(r,o)}else n(r,{})})),!1},initSubmit:function(t,a){var r=e(this),s='';a||(a=r.data("ams-form-submit-message")),a&&(s+=""+a+""),e(t).html('
'+s+"
"),e(t).parents(".hidden").removeClass("hidden")},resetAfterSubmit:function(e){if(e.data("submitted")){if(e.is(":visible")){var t=e.data("ams-submit-button");t&&t.button("reset"),a.form.finalizeSubmitFooter.call(e)}e.data("submitted",!1),e.removeData("ams-submit-button"),e.trigger("myams.form.after-reset")}},finalizeSubmitOnError:function(t){e("i",t).removeClass("fa-spin").removeClass("fa-gear").addClass("fa-ambulance")},initSubmitFooter:function(t){var a=e(this),r='';t||(t=e(this).data("ams-form-submit-message")),t&&(r+=''+t+"");var s=e("footer",a);e("button",s).hide(),s.append('
'+r+"
")},finalizeSubmitFooter:function(){var t=e(this),a=e("footer",t);a&&(e(".row",a).remove(),e("button",a).show())},_submitCallback:function(t,r,s,i){var n;i.is(":visible")&&(a.form.finalizeSubmitFooter.call(i),(n=i.data("ams-submit-button"))&&n.button("reset"));var o,m,u=i.data();if(u.amsFormDatatype)o=u.amsFormDatatype;else{var f=a.ajax&&a.ajax.getResponse(s);f&&(o=f.contentType,t=f.data)}switch(m=e(n?n.data("ams-form-submit-target")||u.amsFormSubmitTarget||"#content":u.amsFormSubmitTarget||"#content"),o){case"json":a.ajax&&a.ajax.handleJSON(t,i,m);break;case"script":case"xml":break;case"html":case"text":default:a.form.resetChanged(i),n&&!0!==n.data("ams-keep-modal")&&a.dialog&&a.dialog.close(i),m.exists()||(m=e("body")),m.parents(".hidden").removeClass("hidden"),e(".alert",m.parents(".alerts-container")).remove(),m.css({opacity:"0.0"}).html(t).delay(50).animate({opacity:"1.0"},300),a.initContent&&a.initContent(m),a.form.setFocus(m)}var l=s.getResponseHeader("X-AMS-Callback");if(l){var c=s.getResponseHeader("X-AMS-Callback-Options");a.executeFunctionByName(l,i,void 0===c?{}:JSON.parse(c),s)}},_getSubmitValidators:function(t){var a=[],r=t.data("ams-form-validator");return r&&a.push([t,r]),e("[data-ams-form-validator]",t).each((function(){var t=e(this);a.push([t,t.data("ams-form-validator")])})),a},_checkSubmitValidators:function(e){var t=a.form._getSubmitValidators(e);if(!t.length)return!0;for(var r=[],s=!0,i=0;i0&&(r=r.concat(s))}if(r.length>0){var f=1===r.length?a.i18n.ERROR_OCCURED:a.i18n.ERRORS_OCCURED;return a.skin&&a.skin.alert(e,"danger",f,r),!1}return s},showErrors:function(t,r){var s;if("string"==typeof r)a.skin&&a.skin.alert(t,"error",a.i18n.ERROR_OCCURED,r);else if(r instanceof Array)s=1===r.length?a.i18n.ERROR_OCCURED:a.i18n.ERRORS_OCCURED,a.skin&&a.skin.alert(t,"error",s,r);else{e(".state-error",t).removeClass("state-error"),s=r.error_header||(r.widgets&&r.widgets.length>1?a.i18n.ERRORS_OCCURED:a.i18n.ERROR_OCCURED);var i,n=[];if(r.messages)for(i=0;i"+o.header+"
"+o.message):n.push(o.message||o)}if(r.widgets)for(i=0;i'+m.message+""):m.label&&n.push(m.label+" : "+m.message);var f=u.parents(".tab-pane").index()+1;if(f>0){var l=e(".nav-tabs",e(u).parents(".tabforms"));e("li:nth-child("+f+")",l).removeClassPrefix("state-").addClass("state-error"),e("li.state-error:first a",t).click()}}a.skin&&a.skin.alert(e(".form-group:first",t),r.error_level||"error",s,n,r.error_message)}}}}(jQuery,this); diff -r de3ef58c6be8 -r 644d0f6f6503 src/pyams_skin/resources/js/myams-plugins-loader.min.js --- a/src/pyams_skin/resources/js/myams-plugins-loader.min.js Wed Oct 16 19:34:20 2019 +0200 +++ b/src/pyams_skin/resources/js/myams-plugins-loader.min.js Fri Nov 08 10:51:09 2019 +0100 @@ -1,1 +1,1 @@ -!function(d,a){"use strict";var f=a.MyAMS;f.plugins={enabled:{},init:function(c){f.plugins.initData(c);var n=[];d("[data-ams-plugins-disabled]",c).each(function(){for(var a=d(this).data("ams-plugins-disabled").split(/\s+/),e=0;e=0)){var g=n.plugins.enabled[u];if(g)switch(typeof g){case"function":g(e);break;default:for(var d=0;d=0)console&&console.warn&&console.warn("Plugin "+e+" is already registered!");else if("object"==typeof a){var s=a.src;s?n.ajax&&n.ajax.check(a.callback,s,(function(s){s&&(n.plugins.enabled[e]=n.getFunctionByName(a.callback),a.css&&n.getCSS(a.css,e+"_css"),t&&n.executeFunctionByName(t))})):(n.plugins.enabled[e]=n.getFunctionByName(a.callback),a.css&&n.getCSS(a.css,e+"_css"),t&&n.executeFunctionByName(t))}else"function"==typeof a&&(n.plugins.enabled[e]=a,t&&n.executeFunctionByName(t))}},n.plugins.i18n={widgets:{},validate:{},datatables:{},fancybox:{ERROR:"Can't load requested content.",RETRY:"Please check URL or try again later.",CLOSE:"Close",NEXT:"Next",PREVIOUS:"Previous"},dndupload:{FILES_SELECTED:"{count} files selected",CHOOSE_FILE:"Select file(s)",ADD_INFO:"to add them to current folder,",DRAG_FILE:"or drag and drop them here!",UPLOAD:"Upload",UPLOADING:"Uploading…",DONE:"Done!",UPLOAD_MORE:"Upload more?",ERROR:"Error!",TRY_AGAIN:"Try again?"}}}(jQuery,this); diff -r de3ef58c6be8 -r 644d0f6f6503 src/pyams_skin/resources/js/myams-require.min.js --- a/src/pyams_skin/resources/js/myams-require.min.js Wed Oct 16 19:34:20 2019 +0200 +++ b/src/pyams_skin/resources/js/myams-require.min.js Fri Nov 08 10:51:09 2019 +0100 @@ -1,1 +1,1 @@ -"use strict";!function(e,t){var n=t.console;String.prototype.startsWith=function(e){var t=this.length,n=e.length;return!(t0},void 0===e.scrollbarWidth&&(e.scrollbarWidth=function(){var t=e('
').appendTo("body"),n=t.children(),r=n.innerWidth()-n.height(99).innerWidth();return t.remove(),r}),e.fn.extend({exists:function(){return e(this).length>0},objectOrParentWithClass:function(e){return this.hasClass(e)?this:this.parents("."+e)},listattr:function(t){var n=[];return this.each(function(){n.push(e(this).attr(t))}),n},style:function(e,t,n){if(void 0!==this.get(0)){var r=this.get(0).style;return void 0!==e?void 0!==t?(n=void 0!==n?n:"",r.setProperty(e,t,n),this):r.getPropertyValue(e):r}},removeClassPrefix:function(t){return this.each(function(n,r){var a=r.className.split(" ").map(function(e){return e.startsWith(t)?"":e});r.className=e.trim(a.join(" "))}),this}}),void 0===t.MyAMS&&(t.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,safeMethods:["GET","HEAD","OPTIONS","TRACE"],csrfCookieName:"csrf_token",csrfHeaderName:"X-CSRF-Token",enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var r=t.MyAMS,a=r;r.baseURL=function(){var t=e('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]').attr("src");return a.devmode=t.indexOf(".min.js")<0,a.devext=a.devmode?"":".min",t.substring(0,t.lastIndexOf("/")+1)}(),r.log=function(){n&&n.debug&&n.debug(this,arguments)},r.getQueryVar=function(e,t){if(e.indexOf("?")<0)return!1;e.endsWith("&")||(e+="&");var n=new RegExp(".*?[&\\?]"+t+"=(.*?)&.*"),r=e.replace(n,"$1");return r!==e&&r},r.rgb2hex=function(t){return"#"+e.map(t.match(/\b(\d+)\b/g),function(e){return("0"+parseInt(e).toString(16)).slice(-2)}).join("")},r.generateId=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+e()+e()},r.generateUUID=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})},r.getObject=function(e,t){if(e){if("string"!=typeof e)return e;var n=e.split(".");t=void 0===t||null===t?window:t;for(var r=0;r").attr("data-ams-id",n).text('@import "'+a.getSource(t)+'";'),r)var c=setInterval(function(){try{s[0].sheet.cssRules;r.call(window,!0,i),clearInterval(c)}catch(e){}},10);s.appendTo(o)}else r&&r.call(window,!1,i)},r.initHandlers=function(t){e(t).on("click","[data-ams-click-handler]",function(t){var n=e(this),r=n.data("ams-disabled-handlers");if(!0!==r&&"click"!==r&&"all"!==r){var i=n.data();if(i.amsClickHandler){!0!==i.amsStopPropagation&&!0!==i.amsClickStopPropagation||t.stopPropagation(),!0!==i.amsClickKeepDefault&&t.preventDefault();for(var o=i.amsClickHandler.split(/\s+/),s=0;s0?e.when.apply(e,i).then(function(){a()}):a()}}(jQuery,this); +"use strict";!function(e,t){var n=t.console;String.prototype.startsWith=function(e){var t=this.length,n=e.length;return!(t0},void 0===e.scrollbarWidth&&(e.scrollbarWidth=function(){var t=e('
').appendTo("body"),n=t.children(),r=n.innerWidth()-n.height(99).innerWidth();return t.remove(),r}),e.fn.extend({exists:function(){return e(this).length>0},objectOrParentWithClass:function(e){return this.hasClass(e)?this:this.parents("."+e)},listattr:function(t){var n=[];return this.each((function(){n.push(e(this).attr(t))})),n},style:function(e,t,n){if(void 0!==this.get(0)){var r=this.get(0).style;return void 0!==e?void 0!==t?(n=void 0!==n?n:"",r.setProperty(e,t,n),this):r.getPropertyValue(e):r}},removeClassPrefix:function(t){return this.each((function(n,r){var a=r.className.split(" ").map((function(e){return e.startsWith(t)?"":e}));r.className=e.trim(a.join(" "))})),this}}),void 0===t.MyAMS&&(t.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,safeMethods:["GET","HEAD","OPTIONS","TRACE"],csrfCookieName:"csrf_token",csrfHeaderName:"X-CSRF-Token",enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var r,a=t.MyAMS,i=a;a.baseURL=(r=e('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]').attr("src"),i.devmode=r.indexOf(".min.js")<0,i.devext=i.devmode?"":".min",r.substring(0,r.lastIndexOf("/")+1)),a.log=function(){n&&n.debug&&n.debug(this,arguments)},a.getQueryVar=function(e,t){if(e.indexOf("?")<0)return!1;e.endsWith("&")||(e+="&");var n=new RegExp(".*?[&\\?]"+t+"=(.*?)&.*"),r=e.replace(n,"$1");return r!==e&&r},a.rgb2hex=function(t){return"#"+e.map(t.match(/\b(\d+)\b/g),(function(e){return("0"+parseInt(e).toString(16)).slice(-2)})).join("")},a.generateId=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+e()+e()},a.generateUUID=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)}))},a.getObject=function(e,t){if(e){if("string"!=typeof e)return e;var n=e.split(".");t=null==t?window:t;for(var r=0;r").attr("data-ams-id",n).text('@import "'+i.getSource(t)+'";'),r)var c=setInterval((function(){try{s[0].sheet.cssRules;r.call(window,!0,a),clearInterval(c)}catch(e){}}),10);s.appendTo(o)}else r&&r.call(window,!1,a)},a.initHandlers=function(t){e(t).on("click","[data-ams-click-handler]",(function(t){var n=e(this),r=n.data("ams-disabled-handlers");if(!0!==r&&"click"!==r&&"all"!==r){var a=n.data();if(a.amsClickHandler){!0!==a.amsStopPropagation&&!0!==a.amsClickStopPropagation||t.stopPropagation(),!0!==a.amsClickKeepDefault&&t.preventDefault();for(var o=a.amsClickHandler.split(/\s+/),s=0;s0?e.when.apply(e,i).then((function(){a()})):a()}}(jQuery,this); diff -r de3ef58c6be8 -r 644d0f6f6503 src/pyams_skin/resources/js/myams.js --- a/src/pyams_skin/resources/js/myams.js Wed Oct 16 19:34:20 2019 +0200 +++ b/src/pyams_skin/resources/js/myams.js Fri Nov 08 10:51:09 2019 +0100 @@ -2096,14 +2096,22 @@ data: formData, dataType: data.amsFormDatatype, beforeSerialize: function(/*form, options*/) { + form.trigger('myams.form.before-serialize'); if (typeof (globals.tinyMCE) !== 'undefined') { globals.tinyMCE.triggerSave(); } }, beforeSubmit: function(data, form /*, options*/) { + form.trigger('myams.form.before-submit', [data]); form.data('submitted', true); + if (form.data('ams-form-reset-before-submit')) { + setTimeout(function() { + ams.form.resetAfterSubmit(form); + }, 250); + } }, error: function(request, status, error, form) { + form.trigger('myams.form.submit-error', [request, status, error]); if (target) { ams.executeFunctionByName(data.amsFormSubmitError || 'MyAMS.form.finalizeSubmitOnError', form, target); } @@ -2125,6 +2133,7 @@ iframe: true, iframeTarget: iframe, success: function(result, status, request, form) { + form.trigger('myams.form.after-submit', [result, status, request]); var modal = $(form).parents('.modal-dialog'); if (modal.exists()) { ams.dialog && ams.dialog.close(form); @@ -2155,8 +2164,9 @@ ams.form.resetAfterSubmit(form); }, success: function(result, status, request, form) { - var callback; - var button = form.data('ams-submit-button'); + form.trigger('myams.form.after-submit', [result, status, request]); + var callback, + button = form.data('ams-submit-button'); if (button) { callback = button.data('ams-form-submit-callback'); } @@ -2246,15 +2256,18 @@ * @param form: the submitted form */ resetAfterSubmit: function(form) { - if (form.is(':visible')) { - var button = form.data('ams-submit-button'); - if (button) { - button.button('reset'); + if (form.data('submitted')) { + if (form.is(':visible')) { + var button = form.data('ams-submit-button'); + if (button) { + button.button('reset'); + } + ams.form.finalizeSubmitFooter.call(form); } - ams.form.finalizeSubmitFooter.call(form); - } - form.data('submitted', false); - form.removeData('ams-submit-button'); + form.data('submitted', false); + form.removeData('ams-submit-button'); + form.trigger('myams.form.after-reset'); + } }, /** diff -r de3ef58c6be8 -r 644d0f6f6503 src/pyams_skin/resources/js/myams.min.js --- a/src/pyams_skin/resources/js/myams.min.js Wed Oct 16 19:34:20 2019 +0200 +++ b/src/pyams_skin/resources/js/myams.min.js Fri Nov 08 10:51:09 2019 +0100 @@ -1,1 +1,1 @@ -"use strict";!function(e,a){var t=a.console;String.prototype.startsWith=function(e){var a=this.length,t=e.length;return!(a0},void 0===e.scrollbarWidth&&(e.scrollbarWidth=function(){var a=e('
').appendTo("body"),t=a.children(),n=t.innerWidth()-t.height(99).innerWidth();return a.remove(),n}),e.fn.extend({exists:function(){return e(this).length>0},objectOrParentWithClass:function(e){return this.hasClass(e)?this:this.parents("."+e)},listattr:function(a){var t=[];return this.each(function(){t.push(e(this).attr(a))}),t},style:function(e,a,t){if(void 0!==this.get(0)){var n=this.get(0).style;return void 0!==e?void 0!==a?(t=void 0!==t?t:"",n.setProperty(e,a,t),this):n.getPropertyValue(e):n}},removeClassPrefix:function(a){return this.each(function(t,n){var s=n.className.split(" ").map(function(e){return e.startsWith(a)?"":e});n.className=e.trim(s.join(" "))}),this}}),void 0===a.MyAMS&&(a.MyAMS={devmode:!0,devext:"",lang:"en",throttleDelay:350,menuSpeed:235,navbarHeight:49,ajaxNav:!0,safeMethods:["GET","HEAD","OPTIONS","TRACE"],csrfCookieName:"csrf_token",csrfHeaderName:"X-CSRF-Token",enableWidgets:!0,enableMobile:!1,enableFastclick:!1,warnOnFormChange:!1,ismobile:/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())});var n=a.MyAMS,s=n;n.baseURL=function(){var a=e('script[src*="/myams.js"], script[src*="/myams.min.js"], script[src*="/myams-core.js"], script[src*="/myams-core.min.js"], script[src*="/myams-require.js"], script[src*="/myams-require.min.js"]').attr("src");return s.devmode=a.indexOf(".min.js")<0,s.devext=s.devmode?"":".min",a.substring(0,a.lastIndexOf("/")+1)}(),n.log=function(){t&&t.debug&&t.debug(this,arguments)},n.getQueryVar=function(e,a){if(e.indexOf("?")<0)return!1;e.endsWith("&")||(e+="&");var t=new RegExp(".*?[&\\?]"+a+"=(.*?)&.*"),n=e.replace(t,"$1");return n!==e&&n},n.rgb2hex=function(a){return"#"+e.map(a.match(/\b(\d+)\b/g),function(e){return("0"+parseInt(e).toString(16)).slice(-2)}).join("")},n.generateId=function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return e()+e()+e()+e()},n.generateUUID=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===a?t:3&t|8).toString(16)})},n.getObject=function(e,a){if(e){if("string"!=typeof e)return e;var t=e.split(".");a=void 0===a||null===a?window:a;for(var n=0;n").attr("data-ams-id",t).text('@import "'+s.getSource(a)+'";'),n)var c=setInterval(function(){try{o[0].sheet.cssRules;n.call(window,!0,i),clearInterval(c)}catch(e){}},10);o.appendTo(r)}else n&&n.call(window,!1,i)},n.initHandlers=function(a){e(a).on("click","[data-ams-click-handler]",function(a){var t=e(this),n=t.data("ams-disabled-handlers");if(!0!==n&&"click"!==n&&"all"!==n){var i=t.data();if(i.amsClickHandler){!0!==i.amsStopPropagation&&!0!==i.amsClickStopPropagation||a.stopPropagation(),!0!==i.amsClickKeepDefault&&a.preventDefault();for(var r=i.amsClickHandler.split(/\s+/),o=0;o127&&n<2048?(a+=String.fromCharCode(n>>6|192),a+=String.fromCharCode(63&n|128)):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128),a+=String.fromCharCode(63&n|128))}return a},decode:function(e){for(var a="",t=0,n=0,s=0,i=0;t191&&n<224?(s=e.charCodeAt(t+1),a+=String.fromCharCode((31&n)<<6|63&s),t+=2):(s=e.charCodeAt(t+1),i=e.charCodeAt(t+2),a+=String.fromCharCode((15&n)<<12|(63&s)<<6|63&i),t+=3);return a}},function(e,a){var t=a.MyAMS;e.fn.extend({contextMenu:function(a){function n(t,n,s){var i=e(window)[n](),r=e(a.menuSelector)[n](),o=t;return t+r>i&&r',openedSign:''},a),n=e(this);n.find("LI").each(function(){var a=e(this);if(a.find("UL").size()>0){a.find("A:first").append(""+t.closedSign+"");var n=a.find("A:first");"#"===n.attr("href")&&n.click(function(){return!1})}}),n.find("LI.active").each(function(){var a=e(this).parents("UL"),n=a.parent("LI");a.slideDown(t.speed),n.find("b:first").html(t.openedSign),n.addClass("open")}),n.find("LI A").on("click",function(){var a=e(this);if(!a.hasClass("active")){var s=a.attr("href").replace(/^#/,""),i=a.parent().find("UL");if(t.accordion){var r=a.parent().parents("UL"),o=n.find("UL:visible");o.each(function(a){var n=!0;if(r.each(function(e){if(r[e]===o[a])return n=!1,!1}),n&&i!==o[a]){var c=e(o[a]);!s&&c.hasClass("active")||c.slideUp(t.speed,function(){e(this).parent("LI").removeClass("open").find("B:first").delay(t.speed).html(t.closedSign)})}})}var c=a.parent().find("UL:first");s||!c.is(":visible")||c.hasClass("active")?c.slideDown(t.speed,function(){a.parent("LI").addClass("open").find("B:first").delay(t.speed).html(t.openedSign)}):c.slideUp(t.speed,function(){a.parent("LI").removeClass("open").find("B:first").delay(t.speed).html(t.closedSign)})}})}})}(jQuery,this),function(e,a){a.MyAMS.event={stop:function(e){e||(e=window.event),e&&"string"!=typeof e&&(e.stopPropagation?(e.stopPropagation(),e.preventDefault()):(e.cancelBubble=!0,e.returnValue=!1))}}}(jQuery,this),function(e,a){var t=a.MyAMS;t.browser={getInternetExplorerVersion:function(){var e=-1;if("Microsoft Internet Explorer"===navigator.appName){var a=navigator.userAgent;null!==new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(a)&&(e=parseFloat(RegExp.$1))}return e},checkVersion:function(){var e="You're not using Windows Internet Explorer.",t=this.getInternetExplorerVersion();t>-1&&(e=t>=8?"You're using a recent copy of Windows Internet Explorer.":"You should upgrade your copy of Windows Internet Explorer."),a.alert&&a.alert(e)},isIE8orlower:function(){var e="0",a=this.getInternetExplorerVersion();return a>-1&&(e=a>=9?0:1),e},copyToClipboard:function(n){function s(n){var s=!1;if(window.clipboardData&&window.clipboardData.setData)s=clipboardData.setData("Text",n);else if(document.queryCommandSupported&&document.queryCommandSupported("copy")){var i=e("