How to Flexajax?

I have a question. I need to make PHP Request to my FelexAjax Function in vTiger, can anybody help?

This is my code: MenuReorder.php

class Settings_FlexSuite_MenuReorder_Action extends Settings_Vtiger_Basic_Action {

    public function process(Vtiger_Request $request) {
        $adb = \PearDatabase::getInstance();
        $modules = \FlexSuite\VtUtils::getEntityModules(true);
        echo json_encode($modules);
    }

    public function validateRequest(Vtiger_Request $request) {
        $request->validateWriteAccess();
    }
}

This is my code: MenuEditor.js

$( document ).ready(function() {

    FlexAjax("FlexSuite").postSettingsAction("MenuReorder", { parameter1:value1 }, "json").then(function(response) {
        var RecordLabel = response.label;
    });

});
1

1 Answer

Use the following code: PHP Side:

class Settings_FlexSuite_MenuReorder_Action extends Settings_Vtiger_Basic_Action {

    public function checkPermission(Vtiger_Request $request)        {
        $currentUser = Users_Record_Model::getCurrentUserModel();
        if(!$currentUser->isAdminUser()) {
            throw new AppException(vtranslate('LBL_PERMISSION_DENIED', 'Vtiger'));
        }
    }

    public function process(Vtiger_Request $request) {
        $adb = \PearDatabase::getInstance();
        $modules = \FlexSuite\VtUtils::getEntityModules(true);
        $response = new Vtiger_Response();
        $response->setResult($modules);
        $response->emit();
    }

}

Java Script Code:

$( document ).ready(function() {
    params = {
        data: {
            module: 'FlexSuite',
            parent: 'Settings',
            action: 'MenuReorder',
        }
    };
    app.helper.showProgress();
    app.request.post(params).then(function(error, data) {
        app.helper.hideProgress();
        if(error === null) {
            var RecordLabel = data.label;
            app.helper.showSuccessNotification({message: RecordLabel});
        }
    });
});
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest