Skip to content

Commit 9d76db4

Browse files
authoredFeb 28, 2021
Merge pull request #238 from uzulla/issue140/improve-js-error-handling-in-admin-page
管理画面操作時のAjax通信エラーについて、エラーダイアログ等をできるだけ出すように修正
2 parents dee136f + 16fbabb commit 9d76db4

13 files changed

+88
-22
lines changed
 

‎app/src/Web/Controller/Admin/CategoriesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function delete(Request $request)
138138
}
139139

140140
/**
141-
* ajax用のカテゴリ追加
141+
* ajax用のカテゴリ追加 admin/entries/create からインクルード
142142
* @param Request $request
143143
* @return string
144144
*/

‎app/src/Web/Controller/Admin/FilesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FilesController extends AdminController
1313
{
1414

1515
/**
16-
* 一覧表示
16+
* 一覧表示 /admin/files/upload からPartial読み込み
1717
* @param Request $request
1818
* @return string
1919
*/

‎app/twig_templates/admin/blog_plugins/index.twig

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
display: $(this).prop('checked') ? 1 : 0,
7878
sig: "{{ sig }}"
7979
}),
80-
cache: false
80+
cache: false,
81+
error: function (data, status, xhr){
82+
alert("エラーが発生しました、ページをリロードしてやり直してください。\n" +
83+
"An error occurred, please reload page and try again.");
84+
}
8185
});
8286
});
8387

‎app/twig_templates/admin/categories/ajax_add.twig

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{# include from admin/entries/create #}
12
<table>
23
<tbody>
34
<tr>
@@ -152,6 +153,13 @@
152153
$('#sys-category-add-name').val('');
153154
$('#sys-category-add').removeAttr('disabled');
154155
$('#sys-category-add').val('{{ _('Add') }}');
156+
},
157+
error: function (data, status, xhr){
158+
alert("カテゴリ追加時にエラーが発生しました、時間をおいてから再度試行してください。\n" +
159+
"An error occurred when adding the category, please wait a while and try again.");
160+
$('#sys-category-add-name').val('');
161+
$('#sys-category-add').removeAttr('disabled');
162+
$('#sys-category-add').val('{{ _('Add') }}');
155163
}
156164
});
157165
return false;

‎app/twig_templates/admin/categories/ajax_add_sp.twig

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{# include from admin/entries/create #}
12
<h3><span class="h3_inner">{{ _('Categories') }}</span></h3>
23

34
<div class="checkbox_list">
@@ -137,6 +138,13 @@
137138
$('#sys-category-add-name').val('');
138139
$('#sys-category-add').removeAttr('disabled');
139140
$('#sys-category-add').val('{{ _('Add') }}');
141+
},
142+
error: function (data, status, xhr){
143+
alert("カテゴリ追加時にエラーが発生しました、時間をおいてから再度試行してください。\n" +
144+
"An error occurred when adding the category, please wait a while and try again.");
145+
$('#sys-category-add-name').val('');
146+
$('#sys-category-add').removeAttr('disabled');
147+
$('#sys-category-add').val('{{ _('Add') }}');
140148
}
141149
});
142150
return false;

‎app/twig_templates/admin/comments/index.twig

+14-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@
143143
};
144144
$('#sys-comment-reply-dialog').dialog(option);
145145
$('#sys-comment-reply-dialog').html('now loading..');
146-
$('#sys-comment-reply-dialog').load(common.fwURL('Comments', 'ajax_reply', {id: id}))
146+
$('#sys-comment-reply-dialog').load(common.fwURL('Comments', 'ajax_reply', {id: id}), function(data, status, xhr){
147+
if(status === "error") {
148+
alert("エラーが発生しました、ページをリロードしてください。\n" +
149+
"An error occurred, please reload page and try again.");
150+
}
151+
});
147152
reply.updateReadStatus(is_private);
148153
};
149154
// コメントを閉じる処理
@@ -170,6 +175,10 @@
170175
$('#sys-reply-message').hide();
171176
$('#sys-reply-error').html(json.error);
172177
$('#sys-reply-error').show();
178+
},
179+
error: function (data, status, xhr){
180+
alert("エラーが発生しました、ページをリロードしてください。\n" +
181+
"An error occurred, please reload page and try again.");
173182
}
174183
});
175184
};
@@ -193,6 +202,10 @@
193202
$('#sys-open-status-' + id + ' > *').show();
194203
$('#sys-comment-approval').show();
195204
alert(json.error);
205+
},
206+
error: function (data, status, xhr){
207+
alert("エラーが発生しました、ページをリロードしてやり直してください。\n" +
208+
"An error occurred, please reload page and try again.");
196209
}
197210
});
198211
});

‎app/twig_templates/admin/entries/ajax_media_load.twig

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{# 新規記事追加ページ /admin/entries/create から読み込み #}
12
{% if files %}
23

34
<ul class="sys-form-add-media">

‎app/twig_templates/admin/entries/ajax_media_load_sp.twig

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{# 新規記事追加ページ /admin/entries/create SP から読み込み #}
12
{% if files %}
23

34
<div class="form_contents">

‎app/twig_templates/admin/files/ajax_index.twig

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{# /admin/files/upload からPartial読み込み #}
12
<h3 id="entry_count">
23
{{ _('File search') }}[{{ _('Hits') }}&nbsp;{{ paging.count }}{{ _(' results') }}]
34
{{ input(req, 'limit', 'select', {'options': page_list_file, 'default': file_default_limit}) }}
@@ -79,7 +80,7 @@
7980
return false;
8081
});
8182
82-
// ファイル削除ボタン
83+
// 複数ファイル削除ボタン
8384
$('#sys-delete-button').click(function () {
8485
if (!confirm('{{ _('Are you sure you want to delete?') }}')) {
8586
return;
@@ -107,6 +108,15 @@
107108
// 削除完了後検索処理を実行
108109
isAjaxSubmit = isPageChange = true;
109110
ajaxSubmit();
111+
},
112+
error: function( response, status, xhr ) {
113+
if (status === "error") {
114+
alert("エラーが発生しました、ページをリロードしてください。\n" +
115+
"Request failed. Please reload page and retry.");
116+
// 失敗しているが、画面を復帰させるために検索処理を実行
117+
isAjaxSubmit = isPageChange = true;
118+
ajaxSubmit();
119+
}
110120
}
111121
});
112122
return false;

‎app/twig_templates/admin/files/upload.twig

+13-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
common.formEnterNonSubmit('sys-file-form');
4343
4444
// ajaxで一覧情報をロード
45-
$('#sys-ajax-files-index').load('{{ url(req, 'Files', 'ajax_index') }}')
45+
$('#sys-ajax-files-index').load('{{ url(req, 'Files', 'ajax_index') }}', writeErrToSysAjaxFilesIndex)
4646
});
4747
4848
// ページ数初期化有無フラグ
@@ -64,7 +64,8 @@
6464
success: function (res) {
6565
$('#sys-ajax-files-index').html(res);
6666
isAjaxSubmit = true;
67-
}
67+
},
68+
error: writeErrToSysAjaxFilesIndex
6869
});
6970
return;
7071
}
@@ -85,7 +86,8 @@
8586
success: function (res) {
8687
$('#sys-ajax-files-index').html(res);
8788
isAjaxSubmit = true;
88-
}
89+
},
90+
error: writeErrToSysAjaxFilesIndex
8991
});
9092
}
9193
@@ -102,5 +104,13 @@
102104
$('input[name=order]').val(order);
103105
ajaxSubmit();
104106
}
107+
108+
function writeErrToSysAjaxFilesIndex( response, status, xhr ) {
109+
if ( status === "error" ) {
110+
$('#sys-ajax-files-index')
111+
.html("<div style='text-align: center; font-size: 2em; font-weight:bold'>エラーが発生しました、ページをリロードしてください。<br>" +
112+
"Loading error. Please reload page.</div>");
113+
}
114+
}
105115
</script>
106116
{% endblock %}

‎public/js/admin/entry_editor.js

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// メディア追加関数
22
var addMedia = {
33
target_id: null,
4-
elrte: true, // elRTEの使用,不使用
4+
elrte: true, // elRTEの使用,不使用
55
init: function(){
66
if (this.target_id!=null) {
77
return ;
88
}
99
// 検索ボタン
1010
$('#sys-add-media-search-button').on('click', function(){
1111
var keyword = $('#sys-add-media-search-keyword').val();
12-
$('#sys-add-media-load').load(addMedia.load({keyword: keyword}));
12+
addMedia.load({keyword: keyword});
1313
});
1414
// Enterキーで検索
1515
$('#sys-add-media-search-keyword').keypress(function(e){
@@ -22,18 +22,27 @@ var addMedia = {
2222
$('#sys-add-media-dialog').dialog('option', {width: $(window).width() - 100});
2323
});
2424
},
25-
load: function(params){
26-
$('#sys-add-media-load').fadeOut('fast', function(){
27-
$('#sys-add-media-load').load(common.fwURL('Entries', 'ajax_media_load', params), function(){
28-
$('#sys-add-media-load').fadeIn('fast');
29-
$('#sys-add-media-load').find('input[type=checkbox]').on('click', function(){
30-
if ($(this).prop('checked')) {
31-
$(this).closest('li').addClass('selected');
25+
load: function (params) {
26+
$('#sys-add-media-load').fadeOut('fast', function () {
27+
$('#sys-add-media-load').load(
28+
common.fwURL('Entries', 'ajax_media_load', params),
29+
function (response, status, xhr) {
30+
if (status === "error") {
31+
alert("エラーが発生しました、ページをリロードしてください。\n" +
32+
"Loading error. Please reload page.");
33+
3234
} else {
33-
$(this).closest('li').removeClass('selected');
35+
$('#sys-add-media-load').fadeIn('fast');
36+
$('#sys-add-media-load').find('input[type=checkbox]').on('click', function () {
37+
if ($(this).prop('checked')) {
38+
$(this).closest('li').addClass('selected');
39+
} else {
40+
$(this).closest('li').removeClass('selected');
41+
}
42+
});
3443
}
35-
})
36-
});
44+
}
45+
);
3746
});
3847
},
3948
open: function(key, config){
@@ -62,7 +71,7 @@ var addMedia = {
6271
}
6372
$('#sys-add-media-dialog').dialog(option);
6473
$('#sys-add-media-load').html('<p>Now loading...</p>');
65-
$('#sys-add-media-load').load(addMedia.load({}));
74+
addMedia.load({});
6675
},
6776
add: function(){
6877
var textarea_id = addMedia.target_id;
@@ -91,7 +100,7 @@ var addMedia = {
91100
// 位置情報取得
92101
getSelection: function(dom) {
93102
var pos = {};
94-
if (/*@cc_on!@*/false) {
103+
if (/*@cc_on!@*/false) { // TODO remove, It's hack for IE<=10 #235
95104
dom.focus();
96105
var range = document.selection.createRange();
97106
var clone = range.duplicate();

‎tests/cli_generate_sample_comment.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Fc2blog\Tests\LoaderHelper;
77

88
define("TEST_APP_DIR", __DIR__ . "/../app");
9+
define("THIS_IS_TEST", true);
910

1011
require_once __DIR__ . "/../app/vendor/autoload.php";
1112

‎tests/cli_generate_sample_upload_image.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Fc2blog\Tests\LoaderHelper;
77

88
define("TEST_APP_DIR", __DIR__ . "/../app");
9+
define("THIS_IS_TEST", true);
910

1011
require_once __DIR__ . "/../app/vendor/autoload.php";
1112

0 commit comments

Comments
 (0)
Please sign in to comment.