_bindHandlers: function()

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


        _bindHandlers: function () {
            var self = this;

            //// Click Handlers
            this.$fetchOptionsButton.on('click', this._fetchOptionsClickHandler.bind(this));
            this.$showDialogButton.on('click', this._showDialogClickHandler.bind(this));
            this.$addImageButton.on('click', this._submitDialogClickHandler.bind(this));
            this.$cancelButton.on('click', this._cancelDialogClickHandler.bind(this));
            this.$imagesTable.on('click', this.selectors.rmImageLink, function () {
                var $this = $j(this),
                    id = $this.data('image-id'),
                    name = self.imagesData[id].sourceVmName;

                if (confirm('Are you sure you want to remove the image "' + name + '"?')) {
                    self.removeImage($this);
                }
                return false;
            });
            var editDelegates = this.selectors.imagesTableRow + ' .highlight, ' + this.selectors.editImageLink;
            var that = this;
            this.$imagesTable.on('click', editDelegates, function () {
                if (!that.$addImageButton.prop('disabled')) {
                    self.showEditDialog($j(this));
                }
                return false;
            });

            //// Change Handlers
            // - image
            this.$options.on('change', this.selectors.imagesSelect, function(e, value) {
                if (arguments.length === 1) { // native change by user
                    this._image.sourceVmName = e.target.value;
                    this._image.$image = this._getSourceByName(e.target.value);
                    delete this._image.snapshot;
                } else {
                    this._tryToUpdateSelect(this.$image, value);
                }
              if (!!this._image.$image && this._image.$image.length == 1){
                this._image.$datacenterId = $j(this._image.$image[0]).attr("datacenterId");
                this._filterPoolsAndFolders(this._image.$datacenterId);
              }

                if (this._isClone()) {
                    this.fetchSnapshots();
                }

                $j('#cloneBehaviour_' + START_STOP)
                    .prop('disabled', this._isTemplate())
                    .siblings('label').toggleClass('disabled', this._isTemplate());
                this.validateOptions(e.target.getAttribute('data-id'));
            }.bind(this));
            // - clone behaviour
            // hidden input, triggered from JS only
            this.$behaviour.on('change', function (e, value) {
                var startStop = $j('#cloneBehaviour_' + START_STOP),
                    freshClone = $j('#cloneBehaviour_' + FRESH_CLONE),
                    onDemandClone = $j('#cloneBehaviour_' + ON_DEMAND_CLONE);

                if (arguments.length === 1) {
                    if (startStop.is(':checked')) {
                        this._image.behaviour = startStop.val();
                    } else if (freshClone.is(':checked')) { // FRESH_CLONE is checked if START_STOP is not
                        this._image.behaviour = freshClone.val();
                    } else if (onDemandClone.is(':checked')){
                        this._image.behaviour = onDemandClone.val();
                    }
                } else {
                    $j(this.selectors.behaviourSwitch).prop('checked', false);
                    $j('#cloneBehaviour_' + value).prop('checked', true);
                    this._image.behaviour = value;
                }
                if (this._image.behaviour == startStop.val()){
                    this._image.nickname = '';
                }
                this.$cloneOptions.toggleClass('hidden', !this._isClone());
                if (this._isClone()) {
                    this.fetchSnapshots();
                    if (this._image.snapshot && this.fetchSnapshotsDeferred) {
                        this.fetchSnapshotsDeferred.then(function () {
                            this.$snapshot.trigger('change', this._image.snapshot);
                        }.bind(this));
                    }
                    !this._image.maxInstances && this.$maxInstances.trigger('change', this._image.maxInstances = 1);
                }

                this.clearErrors(e.target.getAttribute('data-err-id'));

                this.validateOptions(e.target.getAttribute('data-id'));
            }.bind(this));
            $j(this.selectors.behaviourSwitch).on('change', function (e) {
                this.$behaviour.trigger('change', e.target.value);
            }.bind(this));
            // - snapshot
            this.$snapshot.on('change', function(e, value) {
                if (arguments.length === 1) {
                    this._image.snapshot = this.$snapshot.val();
                } else {
                    this._tryToUpdateSelect(this.$snapshot, value);
                }
                this.$currentStateWarning.toggleClass('hidden', this._image.snapshot !== CURRENT_STATE);
                this.validateOptions(e.target.getAttribute('data-id'));
            }.bind(this));

            this.$resourcePool.on('change', function(e, value){
              this.checkHelper('respool', this.$resourcePool.val(), 'pool');
            }.bind(this));

            this.$cloneFolder.on('change', function(e, value){
              this.checkHelper('folder', this.$cloneFolder.val(), 'folder');
            }.bind(this));

            this.$cloneFolder
                .add(this.$resourcePool)
                .add(this.$customizationSpec)
                .add(this.$agentPool)
                .on('change', function (e, value) {
                var elem = e.target;

                if (arguments.length === 1) {
                    this._image[elem.getAttribute('data-id')] = elem.value;
                } else {
                    this._tryToUpdateSelect($j(elem), value);
                }
                this.validateOptions(elem.getAttribute('data-id'));
            }.bind(this));

            // - instances
            this.$maxInstances.on('change', function (e, value) {
                if (arguments.length === 1) {
                    this._image.maxInstances = this.$maxInstances.val();
                } else {
                    this.$maxInstances.val(value);
                }
                this.validateOptions(e.target.getAttribute('data-id'));
            }.bind(this));
            this.$nickname.on('change', function (e, value) {
                if (arguments.length === 1) {
                    this._image.nickname = this.$nickname.val();
                } else {
                    this.$nickname.val(value);
                }
                this.validateOptions(e.target.getAttribute('data-id'));
            }.bind(this));
        },