Search in sources :

Example 1 with GetPostsFailure

use of com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsFailure in project blogwt by billy1380.

the class PostController method fetchPosts.

private void fetchPosts() {
    final GetPostsRequest input = ApiHelper.setAccessCode(new GetPostsRequest());
    input.session = SessionController.get().sessionForApiCall();
    input.includePostContents = Boolean.FALSE;
    input.archiveEntry = archiveEntry;
    input.showAll = Boolean.valueOf(isAdminMode);
    if (SessionController.get().isValidSession()) {
        pager.sortBy = PostSortType.PostSortTypeCreated.toString();
    } else {
        pager.sortBy = PostSortType.PostSortTypePublished.toString();
    }
    input.pager = pager;
    input.tag = tag;
    if (getPostsRequest != null) {
        getPostsRequest.cancel();
    }
    getPostsRequest = ApiHelper.createBlogClient().getPosts(input, new AsyncCallback<GetPostsResponse>() {

        @Override
        public void onSuccess(GetPostsResponse output) {
            getPostsRequest = null;
            if (output.status == StatusType.StatusTypeSuccess) {
                if (output.posts != null && output.posts.size() > 0) {
                    pager = output.pager;
                    updateRowCount(input.pager.count == null ? 0 : input.pager.count.intValue(), input.pager.count == null || input.pager.count.intValue() == 0);
                    updateRowData(input.pager.start.intValue(), output.posts);
                } else {
                    updateRowCount(input.pager.start.intValue(), true);
                    updateRowData(input.pager.start.intValue(), Collections.<Post>emptyList());
                }
            }
            DefaultEventBus.get().fireEventFromSource(new GetPostsSuccess(input, output), PostController.this);
        }

        @Override
        public void onFailure(Throwable caught) {
            getPostsRequest = null;
            DefaultEventBus.get().fireEventFromSource(new GetPostsFailure(input, caught), PostController.this);
        }
    });
}
Also used : GetPostsRequest(com.willshex.blogwt.shared.api.blog.call.GetPostsRequest) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetPostsSuccess(com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsSuccess) GetPostsResponse(com.willshex.blogwt.shared.api.blog.call.GetPostsResponse) GetPostsFailure(com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsFailure)

Aggregations

AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 GetPostsFailure (com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsFailure)1 GetPostsSuccess (com.willshex.blogwt.client.api.blog.event.GetPostsEventHandler.GetPostsSuccess)1 GetPostsRequest (com.willshex.blogwt.shared.api.blog.call.GetPostsRequest)1 GetPostsResponse (com.willshex.blogwt.shared.api.blog.call.GetPostsResponse)1