Jump to content

gebeer

Members
  • Posts

    1,554
  • Joined

  • Last visited

  • Days Won

    48

Everything posted by gebeer

  1. I came across this thread while working on my first PW module that needs to load quite a lot of scripts. So I am going to revive this thread because the OP makes an important point here: how to best find the balance between easy module integration and freedom for PW users when it comes to template structure . In my opinion, best practices for script inclusion should also be considered here. So while giving users the most possible freedom in how to structure their templates, they should at the same time be made aware of ways how to best implement script loading. Not only with PW, but in general. I for myself am still learning a lot about web development best practices while developing sites with PW. There is a lot of useful information to be found here in the forums which is absolutely great. One thing that most of web devs seem to agree upon is that loading scripts at the end of your template just before </body> increases site loading speed and thus user experience. Besides that it also makes sure that the DOM is already available to those scripts. And here lies the culprit of approach 3 proposed by the OP: all additional scripts get loaded in the <head> which slows down page loading time. Thus I would implement the addScripts method like this public function addScripts($event) { $page = $event->object; // don't add this to the admin pages if($page->template == 'admin') return; //other mechanisms to ensure the script only loads when this module was called in the front-end $additionalScripts = '[myScripts...]'; $event->return = str_replace("</body>", $additionalHeadScripts.'</body>', $event->return); } Only drawback I can see: following this approach, the module developer has to make sure that all inline scripts wait for the scripts they depend upon before they are executed (eg with $(window).load or $(document).ready)
  2. Thanks again for the port to leaflet! I prefer OSM over google maps and have been using it for quite some time. Leaflet is very powerful and opens up many possibilities. I forked Mats' module and added support for leaflet-providers so we can choose different map tile providers (see my post here). It is still a work in progress but seems stable. Once it is ready for production I'll make a pull request. Mats, do you think we should use leaflet-providers as standard or offer the user a choice whether they want to use it or not? Next up I will add an icon field and support for Leaflet.awesome-markers.
  3. @Mats thank you so much for your OSM version of the module. Have you opened a thread dedicated to it, yet? Couldn't find it in the forums. I forked your module and added basic support for leaflet-providers. In the field settings we can now choose the map tile provider. and the map renders accordingly (example with MapQuest.Open) (example with OpenStreetMap.BlackAndWhite) I'm thinking adding this on a per marker basis also but I'm not quite sure yet if it makes sense at all to define tiles per marker? We should definitely open a separate thread for your module, what do you think?
  4. I just noticed that I get the error on my vagrant box with latest stable 2.5.3. The error was related to wrong apache user/group in my vagrant box and previously I had solved it like this. But dev versions 2.5.26 and 2.5.27 don't throw this error anymore.
  5. Thank you for your patience with an OOP noob. I don't know how I would copy the array to my module. So some example code would be great. So that I can go on from there with removing keys etc.
  6. How can I access $defaultMarkup from within my hook: public function init() { $this->addHookBefore('Page::render', $this, 'addTooltipJS'); $this->addHookBefore('InputfieldWrapper::render', $this, 'addTooltip'); } public function addTooltip(HookEvent $event) { $defaultMarkup = ; $event->return; }
  7. That is a beast, indeed. And I'm quite new to PW modules. Have read the documentation. But don't no how to access $defaultMarkup in this case. The $event->object is of type InputfieldForm with lots of protected and private properties. Any help would be much appreciated.
  8. @LostKobrakai Thank you. I already had a look at InputfieldWrapper.php and am currently trying to add my hook there. Will report back with results or questions.
  9. I have searched the forum and google but couldn't find anything related. I want to show all field descriptions in admin forms as tooltips. Has this request really not come up before? I imagine a module that hooks into the Inputfield class, adds the description as title value to the inputfield and then makes use of https://jqueryui.com/tooltip/. Am I on the right track here? EDIT: I made a module "InputfieldHookAddTitle": <?php class InputfieldHookAddTitle extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Inputfield Hook Add Title', 'version' => 100, 'summary' => 'Adds title attribute to inputfields with field description as value', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookBefore('Inputfield::render', $this, 'addTitle'); } public function addTitle(HookEvent $event) { $inputfield = $event->object; if ($inputfield->description == "") return; $inputfield->setAttribute('title', $inputfield->description); $event->return; } } This adds title attribute with value description to inputfields. Now I need to get rid of the original <p class="description"> tag which is set in the constructor method. How would I unset this? I don't see a unset method. And how do I add the Jquery tooltip js? EDIT: I managed to add the custom JS to the admin pages, thanks to Soma's blog post. In my site/templates/admin.php I added: // add tooltip JS to admin pages $modules->get('JqueryCore'); $modules->get('JqueryUI'); $config->scripts->add($config->urls->templates . "js/admintooltips.js"); and the admintooltips.js $(function() { var tooltips = $( "[title]" ).tooltip({ position: { my: "left top", at: "right+5 top-5" } }); }); Now I only need to get rid of the original description. Any pointers would be much appreciated.
  10. I made this into a blank site profile. Download and instructions here. Tested on a new PW install and it is working fine. Maybe some of you want to test it in other environments and let me know if I need to amend the README. Thank you.
  11. This is very inspiring. Thank you for sharing! Before I sit down and do this, do you have any plans on releasing this as a site profile? Edit: OK, I sat down and am working on it. Going smoothly so far. Will report back...
  12. @Soma I am sorry, didn't mean to flood the forum with this. Was just exited about the whole thing and that maybe made me go a bit far... Your proposed solution for setup and custom selector to get this working with pages that don't share the same tree is great. Very much appreciated. I put something together quickly to have the same functionality in a frontend form with the help of a jQuery plugin.
  13. @Soma that looks great! I am only having trouble understanding where exactly I need to put the "select_page" field and what the selector for this one would be. Because I am not sure what "options pages" refers to. Are these the area and event pages in your example? EDIT: I got it working now for my scenario. Thanks again. -destination template with title and country single page select field -tour template with title, country field and a destinations multi page select field with custom selector "country=page.country, select_page!='', template=destination"
  14. Your welcome. This is just on a playground site at the moment and will not be online until much later this year. But the code I posted is working for me.
  15. I am currently looking into dependent select fields or cascading select fields (as they are sometimes called), too. So I have a quite similar scenario as yours. I already have setup some working code that I want to share here. For a better understanding about my scenario: 1. parent countries with list of all countries 2. parent destinations, each destination gets assigned one country through "countries" pages asm select field. 3. parent tours, each tour gets assigned 1 or more countries through "countries" field and 1 or more destinations from "destinations" pages asm select field In tours form, when countries are selected I want to filter the destinations field to only show destinations of the previously chosen countries. For my solution I am using this jQuery plugin. So you need to call this in your template. My code is still a work in progress and written around my requirements but should be fairly easy to transfer to other contexts. Template code <?php // do not load _main.php for ajax requests if($config->ajax) $useMain = false; // provide dropdown data for the ajax request if ($input->post->depdrop_parents) { $ids = $input->post->depdrop_parents; $params = $input->post->depdrop_params; $options = []; $option = []; if (count($ids) == 1) { // only 1 id $pages = $pages->find("template=$params[0], countries=$ids[0]"); } // todo else { handle multiple ids} foreach ($pages as $page) { $option["id"] = $page->id; $option["name"] = $page->title; $options[] = $option; } echo json_encode(['output'=>$options, 'selected'=>'']); } // render the form if (!$config->ajax) { $content = ""; $destinations = $pages->find("template=destination,sort=countries.title"); $options = []; $option = []; // build options array for first select field: this is very specific to my scenario foreach ($destinations as $destination) { if (seekKey($options, $destination->countries->first()->id) == $destination->countries->first()->id) continue; $option["value"] = $destination->countries->first()->id; $option["name"] = $destination->countries->first()->title; $options[] = $option; } $content = "<form> <select id='parent' name='countries'>"; foreach ($options as $option) { $value = $option["value"]; $name = $option["name"]; $content .= "<option value='$value'>$name</option>"; } $content .= "</select>"; $content .= "<select id='child-1' name='destination'> </select>"; // need hidden input with value "destination" to populate params for the JS plugin // with the value that will be used as template value above in line 14 $content .= "<input type='hidden' id='dest' value='destination'> //todo submit button and logic </form>"; } In my functions.inc // Find the value in a multidimensional array function seekKey($haystack, $needle){ $output = ""; foreach($haystack as $key => $value){ if($value == $needle){ $output = $value; }elseif(is_array($value)){ $output = seekKey($value, $needle); } } return $output; } Javascript $(document).ready(function () { $("#child-1").depdrop({ url: './', depends: ['parent'], params: ['dest'], initialize: true }); }); Hope this helps.
  16. @Soma Thank you for clarifying I was thinking of it as an extra field type because "parent=page.anotherpageselect" is only working for pages that live under the same parent like you explained here. I'd need something more flexible that can be applied to page select fields whose pages have different parents. Meanwhile I posted about this in Wishlist&Roadmap.
  17. Hello, I am not so new here anymore but still very excited to get to know PW and all the forum users

  18. @adrian Thanks for the pointer. I had already found that here. But as Soma points out it only works for pages that are nested under the same parent. I would need something like this for page select fields that live under different parents in the page tree. My use case: 1. parent countries with list of all countries 2. parent destinations, each destination gets assigned one country through "countries" pages asm select field. 3. parent tours, each tour gets assigned 1 or more countries through "countries" field and 1 or more destinations from "destinations" pages asm select field In tours form, when countries are selected I want to filter the destinations field to only show destinations of the previously chosen countries. Destinations cannot live under countries because I need them under a separate parent where the user can add destinations easily without having to drill through the 249 available countries and search for the right one where they want to add their destinations under. What I think would work in theory: An inputfield type that lets you define which select fields in a template depend on each other and what the hierarchy of those fields is. This inputfield type adds the JS logic to the template form that will get the option values for the dependent select fields via AJAX call and fills them. The PHP of the inputfield type holds the logic to retrieve the right pages for the AJAX request. There are jQuery plugins like this or this available that could be used. Or the JS that is already there when using selector "parent=page.otherpagefield".
  19. @kongondo Thank you for pointing me to that one. But it doesn't do what I need and what Ryan is demonstrating in his introduction video to Select Multiple Transfer module: one select field that gets filled based on the previously selected option in another select field. I just posted about this in Wishlist&Roadmap. Maybe we better continue there because I think this is kind of going beyond the scope of this thread?
  20. In the thread for the Select Multiple Transfer module Ryan mentions that he used "dependent selects" for his introduction video: I searched the dev code and the forum up and down but can't seem to find this fieldtype. Has development been discontinued? I would really love to see that fieldtype in PW and would even be happy to pay for it if it was published as a pro field. I switched over to PW from Joomla/Seblod and they have a fieldtype called "Select Dynamic Cascade" that does just that.
  21. In addition to the Service Pages module mentioned by diogo, there is also a rest helper for processwire made by clsource. I am using it in a new project that implements bidirectional communication between mobile devices and a PW powered site. It is working great so far. I extended clsource's code to support basic HTTP Authentication.
  22. @SteveB My use case: 1. parent countries with list of all countries 2. parent destinations, each destination gets assigned one country through "countries" pages asm select field. 3. parent tours, each tour gets assigned 1 or more countries through "countries" field and 1 or more destinations from "destinations" pages asm select field In tours form, when countries are selected I want to filter the destinations field to only show destinations of the previously chosen countries. Destinations cannot live under countries because I need them under one parent where the user can add destinations easily without having to drill through the 249 available countries and search for the right one where they want to add their destinations under. What I think would work in theory: An inputfield type that lets you define which select fields in a template depend on each other and what the hierarchy of those fields is. This inputfield type adds the JS logic to the template form that will get the option values for the dependent select fields via AJAX call and fills them. The PHP of the inputfield type holds the logic to retrieve the right pages for the AJAX request. I switched over to PW from Joomla/Seblod and they have a fieldtype called "Select Dynamic Cascade" that does just that. Ryan writes in his thread about Select Multiple Transfer module that he used dependent selects for the video demo: So the fieldtype that I am looking for seems to exist somewhere but I can't find it. I already asked in that thread but got no answer so far.
  23. Thank you for confirming.
  24. The serpentine path on my humble quest for the mysterious dependent select input field type that is mentioned by Ryan here and cheered a lot about further down the same thread, led me here. With great expectations I went straight to the linked git repo, only to find these lines: Please allow me one question before I continue my hunt for this seemimngly lost or hidden and so hardly desired feature: Your fieldtype will not work if the pages that the 2 dependent select fields refer to, are not in the same tree, right? Following another turn-off in my frantic search, I discovered this interesting thread and thought I had reached the end of my journey for good. But that method is also only working for pages in the same tree like Soma patiently explains. I desparately need dependent selects for pages with different parents and hope that one day some more light will be shed on the matter for that my and my fellow travellers restless expedition will finally come to a happy ending.
  25. I just installed this great theme and was searching for about 15 min how to activate it. Then I came across this thread and now I know about this config setting. I totally wasn't aware of the switch in user edit profile page. Maybe because until this day I only used the default theme. I think it could save many people quite some time if this information was visible more prominently somewhere in the docs or even on the admin themes module page. What do you think?
×
×
  • Create New...