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
Labels
Merge Requests
144
Merge Requests
144
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
2206f4f8
Commit
2206f4f8
authored
Mar 26, 2019
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_officejs: code cleanup
parent
982396a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
92 deletions
+102
-92
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_controller_page_controller_js.js
...e_module/gadget_officejs_controller_page_controller_js.js
+38
-36
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_controller_page_controller_js.xml
..._module/gadget_officejs_controller_page_controller_js.xml
+2
-2
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.js
...athTemplateItem/web_page_module/gadget_officejs_jio_js.js
+60
-52
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.xml
...thTemplateItem/web_page_module/gadget_officejs_jio_js.xml
+2
-2
No files found.
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_controller_page_controller_js.js
View file @
2206f4f8
...
...
@@ -4,32 +4,33 @@
"
use strict
"
;
function
renderField
(
field_id
,
field_definition
,
document
)
{
var
result
=
{};
for
(
var
key
in
field_definition
.
values
)
{
// order to get the final value (based on Field.py get_value)
// 1.tales, 2.override, 3.form-def-value, 4.context-default
var
raw_value
=
field_definition
.
values
[
key
],
tales_expr
=
field_definition
.
tales
[
key
],
override
=
field_definition
.
overrides
[
key
],
final_value
;
final_value
=
undefined
;
if
(
tales_expr
!==
undefined
&&
tales_expr
!==
null
&&
tales_expr
!==
''
)
{
try
{
throw
"
error
"
;
//final_value = eval(tales_expr);
}
catch
(
e
)
{}
// TALES expressions are usually python code, so for now ignore
}
if
(
final_value
===
undefined
)
{
if
(
override
!==
undefined
&&
override
!==
null
&&
override
!==
''
)
{
final_value
=
override
;
}
else
if
(
raw_value
!==
undefined
&&
raw_value
!==
null
&&
raw_value
!==
''
)
{
final_value
=
raw_value
;
}
else
if
(
document
&&
document
.
hasOwnProperty
(
key
))
{
final_value
=
document
[
key
];
var
key
,
raw_value
,
tales_expr
,
override
,
final_value
,
result
=
{};
for
(
key
in
field_definition
.
values
)
{
if
(
field_definition
.
values
.
hasOwnProperty
(
key
))
{
// order to get the final value (based on Field.py get_value)
// 1.tales, 2.override, 3.form-def-value, 4.context-default
raw_value
=
field_definition
.
values
[
key
];
tales_expr
=
field_definition
.
tales
[
key
];
override
=
field_definition
.
overrides
[
key
];
final_value
=
undefined
;
if
(
tales_expr
!==
undefined
&&
tales_expr
!==
null
&&
tales_expr
!==
''
)
{
try
{
throw
"
error
"
;
//final_value = eval(tales_expr);
}
catch
(
ignore
)
{}
// TALES expressions are usually python code, so for now ignore
}
if
(
final_value
===
undefined
)
{
if
(
override
!==
undefined
&&
override
!==
null
&&
override
!==
''
)
{
final_value
=
override
;
}
else
if
(
raw_value
!==
undefined
&&
raw_value
!==
null
&&
raw_value
!==
''
)
{
final_value
=
raw_value
;
}
else
if
(
document
&&
document
.
hasOwnProperty
(
key
))
{
final_value
=
document
[
key
];
}
}
if
(
final_value
!==
undefined
&&
final_value
!==
null
&&
final_value
!==
''
)
{
result
[
key
]
=
final_value
;
}
}
if
(
final_value
!==
undefined
&&
final_value
!==
null
&&
final_value
!==
''
)
{
result
[
key
]
=
final_value
;
}
}
result
.
type
=
field_definition
.
type
;
...
...
@@ -59,8 +60,8 @@
.
declareMethod
(
"
getFormDefinition
"
,
function
(
portal_type
)
{
var
gadget
=
this
,
parent
=
"
portal_types/
"
+
portal_type
,
query
=
'
portal_type: "Action Information" AND reference: "jio_view" AND parent_relative_url: "
'
+
parent
+
'
"
'
;
parent
=
"
portal_types/
"
+
portal_type
,
query
=
'
portal_type: "Action Information" AND reference: "jio_view" AND parent_relative_url: "
'
+
parent
+
'
"
'
;
return
gadget
.
jio_allDocs
({
query
:
query
})
.
push
(
function
(
data
)
{
if
(
data
.
data
.
rows
.
length
===
0
)
{
...
...
@@ -77,14 +78,15 @@
})
.
declareMethod
(
"
renderForm
"
,
function
(
form_definition
,
document
)
{
var
raw_properties
=
form_definition
.
fields_raw_properties
;
var
form_json
=
{
erp5_document
:
{
"
_embedded
"
:
{
"
_view
"
:
{}},
"
_links
"
:
{}
},
form_definition
:
form_definition
},
i
,
j
,
fields
,
field_info
,
my_element
,
element_id
;
var
i
,
j
,
fields
,
field_info
,
my_element
,
element_id
,
rendered_field
,
raw_properties
=
form_definition
.
fields_raw_properties
,
form_json
=
{
erp5_document
:
{
"
_embedded
"
:
{
"
_view
"
:
{}},
"
_links
"
:
{}
},
form_definition
:
form_definition
};
for
(
i
=
0
;
i
<
form_definition
.
group_list
.
length
;
i
+=
1
)
{
fields
=
form_definition
.
group_list
[
i
][
1
];
for
(
j
=
0
;
j
<
fields
.
length
;
j
+=
1
)
{
...
...
@@ -98,7 +100,7 @@
}
if
(
raw_properties
.
hasOwnProperty
(
my_element
))
{
field_info
=
raw_properties
[
my_element
];
var
rendered_field
=
renderField
(
element_id
,
field_info
,
document
);
rendered_field
=
renderField
(
element_id
,
field_info
,
document
);
form_json
.
erp5_document
.
_embedded
.
_view
[
my_element
]
=
rendered_field
;
}
}
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_controller_page_controller_js.xml
View file @
2206f4f8
...
...
@@ -225,7 +225,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
974.3
8878.8625.14933
</string>
</value>
<value>
<string>
974.3
9977.38000.44305
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>
1553
542945.18
</float>
<float>
1553
613284.01
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.js
View file @
2206f4f8
/*global window, rJS, jIO, FormData, UriTemplate */
/*jslint indent: 2, maxerr: 3 */
(
function
(
window
,
rJS
,
jIO
,
RSVP
,
document
,
URLSearchParams
)
{
(
function
(
window
,
rJS
,
jIO
,
RSVP
,
document
,
URLSearchParams
,
console
)
{
"
use strict
"
;
// jIO call wrapper for redirection to authentication page if needed
...
...
@@ -61,24 +61,28 @@
}
function
processHateoasDict
(
raw_dict
)
{
var
return_dict
=
{};
var
r
aw_fields
,
type
,
parent
,
field_key
,
field_id
,
r
eturn_dict
=
{};
try
{
var
raw_fields
=
raw_dict
.
_embedded
.
_view
,
type
=
raw_dict
.
_links
.
type
.
name
,
parent
=
raw_dict
.
_links
.
parent
.
name
;
/*jslint nomen: true*/
raw_fields
=
raw_dict
.
_embedded
.
_view
;
type
=
raw_dict
.
_links
.
type
.
name
;
parent
=
raw_dict
.
_links
.
parent
.
name
;
/*jslint nomen: false*/
return_dict
.
parent_relative_url
=
"
portal_types/
"
+
parent
;
return_dict
.
portal_type
=
type
;
for
(
var
field_key
in
raw_fields
)
{
var
field_id
=
""
;
if
(
raw_fields
[
field_key
][
"
default
"
]
!==
undefined
&&
raw_fields
[
field_key
][
"
default
"
]
!==
""
)
{
if
(
field_key
.
startsWith
(
"
my_
"
))
{
field_id
=
field_key
.
replace
(
"
my_
"
,
""
);
}
else
if
(
field_key
.
startsWith
(
"
your_
"
))
{
field_id
=
field_key
.
replace
(
"
your_
"
,
""
);
}
else
{
field_id
=
field_key
;
for
(
field_key
in
raw_fields
)
{
if
(
raw_fields
.
hasOwnProperty
(
field_key
))
{
field_id
=
""
;
if
(
raw_fields
[
field_key
][
"
default
"
]
!==
undefined
&&
raw_fields
[
field_key
][
"
default
"
]
!==
""
)
{
if
(
field_key
.
startsWith
(
"
my_
"
))
{
field_id
=
field_key
.
replace
(
"
my_
"
,
""
);
}
else
if
(
field_key
.
startsWith
(
"
your_
"
))
{
field_id
=
field_key
.
replace
(
"
your_
"
,
""
);
}
else
{
field_id
=
field_key
;
}
return_dict
[
field_id
]
=
raw_fields
[
field_key
][
"
default
"
];
}
return_dict
[
field_id
]
=
raw_fields
[
field_key
][
"
default
"
];
}
}
}
catch
(
e
)
{
...
...
@@ -102,9 +106,8 @@
.
declareAcquiredMethod
(
'
getUrlFor
'
,
'
getUrlFor
'
)
.
declareMethod
(
'
createJio
'
,
function
(
jio_options
)
{
var
gadget
=
this
,
var
appcache_storage
,
origin_url
=
window
.
location
.
href
,
prefix
=
"
./
"
,
hateoas_script
=
"
hateoas/ERP5Document_getHateoas
"
,
// TODO manifest should come from gadget.props.cache_file -add script in html body
manifest
=
"
gadget_officejs_discussion_tool.configuration
"
,
...
...
@@ -133,7 +136,7 @@
type
:
"
appcache
"
,
manifest
:
manifest
}
},
appcache_storage
,
},
sync_flag
=
"
appcache-stored
"
,
configuration_ids_dict
=
{};
if
(
jio_options
===
undefined
)
{
...
...
@@ -160,52 +163,57 @@
// TODO: find a better flag for this?
return
appcache_storage
.
get
(
sync_flag
)
.
push
(
undefined
,
function
(
error
)
{
return
appcache_storage
.
repair
()
.
push
(
function
()
{
return
appcache_storage
.
allAttachments
(
origin_url
)
.
push
(
function
(
attachment_dict
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
promise_list
=
[],
i
=
0
;
for
(
var
id
in
attachment_dict
)
{
if
(
error
&&
String
(
error
.
status_code
)
!==
"
404
"
)
{
throw
error
;
}
return
appcache_storage
.
repair
()
.
push
(
function
()
{
return
appcache_storage
.
allAttachments
(
origin_url
)
.
push
(
function
(
attachment_dict
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
id
,
promise_list
=
[],
i
=
0
;
for
(
id
in
attachment_dict
)
{
if
(
attachment_dict
.
hasOwnProperty
(
id
))
{
if
(
id
.
indexOf
(
hateoas_script
)
===
-
1
)
{
promise_list
.
push
(
appcache_storage
.
getAttachment
(
origin_url
,
id
));
}
else
{
promise_list
.
push
(
appcache_storage
.
getAttachment
(
origin_url
,
id
,
{
"
format
"
:
"
json
"
}));
}
configuration_ids_dict
[
""
+
i
]
=
id
;
configuration_ids_dict
[
String
(
i
)
]
=
id
;
i
+=
1
;
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
(
content_list
)
{
var
promise_list
=
[];
for
(
var
i
=
0
;
i
<
content_list
.
length
;
i
+=
1
)
{
var
id
=
configuration_ids_dict
[
""
+
i
],
parser
=
document
.
createElement
(
'
a
'
);
parser
.
href
=
id
;
var
urlParams
=
new
URLSearchParams
(
parser
.
search
);
id
=
urlParams
.
get
(
"
relative_url
"
);
if
(
id
===
null
)
{
id
=
configuration_ids_dict
[
""
+
i
];
}
var
content
=
processHateoasDict
(
content_list
[
i
]);
promise_list
.
push
(
appcache_storage
.
put
(
id
,
content
));
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
()
{
return
appcache_storage
.
put
(
sync_flag
,
{})
.
push
(
undefined
);
});
});
},
function
(
error
)
{
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
(
content_list
)
{
var
i
,
id
,
parser
,
urlParams
,
content
,
promise_list
=
[];
for
(
i
=
0
;
i
<
content_list
.
length
;
i
+=
1
)
{
id
=
configuration_ids_dict
[
String
(
i
)];
parser
=
document
.
createElement
(
'
a
'
);
parser
.
href
=
id
;
urlParams
=
new
URLSearchParams
(
parser
.
search
);
id
=
urlParams
.
get
(
"
relative_url
"
);
if
(
id
===
null
)
{
id
=
configuration_ids_dict
[
String
(
i
)];
}
content
=
processHateoasDict
(
content_list
[
i
]);
promise_list
.
push
(
appcache_storage
.
put
(
id
,
content
));
}
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
()
{
return
appcache_storage
.
put
(
sync_flag
,
{})
.
push
(
undefined
);
});
});
},
function
(
error
)
{
console
.
log
(
"
Error while appcache-local storage synchronization
"
);
if
(
error
&&
error
.
currentTarget
&&
error
.
currentTarget
.
status
==
"
401
"
)
{
if
(
error
&&
error
.
currentTarget
&&
error
.
currentTarget
.
status
==
=
"
401
"
)
{
console
.
log
(
"
Unauthorized access to storage, sync cancelled
"
);
return
;
}
throw
error
;
});
});
});
});
})
.
declareMethod
(
'
allDocs
'
,
function
()
{
...
...
@@ -239,4 +247,4 @@
return
wrapJioCall
(
this
,
'
repair
'
,
arguments
);
});
}(
window
,
rJS
,
jIO
,
RSVP
,
document
,
URLSearchParams
));
\ No newline at end of file
}(
window
,
rJS
,
jIO
,
RSVP
,
document
,
URLSearchParams
,
console
));
\ No newline at end of file
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_jio_js.xml
View file @
2206f4f8
...
...
@@ -234,7 +234,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
974.
38585.37530.1638
4
</string>
</value>
<value>
<string>
974.
40019.39794.6205
4
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>
1553
525541.12
</float>
<float>
1553
611478.88
</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