|
|
@ -1,6 +1,5 @@ |
|
|
var abp = abp || {}; |
|
|
var abp = abp || {}; |
|
|
(function ($) { |
|
|
(function ($) { |
|
|
|
|
|
|
|
|
if (!$) { |
|
|
if (!$) { |
|
|
throw "abp/jquery library requires the jquery library included to the page!"; |
|
|
throw "abp/jquery library requires the jquery library included to the page!"; |
|
|
} |
|
|
} |
|
|
@ -8,7 +7,7 @@ var abp = abp || {}; |
|
|
// ABP CORE OVERRIDES /////////////////////////////////////////////////////
|
|
|
// ABP CORE OVERRIDES /////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
abp.message._showMessage = function (message, title) { |
|
|
abp.message._showMessage = function (message, title) { |
|
|
alert((title || '') + ' ' + message); |
|
|
alert((title || "") + " " + message); |
|
|
|
|
|
|
|
|
return $.Deferred(function ($dfd) { |
|
|
return $.Deferred(function ($dfd) { |
|
|
$dfd.resolve(); |
|
|
$dfd.resolve(); |
|
|
@ -16,7 +15,7 @@ var abp = abp || {}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
abp.message.confirm = function (message, titleOrCallback, callback) { |
|
|
abp.message.confirm = function (message, titleOrCallback, callback) { |
|
|
if (titleOrCallback && !(typeof titleOrCallback == 'string')) { |
|
|
if (titleOrCallback && !(typeof titleOrCallback == "string")) { |
|
|
callback = titleOrCallback; |
|
|
callback = titleOrCallback; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -43,36 +42,30 @@ var abp = abp || {}; |
|
|
abp.dom = abp.dom || {}; |
|
|
abp.dom = abp.dom || {}; |
|
|
|
|
|
|
|
|
abp.dom.onNodeAdded = function (callback) { |
|
|
abp.dom.onNodeAdded = function (callback) { |
|
|
abp.event.on('abp.dom.nodeAdded', callback); |
|
|
abp.event.on("abp.dom.nodeAdded", callback); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
abp.dom.onNodeRemoved = function (callback) { |
|
|
abp.dom.onNodeRemoved = function (callback) { |
|
|
abp.event.on('abp.dom.nodeRemoved', callback); |
|
|
abp.event.on("abp.dom.nodeRemoved", callback); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
var mutationObserverCallback = function (mutationsList) { |
|
|
var mutationObserverCallback = function (mutationsList) { |
|
|
for (var i = 0; i < mutationsList.length; i++) { |
|
|
for (var i = 0; i < mutationsList.length; i++) { |
|
|
var mutation = mutationsList[i]; |
|
|
var mutation = mutationsList[i]; |
|
|
if (mutation.type === 'childList') { |
|
|
if (mutation.type === "childList") { |
|
|
if (mutation.addedNodes && mutation.removedNodes.length) { |
|
|
if (mutation.addedNodes && mutation.removedNodes.length) { |
|
|
for (var k = 0; k < mutation.removedNodes.length; k++) { |
|
|
for (var k = 0; k < mutation.removedNodes.length; k++) { |
|
|
abp.event.trigger( |
|
|
abp.event.trigger("abp.dom.nodeRemoved", { |
|
|
'abp.dom.nodeRemoved', |
|
|
$el: $(mutation.removedNodes[k]), |
|
|
{ |
|
|
}); |
|
|
$el: $(mutation.removedNodes[k]) |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (mutation.addedNodes && mutation.addedNodes.length) { |
|
|
if (mutation.addedNodes && mutation.addedNodes.length) { |
|
|
for (var j = 0; j < mutation.addedNodes.length; j++) { |
|
|
for (var j = 0; j < mutation.addedNodes.length; j++) { |
|
|
abp.event.trigger( |
|
|
abp.event.trigger("abp.dom.nodeAdded", { |
|
|
'abp.dom.nodeAdded', |
|
|
$el: $(mutation.addedNodes[j]), |
|
|
{ |
|
|
}); |
|
|
$el: $(mutation.addedNodes[j]) |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -80,13 +73,10 @@ var abp = abp || {}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
$(function () { |
|
|
$(function () { |
|
|
new MutationObserver(mutationObserverCallback).observe( |
|
|
new MutationObserver(mutationObserverCallback).observe($("body")[0], { |
|
|
$('body')[0], |
|
|
|
|
|
{ |
|
|
|
|
|
subtree: true, |
|
|
subtree: true, |
|
|
childList: true |
|
|
childList: true, |
|
|
} |
|
|
}); |
|
|
); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// AJAX ///////////////////////////////////////////////////////////////////
|
|
|
// AJAX ///////////////////////////////////////////////////////////////////
|
|
|
@ -105,12 +95,13 @@ var abp = abp || {}; |
|
|
.done(function (data, textStatus, jqXHR) { |
|
|
.done(function (data, textStatus, jqXHR) { |
|
|
$dfd.resolve(data); |
|
|
$dfd.resolve(data); |
|
|
userOptions.success && userOptions.success(data); |
|
|
userOptions.success && userOptions.success(data); |
|
|
}).fail(function (jqXHR) { |
|
|
}) |
|
|
if(jqXHR.statusText === 'abort') { |
|
|
.fail(function (jqXHR) { |
|
|
|
|
|
if (jqXHR.statusText === "abort") { |
|
|
//ajax request is abort, ignore error handle.
|
|
|
//ajax request is abort, ignore error handle.
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if (jqXHR.getResponseHeader('_AbpErrorFormat') === 'true') { |
|
|
if (jqXHR.getResponseHeader("_AbpErrorFormat") === "true") { |
|
|
abp.ajax.handleAbpErrorResponse(jqXHR, userOptions, $dfd); |
|
|
abp.ajax.handleAbpErrorResponse(jqXHR, userOptions, $dfd); |
|
|
} else { |
|
|
} else { |
|
|
abp.ajax.handleNonAbpErrorResponse(jqXHR, userOptions, $dfd); |
|
|
abp.ajax.handleNonAbpErrorResponse(jqXHR, userOptions, $dfd); |
|
|
@ -118,39 +109,40 @@ var abp = abp || {}; |
|
|
}); |
|
|
}); |
|
|
}).promise(); |
|
|
}).promise(); |
|
|
|
|
|
|
|
|
promise['jqXHR'] = xhr; |
|
|
promise["jqXHR"] = xhr; |
|
|
|
|
|
|
|
|
return promise; |
|
|
return promise; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
$.extend(abp.ajax, { |
|
|
$.extend(abp.ajax, { |
|
|
defaultOpts: { |
|
|
defaultOpts: { |
|
|
dataType: 'json', |
|
|
dataType: "json", |
|
|
type: 'POST', |
|
|
type: "POST", |
|
|
contentType: 'application/json', |
|
|
contentType: "application/json", |
|
|
headers: { |
|
|
headers: { |
|
|
'X-Requested-With': 'XMLHttpRequest' |
|
|
"X-Requested-With": "XMLHttpRequest", |
|
|
} |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
defaultError: { |
|
|
defaultError: { |
|
|
message: 'An error has occurred!', |
|
|
message: "An error has occurred!", |
|
|
details: 'Error detail not sent by server.' |
|
|
details: "Error detail not sent by server.", |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
defaultError401: { |
|
|
defaultError401: { |
|
|
message: 'You are not authenticated!', |
|
|
message: "You are not authenticated!", |
|
|
details: 'You should be authenticated (sign in) in order to perform this operation.' |
|
|
details: |
|
|
|
|
|
"You should be authenticated (sign in) in order to perform this operation.", |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
defaultError403: { |
|
|
defaultError403: { |
|
|
message: 'You are not authorized!', |
|
|
message: "You are not authorized!", |
|
|
details: 'You are not allowed to perform this operation.' |
|
|
details: "You are not allowed to perform this operation.", |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
defaultError404: { |
|
|
defaultError404: { |
|
|
message: 'Resource not found!', |
|
|
message: "Resource not found!", |
|
|
details: 'The resource requested could not found on the server.' |
|
|
details: "The resource requested could not found on the server.", |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
logError: function (error) { |
|
|
logError: function (error) { |
|
|
@ -161,7 +153,9 @@ var abp = abp || {}; |
|
|
if (error.details) { |
|
|
if (error.details) { |
|
|
return abp.message.error(error.details, error.message); |
|
|
return abp.message.error(error.details, error.message); |
|
|
} else { |
|
|
} else { |
|
|
return abp.message.error(error.message || abp.ajax.defaultError.message); |
|
|
return abp.message.error( |
|
|
|
|
|
error.message || abp.ajax.defaultError.message |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -205,7 +199,9 @@ var abp = abp || {}; |
|
|
handleAbpErrorResponse: function (jqXHR, userOptions, $dfd) { |
|
|
handleAbpErrorResponse: function (jqXHR, userOptions, $dfd) { |
|
|
var messagePromise = null; |
|
|
var messagePromise = null; |
|
|
|
|
|
|
|
|
var responseJSON = jqXHR.responseJSON ? jqXHR.responseJSON : JSON.parse(jqXHR.responseText); |
|
|
var responseJSON = jqXHR.responseJSON |
|
|
|
|
|
? jqXHR.responseJSON |
|
|
|
|
|
: JSON.parse(jqXHR.responseText); |
|
|
|
|
|
|
|
|
if (userOptions.abpHandleError !== false) { |
|
|
if (userOptions.abpHandleError !== false) { |
|
|
messagePromise = abp.ajax.showError(responseJSON.error); |
|
|
messagePromise = abp.ajax.showError(responseJSON.error); |
|
|
@ -233,9 +229,11 @@ var abp = abp || {}; |
|
|
|
|
|
|
|
|
blockUI: function (options) { |
|
|
blockUI: function (options) { |
|
|
if (options.blockUI) { |
|
|
if (options.blockUI) { |
|
|
if (options.blockUI === true) { //block whole page
|
|
|
if (options.blockUI === true) { |
|
|
|
|
|
//block whole page
|
|
|
abp.ui.setBusy(); |
|
|
abp.ui.setBusy(); |
|
|
} else { //block an element
|
|
|
} else { |
|
|
|
|
|
//block an element
|
|
|
abp.ui.setBusy(options.blockUI); |
|
|
abp.ui.setBusy(options.blockUI); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -243,9 +241,11 @@ var abp = abp || {}; |
|
|
|
|
|
|
|
|
unblockUI: function (options) { |
|
|
unblockUI: function (options) { |
|
|
if (options.blockUI) { |
|
|
if (options.blockUI) { |
|
|
if (options.blockUI === true) { //unblock whole page
|
|
|
if (options.blockUI === true) { |
|
|
|
|
|
//unblock whole page
|
|
|
abp.ui.clearBusy(); |
|
|
abp.ui.clearBusy(); |
|
|
} else { //unblock an element
|
|
|
} else { |
|
|
|
|
|
//unblock an element
|
|
|
abp.ui.clearBusy(options.blockUI); |
|
|
abp.ui.clearBusy(options.blockUI); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -257,36 +257,42 @@ var abp = abp || {}; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!settings.headers || settings.headers[abp.security.antiForgery.tokenHeaderName] === undefined) { |
|
|
if ( |
|
|
request.setRequestHeader(abp.security.antiForgery.tokenHeaderName, token); |
|
|
!settings.headers || |
|
|
} |
|
|
settings.headers[abp.security.antiForgery.tokenHeaderName] === undefined |
|
|
|
|
|
) { |
|
|
|
|
|
request.setRequestHeader( |
|
|
|
|
|
abp.security.antiForgery.tokenHeaderName, |
|
|
|
|
|
token |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
$(document).ajaxSend(function (event, request, settings) { |
|
|
$(document).ajaxSend(function (event, request, settings) { |
|
|
return abp.ajax.ajaxSendHandler(event, request, settings); |
|
|
return abp.ajax.ajaxSendHandler(event, request, settings); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
abp.event.on('abp.configurationInitialized', function () { |
|
|
abp.event.on("abp.configurationInitialized", function () { |
|
|
var l = abp.localization.getResource('AbpUi'); |
|
|
var l = abp.localization.getResource("AbpUi"); |
|
|
|
|
|
|
|
|
abp.ajax.defaultError.message = l('DefaultErrorMessage'); |
|
|
abp.ajax.defaultError.message = l("DefaultErrorMessage"); |
|
|
abp.ajax.defaultError.details = l('DefaultErrorMessageDetail'); |
|
|
abp.ajax.defaultError.details = l("DefaultErrorMessageDetail"); |
|
|
abp.ajax.defaultError401.message = l('DefaultErrorMessage401'); |
|
|
abp.ajax.defaultError401.message = l("DefaultErrorMessage401"); |
|
|
abp.ajax.defaultError401.details = l('DefaultErrorMessage401Detail'); |
|
|
abp.ajax.defaultError401.details = l("DefaultErrorMessage401Detail"); |
|
|
abp.ajax.defaultError403.message = l('DefaultErrorMessage403'); |
|
|
abp.ajax.defaultError403.message = l("DefaultErrorMessage403"); |
|
|
abp.ajax.defaultError403.details = l('DefaultErrorMessage403Detail'); |
|
|
abp.ajax.defaultError403.details = l("DefaultErrorMessage403Detail"); |
|
|
abp.ajax.defaultError404.message = l('DefaultErrorMessage404'); |
|
|
abp.ajax.defaultError404.message = l("DefaultErrorMessage404"); |
|
|
abp.ajax.defaultError404.details = l('DefaultErrorMessage404Detail'); |
|
|
abp.ajax.defaultError404.details = l("DefaultErrorMessage404Detail"); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// RESOURCE LOADER ////////////////////////////////////////////////////////
|
|
|
// RESOURCE LOADER ////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
/* UrlStates enum */ |
|
|
/* UrlStates enum */ |
|
|
var UrlStates = { |
|
|
var UrlStates = { |
|
|
LOADING: 'LOADING', |
|
|
LOADING: "LOADING", |
|
|
LOADED: 'LOADED', |
|
|
LOADED: "LOADED", |
|
|
FAILED: 'FAILED' |
|
|
FAILED: "FAILED", |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/* UrlInfo class */ |
|
|
/* UrlInfo class */ |
|
|
@ -333,7 +339,6 @@ var abp = abp || {}; |
|
|
/* ResourceLoader API */ |
|
|
/* ResourceLoader API */ |
|
|
|
|
|
|
|
|
abp.ResourceLoader = (function () { |
|
|
abp.ResourceLoader = (function () { |
|
|
|
|
|
|
|
|
var _urlInfos = {}; |
|
|
var _urlInfos = {}; |
|
|
|
|
|
|
|
|
function getCacheKey(url) { |
|
|
function getCacheKey(url) { |
|
|
@ -341,20 +346,23 @@ var abp = abp || {}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function appendTimeToUrl(url) { |
|
|
function appendTimeToUrl(url) { |
|
|
|
|
|
if (url.indexOf("?") < 0) { |
|
|
if (url.indexOf('?') < 0) { |
|
|
url += "?"; |
|
|
url += '?'; |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
url += '&'; |
|
|
url += "&"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
url += '_=' + new Date().getTime(); |
|
|
url += "_=" + new Date().getTime(); |
|
|
|
|
|
|
|
|
return url; |
|
|
return url; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var _loadFromUrl = function (url, loadCallback, failCallback, serverLoader) { |
|
|
var _loadFromUrl = function ( |
|
|
|
|
|
url, |
|
|
|
|
|
loadCallback, |
|
|
|
|
|
failCallback, |
|
|
|
|
|
serverLoader |
|
|
|
|
|
) { |
|
|
var cacheKey = getCacheKey(url); |
|
|
var cacheKey = getCacheKey(url); |
|
|
|
|
|
|
|
|
var urlInfo = _urlInfos[cacheKey]; |
|
|
var urlInfo = _urlInfos[cacheKey]; |
|
|
@ -374,7 +382,7 @@ var abp = abp || {}; |
|
|
_loadFromUrl(url, loadCallback, failCallback, function (urlInfo) { |
|
|
_loadFromUrl(url, loadCallback, failCallback, function (urlInfo) { |
|
|
$.get({ |
|
|
$.get({ |
|
|
url: url, |
|
|
url: url, |
|
|
dataType: 'text' |
|
|
dataType: "text", |
|
|
}) |
|
|
}) |
|
|
.done(function (script) { |
|
|
.done(function (script) { |
|
|
$.globalEval(script); |
|
|
$.globalEval(script); |
|
|
@ -388,19 +396,17 @@ var abp = abp || {}; |
|
|
|
|
|
|
|
|
var _loadStyle = function (url) { |
|
|
var _loadStyle = function (url) { |
|
|
_loadFromUrl(url, undefined, undefined, function (urlInfo) { |
|
|
_loadFromUrl(url, undefined, undefined, function (urlInfo) { |
|
|
|
|
|
$("<link/>", { |
|
|
$('<link/>', { |
|
|
rel: "stylesheet", |
|
|
rel: 'stylesheet', |
|
|
type: "text/css", |
|
|
type: 'text/css', |
|
|
href: appendTimeToUrl(url), |
|
|
href: appendTimeToUrl(url) |
|
|
}).appendTo("head"); |
|
|
}).appendTo('head'); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
loadScript: _loadScript, |
|
|
loadScript: _loadScript, |
|
|
loadStyle: _loadStyle |
|
|
loadStyle: _loadStyle, |
|
|
} |
|
|
}; |
|
|
})(); |
|
|
})(); |
|
|
|
|
|
|
|
|
})(jQuery); |
|
|
})(jQuery); |