/// 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);

        PD.Shared.Dialogs.TaskStatus.open({
            config: {
                title: "Sync Groups"
            },
            showDetail: true,
            taskStart: function (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;
                    }
                });

            },
            close: function (e) {

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

            }
        });

    }

});