Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ludovic Kiefer
erp5
Commits
133b8ed7
Commit
133b8ed7
authored
Jan 31, 2018
by
Tomáš Peterka
Committed by
Tomáš Peterka
Feb 01, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[renderjs_ui] Allow values which resolves to FALSE to be the default values in *list* fields
parent
32de851f
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
27 deletions
+86
-27
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listfield_js.js
...plateItem/web_page_module/rjs_gadget_erp5_listfield_js.js
+24
-3
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listfield_js.xml
...lateItem/web_page_module/rjs_gadget_erp5_listfield_js.xml
+2
-2
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multilistfield_js.js
...Item/web_page_module/rjs_gadget_erp5_multilistfield_js.js
+34
-11
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multilistfield_js.xml
...tem/web_page_module/rjs_gadget_erp5_multilistfield_js.xml
+2
-2
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_select_js.js
...emplateItem/web_page_module/rjs_gadget_html5_select_js.js
+22
-1
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_select_js.xml
...mplateItem/web_page_module/rjs_gadget_html5_select_js.xml
+2
-8
No files found.
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listfield_js.js
View file @
133b8ed7
...
...
@@ -3,6 +3,27 @@
(
function
(
window
,
rJS
)
{
"
use strict
"
;
function
isEmpty
(
value
)
{
return
(
value
===
undefined
||
value
===
null
||
value
.
length
===
0
);
}
/** More robust way of writing a || b || "" because if b===0 it gets skipped.
*/
function
getNonEmpty
()
{
var
i
;
for
(
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
if
(
!
isEmpty
(
arguments
[
i
]))
{
return
arguments
[
i
];
}
}
if
(
arguments
.
length
===
1
)
{
return
arguments
[
0
];
}
return
arguments
[
arguments
.
length
-
1
];
}
rJS
(
window
)
.
setState
({
tag
:
'
p
'
...
...
@@ -11,7 +32,7 @@
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
field_json
=
options
.
field_json
||
{},
state_dict
=
{
value
:
field_json
.
value
||
field_json
.
default
||
""
,
value
:
getNonEmpty
(
field_json
.
value
,
field_json
[
'
default
'
],
""
)
,
item_list
:
JSON
.
stringify
(
field_json
.
items
),
editable
:
field_json
.
editable
,
required
:
field_json
.
required
,
...
...
@@ -23,8 +44,8 @@
// as user may have modified the input value
render_timestamp
:
new
Date
().
getTime
()
};
if
(
(
!
state_dict
.
value
)
&&
(
state_dict
.
first_item
))
{
// first_item means to select the first item by default on empty value
if
(
isEmpty
(
state_dict
.
value
)
&&
(
state_dict
.
first_item
))
{
state_dict
.
value
=
field_json
.
items
[
0
][
1
];
}
return
this
.
changeState
(
state_dict
);
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_listfield_js.xml
View file @
133b8ed7
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
965.1
659.33258.11707
</string>
</value>
<value>
<string>
965.1
0402.43703.62668
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
151
6786204.34
</float>
<float>
151
7343520.55
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multilistfield_js.js
View file @
133b8ed7
...
...
@@ -3,13 +3,34 @@
(
function
(
window
,
rJS
,
document
,
RSVP
)
{
'
use strict
'
;
function
isEmpty
(
value
)
{
return
(
value
===
undefined
||
value
===
null
||
value
.
length
===
0
);
}
/* Make sure that returned object is an Array instance. */
function
ensureArray
(
obj
)
{
if
(
!
obj
)
{
return
[];
}
if
(
Array
.
isArray
(
obj
))
{
return
obj
;
}
if
(
isEmpty
(
obj
))
{
return
[];
}
return
[
obj
];
}
/** More robust way of writing a || b || "" because if b===0 it gets skipped.
*/
function
getNonEmpty
()
{
var
i
;
for
(
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
if
(
!
isEmpty
(
arguments
[
i
]))
{
return
arguments
[
i
];
}
}
if
(
arguments
.
length
===
1
)
{
return
arguments
[
0
];
}
return
arguments
[
arguments
.
length
-
1
];
}
function
appendListField
(
gadget
,
value
,
item_list
)
{
var
div
=
document
.
createElement
(
'
div
'
);
gadget
.
element
.
appendChild
(
div
);
...
...
@@ -37,10 +58,11 @@
rJS
(
window
)
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
field_json
=
options
.
field_json
||
{},
item_list
=
field_json
.
items
,
item_list
=
ensureArray
(
field_json
.
items
)
,
state_dict
=
{
value_list
:
JSON
.
stringify
(
ensureArray
(
field_json
.
value
||
field_json
.
default
)
ensureArray
(
getNonEmpty
(
field_json
.
value
,
field_json
[
'
default
'
],
[]))
),
editable
:
field_json
.
editable
,
required
:
field_json
.
required
,
...
...
@@ -54,6 +76,11 @@
// as user may have modified the input value
render_timestamp
:
new
Date
().
getTime
()
};
// Items can be simply an array of values. It is a valid input produced
// usually by TALES expression
if
(
item_list
.
length
>
0
&&
!
Array
.
isArray
(
item_list
[
0
]))
{
item_list
=
item_list
.
map
(
function
(
item
)
{
return
[
item
,
item
];
});
}
if
((
item_list
.
length
===
0
)
||
(
item_list
[
0
][
0
]
!==
""
))
{
item_list
.
unshift
([
""
,
""
]);
}
...
...
@@ -77,17 +104,13 @@
element
.
removeChild
(
element
.
firstChild
);
}
function
enQueue
()
{
var
argument_list
=
arguments
;
value_list
.
forEach
(
function
(
value
)
{
queue
.
push
(
function
()
{
return
appendListField
.
apply
(
this
,
argument_list
);
return
appendListField
(
gadget
,
value
,
item_list
);
});
});
}
for
(
i
=
0
;
i
<
value_list
.
length
;
i
+=
1
)
{
enQueue
(
gadget
,
value_list
[
i
],
item_list
);
}
return
queue
;
})
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multilistfield_js.xml
View file @
133b8ed7
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
965.
241.13759.380
5
</string>
</value>
<value>
<string>
965.
10997.12521.6536
5
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
15173
21477.39
</float>
<float>
15173
44745.48
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_select_js.js
View file @
133b8ed7
...
...
@@ -3,6 +3,27 @@
(
function
(
window
,
rJS
,
RSVP
,
Handlebars
)
{
"
use strict
"
;
function
isEmpty
(
value
)
{
return
(
value
===
undefined
||
value
===
null
||
value
.
length
===
0
);
}
/** More robust way of writing a || b || "" because if b===0 it gets skipped.
*/
function
getNonEmpty
()
{
var
i
;
for
(
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
if
(
!
isEmpty
(
arguments
[
i
]))
{
return
arguments
[
i
];
}
}
if
(
arguments
.
length
===
1
)
{
return
arguments
[
0
];
}
return
arguments
[
arguments
.
length
-
1
];
}
// How to change html selected option using JavaScript?
// http://stackoverflow.com/a/20662180
...
...
@@ -32,7 +53,7 @@
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
state_dict
=
{
value
:
options
.
value
||
""
,
value
:
getNonEmpty
(
options
.
value
,
""
)
,
item_list
:
JSON
.
stringify
(
options
.
item_list
),
editable
:
options
.
editable
,
required
:
options
.
required
,
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_select_js.xml
View file @
133b8ed7
...
...
@@ -97,12 +97,6 @@
<none/>
</value>
</item>
<item>
<key>
<string>
subject
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string>
Gadget HTML5 Select JS
</string>
</value>
...
...
@@ -236,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
96
3.62584.36941.22510
</string>
</value>
<value>
<string>
96
5.10402.53372.47291
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -254,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
151
6785191.79
</float>
<float>
151
7343550.97
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment