Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
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
nexedi
converse.js
Commits
2a62e9dc
Commit
2a62e9dc
authored
May 14, 2020
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ad-hoc: Handle errors when fetching commands for an entity
parent
ef66f2e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
7 deletions
+32
-7
src/components/adhoc-commands.js
src/components/adhoc-commands.js
+32
-7
No files found.
src/components/adhoc-commands.js
View file @
2a62e9dc
import
"
./autocomplete.js
"
import
"
./autocomplete.js
"
import
{
CustomElement
}
from
'
./element.js
'
;
import
{
CustomElement
}
from
'
./element.js
'
;
import
{
__
}
from
'
@converse/headless/i18n
'
;
import
{
__
}
from
'
@converse/headless/i18n
'
;
import
{
api
}
from
"
@converse/headless/converse-core
"
;
import
{
api
,
converse
}
from
"
@converse/headless/converse-core
"
;
import
{
converse
}
from
'
@converse/headless/converse-core
'
;
import
{
html
}
from
"
lit-html
"
;
import
{
html
}
from
"
lit-html
"
;
import
{
unsafeHTML
}
from
'
lit-html/directives/unsafe-html.js
'
;
import
{
unsafeHTML
}
from
'
lit-html/directives/unsafe-html.js
'
;
import
log
from
"
@converse/headless/log
"
;
import
log
from
"
@converse/headless/log
"
;
...
@@ -64,6 +63,7 @@ async function getAutoCompleteList () {
...
@@ -64,6 +63,7 @@ async function getAutoCompleteList () {
}
}
const
tpl_adhoc
=
(
o
)
=>
html
`
const
tpl_adhoc
=
(
o
)
=>
html
`
${
o
.
alert
?
html
`<div class="alert alert-
${
o
.
alert_type
}
" role="alert">
${
o
.
alert
}
</div>`
:
''
}
<form class="converse-form" @submit=
${
o
.
fetchCommands
}
>
<form class="converse-form" @submit=
${
o
.
fetchCommands
}
>
<fieldset class="form-group">
<fieldset class="form-group">
<label>
<label>
...
@@ -126,9 +126,11 @@ export class AdHocCommands extends CustomElement {
...
@@ -126,9 +126,11 @@ export class AdHocCommands extends CustomElement {
static
get
properties
()
{
static
get
properties
()
{
return
{
return
{
'
view
'
:
{
type
:
String
},
'
alert
'
:
{
type
:
String
},
'
alert_type
'
:
{
type
:
String
},
'
nonce
'
:
{
type
:
String
},
// Used to force re-rendering
'
showform
'
:
{
type
:
String
},
'
showform
'
:
{
type
:
String
},
'
nonce
'
:
{
type
:
String
}
// Used to force re-rendering
'
view
'
:
{
type
:
String
},
}
}
}
}
...
@@ -141,6 +143,8 @@ export class AdHocCommands extends CustomElement {
...
@@ -141,6 +143,8 @@ export class AdHocCommands extends CustomElement {
render
()
{
render
()
{
return
tpl_adhoc
({
return
tpl_adhoc
({
'
alert
'
:
this
.
alert
,
'
alert_type
'
:
this
.
alert_type
,
'
commands
'
:
this
.
commands
,
'
commands
'
:
this
.
commands
,
'
fetchCommands
'
:
ev
=>
this
.
fetchCommands
(
ev
),
'
fetchCommands
'
:
ev
=>
this
.
fetchCommands
(
ev
),
'
hideCommandForm
'
:
ev
=>
this
.
hideCommandForm
(
ev
),
'
hideCommandForm
'
:
ev
=>
this
.
hideCommandForm
(
ev
),
...
@@ -153,11 +157,32 @@ export class AdHocCommands extends CustomElement {
...
@@ -153,11 +157,32 @@ export class AdHocCommands extends CustomElement {
async
fetchCommands
(
ev
)
{
async
fetchCommands
(
ev
)
{
ev
.
preventDefault
();
ev
.
preventDefault
();
delete
this
.
alert_type
;
delete
this
.
alert
;
const
form_data
=
new
FormData
(
ev
.
target
);
const
form_data
=
new
FormData
(
ev
.
target
);
const
jid
=
form_data
.
get
(
'
jid
'
).
trim
();
const
jid
=
form_data
.
get
(
'
jid
'
).
trim
();
if
(
await
api
.
disco
.
supports
(
Strophe
.
NS
.
ADHOC
,
jid
))
{
let
supported
;
this
.
commands
=
await
api
.
adhoc
.
getCommands
(
jid
);
try
{
this
.
view
=
'
list-commands
'
;
supported
=
await
api
.
disco
.
supports
(
Strophe
.
NS
.
ADHOC
,
jid
)
}
catch
(
e
)
{
log
.
error
(
e
);
}
if
(
supported
)
{
try
{
this
.
commands
=
await
api
.
adhoc
.
getCommands
(
jid
);
this
.
view
=
'
list-commands
'
;
}
catch
(
e
)
{
log
.
error
(
e
);
this
.
alert_type
=
'
danger
'
;
this
.
alert
=
__
(
'
Sorry, an error occurred while looking for commands on that entity.
'
);
this
.
commands
=
[];
log
.
error
(
e
);
return
;
}
}
else
{
this
.
alert_type
=
'
danger
'
;
this
.
alert
=
__
(
"
The specified entity doesn't support ad-hoc commands
"
);
}
}
}
}
...
...
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