0001-assets-use-assets-views-instead-of-ckeditor-browser-.patch
combo/apps/assets/templates/combo/manager_assets_browse.html | ||
---|---|---|
1 |
{% extends "gadjo/base.html" %} |
|
2 |
{% load staticfiles i18n %} |
|
3 | ||
4 |
{% block css %} |
|
5 |
<link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/combo.manager.css"/> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block extrascripts %} |
|
9 |
<script src="{% static "js/combo.manager.js" %}"></script> |
|
10 |
{% endblock %} |
|
11 | ||
12 |
{% block user-links %}{% endblock %} |
|
13 |
{% block sidepage %}{% endblock %} |
|
14 |
{% block site-header %}{% endblock %} |
|
15 |
{% block footer %}{% endblock %} |
|
16 | ||
17 |
{% block appbar %} |
|
18 |
<h2>{% trans "Browse for the file you want, then click 'Embed File' to continue..." %}</h2> |
|
19 |
{% endblock %} |
|
20 | ||
21 |
{% block content %} |
|
22 | ||
23 |
{% if not object_list and not query %} |
|
24 |
<div class="big-msg-info"> |
|
25 |
{% trans "No files found. Upload files using the 'Image Button' or 'Link Button' dialog's 'Upload' tab." %} |
|
26 |
</div> |
|
27 | ||
28 |
{% else %} |
|
29 | ||
30 |
<form> |
|
31 |
{% for k, v in request.GET.items %} |
|
32 |
{% if k != 'q' %}<input type="hidden" name="{{ k }}" value="{{ v }}" />{% endif %} |
|
33 |
{% endfor %} |
|
34 |
<p><input name="q" type="search" value="{{query}}"> <button>{% trans 'Search' %}</button> |
|
35 |
<span class="help_text">{% trans "(case insensitive search over filenames)" %}</span> |
|
36 |
</p> |
|
37 |
</form> |
|
38 | ||
39 |
<div id="assets-browser" class="assets-ckeditor"> |
|
40 |
<div id="assets-listing"> |
|
41 |
{% with asset_for_ckeditor=True %} |
|
42 |
{% include "combo/manager_assets_fragment.html" %} |
|
43 |
{% endwith %} |
|
44 |
</div> |
|
45 |
<div id="asset-preview"></div> |
|
46 |
</div> |
|
47 |
<input href="" id="asset-ckeditor-embed" type="submit" name="_embed" value="{% trans "Embed File" %}" disabled /> |
|
48 | ||
49 |
{% include "gadjo/pagination.html" %} |
|
50 | ||
51 |
{% endif %} |
|
52 |
<script type="text/javascript"> |
|
53 |
// helper functions |
|
54 |
function getUrlParam(paramName) { |
|
55 |
var reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i') ; |
|
56 |
var match = window.location.search.match(reParam) ; |
|
57 | ||
58 |
return (match && match.length > 1) ? match[1] : '' ; |
|
59 |
} |
|
60 | ||
61 |
// embedder |
|
62 |
$(document).on('click', '#asset-ckeditor-embed', function() { |
|
63 |
var funcNum = getUrlParam('CKEditorFuncNum'); |
|
64 |
var fileUrl = $(this).attr('href'); |
|
65 |
console.log(funcNum) |
|
66 |
console.log(fileUrl) |
|
67 |
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl); |
|
68 |
window.close(); |
|
69 |
}); |
|
70 |
console.log(window.opener.CKEDITOR) |
|
71 |
</script> |
|
72 |
{% endblock %} |
combo/apps/assets/templates/combo/manager_assets_fragment.html | ||
---|---|---|
5 | 5 |
<th>{% trans "Name" %}</th> |
6 | 6 |
<th>{% trans "Size" %}</th> |
7 | 7 |
<th></th> |
8 |
{% if not asset_for_ckeditor %} |
|
8 | 9 |
<th></th> |
10 |
{% endif %} |
|
9 | 11 |
</tr> |
10 | 12 |
</thead> |
11 | 13 |
<tbody> |
12 | 14 |
{% for asset in object_list %} |
13 |
<tr class="{{ asset.css_classes }}"> |
|
14 |
<td><a href="{{ asset.src }}">{{ asset.name }}</a></td>
|
|
15 |
<tr class="{{ asset.css_classes }}" data-href="{{ asset.src }}">
|
|
16 |
<td>{% if not asset_for_ckeditor %}<a href="{{ asset.src }}">{{ asset.name }}</a>{% else %}{{ asset.name }}{% endif %}</td>
|
|
15 | 17 |
<td>{% if asset.size %}{{ asset.size|filesizeformat }}{% else %}-{% endif %}</td> |
16 | 18 |
<td class="image">{% if asset.is_image %}<img data-href="{{ asset.src }}" src="{{ asset.thumb }}"/>{% endif %}</td> |
19 |
{% if not asset_for_ckeditor %} |
|
17 | 20 |
<td class="actions"> |
18 | 21 |
{% if asset.key %}{# theme asset #} |
19 | 22 |
<a href="{% url 'combo-manager-slot-asset-upload' key=asset.key %}{% if cell_reference %}?cell_reference={{ cell_reference }}{% endif %}" |
... | ... | |
29 | 32 |
class="delete" rel="popup">{% trans 'Delete' %}</a> |
30 | 33 |
{% endif %} |
31 | 34 |
</td> |
35 |
{% endif %} |
|
32 | 36 |
</tr> |
33 | 37 |
{% endfor %} |
34 | 38 |
</tbody> |
combo/apps/assets/views.py | ||
---|---|---|
119 | 119 |
template_name = 'combo/manager_assets.html' |
120 | 120 |
paginate_by = 10 |
121 | 121 | |
122 |
def get_files(self): |
|
123 |
return list(SlotAsset.get_assets()) + CkEditorAsset.get_assets(self.request) |
|
124 | ||
122 | 125 |
def get_queryset(self): |
123 |
files = list(SlotAsset.get_assets()) + CkEditorAsset.get_assets(self.request)
|
|
126 |
files = self.get_files()
|
|
124 | 127 |
q = self.request.GET.get('q') |
125 | 128 |
if q: |
126 | 129 |
files = [x for x in files if q.lower() in x.name.lower()] |
... | ... | |
142 | 145 |
return url + '?page=%s' % ((i // self.paginate_by) + 1) |
143 | 146 |
return url |
144 | 147 | |
148 | ||
145 | 149 |
assets = Assets.as_view() |
146 | 150 | |
147 | 151 | |
152 |
class AssetsBrowse(Assets): |
|
153 |
template_name = 'combo/manager_assets_browse.html' |
|
154 | ||
155 |
def get_files(self): |
|
156 |
return CkEditorAsset.get_assets(self.request) |
|
157 | ||
158 | ||
159 |
browse = AssetsBrowse.as_view() |
|
160 | ||
161 | ||
148 | 162 |
class AssetUpload(FormView): |
149 | 163 |
form_class = AssetUploadForm |
150 | 164 |
template_name = 'combo/manager_asset_upload.html' |
combo/manager/static/js/combo.manager.js | ||
---|---|---|
284 | 284 |
$(this).addClass('untoggled'); |
285 | 285 |
} |
286 | 286 |
}); |
287 |
$('#assets-browser table tr').on('hover mouseenter', function() { |
|
288 |
var $img = $(this).find('img'); |
|
287 | ||
288 |
function show_asset($elem) { |
|
289 |
var $img = $elem.find('img'); |
|
289 | 290 |
if ($img.data('href')) { |
290 | 291 |
$('#asset-preview').empty().append($('<img src="' + $img.data('href') + '"/>')); |
291 | 292 |
} else { |
292 | 293 |
$('#asset-preview').empty(); |
293 | 294 |
} |
294 | 295 |
return true; |
295 |
}).on('mouseleave', function() { |
|
296 |
$('#asset-preview').empty(); |
|
297 |
}); |
|
296 |
} |
|
297 |
if ($('#assets-browser.assets-ckeditor').length) { |
|
298 |
$('#assets-browser table tr').on('click', function() { |
|
299 |
$('#assets-browser table tr').removeClass('active'); |
|
300 |
$(this).addClass('active'); |
|
301 |
show_asset($(this)); |
|
302 |
$('#asset-ckeditor-embed').attr('href', $(this).data('href')).prop('disabled', false); |
|
303 |
}); |
|
304 |
} else { |
|
305 |
$('#assets-browser table tr').on('hover mouseenter', function() { |
|
306 |
show_asset($(this)); |
|
307 |
}).on('mouseleave', function() { |
|
308 |
$('#asset-preview').empty(); |
|
309 |
}); |
|
310 |
} |
|
298 | 311 |
$('.manager-add-new-cell a').on('click', function() { |
299 | 312 |
$(this).next().toggle(); |
300 | 313 |
return false; |
combo/manager/urls.py | ||
---|---|---|
20 | 20 | |
21 | 21 |
import ckeditor.views as ckeditor_views |
22 | 22 | |
23 |
from combo.apps.assets import views as assets_views |
|
23 | 24 |
from .. import plugins |
24 | 25 |
from . import views |
25 | 26 | |
... | ... | |
94 | 95 |
name='combo-manager-page-order'), |
95 | 96 |
url(r'^ckeditor/upload/', staff_member_required(ckeditor_views.upload), |
96 | 97 |
name='ckeditor_upload'), |
97 |
url(r'^ckeditor/browse/', never_cache(staff_member_required(ckeditor_views.browse)),
|
|
98 |
url(r'^ckeditor/browse/', never_cache(staff_member_required(assets_views.browse)),
|
|
98 | 99 |
name='ckeditor_browse'), |
99 | 100 |
] |
100 | 101 |
tests/test_manager.py | ||
---|---|---|
1041 | 1041 |
app.get('/logout/') |
1042 | 1042 |
assert app.get('/manage/', status=302).location.endswith('/login/?next=/manage/') |
1043 | 1043 | |
1044 | ||
1044 | 1045 |
def test_asset_management(app, admin_user): |
1045 | 1046 |
app = login(app) |
1046 | 1047 |
resp = app.get('/manage/assets/') |
... | ... | |
1099 | 1100 |
resp = resp.form.submit().follow() |
1100 | 1101 |
assert 'have any asset yet.' in resp.text |
1101 | 1102 | |
1103 | ||
1102 | 1104 |
def test_asset_management_anchor(app, admin_user): |
1103 | 1105 |
app = login(app) |
1104 | 1106 |
resp = app.get('/manage/assets/') |
... | ... | |
1134 | 1136 |
resp = resp.follow() |
1135 | 1137 |
assert 'test.png' not in resp.text |
1136 | 1138 | |
1139 | ||
1137 | 1140 |
def test_asset_management_search(app, admin_user): |
1138 | 1141 |
app = login(app) |
1139 | 1142 | |
... | ... | |
1156 | 1159 |
assert resp.text.count('<tr class="asset') == 2 |
1157 | 1160 | |
1158 | 1161 | |
1162 |
def test_assets_browse(app, admin_user): |
|
1163 |
app = login(app) |
|
1164 | ||
1165 |
resp = app.get('/manage/ckeditor/browse/?CKEditor=foo&CKEditorFuncNum=0') |
|
1166 |
assert 'No files found' in resp.text |
|
1167 | ||
1168 |
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'aa.png') |
|
1169 |
pix = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVQI12NoAAAAggCB3UNq9AAAAABJRU5ErkJggg==' |
|
1170 |
default_storage.save(filepath, BytesIO(base64.decodebytes(pix))) |
|
1171 |
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'bb.pdf') |
|
1172 |
pix = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVQI12NoAAAAggCB3UNq9AAAAABJRU5ErkJggg==' |
|
1173 |
default_storage.save(filepath, BytesIO(base64.decodebytes(pix))) |
|
1174 |
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'cc.png') |
|
1175 |
pix = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVQI12NoAAAAggCB3UNq9AAAAABJRU5ErkJggg==' |
|
1176 |
default_storage.save(filepath, BytesIO(base64.decodebytes(pix))) |
|
1177 | ||
1178 |
resp = app.get('/manage/ckeditor/browse/?CKEditor=foo&CKEditorFuncNum=0') |
|
1179 |
assert 'No files found' not in resp.text |
|
1180 | ||
1181 |
resp.form['q'] = 'test' |
|
1182 |
resp = resp.form.submit() |
|
1183 |
assert 'CKEditor=foo' in resp.request.url |
|
1184 |
assert 'CKEditorFuncNum=0' in resp.request.url |
|
1185 |
assert resp.text.count('<tr class="asset') == 0 |
|
1186 | ||
1187 |
resp.form['q'] = 'png' |
|
1188 |
resp = resp.form.submit() |
|
1189 |
assert 'CKEditor=foo' in resp.request.url |
|
1190 |
assert 'CKEditorFuncNum=0' in resp.request.url |
|
1191 |
assert resp.text.count('<tr class="asset') == 2 |
|
1192 | ||
1193 |
for i in range(25): |
|
1194 |
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'cc.png') |
|
1195 |
pix = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVQI12NoAAAAggCB3UNq9AAAAABJRU5ErkJggg==' |
|
1196 |
default_storage.save(filepath, BytesIO(base64.decodebytes(pix))) |
|
1197 |
resp = app.get('/manage/ckeditor/browse/?CKEditor=foo&CKEditorFuncNum=0') |
|
1198 |
resp = resp.click(href='.*page=2.*') |
|
1199 |
assert 'CKEditor=foo' in resp.request.url |
|
1200 |
assert 'CKEditorFuncNum=0' in resp.request.url |
|
1201 | ||
1202 | ||
1159 | 1203 |
def test_asset_slots_management(app, admin_user): |
1160 | 1204 |
app = login(app) |
1161 | 1205 |
assert Asset.objects.count() == 0 |
1162 |
- |