syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject [8/8] syncope git commit: [SYNCOPE-156] modal window review in order to make content change possible at runtime
Date Tue, 15 Sep 2015 13:44:25 GMT
[SYNCOPE-156] modal window review in order to make content change possible at runtime


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/7526a2d5
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/7526a2d5
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/7526a2d5

Branch: refs/heads/SYNCOPE-156
Commit: 7526a2d59c482b708cbfe5da27f216023e554d01
Parents: 85df1a7
Author: fmartelli <fabio.martelli@gmail.com>
Authored: Tue Sep 15 15:43:43 2015 +0200
Committer: fmartelli <fabio.martelli@gmail.com>
Committed: Tue Sep 15 15:43:43 2015 +0200

----------------------------------------------------------------------
 .../syncope/client/console/pages/BasePage.java  |  27 +++
 .../syncope/client/console/pages/Realms.java    | 166 ++++++++++++-------
 .../console/panels/AbstractModalPanel.java      |  43 ++---
 .../console/panels/EditRealmModalPanel.java     |  40 -----
 .../client/console/panels/GroupModalPanel.java  |  14 +-
 .../console/panels/GroupSearchResultPanel.java  |   2 +-
 .../client/console/panels/RealmModalPanel.java  |  79 ++++-----
 .../client/console/rest/RealmRestClient.java    |   8 +
 .../bootstrap/buttons/PrimaryModalButton.java   |   2 +-
 .../markup/html/bootstrap/dialog/BaseModal.java | 116 ++++++++++---
 .../syncope/client/console/pages/Realms.html    |  15 +-
 .../console/panels/AbstractModalPanel.html      |  24 +--
 .../client/console/panels/RealmModalPanel.html  |   6 +-
 .../markup/html/bootstrap/dialog/BaseModal.html |  28 +++-
 14 files changed, 335 insertions(+), 235 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/pages/BasePage.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/BasePage.java
b/client/console/src/main/java/org/apache/syncope/client/console/pages/BasePage.java
index d82c247..921888e 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/pages/BasePage.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/BasePage.java
@@ -22,6 +22,7 @@ import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.rest.UserWorkflowRestClient;
 import org.apache.syncope.client.console.topology.Topology;
+import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
 import org.apache.syncope.common.lib.types.Entitlement;
 import org.apache.wicket.Component;
 import org.apache.wicket.Page;
@@ -175,4 +176,30 @@ public class BasePage extends AbstractBasePage implements IAjaxIndicatorAware
{
             }
         });
     }
+    
+    /**
+     * Set a WindowClosedCallback for a Modal instance.
+     *
+     * @param modal window
+     * @param container container
+     */
+    public void setWindowClosedCallback(final BaseModal modal, final WebMarkupContainer container)
{
+        modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
+
+            private static final long serialVersionUID = 8804221891699487139L;
+
+            @Override
+            public void onClose(final AjaxRequestTarget target) {
+                if (container != null) {
+                    target.add(container);
+                }
+
+                if (isModalResult()) {
+                    info(getString(Constants.OPERATION_SUCCEEDED));
+                    feedbackPanel.refresh(target);
+                    setModalResult(false);
+                }
+            }
+        });
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java
b/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java
index f58ca00..fbe81d6 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/pages/Realms.java
@@ -28,7 +28,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
-import org.apache.syncope.client.console.panels.EditRealmModalPanel;
+import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.panels.Realm;
 import org.apache.syncope.client.console.panels.RealmModalPanel;
 import org.apache.syncope.client.console.rest.RealmRestClient;
@@ -60,25 +60,57 @@ public class Realms extends BasePage {
     @SpringBean
     private RealmRestClient realmRestClient;
 
+    private final WebMarkupContainer menu;
+
     private final WebMarkupContainer content;
 
     protected RealmTO currentRealm;
 
+    final BaseModal<RealmTO> modal;
+
     public Realms(final PageParameters parameters) {
         super(parameters);
 
         final List<RealmTO> realms = realmRestClient.list();
         Collections.sort(realms, new RealmNameComparator());
 
-        addRealmTree(getParentMap(realms), 0L, Realms.this);
+        menu = new WebMarkupContainer("menu");
+        menu.setOutputMarkupId(true);
+        add(menu);
+
+        addRealmTree(getParentMap(realms), 0L, menu);
         setCurrentRealm(realms.get(0));
 
         content = new WebMarkupContainer("content");
         content.add(new Label("header", "Root realm"));
         content.add(new Label("body", "Root realm"));
         content.setOutputMarkupId(true);
-        updateRealmContent(currentRealm);
         add(content);
+
+        modal = new BaseModal<>("modal");
+        content.add(modal);
+
+        modal.setWindowClosedCallback(new WindowClosedCallback() {
+
+            private static final long serialVersionUID = 8804221891699487139L;
+
+            @Override
+            public void onClose(final AjaxRequestTarget target) {
+                final List<RealmTO> realms = realmRestClient.list();
+                Collections.sort(realms, new RealmNameComparator());
+                target.add(addRealmTree(getParentMap(realms), 0L, menu));
+
+                modal.show(false);
+
+                if (isModalResult()) {
+                    info(getString(Constants.OPERATION_SUCCEEDED));
+                    feedbackPanel.refresh(target);
+                    setModalResult(false);
+                }
+            }
+        });
+
+        updateRealmContent(currentRealm);
     }
 
     private MarkupContainer addRealmTree(
@@ -180,92 +212,114 @@ public class Realms extends BasePage {
     private void updateRealmContent(final RealmTO realmTO) {
         content.addOrReplace(new Label("header", realmTO.getName()));
         content.addOrReplace(new Realm("body", realmTO, getPageReference()));
-        setupCreateModal();
-        setupEditModal();
+        setupDeleteLink();
+        setupCreateLink();
+        setupEditLink();
     }
 
-    private void setupCreateModal() {
-        final BaseModal<RealmTO> createModal = new BaseModal<>("createModal");
-        createModal.header(new ResourceModel("createRealm"));
+    private void setupDeleteLink() {
 
-        createModal.setWindowClosedCallback(new WindowClosedCallback() {
+        final AjaxLink<Void> deleteLink = new ClearIndicatingAjaxLink<Void>("deleteLink",
getPageReference()) {
 
-            private static final long serialVersionUID = 8804221891699487139L;
+            private static final long serialVersionUID = -7978723352517770644L;
 
             @Override
-            public void onClose(final AjaxRequestTarget target) {
-                final List<RealmTO> realms = realmRestClient.list();
-                Collections.sort(realms, new RealmNameComparator());
-                target.add(addRealmTree(getParentMap(realms), 0L, Realms.this));
+            protected void onClickInternal(final AjaxRequestTarget target) {
+                try {
+                    final RealmTO toBeDeleted = Realms.this.getCurrentRealm();
+
+                    if (toBeDeleted.getKey() == 0) {
+                        throw new Exception("Root realm cannot be deleted");
+                    }
+
+                    realmRestClient.delete(toBeDeleted.getFullPath());
+
+                    final List<RealmTO> realms = realmRestClient.list();
+                    Collections.sort(realms, new RealmNameComparator());
+                    target.add(addRealmTree(getParentMap(realms), 0L, menu));
+
+//                    info(getString(Constants.OPERATION_SUCCEEDED));
+//                    feedbackPanel.refresh(target);
+                } catch (Exception e) {
+                    LOG.error("While deleting realm", e);
+                    error(getString(Constants.ERROR) + ": " + e.getMessage());
+                    getFeedbackPanel().refresh(target);
+                }
             }
-        });
+        };
 
-        content.addOrReplace(createModal);
+        if (SyncopeConsoleSession.get().owns(Entitlement.REALM_DELETE)) {
+            MetaDataRoleAuthorizationStrategy.authorize(deleteLink, ENABLE, Entitlement.REALM_DELETE);
+        }
 
-        final RealmModalPanel realmModalPanel = new RealmModalPanel(BaseModal.getModalContentId(),
-                this.getPageReference(), createModal,
-                new RealmTO(), this.getCurrentRealm().getFullPath(), Entitlement.REALM_CREATE);
+        content.addOrReplace(deleteLink);
+    }
 
-        realmModalPanel.setOutputMarkupId(true);
-        createModal.addOrReplace(realmModalPanel);
+    private void setupCreateLink() {
 
-        //create new realms                
         final AjaxLink<Void> createLink = new ClearIndicatingAjaxLink<Void>("createLink",
getPageReference()) {
 
             private static final long serialVersionUID = -7978723352517770644L;
 
             @Override
             protected void onClickInternal(final AjaxRequestTarget target) {
-                createModal.addOrReplace(realmModalPanel);
-                createModal.show(target);
-            }
+                modal.header(new ResourceModel("createRealm"));
+
+                final RealmTO realmTO = new RealmTO();
+                modal.setFormModel(realmTO);
 
+                final RealmModalPanel panel = new RealmModalPanel(
+                        modal,
+                        Realms.this.getPageReference(),
+                        realmTO,
+                        Realms.this.getCurrentRealm().getFullPath(),
+                        Entitlement.REALM_CREATE,
+                        true);
+                target.add(modal.setContent(panel));
+
+                modal.addSumbitButton();
+                modal.show(true);
+            }
         };
+
         if (SyncopeConsoleSession.get().owns(Entitlement.REALM_CREATE)) {
             MetaDataRoleAuthorizationStrategy.authorize(createLink, ENABLE, Entitlement.REALM_CREATE);
         }
+
         content.addOrReplace(createLink);
     }
 
-    private void setupEditModal() {
-
-        final BaseModal<RealmTO> editModal = new BaseModal<>("editModal");
-        editModal.header(Model.of(getCurrentRealm().getName()));
-
-        editModal.setWindowClosedCallback(new WindowClosedCallback() {
+    private void setupEditLink() {
+        final AjaxLink<Void> editLink = new ClearIndicatingAjaxLink<Void>("editLink",
getPageReference()) {
 
-            private static final long serialVersionUID = 8804221891699487139L;
+            private static final long serialVersionUID = -6957616042924610290L;
 
             @Override
-            public void onClose(final AjaxRequestTarget target) {
-                final List<RealmTO> realms = realmRestClient.list();
-                Collections.sort(realms, new RealmNameComparator());
-                target.add(addRealmTree(getParentMap(realms), 0L, Realms.this));
-            }
-        });
+            protected void onClickInternal(final AjaxRequestTarget target) {
+                modal.header(Model.of(Realms.this.getCurrentRealm().getName()));
 
-        content.addOrReplace(editModal);
+                final RealmTO realmTO = Realms.this.getCurrentRealm();
+                modal.setFormModel(realmTO);
 
-        final RealmModalPanel ediRealmModalPanel =
-                new EditRealmModalPanel(
-                        BaseModal.getModalContentId(),
+                final RealmModalPanel panel = new RealmModalPanel(
+                        modal,
                         Realms.this.getPageReference(),
-                        editModal, getCurrentRealm(), Realms.this.getCurrentRealm().getFullPath(),
-                        Entitlement.REALM_UPDATE);
-
-        ediRealmModalPanel.setOutputMarkupId(true);
-        editModal.addOrReplace(ediRealmModalPanel);
-
-        final AjaxLink<Void> edit = new ClearIndicatingAjaxLink<Void>("edit",
getPageReference()) {
-
-            private static final long serialVersionUID = -6957616042924610290L;
-
-            @Override
-            protected void onClickInternal(final AjaxRequestTarget target) {
-                editModal.show(target);
+                        realmTO,
+                        realmTO.getFullPath(),
+                        Entitlement.REALM_UPDATE,
+                        false);
+                target.add(modal.setContent(panel));
+
+                modal.addSumbitButton();
+                modal.show(true);
             }
         };
-        content.addOrReplace(edit);
+
+        if (SyncopeConsoleSession.get().owns(Entitlement.REALM_UPDATE)) {
+            MetaDataRoleAuthorizationStrategy.authorize(editLink, ENABLE, Entitlement.REALM_UPDATE);
+        }
+
+        content.addOrReplace(editLink);
     }
 
     private static class ControlSidebarClick<T> {

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/panels/AbstractModalPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/AbstractModalPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/panels/AbstractModalPanel.java
index c704d41..1ddffb7 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/AbstractModalPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/AbstractModalPanel.java
@@ -18,7 +18,6 @@
  */
 package org.apache.syncope.client.console.panels;
 
-import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.init.MIMETypesLoader;
 import org.apache.syncope.client.console.rest.ConfigurationRestClient;
 import org.apache.syncope.client.console.rest.ConnectorRestClient;
@@ -30,9 +29,12 @@ import org.apache.syncope.client.console.rest.TaskRestClient;
 import org.apache.syncope.client.console.rest.UserRestClient;
 import org.apache.syncope.client.console.rest.UserSelfRestClient;
 import org.apache.syncope.client.console.wicket.markup.head.MetaHeaderItem;
+import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
+import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.markup.head.HeaderItem;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.markup.head.PriorityHeaderItem;
+import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.panel.Panel;
 import org.apache.wicket.spring.injection.annot.SpringBean;
 import org.slf4j.Logger;
@@ -44,14 +46,14 @@ public class AbstractModalPanel extends Panel {
 
     protected static final Logger LOG = LoggerFactory.getLogger(AbstractModalPanel.class);
 
+    protected final BaseModal<?> modal;
+
     protected static final String CANCEL = "cancel";
 
     protected static final String SUBMIT = "submit";
 
     protected static final String APPLY = "apply";
 
-    protected static final String FORM = "form";
-
     protected final HeaderItem meta = new MetaHeaderItem("X-UA-Compatible", "IE=edge");
 
     @SpringBean
@@ -84,37 +86,26 @@ public class AbstractModalPanel extends Panel {
     @SpringBean
     protected MIMETypesLoader mimeTypesInitializer;
 
-    protected NotificationPanel feedbackPanel;
-
-    /**
-     * Response flag set by the Modal Window after the operation is completed.
-     */
-    protected boolean modalResult = false;
-
-    public AbstractModalPanel(final String id) {
+    public AbstractModalPanel(final String id, final BaseModal<?> modal) {
         super(id);
-
-        feedbackPanel = new NotificationPanel(Constants.FEEDBACK);
-        feedbackPanel.setOutputMarkupId(true);
-        add(feedbackPanel);
+        this.modal = modal;
     }
 
-    public NotificationPanel getFeedbackPanel() {
-        return feedbackPanel;
+    @Override
+    public void renderHead(final IHeaderResponse response) {
+        super.renderHead(response);
+        response.render(new PriorityHeaderItem(meta));
     }
 
-    public boolean isModalResult() {
-        return modalResult;
+    protected void closeAction(final AjaxRequestTarget target, final Form<?> form)
{
+        this.modal.close(target);
     }
 
-    public void setModalResult(final boolean modalResult) {
-        this.modalResult = modalResult;
+    public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
+        modal.getFeedbackPanel().refresh(target);
     }
 
-    @Override
-    public void renderHead(final IHeaderResponse response) {
-        super.renderHead(response);
-        response.render(new PriorityHeaderItem(meta));
+    public void onError(final AjaxRequestTarget target, final Form<?> form) {
+        modal.getFeedbackPanel().refresh(target);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/panels/EditRealmModalPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/EditRealmModalPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/panels/EditRealmModalPanel.java
deleted file mode 100644
index c4ddfa1..0000000
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/EditRealmModalPanel.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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 org.apache.syncope.client.console.panels;
-
-import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
-import org.apache.syncope.common.lib.to.RealmTO;
-import org.apache.wicket.PageReference;
-
-public class EditRealmModalPanel extends RealmModalPanel {
-
-    private static final long serialVersionUID = -4285220460543213901L;
-
-    public EditRealmModalPanel(
-            final String id,
-            final PageReference pageRef,
-            final BaseModal<RealmTO> window,
-            final RealmTO realmTO,
-            final String parentPath,
-            final String entitlement) {
-
-        super(id, pageRef, window, realmTO, parentPath, entitlement);
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupModalPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupModalPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupModalPanel.java
index b8150aa..9c2f91b 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupModalPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupModalPanel.java
@@ -18,10 +18,10 @@
  */
 package org.apache.syncope.client.console.panels;
 
-import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.syncope.client.console.commons.Constants;
 import org.apache.syncope.client.console.commons.Mode;
+import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
 import org.apache.syncope.common.lib.AnyOperations;
 import org.apache.syncope.common.lib.mod.GroupMod;
 import org.apache.syncope.common.lib.to.GroupTO;
@@ -48,14 +48,14 @@ public class GroupModalPanel extends AbstractModalPanel {
 
     protected GroupTO originalGroupTO;
 
-    public GroupModalPanel(final String id, final Modal<?> window, final GroupTO groupTO)
{
-        this(id, window, groupTO, Mode.ADMIN);
+    public GroupModalPanel(final String id, final BaseModal<?> modal, final GroupTO
groupTO) {
+        this(id, modal, groupTO, Mode.ADMIN);
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    public GroupModalPanel(final String id, final Modal<?> window, final GroupTO groupTO,
final Mode mode) {
+    public GroupModalPanel(final String id, final BaseModal<?> modal, final GroupTO
groupTO, final Mode mode) {
 
-        super(id);
+        super(id, modal);
 
         this.mode = mode;
 
@@ -86,13 +86,13 @@ public class GroupModalPanel extends AbstractModalPanel {
                 } catch (Exception e) {
                     LOG.error("Failure managing groupTO {}", groupTO, e);
                     error(getString(Constants.ERROR) + ": " + e.getMessage());
-                    feedbackPanel.refresh(target);
+                    modal.getFeedbackPanel().refresh(target);
                 }
             }
 
             @Override
             protected void onError(final AjaxRequestTarget target, final Form<?> form)
{
-                feedbackPanel.refresh(target);
+                modal.getFeedbackPanel().refresh(target);
             }
         };
         form.add(submit);

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupSearchResultPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupSearchResultPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupSearchResultPanel.java
index 322e555..6a048b3 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupSearchResultPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/GroupSearchResultPanel.java
@@ -127,7 +127,7 @@ public class GroupSearchResultPanel extends AnySearchResultPanel {
                     @Override
                     public void onClick(final AjaxRequestTarget target, final AnyTO anyTO)
{
                         editModal.addOrReplace(new GroupModalPanel(
-                                BaseModal.getModalContentId(), editModal, (GroupTO) model.getObject()));
+                                BaseModal.getContentId(), editModal, (GroupTO) model.getObject()));
 
                         target.add(editModal);
                         editModal.show(target);

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmModalPanel.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmModalPanel.java
b/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmModalPanel.java
index 29506f4..ed0c491 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmModalPanel.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/panels/RealmModalPanel.java
@@ -20,19 +20,17 @@ package org.apache.syncope.client.console.panels;
 
 import static org.apache.wicket.Component.ENABLE;
 
-import com.googlecode.wicket.jquery.ui.markup.html.link.AjaxSubmitLink;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
+import org.apache.syncope.client.console.pages.AbstractBasePage;
 import org.apache.syncope.client.console.pages.BasePage;
 import org.apache.syncope.client.console.rest.RealmRestClient;
-import org.apache.syncope.client.console.wicket.markup.html.bootstrap.buttons.PrimaryModalButton;
 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
 import org.apache.syncope.common.lib.to.RealmTO;
 import org.apache.wicket.PageReference;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
 import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.spring.injection.annot.SpringBean;
 
 public class RealmModalPanel extends AbstractModalPanel {
@@ -43,7 +41,7 @@ public class RealmModalPanel extends AbstractModalPanel {
 
     private final PageReference pageRef;
 
-    private final BaseModal<RealmTO> modal;
+    private boolean newRealm = false;
 
     @SpringBean
     private RealmRestClient realmRestClient;
@@ -51,69 +49,58 @@ public class RealmModalPanel extends AbstractModalPanel {
     private final String parentPath;
 
     public RealmModalPanel(
-            final String id,
+            final BaseModal<?> modal,
             final PageReference pageRef,
-            final BaseModal<RealmTO> modal,
             final RealmTO realmTO,
             final String parentPath,
             final String entitlement) {
+        this(modal, pageRef, realmTO, parentPath, entitlement, false);
+    }
 
-        super(id);
+    public RealmModalPanel(
+            final BaseModal<?> modal,
+            final PageReference pageRef,
+            final RealmTO realmTO,
+            final String parentPath,
+            final String entitlement,
+            final boolean newRealm) {
+
+        super(BaseModal.getContentId(), modal);
+        this.newRealm = newRealm;
 
         this.pageRef = pageRef;
-        this.modal = modal;
         this.realmTO = realmTO;
         this.parentPath = parentPath;
 
-        final Form<RealmTO> form = new Form<>("realmForm");
-        form.setModel(new CompoundPropertyModel<>(realmTO));
-
         final RealmDetails realmDetail = new RealmDetails("details", realmTO);
         if (SyncopeConsoleSession.get().owns(entitlement)) {
             MetaDataRoleAuthorizationStrategy.authorize(realmDetail, ENABLE, entitlement);
         }
-        form.add(realmDetail);
 
-        final AjaxSubmitLink submit = getOnSubmit(form);
-        modal.addFooterInput(submit);
-        add(form);
+        add(realmDetail);
     }
 
-    protected final PrimaryModalButton getOnSubmit(final Form form) {
-        return new PrimaryModalButton(BaseModal.getModalInputId(), "submit", form) {
-
-            private static final long serialVersionUID = -958724007591692537L;
-
-            @Override
-            protected void onSubmit(final AjaxRequestTarget target, final Form<?> form)
{
-                try {
-                    submitAction(target, form);
-
-                    if (pageRef.getPage() instanceof BasePage) {
-                        ((BasePage) pageRef.getPage()).setModalResult(true);
-                    }
-
-                    closeAction(target, form);
-                } catch (Exception e) {
-                    LOG.error("While creating or updating realm", e);
-                    error(getString(Constants.ERROR) + ": " + e.getMessage());
-                    feedbackPanel.refresh(target);
-                }
+    @Override
+    public void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
+        try {
+            final RealmTO updatedRealmTO = RealmTO.class.cast(form.getModelObject());
+            if (newRealm) {
+                realmRestClient.create(this.parentPath, updatedRealmTO);
+            } else {
+                realmRestClient.update(updatedRealmTO);
             }
 
-            @Override
-            protected void onError(final AjaxRequestTarget target, final Form<?> form)
{
-                feedbackPanel.refresh(target);
+            if (pageRef.getPage() instanceof BasePage) {
+                ((BasePage) pageRef.getPage()).setModalResult(true);
             }
-        };
-    }
 
-    protected void submitAction(final AjaxRequestTarget target, final Form<?> form)
{
-        final RealmTO updatedRealmTO = (RealmTO) form.getModelObject();
-        realmRestClient.create(this.parentPath, updatedRealmTO);
-    }
+            AbstractBasePage.class.cast(pageRef.getPage()).setModalResult(true);
 
-    protected void closeAction(final AjaxRequestTarget target, final Form<?> form)
{
-        this.modal.close(target);
+            closeAction(target, form);
+        } catch (Exception e) {
+            LOG.error("While creating or updating realm", e);
+            error(getString(Constants.ERROR) + ": " + e.getMessage());
+            modal.getFeedbackPanel().refresh(target);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/rest/RealmRestClient.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/rest/RealmRestClient.java
b/client/console/src/main/java/org/apache/syncope/client/console/rest/RealmRestClient.java
index cb2bccc..2d99ee7 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/rest/RealmRestClient.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/rest/RealmRestClient.java
@@ -38,4 +38,12 @@ public class RealmRestClient extends BaseRestClient {
     public void create(final String parentPath, final RealmTO realmTO) {
         getService(RealmService.class).create(parentPath, realmTO);
     }
+
+    public void update(final RealmTO realmTO) {
+        getService(RealmService.class).update(realmTO);
+    }
+
+    public void delete(final String fullPath) {
+        getService(RealmService.class).delete(fullPath);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/buttons/PrimaryModalButton.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/buttons/PrimaryModalButton.java
b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/buttons/PrimaryModalButton.java
index 890b9a7..336f85e 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/buttons/PrimaryModalButton.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/buttons/PrimaryModalButton.java
@@ -30,6 +30,6 @@ public class PrimaryModalButton extends AjaxSubmitLink {
     public PrimaryModalButton(final String id, final String name, final Form<?> form)
{
         super(id, form);
         add(new ButtonBehavior(Buttons.Type.Primary, Buttons.Size.Medium));
-        
+
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.java
----------------------------------------------------------------------
diff --git a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.java
b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.java
index 1403f14..42fbece 100644
--- a/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.java
+++ b/client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.java
@@ -22,71 +22,123 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.behavior.Draggable;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.behavior.DraggableConfig;
 import de.agilecoders.wicket.extensions.markup.html.bootstrap.behavior.Resizable;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.syncope.client.console.commons.Constants;
+import org.apache.syncope.client.console.panels.AbstractModalPanel;
 import org.apache.syncope.client.console.panels.NotificationPanel;
 import org.apache.syncope.client.console.wicket.markup.html.bootstrap.buttons.DefaultModalCloseButton;
+import org.apache.syncope.client.console.wicket.markup.html.bootstrap.buttons.PrimaryModalButton;
 import org.apache.wicket.Component;
-import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
 import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.WindowClosedCallback;
 import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.list.ListItem;
 import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.markup.html.panel.EmptyPanel;
+import org.apache.wicket.model.CompoundPropertyModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class BaseModal<T> extends Modal<T> {
+public class BaseModal<T extends Serializable> extends Modal<T> {
 
     private static final long serialVersionUID = -6142277554912316095L;
 
     protected static final Logger LOG = LoggerFactory.getLogger(BaseModal.class);
 
-    private static final String CONTENT = "modalContent";
+    /** the default id of the content component */
+    public static final String CONTENT_ID = "content";
 
-    private static final String INPUT = "input";
+    private static final String SUBMIT = "submit";
+
+    protected static final String FORM = "form";
 
     protected NotificationPanel feedbackPanel;
 
     private final List<Component> components;
 
-    private final WebMarkupContainer container;
-
     private WindowClosedCallback windowClosedCallback;
 
+    private AbstractModalPanel content;
+
+    private PrimaryModalButton submitButton;
+
+    final Form<T> form;
+
     public BaseModal(final String id) {
         super(id);
-        container = new WebMarkupContainer("container");
-        container.add(new EmptyPanel(CONTENT));
-        container.setOutputMarkupId(true);
-        add(container);
+
+        feedbackPanel = new NotificationPanel(Constants.FEEDBACK);
+        feedbackPanel.setOutputMarkupId(true);
+        add(feedbackPanel);
+
+        form = new Form<T>(FORM);
+        add(form);
+
+        content = new AbstractModalPanel(CONTENT_ID, this) {
+
+            private static final long serialVersionUID = 1L;
+
+        };
+
+        content.setOutputMarkupId(true);
+
+        form.add(content);
+
         setUseCloseHandler(true);
         this.windowClosedCallback = null;
         components = new ArrayList<>();
 
         // Note: it would imply the adding of WebjarsJavaScriptResourceReference about JQuery
resizable and mouse
         add(new Resizable().withChildSelector(".modal-content"));
+        
         // Note: it would imply the adding of WebjarsJavaScriptResourceReference about JQuery
draggable
         add(new Draggable(new DraggableConfig().withHandle(".modal-header").withCursor("move")));
+        
         addButton(new DefaultModalCloseButton());
         setUseKeyboard(true);
         setFadeIn(true);
 
     }
 
-    @Override
-    public MarkupContainer addOrReplace(final Component... component) {
-        return container.addOrReplace(component);
+    public NotificationPanel getFeedbackPanel() {
+        return feedbackPanel;
+    }
+
+    public Form<T> getForm() {
+        return form;
+    }
+
+    public BaseModal<T> setFormModel(final T modelObject) {
+        form.setModel(new CompoundPropertyModel<>(modelObject));
+        return this;
     }
 
-    public static String getModalContentId() {
-        return CONTENT;
+    public T getFormModel() {
+        return form.getModelObject();
     }
 
-    public static String getModalInputId() {
-        return INPUT;
+    public AbstractModalPanel getContent() {
+        return content;
+    }
+
+    public BaseModal<T> setContent(final AbstractModalPanel component) {
+        if (!component.getId().equals(getContentId())) {
+            throw new WicketRuntimeException(
+                    "Modal content id is wrong. Component ID:" + component.getId() + "; content
ID: " + getContentId());
+        }
+
+        content.replaceWith(component);
+        content = component;
+
+        return this;
+    }
+
+    public static String getContentId() {
+        return CONTENT_ID;
     }
 
     public BaseModal<T> setWindowClosedCallback(final WindowClosedCallback callback)
{
@@ -101,8 +153,32 @@ public class BaseModal<T> extends Modal<T> {
         }
     }
 
-    public void addFooterInput(final Component component) {
-        this.components.add(component);
+    public void addSumbitButton() {
+
+        final PrimaryModalButton submit = new PrimaryModalButton(SUBMIT, SUBMIT, form) {
+
+            private static final long serialVersionUID = -958724007591692537L;
+
+            @Override
+            protected void onSubmit(final AjaxRequestTarget target, final Form<?> form)
{
+                BaseModal.this.getContent().onSubmit(target, form);
+            }
+
+            @Override
+            protected void onError(final AjaxRequestTarget target, final Form<?> form)
{
+                BaseModal.this.getContent().onError(target, form);
+            }
+        };
+
+        submit.setOutputMarkupId(true);
+
+        if (submitButton == null) {
+            submitButton = submit;
+            this.components.add(submitButton);
+        } else {
+            submitButton.replaceWith(submit);
+            submitButton = submit;
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html
----------------------------------------------------------------------
diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html
b/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html
index 72d19c6..bf54dac 100644
--- a/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html
+++ b/client/console/src/main/resources/org/apache/syncope/client/console/pages/Realms.html
@@ -29,14 +29,18 @@ under the License.
             <div class="box-tools pull-right">
               <ul class="nav navbar-nav actions">
                 <li>
+                  <a href="#" wicket:id="editLink">
+                    <i class="fa fa-pencil-square-o"></i>
+                  </a>                  
+                </li>
+                <li>
                   <a href="#" wicket:id="createLink">
                     <i class="fa fa-plus"></i>
                   </a>                  
                 </li>
-                <li><a href="#"><i class="fa fa-minus"></i></a></li>
                 <li>
-                  <a href="#" wicket:id="edit">
-                    <i class="fa fa-pencil-square-o"></i>
+                  <a href="#" wicket:id="deleteLink">
+                    <i class="fa fa-minus"></i>
                   </a>                  
                 </li>
               </ul>
@@ -48,13 +52,12 @@ under the License.
             </div>
           </div>
         </div>
-        <div wicket:id="createModal"></div>
-        <div wicket:id="editModal"></div>
+        <div wicket:id="modal"></div>
       </div>
 
       <aside class="control-sidebar control-sidebar-dark control-sidebar-open block-sidebar">
         <section class="sidebar">
-          <ul class="sidebar-menu">
+          <ul class="sidebar-menu" wicket:id="menu">
             <wicket:container wicket:id="list"></wicket:container>
           </ul>
         </section>

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/resources/org/apache/syncope/client/console/panels/AbstractModalPanel.html
----------------------------------------------------------------------
diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/panels/AbstractModalPanel.html
b/client/console/src/main/resources/org/apache/syncope/client/console/panels/AbstractModalPanel.html
index 631c38b..abda19e 100644
--- a/client/console/src/main/resources/org/apache/syncope/client/console/panels/AbstractModalPanel.html
+++ b/client/console/src/main/resources/org/apache/syncope/client/console/panels/AbstractModalPanel.html
@@ -16,30 +16,8 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 -->
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
-
-<!--  <wicket:head>
-      <script type="text/javascript">
-        var notificationShownTimes = 0;
-  
-        function showNotification(componentId, messagecount) {
-          notificationShownTimes++;
-          timeout = 1700 + (messagecount * 500) + notificationShownTimes * 200;
-          $('div#' + componentId).fadeTo('normal', 1.0);
-          setTimeout("$('div#" + componentId + "').fadeOut('normal')", timeout);
-        }
-      </script>
-  
-      <style type="text/css">
-        table.palette td.header {
-          background:url("images/ui-bg_glass_75_e6e6e6_1x400.png")
-            repeat-x scroll 50% 50% #E6E6E6 !important;
-        }
-      </style>
-  </wicket:head>-->
-
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://xmlns.jcp.org/jsf/composite">
   <wicket:panel>
-    <div wicket:id="feedback"/>
     <wicket:child />
   </wicket:panel>
 </html>

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/resources/org/apache/syncope/client/console/panels/RealmModalPanel.html
----------------------------------------------------------------------
diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/panels/RealmModalPanel.html
b/client/console/src/main/resources/org/apache/syncope/client/console/panels/RealmModalPanel.html
index 2f01a50..d07b59f 100644
--- a/client/console/src/main/resources/org/apache/syncope/client/console/panels/RealmModalPanel.html
+++ b/client/console/src/main/resources/org/apache/syncope/client/console/panels/RealmModalPanel.html
@@ -18,10 +18,6 @@ under the License.
 -->
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
   <wicket:extend>
-    <div wicket:id="feedback"/>
-    <form data-example-id="simple-input-groups" class="bs-example bs-example-form" wicket:id="realmForm">
-      <div wicket:id="details">[details]</div>
-      <wicket:child />
-    </form>
+    <div wicket:id="details">[details]</div>
   </wicket:extend>
 </html>

http://git-wip-us.apache.org/repos/asf/syncope/blob/7526a2d5/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.html
----------------------------------------------------------------------
diff --git a/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.html
b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.html
index fe62bae..920581e 100644
--- a/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.html
+++ b/client/console/src/main/resources/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.html
@@ -18,6 +18,25 @@ specific language governing permissions and limitations
 under the License.
 -->
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+  <wicket:head>
+    <script type="text/javascript">
+      var notificationShownTimes = 0;
+
+      function showNotification(componentId, messagecount) {
+        notificationShownTimes++;
+        timeout = 1700 + (messagecount * 500) + notificationShownTimes * 200;
+        $('div#' + componentId).fadeTo('normal', 1.0);
+        setTimeout("$('div#" + componentId + "').fadeOut('normal')", timeout);
+      }
+    </script>
+
+    <style type="text/css">
+      table.palette td.header {
+        background:url("images/ui-bg_glass_75_e6e6e6_1x400.png")
+          repeat-x scroll 50% 50% #E6E6E6 !important;
+      }
+    </style>
+  </wicket:head>
   <wicket:panel>
     <div class="modal-dialog" wicket:id="dialog">
       <div class="modal-content">
@@ -26,16 +45,17 @@ under the License.
           <h4 wicket:id="header-label" class="modal-title">Modal header</h4>
         </div>
         <div class="modal-body">
-          <div wicket:id="container">
-            <span wicket:id="modalContent">[modalContent]</span>
-          </div>
+          <div wicket:id="feedback"/>
+          <form data-example-id="simple-input-groups" class="bs-example bs-example-form"
wicket:id="form">
+            <span wicket:id="content">[modal content]</span>
+          </form>
         </div>
         <div class="modal-footer" wicket:id="footer">
           <wicket:fragment wicket:id="buttons">
             <button type="button" wicket:id="button"></button>
           </wicket:fragment>
           <wicket:fragment wicket:id="inputs">
-            <button wicket:id="input"><wicket:message key="submit"/></button>
+            <button wicket:id="submit"><wicket:message key="submit"/></button>
           </wicket:fragment>
         </div>
       </div>


Mime
View raw message