
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//
// Main Ribbon functions
//\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\////\\//


function ShowRibbonElementsByAccessRights() {
    try {

        // ThisLoginUserAdmin
        // Find elements with 'data-admin-access' attribute
        var AdminAccessElementObjects = $("#MainRibbonTabs").find("[data-admin-access='1']");
        if (AdminAccessElementObjects && AdminAccessElementObjects.length > 0) {
            if (ThisLoginUserAdmin)
                 AdminAccessElementObjects.show();
            else AdminAccessElementObjects.hide();
        }

        // Check user rights for ribbon buttons
        // data-userright-access="51@*UR_AI_ACCESS*@"
        // For each ribbon element tagged with data-userright-access, ask the server whether the
        // logged-in user holds that right and hide the element if they don't.
        $("#MainRibbonTabs").find("[data-userright-access]").each(function () {
            var element = $(this);
            var userRight = element.attr("data-userright-access");

            // Does the "logged in" user have rights to see this button?
            // If not, hide it
            AjaxLoggedInUserHasRight(
                userRight,
                false/*bDisplayError*/,
                function () { /*element.show();*/ },    // hasrightcallback — user has the right
                null,                                   // hasrightobject
                function () { element.hide(); }         // norightcallback — user lacks the right
            );
        });

        // Hide ribbon buttons when a certain feature exists
        // This was added specifically for the "PMO" feature, which hides certain functionality when in "Project Management Only" mode
        $("#MainRibbonTabs").find("[data-userfeature-hide]").each(function () {
            var element = $(this);
            var userFeature = element.attr("data-userfeature-hide");

            // Does the "logged in" user have rights to see this button?
            // If not, hide it
            AjaxLoggedInUserHasFeature(
                userFeature,
                false/*bDisplayError*/,
                function () { element.hide(); },    // hasfeaturecallback — user has the feature
                null,                               // hasrightobject
                function () {  }                    // nofeaturecallback — user lacks the feature
            );
        });

    } catch (e) {
        console.error("ShowRibbonElementsByAccessRights: " + e.message);
    }
}




function ShowStandardTimeSubscription() {
    var sStoreUrl = (sBrandUrls && sBrandUrls.store) || "https://www.strdtime.com/store";
    ToastError("", "Update your subscription at " + sStoreUrl);
    LaunchUrl(sStoreUrl);

    ShowPropertiesPane();

    AjaxRefreshPropertyGridView($("#"+PropertyGridPartialViewDivId), "SUBSCRIPTIONRECORD", "Subscription"/*ObjectDataType*/, "Web Edition"/*ObjectTable*/, "SUBSCRIPTIONRECORD"/*ObjectRecordId*/, ""/*SelectedCellTable*/, ""/*SelectedCellColumnId*/, ""/*PropertyValuesJsonString*/);
}


