Skip to content
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

Merged

Conversation

MdNadimHossain
Copy link
Contributor

@MdNadimHossain MdNadimHossain commented Jul 5, 2022

JIRA

https://digital-engagement.atlassian.net/browse/SDPA-6253

Changes

  1. Added a new form field as previous link in the embed media select step and made it hidden by default, so that it does not show up for the 1st page load
  2. Added js to manipulate the embed media form select step on CKEditor
  3. The first js gets loaded only when the CKEditor and iframe gets loaded and the 2nd one gets loaded with the view

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

Screen Shot 2022-07-11 at 10 52 51 am
Screen Shot 2022-07-11 at 10 53 01 am

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");
Copy link
Contributor Author

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

// Remove the name field value on modal first load if any.
localStorage.removeItem("tideMediaBrowsernameFilterVal");
$("iframe").on("load", function() {
if ($("iframe") && $("iframe").length > 0) {
Copy link
Contributor Author

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

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");
Copy link
Contributor Author

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

// 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');
Copy link
Contributor Author

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

Copy link
Contributor Author

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));
Copy link
Contributor Author

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

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]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formSubmit?

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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
  2. it should be const, it is a mistake, fixing it now, thanks

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, fixing it 👍

}
// 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()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.
  2. 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

Copy link
Contributor

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

Copy link
Contributor

@anthony-malkoun anthony-malkoun left a 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.

@MdNadimHossain
Copy link
Contributor Author

MdNadimHossain commented Jul 11, 2022

@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 -
live media embed demo.webm
Also the previous button works as the back button of a browser, so if the user journey continues, the user can click through to reach to the first page, which is the home page of the modal. But there will be a 2nd phase of this story, where user can select an item when they are viewing the media item. So in that 2nd phase, my idea to stop the user navigate through after first level. So once they go to a different page from the home page, they shouldn't be able to click through from the 2nd page. Cause the whole idea of going to the media page from the modal is to just view the item and if user is satisfied then add it or go back to home page add it.

@anthony-malkoun
Copy link
Contributor

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?

@MdNadimHossain
Copy link
Contributor Author

MdNadimHossain commented Jul 20, 2022

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.
We can track the pagination number on user click and if it is not the first page it will trigger the click when a user goes back. But it becomes ugly cause it triggers so many ajax call. E.g - An user is in the 3rd page of pagination -> goes to different link -> clicks "previous" link -> 1 - "Apply" button triggered 2. pagination triggered to go to 2nd page 3. pagination triggered to go to 3rd page . So 3 ajax call. which doesn't look right
I have informed Leslie about the drawback of this feature and she is fine with it. I have added comment and video demo in the ticket as well for future reference. - https://digital-vic.atlassian.net/browse/SDPAP-6343

@MdNadimHossain MdNadimHossain merged commit 88a812a into develop Aug 17, 2022
@MdNadimHossain MdNadimHossain deleted the feature/SDPA-6253-media-library-inspect-item-improvements branch August 17, 2022 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants