##// END OF EJS Templates
quick-switcher: handle errors using Swal, and create a new helper to make calls the same across whole app.
marcink -
r4339:de17b181 default
parent child Browse files
Show More
@@ -564,13 +564,15 b''
564 564
565 565 $.extend(ajaxSettings, options.ajaxSettings);
566 566
567 that.currentRequest = $.ajax(ajaxSettings).done(function (data) {
567 that.currentRequest = $.ajax(ajaxSettings)
568 .done(function (data) {
568 569 var result;
569 570 that.currentRequest = null;
570 571 result = options.transformResult(data);
571 572 that.processResponse(result, query, cacheKey);
572 573 options.onSearchComplete.call(that.element, query, result.suggestions);
573 }).fail(function (jqXHR, textStatus, errorThrown) {
574 })
575 .fail(function (jqXHR, textStatus, errorThrown) {
574 576 options.onSearchError.call(that.element, query, jqXHR, textStatus, errorThrown);
575 577 });
576 578 }
@@ -588,21 +588,12 b' var CommentsController = function() {'
588 588 var $comment = $(node).closest('.comment');
589 589 var comment_id = $comment.attr('data-comment-id');
590 590
591 Swal.fire({
591 SwalNoAnimation.fire({
592 592 title: 'Delete this comment?',
593 593 icon: 'warning',
594 594 showCancelButton: true,
595 confirmButtonColor: '#84a5d2',
596 cancelButtonColor: '#e85e4d',
597 595 confirmButtonText: _gettext('Yes, delete comment #{0}!').format(comment_id),
598 showClass: {
599 popup: 'swal2-noanimation',
600 backdrop: 'swal2-noanimation'
601 },
602 hideClass: {
603 popup: '',
604 backdrop: ''
605 }
596
606 597 }).then(function(result) {
607 598 if (result.value) {
608 599 self._deleteComment(node);
@@ -50,19 +50,9 b' var UsersAutoComplete = function(input_i'
50 50
51 51 var _showAuthToken = function (authTokenId, showUrl) {
52 52
53 Swal.fire({
53 SwalNoAnimation.fire({
54 54 title: _gettext('Show this authentication token?'),
55 55 showCancelButton: true,
56 confirmButtonColor: '#84a5d2',
57 cancelButtonColor: '#e85e4d',
58 showClass: {
59 popup: 'swal2-noanimation',
60 backdrop: 'swal2-noanimation'
61 },
62 hideClass: {
63 popup: '',
64 backdrop: ''
65 },
66 56 confirmButtonText: _gettext('Show'),
67 57 showLoaderOnConfirm: true,
68 58 allowOutsideClick: function () {
@@ -98,19 +88,9 b' var _showAuthToken = function (authToken'
98 88 var tmpl = ('<code>{0}</code>' +
99 89 '<i class="tooltip icon-clipboard clipboard-action" data-clipboard-text="{1}" title="Copy Token"></i>');
100 90
101 Swal.fire({
91 SwalNoAnimation.fire({
102 92 title: _gettext('Authentication Token'),
103 93 html: tmpl.format(result.value.auth_token, result.value.auth_token),
104 confirmButtonColor: '#84a5d2',
105 cancelButtonColor: '#e85e4d',
106 showClass: {
107 popup: 'swal2-noanimation',
108 backdrop: 'swal2-noanimation'
109 },
110 hideClass: {
111 popup: '',
112 backdrop: ''
113 },
114 94 })
115 95 }
116 96 })
@@ -80,6 +80,30 b' var ajaxPOST = function (url, postData, '
80 80 return request;
81 81 };
82 82
83
84 SwalNoAnimation = Swal.mixin({
85 confirmButtonColor: '#84a5d2',
86 cancelButtonColor: '#e85e4d',
87 showClass: {
88 popup: 'swal2-noanimation',
89 backdrop: 'swal2-noanimation'
90 },
91 hideClass: {
92 popup: '',
93 backdrop: ''
94 },
95 })
96
97
98 /* Example usage:
99 *
100 error: function(jqXHR, textStatus, errorThrown) {
101 var prefix = "Error while fetching entries.\n"
102 var message = formatErrorMessage(jqXHR, textStatus, errorThrown, prefix);
103 ajaxErrorSwal(message);
104 }
105 *
106 * */
83 107 function formatErrorMessage(jqXHR, textStatus, errorThrown, prefix) {
84 108 if(typeof prefix === "undefined") {
85 109 prefix = ''
@@ -107,7 +131,7 b' function formatErrorMessage(jqXHR, textS'
107 131 }
108 132
109 133 function ajaxErrorSwal(message) {
110 Swal.fire({
134 SwalNoAnimation.fire({
111 135 icon: 'error',
112 136 title: _gettext('Ajax Request Error'),
113 137 html: '<span style="white-space: pre-line">{0}</span>'.format(message),
@@ -135,21 +159,13 b' function submitConfirm(event, self, ques'
135 159 }
136 160 event.preventDefault();
137 161
138 Swal.fire({
162 SwalNoAnimation.fire({
139 163 title: question,
140 164 icon: 'warning',
141 165 html: htmlText,
142 showClass: {
143 popup: 'swal2-noanimation',
144 backdrop: 'swal2-noanimation'
145 },
146 hideClass: {
147 popup: '',
148 backdrop: ''
149 },
166
150 167 showCancelButton: true,
151 confirmButtonColor: '#84a5d2',
152 cancelButtonColor: '#e85e4d',
168
153 169 confirmButtonText: confirmText
154 170 }).then(function(result) {
155 171 if (result.value) {
@@ -1069,8 +1069,14 b''
1069 1069 },
1070 1070 onSearchError: function (element, query, jqXHR, textStatus, errorThrown) {
1071 1071 if (jqXHR !== 'abort') {
1072 alert("Error during search.\nError code: {0}".format(textStatus));
1073 window.location = '';
1072 var message = formatErrorMessage(jqXHR, textStatus, errorThrown);
1073 SwalNoAnimation.fire({
1074 icon: 'error',
1075 title: _gettext('Error during search operation'),
1076 html: '<span style="white-space: pre-line">{0}</span>'.format(message),
1077 }).then(function(result) {
1078 window.location.reload();
1079 })
1074 1080 }
1075 1081 },
1076 1082 onSearchStart: function (params) {
General Comments 0
You need to be logged in to leave comments. Login now