/// class PD.Manage.Modules.SyncAllGroupsCommand

PD.Manage.Modules.SyncAllGroupsCommand =
PD.Commands.Command.extend({

    //===================================
    // PUBLIC METHODS
    //===================================

    setDefaults: function () {
        this.props("id", "sync/all-groups");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("arrow_circle2.png"));
        this.props("label", "Sync All Groups");
        this.props("tooltip", "Update all Groups with data<br/>retrieved from Active Directory.");
    },

    execute: function (e) {
        this._super(e);

        PDJS.Shared.TaskStatusDialog.open({
            title: "Sync | Groups",
            taskStart: (args) => {

                PD.ajax({
                    type: "POST",
                    url: PD.Path.resolve("~/Manage/ActiveDirectory/SyncGroups"),
                    success: function (e) {
                        args.startPolling(e);
                    },
                    error: function (e) {
                        args.abort(e.responseJSON);
                        e.errorHandled = true;
                    }
                });

            },
            taskSuccess: (e) => {

                PD.context
                    .get_default()
                    .get_events()
                    .publish("sync/refresh");

            }
        });

    }

});