How to limit child category depth in expression engine's Control Panel? - expressionengine

Does anyone know if it is possible and how to limit the depth of child categories from the backend (Control Panel) in ExpressionEngine?
The idea is to allow someone to add their own category hierarchy from the Control Panel, but limiting them to 4 child categories, for instance:
All > 5 Star > Entertainment > Movies > Animated
but not this:
All > 5 Star > Entertainment > Movies > Animated > 3D
This is just an example.
Any help would be greatly appreciated.

No, not unless you write your own Extension to tap into EE general display hooks (the category add/edit/listing doesn't have any hooks).
Easiest approach would be to use CP CSS JS add-on and code your own JS to prevent the selection too deep.
Target something like $(".category_field select#parent_id") and if the category parent selection has 32 spaces (4x8) Array(33).join(" ") then don't allow the selection and move up the options until you find an option (category parent) that has less spaces (i.e. isn't as deep).
This might work (untested)...
$(".category_field select#parent_id").change( function() {
var $selected = $(this).children("option:selected")
if ($selected.text().indexOf( Array(33).join(" ") ) >= 0) {
// Too deep
$selected.prevAll().each(function(){
if ($(this).text().indexOf( Array(33).join(" ") ) < 0 ) {
$(this).parent().children('option:selected').removeProp('selected');
$(this).prop('selected', true);
return;
}
});
}
});

Related

CKEDitor: show / hide items by menu group

I have a context menu in CKEditor 4 with many items, that I hide or show based on the divs' classes. I tried to show and hide items by menu group, e.g.
editor.addMenuGroup('odt') ;
editor.addMenuItem('item_1', {
label: 'Item 1',
group: 'odt',
order: 100,
command: command_1,
} ;
// More items follow...
editor.contextMenu.addListener(function(element, selection, path) {
let rv = {} ;
// The following is just an example, my logic is more involved
rv['odt'] = CKEDITOR.TRISTATE_OFF ;
return rv ;
}) ;
This doesn't work, i.e., the items belonging to the group I return from the listener are not added to the menu.
Debugging the problem I found out with surprise that the group field in the menuItems inside the editor is set to the menu order, for example
>> Object.entries(CKEDITOR.instances)[0][1]._.menuItems.item_1.group
100
Digging in the code, I found the following surprising lines in ckeditor4/plugins/menu/plugin.js:
CKEDITOR.menuItem = CKEDITOR.tools.createClass( {
$: function( editor, name, definition ) {
[...]
// Transform the group name into its order number.
this.group = editor._.menuGroups[ this.group ];
Therefore, even without knowing if setting CKEDITOR.TRISTATE_OFF on the group name would work, I know for sure that the group name will not be used.
Am I missing something?
Did anybody ever manage to show / hide menu items in CKEditor 4 by menu groups?
Why the group name is transformed to group order in the internal data???

Extracting Script Information for Web Scraping Code

I managed to isolate this tag shown below and I'm trying to extract the product title, sale price, and stock information as variables.
Its type is class 'bs4.element.Tag'
<script type="text/javascript">
var utag_data = {page_breadcrumb:'Home > Components > Computer Cases > Computer Cases > Fractal Design > Item#:N82E16811352069',
page_tab_name:'Components',
product_category_id:['9'],
product_category_name:['Computer Cases'],
product_subcategory_id:['7'],
product_subcategory_name:['Computer Cases'],
product_id:['11-352-069'],
product_web_id:['N82E16811352069'],
product_title:['Fractal Design Focus G Black ATX Mid Tower Computer Case'],
product_manufacture:['Fractal Design'],
product_sale_price:['99.99'],
product_default_shipping_cost:['12.99'],
product_model:['FD-CA-FOCUS-BK-W'],
product_instock:['1'],
product_group_id:['6055851'],
page_type:'Product',
site_region:'CAN',
site_currency:'CAD',
page_name:'NewProductDetail',
search_scope:jQuery('#haQuickSearchStore option:selected').text(),
user_nvtc:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.NVTC),
user_name:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.LOGIN,'LOGINID6'),
third_party_render:[]
};
var description = Biz.Common.QuickSearch.getUrlSearch('Description');
var d = Biz.Common.QuickSearch.getUrlSearch('d');
if(description)
{
utag_data.search_keyword = description;
}
else if(d)
{
utag_data.search_keyword = d;
}
</script>
I'm having trouble accessing the utag_data. I haven't been able to index the product info using numbers or by calling the header. The contents of the entire script seem to be stored in one entry.
managed to isolate this tag
I'd recommend to apply regex to the isolated tag content.
/utag_data = {([^}]+)};/
The first group will contain the target data:
page_breadcrumb:'Home > Components > Computer Cases > Computer Cases > Fractal Design > Item#:N82E16811352069',\n page_tab_name:'Components',\n product_category_id:['9'],\n product_category_name:['Computer Cases'],\n product_subcategory_id:['7'],\n product_subcategory_name:['Computer Cases'],\n product_id:['11-352-069'],\n product_web_id:['N82E16811352069'],\n product_title:['Fractal Design Focus G Black ATX Mid Tower Computer Case'],\n product_manufacture:['Fractal Design'],\n product_sale_price:['99.99'],\n product_default_shipping_cost:['12.99'],\n product_model:['FD-CA-FOCUS-BK-W'],\n product_instock:['1'],\n product_group_id:['6055851'],\n page_type:'Product',\n site_region:'CAN',\n site_currency:'CAD',\n page_name:'NewProductDetail',\n search_scope:jQuery('#haQuickSearchStore option:selected').text(),\n user_nvtc:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.NVTC),\n user_name:Web.StateManager.Cookies.get(Web.StateManager.Cookies.Name.LOGIN,'LOGINID6'),\n third_party_render:[]\n\n
Then split it by semicolon ; and extract from key-values by splitting by :.

Select UI Element by filtering properties in coded ui

I have a web application. And I am using coded ui to write automated tests to test the application.
I have a dropdown with a text box. Which on entering values in the textbox, the values in the dropdown gets filtered based on the text entered.
If I type inside textbox like 'Admin', I will get below options like this:
And I need to capture the two options displayed.
But using IE Developer tool (F12), I am not able to capture the filtered options, because the options that are displayed do not have any unique property (like this below). And the options that are NOT displayed have a class="hidden" property
Any way to capture the elements that are displayed by applying some kind of filter like 'Select ui elements whose class != hidden'
Thanks in advance!!
HI please try below code will it works for you or not.By traversing all those controls that have class ="hidden"
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
UITestControlCollection collection = mainWindow.FindMatchingControls();
foreach (UITestControl links in collection)
{
HtmlHyperlink mylink = (HtmlHyperlink)links;
Console.WriteLine(mylink.InnerText);
}
I'm not sure there is a way to do it by search properties, but there are other approaches.
One way would be to brute force difference the collections. Find all the list items, then find the hidden ones and do a difference.
HtmlControl listControl = /* find the UL somehow */
HtmlControl listItemsSearch = new HtmlControl(listControl);
listItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
HtmlControl hiddenListItemsSearch = new HtmlControl(listControl);
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
var listItems = listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
You will only be able to iterate this collection one time so if you need to iterate multiple times, create a function that returns this search.
var listItemsFunc = () => listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
foreach(var listItem in listItemsFunc()){
// iterate 1
}
foreach(var listItem in listItemsFunc()){
// iterate 2
}
The other way I would consider doing it would be to filter based on the controls which have a clickable point and take up space on the screen (ie, not hidden).
listItemsSearch.FindMatchingControls().Where(x => {
try { x.GetClickablePoint(); return x.Width > 0 && x.Height > 0; } catch { return false; }
});

How can I change the width of a column in a list view is SharePoint?

I have SharePoint 2007 and I have a list view that has a text field that, when shown with quite a few other fields, is only about 1 word narrow.
Is there a way to expand that column without access to css or other web programming languages?
If you can't use CSS, JavaScript, SharePoint Designer, or deploy any C# code to the server.. then you can't change the width of the column.
Try adding a ContentEditor Web Part with the CSS/JavaScript that sets the look of the column. You don't need C# or Designer.
I did something similar with a search page where I needed a JavaScript function to be triggered so I added a CEWP to the page with the following code (see below).
You could change this to look for the id of the column you want to modify. Just remember that ID's of controls in SharePoint are generated during the page render so you won't necessarily know the exact ID. That is why this code looks for an anchor with an ID that ends with '_PSB_Show', instead of looking for the exact ID.
<script type="text/javascript">
var anchors = document.getElementsByTagName("a");
var anchor;
var j;
// Iterate through all anchors on the page and find the one with ID ending in _PSB_Show
for (j = 0; j < anchors.length; j++)
{
if (anchors[j].id.match(/\_PSB_Show$/) != null)
{
anchor = anchors[j];
break;
}
}
// If the anchor is found and the click is supported in the current browser
// Perform a click after 100 ms
if ((anchor != null) && (anchor.click != null))
{
setTimeout("anchor.click();", 100);
}
</script>

Display text above list if list is empty? (SharePoint 2007)

I have seen a SharePoint list (Custom list) where text shows up, whenever a list is empty (only for some views). E.g. to inform users of the guidelines for the list usage.
How can this be implemented?
Ok with javascript/jquery solution
You can also change the list controls on your view pages into Data Views using SharePoint Designer.
Data Views allow you to set a text when there are no items found:
For changing the message that appears for document libraries using jQuery:
// Change text for uploading documents
var docUploadRegexp = new RegExp();
docUploadRegexp.compile('(.+document\\slibrary\\.)(\\s+To\\screate.+\\.)', 'g');
$('table[class*=ms-listviewtable] > tbody > tr > td > table > tbody > tr > td[class*=ms-vb]:first-child').each(function(i, n) {
var matches = $(n).text().match(docUploadRegexp);
if (matches) {
$(n).html(RegExp.$1);
}
});
(Any suggestions on how to make it nicer very welcome - made community wiki.)
To make this work on a custom list, replace (.+document\\slibrary\\.) with (.+list\\.).

Resources