fetchOptions: function()

in cloud-vmware-server/src/main/resources/buildServerResources/vmware-settings.js [85:153]


        fetchOptions: function () {
            var $loader = $j('.options-loader');

            if ( this._fetchOptionsInProgress() || !this.validateServerSettings()) {
                return false;
            }

            this.fetchOptionsDeferred = $j.Deferred()
                .done(function (response) {
                    var $response = $j(response.responseXML),
                        $vms = $response.find('VirtualMachines:eq(0) VirtualMachine'),
                        $pools = $response.find('ResourcePools:eq(0) ResourcePool'),
                        $custSpecs = $response.find('CustomizationSpecs:eq(0) CustomizationSpec'),
                        $folders = $response.find('Folders:eq(0) Folder');

                    this.$response = $response;

                    if ($vms.length) {
                        this.fillOptions($vms, $pools, $folders, $custSpecs);
                        this._toggleDialogSubmitButton(true);
                        this._toggleDialogShowButton(true);
                        this._toggleEditLinks(true);
                    }

                    this.validateImages();

                    return response;
                }.bind(this))
                .fail(function (errors) {
                    if (errors.length &&  errors[0].id === 'errorFetchResultsSSL') {
                        this.addError('An SSL error occurred while connecting to vCenter (is server certificate uploaded to  "SSL / HTTPS Certificates" of the Root project?): <br/>' + errors.text());
                    } else {
                        this.addError('Unable to fetch options: ' + errors.text());
                    }
                    this.fillOptions([], [], [], []);
                    this._displaySnapshotSelect([]);
                    BS.VMWareImageDialog.close();
                    return errors.text();
                }.bind(this))
                .always(function () {
                    $loader.addClass('hidden');
                    this._toggleFetchOptionsButton(true);
                    this._toggleLoadingMessage('fetchOptions');
                }.bind(this));

            this._toggleFetchOptionsButton();
            this._toggleDialogSubmitButton();
            this._toggleLoadingMessage('fetchOptions', true);
            $loader.removeClass('hidden');

            BS.ajaxRequest(this.refreshOptionsUrl, {
                parameters: BS.Clouds.Admin.CreateProfileForm.serializeParameters(),
                onFailure: function (response) {
                    this.fetchOptionsDeferred.reject(response.getStatusText());
                }.bind(this),
                onSuccess: function (response) {
                    var $response = $j(response.responseXML),
                        $error = $response.find('errors:eq(0) error');

                    if ($error.length) {
                        this.fetchOptionsDeferred.reject($error);
                    } else {
                        this.fetchOptionsDeferred.resolve(response);
                    }
                }.bind(this)
            });

            return false; // to prevent link with href='#' to scroll to the top of the page
        },