Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Wagtail Videos
Commits
acc454bc
Commit
acc454bc
authored
Jul 05, 2019
by
Seb
Browse files
Start of js changes to update modal_workflow
parent
3fbae328
Changes
6
Hide whitespace changes
Inline
Side-by-side
wagtailvideos/
templates
/wagtailvideos/
chooser/
chooser.js
→
wagtailvideos/
static
/wagtailvideos/
js/video-
chooser
-modal
.js
View file @
acc454bc
{
%
load
i18n
%
}
VIDEO_CHOOSER_MODAL_ONLOAD_HANDLERS
=
{
function
(
modal
)
{
'
chooser
'
:
function
(
modal
,
jsonData
)
{
var
searchUrl
=
$
(
'
form.video-search
'
,
modal
.
body
).
attr
(
'
action
'
);
var
searchUrl
=
$
(
'
form.video-search
'
,
modal
.
body
).
attr
(
'
action
'
);
/* currentTag stores the tag currently being filtered on, so that we can
/* currentTag stores the tag currently being filtered on, so that we can
...
@@ -69,12 +69,10 @@ function(modal) {
...
@@ -69,12 +69,10 @@ function(modal) {
modal
.
loadResponseText
(
response
);
modal
.
loadResponseText
(
response
);
},
},
error
:
function
(
response
,
textStatus
,
errorThrown
)
{
error
:
function
(
response
,
textStatus
,
errorThrown
)
{
{
%
trans
"
Server Error
"
as
error_label
%
}
message
=
jsonData
[
'
error_message
'
]
+
'
<br />
'
+
errorThrown
+
'
-
'
+
response
.
status
;
{
%
trans
"
Report this error to your webmaster with the following information:
"
as
error_message
%
}
$
(
'
#upload
'
).
append
(
message
=
'
{{ error_message|escapejs }}<br />
'
+
errorThrown
+
'
-
'
+
response
.
status
;
'
<div class="help-block help-critical">
'
+
$
(
'
#upload
'
).
append
(
'
<strong>
'
+
jsonData
[
'
error_label
'
]
+
'
: </strong>
'
+
message
+
'
</div>
'
);
'
<div class="help-block help-critical">
'
+
'
<strong>{{ error_label|escapejs }}: </strong>
'
+
message
+
'
</div>
'
);
}
}
});
});
...
@@ -98,11 +96,13 @@ function(modal) {
...
@@ -98,11 +96,13 @@ function(modal) {
});
});
return
false
;
return
false
;
});
});
{
%
url
'
wagtailadmin_tag_autocomplete
'
as
autocomplete_url
%
}
/* Add tag entry interface (with autocompletion) to the tag field of the image upload form */
/* Add tag entry interface (with autocompletion) to the tag field of the image upload form */
$
(
'
#id_tags
'
,
modal
.
body
).
tagit
({
// $('#id_tags', modal.body).tagit({
autocomplete
:
{
source
:
"
{{ autocomplete_url|addslashes }}
"
}
// autocomplete: {source: "{{ autocomplete_url|addslashes }}"}
});
// });
},
'
video_chosen
'
:
function
(
modal
,
jsonData
)
{
modal
.
respond
(
'
videoChosen
'
,
jsonData
[
'
result
'
]);
modal
.
close
();
},
}
}
wagtailvideos/static/wagtailvideos/js/video-chooser.js
View file @
acc454bc
...
@@ -7,6 +7,7 @@ function createVideoChooser(id) {
...
@@ -7,6 +7,7 @@ function createVideoChooser(id) {
$
(
'
.action-choose
'
,
chooserElement
).
click
(
function
()
{
$
(
'
.action-choose
'
,
chooserElement
).
click
(
function
()
{
ModalWorkflow
({
ModalWorkflow
({
url
:
window
.
chooserUrls
.
videoChooser
,
url
:
window
.
chooserUrls
.
videoChooser
,
onload
:
VIDEO_CHOOSER_MODAL_ONLOAD_HANDLERS
,
responses
:
{
responses
:
{
videoChosen
:
function
(
videoData
)
{
videoChosen
:
function
(
videoData
)
{
input
.
val
(
videoData
.
id
);
input
.
val
(
videoData
.
id
);
...
...
wagtailvideos/templates/wagtailvideos/chooser/video_chosen.js
deleted
100644 → 0
View file @
3fbae328
function
(
modal
)
{
modal
.
respond
(
'
videoChosen
'
,
{{
video_json
|
safe
}});
modal
.
close
();
}
wagtailvideos/views/chooser.py
View file @
acc454bc
...
@@ -6,6 +6,7 @@ from wagtail.admin.forms.search import SearchForm
...
@@ -6,6 +6,7 @@ from wagtail.admin.forms.search import SearchForm
from
wagtail.admin.modal_workflow
import
render_modal_workflow
from
wagtail.admin.modal_workflow
import
render_modal_workflow
from
wagtail.admin.utils
import
PermissionPolicyChecker
,
popular_tags_for_model
from
wagtail.admin.utils
import
PermissionPolicyChecker
,
popular_tags_for_model
from
wagtail.core.models
import
Collection
from
wagtail.core.models
import
Collection
from
wagtail.images.views.chooser
import
get_chooser_js_data
from
wagtail.search
import
index
as
search_index
from
wagtail.search
import
index
as
search_index
from
wagtail.utils.pagination
import
paginate
from
wagtail.utils.pagination
import
paginate
...
@@ -22,14 +23,14 @@ def get_video_json(video):
...
@@ -22,14 +23,14 @@ def get_video_json(video):
image chooser panel
image chooser panel
"""
"""
return
json
.
dumps
(
{
return
{
'id'
:
video
.
id
,
'id'
:
video
.
id
,
'edit_link'
:
reverse
(
'wagtailvideos:edit'
,
args
=
(
video
.
id
,)),
'edit_link'
:
reverse
(
'wagtailvideos:edit'
,
args
=
(
video
.
id
,)),
'title'
:
video
.
title
,
'title'
:
video
.
title
,
'preview'
:
{
'preview'
:
{
'url'
:
video
.
thumbnail
.
url
if
video
.
thumbnail
else
''
,
'url'
:
video
.
thumbnail
.
url
if
video
.
thumbnail
else
''
,
}
}
}
)
}
def
chooser
(
request
):
def
chooser
(
request
):
...
@@ -79,7 +80,7 @@ def chooser(request):
...
@@ -79,7 +80,7 @@ def chooser(request):
paginator
,
videos
=
paginate
(
request
,
videos
,
per_page
=
12
)
paginator
,
videos
=
paginate
(
request
,
videos
,
per_page
=
12
)
return
render_modal_workflow
(
request
,
'wagtailvideos/chooser/chooser.html'
,
'wagtailvideos/chooser/chooser.js'
,
{
return
render_modal_workflow
(
request
,
'wagtailvideos/chooser/chooser.html'
,
None
,
{
'videos'
:
videos
,
'videos'
:
videos
,
'uploadform'
:
uploadform
,
'uploadform'
:
uploadform
,
'searchform'
:
searchform
,
'searchform'
:
searchform
,
...
@@ -87,16 +88,17 @@ def chooser(request):
...
@@ -87,16 +88,17 @@ def chooser(request):
'query_string'
:
q
,
'query_string'
:
q
,
'popular_tags'
:
popular_tags_for_model
(
Video
),
'popular_tags'
:
popular_tags_for_model
(
Video
),
'collections'
:
collections
,
'collections'
:
collections
,
})
}
,
json_data
=
get_chooser_js_data
()
)
def
video_chosen
(
request
,
video_id
):
def
video_chosen
(
request
,
video_id
):
video
=
get_object_or_404
(
Video
,
id
=
video_id
)
video
=
get_object_or_404
(
Video
,
id
=
video_id
)
return
render_modal_workflow
(
return
render_modal_workflow
(
request
,
None
,
'wagtailvideos/chooser/video_chosen.js'
,
request
,
None
,
json_data
=
{
{
'video_json'
:
get_video_json
(
video
)}
'step'
:
'video_chosen'
,
)
'result'
:
get_video_json
(
video
)
})
@
permission_checker
.
require
(
'add'
)
@
permission_checker
.
require
(
'add'
)
...
...
wagtailvideos/wagtail_hooks.py
View file @
acc454bc
from
django.conf.urls
import
include
,
url
from
django.conf.urls
import
include
,
url
from
django.contrib.staticfiles.templatetags.staticfiles
import
static
from
django.urls
import
reverse
from
django.urls
import
reverse
from
django.utils.html
import
format_html
,
format_html_join
from
django.utils.html
import
format_html
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
wagtail.admin.menu
import
MenuItem
from
wagtail.admin.menu
import
MenuItem
from
wagtail.core
import
hooks
from
wagtail.core
import
hooks
...
@@ -19,14 +18,7 @@ def register_admin_urls():
...
@@ -19,14 +18,7 @@ def register_admin_urls():
@
hooks
.
register
(
'insert_editor_js'
)
@
hooks
.
register
(
'insert_editor_js'
)
def
editor_js
():
def
editor_js
():
js_files
=
[
return
format_html
(
static
(
'wagtailvideos/js/video-chooser.js'
),
]
js_includes
=
format_html_join
(
'
\n
'
,
'<script src="{0}"></script>'
,
((
filename
,
)
for
filename
in
js_files
)
)
return
js_includes
+
format_html
(
"""
"""
<script>
<script>
window.chooserUrls.videoChooser = '{0}';
window.chooserUrls.videoChooser = '{0}';
...
...
wagtailvideos/widgets.py
View file @
acc454bc
...
@@ -30,3 +30,9 @@ class AdminVideoChooser(AdminChooser):
...
@@ -30,3 +30,9 @@ class AdminVideoChooser(AdminChooser):
def
render_js_init
(
self
,
id_
,
name
,
value
):
def
render_js_init
(
self
,
id_
,
name
,
value
):
return
"createVideoChooser({0});"
.
format
(
json
.
dumps
(
id_
))
return
"createVideoChooser({0});"
.
format
(
json
.
dumps
(
id_
))
class
Media
:
js
=
[
'wagtailvideos/js/video-chooser-modal.js'
,
'wagtailvideos/js/video-chooser.js'
,
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment