r87 - in trunk: echobase-services/src/main/java/fr/ifremer/echobase/services echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor echobase-ui/src/main/webapp/WEB-INF/includes echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor echobase-ui/src/main/webapp/css
Author: sletellier Date: 2011-11-16 14:12:32 +0100 (Wed, 16 Nov 2011) New Revision: 87 Url: http://forge.codelutin.com/repositories/revision/echobase/87 Log: - Allow to update date in dbeditor - Allow to create entity in dbeditore Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java trunk/echobase-ui/src/main/webapp/WEB-INF/includes/metas.jsp trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp trunk/echobase-ui/src/main/webapp/css/screen.css Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-15 17:40:35 UTC (rev 86) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-11-16 13:12:32 UTC (rev 87) @@ -46,6 +46,7 @@ import org.nuiton.util.beans.BeanMonitor; import org.nuiton.util.beans.PropertyDiff; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; @@ -178,7 +179,14 @@ getTransaction(), entityType); - TopiaEntity entityToSave = dao.findByTopiaId(id); + TopiaEntity entityToSave; + + // Find or create entity if no id + if (StringUtils.isEmpty(id)) { + entityToSave = dao.create(); + } else { + entityToSave = dao.findByTopiaId(id); + } monitor.setBean(entityToSave); for (Map.Entry<String, String> entry : properties.entrySet()) { String propertyName = entry.getKey(); @@ -192,6 +200,11 @@ getTransaction(), (Class<? extends TopiaEntity>) columnMeta.getType()); value = daoFK.findByTopiaId(propertyValue); + + } else if (Date.class.equals(columnMeta.getType())) { + + // Parse date + value = SimpleDateFormat.getInstance().parse(propertyValue); } else { value = propertyValue; } @@ -230,10 +243,14 @@ if (tableMeta.getColumns(propertyName).isFK()) { // replace by the decorate value - sourceValue = getDecoratorService().decorate( - getLocale(), sourceValue, null); - targetValue = getDecoratorService().decorate( - getLocale(), targetValue, null); + if (sourceValue != null) { + sourceValue = getDecoratorService().decorate( + getLocale(), sourceValue, null); + } + if (targetValue != null) { + targetValue = getDecoratorService().decorate( + getLocale(), targetValue, null); + } } buffer.append(String.format("\n Propriété '%s', ancienne valeur : %s, nouvelle valeur : %s", Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-15 17:40:35 UTC (rev 86) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/LoadEntities.java 2011-11-16 13:12:32 UTC (rev 87) @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import org.nuiton.topia.persistence.TopiaEntity; +import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -111,7 +112,9 @@ String editType="'string'"; if (boolean.class.equals(type)) { editType = "'checkbox'"; - } else if (TopiaEntity.class.isAssignableFrom(type)) { + } else if (Date.class.isAssignableFrom(type)) { + editType = "'date'"; + } else if (TopiaEntity.class.isAssignableFrom(type)) { editType = "'formatEntityLabel'"; } return editType; Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/includes/metas.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/includes/metas.jsp 2011-11-15 17:40:35 UTC (rev 86) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/includes/metas.jsp 2011-11-16 13:12:32 UTC (rev 87) @@ -32,5 +32,5 @@ href="<s:url value='/css/screen.css' />"/> <link rel="icon" type="image/png" href="<s:url value='/images/logo_codelutin.png' />"/> - <sj:head jqueryui="true" jquerytheme="cupertino"/> + <sj:head jqueryui="true" loadAtOnce="true" compressed="false" jquerytheme="cupertino"/> </head> Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-15 17:40:35 UTC (rev 86) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/dbeditor/dbeditor.jsp 2011-11-16 13:12:32 UTC (rev 87) @@ -1,26 +1,26 @@ <%-- - #%L - EchoBase :: UI - - $Id$ - $HeadURL$ - %% - Copyright (C) 2011 Ifremer, Codelutin - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - #L% - --%> +#%L +EchoBase :: UI + +$Id$ +$HeadURL$ +%% +Copyright (C) 2011 Ifremer, Codelutin +%% +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +#L% +--%> <%@page contentType="text/html" pageEncoding="UTF-8" %> <%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="sj" uri="/struts-jquery-tags" %> @@ -31,10 +31,22 @@ <title><s:text name="echobase.title.dbEditor"/></title> +<%--<script type="text/javascript" src="/echobase/struts/js/base/jquery.ui.datepicker.min.js"></script>--%> +<script type="text/javascript" src="/echobase/struts/js/base/jquery.ui.datepicker.js"></script> <script type="text/javascript"> jQuery(document).ready(function () { + // Hack to make name=id on sj tags + var combos = $('select[name=""]'); + combos.each(function(obj) { + this.name = this.id; + }); + var pickers = $('input.hasDatepicker'); + pickers.each(function(obj) { + this.name = this.id; + }); + $('[name="tableName"]').change(function(event) { var url = "${reloadUrl}?" + $.param({tableName:this.value}); window.location = url; @@ -74,12 +86,21 @@ // if editor found if (editor) { - // get type for checkbox - var editorType = editor.type; - if (editorType == "checkbox") { - editor.checked = value; + if ($(editor).hasClass("hasDatepicker")) { + + // Update date + var inst = $.datepicker._getInst(editor); + $.datepicker._setDate(inst, new Date(value)); } else { - editor.value = value; + + // get type for checkbox + var editorType = editor.type; + + if (editorType == "checkbox") { + editor.checked = value; + } else { + editor.value = value; + } } } } @@ -97,7 +118,7 @@ <s:select key="tableName" label='%{getText("echobase.common.tableName")}' list="tableNames" headerKey="" headerValue=""/> </div> -<br/> +<br class="clearBoth"/> <s:if test="tableName!=null and tableName != ''"> <s:url id="loadUrl" action="getTableDatas" namespace="/dbeditor" @@ -146,6 +167,7 @@ title="%{getText(#meta.i18nKey)}" edittype='%{getEditType(#meta)}' formatter='%{getFormatter(#meta)}' + formatoptions="{newformat : 'd/m/Y H:i:s'}" sortable="true" editable="true"/> </s:else> @@ -154,12 +176,14 @@ </sjg:grid> + <br class="clearBoth"/> + <s:form id="editForm" action="editTableData" namespace="/dbeditor"> <fieldset> <legend> <s:text name="echobase.common.user"/> </legend> - <s:hidden key="id"/> + <s:hidden id="id" key="id"/> <s:hidden key="tableName"/> <s:iterator value="columnMetas" var="meta" status="status"> <%-- TODO sletellier 20111115 : try to refactor with table url --%> @@ -170,9 +194,7 @@ escapeAmp="false"> <s:param name="entityType" value="%{#meta.typeSimpleName}"/> </s:url> - <%-- TODO sletellier 20111115 : foreign key --%> <s:if test="#meta.fK"> - <%--Foreign : <s:property value="%{#meta.name}"/>--%> <sj:select id="%{#meta.name}" label="%{getText(#meta.i18nKey)}" href="%{urlName}" @@ -183,16 +205,22 @@ <s:else> <s:if test='#meta.columnType == "string"'> <s:textfield id="%{#meta.name}" + name="%{#meta.name}" label="%{getText(#meta.i18nKey)}" disabled="%{#meta.fK}" value=""/> </s:if> <s:elseif test='#meta.columnType == "boolean"'> <s:checkbox id="%{#meta.name}" + name="%{#meta.name}" label="%{getText(#meta.i18nKey)}" value="%{false}"/> </s:elseif> <s:elseif test='#meta.columnType == "date"'> <sj:datepicker id="%{#meta.name}" + name="%{#meta.name}" + timepicker="true" + timepickerShowSecond="true" + timepickerFormat="hh:mm:ss" label="%{getText(#meta.i18nKey)}"/> </s:elseif> </s:else> Modified: trunk/echobase-ui/src/main/webapp/css/screen.css =================================================================== --- trunk/echobase-ui/src/main/webapp/css/screen.css 2011-11-15 17:40:35 UTC (rev 86) +++ trunk/echobase-ui/src/main/webapp/css/screen.css 2011-11-16 13:12:32 UTC (rev 87) @@ -42,6 +42,10 @@ width: 99%; } +.clearBoth { + clear: both; +} + #footer { /*margin-top: 120px;*/ clear: both;
participants (1)
-
sletellier@users.forge.codelutin.com