Search in sources :

Example 11 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class EditMailFooterTabItem method draw.

public Widget draw() {
    final FlexTable content = new FlexTable();
    content.setStyleName("inputFormFlexTable");
    content.setWidth("360px");
    final TextArea footer = new TextArea();
    footer.setSize("340px", "200px");
    content.setHTML(0, 0, "Footer text:");
    content.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    content.setWidget(1, 0, footer);
    content.setHTML(2, 0, "This text will be added as footer for all email notifications (replacing {mailFooter} tag in mail definition).");
    content.getFlexCellFormatter().setStyleName(2, 0, "inputFormInlineComment");
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    if (group == null) {
        ids.put("vo", voId);
    } else {
        ids.put("group", groupId);
    }
    final ArrayList<Attribute> list = new ArrayList<Attribute>();
    final GetListOfAttributes call = new GetListOfAttributes(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            list.addAll(JsonUtils.<Attribute>jsoAsList(jso));
            // only if attribute exists
            if (list != null && !list.isEmpty()) {
                for (Attribute a : list) {
                    if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
                        // if value not null - enter
                        if (!a.getValue().equalsIgnoreCase("null")) {
                            footer.setText(a.getValue());
                        }
                    }
                }
            }
        }
    });
    ArrayList<String> l = new ArrayList<String>();
    if (group == null) {
        l.add("urn:perun:vo:attribute-def:def:mailFooter");
    } else {
        l.add("urn:perun:group:attribute-def:def:mailFooter");
    }
    call.getListOfAttributes(ids, l);
    final TabItem tab = this;
    VerticalPanel vp = new VerticalPanel();
    TabMenu menu = new TabMenu();
    final CustomButton save = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveMailFooter());
    save.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            // will be set
            ArrayList<Attribute> toSend = new ArrayList<Attribute>();
            // will be removed
            ArrayList<Attribute> toRemove = new ArrayList<Attribute>();
            for (Attribute a : list) {
                String oldValue = a.getValue();
                String newValue = "";
                if (a.getFriendlyName().equalsIgnoreCase("mailFooter")) {
                    newValue = footer.getText();
                } else {
                    // other than mailFooter attributes must be skipped
                    continue;
                }
                if (oldValue.equalsIgnoreCase(newValue) || (oldValue.equalsIgnoreCase("null") && newValue.equalsIgnoreCase(""))) {
                    // skip this cycle
                    continue;
                } else {
                    if (newValue.equalsIgnoreCase("")) {
                        // value was cleared
                        toRemove.add(a);
                    } else {
                        // set value
                        a.setValue(newValue);
                        // value was changed / added
                        toSend.add(a);
                    }
                }
            }
            // requests
            SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            RemoveAttributes removeRequest = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(save, tab));
            // send if not empty
            if (!toRemove.isEmpty()) {
                removeRequest.removeAttributes(ids, toRemove);
            }
            if (!toSend.isEmpty()) {
                request.setAttributes(ids, toSend);
            }
        }
    });
    menu.addWidget(save);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(content);
    vp.add(menu);
    vp.setCellHeight(menu, "30px");
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) GetListOfAttributes(cz.metacentrum.perun.webgui.json.attributesManager.GetListOfAttributes) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 12 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class MembershipExpirationTabItem method draw.

public Widget draw() {
    this.titleWidget.setText("Set membership expiration");
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("350px", "100%");
    final FlexTable layout = new FlexTable();
    layout.setSize("100%", "100%");
    layout.setStyleName("inputFormFlexTable");
    layout.setHTML(0, 0, "Current expiration:");
    layout.getFlexCellFormatter().setStyleName(0, 0, "itemName");
    layout.setHTML(0, 1, member.getStatus());
    final Attribute expire = member.getAttribute("urn:perun:member:attribute-def:def:membershipExpiration");
    String expirationValue = null;
    if (expire != null && !"null".equalsIgnoreCase(expire.getValue())) {
        layout.setHTML(0, 1, expire.getValue());
        expirationValue = expire.getValue().substring(0, ((expire.getValue().length() > 10) ? 9 : expire.getValue().length() - 1));
    } else {
        layout.setHTML(0, 1, "<i>never</i>");
    }
    layout.setHTML(1, 0, "New expiration:");
    layout.getFlexCellFormatter().setStyleName(1, 0, "itemName");
    final CustomButton changeButton = new CustomButton("Save", "Save changes in membership expiration date", SmallIcons.INSTANCE.diskIcon());
    final DatePicker picker = new DatePicker();
    picker.setWidth("100%");
    layout.getFlexCellFormatter().setColSpan(2, 0, 2);
    layout.setWidget(2, 0, picker);
    picker.addValueChangeHandler(new ValueChangeHandler<Date>() {

        @Override
        public void onValueChange(ValueChangeEvent<Date> dateValueChangeEvent) {
            layout.setHTML(1, 1, DateTimeFormat.getFormat("yyyy-MM-dd").format(picker.getValue()));
            changeButton.setEnabled(true);
            changeOrNever = true;
        }
    });
    try {
        // set values if possible
        picker.setCurrentMonth(DateTimeFormat.getFormat("yyyy-MM-dd").parse(expirationValue));
        picker.setValue(DateTimeFormat.getFormat("yyyy-MM-dd").parse(expirationValue));
    } catch (Exception ex) {
        // if not parseable, display current date
        picker.setCurrentMonth(new Date());
        picker.setValue(new Date());
    }
    Anchor anchor = new Anchor("Set expiration to 'never'");
    anchor.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            layout.setHTML(1, 1, "<i>never</i>");
            changeOrNever = false;
            changeButton.setEnabled(true);
        }
    });
    layout.setWidget(3, 0, anchor);
    layout.getFlexCellFormatter().setColSpan(3, 0, 2);
    layout.getFlexCellFormatter().getElement(3, 0).setAttribute("style", "text-align: right;");
    TabMenu menu = new TabMenu();
    final TabItem tab = this;
    // by default false
    changeButton.setEnabled(false);
    changeButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            if (changeOrNever) {
                expire.setValueAsString(DateTimeFormat.getFormat("yyyy-MM-dd").format(picker.getValue()));
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("member", member.getId());
                SetAttributes request = new SetAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
                ArrayList<Attribute> list = new ArrayList<Attribute>();
                list.add(expire);
                request.setAttributes(ids, list);
            } else {
                Map<String, Integer> ids = new HashMap<String, Integer>();
                ids.put("member", member.getId());
                RemoveAttributes request = new RemoveAttributes(JsonCallbackEvents.closeTabDisableButtonEvents(changeButton, tab));
                ArrayList<Attribute> list = new ArrayList<Attribute>();
                list.add(expire);
                request.removeAttributes(ids, list);
            }
        }
    });
    menu.addWidget(changeButton);
    menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, ButtonTranslation.INSTANCE.cancelButton(), new ClickHandler() {

        @Override
        public void onClick(ClickEvent clickEvent) {
            session.getTabManager().closeTab(tab, false);
        }
    }));
    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
    this.contentWidget.setWidget(vp);
    return getWidget();
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) ArrayList(java.util.ArrayList) Date(java.util.Date) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) TabItem(cz.metacentrum.perun.webgui.tabs.TabItem) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) DatePicker(com.google.gwt.user.datepicker.client.DatePicker) HashMap(java.util.HashMap) Map(java.util.Map) RemoveAttributes(cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)

Example 13 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class GroupsResourceRequiredAttributesTabItem method draw.

public Widget draw() {
    if (groups == null || groups.get(0) == null) {
        Window.alert("No groups in list.");
    }
    if (JsonUtils.isExtendedInfoVisible()) {
        columnId = 3;
    } else {
        columnId = 2;
    }
    final VerticalPanel mainTab = new VerticalPanel();
    mainTab.setSize("100%", "100%");
    TabMenu menu = new TabMenu();
    mainTab.add(new HTML("<hr size=\"2px\" />"));
    // set attributes type to group_resource
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("resourceToGetServicesFrom", resourceId);
    ids.put("group", groups.get(0).getId());
    // gets all required group attributes for specified group and resource
    final GetResourceRequiredAttributesV2 reqAttrs = new GetResourceRequiredAttributesV2(ids);
    final CellTable<Attribute> reqAttrsTable = reqAttrs.getTable();
    // remove value column
    reqAttrsTable.removeColumn(columnId);
    // create own value column
    Column<Attribute, Attribute> valueColumn = JsonUtils.addColumn(new PerunAttributeValueCell(), "Value", new JsonUtils.GetValue<Attribute, Attribute>() {

        public Attribute getValue(Attribute attribute) {
            // set empty value
            attribute.setValueAsJso(null);
            return attribute;
        }
    }, new FieldUpdater<Attribute, Attribute>() {

        public void update(int index, Attribute object, Attribute value) {
            object = value;
            reqAttrsTable.getSelectionModel().setSelected(object, object.isAttributeValid());
        }
    });
    // add to table
    reqAttrsTable.insertColumn(columnId, valueColumn, "Value");
    // get all required group_resource attributes too
    ids.put("resource", resourceId);
    reqAttrs.setIds(ids);
    reqAttrs.retrieveData();
    reqAttrsTable.addStyleName("perun-table");
    final ScrollPanel sp = new ScrollPanel(reqAttrsTable);
    sp.addStyleName("perun-tableScrollPanel");
    CustomButton saveChangesButton = TabMenu.getPredefinedButton(ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes(), new ClickHandler() {

        public void onClick(ClickEvent event) {
            ArrayList<Attribute> list = reqAttrs.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {
                ArrayList<Attribute> groupList = new ArrayList<Attribute>();
                ArrayList<Attribute> groupResourceList = new ArrayList<Attribute>();
                SetAttributes request = new SetAttributes();
                // TODO - use new confirm dialog
                if (!Window.confirm("Same values for selected attributes will be set to all groups you are about to assign." + "\n\nDo you want to continue ?")) {
                    return;
                }
                // get different attributes
                for (Attribute attr : list) {
                    if (attr.getNamespace().contains("urn:perun:group:")) {
                        groupList.add(attr);
                    } else if (attr.getNamespace().contains("urn:perun:group_resource:")) {
                        groupResourceList.add(attr);
                    }
                }
                if (!(groupList.isEmpty())) {
                    ids.clear();
                    for (int i = 0; i < groups.size(); i++) {
                        ids.put("group", groups.get(i).getId());
                        request.setAttributes(ids, groupList);
                    }
                }
                if (!(groupResourceList.isEmpty())) {
                    ids.clear();
                    ids.put("resource", resourceId);
                    for (int i = 0; i < groups.size(); i++) {
                        ids.put("group", groups.get(i).getId());
                        request.setAttributes(ids, groupResourceList);
                    }
                }
                reqAttrs.clearTableSelectedSet();
            }
        }
    });
    menu.addWidget(UiElements.getRefreshButton(this));
    menu.addWidget(saveChangesButton);
    if (!session.isGroupAdmin() && !session.isVoAdmin())
        saveChangesButton.setEnabled(false);
    // table content
    session.getUiElements().resizePerunTable(sp, 350, this);
    mainTab.add(menu);
    mainTab.add(sp);
    mainTab.setCellHeight(sp, "100%");
    mainTab.setCellHeight(menu, "30px");
    this.contentWidget.setWidget(mainTab);
    return getWidget();
}
Also used : PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) SetAttributes(cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes) TabMenu(cz.metacentrum.perun.webgui.widgets.TabMenu) GetResourceRequiredAttributesV2(cz.metacentrum.perun.webgui.json.attributesManager.GetResourceRequiredAttributesV2) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) JsonUtils(cz.metacentrum.perun.webgui.json.JsonUtils) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton)

Example 14 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class PerunAttributeTableWidget method add.

/**
	 * Adds attributes
	 */
public void add(ArrayList<Attribute> attributes) {
    this.attributes.addAll(attributes);
    for (Attribute a : attributes) {
        this.originalAttributes.put(a.getId(), a.getValue());
    }
    build();
}
Also used : Attribute(cz.metacentrum.perun.webgui.model.Attribute)

Example 15 with Attribute

use of cz.metacentrum.perun.webgui.model.Attribute in project perun by CESNET.

the class PerunAttributeTableWidget method build.

/**
	 * Builds the table
	 */
public void build() {
    ft.clear(true);
    if (!dark) {
        ft.setStyleName("inputFormFlexTable");
    } else {
        ft.setStyleName("inputFormFlexTableDark");
    }
    int nameCol = 0;
    int valCol = 1;
    int descCol = -1;
    if (descriptionShown) {
        nameCol = 0;
        descCol = 2;
        valCol = 1;
    }
    int row = 0;
    final Map<Attribute, PerunAttributeValueCell> valueCells = new HashMap<Attribute, PerunAttributeValueCell>();
    // save button
    saveButton = TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes");
    saveButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            // saving
            ArrayList<Attribute> newAttributes = new ArrayList<Attribute>();
            // for each find
            for (Map.Entry<Attribute, PerunAttributeValueCell> entry : valueCells.entrySet()) {
                Attribute attrOld = entry.getKey();
                PerunAttributeValueCell valueCell = entry.getValue();
                // save the value
                Attribute attr = valueCell.getValue(attrOld);
                newAttributes.add(attr);
            }
            save(newAttributes);
        }
    });
    if (displaySaveButton) {
        ft.setWidget(row, 0, saveButton);
        row++;
    }
    for (Attribute attr : attributes) {
        PerunAttributeNameCell nameCell = new PerunAttributeNameCell();
        PerunAttributeValueCell valueCell = new PerunAttributeValueCell();
        // name
        SafeHtml nameCellHtml = nameCell.getRenderer().render(attr);
        ft.setHTML(row, nameCol, nameCellHtml.asString() + "<strong>:</strong>");
        ft.getFlexCellFormatter().setStyleName(row, nameCol, "itemName");
        // value
        SafeHtml valueCellHtml = valueCell.getRenderer().render(attr);
        ft.setHTML(row, valCol, valueCellHtml);
        valueCells.put(attr, valueCell);
        // description
        if (descriptionShown) {
            PerunAttributeDescriptionCell descCell = new PerunAttributeDescriptionCell();
            SafeHtml descCellHtml = descCell.getRenderer().render(attr);
            ft.setHTML(row, descCol, descCellHtml);
        }
        row++;
    }
}
Also used : PerunAttributeValueCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell) HashMap(java.util.HashMap) Attribute(cz.metacentrum.perun.webgui.model.Attribute) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ArrayList(java.util.ArrayList) PerunAttributeNameCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) PerunAttributeDescriptionCell(cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)

Aggregations

Attribute (cz.metacentrum.perun.webgui.model.Attribute)58 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)17 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)17 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)16 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)16 ArrayList (java.util.ArrayList)16 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)15 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)15 HashMap (java.util.HashMap)14 ListHandler (com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)12 PerunError (cz.metacentrum.perun.webgui.model.PerunError)10 SetAttributes (cz.metacentrum.perun.webgui.json.attributesManager.SetAttributes)9 PerunAttributeValueCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeValueCell)9 Map (java.util.Map)9 RemoveAttributes (cz.metacentrum.perun.webgui.json.attributesManager.RemoveAttributes)8 CheckboxCell (com.google.gwt.cell.client.CheckboxCell)7 GeneralObject (cz.metacentrum.perun.webgui.model.GeneralObject)7 PerunAttributeDescriptionCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeDescriptionCell)7 PerunAttributeNameCell (cz.metacentrum.perun.webgui.widgets.cells.PerunAttributeNameCell)7 Column (com.google.gwt.user.cellview.client.Column)6