Announcement

Collapse
No announcement yet.

Quick Topic Moderation

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Quick Topic Moderation

    I'm trying to give moderators the option to quickly lock a thread & an option to change the topic's prefix while replying to a thread, this is without having to click on the inline-mod button so it basically lets you do this without having an extra click thus being able to save some time as in my case they have to do this action many times in one session, this can help alleviate some of the pressure if you have a busy forum.
    It should look like this:
    Click image for larger version

Name:	1o5IRH9.jpg
Views:	345
Size:	64.4 KB
ID:	29566

    Once you check the box and reply, thread should be locked.
    I know the inline-mod uses the js/inline-mod.js file and I've looked there but can't understand how to use JS to implement this, I'd be glad to get some help on this.

    Thank you

    #2
    I actually managed to create a button that will reply and also lock the thread simultaneously, it's not perfect but seems like it's working.
    Code:
    <vb:if condition="$user['is_moderator']== 1">
    <script>
        document.addEventListener("DOMContentLoaded", function() {
    
            var button = document.getElementById('openCloseButton');
    
            button.addEventListener('click', function(event) {
                event.stopPropagation();
                var dropdown = this.closest(".js-comp-menu-dropdown");
                if (dropdown) {
                    dropdown.classList.remove("b-comp-menu-dropdown--open");
                }
    
                var action = this.getAttribute("data-action");
                if (!action) {
                    console.warn("Unable to find the inline moderation function name.");
                    return false;
                }
    
                var moderationFunction = vBulletin.inlinemod[action];
                if (typeof moderationFunction === 'function') {
                    var params = this.getAttribute("data-params") ? this.getAttribute("data-params").split(",") : [];
                    moderationFunction.apply(this, params);
                } else {
                    console.warn('Unable to find the inline moderation function "{0}". Please ensure that it is defined in inlinemod.js.'.format("vBulletin.inlinemod." + action));
                }
    
                return false;
            });
        });
    
    
        document.addEventListener("DOMContentLoaded", function() {
            // Find the button
            var button = document.getElementById('openCloseButton');
    
            // Set the value of data-node-id attribute to the value of pageData.nodeid
            button.setAttribute('data-node-id', encodeURIComponent(pageData.nodeid));
        });
    
    </script>
    {vb:data userInfo, user, fetchUserinfo, {vb:raw conversation.userid}}
    <div class="b-content-entry-panel__content b-content-entry-panel__content--advanced-options h-clearfix b-content-entry-panel__content--first" data-class="b-content-entry-panel__content--advanced-options">
    <button type="submit" class="b-button js-button b-button--primary js-content-entry-submit" id="openCloseButton" data-action="openCloseThreads" data-params="close" data-node-id="pageData.nodeid">Reply & Lock Thread</button></div>
    
    
    
    </vb:if>​
    I also applied this to the "editor_additional_panels​" hook so it's placed just below the Editor, not a perfect spot but it'll do for now.
    The "is_moderator" conditional isn't really good because it gives access to all moderators globally but it still prevents people without permissions from viewing the button.
    This will also show up in pages such as articles and even creating a topic, so I'm going to try to fix it and post the results when I manage to do so.

    Comment


      #3
      Nice workaround darkboy245!

      You can also accomplish this in a more proper way via PHP Hook using the hookFrontendContentAfterAdd hook. This way, there is only one AJAX call triggered by the Post Reply or Post (New Topic) button. That hook sends a flag if the posting was successful so you can use that flag to only call the closeNode API directly from that PHP hook if the posting was successful.

      Here's the hook documentation from /do_not_upload/development/hooks.txt

      PHP Code:
      public static function hookFrontendContentAfterAdd($params)
      {
              
      //Read only parameter.  True if this is a comment being added, false otherwise.
              //Comments are added via a different action from other content
              
      $params['iscomment'];

              
      //whether or not the add succeeded. Read only.
              
      $params['success'];

              
      //The output that will be returned to the browser.  Read only.
              
      $params['output'];

              
      //the id of the node just added. Can be used to fetch the node
              //content and perform additional actions based on the node
              //just added.
              
      $params['nodeid'];

      I've been actually meaning to create such mod but never had a chance. Maybe now is a good time to start working on it.

      Comment


        #4
        Originally posted by glennrocksvb View Post
        Nice workaround darkboy245!

        You can also accomplish this in a more proper way via PHP Hook using the hookFrontendContentAfterAdd hook. This way, there is only one AJAX call triggered by the Post Reply or Post (New Topic) button. That hook sends a flag if the posting was successful so you can use that flag to only call the closeNode API directly from that PHP hook if the posting was successful.

        Here's the hook documentation from /do_not_upload/development/hooks.txt

        PHP Code:
        public static function hookFrontendContentAfterAdd($params)
        {
        //Read only parameter. True if this is a comment being added, false otherwise.
        //Comments are added via a different action from other content
        $params['iscomment'];

        //whether or not the add succeeded. Read only.
        $params['success'];

        //The output that will be returned to the browser. Read only.
        $params['output'];

        //the id of the node just added. Can be used to fetch the node
        //content and perform additional actions based on the node
        //just added.
        $params['nodeid'];

        I've been actually meaning to create such mod but never had a chance. Maybe now is a good time to start working on it.
        Interesting, so to implement this I would have to use the "success" and "nodeid" params? and then I need to check whether the user has moderator privileges or the closeNode api already does that for you?
        And by closeNode you mean this?
        PHP Code:
        vB_Api::instanceInternal('node')->closeNode($thread['nodeid']); 
        PHP Code:
        $nodeApi->closeNode($nodeids); 
        I can't really find info about closeNode, what I've posted here is basically it.
        I guess I have to look at nodeApi for more information.

        Comment


          #5
          Check core/vb/api/node.php and find the closeNode function. If you are using the compressed PHAR version of the vB5 package, you will not see the api folder. In that case, you'll have to download the non-PHAR version from Members Area.

          Comment

          Users Viewing This Page

          Collapse

          There is 1 user viewing this forum topic.

          • Guest Guest

          Latest Posts

          Collapse

          Working...
          X
          Searching...Please wait.
          An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

          Please push the back button and reload the previous window.'
          An unexpected error was returned: 'Your submission could not be processed because the token has expired.

          Please push the back button and reload the previous window.'
          An internal error has occurred and the module cannot be displayed.
          There are no results that meet this criteria.
          Search Result for "|||"