mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 06:08:21 +01:00
Enh: Added xhr to client response instances
Enh: Added response.header for receiving response header from xhr Enh: Added post action to client module for data-action-click="client.post" Fix: Try using options url as fallback in client calls if the action instance does not provide an url. e.g. client.post(evt, {url:...} Enh: Enable setting ajax dataType from trigger e.g. data-action-click="modal.load" data-action-data-type="json"
This commit is contained in:
parent
7cde220b15
commit
9b5abab9a0
@ -3,6 +3,11 @@ HumHub Change Log
|
|||||||
|
|
||||||
1.2.0-beta.3 under developement
|
1.2.0-beta.3 under developement
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
- Enh: Added xhr to client response instances
|
||||||
|
- Enh: Added response.header for receiving response header from xhr
|
||||||
|
- Enh: Added post action to client module for data-action-click="client.post"
|
||||||
|
- Fix: Try using options url as fallback in client calls if the action instance does not provide an url. e.g. client.post(evt, {url:...}
|
||||||
|
- Enh: Enable setting ajax dataType from trigger e.g. data-action-click="modal.load" data-action-data-type="json"
|
||||||
- Enh: Added action event.data for receiving action specific data options
|
- Enh: Added action event.data for receiving action specific data options
|
||||||
- Enh: Added default run for JsWidget
|
- Enh: Added default run for JsWidget
|
||||||
- Enh: Added File::findByRecord for searching all attached files of a given ActiveRecord
|
- Enh: Added File::findByRecord for searching all attached files of a given ActiveRecord
|
||||||
|
@ -17,8 +17,9 @@ humhub.module('client', function (module, require, $) {
|
|||||||
//Textstatus = "timeout", "error", "abort", "parsererror", "application"
|
//Textstatus = "timeout", "error", "abort", "parsererror", "application"
|
||||||
this.textStatus = textStatus;
|
this.textStatus = textStatus;
|
||||||
this.dataType = dataType;
|
this.dataType = dataType;
|
||||||
|
this.xhr = xhr;
|
||||||
|
|
||||||
var responseType = xhr.getResponseHeader('content-type');
|
var responseType = this.header('content-type');
|
||||||
|
|
||||||
// If we expect json and received json we merge the json result with our response object.
|
// If we expect json and received json we merge the json result with our response object.
|
||||||
if ((!dataType || dataType === 'json') && responseType && responseType.indexOf('json') > -1) {
|
if ((!dataType || dataType === 'json') && responseType && responseType.indexOf('json') > -1) {
|
||||||
@ -27,6 +28,10 @@ humhub.module('client', function (module, require, $) {
|
|||||||
this[dataType] = this.response;
|
this[dataType] = this.response;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Response.prototype.header = function (key) {
|
||||||
|
return this.xhr.getResponseHeader(key);
|
||||||
|
};
|
||||||
|
|
||||||
Response.prototype.setSuccess = function (data) {
|
Response.prototype.setSuccess = function (data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@ -56,13 +61,11 @@ humhub.module('client', function (module, require, $) {
|
|||||||
result.response = this.response.substr(0, 500)
|
result.response = this.response.substr(0, 500)
|
||||||
result.response += (this.response.length > 500) ? '...' : '';
|
result.response += (this.response.length > 500) ? '...' : '';
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
if (this.html && object.isString(this.html)) {
|
if (this.html && object.isString(this.html)) {
|
||||||
result.html = this.html.substr(0, 500)
|
result.html = this.html.substr(0, 500)
|
||||||
result.html += (this.html.length > 500) ? '...' : '';
|
result.html += (this.html.length > 500) ? '...' : '';
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -73,7 +76,7 @@ humhub.module('client', function (module, require, $) {
|
|||||||
} else {
|
} else {
|
||||||
location.reload(true);
|
location.reload(true);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var submit = function ($form, cfg, originalEvent) {
|
var submit = function ($form, cfg, originalEvent) {
|
||||||
if ($form instanceof $.Event && $form.$form && $form.length) {
|
if ($form instanceof $.Event && $form.$form && $form.length) {
|
||||||
@ -99,11 +102,17 @@ humhub.module('client', function (module, require, $) {
|
|||||||
var url = cfg.url || originalEvent.url || $form.attr('action');
|
var url = cfg.url || originalEvent.url || $form.attr('action');
|
||||||
return ajax(url, cfg, originalEvent);
|
return ajax(url, cfg, originalEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var actionPost = function (evt) {
|
||||||
|
post(evt).catch(function(e) {
|
||||||
|
module.log.error(e, true);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var post = function (url, cfg, originalEvent) {
|
var post = function (url, cfg, originalEvent) {
|
||||||
if (url instanceof $.Event) {
|
if (url instanceof $.Event) {
|
||||||
originalEvent = url;
|
originalEvent = url;
|
||||||
url = originalEvent.url;
|
url = originalEvent.url || cfg.url;
|
||||||
} else if (cfg instanceof $.Event) {
|
} else if (cfg instanceof $.Event) {
|
||||||
originalEvent = cfg;
|
originalEvent = cfg;
|
||||||
cfg = {};
|
cfg = {};
|
||||||
@ -120,7 +129,7 @@ humhub.module('client', function (module, require, $) {
|
|||||||
var html = function (url, cfg, originalEvent) {
|
var html = function (url, cfg, originalEvent) {
|
||||||
if (url instanceof $.Event) {
|
if (url instanceof $.Event) {
|
||||||
originalEvent = url;
|
originalEvent = url;
|
||||||
url = originalEvent.url;
|
url = originalEvent.url || cfg.url;
|
||||||
} else if (cfg instanceof $.Event) {
|
} else if (cfg instanceof $.Event) {
|
||||||
originalEvent = cfg;
|
originalEvent = cfg;
|
||||||
cfg = {};
|
cfg = {};
|
||||||
@ -138,7 +147,7 @@ humhub.module('client', function (module, require, $) {
|
|||||||
var get = function (url, cfg, originalEvent) {
|
var get = function (url, cfg, originalEvent) {
|
||||||
if (url instanceof $.Event) {
|
if (url instanceof $.Event) {
|
||||||
originalEvent = url;
|
originalEvent = url;
|
||||||
url = originalEvent.url;
|
url = originalEvent.url || cfg.url;
|
||||||
} else if (cfg instanceof $.Event) {
|
} else if (cfg instanceof $.Event) {
|
||||||
originalEvent = cfg;
|
originalEvent = cfg;
|
||||||
cfg = {};
|
cfg = {};
|
||||||
@ -162,9 +171,13 @@ humhub.module('client', function (module, require, $) {
|
|||||||
cfg = {'success': cfg};
|
cfg = {'success': cfg};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var promise = new Promise(function (resolve, reject) {
|
var promise = new Promise(function (resolve, reject) {
|
||||||
cfg = cfg || {};
|
cfg = cfg || {};
|
||||||
|
|
||||||
|
// allows data-action-data-type="json" on $trigger
|
||||||
|
if(originalEvent && object.isFunction(originalEvent.data)) {
|
||||||
|
cfg.dataType = originalEvent.data('data-type', cfg.dataType);
|
||||||
|
}
|
||||||
|
|
||||||
var errorHandler = cfg.error;
|
var errorHandler = cfg.error;
|
||||||
var error = function (xhr, textStatus, errorThrown) {
|
var error = function (xhr, textStatus, errorThrown) {
|
||||||
@ -285,6 +298,7 @@ humhub.module('client', function (module, require, $) {
|
|||||||
|
|
||||||
module.export({
|
module.export({
|
||||||
ajax: ajax,
|
ajax: ajax,
|
||||||
|
actionPost: actionPost,
|
||||||
post: post,
|
post: post,
|
||||||
get: get,
|
get: get,
|
||||||
html: html,
|
html: html,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user