Jump to content

ProcessEventCalendar


froot
 Share

Recommended Posts

Hi friends,

just 7 months ago, I was "just" a designer and a rather semi-developer, still struggling with WordPress sites and more often than not delegating that work to pros. ProcessWire really helped me realising that it's not that hard after all (well it's still hard but it's doable) and you learn a lot just by doing it which has to be true for all developers anyway. So I started coding myself, I might also have to thank the 2020 pandemic to help me focus a bit more than usual, I created a bunch of websites using PW already – one of which I can't wait to put on showcases but it's still not live yet. That is one big personal milestone for me. The next milestone would be to give something back, and so I'd like to take on contributing some code I wrote, namely a event calendar for anyone to use. It's my first attempt doing this so please don't eat me alive. It's not a PW module yet (that's the plan however) just a git but I'm positive it will be useful once it works – well it works but it still needs more work – because if I had found a module that came close I wouldn't have started coding it myself :D

With that, I will appreciate all input, be it how to improve the .js (probably especially), or the templates, or guidance how to proceed turning this into a PW-module, and of course, in that last process, no pun intended, suggestions to make it more versatile for different needs.

git: github.com/bbblgmsp/ProcessEventCalendar
demo: http://foobar.roofaccess.org/events/

Thank you!

  • Like 9
Link to comment
Share on other sites

  • 2 weeks later...

I made some progress with this, but I have some basic questions, because of some basic obstacles.

Since the module I'm trying to build makes an AJAX-request, how can I call the file? Obviously I want to put the ajax-called file inside the modules/EventsCalendar/ folder, and not inside the root folder.
My .js does the following at the moment which doesn't work for obvious reasons (forbidden):

pullEvents.open("GET", "../site/modules/EventsCalendar/_loadevents.php?m="+m+"&y="+y+"&d="+d+"&view="+view, true);

Also, I need to know how to include a javascript in that module. It's required for at least two of the class's functions. Is there a way to not require the user to add the

<script type="text/javascript" src="/path/to/js/file/"></script>

manually? How about css, how can I include that automatically?

Ideally I want to put .php, .js and .css files inside the module's-folder and everything gets included with no further ado from the user. The user would just need to call the methods inside their markup, add some additional css if needed and that's it.

Many thanks for help.

  • Thanks 1
Link to comment
Share on other sites

On 11/19/2020 at 4:51 PM, fruid said:

manually? How about css, how can I include that automatically?

Are you talking about adding the script in the PW backend or frontend? If backend, then it's simple:

// in your init() method of the module
$url = $this->wire->config->urls($this); // url to current module
$this->wire->config->scripts->add($url."YourScript.js");

 

On 11/19/2020 at 4:51 PM, fruid said:

Since the module I'm trying to build makes an AJAX-request, how can I call the file? Obviously I want to put the ajax-called file inside the modules/EventsCalendar/ folder, and not inside the root folder.

You can hook ProcessPageView::pageNotFound and define custom endpoints so you don't need to create a file for the ajax endpoint manually. A simple example can look like this:

  public function init() {
    $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'handleWebhooks');
  }

  public function handleWebhooks($event) {
    $url = trim($event->arguments(1),"/");

    switch($url) {
      case "api-create-user":
        $this->createUser();
      break;
      case "api-delete-user":
        $this->deleteUser();
      break;
      // by default we exit early and don't do anything
      default: return;
    }

    // show 200 status code instead of 404
    // this could also be done in the method calls above
    http_response_code(200);
    die("success");
  }

 

There's also this thread with lots of infos: 

 

  • Like 1
Link to comment
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
 Share

×
×
  • Create New...