Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-webui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-webui
Commits
a6ca1e32
Verified
Commit
a6ca1e32
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
Add callback on save
parent
860733f6
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!68
DOC: update CHANGELOG
,
!62
FIX: Save WYSIWYG saving in source mode
Pipeline
#18067
canceled
3 years ago
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/js/ext_editmode_wysiwyg_text.js
+41
-24
41 additions, 24 deletions
src/core/js/ext_editmode_wysiwyg_text.js
with
41 additions
and
24 deletions
src/core/js/ext_editmode_wysiwyg_text.js
+
41
−
24
View file @
a6ca1e32
...
...
@@ -39,6 +39,8 @@
*/
var
ext_editmode_wysiwyg_text
=
function
(
$
,
logger
,
ClassicEditor
,
edit_mode
,
getPropertyElements
,
getPropertyDatatype
,
getPropertyName
)
{
var
_callOnSave
=
[];
var
insertEditorInProperty
=
async
function
(
prop
)
{
if
(
!
(
getPropertyDatatype
(
prop
)
===
'
TEXT
'
))
{
// Ignore anything that isn't a list property, even LIST<TEXT>
...
...
@@ -62,16 +64,17 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g
logger
.
debug
(
'
Initialized editor for
'
+
getPropertyName
(
prop
));
// Manually implement saving the data since edit mode is not
// a form to be submitted.
editor
.
model
.
document
.
on
(
"
change:data
"
,
(
e
)
=>
{
_callOnSave
.
push
(()
=>
{
editor
.
updateSourceElement
()
});
//editor.model.document.on("change:data", (e) => {
// console.log(editor.getData());
// console.log(editor.sourceElement.value);
console
.
log
(
editor
.
getData
()
!=
editor
.
sourceElement
.
value
);
if
(
editor
.
getData
()
!=
editor
.
sourceElement
.
value
)
{
console
.
log
(
"
Saving editor...
"
);
editor
.
updateSourceElement
();
}
});
//
//
console.log(editor.getData());
//
//
console.log(editor.sourceElement.value);
//
console.log(editor.getData() != editor.sourceElement.value);
//
if (editor.getData() != editor.sourceElement.value) {
//
console.log("Saving editor...");
//
editor.updateSourceElement();
//
}
//
});
// TODO(fspreck): Add an event listener to save also changes made in
// source mode. What event can we listen to? The following doesn't
// work either.
...
...
@@ -79,28 +82,42 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g
// console.log("Saving after input...");
// editor.updateSourceElement();
// }, true);
const
sourceEditingPlugin
=
editor
.
plugins
.
get
(
"
SourceEditing
"
);
sourceEditingPlugin
.
on
(
"
change:isSourceEditingMode
"
,
(
e
,
name
,
isSourceEditingMode
)
=>
{
if
(
isSourceEditingMode
)
{
// Maybe this helps?
console
.
log
(
"
Entering source editing
"
);
const
[
domSourceEditingElementWrapper
]
=
sourceEditingPlugin
.
_replacedRoots
.
values
();
const
textarea
=
domSourceEditingElementWrapper
.
querySelector
(
'
textarea
'
);
//
const sourceEditingPlugin = editor.plugins.get("SourceEditing");
//
sourceEditingPlugin.on("change:isSourceEditingMode", (e, name, isSourceEditingMode) => {
//
if (isSourceEditingMode) {
//
//
Maybe this helps?
//
console.log("Entering source editing");
//
const [domSourceEditingElementWrapper] = sourceEditingPlugin._replacedRoots.values();
//
const textarea = domSourceEditingElementWrapper.querySelector('textarea');
// TODO(fspreck) this has to be more intelligent since it
// leads to an infinite update loop...
textarea
.
addEventListener
(
"
input
"
,
(
e
)
=>
{
console
.
log
(
"
Input in source mode
"
);
// sourceEditingPlugin._updateEditorData();
});
}
});
//
//
TODO(fspreck) this has to be more intelligent since it
//
//
leads to an infinite update loop...
//
textarea.addEventListener("input", (e) => {
//
console.log("Input in source mode");
//
//
sourceEditingPlugin._updateEditorData();
//
});
//
}
//
});
}
catch
(
error
)
{
logger
.
error
(
error
.
stack
);
}
}
const
proxySaveMethod
=
function
(
original
)
{
const
result
=
function
(
entity
)
{
_callOnSave
.
forEach
(
cb
=>
{
cb
();});
if
(
typeof
original
===
"
function
"
)
{
return
original
(
entity
);
}
return
undefined
;
}
return
result
;
}
var
replaceTextAreas
=
function
(
entity
)
{
// on save, call callbacks
edit_mode
.
app
.
onBeforeInsert
=
proxySaveMethod
(
edit_mode
.
app
.
onBeforeInsert
);
edit_mode
.
app
.
onBeforeUpdate
=
proxySaveMethod
(
edit_mode
.
app
.
onBeforeUpdate
);
const
properties
=
getPropertyElements
(
entity
);
for
(
let
prop
of
properties
)
{
// TODO(fspreck): This will be replaced by a whitelist of properties
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment