Jump to content

gebeer

Members
  • Posts

    1,489
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by gebeer

  1. 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.
  2. @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.
  3. Hello, I am not so new here anymore but still very excited to get to know PW and all the forum users

  4. @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".
  5. @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?
  6. 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.
  7. 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.
  8. @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.
  9. 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.
  10. 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?
  11. This looks like a great module, thank you! I came here searching for dependent select options with PW. Now I'm reading that the video demo uses dependent selects. That is exactly what I need. But I can't seem to find a fieldtype "dependent selects". Is this part of some other fieldtype that I need to install first or how do I set up 2 dependent select fields in the backend?
  12. You can install the profile first and then open a terminal in site/templates and do "bower install". Sorry, I now see that my instructions are not clear about the sequence of steps here. I amended that.
  13. Since I've been working on a few projects where I used Bootstrap 3 and will be using it for future projects, I put together a blank site profile with Bootstrap 3 Sass, Fontawesome and a few markup render functions for Bootstrap dropdown menu, image carousel and accordion. You can find it at https://github.com/gebeer/site-pwbs Features bootstrap-sass-official font-awesome SASS version jquery modernizr render functions for:BS3 dropdown menu BS3 accordion from PageArray BS3 carousel from PW images array Prerequisites compass bower How to install from zip: download the zip extract the folder "site-pwbs" into a clean ProcessWire install's root folder during install of ProcessWire choose the profile "bootstrap-sass-official fontawesome blank profile" After installation The last step after installing the profile is to install all assets with bower: open a terminal in site/templates and execute "bower install" How it works The profile is based on the blank site profile that comes with PW 2.5 and uses the delegate template approach. It comes with a top navbar, a main container and a footer section. Rest is up to you. CSS gets compiled through compass. You can easily override BS variables and exclude BS components that you don't need. I intentionally did not add structure to the sass folder so you can structure your partials yourself as you please. There is only one folder "generic" with _mixins.scss whith a very lean and flexible breakpoint mixin that I discovered here. JS Since I only use the BS javascript plugins I really need, I usually copy them over to my plugins.js file. I use bower to install bootstrap-sass-original and fontawesome because it gives more flexibility than requiring them through ruby gems. This way you can tweak the BS and FA partials to your liking (of course only if you don't intend to do "bower update" further down the road) Enjoy!
  14. @adrian Yes, that is the one. Info also at http://webcomponents.org/polyfills/ @LostKobrakai Your idea with custom .htaccess rule to allow access of html in bower_components is great I'll see if I can put one together...
  15. This might be a dumb question. But what would be the solution to work with web components import links in a PW template and still maintain good security? I guess that rewrite condition is there for a good reason. But also the use of polymers imports is probably going to increase in future. So it would be great to find a secure way of making them work together smoothly with PW.
  16. Thank you guys, I did a search for webcomponents import instead of polymer. That's why that thread didn't come up.
  17. Hello all, on a new project I want to use https://github.com/stevenrskelton/flag-icon which implements svg icons for country flags via webcomponents import. In the <head> I import the webcomponents polyfill js and the flag icons html with <script src="<?php echo $config->urls->templates; ?>bower_components/webcomponentsjs/webcomponents.min.js"></script> <link rel="import" href="<?php echo $config->urls->templates; ?>bower_components/flag-icon/flag-icon.html"> But I get a 403 error: NetworkError: 403 Forbidden - http://dev/pwtest/site/templates/bower_components/flag-icon/flag-icon.html For testing I did: 1. a clean install of html5-boilerplate (not in PW), added flag-icons through bower and linked the resources as above. Here I don't get the 403 error. 2. a clean install of processwire with the blank profile, added flag-icon through bower and linked the resources as above. And here I get the error again. I did this on 2 different servers. Same result. I also checked permission of the import file and they are fine (644). Then I tried to make a demo install on lightning.pw but the service exits with "We're sorry, but something went wrong." To me this seems to be a ProcessWire related problem. Maybe somebody can confirm this or has an idea what is happening? Thank you.
  18. OK, I added SOLVED to the thread title.
  19. I would like to mark this as solved. But the "Mark Solved" Button is missing. I just used it on another thread of mine. But here it is not available. I opened the thread, so I should see this button?
  20. Thanks clsource! This really helps me for better understanding the whole hooking thing in PW. Instead of messing with cookies, I decided to better use token based authentication instead of sessions. Cheers Gerhard
  21. Thank you! I am now going with the token approach. That is much cleaner and more REST like.
  22. gebeer

    Text responsability

    I usually make clear in my offer/cost estimate whether I am responsible for the wording or the client. This helps to avoid problems at a later stage. Also to make clear that time I put into wording review and improvement will be charged extra. PS: maybe this should be moved to the dev talk thread?
  23. Hello, part of my new project is providing a RESTful webservice through PW. I am using clsource's REST Helper for ProcessWire which is working great. For the REST service part of the site I would like to suppress the setting of session cookie for $session->login and $session->logout because I don't need sessions and I don't want to have Set-Cookie in my response header. For user authentication in a PUT request I use $session->login() to verify username and password: $uId = $input->urlSegment1; $u = $users->get($uId); if ($session->login($u->name, $params["upass"])) { $session->logout(); //update user data } In the response header for that request I get: Set-Cookie: wire=ha6io723mkfc9v4scdib3oe8g7; path=/; HttpOnly wire=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT wire=1n8faeiva3vg7u13ijsrs24bt1; path=/; HttpOnly wire_challenge=YK0WRw0Wrd2ZAhKEUCLPOHd9iSySEPb91; expires=Tue, 07-Apr-2015 14:11:24 GMT; path=/; httponly wire=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT wire=u9m41s8b87d3ca1jp1jbl0r6k3; path=/; HttpOnly wire=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT wire=oidcbmht561qnvts2fjnq4b7p3; path=/; HttpOnly persist=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/ At the moment I get rid of it by doing header_remove("Set-Cookie"); But I would like to avoid setting of that cookie in the first place. I found the relevant methods ___login and ___logout in /wire/core/Session.php But searching Captain Hook for "logout" doesn't bring up those methods. I assume they should be hookable because they start with 3 underscores. Now how would I hook into those methods from my template file (not as an autoload module)? The webservice endpoint url is .../api/users/ and my temlate file for that is users.php What I've tried so far is wire()->addHookBefore('Session::logout', null, 'logoutNoCookie'); function logoutNoCookie($event) { $event->replace = true; $sessionName = session_name(); $_SESSION = array(); // if(isset($_COOKIE[$sessionName])) setcookie($sessionName, '', time()-42000, '/'); // if(isset($_COOKIE[$sessionName . "_challenge"])) setcookie($sessionName . "_challenge", '', time()-42000, '/'); session_destroy(); session_name($sessionName); $this->init(); session_regenerate_id(true); $_SESSION[$this->className()] = array(); $user = $this->wire('user'); $guest = $this->wire('users')->getGuestUser(); $this->wire('users')->setCurrentUser($guest); $this->trackChange('logout', $user, $guest); if($user) $this->logoutSuccess($user); $event->return = $this; } But this gives me an error: Fatal error: Using $this when not in object context because I'm placing my hook function outside the class context. What would be the correct way for calling the hook and placing my hook function?
  24. header_remove("Set-Cookie"); did the trick. I guess this is not the cleanest way of doing it. I opened a new thread to find out how I can suppress cookies in the first place as this is somewhat beyond the scope of this thread here.
×
×
  • Create New...