Example usage for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript

List of usage examples for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript

Introduction

In this page you can find the example usage for org.apache.wicket.ajax AjaxRequestTarget prependJavaScript.

Prototype

void prependJavaScript(CharSequence javascript);

Source Link

Document

Adds javascript that will be evaluated on the client side before components are replaced.

Usage

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private ModalWindow generateJoinGameWithoutIdModalWindow(final String id, final Player _player,
        final ModalWindow window) {
    window.setInitialWidth(475);// w w  w.  j a v a  2  s . co m
    window.setInitialHeight(500);
    window.setTitle("Join a match without ID");

    window.setContent(
            new JoinGameWithoutIdModalWindow(window, window.getContentId(), _player, this.dataBoxParent, this));
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);

    this.joinGameWithoutIdLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget _target) {
            _target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            _target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
            window.show(_target);
        }
    };

    this.joinGameWithoutIdLink.setOutputMarkupId(true).setMarkupId(id);
    window.setOutputMarkupId(true);

    this.add(this.joinGameWithoutIdLink);

    return window;
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private void generateImportDeckLink(final String id) {
    final AjaxLink<Void> importDeckLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override/*from   w  w w.ja v  a2  s  .  c o m*/
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            target.appendJavaScript("jQuery('#importDeck').dialog('open');");
        }
    };

    importDeckLink.setOutputMarkupId(true);
    this.importDeckDialog.setOutputMarkupId(true);
    this.add(importDeckLink);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private void generateCreateTokenLink(final String id, final ModalWindow window) {
    window.setInitialWidth(500);/*from w w w  . j  a va2  s  .com*/
    window.setInitialHeight(510);

    final CreateTokenModalWindow createTokenModalWindow = new CreateTokenModalWindow(window.getContentId(),
            window);
    window.setContent(createTokenModalWindow);
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    window.setTitle("Create a token");
    window.setOutputMarkupId(true);
    this.setCreateTokenModalWindow(window);
    this.add(window);

    final AjaxLink<Void> createTokenLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");

            HomePage.this.createTokenWindow.show(target);
        }
    };

    createTokenLink.setOutputMarkupId(true).setMarkupId(id);
    this.add(createTokenLink);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private void generateCountCardsLink(final String id, final ModalWindow window) {
    window.setInitialWidth(740);/* www  .j a va2 s. co  m*/
    window.setInitialHeight(550);

    window.setContent(new CountCardsModalWindow(window.getContentId(), this.session.getGameId()));
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    window.setOutputMarkupId(true);
    this.add(window);

    final AjaxLink<Void> countCardsLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);

            final Long _gameId = HomePage.this.session.getGameId();
            final CountCardsCometChannel cccc = new CountCardsCometChannel(_gameId,
                    HomePage.this.session.getPlayer().getName());

            final List<BigInteger> allPlayersInGame = HomePage.this.persistenceService
                    .giveAllPlayersFromGame(_gameId);
            EventBusPostService.post(allPlayersInGame, cccc);
        }
    };

    countCardsLink.setOutputMarkupId(true);
    this.add(countCardsLink);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private void generateDiscardAtRandomLink(final String id) {
    final AjaxLink<Void> generateDiscardAtRandomLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override//from w  w w  .j  a  v  a  2s .  c o  m
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);

            final Long _gameId = HomePage.this.session.getGameId();
            final List<BigInteger> allPlayersInGame = HomePage.this.persistenceService
                    .giveAllPlayersFromGame(_gameId);

            final Player playerWhoDiscards = HomePage.this.session.getPlayer();
            final Long playerWhoDiscardsDeckId = playerWhoDiscards.getDeck().getDeckId();
            final int allCardsInHand = HomePage.this.persistenceService
                    .getNumberOfCardsInACertainZoneForAGameAndADeck(CardZone.HAND, _gameId,
                            playerWhoDiscardsDeckId)
                    .intValue();

            if (allCardsInHand == 0) {
                return;
            }

            @SuppressWarnings("boxing")
            final int randomCardIndex = (allCardsInHand != 1
                    ? ((Double) Math.floor(Math.random() * allCardsInHand)).intValue()
                    : 0);
            final List<MagicCard> allCardsInHandForAGameAndAPlayer = HomePage.this.persistenceService
                    .getAllCardsInHandForAGameAndADeck(_gameId, playerWhoDiscardsDeckId);
            final MagicCard chosenCard = allCardsInHandForAGameAndAPlayer.remove(randomCardIndex);

            chosenCard.setZone(CardZone.GRAVEYARD);
            HomePage.this.persistenceService.updateCardWithoutMerge(chosenCard);
            HomePage.this.persistenceService.updateAllMagicCards(allCardsInHandForAGameAndAPlayer);

            playerWhoDiscards.setHandDisplayed(Boolean.TRUE);
            playerWhoDiscards.setGraveyardDisplayed(Boolean.TRUE);

            if (allCardsInHandForAGameAndAPlayer.isEmpty()) {
                playerWhoDiscards.getDeck().getCards().clear();
            }

            BattlefieldService.updateHand(target);
            BattlefieldService.updateGraveyard(target);

            final NotifierCometChannel ncc = new NotifierCometChannel(NotifierAction.DISCARD_AT_RANDOM, null,
                    playerWhoDiscards.getId(), playerWhoDiscards.getName(),
                    playerWhoDiscards.getSide().getSideName(), chosenCard.getTitle(), null, "");
            final ConsoleLogStrategy logger = AbstractConsoleLogStrategy.chooseStrategy(
                    ConsoleLogType.DISCARD_AT_RANDOM, null, null, null, chosenCard.getTitle(),
                    playerWhoDiscards.getName(), null, null, null, Boolean.FALSE, _gameId);

            EventBusPostService.post(allPlayersInGame, ncc, new ConsoleLogCometChannel(logger));
        }
    };

    generateDiscardAtRandomLink.setOutputMarkupId(true);
    this.add(generateDiscardAtRandomLink);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private void generateLoginLink(final String id, final ModalWindow window) {
    window.setInitialWidth(300);/*from   ww  w .  java  2 s  .  c o m*/
    window.setInitialHeight(200);
    window.setTitle("HatchetHarry login");
    window.setContent(new LoginModalWindow(window.getContentId(), window));
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    window.setOutputMarkupId(true);
    window.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean onCloseButtonClicked(final AjaxRequestTarget target) {
            target.appendJavaScript("authenticateUserWithFacebook();");
            return true;
        }
    });
    this.add(window);

    final AjaxLink<Void> loginLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
            HomePage.this.loginWindow.show(target);
        }
    };

    loginLink.setOutputMarkupId(true);
    this.add(loginLink);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

private void generatePreferencesLink(final String id, final ModalWindow window) {
    window.setInitialWidth(630);/*from  ww  w .j av a2  s . c o m*/
    window.setInitialHeight(300);
    window.setTitle("User preferences");
    window.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
    window.setMaskType(ModalWindow.MaskType.SEMI_TRANSPARENT);
    window.setOutputMarkupId(true);
    this.add(window);

    final AjaxLink<Void> preferencesLink = new AjaxLink<Void>(id) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            window.setContent(new UserPreferencesModalWindow(window.getContentId(), window));
            target.prependJavaScript(BattlefieldService.HIDE_MENUS);
            target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");
            HomePage.this.preferencesWindow.show(target);
        }
    };

    preferencesLink.setOutputMarkupId(true);
    this.add(preferencesLink);
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void updateTime(final AjaxRequestTarget target, final Date event) {
    target.prependJavaScript(
            "if (document.activeElement.tagName !== 'INPUT') { var chatPos = document.getElementById('chat').scrollTop; document.getElementById('clockLabel').innerHTML = '"
                    + event.toString() + "'; document.getElementById('chat').scrollTop = chatPos; }");
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void playCardFromHand(final AjaxRequestTarget target, final PlayCardFromHandCometChannel event) {
    final MagicCard mc = event.getMagicCard();

    Component me;/*from   w  ww. j  a v a  2s.  c  o  m*/

    if (event.getPlayerName().equals(this.session.getPlayer().getName())) {
        me = this.parentPlaceholder;
    } else {
        me = this.opponentParentPlaceholder;
    }

    me.add(new DisplayNoneBehavior());
    target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(500, notify);");

    BattlefieldService.updateCardsAndRestoreStateInBattlefield(target, this.persistenceService,
            event.getGameId(), mc, true);
    target.appendJavaScript(BattlefieldService.REACTIVATE_BATTLEFIELD_JAVASCRIPT);
    target.appendJavaScript(
            "jQuery('#" + me.getMarkupId() + "').fadeIn(500); jQuery('#cardInBattlefieldContextMenu"
                    + mc.getUuidObject().toString().replace("-", "_")
                    + "').popmenu({ 'background': 'black', 'focusColor': '#BBBBBB' }); ");
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void revealTopLibraryCard(final AjaxRequestTarget target, final RevealTopLibraryCardCometChannel event) {
    target.prependJavaScript(BattlefieldService.HIDE_MENUS);
    target.appendJavaScript("Wicket.Window.unloadConfirmation = false;");

    this.revealTopLibraryCardWindow.setTitle("This is the top card #" + (event.getIndex() + 1L) + " of "
            + event.getPlayerName() + "'s library: ");
    this.revealTopLibraryCardWindow.setContent(new RevealTopLibraryCardModalWindow(
            this.revealTopLibraryCardWindow.getContentId(), this.revealTopLibraryCardWindow, event.getCard()));

    this.allOpenRevealTopLibraryCardWindows.add(this.revealTopLibraryCardWindow);
    this.revealTopLibraryCardWindow.show(target);
}