2018-10-24 14:24:16 +00:00
|
|
|
|
/** @namespace OCP */
|
2019-01-28 10:24:08 +00:00
|
|
|
|
var OCP = Object.assign({}, window.OCP);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @namespace OC
|
|
|
|
|
*/
|
|
|
|
|
Object.assign(window.OC, {
|
2014-05-26 16:43:26 +00:00
|
|
|
|
/* jshint camelcase: false */
|
2017-12-01 09:36:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* Capabilities
|
|
|
|
|
*
|
|
|
|
|
* @type array
|
|
|
|
|
*/
|
|
|
|
|
_capabilities: window.oc_capabilities || null,
|
|
|
|
|
|
2014-05-30 17:02:19 +00:00
|
|
|
|
theme: window.oc_defaults || {},
|
2014-05-19 13:44:19 +00:00
|
|
|
|
|
2017-02-13 15:51:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* Check if a user file is allowed to be handled.
|
|
|
|
|
* @param {string} file to check
|
|
|
|
|
*/
|
|
|
|
|
fileIsBlacklisted: function(file) {
|
2019-05-02 06:28:24 +00:00
|
|
|
|
return !!(file.match(OC.config.blacklist_files_regex));
|
2017-02-13 15:51:23 +00:00
|
|
|
|
},
|
|
|
|
|
|
2015-01-19 10:56:04 +00:00
|
|
|
|
/**
|
2016-11-24 15:05:05 +00:00
|
|
|
|
* Protocol that is used to access this Nextcloud instance
|
2015-01-19 10:56:04 +00:00
|
|
|
|
* @return {string} Used protocol
|
|
|
|
|
*/
|
|
|
|
|
getProtocol: function() {
|
|
|
|
|
return window.location.protocol.split(':')[0];
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-13 13:26:01 +00:00
|
|
|
|
/**
|
2016-11-24 15:05:05 +00:00
|
|
|
|
* Returns the host used to access this Nextcloud instance
|
2016-02-03 10:28:07 +00:00
|
|
|
|
* Host is sometimes the same as the hostname but now always.
|
2015-07-13 13:26:01 +00:00
|
|
|
|
*
|
2016-02-03 10:28:07 +00:00
|
|
|
|
* Examples:
|
|
|
|
|
* http://example.com => example.com
|
2016-04-04 08:57:17 +00:00
|
|
|
|
* https://example.com => example.com
|
2016-02-03 10:28:07 +00:00
|
|
|
|
* http://example.com:8080 => example.com:8080
|
|
|
|
|
*
|
|
|
|
|
* @return {string} host
|
2015-07-13 13:26:01 +00:00
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getHost: function() {
|
|
|
|
|
return window.location.host;
|
|
|
|
|
},
|
|
|
|
|
|
2016-02-03 10:28:07 +00:00
|
|
|
|
/**
|
2016-11-24 15:05:05 +00:00
|
|
|
|
* Returns the hostname used to access this Nextcloud instance
|
2016-02-03 10:28:07 +00:00
|
|
|
|
* The hostname is always stripped of the port
|
|
|
|
|
*
|
|
|
|
|
* @return {string} hostname
|
|
|
|
|
* @since 9.0
|
|
|
|
|
*/
|
|
|
|
|
getHostName: function() {
|
|
|
|
|
return window.location.hostname;
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-13 13:26:01 +00:00
|
|
|
|
/**
|
2016-11-24 15:05:05 +00:00
|
|
|
|
* Returns the port number used to access this Nextcloud instance
|
2015-07-13 13:26:01 +00:00
|
|
|
|
*
|
|
|
|
|
* @return {int} port number
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
getPort: function() {
|
|
|
|
|
return window.location.port;
|
|
|
|
|
},
|
|
|
|
|
|
2017-12-01 09:36:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the capabilities
|
|
|
|
|
*
|
|
|
|
|
* @return {array} capabilities
|
|
|
|
|
*
|
2018-02-15 10:06:51 +00:00
|
|
|
|
* @since 14.0
|
2017-12-01 09:36:13 +00:00
|
|
|
|
*/
|
|
|
|
|
getCapabilities: function() {
|
|
|
|
|
return OC._capabilities;
|
|
|
|
|
},
|
|
|
|
|
|
2011-08-06 21:18:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* get the absolute path to an image file
|
2014-10-07 10:02:58 +00:00
|
|
|
|
* if no extension is given for the image, it will automatically decide
|
2014-04-21 11:46:33 +00:00
|
|
|
|
* between .png and .svg based on what the browser supports
|
|
|
|
|
* @param {string} app the app id to which the image belongs
|
|
|
|
|
* @param {string} file the name of the image file
|
|
|
|
|
* @return {string}
|
2012-07-31 10:21:06 +00:00
|
|
|
|
*/
|
2011-07-25 20:30:55 +00:00
|
|
|
|
imagePath:function(app,file){
|
2016-06-23 10:15:16 +00:00
|
|
|
|
if(file.indexOf('.')==-1){//if no extension is given, use svg
|
|
|
|
|
file+='.svg';
|
2011-07-28 02:28:04 +00:00
|
|
|
|
}
|
2011-07-25 20:30:55 +00:00
|
|
|
|
return OC.filePath(app,'img',file);
|
|
|
|
|
},
|
2014-10-07 10:02:58 +00:00
|
|
|
|
|
2014-11-18 17:53:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* URI-Encodes a file path but keep the path slashes.
|
|
|
|
|
*
|
|
|
|
|
* @param path path
|
|
|
|
|
* @return encoded path
|
|
|
|
|
*/
|
|
|
|
|
encodePath: function(path) {
|
|
|
|
|
if (!path) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
var parts = path.split('/');
|
|
|
|
|
var result = [];
|
|
|
|
|
for (var i = 0; i < parts.length; i++) {
|
|
|
|
|
result.push(encodeURIComponent(parts[i]));
|
|
|
|
|
}
|
|
|
|
|
return result.join('/');
|
|
|
|
|
},
|
|
|
|
|
|
2014-11-18 11:13:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Loads translations for the given app asynchronously.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} app app name
|
|
|
|
|
* @param {Function} callback callback to call after loading
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
addTranslations: function(app, callback) {
|
|
|
|
|
return OC.L10N.load(app, callback);
|
|
|
|
|
},
|
|
|
|
|
|
2014-04-21 11:46:33 +00:00
|
|
|
|
/**
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* Returns the base name of the given path.
|
|
|
|
|
* For example for "/abc/somefile.txt" it will return "somefile.txt"
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path
|
|
|
|
|
* @return {String} base name
|
2014-04-21 11:46:33 +00:00
|
|
|
|
*/
|
2012-09-08 21:56:37 +00:00
|
|
|
|
basename: function(path) {
|
|
|
|
|
return path.replace(/\\/g,'/').replace( /.*\//, '' );
|
|
|
|
|
},
|
2014-10-07 10:02:58 +00:00
|
|
|
|
|
2014-04-21 11:46:33 +00:00
|
|
|
|
/**
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* Returns the dir name of the given path.
|
|
|
|
|
* For example for "/abc/somefile.txt" it will return "/abc"
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path
|
|
|
|
|
* @return {String} dir name
|
2014-04-21 11:46:33 +00:00
|
|
|
|
*/
|
2012-09-08 21:56:37 +00:00
|
|
|
|
dirname: function(path) {
|
2012-09-23 01:16:52 +00:00
|
|
|
|
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
|
2012-09-08 22:35:02 +00:00
|
|
|
|
},
|
2014-10-07 10:02:58 +00:00
|
|
|
|
|
2015-12-21 12:10:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns whether the given paths are the same, without
|
|
|
|
|
* leading, trailing or doubled slashes and also removing
|
|
|
|
|
* the dot sections.
|
|
|
|
|
*
|
|
|
|
|
* @param {String} path1 first path
|
|
|
|
|
* @param {String} path2 second path
|
|
|
|
|
* @return {bool} true if the paths are the same
|
|
|
|
|
*
|
|
|
|
|
* @since 9.0
|
|
|
|
|
*/
|
|
|
|
|
isSamePath: function(path1, path2) {
|
|
|
|
|
var filterDot = function(p) {
|
|
|
|
|
return p !== '.';
|
|
|
|
|
};
|
|
|
|
|
var pathSections1 = _.filter((path1 || '').split('/'), filterDot);
|
|
|
|
|
var pathSections2 = _.filter((path2 || '').split('/'), filterDot);
|
|
|
|
|
path1 = OC.joinPaths.apply(OC, pathSections1);
|
|
|
|
|
path2 = OC.joinPaths.apply(OC, pathSections2);
|
|
|
|
|
return path1 === path2;
|
|
|
|
|
},
|
|
|
|
|
|
2015-07-10 11:01:01 +00:00
|
|
|
|
/**
|
|
|
|
|
* Join path sections
|
|
|
|
|
*
|
|
|
|
|
* @param {...String} path sections
|
|
|
|
|
*
|
|
|
|
|
* @return {String} joined path, any leading or trailing slash
|
|
|
|
|
* will be kept
|
|
|
|
|
*
|
|
|
|
|
* @since 8.2
|
|
|
|
|
*/
|
|
|
|
|
joinPaths: function() {
|
|
|
|
|
if (arguments.length < 1) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
var path = '';
|
2015-07-13 08:57:52 +00:00
|
|
|
|
// convert to array
|
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
|
// discard empty arguments
|
|
|
|
|
args = _.filter(args, function(arg) {
|
|
|
|
|
return arg.length > 0;
|
|
|
|
|
});
|
|
|
|
|
if (args.length < 1) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var lastArg = args[args.length - 1];
|
|
|
|
|
var leadingSlash = args[0].charAt(0) === '/';
|
2015-07-10 11:01:01 +00:00
|
|
|
|
var trailingSlash = lastArg.charAt(lastArg.length - 1) === '/';
|
|
|
|
|
var sections = [];
|
|
|
|
|
var i;
|
2015-07-13 08:57:52 +00:00
|
|
|
|
for (i = 0; i < args.length; i++) {
|
|
|
|
|
sections = sections.concat(args[i].split('/'));
|
2015-07-10 11:01:01 +00:00
|
|
|
|
}
|
|
|
|
|
var first = !leadingSlash;
|
|
|
|
|
for (i = 0; i < sections.length; i++) {
|
|
|
|
|
if (sections[i] !== '') {
|
|
|
|
|
if (first) {
|
|
|
|
|
first = false;
|
|
|
|
|
} else {
|
|
|
|
|
path += '/';
|
|
|
|
|
}
|
|
|
|
|
path += sections[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (trailingSlash) {
|
|
|
|
|
// add it back
|
|
|
|
|
path += '/';
|
|
|
|
|
}
|
|
|
|
|
return path;
|
|
|
|
|
},
|
|
|
|
|
|
2013-08-17 11:07:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* Parses a URL query string into a JS map
|
2014-04-21 11:46:33 +00:00
|
|
|
|
* @param {string} queryString query string in the format param1=1234¶m2=abcde¶m3=xyz
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @return {Object.<string, string>} map containing key/values matching the URL parameters
|
2013-08-17 11:07:18 +00:00
|
|
|
|
*/
|
|
|
|
|
parseQueryString:function(queryString){
|
|
|
|
|
var parts,
|
2014-01-28 15:16:09 +00:00
|
|
|
|
pos,
|
2013-08-17 11:07:18 +00:00
|
|
|
|
components,
|
|
|
|
|
result = {},
|
|
|
|
|
key,
|
|
|
|
|
value;
|
|
|
|
|
if (!queryString){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-01-28 15:16:09 +00:00
|
|
|
|
pos = queryString.indexOf('?');
|
|
|
|
|
if (pos >= 0){
|
|
|
|
|
queryString = queryString.substr(pos + 1);
|
2013-08-17 11:07:18 +00:00
|
|
|
|
}
|
2014-01-28 15:16:09 +00:00
|
|
|
|
parts = queryString.replace(/\+/g, '%20').split('&');
|
2013-08-17 11:07:18 +00:00
|
|
|
|
for (var i = 0; i < parts.length; i++){
|
2014-01-28 15:16:09 +00:00
|
|
|
|
// split on first equal sign
|
2014-04-21 12:28:54 +00:00
|
|
|
|
var part = parts[i];
|
2014-01-28 15:16:09 +00:00
|
|
|
|
pos = part.indexOf('=');
|
|
|
|
|
if (pos >= 0) {
|
|
|
|
|
components = [
|
|
|
|
|
part.substr(0, pos),
|
|
|
|
|
part.substr(pos + 1)
|
2014-04-15 02:44:24 +00:00
|
|
|
|
];
|
2014-01-28 15:16:09 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// key only
|
|
|
|
|
components = [part];
|
|
|
|
|
}
|
2013-08-17 11:07:18 +00:00
|
|
|
|
if (!components.length){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
key = decodeURIComponent(components[0]);
|
|
|
|
|
if (!key){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2014-01-28 15:16:09 +00:00
|
|
|
|
// if equal sign was there, return string
|
|
|
|
|
if (components.length > 1) {
|
|
|
|
|
result[key] = decodeURIComponent(components[1]);
|
|
|
|
|
}
|
|
|
|
|
// no equal sign => null value
|
|
|
|
|
else {
|
|
|
|
|
result[key] = null;
|
|
|
|
|
}
|
2013-08-17 11:07:18 +00:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
},
|
2014-01-24 11:44:31 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Builds a URL query from a JS map.
|
2014-06-23 21:56:10 +00:00
|
|
|
|
* @param {Object.<string, string>} params map containing key/values matching the URL parameters
|
2014-04-21 11:46:33 +00:00
|
|
|
|
* @return {string} String containing a URL query (without question) mark
|
2014-01-24 11:44:31 +00:00
|
|
|
|
*/
|
|
|
|
|
buildQueryString: function(params) {
|
|
|
|
|
if (!params) {
|
2014-04-15 02:44:24 +00:00
|
|
|
|
return '';
|
2014-01-24 11:44:31 +00:00
|
|
|
|
}
|
2014-04-15 02:44:24 +00:00
|
|
|
|
return $.map(params, function(value, key) {
|
|
|
|
|
var s = encodeURIComponent(key);
|
2014-01-24 11:44:31 +00:00
|
|
|
|
if (value !== null && typeof(value) !== 'undefined') {
|
|
|
|
|
s += '=' + encodeURIComponent(value);
|
|
|
|
|
}
|
2014-04-15 02:44:24 +00:00
|
|
|
|
return s;
|
|
|
|
|
}).join('&');
|
2014-01-24 11:44:31 +00:00
|
|
|
|
},
|
|
|
|
|
|
2012-07-31 14:03:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Opens a popup with the setting for an app.
|
2014-04-21 11:46:33 +00:00
|
|
|
|
* @param {string} appid The ID of the app e.g. 'calendar', 'contacts' or 'files'.
|
|
|
|
|
* @param {boolean|string} loadJS If true 'js/settings.js' is loaded. If it's a string
|
2012-07-31 14:03:08 +00:00
|
|
|
|
* it will attempt to load a script by that name in the 'js' directory.
|
2014-04-21 11:46:33 +00:00
|
|
|
|
* @param {boolean} [cache] If true the javascript file won't be forced refreshed. Defaults to true.
|
|
|
|
|
* @param {string} [scriptName] The name of the PHP file to load. Defaults to 'settings.php' in
|
2012-07-31 14:03:08 +00:00
|
|
|
|
* the root of the app directory hierarchy.
|
|
|
|
|
*/
|
2012-07-31 12:17:28 +00:00
|
|
|
|
appSettings:function(args) {
|
|
|
|
|
if(typeof args === 'undefined' || typeof args.appid === 'undefined') {
|
2012-07-31 14:03:08 +00:00
|
|
|
|
throw { name: 'MissingParameter', message: 'The parameter appid is missing' };
|
2012-07-31 12:17:28 +00:00
|
|
|
|
}
|
2012-07-31 14:03:08 +00:00
|
|
|
|
var props = {scriptName:'settings.php', cache:true};
|
|
|
|
|
$.extend(props, args);
|
2012-07-31 10:21:06 +00:00
|
|
|
|
var settings = $('#appsettings');
|
2014-04-15 02:44:24 +00:00
|
|
|
|
if(settings.length === 0) {
|
2012-07-31 14:03:08 +00:00
|
|
|
|
throw { name: 'MissingDOMElement', message: 'There has be be an element with id "appsettings" for the popup to show.' };
|
|
|
|
|
}
|
2012-08-12 16:42:54 +00:00
|
|
|
|
var popup = $('#appsettings_popup');
|
2014-04-15 02:44:24 +00:00
|
|
|
|
if(popup.length === 0) {
|
2012-08-12 16:42:54 +00:00
|
|
|
|
$('body').prepend('<div class="popup hidden" id="appsettings_popup"></div>');
|
2013-02-09 16:20:08 +00:00
|
|
|
|
popup = $('#appsettings_popup');
|
2012-08-12 16:42:54 +00:00
|
|
|
|
popup.addClass(settings.hasClass('topright') ? 'topright' : 'bottomleft');
|
|
|
|
|
}
|
|
|
|
|
if(popup.is(':visible')) {
|
|
|
|
|
popup.hide().remove();
|
2012-07-31 10:21:06 +00:00
|
|
|
|
} else {
|
2012-08-12 16:42:54 +00:00
|
|
|
|
var arrowclass = settings.hasClass('topright') ? 'up' : 'left';
|
|
|
|
|
var jqxhr = $.get(OC.filePath(props.appid, '', props.scriptName), function(data) {
|
|
|
|
|
popup.html(data).ready(function() {
|
2016-06-23 11:39:28 +00:00
|
|
|
|
popup.prepend('<span class="arrow '+arrowclass+'"></span><h2>'+t('core', 'Settings')+'</h2><a class="close"></a>').show();
|
2012-08-12 16:42:54 +00:00
|
|
|
|
popup.find('.close').bind('click', function() {
|
|
|
|
|
popup.remove();
|
2012-09-05 20:17:33 +00:00
|
|
|
|
});
|
2012-08-12 16:42:54 +00:00
|
|
|
|
if(typeof props.loadJS !== 'undefined') {
|
|
|
|
|
var scriptname;
|
|
|
|
|
if(props.loadJS === true) {
|
|
|
|
|
scriptname = 'settings.js';
|
|
|
|
|
} else if(typeof props.loadJS === 'string') {
|
|
|
|
|
scriptname = props.loadJS;
|
|
|
|
|
} else {
|
|
|
|
|
throw { name: 'InvalidParameter', message: 'The "loadJS" parameter must be either boolean or a string.' };
|
2012-07-31 14:03:08 +00:00
|
|
|
|
}
|
2012-08-12 16:42:54 +00:00
|
|
|
|
if(props.cache) {
|
|
|
|
|
$.ajaxSetup({cache: true});
|
|
|
|
|
}
|
|
|
|
|
$.getScript(OC.filePath(props.appid, 'js', scriptname))
|
|
|
|
|
.fail(function(jqxhr, settings, e) {
|
|
|
|
|
throw e;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).show();
|
|
|
|
|
}, 'html');
|
2012-07-31 10:21:06 +00:00
|
|
|
|
}
|
2014-03-14 09:33:19 +00:00
|
|
|
|
},
|
|
|
|
|
|
2018-10-17 19:43:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the user's locale as a BCP 47 compliant language tag
|
|
|
|
|
*
|
|
|
|
|
* @return {String} locale string
|
|
|
|
|
*/
|
|
|
|
|
getCanonicalLocale: function() {
|
|
|
|
|
var locale = this.getLocale();
|
|
|
|
|
return typeof locale === 'string' ? locale.replace(/_/g, '-') : locale;
|
|
|
|
|
},
|
|
|
|
|
|
2014-11-18 11:13:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the user's locale
|
|
|
|
|
*
|
|
|
|
|
* @return {String} locale string
|
|
|
|
|
*/
|
|
|
|
|
getLocale: function() {
|
2017-11-12 09:38:33 +00:00
|
|
|
|
return $('html').data('locale');
|
2017-07-17 08:08:51 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the user's language
|
|
|
|
|
*
|
|
|
|
|
* @returns {String} language string
|
|
|
|
|
*/
|
|
|
|
|
getLanguage: function () {
|
2014-11-18 11:13:44 +00:00
|
|
|
|
return $('html').prop('lang');
|
2016-01-21 14:23:03 +00:00
|
|
|
|
},
|
|
|
|
|
|
2016-09-19 21:49:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* Warn users that the connection to the server was lost temporarily
|
|
|
|
|
*
|
|
|
|
|
* This function is throttled to prevent stacked notfications.
|
|
|
|
|
* After 7sec the first notification is gone, then we can show another one
|
|
|
|
|
* if necessary.
|
|
|
|
|
*/
|
|
|
|
|
_ajaxConnectionLostHandler: _.throttle(function() {
|
|
|
|
|
OC.Notification.showTemporary(t('core', 'Connection to server lost'));
|
|
|
|
|
}, 7 * 1000, {trailing: false}),
|
|
|
|
|
|
2015-12-10 17:08:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* Process ajax error, redirects to main page
|
|
|
|
|
* if an error/auth error status was returned.
|
|
|
|
|
*/
|
|
|
|
|
_processAjaxError: function(xhr) {
|
2016-03-22 17:28:54 +00:00
|
|
|
|
var self = this;
|
2015-12-10 17:08:40 +00:00
|
|
|
|
// purposefully aborted request ?
|
2016-03-22 15:54:01 +00:00
|
|
|
|
// this._userIsNavigatingAway needed to distinguish ajax calls cancelled by navigating away
|
|
|
|
|
// from calls cancelled by failed cross-domain ajax due to SSO redirect
|
2016-03-22 17:28:54 +00:00
|
|
|
|
if (xhr.status === 0 && (xhr.statusText === 'abort' || xhr.statusText === 'timeout' || self._reloadCalled)) {
|
2015-12-10 17:08:40 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 22:44:50 +00:00
|
|
|
|
if (_.contains([302, 303, 307, 401], xhr.status) && OC.currentUser) {
|
2016-03-22 17:28:54 +00:00
|
|
|
|
// sometimes "beforeunload" happens later, so need to defer the reload a bit
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (!self._userIsNavigatingAway && !self._reloadCalled) {
|
2017-02-04 05:47:09 +00:00
|
|
|
|
var timer = 0;
|
|
|
|
|
var seconds = 5;
|
|
|
|
|
var interval = setInterval( function() {
|
2017-02-08 06:55:31 +00:00
|
|
|
|
OC.Notification.showUpdate(n('core', 'Problem loading page, reloading in %n second', 'Problem loading page, reloading in %n seconds', seconds - timer));
|
2017-02-04 05:47:09 +00:00
|
|
|
|
if (timer >= seconds) {
|
2017-02-08 06:55:31 +00:00
|
|
|
|
clearInterval(interval);
|
2017-02-04 05:47:09 +00:00
|
|
|
|
OC.reload();
|
2017-02-08 06:55:31 +00:00
|
|
|
|
}
|
2017-02-04 05:47:09 +00:00
|
|
|
|
timer++;
|
|
|
|
|
}, 1000 // 1 second interval
|
|
|
|
|
);
|
|
|
|
|
|
2016-03-22 17:28:54 +00:00
|
|
|
|
// only call reload once
|
|
|
|
|
self._reloadCalled = true;
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
2016-09-19 21:49:42 +00:00
|
|
|
|
} else if(xhr.status === 0) {
|
|
|
|
|
// Connection lost (e.g. WiFi disconnected or server is down)
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
if (!self._userIsNavigatingAway && !self._reloadCalled) {
|
|
|
|
|
self._ajaxConnectionLostHandler();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
2015-12-10 17:08:40 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registers XmlHttpRequest object for global error processing.
|
|
|
|
|
*
|
|
|
|
|
* This means that if this XHR object returns 401 or session timeout errors,
|
|
|
|
|
* the current page will automatically be reloaded.
|
|
|
|
|
*
|
|
|
|
|
* @param {XMLHttpRequest} xhr
|
|
|
|
|
*/
|
|
|
|
|
registerXHRForErrorProcessing: function(xhr) {
|
|
|
|
|
var loadCallback = function() {
|
|
|
|
|
if (xhr.readyState !== 4) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fire jquery global ajax error handler
|
|
|
|
|
$(document).trigger(new $.Event('ajaxError'), xhr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var errorCallback = function() {
|
|
|
|
|
// fire jquery global ajax error handler
|
|
|
|
|
$(document).trigger(new $.Event('ajaxError'), xhr);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (xhr.addEventListener) {
|
|
|
|
|
xhr.addEventListener('load', loadCallback);
|
|
|
|
|
xhr.addEventListener('error', errorCallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-28 10:24:08 +00:00
|
|
|
|
});
|
2014-04-21 11:46:33 +00:00
|
|
|
|
|