summaryrefslogtreecommitdiff
path: root/assets/js/src/Popover.js
diff options
context:
space:
mode:
author85pando <85pando@googlemail.com>2016-02-05 10:28:40 +0100
committer85pando <85pando@googlemail.com>2016-02-05 10:28:40 +0100
commit791d13c87bf510d913973b77a5f6d152311a1d87 (patch)
tree81412e8dbd3ac4fa0047030a6068afafd975687e /assets/js/src/Popover.js
parent2074aaaa9a75455097e4e77ca09f4fba3e567052 (diff)
parent12aaec03b19a07635f59b00f532c92c37ac1df5f (diff)
Merge remote-tracking branch 'refs/remotes/upstream/master'
Conflicts: app/Locale/de_DE/translations.php
Diffstat (limited to 'assets/js/src/Popover.js')
-rw-r--r--assets/js/src/Popover.js47
1 files changed, 34 insertions, 13 deletions
diff --git a/assets/js/src/Popover.js b/assets/js/src/Popover.js
index 8d72dec8..a5ec647c 100644
--- a/assets/js/src/Popover.js
+++ b/assets/js/src/Popover.js
@@ -13,7 +13,7 @@ Popover.prototype.open = function(link) {
self.app.dropdown.close();
$.get(link, function(content) {
- $("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
+ $("body").prepend('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
self.app.refresh();
self.router.dispatch(this.app);
self.afterOpen();
@@ -55,26 +55,47 @@ Popover.prototype.listen = function() {
Popover.prototype.afterOpen = function() {
var self = this;
- var taskForm = $("#task-form");
+ var popoverForm = $("#popover-content .popover-form");
- if (taskForm) {
- taskForm.on("submit", function(e) {
+ // Submit forms with Ajax request
+ if (popoverForm) {
+ popoverForm.on("submit", function(e) {
e.preventDefault();
$.ajax({
type: "POST",
- url: taskForm.attr("action"),
- data: taskForm.serialize(),
+ url: popoverForm.attr("action"),
+ data: popoverForm.serialize(),
success: function(data, textStatus, request) {
- if (request.getResponseHeader("X-Ajax-Redirect")) {
- window.location = request.getResponseHeader("X-Ajax-Redirect");
- }
- else {
- $("#popover-content").html(data);
- self.afterOpen();
- }
+ self.afterSubmit(data, request, self);
}
});
});
}
+
+ // Submit link with Ajax request
+ $(document).on("click", ".popover-link", function(e) {
+ e.preventDefault();
+
+ $.ajax({
+ type: "GET",
+ url: $(this).attr("href"),
+ success: function(data, textStatus, request) {
+ self.afterSubmit(data, request, self);
+ }
+ });
+ });
+};
+
+Popover.prototype.afterSubmit = function(data, request, self) {
+ var redirect = request.getResponseHeader("X-Ajax-Redirect");
+
+ if (redirect) {
+ window.location = redirect === 'self' ? window.location.href.split("#")[0] : redirect;
+ }
+ else {
+ $("#popover-content").html(data);
+ $("#popover-content input[autofocus]").focus();
+ self.afterOpen();
+ }
};