Jump to content
Sign in to follow this  
SharQ

InputfieldSelector for multiple pages in lister module

Recommended Posts

Hi, 

I've been trying to figure this out for two days now, but I cant seem to solve the issue without core modification, which is not the good way to go for sure. 

  • I have nested hidden pages under a page called groups, and
  • I customised the page lister module a bit extending the ProcessUser class (called processOffers)
  • I have a custom JSTree module to select from these groups, so multiple selection is possible.

My problem is,when click on the filters, and select groups in the lister module, I can see only the first level (which is a parent directory), but not the nested ones what I need. 

I tried to catch the ajax call in my processOffers module, but seems like the control never reach my module, instead it goes to the InputfieldSelector::renderOpval straight, so I have no way to override it or write a hook or anything. 

One thing I noticed is if I copy the ajax query and paste it into my browser url, it invokes my processOffers class, but it doesn't do it if I do it via ajax!
( ...backend/offers/?InputfieldSelector=opval&field=groups&type=&name=filters)

 > Update: Okay, so this one is because of the X-Requested-With:XMLHttpRequest header. 

How could I list the nested pages as a flat list or

how could I interact with this ajax call to override the result? 

Share this post


Link to post
Share on other sites

Okay.... With this, I can override the output in my module. :)

/**
 * ProcessWire Selector Inputfield JS - Override
 *
 * ProcessWire 2.x
 * Copyright (C) 2015 by Ryan Cramer
 * This file licensed under Mozilla Public License v2.0 http://mozilla.org/MPL/2.0/
 *
 * https://processwire.com
 *
 */


$(document).ready(function() {
    
    if( InputfieldSelector ){
    
        //disable XHR header on these fields
        InputfieldSelector.noXHR = ['groups'];

        //disable XHR header
        InputfieldSelector.removeXHR = function(){
            $.ajaxSettings.beforeSend=function(xhr){
                xhr.setRequestHeader('X-Requested-With', {toString: function(){ return ''; }});
            };
        }

        //enable XHR header
        InputfieldSelector.addXHR = function(){
            $.ajaxSettings.beforeSend=function(xhr){
                xhr.setRequestHeader('X-Requested-With', {toString: function(){ return 'XMLHttpRequest'; }});
            };
        }

        //override changefield function
        InputfieldSelector.changeField = function($select) {

            //console.log('changeField'); 
            var $select = $(this); 
            var field = $select.val();
            if(!field || field.length == 0) return;
            if(field == 'toggle-names-labels') return InputfieldSelector.changeFieldToggle($select);
            var $row = $select.parents('.selector-row'); 
            var action = 'opval';
            $row.children('.opval').html(''); 
            $select.attr('data-selected', field); // so we can remember previous value

            var $hiddenInput = $select.parents('.InputfieldSelector').find('.selector-value'); // .selector-value intentional!
            var name = $hiddenInput.attr('name'); 
            var type = $select.attr('data-type'); 

            if(field.match(/\.$/)) {
                action = 'subfield';
                if(field.indexOf('@') > -1) field = field.substring(1, field.length-1); 
                    else field = field.substring(0, field.length-1); 
                $row.addClass('has-subfield'); 
            } else if(field.match(/\.id$/)) {
                field = 'id';
                action = 'opval';
                type = 'selector';
            } else if($select.is(".select-field")) { 
                $row.children('.subfield').html(''); 
                $row.removeClass('has-subfield'); 
            }

            //on certain fields disable XHR
            if( -1 != InputfieldSelector.noXHR.indexOf(field) ){
                InputfieldSelector.removeXHR();
            }

            var url = './?InputfieldSelector=' + action + '&field=' + field + '&type=' + type + '&name=' + name; 
            var $spinner = $(InputfieldSelector.spinner); 

            $row.append($spinner); 

            $.get(url, function(data) {	
                $spinner.remove();
                var $data = $(data); 
                $data.hide();

                if(action == 'opval') {
                    var $opval = $row.children('.opval'); 
                    $opval.html('').append($data);
                    $opval.children(':not(.input-or)').fadeIn('fast'); 

                    //$data.fadeIn('fast');
                    InputfieldSelector.changeAny($select);
                    var $ac = $opval.find(".input-value-autocomplete"); 
                    if($ac.length > 0) InputfieldSelector.setupAutocomplete($ac, field, name); 
                } else {
                    var $subfield = $row.children('.subfield');
                    $subfield.html('').append($data); 
                    $data.fadeIn('fast'); 
                    //$row.children('.subfield').html(data); 	
                }

                InputfieldSelector.normalizeHeightRow($row); 

                //ensure to add XHR back in
                InputfieldSelector.addXHR();

                // this ensures that datepickers don't get confused with each other
                $row.closest('.InputfieldContent').find(".hasDatepicker").datepicker('destroy').removeAttr('id').removeClass('hasDatepicker'); 
            }); 
        };
    
    }
    
}); 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MarkE
      I have been making use of the ProcessPageLister::addSessionBookmark() method to create drill-downs of financial data in a table - so that the user can see the pages comprising the amount in the table cell. This works really well and has been well-received by the client. However, I soon ran into a problem in that the method sets $maxBookmarks = 30;  hard-coded just like that. I changed the code to $maxBookmarks = 400; and haven't noticed any ill-effects so far, so some questions arise:
      Why is it hard-coded rather than modifiable? If the answer to (1) is because too many bookmarks cause a problem, what is the problem? If there is no particular problem with more than 30 bookmarks, is there any other practical limit? Clearly changing the code in my copy of PW is not a good idea as it will get over-written at the next update. Is there a way of dealing with this until (if ever) the variable can be modified through the API?
    • By benbyf
      Hi, Looking to create form elements on a page–some input with a colection of form inputs and the appropriate labels and variables for that input. I've used ProForms in the past and rolled out my own when creating simply one off forms, but I wonder if anyone has found a good way of allowing form creation on page editing so that clients can adhocly make and edit forms?
      Thanks
    • By MarkE
      I am using InputfieldSelector in a custom module. I would like to pre-populate it based on a PW selector (e.g. "template=Booking, bookableSlotPage=8527, bookableSlotPage.tickets>0"). Using initValue will pre-select the template, but I would also like to have the initial display show the field filters as well. Is there a way of doing this in PW or do I need to devise some method of doing it with js?
      By way of context, I am using this for dynamic email lists for my club membership system. The "dynamic" nature of the list is stored as a selector in a field which can then be used by the email function. To date, this has been done by just entering the selector as raw text. I now want to make this easier for 'normal' users by using the InputfieldSelector (in a runtime_markup field) to provide a user-friendly way of creating the selector. But then I need the page to show the initial InputfieldSelector to represent the selector stored in the field, for backwards-compatibility, if nothing else.
    • By Robin S
      Inputfield Selector Select ID
      Uses the Page List Select inputfield for user-friendly input of page IDs into Inputfield Selector.
      Overview
      This module adds a feature to Inputfield Selector, which is most commonly seen in Lister (Find) and Lister Pro.
      When adding a filter row for "Parent", "Has parent/ancestor" or "ID" the user is expected to enter a page ID to match against. But this is not as user-friendly as it could be because the user may be able to identify the desired page by its title or location in the tree but not know its ID. This is particularly the case for site editors who may not even understand the concept of a page ID.
      So this module adds a thunderbolt icon to relevant rows in Inputfield Selector. When the icon is clicked a Page List Select inputfield opens in a modal window, allowing the user to visually select a page from the tree. When the modal is closed with "OK" the ID of the selected page is inserted into the filter row.

      Tip
      After a page selection has been made in the modal window the "OK" button will automatically receive focus so if you prefer you can close the modal by hitting the Enter key rather than mousing to the OK button.
      Installation
      Install the Inputfield Selector Select ID module.
       
      https://github.com/Toutouwai/InputfieldSelectorSelectID
      https://modules.processwire.com/modules/inputfield-selector-select-id/
    • By David Karich
      The Page Hit Counter module for ProcessWire implements a simple page view counter in backend. Page views of visitors are automatically tracked on defined templates, with monitoring of multiple page views. This gives you a quick overview of how many visitors have read a news or a blog post, for example, without first having to open complex tools such as Google Analytics. This module quickly provides simple information, e.g. for editors. Or, for example, to sort certain news by most page views. For example for "Trending Topics".

       
      Works with ProCache and AdBlockers. With a lightweight tracking code of only ~320 bytes (gzipped). And no code changes necessary! In addition GDPR compliant, since no personal data or IP addresses are stored. Only session cookies are stored without information. 
      In addition, there are some options, for example filtering IP addresses (for CronJobs) and filtering bots, spiders and crawlers. You can also configure the lifetime of the session cookies. Repeated page views are not counted during this period. It is also possible to exclude certain roles from tracking. For example, logged in editors who work on a page are not counted as page views.

      Sort by hits and access page views (hit value)
      Each trackable template has an additional field called phits. For example, you want to output all news sorted by the number of page views.
      // It is assumed that the template, e.g. with the name "news", has been configured for tracking. $news = $pages->find("template=news, sort=-phits"); To output the page views of a tracked page, use:
      echo $page->phits; Example: Reset counter per API
      $modules->get("PageHitCounter")->resetPageViews("template=whatever", false); Example: Tracking a page hit via API and jQuery
      If you want to track a template that does not represent a full page to automatically inject a tracking script, you can define allowed API templates in the module that you can track. Below is an example of how you can track a click on news tag using jQuery. This will allow you to find out which keywords are clicked the most. For example, you can sort and display a tag cloud by the number of hits. Suppose your keywords have the template "news_tag". The template "news_tag" was also configured in the Page Hit Counter Module as a trackable API template.
      Example PHP output of keywords / tags:
      // Required: the data attribute "data-pid" with the ID of the template to be tracked. echo $pages->find("template=news_tag, sort=-phits")->each("<a href='{url}' class='news_tag' data-pid='{id}'>{title}</a>"); Example Tracking Script with jQuery:
      /** * Required: Data attribute "data-pid" with the ID of the news tag template * Required: Send the POST request to the URL "location.pathname.replace(/\/?$/, '/') + 'phcv1'" * Required: The POST parameter "pid" with the ID of the template */ $(function(){ if($('a.news_tag').length > 0) { $('a.news_tag').each(function(){ var tPID = $(this).data("pid"); if(tPID) { $(this).on("click", function(){ $.post(location.pathname.replace(/\/?$/, '/') + 'phcv1', {pid: tPID}); }); } }); } }); So simply every click on a tag is counted. Including all checks as for automatic tracking. Like Bot Filtering, Session Lifetime, etc.
      Notice: Tracking with URL segments
      If the option "Allow URL Segments" is activated on a template, the hits are only counted if the base URL of the page is called. If you want the hit to be counted even when a segment is requested, you MUST configure the segments in the template configuration. How to do this can be found here. If you use dynamic segments, configure them as RegEx. There is currently no other option. The problem is that the Page Hit Counter hooked into the PageNotFound process. If URL segments are allowed but not defined, a 404 is never triggered. This means that the Page Hit Counter cannot be called.
      _______________________________________________________
      Background: This module is the result of a customer requirement, where the editors are overwhelmed with analytics or no tracking tools were allowed to be used. However, a way had to be found to at least count page views in a simple form for evaluations. Furthermore, by using ProCache, a way had to be found to count views of a page without clearing the cache.
      _______________________________________________________
      Pros
      Automatic Page View Tracking Lightweight tracking code, only ~320 bytes (gzipped) No code or frontend changes necessary Works with ProCache! Even if no PHP is executed on the cached page, the tracking works Works with browser AdBlockers No cache triggers (for example, ProCache) are triggered. The cache remains persistent GDPR compliant, session-based cookie only, no personal information Filtering of IPs and bots possible Exclude certain roles from tracking Ability to reset Page Views Works with all admin themes Counter database is created as write-optimized InnoDB API to track events for templates that are not viewable No dependencies on libraries, pure VanillaJS (Automatic tracking script) Works in all modern browsers Pages are sortable by hits Cons
      Only for ProcessWire version 3.0.80 or higher (Requires wireCount()) Only for PHP version 5.6.x or higher No support for Internet Explorer <= version 9 (Because of XMLHttpRequest()) No historical data, just simple summation (Because of GDPR) Segment URLs can only be counted if the segments are defined Planned Features / ToDos
      API access to hit values Since version 1.2.1 Possibility to sort the pages by hits (Request by @Zeka) Since version 1.2.0 Don't track logged in users with certain roles (Request by @wbmnfktr) Since version 1.1.0 Possibility to reset the counter for certain pages or templates (Request by @wbmnfktr) Since version 1.1.0 Better bot filter Since version 1.1.0 Disable session lifetime, don't store cookies to track every page view (Request by @matjazp) Since version 1.2.1 Option to hide the counter in the page tree (Request by @matjazp) Since version 1.2.1 Option to hide the counter in the page tree on certain templates Since version 1.2.1 API to track events for templates that are not viewable Since version 1.2.2 Changelog
      1.2.6
      Bug-Fix: Set the counter of a cloned page to 0 Enhancement: The function for resetting counters is now available in the module as a public function to reset counters via own scripts on the API side (Request by @VeiJari) Enhancement: Documentation improvement API reset 1.2.5
      Bug-Fix: When counting 404 hits, cookies are no longer set. The session lifetime is deactivated for the 404 page Enhancement: Documentation improvement regarding URL segments 1.2.4
      Bug-Fix: Resetting the counters on system pages (e.g. 404) does not work (Reported by wbmnfktr) Bug-Fix: Tracking endpoint is logged as 404 if module "Jumplinks" is installed (Reported by wbmnfktr) Enhancement: Corrected few typos (Merged from Sergio #6 – THX!) 1.2.3
      Bug-Fix: Tracking script triggers 404 if pages are configured without slash (#3) Reported by @maxf5 Enhancement: Reduction of the tracking script size if it's gzipped (~320 bytes) Enhancement: Documentation improvement Enhancement: Corrected few typos 1.2.2
      New feature: API to track events for templates that are not viewable Enhancement: Documentation improvement 1.2.1
      API access to hit values Use $page->phits Bug-Fix: No tracking on welcomepage (Reported by wbmnfktr; Thx to matjazp) Bug-Fix: Tracking script path on subfolders (Reported by matjazp) Bug-Fix: Tracking on pages with status "hidden" Enhancement: Change database engine to InnoDB for phits field Enhancement: Option to disable session lifetime set session lifetime to 0, no cookies Enhancement: Better installation check Enhancement: AJAX Request asyncron Enhancement: Reduction of the tracking script size by ~20% Enhancement: Option to hide the counter in the page tree You can output the counter with the field name "phits" Enhancement: Option to hide the counter in the page tree on certain templates Enhancement: Option for activate general IP validation Enhancement: Reduction of tracking overhead up to ~30ms Enhancement: Better bot list for detection 1.2.0
      New feature: Sort pages by hits – New field phits Migrate old counter data to new field 1.1.0
      New feature: Exclude tracking of certain roles New feature: Reset Page Views Better bot filter and detection 1.0.0
      Initial release Notes
      By default, the page views are stored as INT in the database. This allows a maximum counter value of 4.2 billion views (4,294,967,295) per page. If you need more, change the type to BIGINT directly in the database. But I recommend to use Google Analytics or similar tools if you have such a large number of users.
      _______________________________________________________
      Download GitHub: ProcessWire Page Hit Counter (Version 1.2.6)
      PW Module Directory: ProcessWire Page Hit Counter (Version 1.2.6)
      Install via ProcessWire (Classname): PageHitCounter
      _______________________________________________________
      Update information
      If you have used version 1.2.1 from the DEV branch, please replace it completely with the new master version.
×
×
  • Create New...