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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gabriel Monnerat
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
Hide 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 @@
...
@@ -156,7 +156,7 @@
action_doc
=
action_document_list
[
action_key
];
action_doc
=
action_document_list
[
action_key
];
if
(
app_actions
.
includes
(
action_doc
.
reference
))
{
if
(
app_actions
.
includes
(
action_doc
.
reference
))
{
action_settings
=
{
action_settings
=
{
page
:
undefined
,
page
:
"
handle_action
"
,
jio_key
:
jio_key
,
jio_key
:
jio_key
,
title
:
action_doc
.
title
,
title
:
action_doc
.
title
,
action
:
action_doc
.
reference
,
action
:
action_doc
.
reference
,
...
@@ -165,11 +165,12 @@
...
@@ -165,11 +165,12 @@
parent_portal_type
:
portal_type
parent_portal_type
:
portal_type
};
};
if
(
view_categorie_list
.
includes
(
action_settings
.
action_type
))
{
if
(
view_categorie_list
.
includes
(
action_settings
.
action_type
))
{
action_settings
.
page
=
"
ojs_local_controller
"
;
if
(
app_view
===
action_settings
.
action
)
{
action_settings
.
page
=
"
ojs_local_controller
"
;
}
action_info_dict
.
view_list
[
action_settings
.
action
]
=
action_info_dict
.
view_list
[
action_settings
.
action
]
=
action_settings
;
action_settings
;
}
else
{
}
else
{
action_settings
.
page
=
"
handle_action
"
;
action_info_dict
.
action_list
[
action_settings
.
action
]
=
action_info_dict
.
action_list
[
action_settings
.
action
]
=
action_settings
;
action_settings
;
}
}
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_common_util_js.xml
View file @
35809f62
...
@@ -275,7 +275,7 @@
...
@@ -275,7 +275,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<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>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -293,7 +293,7 @@
...
@@ -293,7 +293,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
1
575473624.38
</float>
<float>
1
601668696.35
</float>
<string>
UTC
</string>
<string>
UTC
</string>
</tuple>
</tuple>
</state>
</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 */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 80 */
(
function
(
window
,
document
,
rJS
,
RSVP
)
{
(
function
(
window
,
document
,
rJS
,
RSVP
,
console
)
{
"
use strict
"
;
"
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
)
rJS
(
window
)
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Acquired methods
// Acquired methods
...
@@ -12,6 +49,7 @@
...
@@ -12,6 +49,7 @@
.
declareAcquiredMethod
(
"
notifySubmitted
"
,
'
notifySubmitted
'
)
.
declareAcquiredMethod
(
"
notifySubmitted
"
,
'
notifySubmitted
'
)
.
declareAcquiredMethod
(
"
notifySubmitting
"
,
"
notifySubmitting
"
)
.
declareAcquiredMethod
(
"
notifySubmitting
"
,
"
notifySubmitting
"
)
.
declareAcquiredMethod
(
"
redirect
"
,
"
redirect
"
)
.
declareAcquiredMethod
(
"
redirect
"
,
"
redirect
"
)
.
declareAcquiredMethod
(
"
updateHeader
"
,
"
updateHeader
"
)
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// declared methods
// declared methods
...
@@ -34,7 +72,11 @@
...
@@ -34,7 +72,11 @@
})
})
.
declareMethod
(
"
render
"
,
function
(
options
)
{
.
declareMethod
(
"
render
"
,
function
(
options
)
{
var
gadget
=
this
,
action_reference
;
var
gadget
=
this
,
action_reference
,
form_definition
,
state_options
,
action_gadget
;
return
RSVP
.
Queue
()
return
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
return
RSVP
.
all
([
return
RSVP
.
all
([
...
@@ -44,62 +86,64 @@
...
@@ -44,62 +86,64 @@
]);
]);
})
})
.
push
(
function
(
result
)
{
.
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
)
{
if
(
result
[
1
]
!==
undefined
)
{
options
.
parent_relative_url
=
result
[
1
];
options
.
parent_relative_url
=
result
[
1
];
}
}
action_reference
=
result
[
2
];
action_reference
=
result
[
2
];
return
gadget
.
getActionFormDefinition
(
action_reference
);
return
gadget
.
getActionFormDefinition
(
action_reference
);
})
})
.
push
(
function
(
form_definition
)
{
.
push
(
function
(
result
)
{
var
fragment
=
document
.
createElement
(
'
div
'
),
form_definition
=
result
;
action_gadget_url
,
var
form_type
=
form_definition
.
form_type
,
form_type
=
form_definition
.
form_type
,
child_gadget_url
=
form_definition
.
child_gadget_url
,
child_gadget_url
=
form_definition
.
child_gadget_url
,
//an action form must have a GadgetField called
//action validity determined by gadget_field_action_js_script field
//"gadget_field_new_action_js_script"
valid_action
=
form_definition
.
fields_raw_properties
//this gadget will point the custom action gadget
.
hasOwnProperty
(
"
gadget_field_action_js_script
"
);
valid_action
=
form_definition
.
action_type
===
if
(
!
valid_action
)
{
"
object_jio_js_script
"
&&
form_definition
.
fields_raw_properties
return
gadget
.
notifySubmitted
({
.
hasOwnProperty
(
"
gadget_field_action_js_script
"
),
message
:
'
Could not perform this action: configuration error
'
,
state_options
=
{
status
:
'
fail
'
doc
:
{},
action_options
:
options
,
child_gadget_url
:
child_gadget_url
,
form_type
:
form_type
,
form_definition
:
form_definition
,
view
:
action_reference
,
valid_action
:
valid_action
};
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
})
})
.
push
(
function
(
action_gadget
)
{
.
push
(
function
(
result
)
{
options
.
form_definition
=
form_definition
;
return
gadget
.
redirect
({
return
action_gadget
.
preRenderDocument
(
options
);
'
command
'
:
'
display
'
})
.
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
"
});
}
throw
error
;
});
});
});
}
state_options
=
{
doc
:
{},
action_options
:
options
,
child_gadget_url
:
child_gadget_url
,
form_type
:
form_type
,
form_definition
:
form_definition
,
view
:
action_reference
,
valid_action
:
valid_action
,
action_gadget_url
:
form_definition
.
fields_raw_properties
.
gadget_field_action_js_script
.
values
.
gadget_url
};
delete
form_definition
.
fields_raw_properties
.
gadget_field_action_js_script
;
return
declareActionGadget
(
gadget
,
state_options
);
})
.
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
)
{
if
(
doc
.
header_dict
)
{
state_options
.
header_dict
=
doc
.
header_dict
;
delete
doc
.
header_dict
;
}
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
);
return
gadget
.
changeState
(
state_options
);
});
});
...
@@ -116,6 +160,11 @@
...
@@ -116,6 +160,11 @@
{
element
:
fragment
,
scope
:
'
fg
'
})
{
element
:
fragment
,
scope
:
'
fg
'
})
.
push
(
function
(
form_view_gadget
)
{
.
push
(
function
(
form_view_gadget
)
{
return
form_view_gadget
.
render
(
gadget
.
state
);
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 @@
...
@@ -128,40 +177,15 @@
.
allowPublicAcquisition
(
'
submitContent
'
,
function
(
options
)
{
.
allowPublicAcquisition
(
'
submitContent
'
,
function
(
options
)
{
var
gadget
=
this
,
var
gadget
=
this
,
//target_url = options[1],
content_dict
=
options
[
2
];
content_dict
=
options
[
2
],
fragment
=
document
.
createElement
(
'
div
'
),
submit_dict
;
if
(
gadget
.
state
.
valid_action
)
{
if
(
gadget
.
state
.
valid_action
)
{
return
gadget
.
notifySubmitting
()
return
gadget
.
notifySubmitting
()
.
push
(
function
()
{
.
push
(
function
()
{
gadget
.
element
.
appendChild
(
fragment
);
return
declareActionGadget
(
gadget
,
gadget
.
state
);
return
gadget
.
declareGadget
(
gadget
.
state
.
action_gadget_url
,
{
scope
:
"
action_field
"
,
element
:
fragment
});
})
})
.
push
(
function
(
action_gadget
)
{
.
push
(
function
(
action_gadget
)
{
return
action_gadget
.
handleSubmit
(
content_dict
,
gadget
.
state
);
return
submitAction
(
gadget
,
action_gadget
,
})
gadget
.
state
,
content_dict
);
.
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
gadget
.
notifySubmitted
(
return
gadget
.
notifySubmitted
(
...
@@ -169,4 +193,4 @@
...
@@ -169,4 +193,4 @@
status
:
'
fail
'
});
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 @@
...
@@ -275,7 +275,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
serial
</string>
</key>
<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>
<item>
<item>
<key>
<string>
state
</string>
</key>
<key>
<string>
state
</string>
</key>
...
@@ -293,7 +293,7 @@
...
@@ -293,7 +293,7 @@
</tuple>
</tuple>
<state>
<state>
<tuple>
<tuple>
<float>
1
599861051.5
5
</float>
<float>
1
601668958.2
5
</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