Add remove comment functionality in Vtiger CRM

Add remove comment functionality in Vtiger CRM

By default there is no remove button in comments list. You can add comment, edit it or reply comment. But you can not delete it.

Here is detail instruction how you can add this functionality.

To implement this you need access to change core Vtiger files.

You can also hide this button from users by disabling delete permissions in default roles permissions functionality.

First, let's add buttons to our template files:

layouts/v7/modules/Vtiger/Comment.tpl after 76

After this block:

{if $COMMENTS_MODULE_MODEL->isPermitted('EditView')}

{if $CHILDS_ROOT_PARENT_MODEL}

{assign var=CHILDS_ROOT_PARENT_ID value=$CHILDS_ROOT_PARENT_MODEL->getId()}

{/if}

<a href="javascript:void(0);" class="cursorPointer replyComment feedback" style="color: blue;">

{vtranslate('LBL_REPLY',$MODULE_NAME)}

</a>

{if $CURRENTUSER->getId() eq $COMMENT->get('userid')}

&nbsp;&nbsp;&nbsp;

<a href="javascript:void(0);" class="cursorPointer editComment feedback" style="color: blue;">

{vtranslate('LBL_EDIT',$MODULE_NAME)}

</a>

{/if}

{/if}

Add this lines:

{if $COMMENTS_MODULE_MODEL->isPermitted('Delete')}

{if $CHILDS_ROOT_PARENT_MODEL}

{assign var=CHILDS_ROOT_PARENT_ID value=$CHILDS_ROOT_PARENT_MODEL->getId()}

{/if}

&nbsp;&nbsp;&nbsp;

<a href="javascript:void(0);" class="cursorPointer deleteComment feedback" style="color: blue;">

{vtranslate('LBL_DELETE',$MODULE_NAME)}

</a>

{/if}

Then we need to add button in widgets block. Let's edit following file:

layouts/v7/modules/Vtiger/RecentComments.tpl after 163

Find this block:

{if $CURRENTUSER->getId() eq $COMMENT->get('userid') && $IS_EDITABLE}

{if $IS_CREATABLE}&nbsp;&nbsp;&nbsp;{/if}

<a href="javascript:void(0);" class="cursorPointer editComment feedback" style="color: blue;">

{vtranslate('LBL_EDIT',$MODULE_NAME)}

</a>

{/if}

 

Insert this lines:

{if $COMMENTS_MODULE_MODEL->isPermitted('Delete')}

{if $CHILDS_ROOT_PARENT_MODEL}

{assign var=CHILDS_ROOT_PARENT_ID value=$CHILDS_ROOT_PARENT_MODEL->getId()}

{/if}

&nbsp;&nbsp;&nbsp;

<a href="javascript:void(0);" class="cursorPointer deleteComment feedback" style="color: blue;">

{vtranslate('LBL_DELETE',$MODULE_NAME)}

</a>

{/if}

 

Then we need to edit javascript file to make our button interactive. Let's change file:

layouts/v7/modules/Vtiger/resources/Detail.js after 2908

Find this block:

detailContentsHolder.on('click','.editComment', function(e){

self.removeCommentBlockIfExists();

var currentTarget = jQuery(e.currentTarget);

var commentInfoBlock = currentTarget.closest('.singleComment');

var commentInfoContent = commentInfoBlock.find('.commentInfoContent');

var commentReason = commentInfoBlock.find('[name="editReason"]');

var editCommentBlock = self.getEditCommentBlock();

var fullComment = commentInfoContent.data('fullcomment');

if (fullComment) {

fullComment = app.helper.getDecodedValue(fullComment);

} else {

fullComment = commentInfoContent.text();

}

editCommentBlock.find('.commentcontent').text(fullComment);

editCommentBlock.find('[name="reasonToEdit"]').val(commentReason.text());

editCommentBlock.find('[name="is_private"]').val(commentInfoBlock.find('[name="is_private"]').val());

/*commentInfoContent.hide();

commentInfoBlock.find('.commentActionsContainer').hide();*/

editCommentBlock.appendTo(commentInfoBlock).show();

});

 

Insert this lines:

 

detailContentsHolder.on('click','.deleteComment', function(e){

var currentTarget = jQuery(e.currentTarget);

var commentInfoBlock = currentTarget.closest('.singleComment');

var commentInfoHeader = commentInfoBlock.find('.commentInfoHeader');

var commentId = commentInfoHeader.data('commentid');

 

var params = {

'module': 'ModComments',

'action': 'Delete',

'crmid':commentId

};

app.helper.showProgress();

app.request.post({data: params}).then(

function(err, data) {

if (err === null) {

commentInfoBlock.remove();

app.helper.showSuccessNotification({message:'Comment Deleted Successfully'});

} else {

app.helper.showErrorNotification({message: err.message});

}

app.helper.hideProgress();

});

});

 

Then we need implement delete functionality in Comments delete model. Just  rewrite following file:

modules/ModComments/actions/Delete.php

With this code:

<?php

class ModComments_Delete_Action extends Vtiger_Delete_Action {

 

function checkPermission(Vtiger_Request $request) {

//throw new AppException(vtranslate('LBL_PERMISSION_DENIED'));

        parent::checkPermission($request);

}

 

    public function process(Vtiger_Request $request) {

        $moduleName = $request->getModule();

        $recordId = $request->get('crmid');

 

        $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);

        $moduleModel = $recordModel->getModule();

        $recordModel->delete();

 

        $response = new Vtiger_Response();

        $response->setResult(array('success' => true));

        return $response;

 

    }

}

 

Popular Posts

My most popular posts

Maximum productivity on remote job
Business

Maximum productivity on remote job

I started my own business and intentionally did my best to work from anywhere in the world. Sometimes I sit with my office with a large 27-inch monitor in my apartment in Cheboksary. Sometimes I’m in the office or in some cafe in another city.

Hello! I am Sergey Emelyanov and I am hardworker
Business PHP

Hello! I am Sergey Emelyanov and I am hardworker

I am a programmer. I am an entrepreneur in my heart. I started making money from the age of 11, in the harsh 90s, handing over glassware to a local store and exchanging it for sweets. I earned so much that was enough for various snacks.

Hire Professional CRM developer for $25 per hour

I will make time for your project. Knowledge of Vtiger CRM, SuiteCRM, Laravel, and Vue.js. I offer cooperation options that will help you take advantage of external experience, optimize costs and reduce risks. Full transparency of all stages of work and accounting for time costs. Pay only development working hours after accepting the task. Accept PayPal and Payoneer payment systems. How to hire professional developer? Just fill in the form

Telegram
@sergeyem
Telephone
+4915211100235