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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eteri
erp5
Commits
35809f62
Commit
35809f62
authored
Sep 28, 2020
by
Roque
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_officejs: refactor handle custom actions gadget
parent
c4026c75
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
87 deletions
+112
-87
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_common_util_js.js
...ateItem/web_page_module/gadget_officejs_common_util_js.js
+4
-3
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_common_util_js.xml
...teItem/web_page_module/gadget_officejs_common_util_js.xml
+2
-2
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_page_handle_action_js.js
.../web_page_module/gadget_officejs_page_handle_action_js.js
+104
-80
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_page_handle_action_js.xml
...web_page_module/gadget_officejs_page_handle_action_js.xml
+2
-2
No files found.
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_common_util_js.js
View file @
35809f62
...
...
@@ -156,7 +156,7 @@
action_doc
=
action_document_list
[
action_key
];
if
(
app_actions
.
includes
(
action_doc
.
reference
))
{
action_settings
=
{
page
:
undefined
,
page
:
"
handle_action
"
,
jio_key
:
jio_key
,
title
:
action_doc
.
title
,
action
:
action_doc
.
reference
,
...
...
@@ -165,11 +165,12 @@
parent_portal_type
:
portal_type
};
if
(
view_categorie_list
.
includes
(
action_settings
.
action_type
))
{
if
(
app_view
===
action_settings
.
action
)
{
action_settings
.
page
=
"
ojs_local_controller
"
;
}
action_info_dict
.
view_list
[
action_settings
.
action
]
=
action_settings
;
}
else
{
action_settings
.
page
=
"
handle_action
"
;
action_info_dict
.
action_list
[
action_settings
.
action
]
=
action_settings
;
}
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_common_util_js.xml
View file @
35809f62
...
...
@@ -275,7 +275,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
98
0.16928.56199.10649
</string>
</value>
<value>
<string>
98
7.1958.49484.49100
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -293,7 +293,7 @@
</tuple>
<state>
<tuple>
<float>
1
575473624.38
</float>
<float>
1
601668696.35
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_page_handle_action_js.js
View file @
35809f62
/*global window, document, rJS, RSVP */
/*global window, document, rJS, RSVP
, console
*/
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(
function
(
window
,
document
,
rJS
,
RSVP
)
{
(
function
(
window
,
document
,
rJS
,
RSVP
,
console
)
{
"
use strict
"
;
function
declareActionGadget
(
gadget
,
state_options
)
{
var
fragment
=
document
.
createElement
(
'
div
'
);
gadget
.
element
.
appendChild
(
fragment
);
return
gadget
.
declareGadget
(
state_options
.
action_gadget_url
,
{
scope
:
"
action_field
"
,
element
:
fragment
});
}
function
submitAction
(
gadget
,
action_gadget
,
state_options
,
content_dict
)
{
var
submit_dict
;
//handleSubmit() may return dictionary entries with
//notification messages or redirect options
state_options
.
gadget
=
gadget
;
return
action_gadget
.
handleSubmit
(
content_dict
,
state_options
)
.
push
(
function
(
result
)
{
submit_dict
=
result
;
if
(
submit_dict
.
notify
)
{
return
gadget
.
notifySubmitted
(
submit_dict
.
notify
);
}
})
.
push
(
function
()
{
if
(
submit_dict
.
redirect
)
{
return
gadget
.
redirect
(
submit_dict
.
redirect
);
}
},
function
(
error
)
{
if
(
!
(
error
instanceof
RSVP
.
CancellationError
))
{
console
.
log
(
"
Action error:
"
,
error
);
return
gadget
.
notifySubmitted
({
message
:
"
Action Failed
"
,
status
:
"
error
"
});
}
throw
error
;
});
}
rJS
(
window
)
/////////////////////////////////////////////////////////////////
// Acquired methods
...
...
@@ -12,6 +49,7 @@
.
declareAcquiredMethod
(
"
notifySubmitted
"
,
'
notifySubmitted
'
)
.
declareAcquiredMethod
(
"
notifySubmitting
"
,
"
notifySubmitting
"
)
.
declareAcquiredMethod
(
"
redirect
"
,
"
redirect
"
)
.
declareAcquiredMethod
(
"
updateHeader
"
,
"
updateHeader
"
)
/////////////////////////////////////////////////////////////////
// declared methods
...
...
@@ -34,7 +72,11 @@
})
.
declareMethod
(
"
render
"
,
function
(
options
)
{
var
gadget
=
this
,
action_reference
;
var
gadget
=
this
,
action_reference
,
form_definition
,
state_options
,
action_gadget
;
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
...
...
@@ -44,24 +86,33 @@
]);
})
.
push
(
function
(
result
)
{
if
(
result
[
0
]
!==
undefined
)
{
options
.
portal_type
=
result
[
0
];
}
if
(
result
[
0
]
!==
undefined
)
{
options
.
portal_type
=
result
[
0
];
}
if
(
result
[
1
]
!==
undefined
)
{
options
.
parent_relative_url
=
result
[
1
];
}
action_reference
=
result
[
2
];
return
gadget
.
getActionFormDefinition
(
action_reference
);
})
.
push
(
function
(
form_definition
)
{
var
fragment
=
document
.
createElement
(
'
div
'
),
action_gadget_url
,
form_type
=
form_definition
.
form_type
,
.
push
(
function
(
result
)
{
form_definition
=
result
;
var
form_type
=
form_definition
.
form_type
,
child_gadget_url
=
form_definition
.
child_gadget_url
,
//an action form must have a GadgetField called
//"gadget_field_new_action_js_script"
//this gadget will point the custom action gadget
valid_action
=
form_definition
.
action_type
===
"
object_jio_js_script
"
&&
form_definition
.
fields_raw_properties
.
hasOwnProperty
(
"
gadget_field_action_js_script
"
),
//action validity determined by gadget_field_action_js_script field
valid_action
=
form_definition
.
fields_raw_properties
.
hasOwnProperty
(
"
gadget_field_action_js_script
"
);
if
(
!
valid_action
)
{
return
gadget
.
notifySubmitted
({
message
:
'
Could not perform this action: configuration error
'
,
status
:
'
fail
'
})
.
push
(
function
(
result
)
{
return
gadget
.
redirect
({
'
command
'
:
'
display
'
});
});
}
state_options
=
{
doc
:
{},
action_options
:
options
,
...
...
@@ -69,37 +120,30 @@
form_type
:
form_type
,
form_definition
:
form_definition
,
view
:
action_reference
,
valid_action
:
valid_action
valid_action
:
valid_action
,
action_gadget_url
:
form_definition
.
fields_raw_properties
.
gadget_field_action_js_script
.
values
.
gadget_url
};
if
(
valid_action
)
{
action_gadget_url
=
form_definition
.
fields_raw_properties
.
gadget_field_action_js_script
.
values
.
gadget_url
;
// as custom gadget render is being done here
// avoid to child gadget to render it
delete
form_definition
.
fields_raw_properties
.
gadget_field_action_js_script
;
gadget
.
element
.
appendChild
(
fragment
);
return
gadget
.
declareGadget
(
action_gadget_url
,
{
scope
:
"
action_field
"
,
element
:
fragment
return
declareActionGadget
(
gadget
,
state_options
);
})
.
push
(
function
(
action_gadget
)
{
.
push
(
function
(
result
)
{
action_gadget
=
result
;
options
.
form_definition
=
form_definition
;
//preRenderDocument() may return a document dict with fields to be
//rendered in the action form, or configurations like skip_action_form
return
action_gadget
.
preRenderDocument
(
options
);
})
.
push
(
function
(
doc
)
{
state_options
.
doc
=
doc
;
state_options
.
action_gadget_url
=
action_gadget_url
;
return
gadget
.
changeState
(
state_options
);
},
function
(
error
)
{
if
(
error
.
status
===
404
)
{
return
gadget
.
notifySubmitted
({
message
:
"
Error in action
"
,
status
:
"
error
"
});
if
(
doc
.
header_dict
)
{
state_options
.
header_dict
=
doc
.
header_dict
;
delete
doc
.
header_dict
;
}
throw
error
;
});
state_options
.
doc
=
doc
;
if
(
doc
.
skip_action_form
)
{
delete
state_options
.
doc
.
skip_action_form
;
return
submitAction
(
gadget
,
action_gadget
,
state_options
,
{});
}
return
gadget
.
changeState
(
state_options
);
});
...
...
@@ -116,6 +160,11 @@
{
element
:
fragment
,
scope
:
'
fg
'
})
.
push
(
function
(
form_view_gadget
)
{
return
form_view_gadget
.
render
(
gadget
.
state
);
})
.
push
(
function
()
{
if
(
gadget
.
state
.
header_dict
)
{
return
gadget
.
updateHeader
(
gadget
.
state
.
header_dict
);
}
});
})
...
...
@@ -128,40 +177,15 @@
.
allowPublicAcquisition
(
'
submitContent
'
,
function
(
options
)
{
var
gadget
=
this
,
//target_url = options[1],
content_dict
=
options
[
2
],
fragment
=
document
.
createElement
(
'
div
'
),
submit_dict
;
content_dict
=
options
[
2
];
if
(
gadget
.
state
.
valid_action
)
{
return
gadget
.
notifySubmitting
()
.
push
(
function
()
{
gadget
.
element
.
appendChild
(
fragment
);
return
gadget
.
declareGadget
(
gadget
.
state
.
action_gadget_url
,
{
scope
:
"
action_field
"
,
element
:
fragment
});
return
declareActionGadget
(
gadget
,
gadget
.
state
);
})
.
push
(
function
(
action_gadget
)
{
return
action_gadget
.
handleSubmit
(
content_dict
,
gadget
.
state
);
})
.
push
(
function
(
submit_result
)
{
submit_dict
=
submit_result
;
//submit_dict must contain:
//notify: options_dict for notifySubmitted
//redirect: options_dict for redirect
return
gadget
.
notifySubmitted
(
submit_dict
.
notify
);
})
.
push
(
function
()
{
return
gadget
.
redirect
(
submit_dict
.
redirect
);
},
function
(
error
)
{
if
(
!
(
error
instanceof
RSVP
.
CancellationError
))
{
console
.
log
(
"
Action error:
"
,
error
);
return
gadget
.
notifySubmitted
({
message
:
"
Action Failed
"
,
status
:
"
error
"
});
}
throw
error
;
return
submitAction
(
gadget
,
action_gadget
,
gadget
.
state
,
content_dict
);
});
}
return
gadget
.
notifySubmitted
(
...
...
@@ -169,4 +193,4 @@
status
:
'
fail
'
});
});
}(
window
,
document
,
rJS
,
RSVP
));
}(
window
,
document
,
rJS
,
RSVP
,
console
));
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_page_handle_action_js.xml
View file @
35809f62
...
...
@@ -275,7 +275,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
98
6.35897.25368.15923
</string>
</value>
<value>
<string>
98
7.1942.40980.22510
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -293,7 +293,7 @@
</tuple>
<state>
<tuple>
<float>
1
599861051.5
5
</float>
<float>
1
601668958.2
5
</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