##// 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 $.extend(ajaxSettings, options.ajaxSettings);
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 var result;
569 var result;
569 that.currentRequest = null;
570 that.currentRequest = null;
570 result = options.transformResult(data);
571 result = options.transformResult(data);
571 that.processResponse(result, query, cacheKey);
572 that.processResponse(result, query, cacheKey);
572 options.onSearchComplete.call(that.element, query, result.suggestions);
573 options.onSearchComplete.call(that.element, query, result.suggestions);
573 }).fail(function (jqXHR, textStatus, errorThrown) {
574 })
575 .fail(function (jqXHR, textStatus, errorThrown) {
574 options.onSearchError.call(that.element, query, jqXHR, textStatus, errorThrown);
576 options.onSearchError.call(that.element, query, jqXHR, textStatus, errorThrown);
575 });
577 });
576 }
578 }
@@ -588,21 +588,12 b' var CommentsController = function() {'
588 var $comment = $(node).closest('.comment');
588 var $comment = $(node).closest('.comment');
589 var comment_id = $comment.attr('data-comment-id');
589 var comment_id = $comment.attr('data-comment-id');
590
590
591 Swal.fire({
591 SwalNoAnimation.fire({
592 title: 'Delete this comment?',
592 title: 'Delete this comment?',
593 icon: 'warning',
593 icon: 'warning',
594 showCancelButton: true,
594 showCancelButton: true,
595 confirmButtonColor: '#84a5d2',
596 cancelButtonColor: '#e85e4d',
597 confirmButtonText: _gettext('Yes, delete comment #{0}!').format(comment_id),
595 confirmButtonText: _gettext('Yes, delete comment #{0}!').format(comment_id),
598 showClass: {
596
599 popup: 'swal2-noanimation',
600 backdrop: 'swal2-noanimation'
601 },
602 hideClass: {
603 popup: '',
604 backdrop: ''
605 }
606 }).then(function(result) {
597 }).then(function(result) {
607 if (result.value) {
598 if (result.value) {
608 self._deleteComment(node);
599 self._deleteComment(node);
@@ -50,19 +50,9 b' var UsersAutoComplete = function(input_i'
50
50
51 var _showAuthToken = function (authTokenId, showUrl) {
51 var _showAuthToken = function (authTokenId, showUrl) {
52
52
53 Swal.fire({
53 SwalNoAnimation.fire({
54 title: _gettext('Show this authentication token?'),
54 title: _gettext('Show this authentication token?'),
55 showCancelButton: true,
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 confirmButtonText: _gettext('Show'),
56 confirmButtonText: _gettext('Show'),
67 showLoaderOnConfirm: true,
57 showLoaderOnConfirm: true,
68 allowOutsideClick: function () {
58 allowOutsideClick: function () {
@@ -98,19 +88,9 b' var _showAuthToken = function (authToken'
98 var tmpl = ('<code>{0}</code>' +
88 var tmpl = ('<code>{0}</code>' +
99 '<i class="tooltip icon-clipboard clipboard-action" data-clipboard-text="{1}" title="Copy Token"></i>');
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 title: _gettext('Authentication Token'),
92 title: _gettext('Authentication Token'),
103 html: tmpl.format(result.value.auth_token, result.value.auth_token),
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 return request;
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 function formatErrorMessage(jqXHR, textStatus, errorThrown, prefix) {
107 function formatErrorMessage(jqXHR, textStatus, errorThrown, prefix) {
84 if(typeof prefix === "undefined") {
108 if(typeof prefix === "undefined") {
85 prefix = ''
109 prefix = ''
@@ -107,7 +131,7 b' function formatErrorMessage(jqXHR, textS'
107 }
131 }
108
132
109 function ajaxErrorSwal(message) {
133 function ajaxErrorSwal(message) {
110 Swal.fire({
134 SwalNoAnimation.fire({
111 icon: 'error',
135 icon: 'error',
112 title: _gettext('Ajax Request Error'),
136 title: _gettext('Ajax Request Error'),
113 html: '<span style="white-space: pre-line">{0}</span>'.format(message),
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 event.preventDefault();
160 event.preventDefault();
137
161
138 Swal.fire({
162 SwalNoAnimation.fire({
139 title: question,
163 title: question,
140 icon: 'warning',
164 icon: 'warning',
141 html: htmlText,
165 html: htmlText,
142 showClass: {
166
143 popup: 'swal2-noanimation',
144 backdrop: 'swal2-noanimation'
145 },
146 hideClass: {
147 popup: '',
148 backdrop: ''
149 },
150 showCancelButton: true,
167 showCancelButton: true,
151 confirmButtonColor: '#84a5d2',
168
152 cancelButtonColor: '#e85e4d',
153 confirmButtonText: confirmText
169 confirmButtonText: confirmText
154 }).then(function(result) {
170 }).then(function(result) {
155 if (result.value) {
171 if (result.value) {
@@ -1069,8 +1069,14 b''
1069 },
1069 },
1070 onSearchError: function (element, query, jqXHR, textStatus, errorThrown) {
1070 onSearchError: function (element, query, jqXHR, textStatus, errorThrown) {
1071 if (jqXHR !== 'abort') {
1071 if (jqXHR !== 'abort') {
1072 alert("Error during search.\nError code: {0}".format(textStatus));
1072 var message = formatErrorMessage(jqXHR, textStatus, errorThrown);
1073 window.location = '';
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 onSearchStart: function (params) {
1082 onSearchStart: function (params) {
General Comments 0
You need to be logged in to leave comments. Login now