diff --git a/src/assets/ModalRemote.js b/src/assets/ModalRemote.js index 0b7b616..0c593a9 100644 --- a/src/assets/ModalRemote.js +++ b/src/assets/ModalRemote.js @@ -162,13 +162,13 @@ function ModalRemote(modalId) { * @param {string} method The method of request * @param {object}data of request */ - this.doRemote = function (url, method, data) { + this.doRemote = function (url, method, data, isAsync = false) { var instance = this; $.ajax({ url: url, method: method, data: data, - async: false, + async: isAsync, beforeSend: function () { beforeRemoteRequest.call(instance); }, @@ -294,7 +294,7 @@ function ModalRemote(modalId) { * @param {string} dataRequestMethod POST or GET * @param {number[]} selectedIds */ - this.confirmModal = function (title, message, okLabel, cancelLabel, size, dataUrl, dataRequestMethod, selectedIds) { + this.confirmModal = function (title, message, okLabel, cancelLabel, size, dataUrl, dataRequestMethod, selectedIds, isAsync) { this.show(); this.setSize(size); @@ -329,7 +329,8 @@ function ModalRemote(modalId) { instance.doRemote( dataUrl, dataRequestMethod, - data + data, + isAsync ); } ); @@ -378,13 +379,15 @@ function ModalRemote(modalId) { $(elm).hasAttr('data-modal-size') ? $(elm).attr('data-modal-size') : 'normal', $(elm).hasAttr('href') ? $(elm).attr('href') : $(elm).attr('data-url'), $(elm).hasAttr('data-request-method') ? $(elm).attr('data-request-method') : 'GET', - bulkData + bulkData, + $(elm).hasAttr('data-request-async') ? $(elm).attr('data-request-async') !== 'false' : null ) } else { this.doRemote( $(elm).hasAttr('href') ? $(elm).attr('href') : $(elm).attr('data-url'), $(elm).hasAttr('data-request-method') ? $(elm).attr('data-request-method') : 'GET', - bulkData + bulkData, + $(elm).hasAttr('data-request-async') ? $(elm).attr('data-request-async') !== 'false' : null ); } } diff --git a/src/assets/ModalRemote.min.js b/src/assets/ModalRemote.min.js old mode 100644 new mode 100755 index 1acddb2..a279b0c --- a/src/assets/ModalRemote.min.js +++ b/src/assets/ModalRemote.min.js @@ -1 +1 @@ -function ModalRemote(t){function o(){this.show(),this.displayLoading()}function e(t){this.setTitle(t.status+t.statusText),this.setContent(t.responseText),this.addFooterButton("Close","button","btn btn-default",function(t,o){this.hide()})}function i(t){return void 0!==t.forceReload&&t.forceReload&&("true"==t.forceReload?$.pjax.reload({container:"#crud-datatable-pjax"}):$.pjax.reload({container:t.forceReload})),void 0!==t.forceClose&&t.forceClose?void this.hide():(void 0!==t.size&&this.setSize(t.size),void 0!==t.title&&this.setTitle(t.title),void 0!==t.content&&this.setContent(t.content),void 0!==t.footer&&this.setFooter(t.footer),void(void 0!==$(this.content).find("form")[0]&&this.setupFormSubmit($(this.content).find("form")[0],$(this.footer).find('[type="submit"]')[0])))}this.defaults={okLabel:"OK",executeLabel:"Execute",cancelLabel:"Cancel",loadingTitle:"Loading"},this.modal=$(t),this.dialog=$(t).find(".modal-dialog"),this.header=$(t).find(".modal-header"),this.content=$(t).find(".modal-body"),this.footer=$(t).find(".modal-footer"),this.loadingContent='
',this.show=function(){this.clear(),$(this.modal).modal("show")},this.hide=function(){$(this.modal).modal("hide")},this.toggle=function(){$(this.modal).modal("toggle")},this.clear=function(){$(this.modal).find(".modal-title").remove(),$(this.content).html(""),$(this.footer).html("")},this.setSize=function(t){$(this.dialog).removeClass("modal-lg"),$(this.dialog).removeClass("modal-sm"),"large"==t?$(this.dialog).addClass("modal-lg"):"small"==t?$(this.dialog).addClass("modal-sm"):"normal"!==t&&console.warn("Undefined size "+t)},this.setHeader=function(t){$(this.header).html(t)},this.setContent=function(t){$(this.content).html(t)},this.setFooter=function(t){$(this.footer).html(t)},this.setTitle=function(t){$(this.header).find("h4.modal-title").remove(),$(this.header).append('")},this.hidenCloseButton=function(){$(this.header).find("button.close").hide()},this.showCloseButton=function(){$(this.header).find("button.close").show()},this.displayLoading=function(){this.setContent(this.loadingContent),this.setTitle(this.defaults.loadingTitle)},this.addFooterButton=function(t,o,e,i){buttonElm=document.createElement("button"),buttonElm.setAttribute("type",null===o?"button":o),buttonElm.setAttribute("class",null===e?"btn btn-primary":e),buttonElm.innerHTML=t;var a=this;$(this.footer).append(buttonElm),null!==i&&$(buttonElm).click(function(t){i.call(a,this,t)})},this.doRemote=function(t,a,n){var s=this;$.ajax({url:t,method:a,data:n,async:!1,beforeSend:function(){o.call(s)},error:function(t){e.call(s,t)},success:function(t){i.call(s,t)},contentType:!1,cache:!1,processData:!1})},this.setupFormSubmit=function(t,o){if(void 0===o)console.warn("Modal has form but does not have a submit button");else{var e=this;$(o).click(function(o){var i;i=window.FormData?new FormData($(t)[0]):$(t).serializeArray(),e.doRemote($(t).attr("action"),$(t).hasAttr("method")?$(t).attr("method"):"GET",i)})}},this.confirmModal=function(t,o,e,i,a,n,s,d){this.show(),this.setSize(a),void 0!==t&&this.setTitle(t),this.setContent('
'+o);var l=this;this.addFooterButton(void 0===e?this.defaults.okLabel:e,"submit","btn btn-primary",function(t){var o;window.FormData?(o=new FormData($("#ModalRemoteConfirmForm")[0]),"undefined"!=typeof d&&d&&o.append("pks",d.join())):(o=$("#ModalRemoteConfirmForm"),"undefined"!=typeof d&&d&&(o.pks=d),o=o.serializeArray()),l.doRemote(n,s,o)}),this.addFooterButton(void 0===i?this.defaults.cancelLabel:i,"button","btn btn-default pull-left",function(t){this.hide()})},this.open=function(t,o){$(t).hasAttr("data-confirm-title")||$(t).hasAttr("data-confirm-message")?this.confirmModal($(t).attr("data-confirm-title"),$(t).attr("data-confirm-message"),$(t).attr("data-confirm-ok"),$(t).attr("data-confirm-cancel"),$(t).hasAttr("data-modal-size")?$(t).attr("data-modal-size"):"normal",$(t).hasAttr("href")?$(t).attr("href"):$(t).attr("data-url"),$(t).hasAttr("data-request-method")?$(t).attr("data-request-method"):"GET",o):this.doRemote($(t).hasAttr("href")?$(t).attr("href"):$(t).attr("data-url"),$(t).hasAttr("data-request-method")?$(t).attr("data-request-method"):"GET",o)}}!function(t){t.fn.hasAttr=function(t){return void 0!==this.attr(t)}}(jQuery); +(function(a){a.fn.hasAttr=function(b){return this.attr(b)!==void 0}})(jQuery);function ModalRemote(a){function b(){this.show(),this.displayLoading()}function c(f){this.setTitle(f.status+f.statusText),this.setContent(f.responseText),this.addFooterButton("Close","button","btn btn-default",function(){this.hide()})}function d(f){return void 0!==f.forceReload&&f.forceReload&&("true"==f.forceReload?$.pjax.reload({container:"#crud-datatable-pjax"}):$.pjax.reload({container:f.forceReload})),void 0!==f.forceClose&&f.forceClose?void this.hide():void(void 0!==f.size&&this.setSize(f.size),void 0!==f.title&&this.setTitle(f.title),void 0!==f.content&&this.setContent(f.content),void 0!==f.footer&&this.setFooter(f.footer),void 0!==$(this.content).find("form")[0]&&this.setupFormSubmit($(this.content).find("form")[0],$(this.footer).find("[type=\"submit\"]")[0]))}this.defaults={okLabel:"OK",executeLabel:"Execute",cancelLabel:"Cancel",loadingTitle:"Loading"},this.modal=$(a),this.dialog=$(a).find(".modal-dialog"),this.header=$(a).find(".modal-header"),this.content=$(a).find(".modal-body"),this.footer=$(a).find(".modal-footer"),this.loadingContent="
",this.show=function(){this.clear(),$(this.modal).modal("show")},this.hide=function(){$(this.modal).modal("hide")},this.toggle=function(){$(this.modal).modal("toggle")},this.clear=function(){$(this.modal).find(".modal-title").remove(),$(this.content).html(""),$(this.footer).html("")},this.setSize=function(f){$(this.dialog).removeClass("modal-lg"),$(this.dialog).removeClass("modal-sm"),"large"==f?$(this.dialog).addClass("modal-lg"):"small"==f?$(this.dialog).addClass("modal-sm"):"normal"!==f&&console.warn("Undefined size "+f)},this.setHeader=function(f){$(this.header).html(f)},this.setContent=function(f){$(this.content).html(f)},this.setFooter=function(f){$(this.footer).html(f)},this.setTitle=function(f){$(this.header).find("h4.modal-title").remove(),$(this.header).append("

"+f+"

")},this.hidenCloseButton=function(){$(this.header).find("button.close").hide()},this.showCloseButton=function(){$(this.header).find("button.close").show()},this.displayLoading=function(){this.setContent(this.loadingContent),this.setTitle(this.defaults.loadingTitle)},this.addFooterButton=function(f,g,h,i){buttonElm=document.createElement("button"),buttonElm.setAttribute("type",null===g?"button":g),buttonElm.setAttribute("class",null===h?"btn btn-primary":h),buttonElm.innerHTML=f;var j=this;$(this.footer).append(buttonElm),null!==i&&$(buttonElm).click(function(k){i.call(j,this,k)})},this.doRemote=function(f,g,h,i=!1){var j=this;$.ajax({url:f,method:g,data:h,async:i,beforeSend:function(){b.call(j)},error:function(k){c.call(j,k)},success:function(k){d.call(j,k)},contentType:!1,cache:!1,processData:!1})},this.setupFormSubmit=function(f,g){if(g===void 0)console.warn("Modal has form but does not have a submit button");else{var h=this;$(g).click(function(){var j;j=window.FormData?new FormData($(f)[0]):$(f).serializeArray(),h.doRemote($(f).attr("action"),$(f).hasAttr("method")?$(f).attr("method"):"GET",j)})}},this.confirmModal=function(f,g,h,i,j,k,l,m,n){this.show(),this.setSize(j),f!==void 0&&this.setTitle(f),this.setContent(""+g);var o=this;!1!==h&&this.addFooterButton(h===void 0?this.defaults.okLabel:h,"submit","btn btn-primary",function(){var q;window.FormData?(q=new FormData($("#ModalRemoteConfirmForm")[0]),"undefined"!=typeof m&&m&&q.append("pks",m.join())):(q=$("#ModalRemoteConfirmForm"),"undefined"!=typeof m&&m&&(q.pks=m),q=q.serializeArray()),o.doRemote(k,l,q,n)}),this.addFooterButton(i===void 0?this.defaults.cancelLabel:i,"button","btn btn-default pull-left",function(){this.hide()})},this.open=function(f,g){$(f).hasAttr("data-confirm-title")||$(f).hasAttr("data-confirm-message")?this.confirmModal($(f).attr("data-confirm-title"),$(f).attr("data-confirm-message"),!$(f).attr("data-confirm-alert")&&$(f).attr("data-confirm-ok"),$(f).attr("data-confirm-cancel"),$(f).hasAttr("data-modal-size")?$(f).attr("data-modal-size"):"normal",$(f).hasAttr("href")?$(f).attr("href"):$(f).attr("data-url"),$(f).hasAttr("data-request-method")?$(f).attr("data-request-method"):"GET",g,$(f).hasAttr("data-request-async")?"false"!==$(f).attr("data-request-async"):null):this.doRemote($(f).hasAttr("href")?$(f).attr("href"):$(f).attr("data-url"),$(f).hasAttr("data-request-method")?$(f).attr("data-request-method"):"GET",g,$(f).hasAttr("data-request-async")?"false"!==$(f).attr("data-request-async"):null)}} \ No newline at end of file