Example #1
0
  @Path("@configWidget-sidebar")
  public Object configWidgetSidebar() {
    FormData form = ctx.getForm();
    try {
      int rowIdx = new Integer(form.getString("rowIdx")).intValue();
      HtmlPage sidebar = site.getSidebar();

      HtmlContent content = sidebar.section(0).row(rowIdx).content(0);
      Resource newObject = newObject("HtmlContent", sidebar.getDocument(), content);
      return newObject;
      /*List<LabsWidget> widgets = content.getGadgets(getCoreSession());
      if (!widgets.isEmpty()) {
          LabsWidget widget = widgets.get(0);
          if (WidgetType.OPENSOCIAL.equals(widget.getType())) {
              DocumentRef ref = ((LabsOpensocialGadget)widget).getDoc().getRef();
              if (getCoreSession().exists(ref)) {
                  DocumentModel gadgetDoc = getCoreSession().getDocument(ref);
                  return newObject("HtmlWidget", gadgetDoc, doc, content, widget);
              }
              return Response.noContent().build();
          }
          return newObject("HtmlWidget", null, doc, content, widget);
      }
      return Response.noContent().build();*/

    } catch (Exception e) {
      throw WebException.wrap(
          "Problème lors de la sauvegarde de la configuration du widget de la sidebar", e);
    }
  }
 /**
  * update updateEmptySidebar
  *
  * @param session
  */
 public static void updateEmptySidebar(CoreSession session) {
   try {
     DocumentModelList children = session.query("SELECT * FROM " + Docs.SITE.type());
     for (DocumentModel docLabsSite : children) {
       LabsSite labsSite = Tools.getAdapter(LabsSite.class, docLabsSite, session);
       HtmlPage sidebar = labsSite.getSidebar();
       if (sidebar.getSections().size() < 2) {
         session.removeDocument(sidebar.getDocument().getRef());
         session.save();
         LabsSiteUtils.createDefaultSidebarPage(labsSite.getDocument(), session);
         session.save();
       }
     }
   } catch (ClientException e) {
     LOG.error("updateEmptySidebar : ", e);
   }
 }
Example #3
0
  @POST
  @Path("@manage-sidebar")
  public Object manageSidebar() {
    FormData form = ctx.getForm();
    CoreSession session = getCoreSession();
    try {
      int nbRows = new Integer(form.getString("nbRows")).intValue();
      HtmlPage sidebar = site.getSidebar();
      HtmlSection section = sidebar.section(0);
      section.remove();
      sidebar.addSection();
      section = sidebar.section(0);
      HtmlRow row = null;
      String widget = "";
      for (int i = 0; i < nbRows; i++) {
        widget = form.getString("bloc" + i);
        if (!"html/editor".equals(widget)) {
          row = section.addRow();
          row.addContent(0, "");
          session.saveDocument(sidebar.getDocument());
          session.save();
          GadgetUtils.syncWidgetsConfig(row.content(0), widget, sidebar.getDocument(), session);
        }
      }
    } catch (Exception e) {
      throw WebException.wrap("Problème lors de la sauvegarde des widgets de la sidebar", e);
    }
    // TODO row's widget config

    return Response.ok().build();
  }