1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Your status has been updated - drop down code

Discussion in 'XenForo Development Discussions' started by AndyB, Dec 6, 2013.

  1. AndyB

    AndyB Well-Known Member

    I would like to have a drop down similar to the "Your status has been updated" notice.

    pic001.jpg

    In my add-on "Flag Thread" I confirm an action by using the following code:

    PHP:
    return $this->responseMessage('Thread successfully flagged');
    You can see the entire PHP code here:

    http://xenforo.com/community/threads/flag-thread-v1-0.64451/#post-680040

    Using the return $this->responseMessage() sends the user to another page to make the confirmation. It would be great to be able to stay on the current thread and have a notice like "Your status has been updated" drop down with a different message.
     
  2. Milano

    Milano Well-Known Member

    Add class AutoValidator to your form and use responseRedirect

    PHP:
    $thread $threadModel->getThreadById($threadId);

    return 
    $this->responseRedirect(
        
    XenForo_ControllerResponse_Redirect::SUCCESS,
        
    XenForo_Link::buildPublicLink('threads'$thread),
        
    'Thread successfully flagged'
    );
     
    Matthew Hawley likes this.
  3. Daniel Hood

    Daniel Hood Well-Known Member

    Can you add class="TriggerOverlay" (I think that's the class name, can't check right now)?

    May I ask why you chose to make a new route for this? Seems as if you could have just extended the thread controller to have actionFlag().

    You should also use the {xen:link} functionality instead of the URL method you're using (in my opinion).
     
  4. AndyB

    AndyB Well-Known Member

    Thank you, Daniel.

    Adding class="OverlayTrigger" did the trick! Now I get the Overlay drop down.

    Code:
    $0
    <xen:if is="{$visitor.is_admin}">
    <li><a href="{$requestPaths.fullBasePath}flagthread?flag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase flag_thread}</a></li>
    <li><a href="{$requestPaths.fullBasePath}flagthread?unflag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase unflag_thread}</a></li>
    </xen:if>
    
     
    Last edited: Dec 6, 2013
  5. AndyB

    AndyB Well-Known Member

    Is it possible to have the page reload after the OverlayTrigger drop down? It would be nice to have the Overlay confirm the action and then immediately after the message the page would reload.
     
    Last edited: Dec 6, 2013
  6. xf_phantom

    xf_phantom Well-Known Member

    add data-redirect="on" to your form
     
  7. AndyB

    AndyB Well-Known Member

    Hi xf_phantom,

    I tried that, but unfortunately doesn't force a page reload.

    Code:
    $0
    <xen:if is="{$visitor.is_admin}">
    <li><a href="{$requestPaths.fullBasePath}flagthread?flag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" data-redirect="on" />{xen:phrase flag_thread}</a></li>
    <li><a href="{$requestPaths.fullBasePath}flagthread?unflag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" data-redirect="on" />{xen:phrase unflag_thread}</a></li>
    </xen:if>
    
     
  8. xf_phantom

    xf_phantom Well-Known Member

    this needs to be put into your form!

    <form action="..." method="post" data-redirect="on"
     
    Steve F likes this.
  9. AndyB

    AndyB Well-Known Member

    I'm not using a form, I'm using <a href> link.

    I added Flag Thread and Unflag Thread links as shown here:

    pic001.jpg

    The Template Modification code I currently have is:

    Code:
    $0
    <xen:if is="{$visitor.is_admin}">
    <li><a href="{$requestPaths.fullBasePath}flagthread?flag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase flag_thread}</a></li>
    <li><a href="{$requestPaths.fullBasePath}flagthread?unflag={$thread.thread_id}" rel="nofollow" class="OverlayTrigger" />{xen:phrase unflag_thread}</a></li>
    </xen:if>
    
     
  10. xf_phantom

    xf_phantom Well-Known Member

    Doesn't this open a confirmation form?
     
  11. AndyB

    AndyB Well-Known Member

    Thank you, Milano, Daniel Hood and xf_phantom.

    With the help from all three of you I have coded my add-on the proper way. Clicking the Flag Thread or Unflag Thread link now brings up an overlay form and once the admin clicks Submit, the code runs an action.

    I also removed the unnecessary Route Prefix.
     
    Last edited: Dec 6, 2013

Share This Page