From 55319a0302eaeb7c8761c6c088487b0628321eb1 Mon Sep 17 00:00:00 2001 From: buddh4 Date: Fri, 19 Jan 2018 14:43:56 +0100 Subject: [PATCH] Fix #2947: Allow json success result on modalSubmit --- protected/humhub/docs/CHANGELOG.md | 2 ++ static/js/humhub/humhub.ui.modal.js | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index bb106545a3..f7a515a11f 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -13,6 +13,8 @@ HumHub Change Log - Fix: Typo in password recovery (@acs-ferreira) - Fix: Profile posts of friends not appears on dashboard - Fix #2745: Yii2 2.0.13 will break the admin interface +- Enh: Allow auto detection of response dataType +- Fix #2947: Allow json success result on modalSubmit 1.2.4 (December 13, 2017) diff --git a/static/js/humhub/humhub.ui.modal.js b/static/js/humhub/humhub.ui.modal.js index 43f0c9836f..dfe6460a8d 100644 --- a/static/js/humhub/humhub.ui.modal.js +++ b/static/js/humhub/humhub.ui.modal.js @@ -1,7 +1,7 @@ /** * Module for creating an manipulating modal dialoges. * Normal layout of a dialog: - * + * * - * + * * @param {type} param1 * @param {type} param2 */ @@ -33,7 +33,7 @@ humhub.module('ui.modal', function (module, require, $) { * The Modal class can be used to create new modals or manipulate existing modals. * If the constructor finds an element with the given id we use the existing modal, * if the id is not already used, we create a new modal dom element. - * + * * @param {string} id - id of the modal */ var Modal = function (node, options) { @@ -93,7 +93,7 @@ humhub.module('ui.modal', function (module, require, $) { this.set(options); }; - + Modal.prototype.checkAriaLabel = function () { var $title = this.$.find('.modal-title'); if($title.length) { @@ -190,6 +190,7 @@ humhub.module('ui.modal', function (module, require, $) { Modal.prototype.load = function (url, cfg, originalEvent) { var that = this; var cfg = cfg || {}; + cfg.dataType = cfg.dataType || 'html'; return new Promise(function (resolve, reject) { if (!that.isVisible()) { that.loader(); @@ -204,6 +205,7 @@ humhub.module('ui.modal', function (module, require, $) { Modal.prototype.post = function (url, cfg, originalEvent) { var that = this; var cfg = cfg || {}; + cfg.dataType = cfg.dataType || 'html'; return new Promise(function (resolve, reject) { if (!that.isVisible()) { that.loader(); @@ -346,6 +348,7 @@ humhub.module('ui.modal', function (module, require, $) { * @returns {undefined} */ Modal.prototype.setHeader = function (title) { + debugger; var $header = this.getHeader(); if (!$header.length) { $header = $(this.getTemplate('header')); @@ -415,7 +418,7 @@ humhub.module('ui.modal', function (module, require, $) { Modal.prototype.setBody = function (content) { var $body = this.getBody(); if (!$body.length) { - this.setContent($(this.getTemplate('body'))); + this.getContent().append($(this.getTemplate('body'))); $body = this.getBody(); } $body.html(content); @@ -610,7 +613,9 @@ humhub.module('ui.modal', function (module, require, $) { }); }; + debugger; var submit = function (evt, options) { + debugger; evt.$form = evt.$form || evt.$trigger.closest('form'); if (!evt.$form.length) { @@ -628,6 +633,11 @@ humhub.module('ui.modal', function (module, require, $) { var modal = (id) ? module.get(id) : module.global; return client.submit(evt, _defaultRequestOptions(evt, options)).then(function (response) { + if(response.success) { + modal.close(); + return response; + } + modal.setDialog(response); if (!modal.$.is(':visible')) { modal.show(); @@ -681,6 +691,7 @@ humhub.module('ui.modal', function (module, require, $) { }; var get = function (id, options) { + debugger; var modal = !(modals[id]) ? new Modal(id) : modals[id]; if (options) { modal.set(options);