Package com.arcbees.gwtpwebsite.client.application.buypro.ui

Source Code of com.arcbees.gwtpwebsite.client.application.buypro.ui.EmailPresenter

/**
* Copyright 2013 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.arcbees.gwtpwebsite.client.application.buypro.ui;

import javax.inject.Inject;

import org.fusesource.restygwt.client.Method;
import org.fusesource.restygwt.client.MethodCallback;

import com.arcbees.gwtpwebsite.client.rest.AskForProService;
import com.arcbees.gwtpwebsite.shared.domain.Request;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.View;

public class EmailPresenter extends PresenterWidget<EmailPresenter.MyView> implements EmailViewUiHandlers {
    public interface MyView extends HasUiHandlers<EmailViewUiHandlers>, View {
        void oopsSomethingWentWrong();

        void sayThankYou();

        String getName();

        String getEmail();

        String getMessage();

        boolean isFormValid();

        void showErrorMessage();
    }

    private final AskForProService askForProService;

    @Inject
    EmailPresenter(EventBus eventBus,
                   MyView view,
                   AskForProService askForProService) {
        super(eventBus, view);

        this.askForProService = askForProService;

        getView().setUiHandlers(this);
    }

    @Override
    public void onContactClicked() {
        if (getView().isFormValid()) {
            contactSellerBee();
        } else {
            getView().showErrorMessage();
        }
    }

    private void contactSellerBee() {
        String name = getView().getName();
        String email = getView().getEmail();
        String message = getView().getMessage();

        Request request = new Request();
        request.setClientName(name);
        request.setClientEmail(email);
        request.setBody(message);

        sendRequest(request);
    }

    private void sendRequest(Request request) {
        askForProService.sendRequest(request, new MethodCallback<Void>() {
            @Override
            public void onFailure(Method method, Throwable exception) {
                getView().oopsSomethingWentWrong();
            }

            @Override
            public void onSuccess(Method method, Void response) {
                getView().sayThankYou();
            }
        });
    }
}
TOP

Related Classes of com.arcbees.gwtpwebsite.client.application.buypro.ui.EmailPresenter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.