|
28 | 28 | }); |
29 | 29 |
|
30 | 30 | $('#upload-btn').click(function () { |
31 | | - var options = { |
32 | | - beforeSubmit: showRequest, |
33 | | - success: showResponse, |
34 | | - error: showError |
35 | | - }; |
36 | | -
|
37 | | - function showRequest(formData, jqForm, options) { |
38 | | - $('#upload-btn').html("<i class='fa fa-refresh fa-spin'></i> {{ $lang['btn-uploading'] }}"); |
39 | | - return true; |
40 | | - } |
| 31 | + $(this).html('') |
| 32 | + .append($('<i>').addClass('fa fa-refresh fa-spin')) |
| 33 | + .append(" {{ $lang['btn-uploading'] }}") |
| 34 | + .addClass('disabled'); |
41 | 35 |
|
42 | | - function showResponse(responseText, statusText, xhr, $form) { |
| 36 | + function resetUploadForm() { |
43 | 37 | $('#uploadModal').modal('hide'); |
44 | | - $('#upload-btn').html("{{ $lang['btn-upload'] }}"); |
45 | | - if (responseText != 'OK'){ |
46 | | - notify(responseText); |
47 | | - } |
| 38 | + $('#upload-btn').html("{{ $lang['btn-upload'] }}").removeClass('disabled'); |
48 | 39 | $('input#upload').val(''); |
49 | | - loadItems(); |
50 | 40 | } |
51 | 41 |
|
52 | | - function showError(jqXHR, textStatus, errorThrown) { |
53 | | - $('#upload-btn').html("{{ $lang['btn-upload'] }}"); |
54 | | - if (jqXHR.status == 413) { |
55 | | - notify("{{ $lang['error-too-large'] }}"); |
56 | | - } else if (textStatus == 'error') { |
57 | | - notify("{{ $lang['error-other'] }}" + errorThrown); |
58 | | - } else { |
59 | | - notify("{{ $lang['error-other'] }}" + textStatus + '<br>' + errorThrown); |
| 42 | + $('#uploadForm').ajaxSubmit({ |
| 43 | + success: function (data, statusText, xhr, $form) { |
| 44 | + resetUploadForm(); |
| 45 | + refreshFoldersAndItems(data); |
| 46 | + }, |
| 47 | + error: function () { |
| 48 | + resetUploadForm(); |
| 49 | + notify('Action failed, due to server error.'); |
60 | 50 | } |
61 | | - } |
62 | | -
|
63 | | - $('#uploadForm').ajaxSubmit(options); |
64 | | - return false; |
| 51 | + }); |
65 | 52 | }); |
66 | 53 |
|
67 | 54 | $('#thumbnail-display').click(function () { |
@@ -108,6 +95,39 @@ function setOpenFolders() { |
108 | 95 | // == Ajax actions == |
109 | 96 | // ==================== |
110 | 97 |
|
| 98 | +function performLfmRequest(url, parameter, type) { |
| 99 | + var data = defaultParameters(); |
| 100 | +
|
| 101 | + if (parameter != null) { |
| 102 | + $.each(parameter, function (key, value) { |
| 103 | + data[key] = value; |
| 104 | + }); |
| 105 | + } |
| 106 | +
|
| 107 | + return $.ajax({ |
| 108 | + type: 'GET', |
| 109 | + dataType: type || 'text', |
| 110 | + url: url, |
| 111 | + data: data, |
| 112 | + cache: false |
| 113 | + }).fail(function () { |
| 114 | + notify('Action failed, due to server error.'); |
| 115 | + }); |
| 116 | +} |
| 117 | +
|
| 118 | +var refreshFoldersAndItems = function (data) { |
| 119 | + if (data == success_response) { |
| 120 | + loadFolders(); |
| 121 | + } else { |
| 122 | + notify(data); |
| 123 | + } |
| 124 | +}; |
| 125 | +
|
| 126 | +var hideNavAndShowEditor = function (data) { |
| 127 | + $('#nav-buttons').addClass('hidden'); |
| 128 | + $('#content').html(data); |
| 129 | +} |
| 130 | +
|
111 | 131 | function loadFolders() { |
112 | 132 | performLfmRequest('{{ route("unisharp.lfm.getFolders") }}', {}, 'html') |
113 | 133 | .done(function (data) { |
@@ -154,37 +174,6 @@ function trash(item_name) { |
154 | 174 | }); |
155 | 175 | } |
156 | 176 |
|
157 | | -function performLfmRequest(url, parameter, type) { |
158 | | - var data = defaultParameters(); |
159 | | -
|
160 | | - if (parameter != null) { |
161 | | - $.each(parameter, function (key, value) { |
162 | | - data[key] = value; |
163 | | - }); |
164 | | - } |
165 | | -
|
166 | | - return $.ajax({ |
167 | | - type: 'GET', |
168 | | - dataType: type || 'text', |
169 | | - url: url, |
170 | | - data: data, |
171 | | - cache: false |
172 | | - }); |
173 | | -} |
174 | | -
|
175 | | -var refreshFoldersAndItems = function (data) { |
176 | | - if (data == 'OK') { |
177 | | - loadFolders(); |
178 | | - } else { |
179 | | - notify(data); |
180 | | - } |
181 | | -}; |
182 | | -
|
183 | | -var hideNavAndShowEditor = function (data) { |
184 | | - $('#nav-buttons').addClass('hidden'); |
185 | | - $('#content').html(data); |
186 | | -} |
187 | | -
|
188 | 177 | function cropImage(image_name) { |
189 | 178 | performLfmRequest('{{ route("unisharp.lfm.getCrop") }}', {img: image_name}) |
190 | 179 | .done(hideNavAndShowEditor); |
|
0 commit comments