Search in sources :

Example 1 with HTMLAnchorElement

use of elemental2.dom.HTMLAnchorElement in project kie-wb-common by kiegroup.

the class DocumentPreviewViewImpl method setState.

@Override
public void setState(DocumentPreviewState previewState, Collection<DocumentPreviewStateAction> previewActions) {
    state.className = resolveStateStyle(previewState);
    if (previewState.equals(DocumentPreviewState.STORED)) {
        document.classList.remove(DISABLED_ANCHOR_STYLE);
        document.href = presenter.getDocumentLink();
        document.download = presenter.getDocumentName();
    } else {
        document.classList.add(DISABLED_ANCHOR_STYLE);
        document.removeAttribute("href");
        document.removeAttribute("download");
    }
    clearActions();
    previewActions.forEach(action -> {
        if (actions.lastChild != null) {
            HTMLElement separator = (HTMLElement) doc.createElement("span");
            separator.textContent = "|";
            separator.className = CONTENT;
            actions.appendChild(separator);
        }
        HTMLAnchorElement anchor = (HTMLAnchorElement) doc.createElement("a");
        anchor.textContent = action.getLabel();
        anchor.onclick = event -> {
            action.execute();
            return null;
        };
        actions.appendChild(anchor);
    });
}
Also used : HTMLElement(elemental2.dom.HTMLElement) HTMLAnchorElement(elemental2.dom.HTMLAnchorElement)

Example 2 with HTMLAnchorElement

use of elemental2.dom.HTMLAnchorElement in project kie-wb-common by kiegroup.

the class VariableListItemWidgetTest method testHandleBadgeCloseEvent.

@Test
public void testHandleBadgeCloseEvent() {
    VariablesEditorWidgetView.Presenter presenter = mock(VariablesEditorWidgetView.Presenter.class);
    widget.setParentWidget(presenter);
    HTMLLabelElement tagLabel = mock(HTMLLabelElement.class);
    HTMLAnchorElement tagCloseButton = mock(HTMLAnchorElement.class);
    elemental2.dom.Event ex = mock(elemental2.dom.Event.class);
    ex.type = "SomeType";
    widget.setTagSet(new HashSet<>());
    widget.handleBadgeCloseEvent("internal", tagLabel, tagCloseButton, ex);
    verify(tagLabel, times(1)).remove();
    verify(tagCloseButton, times(1)).remove();
    // Updated Model
    verify(widget, times(1)).notifyModelChanged();
    ex.type = "DoNotUpdateModel";
    widget.setTagSet(new HashSet<>());
    widget.handleBadgeCloseEvent("internal", tagLabel, tagCloseButton, ex);
    verify(tagLabel, times(2)).remove();
    verify(tagCloseButton, times(2)).remove();
    // No New Calls to Updated Model
    verify(widget, times(1)).notifyModelChanged();
}
Also used : HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) HTMLLabelElement(elemental2.dom.HTMLLabelElement) Test(org.junit.Test)

Example 3 with HTMLAnchorElement

use of elemental2.dom.HTMLAnchorElement in project kie-wb-common by kiegroup.

the class HTMLDownloadHelper method download.

public void download(final String filename, final String html) {
    final String sourceHTML = HEADER + html + FOOTER;
    final String source = Global.encodeURIComponent(sourceHTML);
    final HTMLAnchorElement fileDownload = (HTMLAnchorElement) document.createElement("a");
    document.body.appendChild(fileDownload);
    fileDownload.href = ENCODING + source;
    fileDownload.download = filename + FILE_EXTENSION;
    fileDownload.onclick = (e) -> null;
    document.body.removeChild(fileDownload);
}
Also used : HTMLAnchorElement(elemental2.dom.HTMLAnchorElement)

Example 4 with HTMLAnchorElement

use of elemental2.dom.HTMLAnchorElement in project kie-wb-common by kiegroup.

the class VariableListItemWidgetViewImpl method getBadgeCloseButton.

protected HTMLAnchorElement getBadgeCloseButton() {
    final HTMLAnchorElement badgeCloseButton = (HTMLAnchorElement) document.createElement("a");
    badgeCloseButton.id = "closeButton";
    badgeCloseButton.textContent = "x";
    badgeCloseButton.className = "close tagCloseButton tagBadges";
    return badgeCloseButton;
}
Also used : HTMLAnchorElement(elemental2.dom.HTMLAnchorElement)

Example 5 with HTMLAnchorElement

use of elemental2.dom.HTMLAnchorElement in project kie-wb-common by kiegroup.

the class VariableListItemWidgetViewImpl method renderTagElementsBadges.

protected void renderTagElementsBadges() {
    for (final String tag : tagSet) {
        final HTMLLabelElement tagLabel = getBadgeElement(tag);
        final HTMLAnchorElement badgeCloseButton = getBadgeCloseButton();
        badgeCloseButton.onclick = ex -> {
            handleBadgeCloseEvent(tag, tagLabel, badgeCloseButton, ex);
            return null;
        };
        tagLabel.appendChild(badgeCloseButton);
        tagsContainer.appendChild(tagLabel);
        updateTagCount();
        removeButtons.put(tag, badgeCloseButton);
    }
}
Also used : HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) HTMLLabelElement(elemental2.dom.HTMLLabelElement)

Aggregations

HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)7 HTMLLabelElement (elemental2.dom.HTMLLabelElement)3 Test (org.junit.Test)2 HTMLDivElement (elemental2.dom.HTMLDivElement)1 HTMLElement (elemental2.dom.HTMLElement)1 EventHandler (org.jboss.errai.ui.shared.api.annotations.EventHandler)1 Mockito.anyString (org.mockito.Mockito.anyString)1