-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDPA-6253] Added custom previous button for media embed select modal in CKEditor. #87
[SDPA-6253] Added custom previous button for media embed select modal in CKEditor. #87
Conversation
js/embed_media_back_button.js
Outdated
const backButton = $('#entity-embed-dialog-tide-media-browser-home') | ||
$(document).ready(function () { | ||
// Remove the name field value on modal first load if any. | ||
localStorage.removeItem("tideMediaBrowsernameFilterVal"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this localstorage get emptied everytime the embed form loads for the first time, so that on first load the name filter field goes back to empty state
js/embed_media_back_button.js
Outdated
// Remove the name field value on modal first load if any. | ||
localStorage.removeItem("tideMediaBrowsernameFilterVal"); | ||
$("iframe").on("load", function() { | ||
if ($("iframe") && $("iframe").length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there can be multiple iframe loaded in a single page, so this will make sure if there are multiple iframe it will check it is targeting the correct one
js/embed_media_back_button.js
Outdated
iframePath = $("iframe")[1].contentWindow.location.pathname | ||
// Shows the back button when iframe is not in the first page. | ||
if (iframePath && iframePath !== homePagePath) { | ||
backButton.css("display", "block"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only display the previous button if it is not the first page
js/embed_media_back_button.js
Outdated
// Trigger ajax call submit to retrive the user search for current session. | ||
// Will only trigger if there is any filter value set for this session. | ||
if (checkFilterValuesOnLoad (itemName, licenseType, mediaType, published, site)) { | ||
$(this).contents().find('#edit-submit-tide-media-browser').trigger('click'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the filter search for media items is a ajax callback, for this reason, when going back to the first page if there are any filter values it will retrieve that but it won't retrieve the search results, this will make sure that if there are any pre-selected values in the filter, it will just trigger ajax callback to get the search results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on empty values it won't get triggered
}) | ||
} | ||
}; | ||
}(jQuery, Drupal)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a separate js to manipulate the name filter field. This only gets loaded when the view gets loaded
js/embed_media_iframe_form.js
Outdated
Drupal.behaviors.tide_media_media_form = { | ||
attach: function (context, settings) { | ||
let nameField = $('#views-exposed-form-tide-media-browser-media-browser input[name=name]') | ||
const fromSubmit = $('#views-exposed-form-tide-media-browser-media-browser input[type=submit]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formSubmit
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is one let
and one const
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- here the
formSubmit
is view filter selection "Apply" button. So every time user hits the Apply button it checks the name field saves the user input value in the localStorage - it should be const, it is a mistake, fixing it now, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, was just about the spelling... you have fromSubmit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, fixing it 👍
js/embed_media_back_button.js
Outdated
} | ||
// Get the filter values on iframe load. | ||
itemName = $(this).contents().find('#edit-name').val() | ||
licenseType = $(this).contents().find('#edit-field-license-type-target-id-1 :selected').text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing this saved in local storage. Think your selector might not be quite right for all but the name field. e.g. this license type has this HTML:
<select data-drupal-selector="edit-field-license-type-target-id-1" id="edit-field-license-type-target-id-1--1_-ORPXVgy4" name="field_license_type_target_id_1" class="form-select">
Your id is edit-field-license-type-target-id-1--1_-ORPXVgy4
which looks a bit random. You might need to find the name attribute seems more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The filter values except for name field doesn't need to be saved in local storage and coming back to the first page the selection remains the same. Only the namefield value needs to be stored.
- so looks like JQuery can target partial id, got the idea from here - https://stackoverflow.com/questions/37300558/how-to-select-elements-using-jquery-by-partial-id-and-a-class-at-the-same-time
and this scenario it works as well and targets the partial id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @anthony-malkoun the drop down saves fine when I tried in the testing PR now. See the attached steps I followed - live media embed demo.webm
Hmm, that's not quite what I'm seeing. If I have some filters applied, view an item and hit previous, I go back to the listing (at page 1) and the filters are selected but I have to hit apply again to get them active. Is this as expected?
Create.Landing.Page._.Single.Digital.Presence.Content.Management.System.and.22.more.pages.-.Personal.-.Microsoft.Edge.2022-07-12.09-08-47.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MdNadimHossain a few little issues I reckon. Doesn't seem to be saving the drop down filter elements because the id
seems to not be what you're expecting.
Also, should we be saving what page we're at? I feel that if I've navigated through to other pages, then clicking Previous
shouldn't take you back to page 1.
Hey @anthony-malkoun the drop down saves fine when I tried in the testing PR now. See the attached steps I followed - |
OK, I'm not convinced that going back to the first page is what they will want. If I've navigated to page 10 say, and I look at the image and it's not what I want, then I don't want to go back to page 1 and start my search again IMO. Are you saying this functionality is phase 2? |
Hey @anthony-malkoun I have tried this feature to work out, but couldn't work it out for this. So when it changes the pagination the location path of the iframe doesn't change, so there is nothing to trigger an event to retrieve the pagination state of the user. |
JIRA
https://digital-engagement.atlassian.net/browse/SDPA-6253
Changes
Related PRs -
Testing PR - https://github.com/dpc-sdp/content-reference-sdp-vic-gov-au/pull/101
Link - https://nginx-php.pr-101.content-reference-sdp-vic-gov-au.sdp2.sdp.vic.gov.au/
Screenshots