Commit 98af4f25 authored by Jérome Perrin's avatar Jérome Perrin

renderjs_ui: us asBoolean in ERP5JS datetime field

This makes ERP5JS's datetime field behave same as python when using
TALES expression for "date_only" and other less used field values.
parent 8282ce71
Pipeline #32714 failed with stage
in 0 seconds
......@@ -103,6 +103,7 @@
<list>
<string>my_start_date</string>
<string>my_stop_date</string>
<string>my_date_time_field_with_tales</string>
</list>
</value>
</item>
......
......@@ -8,10 +8,11 @@
<link rel="http://www.renderjs.org/rel/interface" href="interface_erp5_form_content_provider.html">
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_global.js"></script>
<!-- custom script -->
<script src="gadget_erp5_field_datetime.js" type="text/javascript"></script>
<script src="gadget_erp5_field_datetime.js"></script>
</head>
<body>
......
......@@ -226,7 +226,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>ERP5TypeTestCase</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>969.41949.34822.14233</string> </value>
<value> <string>1014.23421.40553.48503</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1536676302.67</float>
<float>1707223949.31</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, RSVP*/
/*global window, rJS, RSVP, asBoolean*/
/*jslint indent: 2, maxlen: 80 */
(function (window, rJS, RSVP) {
(function (window, rJS, RSVP, asBoolean) {
"use strict";
var ZONE_LIST = [
......@@ -322,26 +322,26 @@
if (options === undefined || options.format === "erp5") {
if (value !== "") {
if (gadget.state.date_only === 0) {
if (!asBoolean(gadget.state.date_only)) {
value += "+0000";
}
value = new Date(value);
year = value.getUTCFullYear();
month = value.getUTCMonth() + 1;
date = value.getUTCDate();
if (gadget.state.hide_day === 1) {
if (asBoolean(gadget.state.hide_day)) {
date = 1;
}
//get time
if (gadget.state.date_only === 0) {
if (gadget.state.allow_empty_time === 1) {
if (!asBoolean(gadget.state.date_only)) {
if (asBoolean(gadget.state.allow_empty_time)) {
hour = 0;
minute = 0;
} else {
hour = value.getUTCHours();
minute = value.getUTCMinutes();
}
if (gadget.state.ampm_time_style === 1) {
if (asBoolean(gadget.state.ampm_time_style)) {
if (hour > 12) {
result[gadget.state.subfield_ampm_key] = "pm";
hour -= 12;
......@@ -353,7 +353,7 @@
result[gadget.state.subfield_minute_key] = minute;
}
if (gadget.state.hidden_day_is_last_day === 1) {
if (asBoolean(gadget.state.hidden_day_is_last_day)) {
if (month === 12) {
year += 1;
month = 1;
......@@ -375,7 +375,7 @@
}
} else {
//if no value, return empty data
if (gadget.state.date_only === 0) {
if (!asBoolean(gadget.state.date_only)) {
result[gadget.state.subfield_hour_key] = "";
result[gadget.state.subfield_minute_key] = "";
}
......@@ -406,4 +406,4 @@
return true;
}, {mutex: 'changestate'});
}(window, rJS, RSVP));
}(window, rJS, RSVP, asBoolean));
......@@ -216,7 +216,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <string>ERP5TypeTestCase</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.26496.42040.8686</string> </value>
<value> <string>1014.23430.20338.62976</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1609253131.46</float>
<float>1707224080.57</float>
<string>UTC</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testDateTimeFieldTALESDateOnly</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test RenderJS UI</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Clean Up -->
<tr>
<td>open</td>
<td>${base_url}/bar_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<!-- Initialize -->
<tr>
<td>open</td>
<td>${base_url}/bar_module/BarModule_createObjects?num:int=1</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Created Successfully.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/bar_module/0?editable=true</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/go_to_bar_datetime_field_view" />
<!-- Actual test -->
<tr>
<td>assertValue</td>
<td>//input[@name='field_my_date_time_field_with_tales']</td>
<td>2001-02-03</td>
</tr>
<tr>
<td>type</td>
<td>//input[@name='field_my_date_time_field_with_tales']</td>
<td>2003-02-01</td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/click_save" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr>
<td>assertValue</td>
<td>//input[@name='field_my_date_time_field_with_tales']</td>
<td>2003-02-01</td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
......@@ -528,13 +528,13 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
if self.skin == 'ODT':
return tree.xpath('normalize-space((//table[2]//tr//td)[3])')
elif self.skin == 'ODS':
return tree.xpath('normalize-space(//table//tr[7]/td)')
return tree.xpath('normalize-space(//table//tr[8]/td)')
def get_date_time_listbox_stat_value(tree):
if self.skin == 'ODT':
return tree.xpath('normalize-space((//table[2]//tr//td)[4])')
elif self.skin == 'ODS':
return tree.xpath('normalize-space(//table//tr[8]/td)')
return tree.xpath('normalize-space(//table//tr[9]/td)')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=ymd&date_only:int=1' % foo.getPath(), basic=self.auth)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment