r8 - in trunk: . faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence faxtomail-persistence/src/main/xmi faxtomail-service/src/main/java/com/franciaflex/faxtomail/services faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin faxtomail-ui-web/src/main/webapp/css f
Author: kmorin Date: 2014-02-11 11:12:54 +0100 (Tue, 11 Feb 2014) New Revision: 8 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/8 Log: web admin part Added: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/persistence/entity/ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFilterService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserService.java trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js Modified: trunk/faxtomail-persistence/src/main/xmi/faxtomail.zargo trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceSupport.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/CompanyService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration.jsp trunk/faxtomail-ui-web/src/main/webapp/css/configuration.css trunk/pom.xml Modified: trunk/faxtomail-persistence/src/main/xmi/faxtomail.zargo =================================================================== (Binary files differ) Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceSupport.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceSupport.java 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceSupport.java 2014-02-11 10:12:54 UTC (rev 8) @@ -29,6 +29,7 @@ import com.franciaflex.faxtomail.services.service.CompanyService; import com.franciaflex.faxtomail.services.service.ConfigurationService; import com.franciaflex.faxtomail.services.service.FaxToMailWebApplicationContext; +import com.franciaflex.faxtomail.services.service.MailFilterService; import com.franciaflex.faxtomail.services.service.MailFolderService; import java.util.Date; @@ -73,4 +74,7 @@ public MailFolderService getMailFolderService() { return newService(MailFolderService.class); } + public MailFilterService getMailFilterService() { + return newService(MailFilterService.class); + } } Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/CompanyService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/CompanyService.java 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/CompanyService.java 2014-02-11 10:12:54 UTC (rev 8) @@ -3,13 +3,22 @@ import com.franciaflex.faxtomail.persistence.entities.Company; import com.franciaflex.faxtomail.persistence.entities.CompanyTopiaDao; import com.franciaflex.faxtomail.persistence.entities.Configuration; +import com.franciaflex.faxtomail.persistence.entities.MailFilter; +import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; +import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.collect.Collections2; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaEntities; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Map; /** * @author kmorin <kmorin@codelutin.com> @@ -21,7 +30,7 @@ public List<Company> getAllCompanies() { CompanyTopiaDao dao = getPersistenceContext().getCompanyDao(); - List<Company> companies = Lists.newArrayList(dao.findAll()); + List<Company> companies = new ArrayList<>(dao.findAll()); return companies; } @@ -31,14 +40,27 @@ return company; } - public Company saveCompany(Company company) { + public Company saveCompany(Company company, Collection<MailFolder> mailFolders, Map<MailFilter, String> mailFilters) { Preconditions.checkNotNull(company); + ConfigurationService configurationService = getConfigurationService(); configurationService.saveConfiguration(company.getConfiguration()); MailFolderService mailFolderService = getMailFolderService(); - mailFolderService.saveMailFolders(company.getMailFolder()); + mailFolders = mailFolderService.saveMailFolders(mailFolders); + company.setMailFolder(mailFolders); + if (mailFilters != null) { + Map<String, MailFolder> foldersById = Maps.uniqueIndex(mailFolders, TopiaEntities.getTopiaIdFunction()); + for (MailFilter filter : mailFilters.keySet()) { + MailFolder folder = foldersById.get(mailFilters.get(filter)); + filter.setMailFolder(folder); + } + } + MailFilterService mailFilterService = getMailFilterService(); + Collection<MailFilter> filters = mailFilterService.saveMailFilters(mailFilters.keySet()); + company.setMailFilter(filters); + CompanyTopiaDao dao = getPersistenceContext().getCompanyDao(); company = dao.update(company); Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java 2014-02-11 10:12:54 UTC (rev 8) @@ -28,6 +28,10 @@ import com.franciaflex.faxtomail.persistence.entities.Company; import com.franciaflex.faxtomail.persistence.entities.CompanyTopiaDao; import com.franciaflex.faxtomail.persistence.entities.ConfigurationTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroupTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -114,6 +118,29 @@ log.debug("sample data " + companyTopiaDao.count()); } + FaxToMailUserGroupTopiaDao userGroupDao = getPersistenceContext().getFaxToMailUserGroupDao(); + count = userGroupDao.count(); + if (count == 0) { + userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "Chargés de clientèle"); + userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "Commerciaux"); + userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "SAV"); + userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "Administrateurs"); + + getPersistenceContext().commit(); + } + + FaxToMailUserTopiaDao userDao = getPersistenceContext().getFaxToMailUserDao(); + count = userDao.count(); + if (count == 0) { + userDao.create(FaxToMailUser.PROPERTY_NAME, "Marc Lefebvre", FaxToMailUser.PROPERTY_LOGIN, "mlefebvre"); + userDao.create(FaxToMailUser.PROPERTY_NAME, "Cyril Baillet", FaxToMailUser.PROPERTY_LOGIN, "cbaillet"); + userDao.create(FaxToMailUser.PROPERTY_NAME, "Frédéric Viala", FaxToMailUser.PROPERTY_LOGIN, "fviala"); + userDao.create(FaxToMailUser.PROPERTY_NAME, "Claire Marquis", FaxToMailUser.PROPERTY_LOGIN, "cmarquis"); + userDao.create(FaxToMailUser.PROPERTY_NAME, "Agathe Borde", FaxToMailUser.PROPERTY_LOGIN, "aborde"); + userDao.create(FaxToMailUser.PROPERTY_NAME, "Jeanne Bourgoin", FaxToMailUser.PROPERTY_LOGIN, "jbourgoin"); + + getPersistenceContext().commit(); + } } } Added: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFilterService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFilterService.java (rev 0) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFilterService.java 2014-02-11 10:12:54 UTC (rev 8) @@ -0,0 +1,41 @@ +package com.franciaflex.faxtomail.services.service; + +import com.franciaflex.faxtomail.persistence.entities.MailFilter; +import com.franciaflex.faxtomail.persistence.entities.MailFilterTopiaDao; +import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author kmorin <kmorin@codelutin.com> + * @since x.x + */ +public class MailFilterService extends FaxToMailServiceSupport { + + public Collection<MailFilter> saveMailFilters(Collection<MailFilter> mailFilters) { + MailFilterTopiaDao dao = getPersistenceContext().getMailFilterDao(); + + Collection<MailFilter> result = new ArrayList<>(); + for (MailFilter mailFilter : mailFilters) { + + MailFilter filter; + boolean create = mailFilter.getTopiaId() == null; + if (create) { + filter = dao.newInstance(); + } else { + filter = dao.findByTopiaId(mailFilter.getTopiaId()); + } + filter.setExpression(mailFilter.getExpression()); + filter.setMailFolder(mailFilter.getMailFolder()); + + if (create) { + filter = dao.create(filter); + } else { + filter = dao.update(filter); + } + result.add(filter); + } + return result; + } +} Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java 2014-02-11 10:12:54 UTC (rev 8) @@ -8,7 +8,9 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaIdFactory; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; /** * @author kmorin <kmorin@codelutin.com> @@ -18,6 +20,11 @@ private static final Log log = LogFactory.getLog(MailFolderService.class); + public List<MailFolder> getMailFolders(Collection<String> ids) { + MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); + return new ArrayList<MailFolder>(dao.forTopiaIdIn(ids).findAll()); + } + public Collection<MailFolder> saveMailFolders(Collection<MailFolder> mailFolders) { if (mailFolders == null) { return null; Added: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserService.java (rev 0) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/UserService.java 2014-02-11 10:12:54 UTC (rev 8) @@ -0,0 +1,27 @@ +package com.franciaflex.faxtomail.services.service; + +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroupTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserTopiaDao; +import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author kmorin <kmorin@codelutin.com> + * @since x.x + */ +public class UserService extends FaxToMailServiceSupport { + + public List<FaxToMailUser> getAllUsers() { + FaxToMailUserTopiaDao dao = getPersistenceContext().getFaxToMailUserDao(); + return new ArrayList<>(dao.findAll()); + } + + public List<FaxToMailUserGroup> getAllUserGroups() { + FaxToMailUserGroupTopiaDao dao = getPersistenceContext().getFaxToMailUserGroupDao(); + return new ArrayList<>(dao.findAll()); + } +} Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/FaxToMailApplicationContext.java 2014-02-11 10:12:54 UTC (rev 8) @@ -24,7 +24,10 @@ protected static FaxToMailConfiguration applicationConfig; public static FaxToMailConfiguration getApplicationConfig() { - return FaxToMailConfiguration.getInstance(); + if (applicationConfig == null) { + applicationConfig = new FaxToMailConfiguration("faxtomail.properties"); + } + return applicationConfig; } public static FaxToMailTopiaApplicationContext getTopiaApplicationContext() { Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ConfigurationAction.java 2014-02-11 10:12:54 UTC (rev 8) @@ -1,35 +1,44 @@ package com.franciaflex.faxtomail.web.action.admin; import com.franciaflex.faxtomail.persistence.entities.Company; -import com.franciaflex.faxtomail.persistence.entities.Configuration; -import com.franciaflex.faxtomail.persistence.entities.ConfigurationImpl; import com.franciaflex.faxtomail.persistence.entities.Email; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup; +import com.franciaflex.faxtomail.persistence.entities.MailFilter; +import com.franciaflex.faxtomail.persistence.entities.MailFilterAbstract; +import com.franciaflex.faxtomail.persistence.entities.MailFilterImpl; import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import com.franciaflex.faxtomail.persistence.entities.MailFolderAbstract; import com.franciaflex.faxtomail.persistence.entities.MailFolderImpl; import com.franciaflex.faxtomail.services.service.CompanyService; +import com.franciaflex.faxtomail.services.service.MailFolderService; +import com.franciaflex.faxtomail.services.service.UserService; import com.franciaflex.faxtomail.web.FaxToMailActionSupport; +import com.google.common.base.Function; +import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.GsonBuilder; -import com.google.gson.InstanceCreator; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; import com.opensymphony.xwork2.Preparable; +import org.apache.commons.collections4.ComparatorUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaIdFactory; -import org.nuiton.topia.persistence.internal.DefaultTopiaIdFactory; +import org.nuiton.topia.persistence.TopiaEntities; -import java.io.IOException; import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -43,12 +52,24 @@ protected CompanyService companyService; + protected MailFolderService mailFolderService; + + protected UserService userService; + protected List<Company> companies; protected Company company; protected List<MailFolder> mailFolders; + protected Map<String, String> mailFoldersFlat; + + protected List<MailFilterUIBean> mailFilters; + + protected List<FaxToMailUser> allUsers; + + protected List<FaxToMailUserGroup> allUserGroups; + protected String activeTab; @Override @@ -63,12 +84,19 @@ @Override public String execute() throws Exception { - log.debug("execute " + company); String result = super.execute(); + if (!ERROR.equals(result)) { if (company != null) { - company.setMailFolder(mailFolders); - companyService.saveCompany(company); + log.debug(company.getMailFilter()); + Map<MailFilter, String> folderIdByFilter = new HashMap<>(); + if (mailFilters != null) { + for (MailFilterUIBean filter : mailFilters) { + String folderId = filter.getMailFolderId(); + folderIdByFilter.put(filter, folderId); + } + } + companyService.saveCompany(company, mailFolders, folderIdByFilter); } result = INPUT; } @@ -79,8 +107,15 @@ this.companyService = companyService; } + public void setMailFolderService(MailFolderService mailFolderService) { + this.mailFolderService = mailFolderService; + } + + public void setUserService(UserService userService) { + this.userService = userService; + } + public void setCompanyId(String companyId) { - log.debug("set company " + companyId); if (StringUtils.isNotEmpty(companyId)) { this.company = companyService.getCompany(companyId); } @@ -98,7 +133,6 @@ } public Company getCompany() { - log.debug("getCompany " + company); return company; } @@ -115,7 +149,7 @@ } public Map<String, String> getEmailFields() { - Map<String, String> result = Maps.newHashMap(); + Map<String, String> result = new HashMap<>(); result.put(Email.PROPERTY_EMAIL_ADDRESS, "Adresse email"); result.put(Email.PROPERTY_RECEPTION_DATE, "Date de réception"); result.put(Email.PROPERTY_EDI_CODE_NUMBER, "Code EDI"); @@ -129,21 +163,81 @@ return null; } GsonBuilder gsonBuilder = new GsonBuilder(); - String mailFodlers = gsonBuilder.create().toJson(company.getMailFolder()); - log.debug("getFolderTreeAsJson " + mailFodlers); - return mailFodlers; + String mailFolders = gsonBuilder.create().toJson(company.getMailFolder()); + return mailFolders; } public void setFoldersTreeAsJson(String json) { - log.debug("setFoldersTreeAsJson " + json); GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(MailFolder.class, new MailFolderDeserializer()); - mailFolders = Lists.newArrayList((MailFolder[])gsonBuilder.create().fromJson(json, MailFolder[].class)); - log.debug("mailfolders " + mailFolders); - if (!mailFolders.isEmpty()) { - log.debug("name : " + mailFolders.get(0).getName()); + mailFolders = Arrays.asList((MailFolder[])gsonBuilder.create().fromJson(json, MailFolder[].class)); + log.debug(mailFolders); + } + + public Map<String, String> getAllFoldersFlat() { + if (mailFoldersFlat == null) { + mailFoldersFlat = new LinkedHashMap<>(); + if (company.getMailFolder() != null) { + List<MailFolder> folders = new ArrayList<>(company.getMailFolder()); + Collections.sort(folders, new Comparator<MailFolder>() { + @Override + public int compare(MailFolder o1, MailFolder o2) { + return ComparatorUtils.NATURAL_COMPARATOR.compare(o1.getName(), o2.getName()); + } + }); + for (MailFolder folder : folders) { + mailFoldersFlat.putAll(getAllFoldersFlat(folder, "")); + } + } } + return mailFoldersFlat; } + public List<MailFilterUIBean> getMailFilters() { + if (mailFilters == null) { + mailFilters = new ArrayList<>(); + } + return mailFilters; + } + + public void setMailFilters(List<MailFilterUIBean> mailFilters) { + this.mailFilters = mailFilters; + } + + public List<FaxToMailUser> getAllUsers() { + if (allUsers == null) { + allUsers = userService.getAllUsers(); + } + return allUsers; + } + + public List<FaxToMailUserGroup> getAllUserGroups() { + if (allUserGroups == null) { + allUserGroups = userService.getAllUserGroups(); + } + return allUserGroups; + } + + protected Map<String, String> getAllFoldersFlat(MailFolder mailFolder, String prefix) { + Map<String, String> result = new LinkedHashMap<>(); + prefix += "/" + mailFolder.getName(); + result.put(mailFolder.getTopiaId(), prefix); + log.debug(prefix); + + if (mailFolder.getChildren() != null) { + List<MailFolder> children = new ArrayList<>(mailFolder.getChildren()); + Collections.sort(children, new Comparator<MailFolder>() { + @Override + public int compare(MailFolder o1, MailFolder o2) { + return ComparatorUtils.NATURAL_COMPARATOR.compare(o1.getName(), o2.getName()); + } + }); + for (MailFolder child : children) { + result.putAll(getAllFoldersFlat(child, prefix)); + } + } + return result; + } + protected class MailFolderDeserializer implements JsonDeserializer<MailFolder> { @Override @@ -155,7 +249,7 @@ mailFolder.setName(name); MailFolder[] children = context.deserialize(o.get(MailFolder.PROPERTY_CHILDREN), MailFolder[].class); - List<MailFolder> mailFolders = Lists.newArrayList(children); + List<MailFolder> mailFolders = Arrays.asList(children); mailFolder.setChildren(mailFolders); String topiaId = o.get(MailFolder.PROPERTY_TOPIA_ID).getAsString(); @@ -164,4 +258,17 @@ return mailFolder; } } + + public static class MailFilterUIBean extends MailFilterImpl { + + protected String mailFolderId; + + public String getMailFolderId() { + return mailFolderId; + } + + public void setMailFolderId(String mailFolderId) { + this.mailFolderId = mailFolderId; + } + } } Modified: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration.jsp 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/configuration.jsp 2014-02-11 10:12:54 UTC (rev 8) @@ -9,132 +9,24 @@ <script type="text/javascript" src="<s:url value='/js/select2/select2_locale_fr.js' />"></script> <script type="text/javascript" src="<s:url value='/js/jstree/jstree.js' />"></script> - <link rel="stylesheet" type="text/css" href="<s:url value='/css/select2/select2.css' />" /> - <link rel="stylesheet" type="text/css" href="<s:url value='/css/jstree/themes/default/style.min.css' />" /> - <link rel="stylesheet" type="text/css" href="<s:url value='/css/configuration.css' />" /> <script> - - var createNewNode = function() { - $('.jstree').jstree(true).create_node('#', 'Nouvelle racine'); - } - - var formatToSendData = function(mailFolders) { - var result = []; - for (var i = 0 ; i < mailFolders.length ; i++) { - var mailFolder = mailFolders[i]; - var children = formatToSendData(mailFolder.children); - result.push({ name: mailFolder.text, children: children, topiaId: mailFolder.id }); - } - return result; - } - - var formatReceivedData = function(mailFolders) { - var result = []; - for (var i = 0 ; i < mailFolders.length ; i++) { - var mailFolder = mailFolders[i]; - var children = formatReceivedData(mailFolder.children); - result.push({ text: mailFolder.name, children: children, id: mailFolder.topiaId }); - } - return result; - } - var emailFields = {}; <s:iterator value="emailFields"> - emailFields["<s:property value='key'/>"] = "<s:property value='value'/>"; + emailFields["<s:property value='key'/>"] = "<s:property value='value' escapeHtml='false'/>"; </s:iterator> - var updateTableSnapshot = function() { - var tableHeader = $("#table-snapshot thead tr"); - tableHeader.empty(); - var value = $("#tableColumns").val(); - if (value) { - var columns = value.split(","); - for (var i = 0 ; i < columns.length ; i++) { - tableHeader.append("<th>" + emailFields[columns[i]] + "</th>"); - } - } - } + var folderData = JSON.parse('<s:property value="foldersTreeAsJson" escapeHtml="false"/>'); + </script> + <script type="text/javascript" src="<s:url value='/js/configuration.js' />"></script> - $().ready(function() { + <link rel="stylesheet" type="text/css" href="<s:url value='/css/select2/select2.css' />" /> + <link rel="stylesheet" type="text/css" href="<s:url value='/css/jstree/themes/default/style.min.css' />" /> + <link rel="stylesheet" type="text/css" href="<s:url value='/css/configuration.css' />" /> - $('a[data-toggle="tab"]').on('shown', function (e) { - var hash = e.target.hash; - $(":input[name='activeTab']").val(hash); - - /*if (hash == "#tabs-3") { - $('#treeDiagram').jstree(true).refresh(); - - } else if (hash == "#tabs-4") { - $('#treeDiagram2choose').jstree(true).refresh(); - }*/ - }); - - var hash = $(":input[name='activeTab']").val(); - if (!hash) { - hash = "#tabs-1"; - } - $('#tabs a[href="' + hash + '"]').tab('show'); - - // table columns - - $('#tableColumns').select2({tags:[ - <s:iterator value="emailFields"> - { id: "<s:property value='key'/>", text: "<s:property value='value' escapeHtml='false'/>" }, - </s:iterator> - ]}).on("change", function(e) { - console.log(e.val) - updateTableSnapshot(); - }); - - $("#tableColumns").select2("container").find("ul.select2-choices").sortable({ - containment: 'parent', - start: function() { $("#tableColumns").select2("onSortStart"); }, - update: function() { $("#tableColumns").select2("onSortEnd"); } - }); - - updateTableSnapshot(); - - // tree diagram - - var folderData = JSON.parse('<s:property value="foldersTreeAsJson" escapeHtml="false"/>'); - folderData = formatReceivedData(folderData); - - $.jstree.defaults.core.themes.variant = "large"; - // so that create works - $.jstree.defaults.core.check_callback = true; - $.jstree.defaults.core.multiple = false; - - $('#treeDiagram').jstree({ - core: { - data: folderData - }, - state: { key: "faxtomail-treeDiagram" }, - plugins: [ "contextmenu", "sort", "state", "unique", "dnd" ] - }); - - $('#treeDiagram2choose').jstree({ - core: { - data: folderData - }, - state: { key: "faxtomail-treeDiagram2choose" }, - plugins: [ "sort", "state" ] - }); - - $("#main_form").submit(function(event) { - var mailFolders = $('#treeDiagram').jstree(true).get_json('#', {}); - var foldersAsJson = formatToSendData(mailFolders); - console.log(foldersAsJson); - - var input = $("<input>") - .attr("type", "hidden") - .attr("name", "foldersTreeAsJson").val(JSON.stringify(foldersAsJson)); - $('#main_form').append($(input)); - }); - }); - </script> </head> <body> + <!-- navbar --> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="navbar-inner"> <div class="container"> @@ -174,15 +66,17 @@ <s:hidden name="activeTab"/> <ul id="tabs" class="nav nav-tabs"> - <li><a href="#tabs-1" data-toggle="tab">Général</a></li> - <li><a href="#tabs-2" data-toggle="tab">Champs du tableau</a></li> - <li><a href="#tabs-3" data-toggle="tab">Arborescence</a></li> - <li><a href="#tabs-4" data-toggle="tab">Filtres de mail</a></li> + <li><a href="#tabs-general" data-toggle="tab">Général</a></li> + <li><a href="#tabs-table" data-toggle="tab">Champs du tableau</a></li> + <li><a href="#tabs-tree" data-toggle="tab">Arborescence</a></li> + <li><a href="#tabs-filters" data-toggle="tab">Filtres de mail</a></li> + <li><a href="#tabs-rights" data-toggle="tab">Droits</a></li> + <li><a href="#tabs-email-accounts" data-toggle="tab">Comptes mails</a></li> </ul> <div class="tab-content"> - <div id="tabs-1" class="tab-pane"> + <div id="tabs-general" class="tab-pane"> <!-- Général --> <s:checkbox name="company.configuration.sendAknowledgement" @@ -201,7 +95,7 @@ </div> - <div id="tabs-2" class="tab-pane"> + <div id="tabs-table" class="tab-pane"> <!-- Champs du tableau --> <div class="control-group "> @@ -225,7 +119,7 @@ </div> - <div id="tabs-3" class="tab-pane"> + <div id="tabs-tree" class="tab-pane"> <!-- Tree Diagram --> <div id="treeDiagram" class="jstree margin-bottom25"> @@ -237,7 +131,7 @@ </div> - <div id="tabs-4" class="tab-pane"> + <div id="tabs-filters" class="tab-pane"> <!-- Filtres de mail --> <table id="filters" class="table table-bordered"> <thead> @@ -246,16 +140,197 @@ <th>Dossier</th> </tr> </thead> + <tbody> + <s:iterator value="company.mailFilter" status="rowStatus" var="filter"> + <tr> + <td> + <s:property value='expression'/> + <s:hidden name="mailFilters[%{#rowStatus.index}].expression" + value="%{#filter.expression}"/> + </td> + <td> + <s:property value='allFoldersFlat.get(mailFolder.topiaId)'/> + <s:hidden name="mailFilters[%{#rowStatus.index}].mailFolderId" + value="%{#filter.mailFolder.topiaId}"/> + </td> + <s:hidden name="mailFilters[%{#rowStatus.index}].topiaId" + value="%{#filter.topiaId}"/> + </tr> + </s:iterator> + </tbody> </table> - <s:textfield name="newFilterExpression" - label="Nouveau filtre"/> + <fieldset class="margin-bottom25"> + <legend>Nouveau filtre</legend> - <div id="treeDiagram2choose" class="jstree"> - </div> + <div id="newFilterExpression-group" class="control-group"> + <label for="newFilterExpression">Expression</label> + <div class="controls"> + <input type="text" + id="newFilterExpression" + class="input-xxlarge" + <s:if test="allFoldersFlat.isEmpty()">disabled</s:if>/> + <span id="newFilterExpression-help" class="help-inline"></span> + </div> + </div> + <div id="newFilterFolder-group" class="control-group"> + <label for="newFilterFolder">Dossier de destination</label> + <div class="controls"> + <select id="newFilterFolder" + class="input-xxlarge" + <s:if test="allFoldersFlat.isEmpty()">disabled</s:if>> + <s:iterator value="allFoldersFlat"> + <option value="<s:property value='key'/>"><s:property value='value'/></option> + </s:iterator> + </select> + <span id="newFilterFolder-help" class="help-inline"></span> + </div> + </div> + + <div> + <button class="btn" type="button" onClick="createNewFilter()" <s:if test="allFoldersFlat.isEmpty()">disabled</s:if>> + <i class="icon-plus"></i> Ajouter + </button> + </div> + + </fieldset> </div> + <div id="tabs-rights" class="tab-pane"> + <!-- Droits d'accès --> + <table id="rights" class="table table-bordered"> + <thead> + <tr> + <th>Utilisateur ou groupe</th> + <th>Dossier</th> + <th>Type</th> + </tr> + </thead> + <tbody></tbody> + </table> + + <fieldset class="margin-bottom25"> + + <legend>Nouveau droit</legend> + + <div id="newRightUser-group" class="control-group"> + <label for="newRightUser">Utilisateur ou groupe</label> + <div class="controls"> + <select id="newRightUser" + class="input-xxlarge" + <s:if test="allUsers.isEmpty() && allUserGroups.isEmpty()">disabled</s:if>> + <optgroup label="Utilisateurs"> + <s:iterator value="allUsers"> + <option value="<s:property value='topiaId'/>"><s:property value='name'/></option> + </s:iterator> + </optgroup> + <optgroup label="Groupes"> + <s:iterator value="allUserGroups"> + <option value="<s:property value='topiaId'/>"><s:property value='name'/></option> + </s:iterator> + </optgroup> + </select> + <span id="newRightUser-help" class="help-inline"></span> + </div> + </div> + + <div id="newRightFolder-group" class="control-group"> + <label for="newRightFolder">Dossier de destination</label> + <div class="controls"> + <select id="newRightFolder" + class="input-xxlarge" + <s:if test="allFoldersFlat.isEmpty()">disabled</s:if>> + <s:iterator value="allFoldersFlat"> + <option value="<s:property value='key'/>"><s:property value='value'/></option> + </s:iterator> + </select> + <span id="newRightFolder-help" class="help-inline"></span> + </div> + </div> + + <div id="newRightTypes-group" class="control-group"> + <label>Types</label> + <div class="controls"> + <label class="checkbox inline"> + <input type="checkbox" id="newRightType-read" value="READ"/> lecture + </label> + <label class="checkbox inline"> + <input type="checkbox" id="newRightType-write" value="WRITE"/> écriture + </label> + <label class="checkbox inline"> + <input type="checkbox" id="newRightType-archive" value="ARCHIVE"/> archives + </label> + <span id="newRightType-help" class="help-inline"></span> + </div> + </div> + + <div> + <button class="btn" type="button" onClick="createNewRight()" <s:if test="allFoldersFlat.isEmpty()">disabled</s:if>> + <i class="icon-plus"></i> Ajouter + </button> + </div> + + </fieldset> + + </div> + + <div id="tabs-email-accounts" class="tab-pane"> + <!-- Comptes email --> + <table id="emailAccounts" class="table table-bordered"> + <thead> + <tr> + <th>Nom d'utilisateur</th> + <th>Serveur</th> + <th>Port</th> + </tr> + </thead> + <tbody></tbody> + </table> + + <fieldset class="margin-bottom25"> + <legend>Nouveau compte mail</legend> + + <div id="newEmailAccountUsername-group" class="control-group"> + <label for="newEmailAccountUsername">Nom d'utilisateur</label> + <div class="controls"> + <input type="text" + id="newEmailAccountUsername" + class="input-xxlarge"/> + <span id="newEmailAccountUsername-help" class="help-inline"></span> + </div> + </div> + + <div id="newEmailAccountServer-group" class="control-group"> + <label for="newEmailAccountServer">Serveur</label> + <div class="controls"> + <input type="text" + id="newEmailAccountServer" + class="input-xxlarge"/> + <span id="newEmailAccountServer-help" class="help-inline"></span> + </div> + </div> + + <div id="newEmailAccountPort-group" class="control-group"> + <label for="newEmailAccountPort">Port</label> + <div class="controls"> + <input type="number" + id="newEmailAccountPort" + class="input-xxlarge"/> + <span id="newEmailAccountPort-help" class="help-inline"></span> + </div> + </div> + + <div> + <button class="btn" type="button" onClick="createNewEmailAccount()"> + <i class="icon-plus"></i> Ajouter + </button> + </div> + + </fieldset> + + </div> + </div> <div class="form-actions"> @@ -264,7 +339,6 @@ </s:form> </s:if> - </div> </body> </html> Modified: trunk/faxtomail-ui-web/src/main/webapp/css/configuration.css =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/css/configuration.css 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/faxtomail-ui-web/src/main/webapp/css/configuration.css 2014-02-11 10:12:54 UTC (rev 8) @@ -21,4 +21,5 @@ } #treeDiagram { + background: #f0f0f0; } \ No newline at end of file Added: trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js (rev 0) +++ trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-02-11 10:12:54 UTC (rev 8) @@ -0,0 +1,238 @@ +/** + * adds a new folder in the tree + */ +var createNewNode = function() { + $('.jstree').jstree(true).create_node('#', 'Nouvelle racine'); +} + +/** + * adds a new filter in the table + */ +var createNewFilter = function() { + var filterExpression = $("#newFilterExpression").val(); + if (!filterExpression) { + $("#newFilterExpression-group").addClass("error"); + $("#newFilterExpression-group .help-inline").text("Veuillez entrer une valeur"); + return; + } + $("#newFilterExpression-group").removeClass("error"); + $("#newFilterExpression-group .help-inline").text(""); + + var filterFolderId = $("#newFilterFolder :selected").val(); + var filterFolder = $("#newFilterFolder :selected").text(); + if (!filterFolder) { + $("#newFilterFolder-group").addClass("error"); + $("#newFilterFolder-group .help-inline").text("Veuillez sélectionner un dossier"); + return; + } + $("#newFilterFolder-group").removeClass("error"); + $("#newFilterFolder-group .help-inline").text(""); + + var index = $("#filters tbody tr").length; + var row = "<tr>" + + "<td>" + + filterExpression + + "<input type='hidden' name='mailFilters[" + index + "].expression' value='" + filterExpression + "'/>" + + "</td>" + + "<td>" + + filterFolder + + "<input type='hidden' name='mailFilters[" + index + "].mailFolderId' value='" + filterFolderId + "'/>" + + "</td>" + + "</tr>"; + $("#filters tbody").append(row); +} + +/** + * adds a new right in the table + */ +var createNewRight = function() { + var rightUserId = $("#newRightUser :selected").val(); + var rightUser = $("#newRightUser :selected").text(); + if (!rightUser) { + $("#newRightUser-group").addClass("error"); + $("#newRightUser-group .help-inline").text("Veuillez sélectionner au moins un utilisateur"); + return; + } + $("#newRightUser-group").removeClass("error"); + $("#newRightUser-group .help-inline").text(""); + + var rightFolderId = $("#newRightFolder :selected").val(); + var rightFolder = $("#newRightFolder :selected").text(); + if (!rightFolder) { + $("#newRightFolder-group").addClass("error"); + $("#newRightFolder-group .help-inline").text("Veuillez sélectionner un dossier"); + return; + } + $("#newRightFolder-group").removeClass("error"); + $("#newRightFolder-group .help-inline").text(""); + + var rightTypeIds = new Array(); + var rightTypes = new Array(); + var checkedTypes = $("#newRightTypes-group :checked"); + if (checkedTypes.length == 0) { + $("#newRightTypes-group").removeClass("error"); + $("#newRightTypes-group .help-inline").text(""); + return; + } + $("#newRightTypes-group").addClass("error"); + $("#newRightTypes-group .help-inline").text("Veuillez choisir au moins un type"); + checkedTypes.each(function() { + rightTypeIds.push($(this).val()); + rightTypes.push($(this).parent().text().trim()); + }); + + var index = $("#rights tbody tr").length; + var row = "<tr>" + + "<td>" + + rightUser + + "<input type='hidden' name='rights[" + index + "].userId' value='" + rightUserId + "'/>" + + "</td>" + + "<td>" + + rightFolder + + "<input type='hidden' name='rights[" + index + "].mailFolderId' value='" + rightFolderId + "'/>" + + "</td>" + + "<td>" + + rightTypes.join(", ") + + "<input type='hidden' name='rights[" + index + "].types' value='" + rightTypeIds.join(",") + "'/>" + + "</td>" + + "</tr>"; + $("#rights tbody").append(row); +} + +var createNewEmailAccount = function() { + var emailAccountUsername = $("#newEmailAccountUsername").val(); + if (!emailAccountUsername) { + $("#newEmailAccountUsername-group").addClass("error"); + $("#newEmailAccountUsername-group .help-inline").text("Veuillez entrer une valeur"); + return; + } + $("#newEmailAccountUsername-group").removeClass("error"); + $("#newEmailAccountUsername-group .help-inline").text(""); + + var emailAccountServer = $("#newEmailAccountServer").val(); + if (!emailAccountServer) { + $("#newEmailAccountServer-group").addClass("error"); + $("#newEmailAccountServer-group .help-inline").text("Veuillez entrer une valeur"); + return; + } + $("#newEmailAccountServer-group").removeClass("error"); + $("#newEmailAccountServer-group .help-inline").text(""); + + var emailAccountPort = $("#newEmailAccountPort").val(); + if (!emailAccountPort) { + $("#newEmailAccountPort-group").addClass("error"); + $("#newEmailAccountPort-group .help-inline").text("Veuillez entrer une valeur"); + return; + } + $("#newEmailAccountPort-group").removeClass("error"); + $("#newEmailAccountPort-group .help-inline").text(""); + + var index = $("#emailAccounts tbody tr").length; + var row = "<tr>" + + "<td>" + + emailAccountUsername + + "<input type='hidden' name='emailAccounts[" + index + "].username' value='" + emailAccountUsername + "'/>" + + "</td>" + + "<td>" + + emailAccountServer + + "<input type='hidden' name='emailAccounts[" + index + "].server' value='" + emailAccountServer + "'/>" + + "</td>" + + "<td>" + + emailAccountPort + + "<input type='hidden' name='emailAccounts[" + index + "].port' value='" + emailAccountPort + "'/>" + + "</td>" + + "</tr>"; + $("#emailAccounts tbody").append(row); + console.log("debig") +} + +var formatToSendData = function(mailFolders) { + var result = []; + for (var i = 0 ; i < mailFolders.length ; i++) { + var mailFolder = mailFolders[i]; + var children = formatToSendData(mailFolder.children); + result.push({ name: mailFolder.text, children: children, topiaId: mailFolder.id }); + } + return result; +} + +var formatReceivedData = function(mailFolders) { + var result = []; + for (var i = 0 ; i < mailFolders.length ; i++) { + var mailFolder = mailFolders[i]; + var children = formatReceivedData(mailFolder.children); + result.push({ text: mailFolder.name, children: children, id: mailFolder.topiaId }); + } + return result; +} + +var updateTableSnapshot = function() { + var tableHeader = $("#table-snapshot thead tr"); + tableHeader.empty(); + var value = $("#tableColumns").val(); + if (value) { + var columns = value.split(","); + for (var i = 0 ; i < columns.length ; i++) { + tableHeader.append("<th>" + emailFields[columns[i]] + "</th>"); + } + } +} + +$().ready(function() { + + $('a[data-toggle="tab"]').on('shown', function (e) { + var hash = e.target.hash; + $(":input[name='activeTab']").val(hash); + }); + + var hash = $(":input[name='activeTab']").val(); + if (!hash) { + hash = "#tabs-general"; + } + $('#tabs a[href="' + hash + '"]').tab('show'); + + // table columns + + var tableColumnTags = new Array(); + for (var k in emailFields) { + tableColumnTags.push({ id: k, text: emailFields[k] }) + } + $('#tableColumns').select2({tags:tableColumnTags}).on("change", function(e) { + updateTableSnapshot(); + }); + + $("#tableColumns").select2("container").find("ul.select2-choices").sortable({ + containment: 'parent', + start: function() { $("#tableColumns").select2("onSortStart"); }, + update: function() { $("#tableColumns").select2("onSortEnd"); } + }); + + updateTableSnapshot(); + + // tree diagram + folderData = formatReceivedData(folderData); + + $('#treeDiagram').jstree({ + core: { + data: folderData, + check_callback: true, + multiple: false, + themes: { + variant: "large" + } + }, + state: { key: "faxtomail-treeDiagram" }, + plugins: [ "contextmenu", "sort", "state", "unique", "dnd" ] + }); + + $("#main_form").submit(function(event) { + var mailFolders = $('#treeDiagram').jstree(true).get_json('#', {}); + var foldersAsJson = formatToSendData(mailFolders); + console.log(foldersAsJson); + + var input = $("<input>") + .attr("type", "hidden") + .attr("name", "foldersTreeAsJson").val(JSON.stringify(foldersAsJson)); + $('#main_form').append($(input)); + }); +}); \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2014-02-06 16:42:22 UTC (rev 7) +++ trunk/pom.xml 2014-02-11 10:12:54 UTC (rev 8) @@ -113,6 +113,9 @@ <license.organizationName>Franciaflex</license.organizationName> <license.licenseName>gpl_v3</license.licenseName> + <!-- Java version --> + <maven.compiler.source>1.7</maven.compiler.source> + <maven.compiler.target>1.7</maven.compiler.target> <!-- Last JRE version to use --> <jreVersion>1.7.45</jreVersion> @@ -451,6 +454,8 @@ </dependencyManagement> <build> + + <pluginManagement> <plugins>
participants (1)
-
kmorin@users.forge.codelutin.com