|
189 | 189 | * } |
190 | 190 | */ |
191 | 191 | eAjaxSuccess: undefined, |
| 192 | + eAjaxError: undefined, |
192 | 193 | eAjaxMethod: undefined, // POST/GET |
193 | 194 | defaultWidth: 150, |
194 | 195 | defaultZindex: 1101, |
|
807 | 808 | success: function (json) { |
808 | 809 | var d = null |
809 | 810 | if (p.eAjaxSuccess && $.isFunction(p.eAjaxSuccess)) { |
810 | | - d = p.eAjaxSuccess(json) |
| 811 | + d = p.eAjaxSuccess.call(self, json, 'init') |
| 812 | + if (d===false) return |
| 813 | + if (typeof d == 'string') { |
| 814 | + self.showMessage(d, true) |
| 815 | + return |
| 816 | + } |
811 | 817 | } |
812 | 818 | if (!d) d = p.defaultAjaxResult |
813 | 819 | self.afterInit(self, d.list) |
814 | 820 | }, |
815 | 821 | error: function (jqXHR, textStatus, errorThrown) { |
816 | | - self.ajaxErrorNotify(self, errorThrown) |
| 822 | + if (p.eAjaxError && $.isFunction(p.eAjaxError)) { |
| 823 | + p.eAjaxError.call(self, jqXHR, textStatus, errorThrown) |
| 824 | + }else{ |
| 825 | + self.ajaxErrorNotify(errorThrown) |
| 826 | + } |
817 | 827 | } |
818 | 828 | }) |
819 | 829 | } |
|
1097 | 1107 |
|
1098 | 1108 | /** |
1099 | 1109 | * Ajax request fail |
1100 | | - * @param {Object} self |
1101 | 1110 | * @param {string} errorThrown |
1102 | 1111 | */ |
1103 | | - SelectPage.prototype.ajaxErrorNotify = function (self, errorThrown) { |
1104 | | - self.showMessage(self.message.ajax_error) |
| 1112 | + SelectPage.prototype.ajaxErrorNotify = function (errorThrown) { |
| 1113 | + this.showMessage(errorThrown||this.message.ajax_error) |
1105 | 1114 | } |
1106 | 1115 |
|
1107 | 1116 | /** |
1108 | 1117 | * Message box |
1109 | | - * @param {Object} self |
1110 | 1118 | * @param msg {string} the text need to show |
1111 | 1119 | */ |
1112 | | - SelectPage.prototype.showMessage = function (self, msg) { |
| 1120 | + SelectPage.prototype.showMessage = function (msg, slient) { |
1113 | 1121 | if (!msg) return |
| 1122 | + var self = this |
1114 | 1123 | var msgLi = '<li class="' + self.css_class.message_box + '"><i class="sp-iconfont if-warning"></i> ' + msg + '</li>' |
1115 | | - self.elem.results.empty().append(msgLi).show() |
1116 | | - self.calcResultsSize(self) |
1117 | | - self.setOpenStatus(self, true) |
1118 | | - self.elem.control.hide() |
| 1124 | + self.elem.results.empty().append(msgLi) |
| 1125 | + if(!slient) { |
| 1126 | + self.elem.results.show() |
| 1127 | + self.calcResultsSize(self) |
| 1128 | + self.setOpenStatus(self, true) |
| 1129 | + } |
| 1130 | + if (self.elem.control) self.elem.control.hide() |
1119 | 1131 | if (self.option.pagination) self.elem.navi.hide() |
1120 | 1132 | } |
1121 | 1133 |
|
|
1351 | 1363 | success: function (returnData) { |
1352 | 1364 | if (!returnData || !$.isPlainObject(returnData)) { |
1353 | 1365 | self.hideResults(self) |
1354 | | - self.ajaxErrorNotify(self, errorThrown) |
| 1366 | + self.ajaxErrorNotify() |
1355 | 1367 | return |
1356 | 1368 | } |
1357 | 1369 | var data = {}, json = {} |
1358 | 1370 | try { |
1359 | | - data = p.eAjaxSuccess(returnData) |
| 1371 | + data = p.eAjaxSuccess.call(self, returnData, 'search') |
| 1372 | + if (data===false) return |
| 1373 | + if (typeof data == 'string') { |
| 1374 | + self.showMessage(data) |
| 1375 | + return |
| 1376 | + } |
1360 | 1377 | if (!data) data = p.defaultAjaxResult |
1361 | 1378 | json.originalResult = data.list |
1362 | 1379 | json.cnt_whole = data.totalRow |
1363 | 1380 | } catch (e) { |
1364 | | - self.showMessage(self, self.message.ajax_error) |
| 1381 | + console.error(e); |
| 1382 | + self.showMessage(self.message.ajax_error) |
1365 | 1383 | return |
1366 | 1384 | } |
1367 | 1385 |
|
|
1390 | 1408 | error: function (jqXHR, textStatus, errorThrown) { |
1391 | 1409 | if (textStatus != 'abort') { |
1392 | 1410 | self.hideResults(self) |
1393 | | - self.ajaxErrorNotify(self, errorThrown) |
| 1411 | + if (p.eAjaxError && $.isFunction(p.eAjaxError)) { |
| 1412 | + p.eAjaxError.call(self, jqXHR, textStatus, errorThrown) |
| 1413 | + }else{ |
| 1414 | + self.ajaxErrorNotify(errorThrown) |
| 1415 | + } |
1394 | 1416 | } |
1395 | 1417 | }, |
1396 | 1418 | complete: function () { |
|
1669 | 1691 | var selectedSize = el.element_box.find('li.selected_tag').length |
1670 | 1692 | if (selectedSize > 0 && selectedSize >= p.maxSelectLimit) { |
1671 | 1693 | var msg = self.message.max_selected |
1672 | | - self.showMessage(self, msg.replace(self.template.msg.maxSelectLimit, p.maxSelectLimit)) |
| 1694 | + self.showMessage(msg.replace(self.template.msg.maxSelectLimit, p.maxSelectLimit)) |
1673 | 1695 | return |
1674 | 1696 | } |
1675 | 1697 | } |
|
0 commit comments