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
Binh
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
Hide 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 @@
...
@@ -3,6 +3,27 @@
(
function
(
window
,
rJS
)
{
(
function
(
window
,
rJS
)
{
"
use strict
"
;
"
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
)
rJS
(
window
)
.
setState
({
.
setState
({
tag
:
'
p
'
tag
:
'
p
'
...
@@ -11,7 +32,7 @@
...
@@ -11,7 +32,7 @@
.
declareMethod
(
'
render
'
,
function
(
options
)
{
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
field_json
=
options
.
field_json
||
{},
var
field_json
=
options
.
field_json
||
{},
state_dict
=
{
state_dict
=
{
value
:
field_json
.
value
||
field_json
.
default
||
""
,
value
:
getNonEmpty
(
field_json
.
value
,
field_json
[
'
default
'
],
""
)
,
item_list
:
JSON
.
stringify
(
field_json
.
items
),
item_list
:
JSON
.
stringify
(
field_json
.
items
),
editable
:
field_json
.
editable
,
editable
:
field_json
.
editable
,
required
:
field_json
.
required
,
required
:
field_json
.
required
,
...
@@ -23,8 +44,8 @@
...
@@ -23,8 +44,8 @@
// as user may have modified the input value
// as user may have modified the input value
render_timestamp
:
new
Date
().
getTime
()
render_timestamp
:
new
Date
().
getTime
()
};
};
// first_item means to select the first item by default on empty value
if
(
(
!
state_dict
.
value
)
&&
(
state_dict
.
first_item
))
{
if
(
isEmpty
(
state_dict
.
value
)
&&
(
state_dict
.
first_item
))
{
state_dict
.
value
=
field_json
.
items
[
0
][
1
];
state_dict
.
value
=
field_json
.
items
[
0
][
1
];
}
}
return
this
.
changeState
(
state_dict
);
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 @@
...
@@ -230,7 +230,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<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>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -248,7 +248,7 @@
...
@@ -248,7 +248,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
151
6786204.34
</float>
<float>
151
7343520.55
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</state>
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multilistfield_js.js
View file @
133b8ed7
...
@@ -3,13 +3,34 @@
...
@@ -3,13 +3,34 @@
(
function
(
window
,
rJS
,
document
,
RSVP
)
{
(
function
(
window
,
rJS
,
document
,
RSVP
)
{
'
use strict
'
;
'
use strict
'
;
function
isEmpty
(
value
)
{
return
(
value
===
undefined
||
value
===
null
||
value
.
length
===
0
);
}
/* Make sure that returned object is an Array instance. */
/* Make sure that returned object is an Array instance. */
function
ensureArray
(
obj
)
{
function
ensureArray
(
obj
)
{
if
(
!
obj
)
{
return
[];
}
if
(
Array
.
isArray
(
obj
))
{
return
obj
;
}
if
(
Array
.
isArray
(
obj
))
{
return
obj
;
}
if
(
isEmpty
(
obj
))
{
return
[];
}
return
[
obj
];
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
)
{
function
appendListField
(
gadget
,
value
,
item_list
)
{
var
div
=
document
.
createElement
(
'
div
'
);
var
div
=
document
.
createElement
(
'
div
'
);
gadget
.
element
.
appendChild
(
div
);
gadget
.
element
.
appendChild
(
div
);
...
@@ -37,10 +58,11 @@
...
@@ -37,10 +58,11 @@
rJS
(
window
)
rJS
(
window
)
.
declareMethod
(
'
render
'
,
function
(
options
)
{
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
field_json
=
options
.
field_json
||
{},
var
field_json
=
options
.
field_json
||
{},
item_list
=
field_json
.
items
,
item_list
=
ensureArray
(
field_json
.
items
)
,
state_dict
=
{
state_dict
=
{
value_list
:
JSON
.
stringify
(
value_list
:
JSON
.
stringify
(
ensureArray
(
field_json
.
value
||
field_json
.
default
)
ensureArray
(
getNonEmpty
(
field_json
.
value
,
field_json
[
'
default
'
],
[]))
),
),
editable
:
field_json
.
editable
,
editable
:
field_json
.
editable
,
required
:
field_json
.
required
,
required
:
field_json
.
required
,
...
@@ -54,6 +76,11 @@
...
@@ -54,6 +76,11 @@
// as user may have modified the input value
// as user may have modified the input value
render_timestamp
:
new
Date
().
getTime
()
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
]
!==
""
))
{
if
((
item_list
.
length
===
0
)
||
(
item_list
[
0
][
0
]
!==
""
))
{
item_list
.
unshift
([
""
,
""
]);
item_list
.
unshift
([
""
,
""
]);
}
}
...
@@ -77,17 +104,13 @@
...
@@ -77,17 +104,13 @@
element
.
removeChild
(
element
.
firstChild
);
element
.
removeChild
(
element
.
firstChild
);
}
}
function
enQueue
()
{
value_list
.
forEach
(
function
(
value
)
{
var
argument_list
=
arguments
;
queue
queue
.
push
(
function
()
{
.
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
;
return
queue
;
})
})
...
@@ -199,4 +222,4 @@
...
@@ -199,4 +222,4 @@
return
true
;
return
true
;
},
{
mutex
:
'
changestate
'
});
},
{
mutex
:
'
changestate
'
});
}(
window
,
rJS
,
document
,
RSVP
));
}(
window
,
rJS
,
document
,
RSVP
));
\ No newline at end of file
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_multilistfield_js.xml
View file @
133b8ed7
...
@@ -230,7 +230,7 @@
...
@@ -230,7 +230,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<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>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -248,7 +248,7 @@
...
@@ -248,7 +248,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
15173
21477.39
</float>
<float>
15173
44745.48
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</state>
...
...
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_html5_select_js.js
View file @
133b8ed7
...
@@ -3,6 +3,27 @@
...
@@ -3,6 +3,27 @@
(
function
(
window
,
rJS
,
RSVP
,
Handlebars
)
{
(
function
(
window
,
rJS
,
RSVP
,
Handlebars
)
{
"
use strict
"
;
"
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?
// How to change html selected option using JavaScript?
// http://stackoverflow.com/a/20662180
// http://stackoverflow.com/a/20662180
...
@@ -32,7 +53,7 @@
...
@@ -32,7 +53,7 @@
.
declareMethod
(
'
render
'
,
function
(
options
)
{
.
declareMethod
(
'
render
'
,
function
(
options
)
{
var
state_dict
=
{
var
state_dict
=
{
value
:
options
.
value
||
""
,
value
:
getNonEmpty
(
options
.
value
,
""
)
,
item_list
:
JSON
.
stringify
(
options
.
item_list
),
item_list
:
JSON
.
stringify
(
options
.
item_list
),
editable
:
options
.
editable
,
editable
:
options
.
editable
,
required
:
options
.
required
,
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 @@
...
@@ -97,12 +97,6 @@
<none/>
<none/>
</value>
</value>
</item>
</item>
<item>
<key>
<string>
subject
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<item>
<key>
<string>
title
</string>
</key>
<key>
<string>
title
</string>
</key>
<value>
<string>
Gadget HTML5 Select JS
</string>
</value>
<value>
<string>
Gadget HTML5 Select JS
</string>
</value>
...
@@ -236,7 +230,7 @@
...
@@ -236,7 +230,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<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>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -254,7 +248,7 @@
...
@@ -254,7 +248,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
151
6785191.79
</float>
<float>
151
7343550.97
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</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