Jump to content

Suggestions on implementing a Pinterest like save button


Liam88
 Share

Recommended Posts

21 minutes ago, flydev ?? said:

I am used to use the Delayed Output Strat so I can't tell you right now what's going on for real

Yeah I'll have to search if there are any other threads for markup regions strat.

Getting the same output with the suggestion above so did a bit of searching and found this - https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files

Adding $this->halt to the end of each case prevents the continued render when using it within _init.php (the prepended file).

This does not work if just adding to _main.php. 

This is the action area now - 

<?php
if($config->ajax && $input->post->bookmark){

  bd($input->post->bookmark); // debug with tracy, uncomment if you have it
  $bookmarkid = $sanitizer->int($input->post->bookmark);
  $action = $sanitizer->name($input->post->action);
  $bookmarks = $user->getUnformatted('bookmarks');
  switch($action) {
    case 'save': // save logic
      if(!$bookmarks->has($bookmarkid /* this was bookmark, now bookmarkid */)) {
        // add bookmark
        $bookmarks->add($bookmarkid /* same change here */);
        $user->setAndSave('bookmarks', $bookmarks);
        $message = 'Borat saved bookmark "'. $bookmark->id .'" ?';
		$this->halt(); 
      }
      else {
        $message = 'Nothing done';
      }      
      $success = true;
      break;
    case 'remove': // remove logic
      if($bookmarks->has($bookmarkid)) {
        $bookmarks->remove($bookmarkid);
        $user->setAndSave('bookmarks', $bookmarks);
        $message = 'Borat removed bookmark "'. $bookmark->id .'" ';
		$this->halt(); 
      } else {
        $message = 'Nothing done';
      }
      $success = true;
      break;
    default:
      $message = 'error';
      $success = false;
  }
    
 $json = array( 
    'id' => $bookmarkid,
    'action' => $action,
    'message' => $message,
    'success' => $success
  ); 
  header('Content-Type: text/json; charset=utf-8');
  echo json_encode($json);
  return;
}
?>

Now I get this within preview:

image.thumb.png.024869a10ad8db0943aaf9b03916a625.png

and FINALLY it now saves into the user area. 

Celebrate Meme Discover more interesting Birthday, Celebrate ...

A huge thank you @flydev ??. Learnt so much through this thread and hoping it helps others!

I'll even keep in borat in recognition of your input.

  • Like 1
Link to comment
Share on other sites

20 minutes ago, Liam88 said:

Getting the same output with the suggestion above so did a bit of searching and found this - https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files

Adding $this->halt to the end of each case prevents the continued render when using it within _init.php (the prepended file).

great perseverance from you, learning new things from each others as always. @szabesz given the answer too there :

 

 

  • 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...